From d17824e722073e9feb51a37f4ad139684a929f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 27 Nov 2013 22:15:01 +0100 Subject: [PATCH] computers and robots no longer start when right clicked, instead there's a button in the gui now that allows turning the computer/robot on or off (also useful for rebooting when locked in some interruptible loop); removed the 'power' slot from computer cases --- .../opencomputers/textures/gui/computer.png | Bin 0 -> 1645 bytes assets/opencomputers/textures/gui/power.png | Bin 0 -> 332 bytes assets/opencomputers/textures/gui/robot.png | Bin 649 -> 650 bytes li/cil/oc/client/PacketSender.scala | 9 ++++ li/cil/oc/client/gui/Case.scala | 35 ++++++++++++++- li/cil/oc/client/gui/ImageButton.scala | 40 ++++++++++++++++++ li/cil/oc/client/gui/Robot.scala | 33 +++++++++++++-- li/cil/oc/common/PacketType.scala | 2 + li/cil/oc/common/block/Case.scala | 1 - li/cil/oc/common/block/Computer.scala | 14 ------ li/cil/oc/common/block/RobotProxy.scala | 1 - li/cil/oc/common/container/Case.scala | 10 ++--- li/cil/oc/common/tileentity/Case.scala | 8 ++-- li/cil/oc/server/PacketHandler.scala | 19 ++++++++- 14 files changed, 140 insertions(+), 32 deletions(-) create mode 100644 assets/opencomputers/textures/gui/computer.png create mode 100644 assets/opencomputers/textures/gui/power.png create mode 100644 li/cil/oc/client/gui/ImageButton.scala diff --git a/assets/opencomputers/textures/gui/computer.png b/assets/opencomputers/textures/gui/computer.png new file mode 100644 index 0000000000000000000000000000000000000000..fb40402b01841779b4d1bd7d504901bd04ee4038 GIT binary patch literal 1645 zcmds%`#02i7{@|P=-p})#_j#Z5{^iMbb+(m~P?7)uNZH$2 zy8!_0j1a(}b|n0vm&cAM#*w|^+@pfyexb$$0jt2MGeHFV2x>@>TM#ucG5S@I`Ho57 z)zO1YG$tAc8v|o7G<2!CIT{c_dU|?JP7WTA-?3O*Tbr7i5{bmFuCDFv?cml$%+3`T z=jQCbv;GIrKYXJc0MRCUYb%cg{@goitg;Rk84n^KX$b$gy**6a=jElv>-LF>)otD9 zbk}zUm7f99iu2{8BzF@3WfQ)zQA7(yCb@%*lrIaJ+e^aPE|6~sxrJ|I7q!7cNFHKR zuSjX?XPVe{l=W&7v^n#qTlbMTv_7U5__JmT#i6wpv$D{xNpZ}QTaf34*F5eZ9*zD4wnzFxt$lYi&(w>ocES62W>S=UThtt%+W*=v7cF8Cjtf?Rrz}*(hk?IzPq?GA`djL%?6E+Z$JedKROUpbhIf7~KT3QmtMHo^L=@B} zGKEl09XvlmjlceTAsKPb(TIT+1#(c4So_5k5enY**FcB)cpV#Qu3v;F=FMT5J#a9R zD97?*7-H$D7xv5#->O3u5GV8_N1qUg5d?2p%14EWb1S>BWru4YRIYV|K`GJ6Bf>)N zfHxXxV}z=UyvDK&^JDm#@J*>6DT3dZ+aN5``<)xRb!81uLk{4H0vuqI$O#?i^;9o| zmzlb_h`-Iqh|%f=)hAgi=&9w+{92RgX>B?!^rtdL|1nbSo6Vk{)ZC8)?sa14<>6 z^!3&ZbVQKlFaeq+|81Q)HxM(_^JBL(S8io!1zG1A;Z8gGTpPO*F-~vU6X{Ti!Be)( zyO)Pt$jf2q$$BIdru9T zle7k>UD_OCuP774`Lmm)6JHYypHH<{xOPv`-J(eCfn*(w-sHW@!e`I(BCi}@)ECN%{e1%&S(@&Cvof1V9cKugBF&`9un^m|2nva@x~3Cg8^ E0K{~HZ~y=R literal 0 HcmV?d00001 diff --git a/assets/opencomputers/textures/gui/power.png b/assets/opencomputers/textures/gui/power.png new file mode 100644 index 0000000000000000000000000000000000000000..3f462fdab58685a15450ee7cb1375a1932b6f26c GIT binary patch literal 332 zcmV-S0ki&zP)#`{O9+yaIFW9%5`{Ga&!)>0Sd z7s7lGR&r1L*gT1mrM@9ji0{EtZU%r zGtPLKRvYtFwOsSJ8c+%jD!$CD+{W~LKjSkV28M%-@BEk5PUd^CVqWT@RYMsZ90eigjq(-=UgEH1u1A;co#5u7`~+wmDll=X&uIBGQHX(IBjdSyT>p6r zJ{?y;Rl>mVK<>etwHv%Zn&aQxXUK|*KfH|bib&=ETMSuUvw!gkSTW2~=SSAnCi%p- Zfsw)6rBmXlNyki(l&7no%Q~loCIE|UgO~sS delta 388 zcmeBT?PQ(M8~@zX#WAGf)|)$ydCdj_tO3%?eP92U-?1!ED@)6D(Z(kR@AI45e4jNc z{OVp36@2H)wpw4+yh~L-ncv4xD`AdU^sLHP`vB7d*`ue$6dwKC`G?8kzxMmh-koe0 z)MXAti%MU|ezS_q0e5i*hHVTxS%_WNrgW79uUQxx9x(h~es$x?#cmqs%_Q$~*uFd_WiI*G z8m<<~=wSb_W?t$Y7v&{_pLiG;>QUuQoTLZ(%mtL=3k{1N*MO|%OUIHIXPXN YftevBqBCTH*L1Lyr>mdKI;Vst07_ql ClientPacketSender} import li.cil.oc.common.container import li.cil.oc.common.tileentity +import net.minecraft.client.gui.GuiButton import net.minecraft.entity.player.InventoryPlayer -import net.minecraft.util.StatCollector +import net.minecraft.util.{ResourceLocation, StatCollector} class Case(playerInventory: InventoryPlayer, val computer: tileentity.Case) extends DynamicGuiContainer(new container.Case(playerInventory, computer)) { + protected val computerBackground = new ResourceLocation(Settings.resourceDomain, "textures/gui/computer.png") + protected val powerIcon = new ResourceLocation(Settings.resourceDomain, "textures/gui/power.png") + + protected var powerButton: ImageButton = _ + + def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T]) + + protected override def actionPerformed(button: GuiButton) { + if (button.id == 0) { + ClientPacketSender.sendComputerPower(computer, !computer.isRunning) + } + } + + override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) { + powerButton.toggled = computer.isRunning + super.drawScreen(mouseX, mouseY, dt) + } + + override def initGui() { + super.initGui() + powerButton = new ImageButton(0, guiLeft + 70, guiTop + 33, 18, 18, powerIcon) + add(buttonList, powerButton) + } + override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) = { super.drawGuiContainerForegroundLayer(mouseX, mouseY) fontRenderer.drawString( @@ -14,5 +41,11 @@ class Case(playerInventory: InventoryPlayer, val computer: tileentity.Case) exte 8, 6, 0x404040) } + override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) { + super.drawGuiContainerBackgroundLayer(dt, mouseX, mouseY) + mc.renderEngine.bindTexture(computerBackground) + drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize) + } + override def doesGuiPauseGame = false } \ No newline at end of file diff --git a/li/cil/oc/client/gui/ImageButton.scala b/li/cil/oc/client/gui/ImageButton.scala new file mode 100644 index 000000000..bb3364941 --- /dev/null +++ b/li/cil/oc/client/gui/ImageButton.scala @@ -0,0 +1,40 @@ +package li.cil.oc.client.gui + +import cpw.mods.fml.relauncher.{SideOnly, Side} +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiButton +import net.minecraft.client.renderer.Tessellator +import net.minecraft.util.ResourceLocation +import org.lwjgl.opengl.GL11 + +@SideOnly(Side.CLIENT) +class ImageButton(id: Int, x: Int, y: Int, w: Int, h: Int, val image: ResourceLocation) extends GuiButton(id, x, y, w, h, null) { + + var toggled = false + + override def drawButton(mc: Minecraft, mouseX: Int, mouseY: Int) { + if (drawButton) { + mc.renderEngine.bindTexture(image) + GL11.glColor4f(1, 1, 1, 1) + field_82253_i = mouseX >= xPosition && mouseY >= yPosition && mouseX < xPosition + width && mouseY < yPosition + height + + val x0 = xPosition + val x1 = xPosition + width + val y0 = yPosition + val y1 = yPosition + height + + val u0 = if (toggled) 0.5 else 0 + val u1 = u0 + 0.5 + val v0 = if (getHoverState(field_82253_i) == 2) 0.5 else 0 + val v1 = v0 + 0.5 + + val t = Tessellator.instance + t.startDrawingQuads() + t.addVertexWithUV(x0, y1, zLevel, u0, v1) + t.addVertexWithUV(x1, y1, zLevel, u1, v1) + t.addVertexWithUV(x1, y0, zLevel, u1, v0) + t.addVertexWithUV(x0, y0, zLevel, u0, v0) + t.draw() + } + } +} diff --git a/li/cil/oc/client/gui/Robot.scala b/li/cil/oc/client/gui/Robot.scala index 6ae37315f..60c513638 100644 --- a/li/cil/oc/client/gui/Robot.scala +++ b/li/cil/oc/client/gui/Robot.scala @@ -1,12 +1,15 @@ package li.cil.oc.client.gui +import java.util import li.cil.oc.Settings import li.cil.oc.client.renderer.MonospaceFontRenderer import li.cil.oc.client.renderer.gui.BufferRenderer +import li.cil.oc.client.{PacketSender => ClientPacketSender} import li.cil.oc.common.container import li.cil.oc.common.tileentity import li.cil.oc.util.RenderState import net.minecraft.client.Minecraft +import net.minecraft.client.gui.GuiButton import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.client.renderer.Tessellator import net.minecraft.entity.player.InventoryPlayer @@ -19,9 +22,12 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten xSize = 256 ySize = 242 - private val background = new ResourceLocation(Settings.resourceDomain, "textures/gui/robot.png") + private val robotBackground = new ResourceLocation(Settings.resourceDomain, "textures/gui/robot.png") + protected val powerIcon = new ResourceLocation(Settings.resourceDomain, "textures/gui/power.png") private val selection = new ResourceLocation(Settings.resourceDomain, "textures/gui/robot_selection.png") + protected var powerButton: ImageButton = _ + protected val buffer = robot.buffer private val bufferWidth = 242.0 @@ -31,16 +37,35 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten private val inventoryX = 176 private val inventoryY = 140 - private val powerX = 8 + private val powerX = 28 private val powerY = 142 - private val powerWidth = 160 + private val powerWidth = 140 private val powerHeight = 12 private val selectionSize = 20 private val selectionsStates = 17 private val selectionStepV = 1 / selectionsStates.toDouble + def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T]) + + protected override def actionPerformed(button: GuiButton) { + if (button.id == 0) { + ClientPacketSender.sendComputerPower(robot, !robot.isRunning) + } + } + + override def drawScreen(mouseX: Int, mouseY: Int, dt: Float) { + powerButton.toggled = robot.isRunning + super.drawScreen(mouseX, mouseY, dt) + } + + override def initGui() { + super.initGui() + powerButton = new ImageButton(0, guiLeft + 7, guiTop + 139, 18, 18, powerIcon) + add(buttonList, powerButton) + } + override def drawSlotInventory(slot: Slot) { RenderState.makeItBlend() super.drawSlotInventory(slot) @@ -69,7 +94,7 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten } override def drawGuiContainerBackgroundLayer(dt: Float, mouseX: Int, mouseY: Int) { - mc.renderEngine.bindTexture(background) + mc.renderEngine.bindTexture(robotBackground) drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize) drawPowerLevel() drawSelection() diff --git a/li/cil/oc/common/PacketType.scala b/li/cil/oc/common/PacketType.scala index fb5e6b3d0..f01df2459 100644 --- a/li/cil/oc/common/PacketType.scala +++ b/li/cil/oc/common/PacketType.scala @@ -5,6 +5,8 @@ object PacketType extends Enumeration { ChargerStateRequest, ChargerStateResponse, + ComputerPower, + ComputerStateRequest, ComputerStateResponse, diff --git a/li/cil/oc/common/block/Case.scala b/li/cil/oc/common/block/Case.scala index cf5c4a62c..a573ff4fb 100644 --- a/li/cil/oc/common/block/Case.scala +++ b/li/cil/oc/common/block/Case.scala @@ -63,7 +63,6 @@ class Case(val parent: SimpleDelegator) extends Computer with SimpleDelegate { override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = { - super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ) if (!player.isSneaking) { if (!world.isRemote) { player.openGui(OpenComputers, GuiType.Case.id, world, x, y, z) diff --git a/li/cil/oc/common/block/Computer.scala b/li/cil/oc/common/block/Computer.scala index 6fec27049..f38bf281f 100644 --- a/li/cil/oc/common/block/Computer.scala +++ b/li/cil/oc/common/block/Computer.scala @@ -1,7 +1,6 @@ package li.cil.oc.common.block import li.cil.oc.common.tileentity -import net.minecraft.entity.player.EntityPlayer import net.minecraft.world.{World, IBlockAccess} import net.minecraftforge.common.ForgeDirection @@ -23,19 +22,6 @@ abstract class Computer extends Delegate { case _ => super.isProvidingWeakPower(world, x, y, z, side) } - override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, - side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = { - if (!player.isSneaking) { - if (!world.isRemote) { - world.getBlockTileEntity(x, y, z) match { - case t: tileentity.Computer if !t.computer.isPaused && t.computer.canInteract(player.getCommandSenderName) => t.computer.start() - case _ => - } - } - } - super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ) - } - override def onNeighborBlockChange(world: World, x: Int, y: Int, z: Int, blockId: Int) = world.getBlockTileEntity(x, y, z) match { case computer: tileentity.Computer => computer.checkRedstoneInputChanged() diff --git a/li/cil/oc/common/block/RobotProxy.scala b/li/cil/oc/common/block/RobotProxy.scala index 07b005513..d4d7ef290 100644 --- a/li/cil/oc/common/block/RobotProxy.scala +++ b/li/cil/oc/common/block/RobotProxy.scala @@ -71,7 +71,6 @@ class RobotProxy(val parent: SpecialDelegator) extends Computer with SpecialDele override def onBlockActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = { - super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ) if (!player.isSneaking) { if (!world.isRemote) { player.openGui(OpenComputers, GuiType.Robot.id, world, x, y, z) diff --git a/li/cil/oc/common/container/Case.scala b/li/cil/oc/common/container/Case.scala index b2ac2284d..568138a65 100644 --- a/li/cil/oc/common/container/Case.scala +++ b/li/cil/oc/common/container/Case.scala @@ -5,20 +5,20 @@ import li.cil.oc.common.tileentity import net.minecraft.entity.player.{EntityPlayer, InventoryPlayer} class Case(playerInventory: InventoryPlayer, `case`: tileentity.Case) extends Player(playerInventory, `case`) { - addSlotToContainer(58, 17, api.driver.Slot.Power) - for (i <- 0 to 2) { - addSlotToContainer(80, 17 + i * slotSize, api.driver.Slot.Card) + addSlotToContainer(98, 16 + i * slotSize, api.driver.Slot.Card) } for (i <- 0 to 1) { - addSlotToContainer(102, 17 + i * slotSize, api.driver.Slot.Memory) + addSlotToContainer(120, 16 + i * slotSize, api.driver.Slot.Memory) } for (i <- 0 to 1) { - addSlotToContainer(124, 17 + i * slotSize, api.driver.Slot.HardDiskDrive) + addSlotToContainer(142, 16 + i * slotSize, api.driver.Slot.HardDiskDrive) } + addSlotToContainer(142, 16 + 2 * slotSize, api.driver.Slot.Disk) + // Show the player's inventory. addPlayerInventorySlots(8, 84) diff --git a/li/cil/oc/common/tileentity/Case.scala b/li/cil/oc/common/tileentity/Case.scala index 8543eb36b..f356428d2 100644 --- a/li/cil/oc/common/tileentity/Case.scala +++ b/li/cil/oc/common/tileentity/Case.scala @@ -16,10 +16,10 @@ class Case(isRemote: Boolean) extends Computer(isRemote) { def isItemValidForSlot(slot: Int, stack: ItemStack) = (slot, Registry.driverFor(stack)) match { case (_, None) => false // Invalid item. - case (0, Some(driver)) => driver.slot(stack) == Slot.Power - case (1 | 2 | 3, Some(driver)) => driver.slot(stack) == Slot.Card - case (4 | 5, Some(driver)) => driver.slot(stack) == Slot.Memory - case (6 | 7, Some(driver)) => driver.slot(stack) == Slot.HardDiskDrive + case (0 | 1 | 2, Some(driver)) => driver.slot(stack) == Slot.Card + case (3 | 4, Some(driver)) => driver.slot(stack) == Slot.Memory + case (5 | 6, Some(driver)) => driver.slot(stack) == Slot.HardDiskDrive + case (7, Some(driver)) => driver.slot(stack) == Slot.Disk case _ => false // Invalid slot. } } \ No newline at end of file diff --git a/li/cil/oc/server/PacketHandler.scala b/li/cil/oc/server/PacketHandler.scala index 182d8fb76..9aeb0336f 100644 --- a/li/cil/oc/server/PacketHandler.scala +++ b/li/cil/oc/server/PacketHandler.scala @@ -4,6 +4,7 @@ import cpw.mods.fml.common.network.Player import li.cil.oc.common.PacketType import li.cil.oc.common.tileentity._ import li.cil.oc.common.{PacketHandler => CommonPacketHandler} +import net.minecraft.entity.player.EntityPlayer import net.minecraftforge.common.DimensionManager import scala.Some @@ -14,6 +15,7 @@ class PacketHandler extends CommonPacketHandler { def dispatch(p: PacketParser) = p.packetType match { case PacketType.ChargerStateRequest => onChargerStateRequest(p) + case PacketType.ComputerPower => onComputerPower(p) case PacketType.ComputerStateRequest => onComputerStateRequest(p) case PacketType.PowerStateRequest => onPowerStateRequest(p) case PacketType.RedstoneStateRequest => onRedstoneStateRequest(p) @@ -27,8 +29,21 @@ class PacketHandler extends CommonPacketHandler { } def onChargerStateRequest(p: PacketParser) = - p.readTileEntity[Charger]() match { - case Some(t) => PacketSender.sendChargerState(t, Option(p.player)) + p.readTileEntity[Computer]() match { + case Some(t) => PacketSender.sendComputerState(t, Option(p.player)) + case _ => // Invalid packet. + } + + def onComputerPower(p: PacketParser) = + p.readTileEntity[Computer]() match { + case Some(t) => p.player match { + case player: EntityPlayer if t.computer.canInteract(player.getCommandSenderName) => + if (p.readBoolean()) { + if (!t.computer.isPaused) t.computer.start() + } + else t.computer.stop() + case _ => + } case _ => // Invalid packet. }