mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-13 09:18:05 -04:00
Tweaked and cleaned up slot highlighting a bit, also made it available in robot GUI.
This commit is contained in:
parent
f0ebe7b0ee
commit
e3649a3887
@ -19,13 +19,13 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
|
|||||||
|
|
||||||
protected var hoveredStackNEI: Option[ItemStack] = None
|
protected var hoveredStackNEI: Option[ItemStack] = None
|
||||||
|
|
||||||
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) {
|
override protected def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) {
|
||||||
fontRenderer.drawString(
|
fontRenderer.drawString(
|
||||||
StatCollector.translateToLocal("container.inventory"),
|
StatCollector.translateToLocal("container.inventory"),
|
||||||
8, ySize - 96 + 2, 0x404040)
|
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)
|
GL11.glColor4f(1, 1, 1, 1)
|
||||||
mc.renderEngine.bindTexture(Textures.guiBackground)
|
mc.renderEngine.bindTexture(Textures.guiBackground)
|
||||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
|
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
|
||||||
@ -39,9 +39,12 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
|
|||||||
super.drawScreen(mouseX, mouseY, dt)
|
super.drawScreen(mouseX, mouseY, dt)
|
||||||
}
|
}
|
||||||
|
|
||||||
override def drawSlotInventory(slot: Slot) {
|
override protected def drawSlotInventory(slot: Slot) {
|
||||||
slot match {
|
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 _ =>
|
case _ =>
|
||||||
if (!isInPlayerInventory(slot)) {
|
if (!isInPlayerInventory(slot)) {
|
||||||
GL11.glDisable(GL11.GL_DEPTH_TEST)
|
GL11.glDisable(GL11.GL_DEPTH_TEST)
|
||||||
@ -71,10 +74,10 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
|
|||||||
case Some(hovered) =>
|
case Some(hovered) =>
|
||||||
val hoveredIsInPlayerInventory = isInPlayerInventory(hovered)
|
val hoveredIsInPlayerInventory = isInPlayerInventory(hovered)
|
||||||
(currentIsInPlayerInventory != hoveredIsInPlayerInventory) &&
|
(currentIsInPlayerInventory != hoveredIsInPlayerInventory) &&
|
||||||
((currentIsInPlayerInventory && slot.getHasStack && hovered.isItemValid(slot.getStack)) ||
|
((currentIsInPlayerInventory && slot.getHasStack && isSelectiveSlot(hovered) && hovered.isItemValid(slot.getStack)) ||
|
||||||
(hoveredIsInPlayerInventory && hovered.getHasStack && slot.isItemValid(hovered.getStack)))
|
(hoveredIsInPlayerInventory && hovered.getHasStack && isSelectiveSlot(slot) && slot.isItemValid(hovered.getStack)))
|
||||||
case _ => hoveredStackNEI match {
|
case _ => hoveredStackNEI match {
|
||||||
case Some(stack) => !currentIsInPlayerInventory && slot.isItemValid(stack)
|
case Some(stack) => !currentIsInPlayerInventory && isSelectiveSlot(slot) && slot.isItemValid(stack)
|
||||||
case _ => false
|
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)
|
GL11.glColor4f(1, 1, 1, 1)
|
||||||
mc.renderEngine.bindTexture(Textures.guiSlot)
|
mc.renderEngine.bindTexture(Textures.guiSlot)
|
||||||
val t = Tessellator.instance
|
val t = Tessellator.instance
|
||||||
|
@ -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.TextBufferRenderCache
|
||||||
import li.cil.oc.client.renderer.gui.BufferRenderer
|
import li.cil.oc.client.renderer.gui.BufferRenderer
|
||||||
import li.cil.oc.client.{Textures, PacketSender => ClientPacketSender}
|
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.common.{container, tileentity}
|
||||||
import li.cil.oc.server.driver
|
import li.cil.oc.server.driver
|
||||||
import li.cil.oc.util.RenderState
|
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.Minecraft
|
||||||
import net.minecraft.client.gui.GuiButton
|
import net.minecraft.client.gui.GuiButton
|
||||||
import net.minecraft.client.renderer.Tessellator
|
import net.minecraft.client.renderer.Tessellator
|
||||||
import net.minecraft.client.renderer.texture.TextureMap
|
|
||||||
import net.minecraft.entity.player.InventoryPlayer
|
import net.minecraft.entity.player.InventoryPlayer
|
||||||
import net.minecraft.inventory.Slot
|
|
||||||
import org.lwjgl.input.{Keyboard, Mouse}
|
import org.lwjgl.input.{Keyboard, Mouse}
|
||||||
import org.lwjgl.opengl.GL11
|
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 {
|
override protected val buffer = robot.components.collect {
|
||||||
case Some(buffer: api.component.TextBuffer) => buffer
|
case Some(buffer: api.component.TextBuffer) => buffer
|
||||||
}.headOption.orNull
|
}.headOption.orNull
|
||||||
@ -97,23 +94,6 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
|
|||||||
add(buttonList, scrollButton)
|
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() {
|
override def drawBuffer() {
|
||||||
if (buffer != null) {
|
if (buffer != null) {
|
||||||
GL11.glTranslatef(bufferX, bufferY, 0)
|
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()
|
drawBufferLayer()
|
||||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS) // Me lazy... prevents NEI render glitch.
|
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)) {
|
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()
|
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.
|
GL11.glColor3f(1, 1, 1) // Required under Linux.
|
||||||
if (buffer != null) mc.renderEngine.bindTexture(Textures.guiRobot)
|
if (buffer != null) mc.renderEngine.bindTexture(Textures.guiRobot)
|
||||||
else mc.renderEngine.bindTexture(Textures.guiRobotNoScreen)
|
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) {
|
if (code == Keyboard.KEY_ESCAPE) {
|
||||||
super.keyTyped(char, code)
|
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)
|
super.mouseMovedOrUp(mouseX, mouseY, button)
|
||||||
if (button == 0) {
|
if (button == 0) {
|
||||||
isDragging = false
|
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)
|
super.mouseClickMove(mouseX, mouseY, lastButtonClicked, timeSinceMouseClick)
|
||||||
if (isDragging) {
|
if (isDragging) {
|
||||||
scrollMouse(mouseY)
|
scrollMouse(mouseY)
|
||||||
|
@ -5,6 +5,7 @@ import java.util
|
|||||||
import li.cil.oc.Localization
|
import li.cil.oc.Localization
|
||||||
import li.cil.oc.client.gui.widget.ProgressBar
|
import li.cil.oc.client.gui.widget.ProgressBar
|
||||||
import li.cil.oc.client.{Textures, PacketSender => ClientPacketSender}
|
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.template.AssemblerTemplates
|
||||||
import li.cil.oc.common.{container, tileentity}
|
import li.cil.oc.common.{container, tileentity}
|
||||||
import net.minecraft.client.gui.GuiButton
|
import net.minecraft.client.gui.GuiButton
|
||||||
@ -97,5 +98,7 @@ class RobotAssembler(playerInventory: InventoryPlayer, val assembler: tileentity
|
|||||||
drawWidgets()
|
drawWidgets()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override protected def drawDisabledSlot(slot: ComponentSlot) {}
|
||||||
|
|
||||||
override def doesGuiPauseGame = false
|
override def doesGuiPauseGame = false
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ import li.cil.oc.util.SideTracker
|
|||||||
import net.minecraft.entity.player.InventoryPlayer
|
import net.minecraft.entity.player.InventoryPlayer
|
||||||
|
|
||||||
class Disassembler(playerInventory: InventoryPlayer, disassembler: tileentity.Disassembler) extends Player(playerInventory, disassembler) {
|
class Disassembler(playerInventory: InventoryPlayer, disassembler: tileentity.Disassembler) extends Player(playerInventory, disassembler) {
|
||||||
addSlotToContainer(80, 35)
|
addSlotToContainer(80, 35, "ocitem")
|
||||||
addPlayerInventorySlots(8, 84)
|
addPlayerInventorySlots(8, 84)
|
||||||
|
|
||||||
var disassemblyProgress = 0.0
|
var disassemblyProgress = 0.0
|
||||||
|
@ -26,7 +26,8 @@ class DynamicComponentSlot(val container: Player, inventory: IInventory, index:
|
|||||||
|
|
||||||
override def getSlotStackLimit =
|
override def getSlotStackLimit =
|
||||||
slot match {
|
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
|
case _ => 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ class Robot(playerInventory: InventoryPlayer, robot: tileentity.Robot) extends P
|
|||||||
override def canInteractWith(player: EntityPlayer) =
|
override def canInteractWith(player: EntityPlayer) =
|
||||||
super.canInteractWith(player) && robot.canInteract(player.getCommandSenderName)
|
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)
|
def isValid = robot.isInventorySlot(getSlotIndex)
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
|
@ -13,7 +13,7 @@ class RobotAssembler(playerInventory: InventoryPlayer, val assembler: tileentity
|
|||||||
// Computer case.
|
// Computer case.
|
||||||
{
|
{
|
||||||
val index = inventorySlots.size
|
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
|
@SideOnly(Side.CLIENT) override
|
||||||
def func_111238_b() = !isAssembling && super.func_111238_b()
|
def func_111238_b() = !isAssembling && super.func_111238_b()
|
||||||
|
|
||||||
|
@ -6,10 +6,10 @@ import li.cil.oc.util.SideTracker
|
|||||||
import net.minecraft.entity.player.InventoryPlayer
|
import net.minecraft.entity.player.InventoryPlayer
|
||||||
|
|
||||||
class ServerRack(playerInventory: InventoryPlayer, rack: tileentity.ServerRack) extends Player(playerInventory, rack) {
|
class ServerRack(playerInventory: InventoryPlayer, rack: tileentity.ServerRack) extends Player(playerInventory, rack) {
|
||||||
addSlotToContainer(106, 8)
|
addSlotToContainer(106, 8, "server")
|
||||||
addSlotToContainer(106, 26)
|
addSlotToContainer(106, 26, "server")
|
||||||
addSlotToContainer(106, 44)
|
addSlotToContainer(106, 44, "server")
|
||||||
addSlotToContainer(106, 62)
|
addSlotToContainer(106, 62, "server")
|
||||||
addPlayerInventorySlots(8, 84)
|
addPlayerInventorySlots(8, 84)
|
||||||
|
|
||||||
var lastSentSwitchMode = !rack.internalSwitch
|
var lastSentSwitchMode = !rack.internalSwitch
|
||||||
|
@ -11,7 +11,8 @@ class StaticComponentSlot(val container: Player, inventory: IInventory, index: I
|
|||||||
|
|
||||||
override def getSlotStackLimit =
|
override def getSlotStackLimit =
|
||||||
slot match {
|
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
|
case _ => 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user