From 78957853ef638ea4f0fbec1451bfef2025a2cf0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 20 Jul 2014 17:22:25 +0200 Subject: [PATCH] Adjusted robot GUI for new font renderer's char aspect ratio (auto-sizes now). Extracted the commonly used progress bar code into a common class. --- .../assets/opencomputers/textures/gui/bar.png | Bin 0 -> 136 bytes .../textures/gui/disassembler.png | Bin 655 -> 651 bytes .../opencomputers/textures/gui/robot.png | Bin 651 -> 589 bytes .../textures/gui/robot_assembler.png | Bin 1766 -> 1757 bytes .../textures/gui/robot_noscreen.png | Bin 601 -> 592 bytes .../scala/li/cil/oc/client/Textures.scala | 2 + .../oc/client/gui/CustomGuiContainer.scala | 3 +- .../li/cil/oc/client/gui/Disassembler.scala | 31 +------- .../scala/li/cil/oc/client/gui/Robot.scala | 69 +++++++----------- .../li/cil/oc/client/gui/RobotAssembler.scala | 36 ++------- .../li/cil/oc/client/gui/TextBuffer.scala | 1 + .../oc/client/gui/widget/ProgressBar.scala | 34 +++++++++ .../li/cil/oc/client/gui/widget/Widget.scala | 15 ++++ .../client/gui/widget/WidgetContainer.scala | 25 +++++++ .../client/renderer/gui/BufferRenderer.scala | 8 +- .../li/cil/oc/common/container/Robot.scala | 14 ++-- 16 files changed, 127 insertions(+), 111 deletions(-) create mode 100644 src/main/resources/assets/opencomputers/textures/gui/bar.png create mode 100644 src/main/scala/li/cil/oc/client/gui/widget/ProgressBar.scala create mode 100644 src/main/scala/li/cil/oc/client/gui/widget/Widget.scala create mode 100644 src/main/scala/li/cil/oc/client/gui/widget/WidgetContainer.scala diff --git a/src/main/resources/assets/opencomputers/textures/gui/bar.png b/src/main/resources/assets/opencomputers/textures/gui/bar.png new file mode 100644 index 0000000000000000000000000000000000000000..fac816754b9e88453b0da622d4913cf3745c5847 GIT binary patch literal 136 zcmeAS@N?(olHy`uVBq!ia0vp^JwVLE!3-qZ*DbvQq$EpRBT9nv(@M${i&7aJQ}UBi z6+Ckj(^G>|6H_V+Po~-c6|n{Qgt(@iNdq!HlYaC9DG5&($B>F!NeL3HixWh8ngR{D e*u)t)3>etvFfg{Vsx$!AFnGH9xvX-L1;Fyx1 zl&avFo0y&&l$w}QS$Hzl2B=6Pz$e7@*s){X-QEBH|2H=`2a1J;hW`K00OU3%uQUMi zIZA^3f`MERV7S-3Hxg*mS5FtmkcwMx?i}npq#(eSup+tgzxllfa%LOf9$cf5vhRP2 z#f&q{eP=l8tUYR#`QATsU_3bO)AEn;!94{AhP=L6T({Zb;!wu2L(2}OH8C)p3H{H| zAojO*`bi))^YwcM-D{rGOcSio)zg4~`iXl3Bg4*fuH9$7lZ`+Yc)I$ztaD0e0szg4 BwwnL| literal 655 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5FjO4;u=vBoS#-wo>-L1;Fyx1 zl&avFo0y&&l$w}QS$Hzl2B=6nz$e7@*s){X-QEBH|4%!UW^Qf{6b=my{r{f^hLoSrX(I4CI0VL$H5^5YV=-o-U3d6}R5pam->izNCJ>m?g@|2nV4u=&yP?_V+lITzHQHr&s>l<`~;L!gX87xNKbhlRZt zR2@XvJ039{t!jM4kY3pEnQg(3un7GH;upAIu)g}j^!Mo`=Z$d>s`Mf_9~9}mh&iyc zVX-099S1fs^k2QanKA7D2YzIyr7(Q?`rpmlng=BK-(2YR>a{7%d;V-n-YSZ$48(T$ z7g4iSR9LYeU4r3&%L$hg${4~1g1=ZBs+$=Yc35U<<;bJU&)}NPHJg)(VMEwoP6p*? zzw;)uGzd<8J)c4O+er^b4Ow*cRN>zcevtbS*(3$k_e?wtYbP0 Hl+XkKG~&3N diff --git a/src/main/resources/assets/opencomputers/textures/gui/robot.png b/src/main/resources/assets/opencomputers/textures/gui/robot.png index 6d4200f7cdd51cdf125fac9b020f578c628376b0..175015ea0e69e55f76f14bd8e8880c87d4645f7a 100644 GIT binary patch literal 589 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5FjO4;u=vBoS#-wo>-L1;Fyx1 zl&avFo0y&&l$w}QS$Hzl2B=6hz$e7@*s){X-QEBH|2H=`2a1J;h635XR()H69QKkR zzhEF22pFWincaZ4?DlkV45_&F=8hv*vw;BX1(jnv|4&>k60^nWpcK!U-_ogKNpaaN z`!~3J+0)q}wD;**wE&~_`=|b6(}>)>u9jT`XzGvv2QD+5_F1X^J$SuupZ3*w2IIdW zw{7*lD!;w;Bq9UmqZM&J1I)nM&y~ljn z?3rMyp|pcj!|q$t3Wa+oxSfzglViweF>#VotVS1JAoy#s;3-j{a7OE1Hc*r!gS7># z!gk1|+pXtkaL8&XW$)N0e>si0V_xOojf^hmXLn3zU}nfv=~WC63_JzW=jrO_vd$@? F2>|2zgueg) literal 651 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5FjO4;u=vBoS#-wo>-L1;Fyx1 zl&avFo0y&&l$w}QS$Hzl2B=6ez$e5NNOyO4A3JvJ|NsBy=H`ryjG>{SX=l>d+1Z(x zn1F)Ul4oTB6>*mY`2_>HP{82j&-e*w>q}1;$B>F!Z|)wn!n83?OD2GKcgMV4`Ja9)`6Yc|YTnh7-tD`*Zkt!;TtjyGhN)E>e?5E25YElO@Q~sD`6acJ zeH#|vn)X?(-ONdvfxUL`x!H662qS9&v6&eAvZBw;&S)`lI)^Ujpu9xz5{D%y)=@z3 z1$n83Yk)!y+HVXwP^1_bGFlf$J>2zCTzVlRgMxIz9LB1d@yW)FUncFTpU+Tr()T}0 l2VcW=ZdPP%{-@g+m>D+s^_pLQ^Z7AI#?#f$Wt~$(697Vev627) diff --git a/src/main/resources/assets/opencomputers/textures/gui/robot_assembler.png b/src/main/resources/assets/opencomputers/textures/gui/robot_assembler.png index 51d082204a9af7ee0c808807987c578db9bc0015..308dea6f4483852577d1e6da8b0b217d4b2e842a 100644 GIT binary patch delta 1547 zcmY*Zc|6m99R7T_*_Ir0q*{8}&+((nk-MpuGZJEsC|A*nP%5+Ek9|exw=hX0S2-7n z4lBfx6iTj=P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}kyQTYb${zP3vB(xg*B2HmxtfaX z?XI0TjS3;_ZbC>O2f*Ia@dQ)n~Ebs1AV?=qFSS0Dpgdz9;WrD|L|y zs}`MP21V`ivZBu$>%%*~%XKd5);C14gh)utnI%daal&4^C)#px9U!WZ z=wGQblUEjHkhxb=g3HsKQ{jYPGHe0Dm9*pWx4sH?S#4|KqD`z5yHvQ3|X9??#-hYeAW=_W0!)|{n3v!gVo~Ii2*;@JL zn{NIt_*4r=FMccS8XX@oK;=nh7eqk#Qkand)floJbhL*L2a%D()e7Xiw<=AbahCv%=xrM|z`(x9a zZzP~KRA$4GXDYLI8!vIyvSo&*B8`sGF(5;0P#xiR!a#KPk}RF4>*S+7zvgaD)1>=o zTki&7_~E1sbH?CvSy8eYKfb(E#K8;SVj=bvO4hpDLKbApeV@9bytcsqLVopG-M|2t W-;ais$K|W60T(BC$9oQpi~j+y1fN9! diff --git a/src/main/resources/assets/opencomputers/textures/gui/robot_noscreen.png b/src/main/resources/assets/opencomputers/textures/gui/robot_noscreen.png index 18a0807acba4b97767b6b4e71bace3873cdd5a70..f2c80254ad706ad1e9cefc7e2dff9eae91f11742 100644 GIT binary patch delta 374 zcmcb~a)D)nXT4~EPl#)GclWVl$NvBSZ*FeRz`zh18VY2e%!(=na@b3P{DOg8AYhR4 zW_Dv>VBF{F;uunK>&;z9u4V@TmIHy;fBv7mn6sjTn{ly{&sSBW_6O6_m}@Vb$SIvX zb7JnA*{%v&>+5B1u_vsURhg%K0BCAM?J{*$tLMV?$JK6|AJuPAk6ratX8Dg(6*-&M z=CA-2z<`7P$2ISs)io?DT85>}lNU1fOy0mKE_L8+C8q&HO2w@Q T%K7JifOLDh`njxgN@xNAfkBAd literal 601 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K58911MRQ8&P5FjO4;u=vBoS#-wo>-L1;Fyx1 zl&avFo0y&&l$w}QS$Hzl2B=6Pz$e7DySw|?v19-L|2H=`Pdk$a6b=my1#($_OI!zX zI7)*2f`MERV7S-3Hxg*mVNVywkcwMx?q1|-au8s>a53un|Nj=c9~4^;Y!Q2QXL^d< zA=_JQ-yM}VU-eCM+qN+;t#QSke}x(P4GXiDt<+@zxpUjjuTySV&bKg&+^=cJ_@!j! zv*JBRqmLy|E=^SiO2ff7q1saO{p>Gv85l&^Z@lw7uC|*YeXH(uU%%XzG6uh0d)Lj5 z`6CQh4rOpL&AGZQ#{42jX3HB;;2?trHxK0{f}7Zp#XxMSh5AwpqkyU#!fxDGK$Be{ zs&|#^c-51SzZe*%u+5mqko!|-w%E+IpMDjyt@yicE$f03G#!J4+fdJR#~PGW;Gk|= aJ1_>~za-p$YFG|RD-52lelF{r5}E*E|CR>; diff --git a/src/main/scala/li/cil/oc/client/Textures.scala b/src/main/scala/li/cil/oc/client/Textures.scala index 2e33d918e..581bd959a 100644 --- a/src/main/scala/li/cil/oc/client/Textures.scala +++ b/src/main/scala/li/cil/oc/client/Textures.scala @@ -9,6 +9,7 @@ object Textures extends ResourceManagerReloadListener { val fontAliased = new ResourceLocation(Settings.resourceDomain, "textures/font/chars_aliased.png") val guiBackground = new ResourceLocation(Settings.resourceDomain, "textures/gui/background.png") + val guiBar = new ResourceLocation(Settings.resourceDomain, "textures/gui/bar.png") val guiBorders = new ResourceLocation(Settings.resourceDomain, "textures/gui/borders.png") val guiButtonPower = new ResourceLocation(Settings.resourceDomain, "textures/gui/button_power.png") val guiButtonRange = new ResourceLocation(Settings.resourceDomain, "textures/gui/button_range.png") @@ -75,6 +76,7 @@ object Textures extends ResourceManagerReloadListener { manager.getResource(fontAliased) manager.getResource(guiBackground) + manager.getResource(guiBar) manager.getResource(guiBorders) manager.getResource(guiButtonPower) manager.getResource(guiButtonRange) diff --git a/src/main/scala/li/cil/oc/client/gui/CustomGuiContainer.scala b/src/main/scala/li/cil/oc/client/gui/CustomGuiContainer.scala index 0c3751f4a..acdddd7e9 100644 --- a/src/main/scala/li/cil/oc/client/gui/CustomGuiContainer.scala +++ b/src/main/scala/li/cil/oc/client/gui/CustomGuiContainer.scala @@ -2,6 +2,7 @@ package li.cil.oc.client.gui import java.util +import li.cil.oc.client.gui.widget.WidgetContainer import net.minecraft.client.gui.FontRenderer import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.client.renderer.RenderHelper @@ -14,7 +15,7 @@ import scala.collection.convert.WrapAsScala._ // transformations that break things! Such fun. Many annoyed. And yes, this // is a common issue, have a look at EnderIO and Enchanting Plus. They have // to work around this, too. -abstract class CustomGuiContainer(container: Container) extends GuiContainer(container) { +abstract class CustomGuiContainer(container: Container) extends GuiContainer(container) with WidgetContainer { // Pretty much Scalaified copy-pasta from base-class. override def drawHoveringText(text: util.List[_], x: Int, y: Int, font: FontRenderer) { copiedDrawHoveringText(text, x, y, font) diff --git a/src/main/scala/li/cil/oc/client/gui/Disassembler.scala b/src/main/scala/li/cil/oc/client/gui/Disassembler.scala index 1316f98dc..7c5917aaf 100644 --- a/src/main/scala/li/cil/oc/client/gui/Disassembler.scala +++ b/src/main/scala/li/cil/oc/client/gui/Disassembler.scala @@ -1,8 +1,8 @@ package li.cil.oc.client.gui import li.cil.oc.client.Textures +import li.cil.oc.client.gui.widget.ProgressBar import li.cil.oc.common.{container, tileentity} -import net.minecraft.client.renderer.Tessellator import net.minecraft.entity.player.InventoryPlayer import net.minecraft.util.StatCollector import org.lwjgl.opengl.GL11 @@ -10,11 +10,7 @@ import org.lwjgl.opengl.GL11 class Disassembler(playerInventory: InventoryPlayer, val disassembler: tileentity.Disassembler) extends DynamicGuiContainer(new container.Disassembler(playerInventory, disassembler)) { private def disassemblerContainer = inventorySlots.asInstanceOf[container.Disassembler] - private val progressX = 8 - private val progressY = 65 - - private val progressWidth = 160 - private val progressHeight = 12 + val progress = addWidget(new ProgressBar(18, 65)) override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) = { fontRenderer.drawString( @@ -27,26 +23,7 @@ class Disassembler(playerInventory: InventoryPlayer, val disassembler: tileentit super.drawGuiContainerBackgroundLayer(dt, mouseX, mouseY) mc.renderEngine.bindTexture(Textures.guiDisassembler) drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize) - drawProgress() - } - - private def drawProgress() { - val level = disassemblerContainer.disassemblyProgress / 100.0 - - val u0 = 0 - val u1 = progressWidth / 256.0 * level - val v0 = 1 - progressHeight / 256.0 - val v1 = 1 - val x = guiLeft + progressX - val y = guiTop + progressY - val w = progressWidth * level - - val t = Tessellator.instance - t.startDrawingQuads() - t.addVertexWithUV(x, y, zLevel, u0, v0) - t.addVertexWithUV(x, y + progressHeight, zLevel, u0, v1) - t.addVertexWithUV(x + w, y + progressHeight, zLevel, u1, v1) - t.addVertexWithUV(x + w, y, zLevel, u1, v0) - t.draw() + progress.level = disassemblerContainer.disassemblyProgress / 100.0 + drawWidgets() } } diff --git a/src/main/scala/li/cil/oc/client/gui/Robot.scala b/src/main/scala/li/cil/oc/client/gui/Robot.scala index 906365113..a21b1ca03 100644 --- a/src/main/scala/li/cil/oc/client/gui/Robot.scala +++ b/src/main/scala/li/cil/oc/client/gui/Robot.scala @@ -2,6 +2,7 @@ package li.cil.oc.client.gui import java.util +import li.cil.oc.client.gui.widget.ProgressBar import li.cil.oc.client.renderer.TextBufferRenderCache import li.cil.oc.client.renderer.gui.BufferRenderer import li.cil.oc.client.{Textures, PacketSender => ClientPacketSender} @@ -26,13 +27,13 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten override protected val hasKeyboard = robot.info.components.map(api.Driver.driverFor).contains(driver.item.Keyboard) - private val withScreenHeight = 242 + private val withScreenHeight = 256 private val noScreenHeight = 108 private val deltaY = if (buffer != null) 0 else withScreenHeight - noScreenHeight xSize = 256 - ySize = 242 - deltaY + ySize = 256 - deltaY protected var powerButton: ImageButton = _ @@ -48,25 +49,23 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten private val slotSize = 18 - override protected val bufferX = 8 - override protected val bufferY = 8 - private val bufferWidth = 242.0 - private val bufferHeight = 128.0 - private val bufferMargin = BufferRenderer.innerMargin + private val maxBufferWidth = 240.0 + private val maxBufferHeight = 140.0 + + private def bufferWidth = math.min(maxBufferWidth, TextBufferRenderCache.renderer.charRenderWidth * 48.0) + private def bufferHeight = math.min(maxBufferHeight, TextBufferRenderCache.renderer.charRenderHeight * 14.0) + override protected def bufferX = (8 + (maxBufferWidth - bufferWidth) / 2).toInt + override protected def bufferY = (8 + (maxBufferHeight - bufferHeight) / 2).toInt private val inventoryX = 169 - private val inventoryY = 141 - deltaY + private val inventoryY = 155 - deltaY 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 - deltaY - - private val powerWidth = 140 - private val powerHeight = 12 + private val power = addWidget(new ProgressBar(26, 156 - deltaY)) private val selectionSize = 20 private val selectionsStates = 17 @@ -92,7 +91,7 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten override def initGui() { super.initGui() - powerButton = new ImageButton(0, guiLeft + 5, guiTop + 139 - deltaY, 18, 18, Textures.guiButtonPower, canToggle = true) + powerButton = new ImageButton(0, guiLeft + 5, guiTop + 153 - deltaY, 18, 18, Textures.guiButtonPower, canToggle = true) scrollButton = new ImageButton(1, guiLeft + scrollX + 1, guiTop + scrollY + 1, 6, 13, Textures.guiButtonScroll) add(buttonList, powerButton) add(buttonList, scrollButton) @@ -119,9 +118,13 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten if (buffer != null) { GL11.glTranslatef(bufferX, bufferY, 0) RenderState.disableLighting() + GL11.glPushMatrix() + GL11.glTranslatef(-2, -2, 0) + BufferRenderer.drawBackground() + GL11.glPopMatrix() RenderState.makeItBlend() - val scaleX = (bufferWidth - 2) / buffer.renderWidth - val scaleY = (bufferHeight - 2) / buffer.renderHeight + val scaleX = bufferWidth / buffer.renderWidth + val scaleY = bufferHeight / buffer.renderHeight val scale = math.min(scaleX, scaleY) if (scaleX > scale) { GL11.glTranslated(buffer.renderWidth * (scaleX - scale) / 2, 0, 0) @@ -129,7 +132,7 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten else if (scaleY > scale) { GL11.glTranslated(0, buffer.renderHeight * (scaleY - scale) / 2, 0) } - GL11.glScaled(scale, scale, scale) +// GL11.glScaled(scale, scale, scale) GL11.glScaled(this.scale, this.scale, 1) BufferRenderer.drawText(buffer) } @@ -138,7 +141,7 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten protected override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int) { drawBufferLayer() GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS) // Me lazy... prevents NEI render glitch. - if (isPointInRegion(powerX, powerY, powerWidth, powerHeight, mouseX, mouseY)) { + if (isPointInRegion(power.x, power.y, power.width, power.height, mouseX, mouseY)) { val tooltip = new java.util.ArrayList[String] val format = Localization.Robot.Power + ": %d%% (%d/%d)" tooltip.add(format.format( @@ -160,7 +163,8 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten if (buffer != null) mc.renderEngine.bindTexture(Textures.guiRobot) else mc.renderEngine.bindTexture(Textures.guiRobotNoScreen) drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize) - drawPowerLevel() + power.level = robot.globalBuffer / robot.globalBufferSize + drawWidgets() if (robot.inventorySize > 0) { drawSelection() } @@ -249,8 +253,11 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten override protected def changeSize(w: Double, h: Double, recompile: Boolean) = { val bw = w * TextBufferRenderCache.renderer.charRenderWidth val bh = h * TextBufferRenderCache.renderer.charRenderHeight - val scaleX = math.min(bufferWidth / (bw + bufferMargin * 2.0), 1) - val scaleY = math.min(bufferHeight / (bh + bufferMargin * 2.0), 1) + val scaleX = math.min(bufferWidth / bw, 1) + val scaleY = math.min(bufferHeight / bh, 1) + if (recompile) { + BufferRenderer.compileBackground(bufferWidth.toInt, bufferHeight.toInt, forRobot = true) + } math.min(scaleX, scaleY) } @@ -273,24 +280,4 @@ class Robot(playerInventory: InventoryPlayer, val robot: tileentity.Robot) exten t.draw() } } - - private def drawPowerLevel() { - val level = robot.globalBuffer / robot.globalBufferSize - - val u0 = 0 - val u1 = powerWidth / 256.0 * level - val v0 = 1 - powerHeight / 256.0 - val v1 = 1 - val x = guiLeft + powerX - val y = guiTop + powerY - val w = powerWidth * level - - val t = Tessellator.instance - t.startDrawingQuads() - t.addVertexWithUV(x, y, zLevel, u0, v0) - t.addVertexWithUV(x, y + powerHeight, zLevel, u0, v1) - t.addVertexWithUV(x + w, y + powerHeight, zLevel, u1, v1) - t.addVertexWithUV(x + w, y, zLevel, u1, v0) - t.draw() - } } \ No newline at end of file diff --git a/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala b/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala index f0fc4e39b..6c263e7d3 100644 --- a/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala +++ b/src/main/scala/li/cil/oc/client/gui/RobotAssembler.scala @@ -3,11 +3,11 @@ package li.cil.oc.client.gui import java.util import li.cil.oc.api.driver.{Inventory, Memory, Processor, Slot} +import li.cil.oc.client.gui.widget.ProgressBar import li.cil.oc.client.{Textures, PacketSender => ClientPacketSender} import li.cil.oc.common.{container, tileentity} import li.cil.oc.{Localization, api} import net.minecraft.client.gui.GuiButton -import net.minecraft.client.renderer.Tessellator import net.minecraft.entity.player.InventoryPlayer import org.lwjgl.opengl.GL11 @@ -22,11 +22,7 @@ class RobotAssembler(playerInventory: InventoryPlayer, val assembler: tileentity protected var runButton: ImageButton = _ - private val progressX = 28 - private val progressY = 92 - - private val progressWidth = 140 - private val progressHeight = 12 + private val progress = addWidget(new ProgressBar(28, 92)) val suggestedComponents = Array( "Screen" -> (() => hasComponent("screen1")), @@ -140,7 +136,7 @@ class RobotAssembler(playerInventory: InventoryPlayer, val assembler: tileentity drawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRenderer) } } - else if (isPointInRegion(progressX, progressY, progressWidth, progressHeight, mouseX, mouseY)) { + else if (isPointInRegion(progress.x, progress.y, progress.width, progress.height, mouseX, mouseY)) { val tooltip = new java.util.ArrayList[String] val timeRemaining = formatTime(assemblerContainer.assemblyRemainingTime) tooltip.add(Localization.RobotAssembler.Progress(assemblerContainer.assemblyProgress, timeRemaining)) @@ -160,30 +156,10 @@ class RobotAssembler(playerInventory: InventoryPlayer, val assembler: tileentity super.drawGuiContainerBackgroundLayer(dt, mouseX, mouseY) mc.renderEngine.bindTexture(Textures.guiRobotAssembler) drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize) - if (assemblerContainer.isAssembling) { - drawProgress() - } + if (assemblerContainer.isAssembling) progress.level = assemblerContainer.assemblyProgress / 100.0 + else progress.level = 0 + drawWidgets() } override def doesGuiPauseGame = false - - private def drawProgress() { - val level = assemblerContainer.assemblyProgress / 100.0 - - val u0 = 0 - val u1 = progressWidth / 256.0 * level - val v0 = 1 - progressHeight / 256.0 - val v1 = 1 - val x = guiLeft + progressX - val y = guiTop + progressY - val w = progressWidth * level - - val t = Tessellator.instance - t.startDrawingQuads() - t.addVertexWithUV(x, y, zLevel, u0, v0) - t.addVertexWithUV(x, y + progressHeight, zLevel, u0, v1) - t.addVertexWithUV(x + w, y + progressHeight, zLevel, u1, v1) - t.addVertexWithUV(x + w, y, zLevel, u1, v0) - t.draw() - } } \ No newline at end of file diff --git a/src/main/scala/li/cil/oc/client/gui/TextBuffer.scala b/src/main/scala/li/cil/oc/client/gui/TextBuffer.scala index 98a4c4dc0..c4e12a2c7 100644 --- a/src/main/scala/li/cil/oc/client/gui/TextBuffer.scala +++ b/src/main/scala/li/cil/oc/client/gui/TextBuffer.scala @@ -50,6 +50,7 @@ trait TextBuffer extends GuiScreen { } protected def drawBufferLayer() { + if (buffer == null) return val oldWidth = currentWidth val oldHeight = currentHeight if (buffer != null) { diff --git a/src/main/scala/li/cil/oc/client/gui/widget/ProgressBar.scala b/src/main/scala/li/cil/oc/client/gui/widget/ProgressBar.scala new file mode 100644 index 000000000..7f9beb31e --- /dev/null +++ b/src/main/scala/li/cil/oc/client/gui/widget/ProgressBar.scala @@ -0,0 +1,34 @@ +package li.cil.oc.client.gui.widget + +import li.cil.oc.client.Textures +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.Tessellator + +class ProgressBar(val x: Int, val y: Int) extends Widget { + override def width = 140 + + override def height = 12 + + var level = 0.0 + + def draw() { + if (level > 0) { + val u0 = 0 + val u1 = width / 256.0 * level + val v0 = 1 - height / 256.0 + val v1 = 1 + val tx = owner.windowX + x + val ty = owner.windowY + y + val w = width * level + + Minecraft.getMinecraft.renderEngine.bindTexture(Textures.guiBar) + val t = Tessellator.instance + t.startDrawingQuads() + t.addVertexWithUV(tx, ty, owner.windowZ, u0, v0) + t.addVertexWithUV(tx, ty + height, owner.windowZ, u0, v1) + t.addVertexWithUV(tx + w, ty + height, owner.windowZ, u1, v1) + t.addVertexWithUV(tx + w, ty, owner.windowZ, u1, v0) + t.draw() + } + } +} diff --git a/src/main/scala/li/cil/oc/client/gui/widget/Widget.scala b/src/main/scala/li/cil/oc/client/gui/widget/Widget.scala new file mode 100644 index 000000000..c97facd41 --- /dev/null +++ b/src/main/scala/li/cil/oc/client/gui/widget/Widget.scala @@ -0,0 +1,15 @@ +package li.cil.oc.client.gui.widget + +abstract class Widget { + var owner: WidgetContainer = _ + + def x: Int + + def y: Int + + def width: Int + + def height: Int + + def draw() +} diff --git a/src/main/scala/li/cil/oc/client/gui/widget/WidgetContainer.scala b/src/main/scala/li/cil/oc/client/gui/widget/WidgetContainer.scala new file mode 100644 index 000000000..dbb010e44 --- /dev/null +++ b/src/main/scala/li/cil/oc/client/gui/widget/WidgetContainer.scala @@ -0,0 +1,25 @@ +package li.cil.oc.client.gui.widget + +import net.minecraft.client.gui.inventory.GuiContainer + +import scala.collection.mutable + +trait WidgetContainer { self: GuiContainer => + protected val widgets = mutable.ArrayBuffer.empty[Widget] + + def addWidget[T <: Widget](widget: T) = { + widgets += widget + widget.owner = this + widget + } + + def windowX = guiLeft + + def windowY = guiTop + + def windowZ = zLevel + + def drawWidgets() { + widgets.foreach(_.draw()) + } +} diff --git a/src/main/scala/li/cil/oc/client/renderer/gui/BufferRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/gui/BufferRenderer.scala index 15600d552..fd854b788 100644 --- a/src/main/scala/li/cil/oc/client/renderer/gui/BufferRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/gui/BufferRenderer.scala @@ -25,7 +25,7 @@ object BufferRenderer { RenderState.checkError(getClass.getName + ".displayLists: leaving") }) - def compileBackground(bufferWidth: Int, bufferHeight: Int) = + def compileBackground(bufferWidth: Int, bufferHeight: Int, forRobot: Boolean = false) = if (textureManager.isDefined) { RenderState.checkError(getClass.getName + ".compileBackground: entering (aka: wasntme)") @@ -38,10 +38,8 @@ object BufferRenderer { GL11.glBegin(GL11.GL_QUADS) - val c0 = 0 - val c1 = 7 - val c2 = 9 - val c3 = 16 + val margin = if (forRobot) 1 else 7 + val (c0, c1, c2, c3) = if (forRobot) (5, 7, 9, 11) else (0, 7, 9, 16) // Top border (left corner, middle bar, right corner). drawBorder( diff --git a/src/main/scala/li/cil/oc/common/container/Robot.scala b/src/main/scala/li/cil/oc/common/container/Robot.scala index a558e9080..af623d838 100644 --- a/src/main/scala/li/cil/oc/common/container/Robot.scala +++ b/src/main/scala/li/cil/oc/common/container/Robot.scala @@ -14,17 +14,17 @@ class Robot(playerInventory: InventoryPlayer, robot: tileentity.Robot) extends P case Some(buffer: api.component.TextBuffer) => true case _ => false } - private val withScreenHeight = 242 + private val withScreenHeight = 256 private val noScreenHeight = 108 val deltaY = if (hasScreen) 0 else withScreenHeight - noScreenHeight - addSlotToContainer(170 + 0 * slotSize, 218 - deltaY, api.driver.Slot.Tool) - addSlotToContainer(170 + 1 * slotSize, 218 - deltaY, robot.containerSlotType(1), robot.containerSlotTier(1)) - addSlotToContainer(170 + 2 * slotSize, 218 - deltaY, robot.containerSlotType(2), robot.containerSlotTier(2)) - addSlotToContainer(170 + 3 * slotSize, 218 - deltaY, robot.containerSlotType(3), robot.containerSlotTier(3)) + addSlotToContainer(170 + 0 * slotSize, 232 - deltaY, api.driver.Slot.Tool) + addSlotToContainer(170 + 1 * slotSize, 232 - deltaY, robot.containerSlotType(1), robot.containerSlotTier(1)) + addSlotToContainer(170 + 2 * slotSize, 232 - deltaY, robot.containerSlotType(2), robot.containerSlotTier(2)) + addSlotToContainer(170 + 3 * slotSize, 232 - deltaY, robot.containerSlotType(3), robot.containerSlotTier(3)) for (i <- 0 to 3) { - val y = 142 + i * slotSize - deltaY + val y = 156 + i * slotSize - deltaY for (j <- 0 to 3) { val x = 170 + j * slotSize addSlotToContainer(new InventorySlot(this, otherInventory, inventorySlots.size, x, y)) @@ -34,7 +34,7 @@ class Robot(playerInventory: InventoryPlayer, robot: tileentity.Robot) extends P addSlotToContainer(new InventorySlot(this, otherInventory, inventorySlots.size, -10000, -10000)) } - addPlayerInventorySlots(6, 160 - deltaY) + addPlayerInventorySlots(6, 174 - deltaY) // This factor is used to make the energy values transferable using // MCs 'progress bar' stuff, even though those internally send the