Started work on new rack GUI.

This commit is contained in:
Florian Nücke 2015-11-07 09:11:25 +01:00
parent c674b5b448
commit 7e80b27e70
12 changed files with 237 additions and 74 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -407,7 +407,9 @@ object PacketHandler extends CommonPacketHandler {
def onRackInventory(p: PacketParser) = def onRackInventory(p: PacketParser) =
p.readTileEntity[Rack]() match { p.readTileEntity[Rack]() match {
case Some(t) => case Some(t) =>
for (slot <- 0 until t.getSizeInventory) { val count = p.readInt()
for (_ <- 0 until count) {
val slot = p.readInt()
t.setInventorySlotContents(slot, p.readItemStack()) t.setInventorySlotContents(slot, p.readItemStack())
} }
case _ => // Invalid packet. case _ => // Invalid packet.

View File

@ -35,6 +35,7 @@ object Textures {
val guiPrinterInk = new ResourceLocation(Settings.resourceDomain, "textures/gui/printer_ink.png") val guiPrinterInk = new ResourceLocation(Settings.resourceDomain, "textures/gui/printer_ink.png")
val guiPrinterMaterial = new ResourceLocation(Settings.resourceDomain, "textures/gui/printer_material.png") val guiPrinterMaterial = new ResourceLocation(Settings.resourceDomain, "textures/gui/printer_material.png")
val guiPrinterProgress = new ResourceLocation(Settings.resourceDomain, "textures/gui/printer_progress.png") val guiPrinterProgress = new ResourceLocation(Settings.resourceDomain, "textures/gui/printer_progress.png")
val guiRack = new ResourceLocation(Settings.resourceDomain, "textures/gui/rack.png")
val guiRaid = new ResourceLocation(Settings.resourceDomain, "textures/gui/raid.png") val guiRaid = new ResourceLocation(Settings.resourceDomain, "textures/gui/raid.png")
val guiRange = new ResourceLocation(Settings.resourceDomain, "textures/gui/range.png") val guiRange = new ResourceLocation(Settings.resourceDomain, "textures/gui/range.png")
val guiRobot = new ResourceLocation(Settings.resourceDomain, "textures/gui/robot.png") val guiRobot = new ResourceLocation(Settings.resourceDomain, "textures/gui/robot.png")

View File

@ -10,14 +10,72 @@ import net.minecraft.client.gui.GuiButton
import net.minecraft.client.gui.GuiScreen import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.renderer.Tessellator import net.minecraft.client.renderer.Tessellator
import net.minecraft.entity.player.InventoryPlayer import net.minecraft.entity.player.InventoryPlayer
import net.minecraft.util.ResourceLocation
import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11 import org.lwjgl.opengl.GL11
import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsJava._
class Rack(playerInventory: InventoryPlayer, val rack: tileentity.Rack) extends DynamicGuiContainer(new container.Rack(playerInventory, rack)) { class Rack(playerInventory: InventoryPlayer, val rack: tileentity.Rack) extends DynamicGuiContainer(new container.Rack(playerInventory, rack)) {
// protected var switchButton: ImageButton = _ ySize = 210
//
final val busSlaveBlankUVs = (195, 1, 3, 4)
final val busSlavePresentUVs = (194, 6, 5, 4)
final val busMasterBlankUVs = (195, 14, 3, 5)
final val busMasterPresentUVs = (194, 20, 5, 5)
final val connectorSlaveUVs = (194, 11, 1, 2)
final val hoverSlaveUVs = (196, 11, 3, 2)
final val connectorMasterUVs = (194, 26, 1, 3)
final val hoverMasterUVs = (196, 26, 3, 3)
final val wireSlaveUVs = Array(
(186, 1, 6, 2),
(186, 4, 6, 2),
(186, 7, 6, 2),
(186, 10, 6, 2),
(186, 13, 6, 2)
)
final val wireMasterUVs = Array(
(186, 16, 6, 3),
(186, 20, 6, 3),
(186, 24, 6, 3),
(186, 28, 6, 3),
(186, 32, 6, 3)
)
final val busStart = Array(
(45, 22),
(56, 22),
(67, 22),
(78, 22),
(89, 22)
)
final val busGap = 3
final val connectorStart = Array(
(37, 23),
(37, 43),
(37, 63),
(37, 83)
)
final val connectorGap = 2
final val relayModeUVs = (195, 30, 4, 2)
final val wireRelay = Array(
(50, 104),
(61, 104),
(72, 104),
(83, 104)
)
var switchButton: ImageButton = _
var wireButtons = Array.fill(5)(Array.fill(rack.getSizeInventory * 4)(null: ImageButton))
// protected var powerButtons = new Array[ImageButton](4) // protected var powerButtons = new Array[ImageButton](4)
// //
// protected var sideButtons = new Array[GuiButton](4) // protected var sideButtons = new Array[GuiButton](4)
@ -64,18 +122,18 @@ class Rack(playerInventory: InventoryPlayer, val rack: tileentity.Rack) extends
// ClientPacketSender.sendServerSwitchMode(rack, !rack.internalSwitch) // ClientPacketSender.sendServerSwitchMode(rack, !rack.internalSwitch)
// } // }
// } // }
//
// override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) { override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) {
// for (i <- 0 to 3) { // for (i <- 0 to 3) {
// powerButtons(i).toggled = rack.isRunning(i) // powerButtons(i).toggled = rack.isRunning(i)
// sideButtons(i).displayString = sideName(i) // sideButtons(i).displayString = sideName(i)
// } // }
// switchButton.displayString = if (rack.internalSwitch) Localization.ServerRack.SwitchInternal else Localization.ServerRack.SwitchExternal switchButton.displayString = if (rack.isRelayEnabled) Localization.ServerRack.SwitchInternal else Localization.ServerRack.SwitchExternal
// super.drawScreen(mouseX, mouseY, dt) super.drawScreen(mouseX, mouseY, dt)
// } }
//
// override def initGui() { override def initGui() {
// super.initGui() super.initGui()
// for (i <- 0 to 3) { // for (i <- 0 to 3) {
// powerButtons(i) = new ImageButton(i, guiLeft + 84, guiTop + 7 + i * 18, 18, 18, Textures.guiButtonPower, canToggle = true) // powerButtons(i) = new ImageButton(i, guiLeft + 84, guiTop + 7 + i * 18, 18, 18, Textures.guiButtonPower, canToggle = true)
// add(buttonList, powerButtons(i)) // add(buttonList, powerButtons(i))
@ -88,17 +146,17 @@ class Rack(playerInventory: InventoryPlayer, val rack: tileentity.Rack) extends
// rangeButtons(i) = new ImageButton(8 + i, guiLeft + 8 + i * 48, guiTop + 50, 16, 18, Textures.guiButtonRange, if (i == 0) "-" else "+") // rangeButtons(i) = new ImageButton(8 + i, guiLeft + 8 + i * 48, guiTop + 50, 16, 18, Textures.guiButtonRange, if (i == 0) "-" else "+")
// add(buttonList, rangeButtons(i)) // add(buttonList, rangeButtons(i))
// } // }
// switchButton = new ImageButton(10, guiLeft + 8, guiTop + 17, 64, 18, Textures.guiButtonSwitch, Localization.ServerRack.SwitchExternal, textIndent = 18) switchButton = new ImageButton(0, guiLeft + 101, guiTop + 96, 65, 18, Textures.guiButtonSwitch, Localization.ServerRack.SwitchExternal, textIndent = 18)
// add(buttonList, switchButton) add(buttonList, switchButton)
// } }
//
// override def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) = { override def drawSecondaryForegroundLayer(mouseX: Int, mouseY: Int) = {
// super.drawSecondaryForegroundLayer(mouseX, mouseY) super.drawSecondaryForegroundLayer(mouseX, mouseY)
// GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS) // Prevents NEI render glitch. GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS) // Prevents NEI render glitch.
//
// fontRendererObj.drawString( fontRendererObj.drawString(
// Localization.localizeImmediately(rack.getInventoryName), Localization.localizeImmediately(rack.getInventoryName),
// 8, 6, 0x404040) 8, 6, 0x404040)
// //
// val rangeY = 39 // val rangeY = 39
// fontRendererObj.drawString(Localization.ServerRack.WirelessRange, 8, rangeY, 0x404040) // fontRendererObj.drawString(Localization.ServerRack.WirelessRange, 8, rangeY, 0x404040)
@ -132,6 +190,89 @@ class Rack(playerInventory: InventoryPlayer, val rack: tileentity.Rack) extends
// copiedDrawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj) // copiedDrawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj)
// } // }
// //
// GL11.glPopAttrib()
// } GL11.glColor3f(1, 1, 1)
mc.renderEngine.bindTexture(Textures.guiRack)
if (rack.isRelayEnabled) {
val (left, top, w, h) = relayModeUVs
for ((x, y) <- wireRelay) {
drawRect(x, y, w, h, left, top)
}
}
val (mcx, mcy, mcw, mch) = connectorMasterUVs
val (mbx, mby, mbw, mbh) = busMasterBlankUVs
val (mpx, mpy, mpw, mph) = busMasterPresentUVs
val (scx, scy, scw, sch) = connectorSlaveUVs
val (sbx, sby, sbw, sbh) = busSlaveBlankUVs
val (spx, spy, spw, sph) = busSlavePresentUVs
for (mountable <- 0 until rack.getSizeInventory) {
val presence = inventoryContainer.nodePresence(mountable)
// Draw connectable indicators next to item slots.
val (cx, cy) = connectorStart(mountable)
if (presence(0)) {
drawRect(cx, cy, mcw, mch, mcx, mcy)
}
for (connectable <- 1 until 4) {
if (presence(connectable)) {
drawRect(cx, cy + (mch + connectorGap) + (sch + connectorGap) * (connectable - 1), scw, sch, scx, scy)
}
}
// Draw connection points on buses.
val offset = mountable * (mbh + sbh * 3 + busGap)
for (bus <- 0 until 5) {
val (bx, by) = busStart(bus)
if (presence(0)) {
drawRect(bx - 1, by + offset, mpw, mph, mpx, mpy)
}
else {
drawRect(bx, by + offset, mbw, mbh, mbx, mby)
}
for (connectable <- 0 until 3) {
if (presence(connectable + 1)) {
drawRect(bx - 1, by + offset + mph + sph * connectable, spw, sph, spx, spy)
}
else {
drawRect(bx, by + offset + mbh + sbh * connectable, sbw, sbh, sbx, sby)
}
}
}
// Draw active connections.
}
for (bus <- 0 until 5) {
val x = 122
val y = 20 + bus * 11
fontRendererObj.drawString(
Localization.localizeImmediately("TODO"),
x, y, 0x404040)
}
GL11.glPopAttrib()
}
override def drawSecondaryBackgroundLayer() {
GL11.glColor3f(1, 1, 1) // Required under Linux.
mc.renderEngine.bindTexture(Textures.guiRack)
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize)
}
private def drawRect(x: Int, y: Int, w: Int, h: Int, u: Int, v: Int): Unit = {
val u0 = u / 256f
val v0 = v / 256f
val u1 = u0 + w / 256f
val v1 = v0 + h / 256f
val t = Tessellator.instance
t.startDrawingQuads()
t.addVertexWithUV(x, y, windowZ, u0, v0)
t.addVertexWithUV(x, y + h, windowZ, u0, v1)
t.addVertexWithUV(x + w, y + h, windowZ, u1, v1)
t.addVertexWithUV(x + w, y, windowZ, u1, v0)
t.draw()
}
} }

View File

@ -47,7 +47,7 @@ abstract class PacketBuilder(stream: OutputStream) extends DataOutputStream(stre
} }
} }
def writeNBT(nbt: NBTTagCompound) = CompressedStreamTools.writeCompressed(nbt, this) def writeNBT(nbt: NBTTagCompound) = CompressedStreamTools.write(nbt, this)
def writePacketType(pt: PacketType.Value) = writeByte(pt.id) def writePacketType(pt: PacketType.Value) = writeByte(pt.id)

