From e26e09a264c7f4b274208b015f37224ad7b9e13d Mon Sep 17 00:00:00 2001 From: CrushedPixel Date: Wed, 8 Jul 2015 12:13:23 +0200 Subject: [PATCH] Made GuiDraggingNumberInput fully functional Linked GuiObjectManager to new Keybinding Renamed RoundUtils#round to RoundUtils#round2Decimals for easier understanding --- .../events/handlers/KeyInputHandler.java | 5 +++ .../replaymod/gui/GuiEditKeyframe.java | 12 ++--- .../replaymod/gui/GuiObjectManager.java | 44 ++++++++++++++++--- .../gui/elements/GuiDraggingNumberInput.java | 25 ++++++++--- .../replaymod/registry/KeybindRegistry.java | 2 + .../replaymod/utils/RoundUtils.java | 2 +- .../assets/replaymod/lang/en_US.lang | 5 ++- 7 files changed, 76 insertions(+), 19 deletions(-) diff --git a/src/main/java/eu/crushedpixel/replaymod/events/handlers/KeyInputHandler.java b/src/main/java/eu/crushedpixel/replaymod/events/handlers/KeyInputHandler.java index da7cf3a6..863adb56 100755 --- a/src/main/java/eu/crushedpixel/replaymod/events/handlers/KeyInputHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/handlers/KeyInputHandler.java @@ -5,6 +5,7 @@ import eu.crushedpixel.replaymod.entities.CameraEntity.MoveDirection; import eu.crushedpixel.replaymod.gui.GuiAssetManager; import eu.crushedpixel.replaymod.gui.GuiKeyframeRepository; import eu.crushedpixel.replaymod.gui.GuiMouseInput; +import eu.crushedpixel.replaymod.gui.GuiObjectManager; import eu.crushedpixel.replaymod.recording.ConnectionEventHandler; import eu.crushedpixel.replaymod.registry.KeybindRegistry; import eu.crushedpixel.replaymod.registry.PlayerHandler; @@ -205,5 +206,9 @@ public class KeyInputHandler { if(kb.getKeyDescription().equals(KeybindRegistry.KEY_ASSET_MANAGER) && (kb.isPressed() || kb.getKeyCode() == keyCode)) { mc.displayGuiScreen(new GuiAssetManager()); } + + if(kb.getKeyDescription().equals(KeybindRegistry.KEY_OBJECT_MANAGER) && (kb.isPressed() || kb.getKeyCode() == keyCode)) { + mc.displayGuiScreen(new GuiObjectManager()); + } } } diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiEditKeyframe.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiEditKeyframe.java index fd548665..d49ae34d 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiEditKeyframe.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiEditKeyframe.java @@ -108,12 +108,12 @@ public class GuiEditKeyframe extends GuiScreen { //Position/Virtual Time Input if(posKeyframe) { Position pos = ((Keyframe)keyframe).getValue(); - xCoord = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round(pos.getX()), true); - yCoord = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round(pos.getY()), true); - zCoord = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round(pos.getZ()), true); - yaw = new GuiNumberInput(fontRendererObj, 0, 0, 100, -90d, 90d, RoundUtils.round(pos.getYaw()), true); - pitch = new GuiNumberInput(fontRendererObj, 0, 0, 100, -180d, 180d, RoundUtils.round(pos.getPitch()), true); - roll = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round(pos.getRoll()), true); + xCoord = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getX()), true); + yCoord = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getY()), true); + zCoord = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getZ()), true); + yaw = new GuiNumberInput(fontRendererObj, 0, 0, 100, -90d, 90d, RoundUtils.round2Decimals(pos.getYaw()), true); + pitch = new GuiNumberInput(fontRendererObj, 0, 0, 100, -180d, 180d, RoundUtils.round2Decimals(pos.getPitch()), true); + roll = new GuiNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getRoll()), true); posInputs.add(xCoord); posInputs.add(yCoord); diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiObjectManager.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiObjectManager.java index 5522b1cb..16dd6065 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiObjectManager.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiObjectManager.java @@ -1,6 +1,10 @@ package eu.crushedpixel.replaymod.gui; +import eu.crushedpixel.replaymod.gui.elements.ComposedElement; +import eu.crushedpixel.replaymod.gui.elements.GuiDraggingNumberInput; +import eu.crushedpixel.replaymod.utils.MouseUtils; import net.minecraft.client.gui.GuiScreen; +import org.lwjgl.util.Point; import java.io.IOException; @@ -8,38 +12,68 @@ public class GuiObjectManager extends GuiScreen { private boolean initialized = false; + private GuiDraggingNumberInput anchorXInput, anchorYInput, anchorZInput; + + private ComposedElement numberInputs; + @Override public void initGui() { - super.initGui(); + if(!initialized) { + anchorXInput = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 50, null, null, 0d, true); + anchorYInput = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 50, null, null, 0d, true); + anchorZInput = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 50, null, null, 0d, true); + + numberInputs = new ComposedElement(anchorXInput, anchorYInput, anchorZInput); + } + + anchorXInput.width = anchorYInput.width = anchorZInput.width = 45; + anchorXInput.yPosition = anchorYInput.yPosition = anchorZInput.yPosition = 50; + + anchorXInput.xPosition = 20; + anchorYInput.xPosition = anchorXInput.xPosition+anchorXInput.width + 5; + anchorZInput.xPosition = anchorYInput.xPosition+anchorYInput.width + 5; + + initialized = true; } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.drawDefaultBackground(); + + numberInputs.draw(mc, mouseX, mouseY); + super.drawScreen(mouseX, mouseY, partialTicks); } @Override protected void keyTyped(char typedChar, int keyCode) throws IOException { + Point mousePos = MouseUtils.getMousePos(); + numberInputs.buttonPressed(mc, mousePos.getX(), mousePos.getY(), typedChar, keyCode); + super.keyTyped(typedChar, keyCode); } @Override public void updateScreen() { + numberInputs.tick(mc); super.updateScreen(); } @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + numberInputs.mouseClick(mc, mouseX, mouseY, mouseButton); super.mouseClicked(mouseX, mouseY, mouseButton); } @Override - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); + protected void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) { + numberInputs.mouseDrag(mc, mouseX, mouseY, mouseButton); + super.mouseClickMove(mouseX, mouseY, mouseButton, timeSinceLastClick); } @Override - protected void mouseReleased(int mouseX, int mouseY, int state) { - super.mouseReleased(mouseX, mouseY, state); + protected void mouseReleased(int mouseX, int mouseY, int mouseButton) { + numberInputs.mouseRelease(mc, mouseX, mouseY, mouseButton); + super.mouseReleased(mouseX, mouseY, mouseButton); } } diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiDraggingNumberInput.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiDraggingNumberInput.java index 857ccb48..227f063c 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiDraggingNumberInput.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiDraggingNumberInput.java @@ -1,27 +1,39 @@ package eu.crushedpixel.replaymod.gui.elements; +import eu.crushedpixel.replaymod.utils.MouseUtils; +import eu.crushedpixel.replaymod.utils.RoundUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; -public class GuiDraggingNumberInput extends GuiNumberInput { +public class GuiDraggingNumberInput extends GuiNumberInputWithText { public GuiDraggingNumberInput(FontRenderer fontRenderer, int xPos, int yPos, int width, Double minimum, Double maximum, Double defaultValue, boolean acceptFloats) { - super(fontRenderer, xPos, yPos, width, minimum, maximum, defaultValue, acceptFloats); + this(fontRenderer, xPos, yPos, width, minimum, maximum, defaultValue, acceptFloats, ""); + } + + public GuiDraggingNumberInput(FontRenderer fontRenderer, + int xPos, int yPos, int width, Double minimum, + Double maximum, Double defaultValue, boolean acceptFloats, String suffix) { + super(fontRenderer, xPos, yPos, width, minimum, maximum, defaultValue, acceptFloats, suffix); } private int prevMouseX; private boolean dragging; + private boolean clicked; @Override public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { - dragging = false; - prevMouseX = mouseX; + if(MouseUtils.isMouseWithinBounds(xPosition, yPosition, width, height)) { + dragging = false; + clicked = true; + prevMouseX = mouseX; + } } @Override public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) { - if(mouseX != prevMouseX) { + if(clicked && mouseX != prevMouseX) { dragging = true; int diff = mouseX - prevMouseX; prevMouseX = mouseX; @@ -33,7 +45,7 @@ public class GuiDraggingNumberInput extends GuiNumberInput { } double value = getPreciseValue(); - double valueDiff = (diff/200) * bounds; + double valueDiff = RoundUtils.round2Decimals((diff / 200f) * bounds); this.setValue(value+valueDiff); } @@ -42,6 +54,7 @@ public class GuiDraggingNumberInput extends GuiNumberInput { @Override public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) { + clicked = false; if(!dragging) { super.mouseClick(mc, mouseX, mouseY, button); } diff --git a/src/main/java/eu/crushedpixel/replaymod/registry/KeybindRegistry.java b/src/main/java/eu/crushedpixel/replaymod/registry/KeybindRegistry.java index ef2d0bc8..c8ecbf9e 100755 --- a/src/main/java/eu/crushedpixel/replaymod/registry/KeybindRegistry.java +++ b/src/main/java/eu/crushedpixel/replaymod/registry/KeybindRegistry.java @@ -23,6 +23,7 @@ public class KeybindRegistry { public static final String KEY_ADD_MARKER = "replaymod.input.marker"; public static final String KEY_PATH_PREVIEW = "replaymod.input.pathpreview"; public static final String KEY_ASSET_MANAGER = "replaymod.input.assetmanager"; + public static final String KEY_OBJECT_MANAGER = "replaymod.input.objectmanager"; private static Minecraft mc = Minecraft.getMinecraft(); public static void initialize() { @@ -41,6 +42,7 @@ public class KeybindRegistry { bindings.add(new KeyBinding(KEY_PLAY_PAUSE, Keyboard.KEY_P, "replaymod.title")); bindings.add(new KeyBinding(KEY_PATH_PREVIEW, Keyboard.KEY_H, "replaymod.title")); bindings.add(new KeyBinding(KEY_ASSET_MANAGER, Keyboard.KEY_G, "replaymod.title")); + bindings.add(new KeyBinding(KEY_OBJECT_MANAGER, Keyboard.KEY_F, "replaymod.title")); mc.gameSettings.keyBindings = bindings.toArray(new KeyBinding[bindings.size()]); diff --git a/src/main/java/eu/crushedpixel/replaymod/utils/RoundUtils.java b/src/main/java/eu/crushedpixel/replaymod/utils/RoundUtils.java index bb4289f0..d90e8ff6 100644 --- a/src/main/java/eu/crushedpixel/replaymod/utils/RoundUtils.java +++ b/src/main/java/eu/crushedpixel/replaymod/utils/RoundUtils.java @@ -2,6 +2,6 @@ package eu.crushedpixel.replaymod.utils; public class RoundUtils { - public static double round(double val) { return Math.round(val*100.0) / 100.0; } + public static double round2Decimals(double val) { return Math.round(val*100.0) / 100.0; } } diff --git a/src/main/resources/assets/replaymod/lang/en_US.lang b/src/main/resources/assets/replaymod/lang/en_US.lang index 1d4ced1c..a59a2914 100644 --- a/src/main/resources/assets/replaymod/lang/en_US.lang +++ b/src/main/resources/assets/replaymod/lang/en_US.lang @@ -258,6 +258,7 @@ replaymod.input.playpause=Play/Pause Replay replaymod.input.marker=Add Event Marker replaymod.input.pathpreview=Toggle Path Preview replaymod.input.assetmanager=Open Asset Manager +replaymod.input.objectmanager=Open Object Manager #Keyframe Presets GUI replaymod.gui.keyframerepository.title=Keyframe Repository @@ -363,4 +364,6 @@ replaymod.gui.assets.filechooser=Asset File replaymod.gui.assets.defaultname=New Asset replaymod.gui.assets.emptylist=No Assets available replaymod.gui.assets.namehint=Asset Name -replaymod.gui.assets.changefile=Change Asset File \ No newline at end of file +replaymod.gui.assets.changefile=Change Asset File + +#Object Manager Gui