mirror of
https://github.com/GTNewHorizons/BetterP2P.git
synced 2026-11-20 20:12:35 +00:00
add search bar and custom name display
This commit is contained in:
1 parent
9291407039
commit
90fcf8cd5c
9 files changed
+72
-16
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package com.projecturanus.betterp2p.client.gui
|
||||
|
||||
import appeng.client.gui.widgets.MEGuiTextField
|
||||
import com.projecturanus.betterp2p.BetterP2P
|
||||
import com.projecturanus.betterp2p.MODID
|
||||
import com.projecturanus.betterp2p.capability.MemoryInfo
|
||||
@@ -35,6 +36,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
private var selectedIndex = -1
|
||||
|
||||
private lateinit var scrollBar: WidgetScrollBar
|
||||
private lateinit var searchBar: MEGuiTextField
|
||||
|
||||
private val infos = msg.infos.map(::InfoWrapper).toMutableList()
|
||||
|
||||
@@ -53,7 +55,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
|
||||
private var mode = msg.memoryInfo.mode
|
||||
private var modeString = getModeString()
|
||||
private val modeButton by lazy { GuiButton(0, guiLeft + 8, guiTop + 140, 205, 20, modeString) }
|
||||
private val modeButton by lazy { GuiButton(0, guiLeft + 8, guiTop + 154, 205, 20, modeString) }
|
||||
|
||||
init {
|
||||
selectInfo(msg.memoryInfo.selectedIndex)
|
||||
@@ -61,7 +63,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
infoOnScreen = sortedInfo.take(5)
|
||||
|
||||
val list = mutableListOf<WidgetP2PDevice>()
|
||||
for (i in 0..4) {
|
||||
for (i in 0..3) {
|
||||
list += WidgetP2PDevice(::selectedInfo, ::mode, { sortedInfo.getOrNull(i + scrollBar.currentScroll) }, 0, 0)
|
||||
}
|
||||
widgetDevices = list.toList()
|
||||
@@ -71,14 +73,36 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
super.initGui()
|
||||
checkInfo()
|
||||
scrollBar = WidgetScrollBar()
|
||||
searchBar = MEGuiTextField(fontRendererObj, guiLeft + 148, guiTop + 3, 65, 10)
|
||||
searchBar.maxStringLength = 25
|
||||
searchBar.setTextColor(0xFFFFFF)
|
||||
searchBar.visible = true
|
||||
searchBar.enableBackgroundDrawing = false
|
||||
scrollBar.displayX = guiLeft + 218
|
||||
scrollBar.displayY = guiTop + 19
|
||||
scrollBar.height = 114
|
||||
scrollBar.setRange(0, infos.size.coerceIn(0..(infos.size-5).coerceAtLeast(0)), 23)
|
||||
scrollBar.setRange(0, infos.size.coerceIn(0..(infos.size - 4).coerceAtLeast(0)), 23)
|
||||
|
||||
for (i in 0..4) {
|
||||
for (i in 0..3) {
|
||||
widgetDevices[i].x = guiLeft + tableX
|
||||
widgetDevices[i].y = guiTop + tableY + 23 * i
|
||||
widgetDevices[i].y = guiTop + tableY + 33 * i
|
||||
}
|
||||
}
|
||||
|
||||
private fun reGenInfoFromText() {
|
||||
var tmpInfo = infos.filter { it.frequency.toHexString().contains(searchBar.text) || it.frequency.toHexString().format4().contains(searchBar.text) || it.name.contains(searchBar.text) }
|
||||
if (searchBar.text.isEmpty())
|
||||
tmpInfo = infos
|
||||
sortedInfo = tmpInfo.sortedBy {
|
||||
if (it.index == selectedIndex) {
|
||||
-2 // Put the selected p2p in the front
|
||||
} else if (it.frequency != 0.toLong() && it.frequency == selectedInfo?.frequency && !it.output) {
|
||||
-3 // Put input in the beginning
|
||||
} else if (it.frequency != 0.toLong() && it.frequency == selectedInfo?.frequency) {
|
||||
-1 // Put same frequency in the front
|
||||
} else {
|
||||
it.frequency + Short.MAX_VALUE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +143,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
|
||||
private fun drawInformation() {
|
||||
val x = 8
|
||||
var y = 170
|
||||
var y = 178
|
||||
for (line in descriptionLines) {
|
||||
fontRendererObj.drawString(line, guiLeft + x, guiTop + y, 0)
|
||||
y += fontRendererObj.FONT_HEIGHT
|
||||
@@ -135,6 +159,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
drawDefaultBackground()
|
||||
drawBackground()
|
||||
scrollBar.draw(this)
|
||||
searchBar.drawTextBox()
|
||||
|
||||
for (widget in widgetDevices) {
|
||||
widget.render(this, mouseX, mouseY, partialTicks)
|
||||
@@ -222,6 +247,11 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
switchMode()
|
||||
}
|
||||
scrollBar.click(mouseX, mouseY)
|
||||
searchBar.mouseClicked(mouseX, mouseY, mouseButton)
|
||||
if (mouseButton == 1 && searchBar.isMouseIn(mouseX, mouseY)) {
|
||||
this.searchBar.text = ""
|
||||
reGenInfoFromText()
|
||||
}
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton)
|
||||
}
|
||||
|
||||
@@ -255,4 +285,13 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound {
|
||||
override fun doesGuiPauseGame(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun keyTyped(char: Char, key: Int) {
|
||||
if (char == ' ' && searchBar.text.isEmpty()) {
|
||||
return
|
||||
}
|
||||
searchBar.textboxKeyTyped(char, key)
|
||||
reGenInfoFromText()
|
||||
super.keyTyped(char, key)
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ class InfoWrapper(info: P2PInfo) {
|
||||
val facing: EnumFacing = info.facing
|
||||
val description: String
|
||||
val output: Boolean = info.output
|
||||
val name: String = info.name
|
||||
var error: Boolean = false
|
||||
|
||||
// Widgets
|
||||
|
||||
@@ -14,7 +14,7 @@ class WidgetP2PDevice(private val selectedInfoProperty: KMutableProperty0<InfoWr
|
||||
private val inactiveColor = 0x45FFEA05
|
||||
|
||||
private val rowWidth = 203
|
||||
private val rowHeight = 22
|
||||
private val rowHeight = 32
|
||||
|
||||
private var selectedInfo: InfoWrapper?
|
||||
get() = selectedInfoProperty.get()
|
||||
@@ -43,6 +43,7 @@ class WidgetP2PDevice(private val selectedInfoProperty: KMutableProperty0<InfoWr
|
||||
|
||||
fontRenderer.drawString(info.description, x + 24, y + 3, 0)
|
||||
fontRenderer.drawString(I18n.format("gui.advanced_memory_card.pos", info.posX, info.posY, info.posZ, info.facing.name), x + 24, y + 12, 0)
|
||||
fontRenderer.drawString(I18n.format("gui.advanced_memory_card.name", info.name), x + 24, y + 21, 0)
|
||||
|
||||
if (selectedInfo == null) {
|
||||
info.bindButton.enabled = false
|
||||
@@ -85,21 +86,24 @@ class WidgetP2PDevice(private val selectedInfoProperty: KMutableProperty0<InfoWr
|
||||
info.bindButton.enabled = false
|
||||
info.selectButton.enabled = true
|
||||
|
||||
info.selectButton.xPosition = x + 166
|
||||
info.selectButton.yPosition = y + 1
|
||||
info.selectButton.xPosition = x + 172
|
||||
info.selectButton.width = 28
|
||||
info.selectButton.yPosition = y + 6
|
||||
info.selectButton.drawButton(gui.mc, mouseX, mouseY)
|
||||
} else if (info.bindButton.enabled && info.selectButton.enabled) {
|
||||
info.bindButton.enabled = true
|
||||
info.selectButton.enabled = true
|
||||
|
||||
// Select button on the left
|
||||
info.selectButton.xPosition = x + 130
|
||||
info.selectButton.yPosition = y + 1
|
||||
info.selectButton.xPosition = x + 141
|
||||
info.selectButton.width = 28
|
||||
info.selectButton.yPosition = y + 6
|
||||
info.selectButton.drawButton(gui.mc, mouseX, mouseY)
|
||||
|
||||
// Bind button on the right
|
||||
info.bindButton.xPosition = x + 166
|
||||
info.bindButton.yPosition = y + 1
|
||||
info.bindButton.xPosition = x + 172
|
||||
info.bindButton.width = 28
|
||||
info.bindButton.yPosition = y + 6
|
||||
info.bindButton.drawButton(gui.mc, mouseX, mouseY)
|
||||
} else if (!info.selectButton.enabled && !info.bindButton.enabled) {
|
||||
// TODO Unbind
|
||||
|
||||
@@ -2,5 +2,5 @@ package com.projecturanus.betterp2p.network
|
||||
|
||||
import net.minecraft.util.EnumFacing
|
||||
|
||||
class P2PInfo(val index: Int, val frequency: Long, val posX: Int, val posY: Int, val posZ: Int, val facing: EnumFacing, val output: Boolean, val hasChannel: Boolean) {
|
||||
class P2PInfo(val index: Int, val frequency: Long, val posX: Int, val posY: Int, val posZ: Int, val facing: EnumFacing, val name: String, val output: Boolean, val hasChannel: Boolean) {
|
||||
}
|
||||
@@ -11,7 +11,12 @@ fun readInfo(buf: ByteBuf): P2PInfo {
|
||||
val posY = buf.readInt()
|
||||
val posZ = buf.readInt()
|
||||
val facing = EnumFacing.values()[buf.readInt()]
|
||||
return P2PInfo(index, freq, posX, posY, posZ, facing, buf.readBoolean(), buf.readBoolean())
|
||||
val nameLength = buf.readShort() - 1
|
||||
var name = ""
|
||||
for (i in 0..nameLength) {
|
||||
name += buf.readChar()
|
||||
}
|
||||
return P2PInfo(index, freq, posX, posY, posZ, facing, name, buf.readBoolean(), buf.readBoolean())
|
||||
}
|
||||
|
||||
fun writeInfo(buf: ByteBuf, info: P2PInfo) {
|
||||
@@ -21,6 +26,10 @@ fun writeInfo(buf: ByteBuf, info: P2PInfo) {
|
||||
buf.writeInt(info.posY)
|
||||
buf.writeInt(info.posZ)
|
||||
buf.writeInt(info.facing.ordinal)
|
||||
buf.writeShort(info.name.length)
|
||||
for (c in info.name) {
|
||||
buf.writeChar(c.toInt())
|
||||
}
|
||||
buf.writeBoolean(info.output)
|
||||
buf.writeBoolean(info.hasChannel)
|
||||
}
|
||||
|
||||
@@ -106,4 +106,4 @@ val PartP2PTunnel<*>.hasChannel
|
||||
get() = isPowered && isActive
|
||||
|
||||
fun PartP2PTunnel<*>.getInfo(index: Int)
|
||||
= P2PInfo(index, frequency, location.x, location.y, location.z, EnumFacing.getFront(side.getEnumIndex()), isOutput, hasChannel)
|
||||
= P2PInfo(index, frequency, location.x, location.y, location.z, EnumFacing.getFront(side.getEnumIndex()), customName, isOutput, hasChannel)
|
||||
@@ -4,6 +4,7 @@ item.advanced_memory_card.not_selected=No Frequency
|
||||
gui.advanced_memory_card.select=Select
|
||||
gui.advanced_memory_card.bind=Bind
|
||||
gui.advanced_memory_card.pos=Pos: %d, %d, %d Side: %s
|
||||
gui.advanced_memory_card.name=Name: %s
|
||||
gui.advanced_memory_card.mode.input=Mode: Bind Input
|
||||
gui.advanced_memory_card.mode.output=Mode: Bind Output
|
||||
gui.advanced_memory_card.mode.copy=Mode: Copy Output
|
||||
|
||||
@@ -4,6 +4,7 @@ item.advanced_memory_card.not_selected=无内容
|
||||
gui.advanced_memory_card.select=选择
|
||||
gui.advanced_memory_card.bind=绑定
|
||||
gui.advanced_memory_card.pos=位置: %d, %d, %d 朝向: %s
|
||||
gui.advanced_memory_card.name=名称: %s
|
||||
gui.advanced_memory_card.mode.input=模式:绑定输入
|
||||
gui.advanced_memory_card.mode.output=模式:绑定输出
|
||||
gui.advanced_memory_card.mode.copy=模式:复制输出
|
||||
@@ -11,3 +12,4 @@ gui.advanced_memory_card.desc.mode=改变为%s
|
||||
gui.advanced_memory_card.desc.mode.input=输入
|
||||
gui.advanced_memory_card.desc.mode.output=输出
|
||||
gui.advanced_memory_card.desc.not_set=未配置
|
||||
gui.advanced_memory_card.desc.effect=效果:
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Reference in new issue
Block a user