View File

@ -1,5 +1,6 @@
package li.cil.oc.common package li.cil.oc.common
import java.io.BufferedInputStream
import java.io.DataInputStream import java.io.DataInputStream
import java.io.InputStream import java.io.InputStream
import java.util.zip.GZIPInputStream import java.util.zip.GZIPInputStream
@ -13,6 +14,7 @@ import li.cil.oc.common.block.RobotAfterimage
import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraft.nbt.CompressedStreamTools import net.minecraft.nbt.CompressedStreamTools
import net.minecraft.nbt.NBTSizeTracker
import net.minecraft.world.World import net.minecraft.world.World
import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.common.util.ForgeDirection
@ -36,12 +38,12 @@ abstract class PacketHandler {
} }
/** /**
* Gets the world for the specified dimension. * Gets the world for the specified dimension.
* *
* For clients this returns the client's world if it is the specified * For clients this returns the client's world if it is the specified
* dimension; None otherwise. For the server it returns the world for the * dimension; None otherwise. For the server it returns the world for the
* specified dimension, if such a dimension exists; None otherwise. * specified dimension, if such a dimension exists; None otherwise.
*/ */
protected def world(player: EntityPlayer, dimension: Int): Option[World] protected def world(player: EntityPlayer, dimension: Int): Option[World]
protected def dispatch(p: PacketParser): Unit protected def dispatch(p: PacketParser): Unit
@ -111,7 +113,7 @@ abstract class PacketHandler {
else null else null
} }
def readNBT() = CompressedStreamTools.readCompressed(this) def readNBT() = CompressedStreamTools.read(this)
def readPacketType() = PacketType(readByte()) def readPacketType() = PacketType(readByte())
} }

