mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
Inventory scrolling robot GUI.
Limiting maximum inventory space in robots (regardless of number of upgrades) to 64.
This commit is contained in:
parent
dd28370487
commit
68b9cc17c4
@ -1,8 +1,8 @@
|
||||
package li.cil.oc.client
|
||||
|
||||
import li.cil.oc.common.tileentity._
|
||||
import li.cil.oc.common.tileentity.traits.{Computer, TextBuffer}
|
||||
import li.cil.oc.common.{CompressedPacketBuilder, PacketBuilder, PacketType, component}
|
||||
import li.cil.oc.common.tileentity.traits.Computer
|
||||
import li.cil.oc.common.{CompressedPacketBuilder, PacketBuilder, PacketType}
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
|
||||
|
@ -17,6 +17,8 @@ class ImageButton(id: Int, x: Int, y: Int, w: Int, h: Int,
|
||||
|
||||
var toggled = false
|
||||
|
||||
var hoverOverride = false
|
||||
|
||||
override def drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) {
|
||||
if (drawButton) {
|
||||
mc.renderEngine.bindTexture(image)
|
||||
@ -30,7 +32,7 @@ class ImageButton(id: Int, x: Int, y: Int, w: Int, h: Int,
|
||||
|
||||
val u0 = if (toggled) 0.5 else 0
|
||||
val u1 = u0 + (if (canToggle) 0.5 else 1)
|
||||
val v0 = if (getHoverState(field_82253_i) == 2) 0.5 else 0
|
||||
val v0 = if (hoverOverride || getHoverState(field_82253_i) == 2) 0.5 else 0
|
||||
val v1 = v0 + 0.5
|
||||
|
||||
val t = Tessellator.instance
|
||||
@ -44,7 +46,7 @@ class ImageButton(id: Int, x: Int, y: Int, w: Int, h: Int,
|
||||
if (displayString != null) {
|
||||
val color =
|
||||
if (!enabled) textDisabledColor
|
||||
else if (field_82253_i) textHoverColor
|
||||
else if (hoverOverride || field_82253_i) textHoverColor
|
||||
else textColor
|
||||
drawCenteredString(mc.fontRenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, color)
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import net.minecraft.client.renderer.texture.TextureMap
|
||||
import net.minecraft.entity.player.InventoryPlayer
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.util.StatCollector
|
||||
import org.lwjgl.input.Keyboard
|
||||
import org.lwjgl.input.{Mouse, Keyboard}
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) extends CustomGuiContainer(new container.Robot(playerInventory, robot)) with TextBuffer {
|
||||
@ -36,13 +36,24 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
|
||||
|
||||
// Scroll offset for robot inventory.
|
||||
private var inventoryOffset = 0
|
||||
private var isDragging = false
|
||||
|
||||
private def canScroll = robot.inventorySize > 16
|
||||
private def maxOffset = robot.inventorySize / 4 - 4
|
||||
|
||||
private val slotSize = 18
|
||||
|
||||
private val bufferWidth = 242.0
|
||||
private val bufferHeight = 128.0
|
||||
private val bufferMargin = BufferRenderer.innerMargin
|
||||
|
||||
private val inventoryX = 168
|
||||
private val inventoryY = 140
|
||||
private val inventoryX = 169
|
||||
private val inventoryY = 141
|
||||
|
||||
private val scrollX = inventoryX + slotSize * 4 + 2
|
||||
private val scrollY = inventoryY
|
||||
private val scrollWidth = 8
|
||||
private val scrollHeight = 94
|
||||
|
||||
private val powerX = 26
|
||||
private val powerY = 142
|
||||
@ -64,14 +75,18 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
|
||||
|
||||
override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) {
|
||||
powerButton.toggled = robot.isRunning
|
||||
scrollButton.enabled = robot.inventorySize > 16
|
||||
scrollButton.enabled = canScroll
|
||||
scrollButton.hoverOverride = isDragging
|
||||
if (robot.inventorySize < 16 + inventoryOffset * 4) {
|
||||
scrollTo(0)
|
||||
}
|
||||
super.drawScreen(mouseX, mouseY, dt)
|
||||
}
|
||||
|
||||
override def initGui() {
|
||||
super.initGui()
|
||||
powerButton = new ImageButton(0, guiLeft + 5, guiTop + 139, 18, 18, Textures.guiButtonPower, canToggle = true)
|
||||
scrollButton = new ImageButton(1, guiLeft + 244, guiTop + 142, 6, 13, Textures.guiButtonScroll)
|
||||
scrollButton = new ImageButton(1, guiLeft + scrollX + 1, guiTop + scrollY + 1, 6, 13, Textures.guiButtonScroll)
|
||||
add(buttonList, powerButton)
|
||||
add(buttonList, scrollButton)
|
||||
}
|
||||
@ -149,6 +164,80 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
|
||||
}
|
||||
}
|
||||
|
||||
override protected def mouseClicked(mouseX: Int, mouseY: Int, button: Int) {
|
||||
super.mouseClicked(mouseX, mouseY, button)
|
||||
if (canScroll && button == 0 && isCoordinateOverScrollBar(mouseX - guiLeft, mouseY - guiTop)) {
|
||||
isDragging = true
|
||||
scrollMouse(mouseY)
|
||||
}
|
||||
}
|
||||
|
||||
override 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) {
|
||||
super.mouseClickMove(mouseX, mouseY, lastButtonClicked, timeSinceMouseClick)
|
||||
if (isDragging) {
|
||||
scrollMouse(mouseY)
|
||||
}
|
||||
}
|
||||
|
||||
private def scrollMouse(mouseY: Int) {
|
||||
scrollTo(math.round((mouseY - guiTop - scrollY + 1 - 6.5) * maxOffset / (scrollHeight - 13.0)).toInt)
|
||||
}
|
||||
|
||||
override def handleMouseInput() {
|
||||
super.handleMouseInput()
|
||||
if (Mouse.hasWheel && Mouse.getEventDWheel != 0) {
|
||||
val mouseX = Mouse.getEventX * width / mc.displayWidth - guiLeft
|
||||
val mouseY = height - Mouse.getEventY * height / mc.displayHeight - 1 - guiTop
|
||||
if (isCoordinateOverInventory(mouseX, mouseY) || isCoordinateOverScrollBar(mouseX, mouseY)) {
|
||||
if (math.signum(Mouse.getEventDWheel) < 0) scrollDown()
|
||||
else scrollUp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def isCoordinateOverInventory(x: Int, y: Int) =
|
||||
x >= inventoryX && x < inventoryX + slotSize * 4 &&
|
||||
y >= inventoryY && y < inventoryY + slotSize * 4
|
||||
|
||||
private def isCoordinateOverScrollBar(x: Int, y: Int) =
|
||||
x > scrollX && x < scrollX + scrollWidth &&
|
||||
y >= scrollY && y < scrollY + scrollHeight
|
||||
|
||||
private def scrollUp() = scrollTo(inventoryOffset - 1)
|
||||
|
||||
private def scrollDown() = scrollTo(inventoryOffset + 1)
|
||||
|
||||
private def scrollTo(row: Int) {
|
||||
inventoryOffset = math.max(0, math.min(maxOffset, row))
|
||||
for (index <- 4 until 68) {
|
||||
val slot = inventorySlots.getSlot(index)
|
||||
val displayIndex = index - inventoryOffset * 4 - 4
|
||||
if (displayIndex >= 0 && displayIndex < 16) {
|
||||
slot.xDisplayPosition = 1 + inventoryX + (displayIndex % 4) * slotSize
|
||||
slot.yDisplayPosition = 1 + inventoryY + (displayIndex / 4) * slotSize
|
||||
}
|
||||
else {
|
||||
// Hide the rest!
|
||||
slot.xDisplayPosition = -10000
|
||||
slot.yDisplayPosition = -10000
|
||||
}
|
||||
}
|
||||
val yMin = guiTop + scrollY + 1
|
||||
if (maxOffset > 0) {
|
||||
scrollButton.yPosition = yMin + (scrollHeight - 15) * inventoryOffset / maxOffset
|
||||
}
|
||||
else {
|
||||
scrollButton.yPosition = yMin
|
||||
}
|
||||
}
|
||||
|
||||
override protected def changeSize(w: Double, h: Double) = {
|
||||
val bw = w * MonospaceFontRenderer.fontWidth
|
||||
val bh = h * MonospaceFontRenderer.fontHeight
|
||||
@ -158,21 +247,23 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten
|
||||
}
|
||||
|
||||
private def drawSelection() {
|
||||
RenderState.makeItBlend()
|
||||
Minecraft.getMinecraft.renderEngine.bindTexture(Textures.guiRobotSelection)
|
||||
val now = System.currentTimeMillis() / 1000.0
|
||||
val offsetV = ((now - now.toInt) * selectionsStates).toInt * selectionStepV
|
||||
val slot = robot.selectedSlot - robot.actualSlot(0)
|
||||
val x = guiLeft + inventoryX + (slot % 4) * (selectionSize - 2)
|
||||
val y = guiTop + inventoryY + (slot / 4) * (selectionSize - 2)
|
||||
val slot = robot.selectedSlot - robot.actualSlot(0) - inventoryOffset * 4
|
||||
if (slot >= 0 && slot < 16) {
|
||||
RenderState.makeItBlend()
|
||||
Minecraft.getMinecraft.renderEngine.bindTexture(Textures.guiRobotSelection)
|
||||
val now = System.currentTimeMillis() / 1000.0
|
||||
val offsetV = ((now - now.toInt) * selectionsStates).toInt * selectionStepV
|
||||
val x = guiLeft + inventoryX - 1 + (slot % 4) * (selectionSize - 2)
|
||||
val y = guiTop + inventoryY - 1 + (slot / 4) * (selectionSize - 2)
|
||||
|
||||
val t = Tessellator.instance
|
||||
t.startDrawingQuads()
|
||||
t.addVertexWithUV(x, y, zLevel, 0, offsetV)
|
||||
t.addVertexWithUV(x, y + selectionSize, zLevel, 0, offsetV + selectionStepV)
|
||||
t.addVertexWithUV(x + selectionSize, y + selectionSize, zLevel, 1, offsetV + selectionStepV)
|
||||
t.addVertexWithUV(x + selectionSize, y, zLevel, 1, offsetV)
|
||||
t.draw()
|
||||
val t = Tessellator.instance
|
||||
t.startDrawingQuads()
|
||||
t.addVertexWithUV(x, y, zLevel, 0, offsetV)
|
||||
t.addVertexWithUV(x, y + selectionSize, zLevel, 0, offsetV + selectionStepV)
|
||||
t.addVertexWithUV(x + selectionSize, y + selectionSize, zLevel, 1, offsetV + selectionStepV)
|
||||
t.addVertexWithUV(x + selectionSize, y, zLevel, 1, offsetV)
|
||||
t.draw()
|
||||
}
|
||||
}
|
||||
|
||||
private def drawPowerLevel() {
|
||||
|
@ -374,6 +374,8 @@ class TextBuffer(val owner: component.Container) extends ManagedComponent with a
|
||||
object TextBuffer {
|
||||
|
||||
abstract class Proxy {
|
||||
def owner: TextBuffer
|
||||
|
||||
var dirty = false
|
||||
|
||||
var nodeAddress = ""
|
||||
@ -382,17 +384,25 @@ object TextBuffer {
|
||||
|
||||
def onScreenColorChange()
|
||||
|
||||
def onScreenCopy(col: Int, row: Int, w: Int, h: Int, tx: Int, ty: Int)
|
||||
def onScreenCopy(col: Int, row: Int, w: Int, h: Int, tx: Int, ty: Int) {
|
||||
owner.relativeLitArea = -1
|
||||
}
|
||||
|
||||
def onScreenDepthChange(depth: ColorDepth)
|
||||
|
||||
def onScreenFill(col: Int, row: Int, w: Int, h: Int, c: Char)
|
||||
def onScreenFill(col: Int, row: Int, w: Int, h: Int, c: Char) {
|
||||
owner.relativeLitArea = -1
|
||||
}
|
||||
|
||||
def onScreenPaletteChange(index: Int)
|
||||
|
||||
def onScreenResolutionChange(w: Int, h: Int)
|
||||
def onScreenResolutionChange(w: Int, h: Int) {
|
||||
owner.relativeLitArea = -1
|
||||
}
|
||||
|
||||
def onScreenSet(col: Int, row: Int, s: String, vertical: Boolean)
|
||||
def onScreenSet(col: Int, row: Int, s: String, vertical: Boolean) {
|
||||
owner.relativeLitArea = -1
|
||||
}
|
||||
|
||||
def keyDown(character: Char, code: Int, player: EntityPlayer)
|
||||
|
||||
@ -412,19 +422,37 @@ object TextBuffer {
|
||||
class ClientProxy(val owner: TextBuffer) extends Proxy {
|
||||
override def render() = TextBufferRenderCache.render(owner)
|
||||
|
||||
override def onScreenColorChange() = dirty = true
|
||||
override def onScreenColorChange() {
|
||||
dirty = true
|
||||
}
|
||||
|
||||
override def onScreenCopy(col: Int, row: Int, w: Int, h: Int, tx: Int, ty: Int) = dirty = true
|
||||
override def onScreenCopy(col: Int, row: Int, w: Int, h: Int, tx: Int, ty: Int) {
|
||||
super.onScreenCopy(col, row, w, h, tx, ty)
|
||||
dirty = true
|
||||
}
|
||||
|
||||
override def onScreenDepthChange(depth: ColorDepth) = dirty = true
|
||||
override def onScreenDepthChange(depth: ColorDepth) {
|
||||
dirty = true
|
||||
}
|
||||
|
||||
override def onScreenFill(col: Int, row: Int, w: Int, h: Int, c: Char) = dirty = true
|
||||
override def onScreenFill(col: Int, row: Int, w: Int, h: Int, c: Char) {
|
||||
super.onScreenFill(col, row, w, h, c)
|
||||
dirty = true
|
||||
}
|
||||
|
||||
override def onScreenPaletteChange(index: Int) = dirty = true
|
||||
override def onScreenPaletteChange(index: Int) {
|
||||
dirty = true
|
||||
}
|
||||
|
||||
override def onScreenResolutionChange(w: Int, h: Int) = dirty = true
|
||||
override def onScreenResolutionChange(w: Int, h: Int) {
|
||||
super.onScreenResolutionChange(w, h)
|
||||
dirty = true
|
||||
}
|
||||
|
||||
override def onScreenSet(col: Int, row: Int, s: String, vertical: Boolean) = dirty = true
|
||||
override def onScreenSet(col: Int, row: Int, s: String, vertical: Boolean) {
|
||||
super.onScreenSet(col, row, s, vertical)
|
||||
dirty = true
|
||||
}
|
||||
|
||||
override def keyDown(character: Char, code: Int, player: EntityPlayer) =
|
||||
ClientPacketSender.sendKeyDown(nodeAddress, character, code)
|
||||
@ -448,76 +476,76 @@ object TextBuffer {
|
||||
ClientPacketSender.sendMouseScroll(nodeAddress, x, y, delta)
|
||||
}
|
||||
|
||||
class ServerProxy(val buffer: TextBuffer) extends Proxy {
|
||||
class ServerProxy(val owner: TextBuffer) extends Proxy {
|
||||
override def onScreenColorChange() {
|
||||
buffer.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferColorChange(buffer.node.address, buffer.data.foreground, buffer.data.background, buffer.owner)
|
||||
owner.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferColorChange(owner.node.address, owner.data.foreground, owner.data.background, owner.owner)
|
||||
}
|
||||
|
||||
override def onScreenCopy(col: Int, row: Int, w: Int, h: Int, tx: Int, ty: Int) {
|
||||
buffer.relativeLitArea = -1
|
||||
buffer.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferCopy(buffer.node.address, col, row, w, h, tx, ty, buffer.owner)
|
||||
super.onScreenCopy(col, row, w, h, tx, ty)
|
||||
owner.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferCopy(owner.node.address, col, row, w, h, tx, ty, owner.owner)
|
||||
}
|
||||
|
||||
override def onScreenDepthChange(depth: ColorDepth) {
|
||||
buffer.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferDepthChange(buffer.node.address, depth, buffer.owner)
|
||||
owner.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferDepthChange(owner.node.address, depth, owner.owner)
|
||||
}
|
||||
|
||||
override def onScreenFill(col: Int, row: Int, w: Int, h: Int, c: Char) {
|
||||
buffer.relativeLitArea = -1
|
||||
buffer.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferFill(buffer.node.address, col, row, w, h, c, buffer.owner)
|
||||
super.onScreenFill(col, row, w, h, c)
|
||||
owner.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferFill(owner.node.address, col, row, w, h, c, owner.owner)
|
||||
}
|
||||
|
||||
override def onScreenPaletteChange(index: Int) {
|
||||
buffer.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferPaletteChange(buffer.node.address, index, buffer.getPaletteColor(index), buffer.owner)
|
||||
owner.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferPaletteChange(owner.node.address, index, owner.getPaletteColor(index), owner.owner)
|
||||
}
|
||||
|
||||
override def onScreenResolutionChange(w: Int, h: Int) {
|
||||
buffer.relativeLitArea = -1
|
||||
buffer.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferResolutionChange(buffer.node.address, w, h, buffer.owner)
|
||||
super.onScreenResolutionChange(w, h)
|
||||
owner.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferResolutionChange(owner.node.address, w, h, owner.owner)
|
||||
}
|
||||
|
||||
override def onScreenSet(col: Int, row: Int, s: String, vertical: Boolean) {
|
||||
buffer.relativeLitArea = -1
|
||||
buffer.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferSet(buffer.node.address, col, row, s, vertical, buffer.owner)
|
||||
super.onScreenSet(col, row, s, vertical)
|
||||
owner.owner.markChanged()
|
||||
ServerPacketSender.sendTextBufferSet(owner.node.address, col, row, s, vertical, owner.owner)
|
||||
}
|
||||
|
||||
override def keyDown(character: Char, code: Int, player: EntityPlayer) {
|
||||
buffer.node.sendToVisible("keyboard.keyDown", player, Char.box(character), Int.box(code))
|
||||
owner.node.sendToVisible("keyboard.keyDown", player, Char.box(character), Int.box(code))
|
||||
}
|
||||
|
||||
override def keyUp(character: Char, code: Int, player: EntityPlayer) {
|
||||
buffer.node.sendToVisible("keyboard.keyUp", player, Char.box(character), Int.box(code))
|
||||
owner.node.sendToVisible("keyboard.keyUp", player, Char.box(character), Int.box(code))
|
||||
}
|
||||
|
||||
override def clipboard(value: String, player: EntityPlayer) {
|
||||
buffer.node.sendToVisible("keyboard.clipboard", player, value)
|
||||
owner.node.sendToVisible("keyboard.clipboard", player, value)
|
||||
}
|
||||
|
||||
override def mouseDown(x: Int, y: Int, button: Int, player: EntityPlayer) {
|
||||
if (Settings.get.inputUsername) buffer.node.sendToReachable("computer.checked_signal", player, "touch", Int.box(x), Int.box(y), Int.box(button), player.getCommandSenderName)
|
||||
else buffer.node.sendToReachable("computer.checked_signal", player, "touch", Int.box(x), Int.box(y), Int.box(button))
|
||||
if (Settings.get.inputUsername) owner.node.sendToReachable("computer.checked_signal", player, "touch", Int.box(x), Int.box(y), Int.box(button), player.getCommandSenderName)
|
||||
else owner.node.sendToReachable("computer.checked_signal", player, "touch", Int.box(x), Int.box(y), Int.box(button))
|
||||
}
|
||||
|
||||
override def mouseDrag(x: Int, y: Int, button: Int, player: EntityPlayer) {
|
||||
if (Settings.get.inputUsername) buffer.node.sendToReachable("computer.checked_signal", player, "drag", Int.box(x), Int.box(y), Int.box(button), player.getCommandSenderName)
|
||||
else buffer.node.sendToReachable("computer.checked_signal", player, "drag", Int.box(x), Int.box(y), Int.box(button))
|
||||
if (Settings.get.inputUsername) owner.node.sendToReachable("computer.checked_signal", player, "drag", Int.box(x), Int.box(y), Int.box(button), player.getCommandSenderName)
|
||||
else owner.node.sendToReachable("computer.checked_signal", player, "drag", Int.box(x), Int.box(y), Int.box(button))
|
||||
}
|
||||
|
||||
override def mouseUp(x: Int, y: Int, button: Int, player: EntityPlayer) {
|
||||
if (Settings.get.inputUsername) buffer.node.sendToReachable("computer.checked_signal", player, "drop", Int.box(x), Int.box(y), Int.box(button), player.getCommandSenderName)
|
||||
else buffer.node.sendToReachable("computer.checked_signal", player, "drop", Int.box(x), Int.box(y), Int.box(button))
|
||||
if (Settings.get.inputUsername) owner.node.sendToReachable("computer.checked_signal", player, "drop", Int.box(x), Int.box(y), Int.box(button), player.getCommandSenderName)
|
||||
else owner.node.sendToReachable("computer.checked_signal", player, "drop", Int.box(x), Int.box(y), Int.box(button))
|
||||
}
|
||||
|
||||
override def mouseScroll(x: Int, y: Int, delta: Int, player: EntityPlayer) {
|
||||
if (Settings.get.inputUsername) buffer.node.sendToReachable("computer.checked_signal", player, "scroll", Int.box(x), Int.box(y), Int.box(delta), player.getCommandSenderName)
|
||||
else buffer.node.sendToReachable("computer.checked_signal", player, "scroll", Int.box(x), Int.box(y), Int.box(delta))
|
||||
if (Settings.get.inputUsername) owner.node.sendToReachable("computer.checked_signal", player, "scroll", Int.box(x), Int.box(y), Int.box(delta), player.getCommandSenderName)
|
||||
else owner.node.sendToReachable("computer.checked_signal", player, "scroll", Int.box(x), Int.box(y), Int.box(delta))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package li.cil.oc.common.container
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.common.InventorySlots.Tier
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.inventory.{IInventory, Slot}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.Icon
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
@ -18,6 +18,25 @@ trait ComponentSlot extends Slot {
|
||||
|
||||
def tierIcon: Icon
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
var slotIndex = super.getSlotIndex
|
||||
|
||||
override def getStack = inventory.getStackInSlot(slotIndex)
|
||||
|
||||
override def putStack(stack: ItemStack) {
|
||||
inventory.setInventorySlotContents(slotIndex, stack)
|
||||
onSlotChanged()
|
||||
}
|
||||
|
||||
override def decrStackSize(amount: Int) = inventory.decrStackSize(slotIndex, amount)
|
||||
|
||||
override def isSlotInInventory(inventory: IInventory, slot: Int) = inventory == this.inventory && slot == slotIndex
|
||||
|
||||
override def getSlotIndex = slotIndex
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def func_111238_b() = tier != Tier.None && super.func_111238_b()
|
||||
|
||||
|
@ -2,13 +2,12 @@ package li.cil.oc.common.container
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.common.InventorySlots.{Tier, InventorySlot}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.entity.player.InventoryPlayer
|
||||
import net.minecraft.inventory.Container
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.inventory.{ICrafting, Container, IInventory, Slot}
|
||||
import net.minecraft.item.ItemStack
|
||||
import li.cil.oc.common.InventorySlots.{Tier, InventorySlot}
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
|
||||
abstract class Player(val playerInventory: InventoryPlayer, val otherInventory: IInventory) extends Container {
|
||||
/** Number of player inventory slots to display horizontally. */
|
||||
@ -117,4 +116,11 @@ abstract class Player(val playerInventory: InventoryPlayer, val otherInventory:
|
||||
addSlotToContainer(new Slot(playerInventory, index, x, y))
|
||||
}
|
||||
}
|
||||
|
||||
protected def sendProgressBarUpdate(id: Int, value: Int) {
|
||||
for (entry <- crafters) entry match {
|
||||
case player: ICrafting => player.sendProgressBarUpdate(this, id, value)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
}
|
@ -6,8 +6,8 @@ import li.cil.oc.api
|
||||
import li.cil.oc.client.gui.Icons
|
||||
import li.cil.oc.common.tileentity
|
||||
import li.cil.oc.common.InventorySlots.Tier
|
||||
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
||||
import net.minecraft.entity.player.{EntityPlayer, InventoryPlayer}
|
||||
import net.minecraft.inventory.IInventory
|
||||
|
||||
class Robot(playerInventory: InventoryPlayer, robot: tileentity.Robot) extends Player(playerInventory, robot) {
|
||||
addSlotToContainer(170 + 0 * slotSize, 218, api.driver.Slot.Tool)
|
||||
@ -19,40 +19,53 @@ class Robot(playerInventory: InventoryPlayer, robot: tileentity.Robot) extends P
|
||||
val y = 142 + i * slotSize
|
||||
for (j <- 0 to 3) {
|
||||
val x = 170 + j * slotSize
|
||||
val index = inventorySlots.size
|
||||
addSlotToContainer(new StaticComponentSlot(this, otherInventory, index, x, y, api.driver.Slot.None, Tier.Any) {
|
||||
def isValid = robot.isInventorySlot(getSlotIndex)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def func_111238_b() = isValid && super.func_111238_b()
|
||||
|
||||
override def getBackgroundIconIndex = {
|
||||
if (isValid) super.getBackgroundIconIndex
|
||||
else Icons.get(Tier.None)
|
||||
}
|
||||
|
||||
override def getStack = {
|
||||
if (isValid) super.getStack
|
||||
else null
|
||||
}
|
||||
})
|
||||
addSlotToContainer(new InventorySlot(this, otherInventory, inventorySlots.size, x, y))
|
||||
}
|
||||
}
|
||||
for (i <- 16 until 64) {
|
||||
addSlotToContainer(new InventorySlot(this, otherInventory, inventorySlots.size, -10000, -10000))
|
||||
}
|
||||
|
||||
addPlayerInventorySlots(6, 160)
|
||||
|
||||
var lastSentBuffer = Double.NegativeInfinity
|
||||
private var lastSentBuffer = -1
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def updateProgressBar(id: Int, value: Int) {
|
||||
super.updateProgressBar(id, value)
|
||||
if (id == 0) {
|
||||
robot.globalBuffer = value
|
||||
}
|
||||
}
|
||||
|
||||
override def detectAndSendChanges() {
|
||||
super.detectAndSendChanges()
|
||||
if (FMLCommonHandler.instance.getEffectiveSide.isServer) {
|
||||
if (math.abs(robot.globalBuffer - lastSentBuffer) > 1) {
|
||||
lastSentBuffer = robot.globalBuffer
|
||||
ServerPacketSender.sendPowerState(robot)
|
||||
val currentBuffer = robot.globalBuffer.toInt
|
||||
if (currentBuffer != lastSentBuffer) {
|
||||
lastSentBuffer = currentBuffer
|
||||
sendProgressBarUpdate(0, lastSentBuffer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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, api.driver.Slot.None, Tier.Any) {
|
||||
def isValid = robot.isInventorySlot(getSlotIndex)
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def func_111238_b() = isValid && super.func_111238_b()
|
||||
|
||||
override def getBackgroundIconIndex = {
|
||||
if (isValid) super.getBackgroundIconIndex
|
||||
else Icons.get(Tier.None)
|
||||
}
|
||||
|
||||
override def getStack = {
|
||||
if (isValid) super.getStack
|
||||
else null
|
||||
}
|
||||
}
|
||||
}
|
@ -5,8 +5,7 @@ import cpw.mods.fml.common.FMLCommonHandler
|
||||
import li.cil.oc.common.{InventorySlots, tileentity}
|
||||
import li.cil.oc.util.ItemUtils
|
||||
import net.minecraft.entity.player.InventoryPlayer
|
||||
import net.minecraft.inventory.{ICrafting, Slot}
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
import net.minecraft.inventory.Slot
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.common.InventorySlots.Tier
|
||||
import li.cil.oc.client.gui.Icons
|
||||
@ -84,11 +83,4 @@ class RobotAssembler(playerInventory: InventoryPlayer, assembler: tileentity.Rob
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def sendProgressBarUpdate(id: Int, value: Int) {
|
||||
for (entry <- crafters) entry match {
|
||||
case player: ICrafting => player.sendProgressBarUpdate(this, id, value)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
}
|
@ -44,7 +44,7 @@ class Robot(val isRemote: Boolean) extends traits.Computer with traits.PowerInfo
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
val actualInventorySize = 275
|
||||
val actualInventorySize = 83
|
||||
|
||||
var inventorySize = 0
|
||||
|
||||
@ -547,7 +547,7 @@ class Robot(val isRemote: Boolean) extends traits.Computer with traits.PowerInfo
|
||||
|
||||
override def hasRedstoneCard = (containerSlots ++ componentSlots).exists(slot => Option(getStackInSlot(slot)).fold(false)(driver.item.RedstoneCard.worksWith))
|
||||
|
||||
private def computeInventorySize() = math.min(256, (containerSlots ++ componentSlots).foldLeft(0)((acc, slot) => acc + (Option(getStackInSlot(slot)) match {
|
||||
private def computeInventorySize() = math.min(64, (containerSlots ++ componentSlots).foldLeft(0)((acc, slot) => acc + (Option(getStackInSlot(slot)) match {
|
||||
case Some(stack) => Option(Driver.driverFor(stack)) match {
|
||||
case Some(driver: api.driver.Inventory) => driver.inventoryCapacity(stack)
|
||||
case _ => 0
|
||||
|
@ -8,7 +8,7 @@ import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.common.DimensionManager
|
||||
|
||||
object Loot extends Item {
|
||||
override def worksWith(stack: ItemStack) = isOneOf(stack, api.Items.get("lootDisk"))
|
||||
override def worksWith(stack: ItemStack) = isOneOf(stack, api.Items.get("lootDisk"), api.Items.get("openOS"))
|
||||
|
||||
override def createEnvironment(stack: ItemStack, container: component.Container) =
|
||||
createEnvironment(stack, 0, container)
|
||||
|
Loading…
x
Reference in New Issue
Block a user