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 000000000..fac816754 Binary files /dev/null and b/src/main/resources/assets/opencomputers/textures/gui/bar.png differ diff --git a/src/main/resources/assets/opencomputers/textures/gui/disassembler.png b/src/main/resources/assets/opencomputers/textures/gui/disassembler.png index 24cc4cccc..e1870e211 100644 Binary files a/src/main/resources/assets/opencomputers/textures/gui/disassembler.png and b/src/main/resources/assets/opencomputers/textures/gui/disassembler.png differ diff --git a/src/main/resources/assets/opencomputers/textures/gui/robot.png b/src/main/resources/assets/opencomputers/textures/gui/robot.png index 6d4200f7c..175015ea0 100644 Binary files a/src/main/resources/assets/opencomputers/textures/gui/robot.png and b/src/main/resources/assets/opencomputers/textures/gui/robot.png differ 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 51d082204..308dea6f4 100644 Binary files a/src/main/resources/assets/opencomputers/textures/gui/robot_assembler.png and b/src/main/resources/assets/opencomputers/textures/gui/robot_assembler.png differ 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 18a0807ac..f2c80254a 100644 Binary files a/src/main/resources/assets/opencomputers/textures/gui/robot_noscreen.png and b/src/main/resources/assets/opencomputers/textures/gui/robot_noscreen.png differ diff --git a/src/main/scala/li/cil/oc/client/Textures.scala b/src/main/scala/li/cil/oc/client/Textures.scala index b717dfbb0..52df95840 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 { 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 { tm.bindTexture(fontAliased) tm.bindTexture(guiBackground) + tm.bindTexture(guiBar) tm.bindTexture(guiBorders) tm.bindTexture(guiButtonPower) tm.bindTexture(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 ad85bab36..b64c7140b 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) = { fontRendererObj.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 61e7245ac..984c77696 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) @@ -102,9 +101,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) @@ -112,7 +115,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) } @@ -121,7 +124,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 (func_146978_c(powerX, powerY, powerWidth, powerHeight, mouseX, mouseY)) { + if (func_146978_c(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( @@ -143,7 +146,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() } @@ -260,8 +264,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) } @@ -284,24 +291,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 2da524f15..fc579b1d8 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, fontRendererObj) } } - else if (func_146978_c(progressX, progressY, progressWidth, progressHeight, mouseX, mouseY)) { + else if (func_146978_c(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 14218aad0..6ead080a7 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 ea3aadde8..b95332f43 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 @@ -26,7 +26,7 @@ object BufferRenderer { Textures.init(tm) }) - 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)") @@ -39,10 +39,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