diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt index 1165975..6f14787 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/GuiAdvancedMemoryCard.kt @@ -7,6 +7,7 @@ import com.projecturanus.betterp2p.client.ClientCache import com.projecturanus.betterp2p.client.TextureBound import com.projecturanus.betterp2p.client.gui.widget.* import com.projecturanus.betterp2p.network.* +import net.minecraft.client.gui.FontRenderer import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.GuiScreen import net.minecraft.client.renderer.Tessellator @@ -14,6 +15,7 @@ import net.minecraft.client.resources.I18n import net.minecraft.util.ResourceLocation import org.lwjgl.input.Keyboard import org.lwjgl.input.Mouse +import org.lwjgl.opengl.GL11 import java.util.* const val GUI_WIDTH = 288 @@ -72,6 +74,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { ) } + val BACKGROUND: ResourceLocation = ResourceLocation(MODID, "textures/gui/advanced_memory_card.png") private val selectedInfo: InfoWrapper? get() = infos.selectedInfo @@ -106,13 +109,13 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { scale = GuiScale.DYNAMIC } val numEntries = scale.size(height - 75) - ySize = (numEntries * P2P_ENTRY_HEIGHT) + 75 + (numEntries - 1) + ySize = (numEntries * P2PEntryConstants.HEIGHT) + 75 + (numEntries - 1) guiTop = (h - ySize) / 2 guiLeft = (width - GUI_WIDTH) / 2 scrollBar.displayX = guiLeft + 268 scrollBar.displayY = guiTop + 19 - scrollBar.height = numEntries * P2P_ENTRY_HEIGHT + (numEntries - 1) - 7 + scrollBar.height = numEntries * P2PEntryConstants.HEIGHT + (numEntries - 1) - 7 scrollBar.setRange(0, infos.size.coerceIn(0, (infos.size - numEntries).coerceAtLeast(0)), 23) searchBar.setMaxStringLength(40) @@ -170,11 +173,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { drawDefaultBackground() drawBackground() - scrollBar.draw(this) - searchBar.drawTextBox() - col.render(this, mouseX, mouseY, partialTicks) - modeButton.drawButton(mc, mouseX, mouseY) - resizeButton.draw(mc, mouseX, mouseY, partialTicks) + // Draw the stuff that resets GL state first fontRendererObj.drawString(I18n.format("item.advanced_memory_card.name"), guiLeft + tableX, guiTop + 6, 0) if (modeButton.func_146115_a()) { descriptionLines.clear() @@ -183,10 +182,26 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { descriptionLines.clear() } drawInformation() + searchBar.drawTextBox() + resizeButton.draw(mc, mouseX, mouseY, partialTicks) + modeButton.drawButton(mc, mouseX, mouseY) + + // Now do our drawing + GL11.glPushAttrib(GL11.GL_BLEND or GL11.GL_TEXTURE_2D or GL11.GL_COLOR) + GL11.glEnable(GL11.GL_BLEND) + GL11.glEnable(GL11.GL_TEXTURE_2D) + GL11.glColor3f(255f, 255f, 255f) + scrollBar.draw(this) + + col.render(this, mouseX, mouseY, partialTicks) + // The GL state is already messed up here by string drawing but oh well + GL11.glPopAttrib() if (searchBar.isMouseIn(mouseX, mouseY)) { drawHoveringText(sortRules, guiLeft, guiTop + ySize - 40, fontRendererObj) } else if (resizeButton.isHovering(mouseX, mouseY)) { drawHoveringText(listOf(I18n.format(resizeButton.hoverText())), mouseX, mouseY, fontRendererObj) + } else { + col.mouseHovered(mouseX, mouseY) } super.drawScreen(mouseX, mouseY, partialTicks) } @@ -230,6 +245,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { col.mouseClicked(mouseX, mouseY, mouseButton) if (modeButton.mousePressed(mc, mouseX, mouseY)) { switchMode() + modeButton.func_146113_a(mc.soundHandler) } scrollBar.click(mouseX, mouseY) resizeButton.mousePressed(mouseX, mouseY) @@ -254,8 +270,8 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { super.handleMouseInput() val i = Mouse.getEventDWheel() if (i != 0 && isShiftKeyDown()) { - val x = Mouse.getEventX() * width / mc.displayWidth - val y = height - Mouse.getEventY() * height / mc.displayHeight - 1 +// val x = Mouse.getEventX() * width / mc.displayWidth +// val y = height - Mouse.getEventY() * height / mc.displayHeight - 1 // this.mouseWheelEvent(x, y, i / Math.abs(i)) } else if (i != 0) { scrollBar.wheel(i) @@ -268,8 +284,12 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { mc.textureManager.bindTexture(loc) } + fun bindTexture(loc: ResourceLocation) { + mc.textureManager.bindTexture(loc) + } + private fun drawBackground() { - bindTexture(MODID, "textures/gui/advanced_memory_card.png") + bindTexture(BACKGROUND) val tessellator = Tessellator.instance // Draw the top part drawTexturedQuad(tessellator, guiLeft.toDouble(), guiTop.toDouble(), @@ -277,7 +297,7 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { u0 = 0.0, v0 = 0.0, u1 = 1.0, v1 = 60.0 / GUI_TEX_HEIGHT) // Draw P2P segments - val p2pHeight = P2P_ENTRY_HEIGHT + 1.0 + val p2pHeight = P2PEntryConstants.HEIGHT + 1.0 for (i in 0 until scale.size(ySize - 75) - 2) { drawTexturedQuad(tessellator, guiLeft.toDouble(), guiTop + 60.0 + p2pHeight * i, (guiLeft + GUI_WIDTH).toDouble(), guiTop + 60.0 + p2pHeight * (i + 1), @@ -296,10 +316,18 @@ class GuiAdvancedMemoryCard(msg: S2CListP2P) : GuiScreen(), TextureBound { } override fun keyTyped(char: Char, key: Int) { - if(key == Keyboard.KEY_LSHIFT) return - if (!col.keyTyped(char, key) && !(char.isWhitespace() && searchBar.text.isEmpty()) && searchBar.textboxKeyTyped(char, key)){ + if (key == Keyboard.KEY_LSHIFT || col.keyTyped(char, key)) return + if (!(char.isWhitespace() && searchBar.text.isEmpty()) && searchBar.textboxKeyTyped(char, key)){ infos.refilter() + } else if (char == 'e') { + mc.displayGuiScreen(null as GuiScreen?) + mc.setIngameFocus() + return } return super.keyTyped(char, key) } + + public override fun drawHoveringText(textLines: List?, x: Int, y: Int, font: FontRenderer?) { + super.drawHoveringText(textLines, x, y, font) + } } diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/GuiHelper.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/GuiHelper.kt index b95fbe1..d27b0b0 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/GuiHelper.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/GuiHelper.kt @@ -3,10 +3,6 @@ package com.projecturanus.betterp2p.client.gui import net.minecraft.client.renderer.Tessellator import net.minecraft.util.ResourceLocation -fun bindTexture(loc: ResourceLocation) { - -} - /** * Draws a textured quad. * diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/InfoWrapper.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/InfoWrapper.kt index 0c4b3ba..f67cfb4 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/InfoWrapper.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/InfoWrapper.kt @@ -1,11 +1,17 @@ package com.projecturanus.betterp2p.client.gui +import appeng.api.parts.PartItemStack +import appeng.me.GridNode +import appeng.parts.p2p.PartP2PTunnel +import appeng.parts.p2p.PartP2PTunnelME +import appeng.tile.networking.TileCableBus import com.projecturanus.betterp2p.network.P2PInfo import com.projecturanus.betterp2p.network.hashP2P import net.minecraft.client.gui.GuiButton import net.minecraft.client.resources.I18n +import net.minecraft.util.IIcon +import net.minecraftforge.common.DimensionManager import net.minecraftforge.common.util.ForgeDirection -import java.util.* class InfoWrapper(info: P2PInfo) { // Basic information @@ -19,29 +25,81 @@ class InfoWrapper(info: P2PInfo) { val posZ: Int = info.posZ val dim: Int = info.world val facing: ForgeDirection = info.facing - val description: String val output: Boolean = info.output - var name: String = info.name - var error: Boolean = false + val tile: TileCableBus? by lazy { + DimensionManager.getWorld(dim)?.getTileEntity(posX, posY, posZ) as? TileCableBus + } - // Widgets - val selectButton = GuiButton(0, 0, 0, 34, 20, I18n.format("gui.advanced_memory_card.select")) - val bindButton = GuiButton(0, 0, 0, 34, 20, I18n.format("gui.advanced_memory_card.bind")) - val renameButton = GuiButton(0, 0, 0, 0, 0,"") - init { - description = buildString { - append("P2P ") + val icon: IIcon? by lazy { + (tile?.getPart(info.facing) as? PartP2PTunnel<*>)?.typeTexture + } + val overlay: IIcon? by lazy { + tile?.getPart(info.facing)?.getItemStack(PartItemStack.Wrench)?.iconIndex + } + + val typeName: String by lazy { + val item = tile?.getPart(info.facing)?.getItemStack(PartItemStack.Wrench) + I18n.format(item?.getItem()?.getItemStackDisplayName(item)?.split(" - ")?.getOrNull(1) + ?: "§c") + } + + val description: String by lazy { + buildString { + append("Type: ") + append(typeName) + append(" - ") if (output) append(I18n.format("gui.advanced_memory_card.desc.mode.output")) else append(I18n.format("gui.advanced_memory_card.desc.mode.input")) - append(" - ") - if (info.frequency.toInt() == 0) - append(I18n.format("gui.advanced_memory_card.desc.not_set")) - else - append(info.frequency.toHexString().format4()) } } + val freqDisplay: String by lazy { + buildString { + append(I18n.format("item.advanced_memory_card.selected")) + append(" ") + if (frequency != 0L) { + val hex: String = buildString { + append((frequency shr 32).toUInt().toString(16).uppercase()) + append(frequency.toUInt().toString(16).uppercase()) + }.format4() + append(hex) + } else { + append(I18n.format("gui.advanced_memory_card.desc.not_set")) + } + } + } + + val hoverInfo: List by lazy { + val online = (tile?.getPart(info.facing) as? PartP2PTunnel<*>)?.proxy?.isPowered + val list = mutableListOf( + "§b$typeName§r", + "§e" + I18n.format("gui.advanced_memory_card.pos", info.posX, info.posY, info.posZ), + "§e" + I18n.format("gui.advanced_memory_card.side", info.facing.name), + "§e" + I18n.format("gui.advanced_memory_card.dim", info.world) + ) + if (error || frequency == 0L) { + list.add("§c" + I18n.format("gui.advanced_memory_card.p2p_status.unbound")) + } else { + list.add("§a" + I18n.format("gui.advanced_memory_card.p2p_status.bound")) + } + if (online != true) list.add("§c" + I18n.format("gui.advanced_memory_card.p2p_status.offline")) + list + } + + val channels: String? by lazy { + val c = ((tile?.getPart(facing) as? PartP2PTunnelME)?.externalFacingNode as? GridNode)?.usedChannels() + if (c != null) { + I18n.format("gui.advanced_memory_card.extra.channel", c) + } else null + } + + var name: String = info.name + var error: Boolean = false + + // Widgets + val bindButton = GuiButton(0, 0, 0, 34, 20, I18n.format("gui.advanced_memory_card.bind")) + val renameButton = GuiButton(0, 0, 0, 0, 0,"") override fun hashCode(): Int { return code.hashCode() @@ -60,23 +118,13 @@ class InfoWrapper(info: P2PInfo) { } } -fun Long.toHexString(): String { - var tmp = this - var hex = String() - while (tmp != 0.toLong()) { - hex += Integer.toHexString((tmp % 16).toInt()) - tmp /= 16 - } - return hex.uppercase(Locale.getDefault()).reversed() -} - fun String.format4(): String { - var format = String() + val format = StringBuilder() for (index in this.indices) { if (index % 4 == 0 && index != 0) { - format += " " + format.append(" ") } - format += this[index] + format.append(this[index]) } - return format + return format.toString() } diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/widget/GuiScale.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/widget/GuiScale.kt index 68ff9ad..0ef5f5d 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/widget/GuiScale.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/widget/GuiScale.kt @@ -4,5 +4,5 @@ enum class GuiScale(inline val size: (Int) -> Int, val minHeight: Int, val unloc SMALL({ 4 }, 0, "gui.advanced_memory_card.gui_scale.small"), NORMAL({ 6 }, 326, "gui.advanced_memory_card.gui_scale.normal"), LARGE({ 8 }, 409, "gui.advanced_memory_card.gui_scale.large"), - DYNAMIC({ availableHeight -> availableHeight / P2P_ENTRY_HEIGHT }, 0, "gui.advanced_memory_card.gui_scale.dynamic") + DYNAMIC({ availableHeight -> availableHeight / P2PEntryConstants.HEIGHT }, 0, "gui.advanced_memory_card.gui_scale.dynamic") } diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetButton.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetButton.kt index f4aaebb..1fe425e 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetButton.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetButton.kt @@ -29,13 +29,12 @@ abstract class WidgetButton(val gui: GuiAdvancedMemoryCard, x: Int, y: Int, widt fun draw(mc: Minecraft?, mouseX: Int, mouseY: Int, partialTicks: Float) { val tessellator = Tessellator.instance - gui.bindTexture(MODID, "textures/gui/advanced_memory_card.png") + gui.bindTexture(gui.BACKGROUND) GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f) field_146123_n = mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height val k = getHoverState(field_146123_n) GL11.glEnable(GL11.GL_BLEND) - OpenGlHelper.glBlendFunc(770, 771, 1, 0) - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0) // Draw button backdrop drawTexturedQuad(tessellator, xPosition.toDouble(), yPosition.toDouble(), (xPosition + width).toDouble(), (yPosition + height).toDouble(), diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetP2PColumn.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetP2PColumn.kt index cf98a2f..19fa4f1 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetP2PColumn.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetP2PColumn.kt @@ -1,5 +1,6 @@ package com.projecturanus.betterp2p.client.gui.widget +import appeng.core.localization.GuiColors import com.projecturanus.betterp2p.BetterP2P import com.projecturanus.betterp2p.capability.P2PTunnelInfo import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard @@ -7,8 +8,8 @@ import com.projecturanus.betterp2p.client.gui.InfoList import com.projecturanus.betterp2p.client.gui.InfoWrapper import com.projecturanus.betterp2p.item.BetterMemoryCardModes import com.projecturanus.betterp2p.network.* +import net.minecraft.client.gui.GuiTextField import net.minecraftforge.common.util.ForgeDirection -import org.lwjgl.input.Keyboard import kotlin.reflect.KProperty0 /** @@ -23,8 +24,8 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard, val mode: () -> BetterMemoryCardModes, private var scrollBar: WidgetScrollBar) { - private val entries: MutableList = mutableListOf() - private val renameBar: IGuiTextField = IGuiTextField(0,0) + val entries: MutableList = mutableListOf() + private val renameBar: IGuiTextField = IGuiTextField(160,12) init { renameBar.setMaxStringLength(50) @@ -38,7 +39,7 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard, for (i in 0 until scale.size(availableHeight)) { val widget = WidgetP2PDevice( selectedInfo, mode, { infos.filtered.getOrNull(i + scrollBar.currentScroll) }, - x, y + i * (P2P_ENTRY_HEIGHT + 1)) + x, y + i * (P2PEntryConstants.HEIGHT + 1)) entries.add(widget) } } @@ -48,7 +49,7 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard, this.y = y for ((i, entry) in entries.withIndex()) { entry.x = x - entry.y = y + i * (P2P_ENTRY_HEIGHT + 1) + entry.y = y + i * (P2PEntryConstants.HEIGHT + 1) } } @@ -56,7 +57,7 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard, for (widget in entries){ widget.renderNameTextField = true } - if(renameBar.info != null && renameBar.info.name != renameBar.text){ + if(renameBar.info != null && !renameBar.text.isEmpty() && renameBar.info.name != renameBar.text){ val info:InfoWrapper = renameBar.info renameBar.text = renameBar.text.trim() ModNetwork.channel.sendToServer(C2SP2PTunnelInfo(P2PTunnelInfo(info.posX,info.posY,info.posZ,info.dim, ForgeDirection.valueOf(info.facing.name).ordinal,renameBar.text))) @@ -72,15 +73,17 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard, // ModNetwork.channel.sendToServer(C2STransportPlayer(P2PTunnelInfo(info.posX,info.posY,info.posZ,info.dim,0))) //} + /** + * Called when rename button "area" is clicked. Rename text bar must be + * visible after this is called. + */ private fun onRenameButtonClicked(info:InfoWrapper, index: Int) { // if (GuiScreen.isShiftKeyDown()) { // transportPlayer(info) // } renameBar.isVisible = true - renameBar.y = (this.y) + index * (P2P_ENTRY_HEIGHT + 1) + 19 + renameBar.y = (this.y) + index * (P2PEntryConstants.HEIGHT + 1) + 1 renameBar.x = this.x + 50 - renameBar.w = 120 - renameBar.h = 12 renameBar.text = info.name renameBar.setFocus(true,0) renameBar.info = info @@ -88,6 +91,7 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard, private fun onSelectButtonClicked(info: InfoWrapper) { gui.selectInfo(info.code) + info.bindButton.func_146113_a(gui.mc.soundHandler) } private fun onBindButtonClicked(info: InfoWrapper) { @@ -107,6 +111,7 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard, ModNetwork.channel.sendToServer(C2SLinkP2P(input.code, info.code)) } } + info.bindButton.func_146113_a(gui.mc.soundHandler) } private fun findInput(frequency: Long?) = @@ -116,17 +121,22 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard, var clickRenameButton = false for ((index,widget) in entries.withIndex()) { val info = widget.infoSupplier() - if (info?.selectButton?.mousePressed(gui.mc, mouseX, mouseY) == true) { - onSelectButtonClicked(widget.infoSupplier()!!) - } else if (info?.bindButton?.mousePressed(gui.mc, mouseX, mouseY) == true) { + if (info?.bindButton?.mousePressed(gui.mc, mouseX, mouseY) == true) { onBindButtonClicked(widget.infoSupplier()!!) - } else if (info?.renameButton?.mousePressed(gui.mc, mouseX,mouseY) == true) { - if(renameBar.info != widget.infoSupplier()!!) { + } else if (mouseX > widget.x.toDouble() + 50 && mouseX < widget.x.toDouble() + 50 + 160 && + mouseY > widget.y.toDouble() + 1 && mouseY < widget.y + 1 + 13 && + widget.infoSupplier() != null) { + if(renameBar.info != widget.infoSupplier()) { finishRename() } widget.renderNameTextField = false onRenameButtonClicked(widget.infoSupplier()!!, index) clickRenameButton = true + } else if (mouseX > widget.x && mouseX < widget.x + P2PEntryConstants.WIDTH && + mouseY > widget.y && mouseY < widget.y + P2PEntryConstants.HEIGHT && + info != null && selectedInfo.get() != info + ) { + onSelectButtonClicked(info) } } renameBar.mouseClicked(mouseX,mouseY,mouseButton) @@ -135,12 +145,30 @@ class WidgetP2PColumn(private val gui: GuiAdvancedMemoryCard, } } + fun mouseHovered(mouseX: Int, mouseY: Int) { + entries.forEach { + val info = it.infoSupplier() + if (mouseX > it.x.toDouble() && mouseX < it.x + 20.0 && + mouseY > it.y.toDouble() && mouseY < it.y + P2PEntryConstants.HEIGHT && info != null) { + gui.drawHoveringText(info.hoverInfo, it.x + 168, it.y + 15, gui.mc.fontRenderer) + } else if (mouseX > it.x.toDouble() + 50 && mouseX < it.x.toDouble() + 50 + 160 && + mouseY > it.y.toDouble() + 1 && mouseY < it.y + 1 + 13 && + !renameBar.isFocused && info != null + ) { + GuiTextField.drawRect( + it.x + 50, + it.y + 1, + it.x + 50 + 160, + it.y + 1 + 12, + GuiColors.SearchboxFocused.color) + } + } + } + fun keyTyped(char: Char, key: Int): Boolean { - if(renameBar.isFocused){ - if(key == Keyboard.KEY_RETURN){ + if (renameBar.isFocused) { + if (!renameBar.textboxKeyTyped(char, key)) { finishRename() - }else{ - renameBar.textboxKeyTyped(char, key) } return true } diff --git a/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetP2PDevice.kt b/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetP2PDevice.kt index 85d3c2a..39924c5 100644 --- a/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetP2PDevice.kt +++ b/src/main/java/com/projecturanus/betterp2p/client/gui/widget/WidgetP2PDevice.kt @@ -1,26 +1,26 @@ package com.projecturanus.betterp2p.client.gui.widget -import appeng.me.GridNode -import appeng.parts.p2p.PartP2PTunnelME -import appeng.tile.networking.TileCableBus -import com.projecturanus.betterp2p.client.gui.GuiAdvancedMemoryCard -import com.projecturanus.betterp2p.client.gui.InfoWrapper +import com.projecturanus.betterp2p.client.gui.* import com.projecturanus.betterp2p.item.BetterMemoryCardModes import net.minecraft.client.gui.GuiScreen +import net.minecraft.client.renderer.OpenGlHelper +import net.minecraft.client.renderer.Tessellator import net.minecraft.client.resources.I18n -import net.minecraftforge.common.DimensionManager -import net.minecraftforge.common.util.ForgeDirection -import java.awt.Color +import net.minecraft.util.IIcon +import org.lwjgl.opengl.GL11 import kotlin.reflect.KProperty0 -const val P2P_ENTRY_HEIGHT: Int = 41 -const val P2P_ENTRY_WIDTH: Int = 254 +object P2PEntryConstants { + const val HEIGHT = 41 + const val WIDTH = 254 + const val OUTPUT_COLOR = 0x4566ccff + const val SELECTED_COLOR = 0x4545DA75 + const val ERROR_COLOR = 0x45DA4527 + const val INACTIVE_COLOR = 0x45FFEA05 + const val LEFT_ALIGN = 24 +} class WidgetP2PDevice(private val selectedInfoProperty: KProperty0, val modeSupplier: () -> BetterMemoryCardModes, val infoSupplier: () -> InfoWrapper?, var x: Int, var y: Int): Widget() { - private val outputColor = 0x4566ccff - private val selectedColor = 0x4545DA75 - private val errorColor = 0x45DA4527 - private val inactiveColor = 0x45FFEA05 var renderNameTextField = true @@ -30,40 +30,54 @@ class WidgetP2PDevice(private val selectedInfoProperty: KProperty0 fun render(gui: GuiAdvancedMemoryCard, mouseX: Int, mouseY: Int, partialTicks: Float) { val info = infoSupplier() if (info != null) { - val fontRenderer = gui.mc.fontRenderer + // Draw the background first if (selectedInfo?.code == info.code) - GuiScreen.drawRect(x, y, x + P2P_ENTRY_WIDTH, y + P2P_ENTRY_HEIGHT, selectedColor) + GuiScreen.drawRect(x, y, x + P2PEntryConstants.WIDTH, y + P2PEntryConstants.HEIGHT, P2PEntryConstants.SELECTED_COLOR) else if (info.error) { - // P2P output without an input - GuiScreen.drawRect(x, y, x + P2P_ENTRY_WIDTH, y + P2P_ENTRY_HEIGHT, errorColor) - } - else if (!info.hasChannel && info.frequency != 0.toLong()) { + // P2P output without an input, or unbound + GuiScreen.drawRect(x, y, x + P2PEntryConstants.WIDTH, y + P2PEntryConstants.HEIGHT, P2PEntryConstants.ERROR_COLOR) + } else if (!info.hasChannel && info.frequency != 0L) { // No channel - GuiScreen.drawRect(x, y, x + P2P_ENTRY_WIDTH, y + P2P_ENTRY_HEIGHT, inactiveColor) - } - else if (selectedInfo?.frequency == info.frequency && info.frequency != 0.toLong()) { + GuiScreen.drawRect(x, y, x + P2PEntryConstants.WIDTH, y + P2PEntryConstants.HEIGHT, P2PEntryConstants.INACTIVE_COLOR) + } else if (selectedInfo?.frequency == info.frequency && info.frequency != 0.toLong()) { // Show same frequency - GuiScreen.drawRect(x, y, x + P2P_ENTRY_WIDTH, y + P2P_ENTRY_HEIGHT, outputColor) + GuiScreen.drawRect(x, y, x + P2PEntryConstants.WIDTH, y + P2PEntryConstants.HEIGHT, P2PEntryConstants.OUTPUT_COLOR) } - 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) - if(renderNameTextField) { - fontRenderer.drawString(I18n.format("gui.advanced_memory_card.name", info.name), x + 24, y + 21, 0) + GL11.glColor3f(255f, 255f, 255f) + // Draw our icons... + drawIcon(gui, info.icon!!, info.overlay!!, x + 3, y + 3) + gui.bindTexture(gui.BACKGROUND) + if (info.output) { + drawTexturedQuad(Tessellator.instance, x.toDouble(), y + 4.0, x + 16.0, y + 20.0, + 144.0 / GUI_WIDTH, 200.0 / GUI_TEX_HEIGHT, 160.0 / GUI_WIDTH, 216.0 / GUI_TEX_HEIGHT) } else { - fontRenderer.drawString(I18n.format("gui.advanced_memory_card.name", ""), x + 24, y + 21, 0) + drawTexturedQuad(Tessellator.instance, x.toDouble(), y + 4.0, x + 16.0, y + 20.0, + 128.0 / GUI_WIDTH, 200.0 / GUI_TEX_HEIGHT, 144.0 / GUI_WIDTH, 216.0 / GUI_TEX_HEIGHT) + } + if (info.error || info.frequency == 0L || !info.hasChannel) { + drawTexturedQuad(Tessellator.instance, x + 3.0, y + 20.0, x + 19.0, y + 36.0, + 144.0 / GUI_WIDTH, 216.0 / GUI_TEX_HEIGHT, 160.0 / GUI_WIDTH, 232.0 / GUI_TEX_HEIGHT) + } else { + drawTexturedQuad(Tessellator.instance, x + 3.0, y + 20.0, x + 19.0, y + 36.0, + 128.0 / GUI_WIDTH, 216.0 / GUI_TEX_HEIGHT, 144.0 / GUI_WIDTH, 232.0 / GUI_TEX_HEIGHT) + } + // Now draw the stuff that messes up our GL state (aka text) + val fontRenderer = gui.mc.fontRenderer + val leftAlign = x + P2PEntryConstants.LEFT_ALIGN + if (renderNameTextField) { + fontRenderer.drawString(I18n.format("gui.advanced_memory_card.name", info.name), leftAlign, y + 3, 0) + } else { + fontRenderer.drawString(I18n.format("gui.advanced_memory_card.name", ""), leftAlign, y + 3, 0) + } + fontRenderer.drawString(info.description, leftAlign, y + 13, 0) + fontRenderer.drawString(info.freqDisplay, leftAlign, y + 23, 0) + if (info.channels != null) { + fontRenderer.drawString(info.channels, leftAlign, y + 33, 0) } - fontRenderer.drawString(getExtraInfo(info.dim, info.posX, info.posY, info.posZ, info.facing), x + 24, y + 30, 0) - if (selectedInfo == null) { info.bindButton.enabled = false - info.selectButton.enabled = true - } else if (info.code != selectedInfo?.code) { - info.bindButton.enabled = true - info.selectButton.enabled = true } else { - // TODO Unbind - info.bindButton.enabled = false - info.selectButton.enabled = false + info.bindButton.enabled = info.code != selectedInfo?.code } val mode = modeSupplier() @@ -71,92 +85,38 @@ class WidgetP2PDevice(private val selectedInfoProperty: KProperty0 info.bindButton.enabled = false } drawButtons(gui, info, mouseX, mouseY, partialTicks) - drawP2PColors(gui, info.frequency, x, y) - } - } - - private fun drawP2PColors(gui: GuiScreen, frequency: Long, x: Int, y: Int) { - drawRectBorder(x + 9, y + 9, 3, 3, Color.BLACK.rgb) - for (row in 0..1) { - for (col in 0..1) { - for (colorIndex in 0..3) { - val offsetX: Int = colorIndex % 2 - val offsetY: Int = colorIndex / 2 - drawHorizontalLine(x + 7 + col * 6 + offsetX, x + 8 + col * 6 + offsetX, y + 7 + row * 6 + offsetY, Color.BLACK.rgb) - } - drawRectBorder(x + 6 + col * 6, y + 6 + row * 6, 3, 3, Color.BLACK.rgb) - } } } private fun drawButtons(gui: GuiScreen, info: InfoWrapper, mouseX: Int, mouseY: Int, partialTicks: Float) { info.renameButton.xPosition = x + 50 info.renameButton.width = 120 - info.renameButton.yPosition = y + 19 + info.renameButton.yPosition = y + 1 info.renameButton.height = 12 - if (!info.bindButton.enabled && info.selectButton.enabled) { + if (!info.bindButton.enabled) { info.bindButton.enabled = false - info.selectButton.enabled = true - - info.selectButton.xPosition = x + 215 - info.selectButton.width = 32 - info.selectButton.yPosition = y + 6 - info.selectButton.drawButton(gui.mc, mouseX, mouseY) - } else if (info.bindButton.enabled && info.selectButton.enabled) { + } else if (info.bindButton.enabled) { info.bindButton.enabled = true - info.selectButton.enabled = true - - // Select button on the left - info.selectButton.xPosition = x + 178 - info.selectButton.width = 32 - info.selectButton.yPosition = y + 6 - info.selectButton.drawButton(gui.mc, mouseX, mouseY) - - // Bind button on the right - info.bindButton.xPosition = x + 215 - info.bindButton.width = 32 - info.bindButton.yPosition = y + 6 + info.bindButton.xPosition = x + 190 + info.bindButton.width = 56 + info.bindButton.yPosition = y + 14 info.bindButton.drawButton(gui.mc, mouseX, mouseY) - } else if (!info.selectButton.enabled && !info.bindButton.enabled) { + } else if (!info.bindButton.enabled) { // TODO Unbind info.bindButton.enabled = false - info.selectButton.enabled = false } } - // For a future feature ;P - -// private fun drawIcon(gui: GuiAdvancedMemoryCard, posX: Int, posY: Int, posZ: Int, face: ForgeDirection, world: Int) { -// val tile = DimensionManager.getWorld(world)?.getTileEntity(posX, posY, posZ) -// if (tile is TileCableBus) { -// val p2p = (tile.getPart(face) as? PartP2PTunnel<*>) ?: return -// val icon: IIcon = p2p.getItemStack().getIconIndex() ?: return -// val tessellator = Tessellator.instance -// gui.bindTexture(MODID, "textures/gui/advanced_memory_card.png") -// gui.mc.renderEngine.bindTexture(gui.mc.renderEngine.getResourceLocation(0)) -// GL11.glPushAttrib(GL11.GL_BLEND or GL11.GL_TEXTURE_2D or GL11.GL_COLOR) -// GL11.glEnable(GL11.GL_BLEND) -// GL11.glEnable(GL11.GL_TEXTURE_2D) -// GL11.glColor3f(255f, 255f, 255f) -// OpenGlHelper.glBlendFunc(770, 771, 1, 0) -// tessellator.startDrawingQuads() -// tessellator.addVertexWithUV(x.toDouble(), y + rowHeight.toDouble(), 0.0, icon.minU.toDouble(), icon.maxV.toDouble()) -// tessellator.addVertexWithUV(x + rowWidth.toDouble(), y + rowHeight.toDouble(), 0.0, icon.maxU.toDouble(), icon.maxV.toDouble()) -// tessellator.addVertexWithUV(x + rowWidth.toDouble(), y.toDouble(), 0.0, icon.maxU.toDouble(), icon.minV.toDouble()) -// tessellator.addVertexWithUV(x.toDouble(), y.toDouble(), 0.0, icon.minU.toDouble(), icon.minV.toDouble()) -// tessellator.draw() -// GL11.glPopAttrib() -// } -// } -} - -fun getExtraInfo(world: Int, posX: Int, poxY: Int, posZ: Int, face: ForgeDirection): String { - val tile = DimensionManager.getWorld(world)?.getTileEntity(posX, poxY, posZ) - if (tile is TileCableBus) { - val used = ((tile.getPart(face) as? PartP2PTunnelME)?.externalFacingNode as? GridNode)?.usedChannels() - if (used != null) { - return I18n.format("gui.advanced_memory_card.extra.channel", used) - } + private fun drawIcon(gui: GuiAdvancedMemoryCard, icon: IIcon, overlay: IIcon, x: Int, y: Int) { + val tessellator = Tessellator.instance + gui.mc.renderEngine.bindTexture(gui.mc.renderEngine.getResourceLocation(0)) + GL11.glPushAttrib(GL11.GL_BLEND or GL11.GL_TEXTURE_2D or GL11.GL_COLOR) + GL11.glEnable(GL11.GL_BLEND) + GL11.glEnable(GL11.GL_TEXTURE_2D) + GL11.glColor3f(255f, 255f, 255f) + OpenGlHelper.glBlendFunc(770, 771, 1, 0) + drawTexturedQuad(tessellator, x.toDouble() + 1, y.toDouble() + 1, x + 15.0, y + 15.0, icon.minU.toDouble(), icon.minV.toDouble(), icon.maxU.toDouble(), icon.maxV.toDouble()) + drawTexturedQuad(tessellator, x.toDouble(), y.toDouble(), x + 16.0, y + 16.0, overlay.minU.toDouble(), overlay.minV.toDouble(), overlay.maxU.toDouble(), overlay.maxV.toDouble()) + GL11.glPopAttrib() } - return I18n.format("gui.advanced_memory_card.extra.none") } diff --git a/src/main/resources/assets/betterp2p/lang/en_US.lang b/src/main/resources/assets/betterp2p/lang/en_US.lang index 67d26a6..25a11ed 100644 --- a/src/main/resources/assets/betterp2p/lang/en_US.lang +++ b/src/main/resources/assets/betterp2p/lang/en_US.lang @@ -1,9 +1,10 @@ item.advanced_memory_card.name=Advanced Memory Card -item.advanced_memory_card.selected=Frequency: {} -item.advanced_memory_card.not_selected=No Frequency +item.advanced_memory_card.selected=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.pos=Pos: %d, %d, %d +gui.advanced_memory_card.side=Side: %s +gui.advanced_memory_card.dim=Dim: %d gui.advanced_memory_card.name=Name: %s gui.advanced_memory_card.sortinfo1=Sorting tags gui.advanced_memory_card.sortinfo2=Show Input P2Ps only @@ -12,7 +13,6 @@ gui.advanced_memory_card.sortinfo4=Show Bound P2Ps only gui.advanced_memory_card.sortinfo5=Show Unbound P2Ps only gui.advanced_memory_card.sortinfo6=Tags are space separated and are combined w/ the AND operator. gui.advanced_memory_card.extra.channel=Channels used: %s -gui.advanced_memory_card.extra.none=No Extra Info 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 @@ -26,3 +26,8 @@ gui.advanced_memory_card.gui_scale.small=Small gui.advanced_memory_card.gui_scale.normal=Standard gui.advanced_memory_card.gui_scale.large=Large gui.advanced_memory_card.gui_scale.dynamic=Automatic +gui.advanced_memory_card.p2p_status.bound=Bound +gui.advanced_memory_card.p2p_status.unbound=Unbound +gui.advanced_memory_card.p2p_status.input=Input +gui.advanced_memory_card.p2p_status.output=Output +gui.advanced_memory_card.p2p_status.offline=Offline diff --git a/src/main/resources/assets/betterp2p/lang/zh_CN.lang b/src/main/resources/assets/betterp2p/lang/zh_CN.lang index c24d7f9..90c1e7e 100644 --- a/src/main/resources/assets/betterp2p/lang/zh_CN.lang +++ b/src/main/resources/assets/betterp2p/lang/zh_CN.lang @@ -1,10 +1,18 @@ item.advanced_memory_card.name=高级内存卡 -item.advanced_memory_card.selected=频率: {} -item.advanced_memory_card.not_selected=无内容 +item.advanced_memory_card.selected=频率: gui.advanced_memory_card.select=选择 gui.advanced_memory_card.bind=绑定 -gui.advanced_memory_card.pos=位置: %d, %d, %d 朝向: %s +gui.advanced_memory_card.pos=位置: %d, %d, %d +gui.advanced_memory_card.side=朝向: %s +gui.advanced_memory_card.dim=Dim: %d gui.advanced_memory_card.name=名称: %s +gui.advanced_memory_card.sortinfo1=Sorting tags +gui.advanced_memory_card.sortinfo2=Show Input P2Ps only +gui.advanced_memory_card.sortinfo3=Show Output P2Ps only +gui.advanced_memory_card.sortinfo4=Show Bound P2Ps only +gui.advanced_memory_card.sortinfo5=Show Unbound P2Ps only +gui.advanced_memory_card.sortinfo6=Tags are space separated and are combined w/ the AND operator. +gui.advanced_memory_card.extra.channel=Channels used: %s gui.advanced_memory_card.mode.input=模式:绑定输入 gui.advanced_memory_card.mode.output=模式:绑定输出 gui.advanced_memory_card.mode.copy=模式:复制输出 @@ -13,7 +21,13 @@ 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=效果: +gui.advanced_memory_card.gui_scale.resize=Resize gui.advanced_memory_card.gui_scale.small=小 gui.advanced_memory_card.gui_scale.normal=中 gui.advanced_memory_card.gui_scale.large=大 gui.advanced_memory_card.gui_scale.dynamic=自动 +gui.advanced_memory_card.p2p_status.bound=Bound +gui.advanced_memory_card.p2p_status.unbound=Unbound +gui.advanced_memory_card.p2p_status.input=输入 +gui.advanced_memory_card.p2p_status.output=输出 +gui.advanced_memory_card.p2p_status.offline=设备关闭 diff --git a/src/main/resources/assets/betterp2p/textures/gui/advanced_memory_card.png b/src/main/resources/assets/betterp2p/textures/gui/advanced_memory_card.png index 13b64b7..fb0e23c 100644 Binary files a/src/main/resources/assets/betterp2p/textures/gui/advanced_memory_card.png and b/src/main/resources/assets/betterp2p/textures/gui/advanced_memory_card.png differ