From decdd3a87b52c458ec8b9ff1697bdb2f7d69429a Mon Sep 17 00:00:00 2001 From: CrazyPants Date: Fri, 12 Sep 2014 22:57:06 +0800 Subject: [PATCH] Right mouse button now goes 'back' on the color and redstone mode buttons. --- .../crazypants/enderio/gui/ColorButton.java | 24 ++++++++++++++ .../enderio/gui/RedstoneModeButton.java | 31 ++++++++++++++++--- .../enderio/machine/RedstoneControlMode.java | 9 ++++++ 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/main/java/crazypants/enderio/gui/ColorButton.java b/src/main/java/crazypants/enderio/gui/ColorButton.java index c79b0ede..cf62007b 100644 --- a/src/main/java/crazypants/enderio/gui/ColorButton.java +++ b/src/main/java/crazypants/enderio/gui/ColorButton.java @@ -1,10 +1,13 @@ package crazypants.enderio.gui; +import java.awt.Rectangle; + import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; import net.minecraft.item.ItemDye; import net.minecraft.util.MathHelper; +import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import crazypants.gui.IGuiScreen; @@ -15,6 +18,8 @@ public class ColorButton extends IconButtonEIO { private int colorIndex = 0; private String tooltipPrefix = ""; + + private boolean rightMouseDown = false; public ColorButton(IGuiScreen gui, int id, int x, int y) { super(gui, id, x, y, null); @@ -48,6 +53,14 @@ public class ColorButton extends IconButtonEIO { } setColorIndex(colorIndex); } + + private void prevColor() { + colorIndex--; + if(colorIndex < 0) { + colorIndex = ItemDye.field_150923_a.length - 1; + } + setColorIndex(colorIndex); + } public int getColorIndex() { return colorIndex; @@ -67,6 +80,17 @@ public class ColorButton extends IconButtonEIO { public void drawButton(Minecraft mc, int mouseX, int mouseY) { super.drawButton(mc, mouseX, mouseY); if(visible) { + + Rectangle r = new Rectangle(xPosition, yPosition, width, height); + if(r.contains(mouseX, mouseY)) { + if(rightMouseDown && Mouse.getEventButton() == 1 && !Mouse.getEventButtonState()) { + prevColor(); + } + rightMouseDown = Mouse.getEventButton() == 1 && Mouse.getEventButtonState(); + } else { + rightMouseDown = false; + } + Tessellator tes = Tessellator.instance; tes.startDrawingQuads(); diff --git a/src/main/java/crazypants/enderio/gui/RedstoneModeButton.java b/src/main/java/crazypants/enderio/gui/RedstoneModeButton.java index 2b6d63ca..b36f3d76 100644 --- a/src/main/java/crazypants/enderio/gui/RedstoneModeButton.java +++ b/src/main/java/crazypants/enderio/gui/RedstoneModeButton.java @@ -1,5 +1,9 @@ package crazypants.enderio.gui; +import java.awt.Rectangle; + +import org.lwjgl.input.Mouse; + import net.minecraft.client.Minecraft; import crazypants.enderio.machine.IRedstoneModeControlable; import crazypants.enderio.machine.PacketRedstoneMode; @@ -14,12 +18,14 @@ public class RedstoneModeButton extends IconButtonEIO { private static IconEIO[] ICONS = new IconEIO[] { IconEIO.REDSTONE_MODE_ALWAYS, IconEIO.REDSTONE_MODE_WITH_SIGNAL, IconEIO.REDSTONE_MODE_WITHOUT_SIGNAL, IconEIO.REDSTONE_MODE_NEVER }; - IRedstoneModeControlable model; - RedstoneControlMode curMode; + private IRedstoneModeControlable model; + private RedstoneControlMode curMode; + + private boolean rightMouseDown = false; - BlockCoord bc; + private BlockCoord bc; - String tooltipKey = "enderio.gui.tooltip.redstoneControlMode"; + private String tooltipKey = "enderio.gui.tooltip.redstoneControlMode"; public RedstoneModeButton(IGuiScreen gui, int id, int x, int y, IRedstoneModeControlable model) { this(gui, id, x, y, model, null); @@ -58,6 +64,13 @@ public class RedstoneModeButton extends IconButtonEIO { } setMode(curMode.next()); } + + private void prevMode() { + if(curMode == null) { + curMode = RedstoneControlMode.ON; + } + setMode(curMode.previous()); + } public void setMode(RedstoneControlMode mode) { if(mode == curMode) { @@ -75,6 +88,16 @@ public class RedstoneModeButton extends IconButtonEIO { @Override public void drawButton(Minecraft mc, int mouseX, int mouseY) { super.drawButton(mc, mouseX, mouseY); + + Rectangle r = new Rectangle(xPosition, yPosition, width, height); + if(r.contains(mouseX, mouseY)) { + if(rightMouseDown && Mouse.getEventButton() == 1 && !Mouse.getEventButtonState()) { + prevMode(); + } + rightMouseDown = Mouse.getEventButton() == 1 && Mouse.getEventButtonState(); + } else { + rightMouseDown = false; + } } } diff --git a/src/main/java/crazypants/enderio/machine/RedstoneControlMode.java b/src/main/java/crazypants/enderio/machine/RedstoneControlMode.java index cca71877..633cf6dc 100644 --- a/src/main/java/crazypants/enderio/machine/RedstoneControlMode.java +++ b/src/main/java/crazypants/enderio/machine/RedstoneControlMode.java @@ -47,4 +47,13 @@ public enum RedstoneControlMode { return values()[ord]; } + public RedstoneControlMode previous() { + int ord = ordinal(); + ord--; + if(ord < 0) { + ord = values().length - 1; + } + return values()[ord]; + } + }