View File

@ -1,5 +1,6 @@
package li.cil.oc.common.container package li.cil.oc.common.container
import li.cil.oc.api.component.RackMountable
import li.cil.oc.common.Slot import li.cil.oc.common.Slot
import li.cil.oc.common.tileentity import li.cil.oc.common.tileentity
import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.ExtendedNBT._
@ -9,27 +10,35 @@ import net.minecraft.nbt.NBTTagIntArray
import net.minecraftforge.common.util.Constants.NBT import net.minecraftforge.common.util.Constants.NBT
import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.common.util.ForgeDirection
class Rack(playerInventory: InventoryPlayer, rack: tileentity.Rack) extends Player(playerInventory, rack) { class Rack(playerInventory: InventoryPlayer, val rack: tileentity.Rack) extends Player(playerInventory, rack) {
addSlotToContainer(106, 8, Slot.RackMountable) addSlotToContainer(20, 23, Slot.RackMountable)
addSlotToContainer(106, 26, Slot.RackMountable) addSlotToContainer(20, 43, Slot.RackMountable)
addSlotToContainer(106, 44, Slot.RackMountable) addSlotToContainer(20, 63, Slot.RackMountable)
addSlotToContainer(106, 62, Slot.RackMountable) addSlotToContainer(20, 83, Slot.RackMountable)
addPlayerInventorySlots(8, 84) addPlayerInventorySlots(8, 128)
final val MaxConnections = 4
val nodePresence = Array.fill(4)(Array.fill(4)(false))
override def updateCustomData(nbt: NBTTagCompound): Unit = { override def updateCustomData(nbt: NBTTagCompound): Unit = {
super.updateCustomData(nbt) super.updateCustomData(nbt)
nbt.setNewTagList("nodeMapping", rack.nodeMapping.map(sides => toNbt(sides.map { nbt.getTagList("nodeMapping", NBT.TAG_INT_ARRAY).map((sides: NBTTagIntArray) => {
case Some(side) => side.ordinal() sides.func_150302_c().map(side => if (side >= 0) Option(ForgeDirection.getOrientation(side)) else None)
case _ => -1 }).copyToArray(rack.nodeMapping)
}))) nbt.getBooleanArray("nodePresence").grouped(MaxConnections).copyToArray(nodePresence)
nbt.setBoolean("isRelayEnabled", rack.isRelayEnabled) rack.isRelayEnabled = nbt.getBoolean("isRelayEnabled")
} }
override protected def detectCustomDataChanges(nbt: NBTTagCompound): Unit = { override protected def detectCustomDataChanges(nbt: NBTTagCompound): Unit = {
super.detectCustomDataChanges(nbt) super.detectCustomDataChanges(nbt)
nbt.getTagList("nodeMapping", NBT.TAG_INT_ARRAY).map((sides: NBTTagIntArray) => { nbt.setNewTagList("nodeMapping", rack.nodeMapping.map(sides => toNbt(sides.map {
sides.func_150302_c().map(side => if (side >= 0) Option(ForgeDirection.getOrientation(side)) else None) case Some(side) => side.ordinal()
}).copyToArray(rack.nodeMapping) case _ => -1
rack.isRelayEnabled = nbt.getBoolean("isRelayEnabled") })))
nbt.setBooleanArray("nodePresence", (0 until rack.getSizeInventory).flatMap(slot => rack.getMountable(slot) match {
case mountable: RackMountable => (Seq(true) ++ (0 until math.min(MaxConnections - 1, mountable.getConnectableCount)).map(index => mountable.getConnectableAt(index) != null)).padTo(MaxConnections, false)
case _ => Array.fill(MaxConnections)(false)
}).toArray)
nbt.setBoolean("isRelayEnabled", rack.isRelayEnabled)
} }
} }

