Tweaked and cleaned up slot highlighting a bit, also made it available in robot GUI.

This commit is contained in:
Florian Nücke 2014-09-11 16:19:36 +02:00
parent f0ebe7b0ee
commit e3649a3887
9 changed files with 50 additions and 44 deletions

View File

@ -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

View File

@ -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)

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -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
}
}