mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
computer gui
This commit is contained in:
parent
16ec4f6acd
commit
a99f7f0136
@ -1,2 +1,3 @@
|
||||
oc.block.Computer.name=Computer
|
||||
oc.block.Screen.name=Screen
|
||||
oc.block.Screen.name=Screen
|
||||
oc.container.computer=Computer
|
BIN
assets/opencomputers/textures/gui/computer.png
Normal file
BIN
assets/opencomputers/textures/gui/computer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 583 B |
BIN
assets/opencomputers/textures/gui/icon_hdd.png
Normal file
BIN
assets/opencomputers/textures/gui/icon_hdd.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 265 B |
BIN
assets/opencomputers/textures/gui/icon_pci.png
Normal file
BIN
assets/opencomputers/textures/gui/icon_pci.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 218 B |
BIN
assets/opencomputers/textures/gui/icon_psu.png
Normal file
BIN
assets/opencomputers/textures/gui/icon_psu.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 176 B |
BIN
assets/opencomputers/textures/gui/icon_ram.png
Normal file
BIN
assets/opencomputers/textures/gui/icon_ram.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 208 B |
@ -8,32 +8,68 @@ import net.minecraft.client.gui.inventory.GuiContainer
|
||||
import net.minecraft.entity.player.InventoryPlayer
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraft.util.StatCollector
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
|
||||
class GuiComputer(inventory: InventoryPlayer, val tileEntity: TileEntityComputer) extends GuiContainer(new ContainerComputer(inventory, tileEntity)) {
|
||||
val button = new GuiButton(1, 5, 4, "test")
|
||||
private val background = new ResourceLocation("opencomputers", "textures/gui/computer.png")
|
||||
|
||||
private val iconPsu = new ResourceLocation("opencomputers", "textures/gui/icon_psu.png")
|
||||
private val iconPci = new ResourceLocation("opencomputers", "textures/gui/icon_pci.png")
|
||||
private val iconRam = new ResourceLocation("opencomputers", "textures/gui/icon_ram.png")
|
||||
private val iconHdd = new ResourceLocation("opencomputers", "textures/gui/icon_hdd.png")
|
||||
|
||||
private val icons = Array(iconPsu, iconPci, iconPci, iconPci, iconRam, iconRam, iconHdd, iconHdd)
|
||||
|
||||
private var (x, y) = (0, 0)
|
||||
|
||||
override def initGui() = {
|
||||
super.initGui()
|
||||
x = (width - xSize) / 2
|
||||
y = (height - ySize) / 2
|
||||
}
|
||||
|
||||
override def drawSlotInventory(slot: Slot) = {
|
||||
super.drawSlotInventory(slot)
|
||||
if (slot.slotNumber < 8 && !slot.getHasStack())
|
||||
drawSlotIcon(slot, icons(slot.slotNumber))
|
||||
}
|
||||
|
||||
override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) = {
|
||||
//draw text and stuff here
|
||||
//the parameters for drawString are: string, x, y, color
|
||||
fontRenderer.drawString("Computer ", 8, 6, 4210752);
|
||||
//draws "Inventory" or your regional equivalent
|
||||
fontRenderer.drawString(
|
||||
StatCollector.translateToLocal("oc.container.computer"),
|
||||
8, ySize - 96 + 2, 4210752);
|
||||
8, 6, 0x404040)
|
||||
fontRenderer.drawString(
|
||||
StatCollector.translateToLocal("container.inventory"),
|
||||
8, ySize - 96 + 2, 0x404040)
|
||||
}
|
||||
|
||||
override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) = {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.renderEngine.func_110577_a(new ResourceLocation(""));
|
||||
val x = (width - xSize) / 2
|
||||
val y = (height - ySize) / 2;
|
||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
|
||||
}
|
||||
|
||||
override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) = {
|
||||
super.drawScreen(mouseX, mouseY, dt);
|
||||
button.drawButton(this.mc, mouseX, mouseY)
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F)
|
||||
setTexture(background)
|
||||
drawTexturedModalRect(x, y, 0, 0, xSize, ySize)
|
||||
}
|
||||
|
||||
override def doesGuiPauseGame = false
|
||||
|
||||
private def drawSlotIcon(slot: Slot, icon: ResourceLocation) = {
|
||||
GL11.glPushAttrib(0xFFFFFF)
|
||||
GL11.glDisable(GL11.GL_LIGHTING)
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST)
|
||||
GL11.glEnable(GL11.GL_BLEND)
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
|
||||
GL11.glColor4f(1, 1, 1, 0.25f)
|
||||
setTexture(icon)
|
||||
val t = Tessellator.instance
|
||||
t.startDrawingQuads()
|
||||
t.addVertexWithUV(slot.xDisplayPosition, slot.yDisplayPosition + 16, zLevel, 0, 1)
|
||||
t.addVertexWithUV(slot.xDisplayPosition + 16, slot.yDisplayPosition + 16, zLevel, 1, 1)
|
||||
t.addVertexWithUV(slot.xDisplayPosition + 16, slot.yDisplayPosition, zLevel, 1, 0)
|
||||
t.addVertexWithUV(slot.xDisplayPosition, slot.yDisplayPosition, zLevel, 0, 0)
|
||||
t.draw()
|
||||
GL11.glPopAttrib()
|
||||
}
|
||||
|
||||
private def setTexture(value: ResourceLocation) =
|
||||
mc.renderEngine.func_110577_a(value)
|
||||
}
|
@ -6,19 +6,41 @@ import net.minecraft.inventory.Slot
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
class ContainerComputer(playerInventory: InventoryPlayer, computer: TileEntityComputer) extends GenericInventoryContainer(playerInventory, computer) {
|
||||
// Show the computer's inventory.
|
||||
// TODO nicer layout, separate for types, based on background image once it exists
|
||||
for (slotY <- 0 until 3) {
|
||||
for (slotX <- 0 until 3) {
|
||||
val index = slotX + slotY * 3
|
||||
val x = 62 + slotX * slotSize
|
||||
val y = 17 + slotY * slotSize
|
||||
addSlotToContainer(new Slot(computer, index, x, y) {
|
||||
override def isItemValid(item: ItemStack) = {
|
||||
computer.isItemValidForSlot(index, item)
|
||||
}
|
||||
})
|
||||
// PSU
|
||||
addSlotToContainer(new Slot(computer, 0, 58, 17) {
|
||||
override def isItemValid(item: ItemStack) = {
|
||||
computer.isItemValidForSlot(0, item)
|
||||
}
|
||||
})
|
||||
|
||||
// PCI
|
||||
for (i <- 0 to 2) {
|
||||
val index = i + 1
|
||||
addSlotToContainer(new Slot(computer, index, 80, 17 + i * slotSize) {
|
||||
override def isItemValid(item: ItemStack) = {
|
||||
computer.isItemValidForSlot(index, item)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// RAM
|
||||
for (i <- 0 to 1) {
|
||||
val index = i + 4
|
||||
addSlotToContainer(new Slot(computer, index, 102, 17 + i * slotSize) {
|
||||
override def isItemValid(item: ItemStack) = {
|
||||
computer.isItemValidForSlot(index, item)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// HDD
|
||||
for (i <- 0 to 1) {
|
||||
val index = i + 6
|
||||
addSlotToContainer(new Slot(computer, index, 124, 17 + i * slotSize) {
|
||||
override def isItemValid(item: ItemStack) = {
|
||||
computer.isItemValidForSlot(index, item)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Show the player's inventory.
|
||||
|
@ -10,7 +10,7 @@ import net.minecraft.nbt.NBTTagList
|
||||
import net.minecraft.world.World
|
||||
|
||||
trait ItemComponentProxy extends IInventory {
|
||||
protected val inventory = new Array[ItemStack](9)
|
||||
protected val inventory = new Array[ItemStack](8)
|
||||
|
||||
protected val itemComponents = Array.fill(inventory.length)(0)
|
||||
|
||||
@ -119,9 +119,9 @@ trait ItemComponentProxy extends IInventory {
|
||||
def isItemValidForSlot(slot: Int, item: ItemStack) = (slot, Drivers.driverFor(item)) match {
|
||||
case (_, None) => false // Invalid item.
|
||||
case (0, Some(driver)) => driver.instance.componentType(item) == ComponentType.PSU
|
||||
case (1 | 2 | 3, Some(driver)) => driver.instance.componentType(item) == ComponentType.RAM
|
||||
case (4 | 5 | 6, Some(driver)) => driver.instance.componentType(item) == ComponentType.HDD
|
||||
case (7 | 8, Some(driver)) => driver.instance.componentType(item) == ComponentType.PCI
|
||||
case (1 | 2 | 3, Some(driver)) => driver.instance.componentType(item) == ComponentType.PCI
|
||||
case (4 | 5, Some(driver)) => driver.instance.componentType(item) == ComponentType.RAM
|
||||
case (6 | 7, Some(driver)) => driver.instance.componentType(item) == ComponentType.HDD
|
||||
case (_, Some(_)) => false // Invalid slot.
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ class Computer(val owner: IComputerEnvironment) extends IComputerContext with IC
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
def start() = stateMonitor.synchronized(
|
||||
state == State.Stopped && init() && {
|
||||
state == State.Stopped && init() && (try {
|
||||
state = State.Suspended
|
||||
|
||||
// Mark state change in owner, to send it to clients.
|
||||
@ -172,7 +172,12 @@ class Computer(val owner: IComputerEnvironment) extends IComputerContext with IC
|
||||
|
||||
future = Some(Executor.pool.submit(this))
|
||||
true
|
||||
})
|
||||
}
|
||||
catch {
|
||||
// The above code may throw if some component was removed by abnormal
|
||||
// means (e.g. mod providing the block was removed/disabled).
|
||||
case _: Throwable => close(); false
|
||||
}))
|
||||
|
||||
def stop() = saveMonitor.synchronized(stateMonitor.synchronized {
|
||||
if (state != State.Stopped) {
|
||||
@ -697,8 +702,15 @@ class Computer(val owner: IComputerEnvironment) extends IComputerContext with IC
|
||||
state = State.Stopped
|
||||
|
||||
// Shutdown any installed components.
|
||||
for (id <- components.keys)
|
||||
owner.driver(id).get.instance.onUninstall(this, owner.component(id).get)
|
||||
try {
|
||||
for (id <- components.keys)
|
||||
owner.driver(id).get.instance.onUninstall(this, owner.component(id).get)
|
||||
}
|
||||
catch {
|
||||
// The above code may throw if some component was removed by abnormal
|
||||
// means (e.g. mod providing the block was removed/disabled).
|
||||
case _: Throwable => // Ignore.
|
||||
}
|
||||
|
||||
lua.setTotalMemory(Integer.MAX_VALUE);
|
||||
lua.close()
|
||||
|
Loading…
x
Reference in New Issue
Block a user