View File

@ -1,10 +1,7 @@
package li.cil.oc.common.inventory package li.cil.oc.common.inventory
import li.cil.oc.Settings
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound import net.minecraft.nbt.NBTTagCompound
import net.minecraft.nbt.NBTTagList
import net.minecraftforge.common.util.Constants.NBT
trait ItemStackInventory extends Inventory { trait ItemStackInventory extends Inventory {
// The item stack that provides the inventory. // The item stack that provides the inventory.
@ -21,34 +18,20 @@ trait ItemStackInventory extends Inventory {
// Load items from tag. // Load items from tag.
def reinitialize() { def reinitialize() {
if (!container.hasTagCompound) {
container.setTagCompound(new NBTTagCompound())
}
for (i <- items.indices) { for (i <- items.indices) {
updateItems(i, null) updateItems(i, null)
} }
if (container.getTagCompound.hasKey(Settings.namespace + "items")) { if (!container.hasTagCompound) {
val list = container.getTagCompound.getTagList(Settings.namespace + "items", NBT.TAG_COMPOUND) container.setTagCompound(new NBTTagCompound())
for (i <- 0 until (list.tagCount min items.length)) {
val tag = list.getCompoundTagAt(i)
if (!tag.hasNoTags) {
updateItems(i, ItemStack.loadItemStackFromNBT(tag))
}
}
} }
load(container.getTagCompound)
} }
// Write items back to tag. // Write items back to tag.
override def markDirty() { override def markDirty() {
val list = new NBTTagList() if (!container.hasTagCompound) {
for (i <- items.indices) { container.setTagCompound(new NBTTagCompound())
val tag = new NBTTagCompound()
items(i) match {
case Some(stack) => stack.writeToNBT(tag)
case _ =>
}
list.appendTag(tag)
} }
container.getTagCompound.setTag(Settings.namespace + "items", list) save(container.getTagCompound)
} }
} }

View File

@ -202,7 +202,7 @@ class Rack extends traits.PowerAcceptor with traits.Hub with traits.PowerBalance
override def getInventoryStackLimit = 1 override def getInventoryStackLimit = 1
override def isItemValidForSlot(slot: Int, stack: ItemStack): Boolean = (slot, Option(Driver.driverFor(stack, getClass))) match { override def isItemValidForSlot(slot: Int, stack: ItemStack): Boolean = (slot, Option(Driver.driverFor(stack, getClass))) match {
case (0, Some(driver)) => driver.slot(stack) == Slot.RackMountable case (_, Some(driver)) => driver.slot(stack) == Slot.RackMountable
case _ => false case _ => false
} }
@ -218,6 +218,23 @@ class Rack extends traits.PowerAcceptor with traits.Hub with traits.PowerBalance
} }
} }
// ----------------------------------------------------------------------- //
// ComponentInventory
override protected def onItemAdded(slot: Int, stack: ItemStack): Unit = {
// Reset mappings when adding an item.
for (connectable <- 0 until 4) {
nodeMapping(slot)(connectable) = None
}
super.onItemAdded(slot, stack)
}
override protected def connectItemNode(node: Node): Unit = {
// By default create a new network for mountables. They have to
// be wired up manually (mapping is reset in onItemAdded).
api.Network.joinNewNetwork(node)
}
// ----------------------------------------------------------------------- // // ----------------------------------------------------------------------- //
// TileEntity // TileEntity

