Made GuiDraggingNumberInput fully functional

Linked GuiObjectManager to new Keybinding
Renamed RoundUtils#round to RoundUtils#round2Decimals for easier understanding
This commit is contained in:
CrushedPixel
2015-07-08 12:13:23 +02:00
parent 54f35eca03
commit e26e09a264
7 changed files with 76 additions and 19 deletions

View File

@@ -108,12 +108,12 @@ public class GuiEditKeyframe extends GuiScreen {
//Position/Virtual Time Input
if(posKeyframe) {
Position pos = ((Keyframe<Position>)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);

View File

@@ -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);
}
}

View File

@@ -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);
}