From e3649a3887cad1e360b3b87e361584d04d1ac7a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Thu, 11 Sep 2014 16:19:36 +0200 Subject: [PATCH] Tweaked and cleaned up slot highlighting a bit, also made it available in robot GUI. --- .../oc/client/gui/DynamicGuiContainer.scala | 34 +++++++++++++---- .../scala/li/cil/oc/client/gui/Robot.scala | 37 +++++-------------- .../li/cil/oc/client/gui/RobotAssembler.scala | 3 ++ .../oc/common/container/Disassembler.scala | 2 +- .../container/DynamicComponentSlot.scala | 3 +- .../li/cil/oc/common/container/Robot.scala | 2 +- .../oc/common/container/RobotAssembler.scala | 2 +- .../cil/oc/common/container/ServerRack.scala | 8 ++-- .../container/StaticComponentSlot.scala | 3 +- 9 files changed, 50 insertions(+), 44 deletions(-) diff --git a/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala b/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala index d6a2298e8..fa00686e3 100644 --- a/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala +++ b/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala @@ -19,13 +19,13 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai protected var hoveredStackNEI: Option[ItemStack] = None - override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) { + override protected def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) { fontRenderer.drawString( StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 0x404040) } - override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) { + override protected def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) { GL11.glColor4f(1, 1, 1, 1) mc.renderEngine.bindTexture(Textures.guiBackground) drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize) @@ -39,9 +39,12 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai super.drawScreen(mouseX, mouseY, dt) } - override def drawSlotInventory(slot: Slot) { + override protected def drawSlotInventory(slot: Slot) { slot match { - case component: ComponentSlot if component.tier == common.Tier.None || component.slot == common.Slot.None => // Ignore. + case component: ComponentSlot if component.slot == common.Slot.None || component.tier == common.Tier.None => + if (!slot.getHasStack && slot.xDisplayPosition >= 0 && slot.yDisplayPosition >= 0 && component.tierIcon != null) { + drawDisabledSlot(component) + } case _ => if (!isInPlayerInventory(slot)) { GL11.glDisable(GL11.GL_DEPTH_TEST) @@ -71,10 +74,10 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai case Some(hovered) => val hoveredIsInPlayerInventory = isInPlayerInventory(hovered) (currentIsInPlayerInventory != hoveredIsInPlayerInventory) && - ((currentIsInPlayerInventory && slot.getHasStack && hovered.isItemValid(slot.getStack)) || - (hoveredIsInPlayerInventory && hovered.getHasStack && slot.isItemValid(hovered.getStack))) + ((currentIsInPlayerInventory && slot.getHasStack && isSelectiveSlot(hovered) && hovered.isItemValid(slot.getStack)) || + (hoveredIsInPlayerInventory && hovered.getHasStack && isSelectiveSlot(slot) && slot.isItemValid(hovered.getStack))) case _ => hoveredStackNEI match { - case Some(stack) => !currentIsInPlayerInventory && slot.isItemValid(stack) + case Some(stack) => !currentIsInPlayerInventory && isSelectiveSlot(slot) && slot.isItemValid(stack) case _ => false } } @@ -89,7 +92,22 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai } } - private def drawSlotBackground(x: Int, y: Int) { + private def isSelectiveSlot(slot: Slot) = slot match { + case component: ComponentSlot => component.slot != common.Slot.Any && component.slot != common.Slot.Tool + case _ => false + } + + protected def drawDisabledSlot(slot: ComponentSlot) { + GL11.glColor4f(1, 1, 1, 1) + mc.getTextureManager.bindTexture(TextureMap.locationItemsTexture) + GL11.glDisable(GL11.GL_DEPTH_TEST) + GL11.glDisable(GL11.GL_LIGHTING) + drawTexturedModelRectFromIcon(slot.xDisplayPosition, slot.yDisplayPosition, slot.tierIcon, 16, 16) + GL11.glEnable(GL11.GL_LIGHTING) + GL11.glEnable(GL11.GL_DEPTH_TEST) + } + + protected def drawSlotBackground(x: Int, y: Int) { GL11.glColor4f(1, 1, 1, 1) mc.renderEngine.bindTexture(Textures.guiSlot) val t = Tessellator.instance diff --git a/src/main/scala/li/cil/oc/client/gui/Robot.scala b/src/main/scala/li/cil/oc/client/gui/Robot.scala index 54fa5b444..0e094e9c3 100644 --- a/src/main/scala/li/cil/oc/client/gui/Robot.scala +++ b/src/main/scala/li/cil/oc/client/gui/Robot.scala @@ -6,21 +6,18 @@ import li.cil.oc.client.gui.widget.ProgressBar import li.cil.oc.client.renderer.TextBufferRenderCache import li.cil.oc.client.renderer.gui.BufferRenderer import li.cil.oc.client.{Textures, PacketSender => ClientPacketSender} -import li.cil.oc.common.container.StaticComponentSlot import li.cil.oc.common.{container, tileentity} import li.cil.oc.server.driver import li.cil.oc.util.RenderState -import li.cil.oc.{Settings, Localization, api} +import li.cil.oc.{Localization, Settings, api} import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiButton import net.minecraft.client.renderer.Tessellator -import net.minecraft.client.renderer.texture.TextureMap import net.minecraft.entity.player.InventoryPlayer -import net.minecraft.inventory.Slot import org.lwjgl.input.{Keyboard, Mouse} import org.lwjgl.opengl.GL11 -class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) extends CustomGuiContainer(new container.Robot(playerInventory, robot)) with TextBuffer { +class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) extends DynamicGuiContainer(new container.Robot(playerInventory, robot)) with TextBuffer { override protected val buffer = robot.components.collect { case Some(buffer: api.component.TextBuffer) => buffer }.headOption.orNull @@ -97,23 +94,6 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten add(buttonList, scrollButton) } - override def drawSlotInventory(slot: Slot) { - RenderState.makeItBlend() - super.drawSlotInventory(slot) - GL11.glColor3f(1, 1, 1) - GL11.glDisable(GL11.GL_BLEND) - if (!slot.getHasStack) slot match { - case component: StaticComponentSlot if component.tierIcon != null => - mc.getTextureManager.bindTexture(TextureMap.locationItemsTexture) - GL11.glDisable(GL11.GL_DEPTH_TEST) - GL11.glDisable(GL11.GL_LIGHTING) - drawTexturedModelRectFromIcon(slot.xDisplayPosition, slot.yDisplayPosition, component.tierIcon, 16, 16) - GL11.glEnable(GL11.GL_LIGHTING) - GL11.glEnable(GL11.GL_DEPTH_TEST) - case _ => - } - } - override def drawBuffer() { if (buffer != null) { GL11.glTranslatef(bufferX, bufferY, 0) @@ -138,7 +118,7 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten } } - protected override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) { + override protected def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) { drawBufferLayer() GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS) // Me lazy... prevents NEI render glitch. if (isPointInRegion(power.x, power.y, power.width, power.height, mouseX, mouseY)) { @@ -158,7 +138,7 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten GL11.glPopAttrib() } - override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) { + override protected def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) { GL11.glColor3f(1, 1, 1) // Required under Linux. if (buffer != null) mc.renderEngine.bindTexture(Textures.guiRobot) else mc.renderEngine.bindTexture(Textures.guiRobotNoScreen) @@ -170,7 +150,10 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten } } - protected override def keyTyped(char: Char, code: Int) { + // No custom slots, we just extend DynamicGuiContainer for the highlighting. + override protected def drawSlotBackground(x: Int, y: Int) {} + + override protected def keyTyped(char: Char, code: Int) { if (code == Keyboard.KEY_ESCAPE) { super.keyTyped(char, code) } @@ -184,14 +167,14 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten } } - override def mouseMovedOrUp(mouseX: Int, mouseY: Int, button: Int) { + override protected def mouseMovedOrUp(mouseX: Int, mouseY: Int, button: Int) { super.mouseMovedOrUp(mouseX, mouseY, button) if (button == 0) { isDragging = false } } - override def mouseClickMove(mouseX: Int, mouseY: Int, lastButtonClicked: Int, timeSinceMouseClick: Long) { + override protected def mouseClickMove(mouseX: Int, mouseY: Int, lastButtonClicked: Int, timeSinceMouseClick: Long) { super.mouseClickMove(mouseX, mouseY, lastButtonClicked, timeSinceMouseClick) if (isDragging) { scrollMouse(mouseY) diff --git a/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala b/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala index 32b944ea4..9edafef3f 100644 --- a/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala +++ b/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala @@ -5,6 +5,7 @@ import java.util import li.cil.oc.Localization import li.cil.oc.client.gui.widget.ProgressBar import li.cil.oc.client.{Textures, PacketSender => ClientPacketSender} +import li.cil.oc.common.container.ComponentSlot import li.cil.oc.common.template.AssemblerTemplates import li.cil.oc.common.{container, tileentity} import net.minecraft.client.gui.GuiButton @@ -97,5 +98,7 @@ class RobotAssembler(playerInventory: InventoryPlayer, val assembler: tileentity drawWidgets() } + override protected def drawDisabledSlot(slot: ComponentSlot) {} + override def doesGuiPauseGame = false } \ No newline at end of file diff --git a/src/main/scala/li/cil/oc/common/container/Disassembler.scala b/src/main/scala/li/cil/oc/common/container/Disassembler.scala index fd8de4b40..d19765760 100644 --- a/src/main/scala/li/cil/oc/common/container/Disassembler.scala +++ b/src/main/scala/li/cil/oc/common/container/Disassembler.scala @@ -6,7 +6,7 @@ import li.cil.oc.util.SideTracker import net.minecraft.entity.player.InventoryPlayer class Disassembler(playerInventory: InventoryPlayer, disassembler: tileentity.Disassembler) extends Player(playerInventory, disassembler) { - addSlotToContainer(80, 35) + addSlotToContainer(80, 35, "ocitem") addPlayerInventorySlots(8, 84) var disassemblyProgress = 0.0 diff --git a/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala b/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala index 415a87766..068a963ec 100644 --- a/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala +++ b/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala @@ -26,7 +26,8 @@ class DynamicComponentSlot(val container: Player, inventory: IInventory, index: override def getSlotStackLimit = slot match { - case common.Slot.Tool | common.Slot.None => super.getSlotStackLimit + case common.Slot.Tool | common.Slot.Any => super.getSlotStackLimit + case common.Slot.None => 0 case _ => 1 } diff --git a/src/main/scala/li/cil/oc/common/container/Robot.scala b/src/main/scala/li/cil/oc/common/container/Robot.scala index 180a09088..d0a580db8 100644 --- a/src/main/scala/li/cil/oc/common/container/Robot.scala +++ b/src/main/scala/li/cil/oc/common/container/Robot.scala @@ -76,7 +76,7 @@ class Robot(playerInventory: InventoryPlayer, robot: tileentity.Robot) extends P override def canInteractWith(player: EntityPlayer) = super.canInteractWith(player) && robot.canInteract(player.getCommandSenderName) - class InventorySlot(container: Player, inventory: IInventory, index: Int, x: Int, y: Int) extends StaticComponentSlot(container, inventory, index, x, y, common.Slot.None, common.Tier.Any) { + class InventorySlot(container: Player, inventory: IInventory, index: Int, x: Int, y: Int) extends StaticComponentSlot(container, inventory, index, x, y, common.Slot.Any, common.Tier.Any) { def isValid = robot.isInventorySlot(getSlotIndex) @SideOnly(Side.CLIENT) diff --git a/src/main/scala/li/cil/oc/common/container/RobotAssembler.scala b/src/main/scala/li/cil/oc/common/container/RobotAssembler.scala index d2dad74b2..075b9a1e6 100644 --- a/src/main/scala/li/cil/oc/common/container/RobotAssembler.scala +++ b/src/main/scala/li/cil/oc/common/container/RobotAssembler.scala @@ -13,7 +13,7 @@ class RobotAssembler(playerInventory: InventoryPlayer, val assembler: tileentity // Computer case. { val index = inventorySlots.size - addSlotToContainer(new StaticComponentSlot(this, otherInventory, index, 12, 12, common.Slot.Any, common.Tier.Any) { + addSlotToContainer(new StaticComponentSlot(this, otherInventory, index, 12, 12, "template", common.Tier.Any) { @SideOnly(Side.CLIENT) override def func_111238_b() = !isAssembling && super.func_111238_b() diff --git a/src/main/scala/li/cil/oc/common/container/ServerRack.scala b/src/main/scala/li/cil/oc/common/container/ServerRack.scala index 3608533ef..b354d34e5 100644 --- a/src/main/scala/li/cil/oc/common/container/ServerRack.scala +++ b/src/main/scala/li/cil/oc/common/container/ServerRack.scala @@ -6,10 +6,10 @@ import li.cil.oc.util.SideTracker import net.minecraft.entity.player.InventoryPlayer class ServerRack(playerInventory: InventoryPlayer, rack: tileentity.ServerRack) extends Player(playerInventory, rack) { - addSlotToContainer(106, 8) - addSlotToContainer(106, 26) - addSlotToContainer(106, 44) - addSlotToContainer(106, 62) + addSlotToContainer(106, 8, "server") + addSlotToContainer(106, 26, "server") + addSlotToContainer(106, 44, "server") + addSlotToContainer(106, 62, "server") addPlayerInventorySlots(8, 84) var lastSentSwitchMode = !rack.internalSwitch diff --git a/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala b/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala index f0d5774ea..a629061a0 100644 --- a/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala +++ b/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala @@ -11,7 +11,8 @@ class StaticComponentSlot(val container: Player, inventory: IInventory, index: I override def getSlotStackLimit = slot match { - case common.Slot.Tool | common.Slot.None => super.getSlotStackLimit + case common.Slot.Tool | common.Slot.Any => super.getSlotStackLimit + case common.Slot.None => 0 case _ => 1 } }