View File

@ -10,6 +10,7 @@ import li.cil.oc.common.tileentity
import li.cil.oc.server.component import li.cil.oc.server.component
import li.cil.oc.util.ExtendedInventory._ import li.cil.oc.util.ExtendedInventory._
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
object DriverServer extends Item with HostAware { object DriverServer extends Item with HostAware {
override def worksWith(stack: ItemStack): Boolean = isOneOf(stack, override def worksWith(stack: ItemStack): Boolean = isOneOf(stack,
@ -24,4 +25,11 @@ object DriverServer extends Item with HostAware {
} }
override def slot(stack: ItemStack): String = Slot.RackMountable override def slot(stack: ItemStack): String = Slot.RackMountable
override def dataTag(stack: ItemStack): NBTTagCompound = {
if (!stack.hasTagCompound) {
stack.setTagCompound(new NBTTagCompound())
}
stack.getTagCompound
}
} }

View File

@ -115,6 +115,7 @@ object ModOpenComputers extends ModProxy {
api.Driver.add(DriverNetworkCard) api.Driver.add(DriverNetworkCard)
api.Driver.add(DriverKeyboard) api.Driver.add(DriverKeyboard)
api.Driver.add(DriverRedstoneCard) api.Driver.add(DriverRedstoneCard)
api.Driver.add(DriverServer)
api.Driver.add(DriverTablet) api.Driver.add(DriverTablet)
api.Driver.add(DriverWirelessNetworkCard) api.Driver.add(DriverWirelessNetworkCard)

View File

@ -5,12 +5,11 @@ import java.util
import li.cil.oc.OpenComputers import li.cil.oc.OpenComputers
import li.cil.oc.api import li.cil.oc.api
import li.cil.oc.api
import li.cil.oc.api.Machine import li.cil.oc.api.Machine
import li.cil.oc.api.StateAware import li.cil.oc.api.StateAware
import li.cil.oc.api.StateAware.State
import li.cil.oc.api.component.RackBusConnectable import li.cil.oc.api.component.RackBusConnectable
import li.cil.oc.api.internal import li.cil.oc.api.internal
import StateAware.State
import li.cil.oc.api.machine.MachineHost import li.cil.oc.api.machine.MachineHost
import li.cil.oc.api.network.Analyzable import li.cil.oc.api.network.Analyzable
import li.cil.oc.api.network.Environment import li.cil.oc.api.network.Environment
@ -30,7 +29,7 @@ import net.minecraft.nbt.NBTTagCompound
import scala.collection.convert.WrapAsJava._ import scala.collection.convert.WrapAsJava._
class Server(val rack: tileentity.Rack, val slot: Int) extends Environment with MachineHost with ServerInventory with ComponentInventory with Analyzable with internal.Server { class Server(val rack: tileentity.Rack, val slot: Int) extends Environment with MachineHost with ServerInventory with ComponentInventory with Analyzable with internal.Server {
val machine = Machine.create(this) lazy val machine = Machine.create(this)
val node = machine.node val node = machine.node