Reworked GuiEditKeyframe to use ComposedElements
Made GuiArrowButton a subclass of GuiAdvancedButton Added consistency to ReplayHandler by renaming getMarkers() to getMarkerKeyframes() and removing redundant methods which can be accessed via KeyframeList class
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
package eu.crushedpixel.replaymod.gui;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiAdvancedTextField;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiArrowButton;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiDraggingNumberInput;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiNumberInput;
|
||||
import eu.crushedpixel.replaymod.gui.elements.*;
|
||||
import eu.crushedpixel.replaymod.holders.AdvancedPosition;
|
||||
import eu.crushedpixel.replaymod.holders.Keyframe;
|
||||
import eu.crushedpixel.replaymod.holders.Marker;
|
||||
import eu.crushedpixel.replaymod.holders.TimestampValue;
|
||||
import eu.crushedpixel.replaymod.interpolation.KeyframeList;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import eu.crushedpixel.replaymod.utils.RoundUtils;
|
||||
import eu.crushedpixel.replaymod.utils.TimestampUtils;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -18,17 +16,17 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.util.Point;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiEditKeyframe extends GuiScreen {
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private GuiButton saveButton, cancelButton;
|
||||
private GuiAdvancedButton saveButton, cancelButton;
|
||||
private GuiArrowButton leftButton, rightButton;
|
||||
|
||||
private GuiNumberInput xCoord, yCoord, zCoord, pitch, yaw, roll;
|
||||
@@ -36,8 +34,8 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
|
||||
private GuiAdvancedTextField markerNameInput;
|
||||
|
||||
private List<GuiTextField> inputs = new ArrayList<GuiTextField>();
|
||||
private List<GuiTextField> posInputs = new ArrayList<GuiTextField>();
|
||||
private ComposedElement inputs;
|
||||
private ComposedElement posInputs;
|
||||
|
||||
private int virtualHeight = 200;
|
||||
private int virtualY;
|
||||
@@ -66,7 +64,7 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
|
||||
KeyframeList<AdvancedPosition> positionKeyframes = ReplayHandler.getPositionKeyframes();
|
||||
KeyframeList<TimestampValue> timeKeyframes = ReplayHandler.getTimeKeyframes();
|
||||
KeyframeList<Marker> markerKeyframes = ReplayHandler.getMarkers();
|
||||
KeyframeList<Marker> markerKeyframes = ReplayHandler.getMarkerKeyframes();
|
||||
|
||||
if(posKeyframe) {
|
||||
previous = positionKeyframes.getPreviousKeyframe(keyframe.getRealTimestamp() - 1);
|
||||
@@ -93,24 +91,50 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
virtualY = this.height - virtualHeight - 10;
|
||||
|
||||
if(!initialized) {
|
||||
saveButton = new GuiButton(GuiConstants.KEYFRAME_EDITOR_SAVE_BUTTON, 0, 0, 100, 20, I18n.format("replaymod.gui.save"));
|
||||
cancelButton = new GuiButton(GuiConstants.KEYFRAME_EDITOR_CANCEL_BUTTON, 0, 0, 100, 20, I18n.format("replaymod.gui.cancel"));
|
||||
saveButton = new GuiAdvancedButton(GuiConstants.KEYFRAME_EDITOR_SAVE_BUTTON, 0, 0, I18n.format("replaymod.gui.save")) {
|
||||
@Override
|
||||
public void performAction() {
|
||||
save = true;
|
||||
mc.displayGuiScreen(null);
|
||||
}
|
||||
};
|
||||
|
||||
leftButton = new GuiArrowButton(GuiConstants.KEYFRAME_EDITOR_LEFT_BUTTON, 0, 0, "", GuiArrowButton.Direction.LEFT);
|
||||
rightButton = new GuiArrowButton(GuiConstants.KEYFRAME_EDITOR_RIGHT_BUTTON, 0, 0, "", GuiArrowButton.Direction.RIGHT);
|
||||
cancelButton = new GuiAdvancedButton(GuiConstants.KEYFRAME_EDITOR_CANCEL_BUTTON, 0, 0, I18n.format("replaymod.gui.cancel")) {
|
||||
@Override
|
||||
public void performAction() {
|
||||
save = false;
|
||||
mc.displayGuiScreen(null);
|
||||
}
|
||||
};
|
||||
|
||||
leftButton = new GuiArrowButton(GuiConstants.KEYFRAME_EDITOR_LEFT_BUTTON, 0, 0, "", GuiArrowButton.Direction.LEFT) {
|
||||
@Override
|
||||
public void performAction() {
|
||||
save = true;
|
||||
mc.displayGuiScreen(new GuiEditKeyframe(previous));
|
||||
}
|
||||
};
|
||||
|
||||
rightButton = new GuiArrowButton(GuiConstants.KEYFRAME_EDITOR_RIGHT_BUTTON, 0, 0, "", GuiArrowButton.Direction.RIGHT){
|
||||
@Override
|
||||
public void performAction() {
|
||||
save = true;
|
||||
mc.displayGuiScreen(new GuiEditKeyframe(next));
|
||||
}
|
||||
};
|
||||
|
||||
saveButton.width = cancelButton.width = 100;
|
||||
|
||||
leftButton.enabled = previous != null;
|
||||
rightButton.enabled = next != null;
|
||||
|
||||
//Real Time Input
|
||||
int timestamp = keyframe.getRealTimestamp();
|
||||
min = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 30, 0d, 9d, (double)TimestampUtils.getMinutesFromTimestamp(timestamp), false);
|
||||
sec = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 25, 0d, 59d, (double)TimestampUtils.getSecondsFromTimestamp(timestamp), false);
|
||||
ms = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 35, 0d, 999d, (double)TimestampUtils.getMillisecondsFromTimestamp(timestamp), false);
|
||||
min = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 30, 0d, 9d, (double)TimestampUtils.getMinutesFromTimestamp(timestamp), false, "", 1);
|
||||
sec = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 25, 0d, 59d, (double)TimestampUtils.getSecondsFromTimestamp(timestamp), false, "", 1);
|
||||
ms = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 35, 0d, 999d, (double)TimestampUtils.getMillisecondsFromTimestamp(timestamp), false, "", 1);
|
||||
|
||||
inputs.add(min);
|
||||
inputs.add(sec);
|
||||
inputs.add(ms);
|
||||
inputs = new ComposedElement(min, sec, ms, saveButton, cancelButton, leftButton, rightButton);
|
||||
|
||||
//Position/Virtual Time Input
|
||||
if(posKeyframe) {
|
||||
@@ -122,14 +146,8 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
pitch = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 100, -180d, 180d, RoundUtils.round2Decimals(pos.getPitch()), true);
|
||||
roll = new GuiDraggingNumberInput(fontRendererObj, 0, 0, 100, null, null, RoundUtils.round2Decimals(pos.getRoll()), true);
|
||||
|
||||
posInputs.add(xCoord);
|
||||
posInputs.add(yCoord);
|
||||
posInputs.add(zCoord);
|
||||
posInputs.add(yaw);
|
||||
posInputs.add(pitch);
|
||||
posInputs.add(roll);
|
||||
|
||||
inputs.addAll(posInputs);
|
||||
posInputs = new ComposedElement(xCoord, yCoord, zCoord, yaw, pitch, roll);
|
||||
inputs.addPart(posInputs);
|
||||
} else if(markerKeyframe) {
|
||||
String name = ((Keyframe<Marker>)keyframe).getValue().getName();
|
||||
if(name == null) name = "";
|
||||
@@ -137,7 +155,7 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
markerNameInput.hint = I18n.format("replaymod.gui.editkeyframe.markername");
|
||||
markerNameInput.setText(name);
|
||||
|
||||
inputs.add(markerNameInput);
|
||||
inputs.addPart(markerNameInput);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,10 +187,13 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
|
||||
int x = w + left + 5;
|
||||
int i = 0;
|
||||
for(GuiTextField input : posInputs) {
|
||||
input.xPosition = i < 3 ? x : left+totalWidth-100;
|
||||
input.yPosition = i < 3 ? virtualY + 20 + i*30 : virtualY + 20 + (i-3)*30;
|
||||
i++;
|
||||
for(GuiElement input : posInputs.getParts()) {
|
||||
if(input instanceof GuiTextField) {
|
||||
GuiTextField textField = (GuiTextField)input;
|
||||
textField.xPosition = i < 3 ? x : left+totalWidth-100;
|
||||
textField.yPosition = i < 3 ? virtualY + 20 + i*30 : virtualY + 20 + (i-3)*30;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
} else if(markerKeyframe) {
|
||||
markerNameInput.xPosition = width/2 - 100;
|
||||
@@ -207,8 +228,8 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
ReplayHandler.addKeyframe(keyframeBackup);
|
||||
ReplayHandler.selectKeyframe(keyframeBackup);
|
||||
} else {
|
||||
ReplayHandler.getMarkers().remove(keyframe);
|
||||
ReplayHandler.getMarkers().add(keyframeBackup);
|
||||
ReplayHandler.getMarkerKeyframes().remove(keyframe);
|
||||
ReplayHandler.getMarkerKeyframes().add(keyframeBackup);
|
||||
ReplayHandler.selectMarkerKeyframe(keyframeBackup);
|
||||
}
|
||||
} else {
|
||||
@@ -227,9 +248,8 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
for(GuiTextField input : inputs) {
|
||||
if(input != null) input.textboxKeyTyped(typedChar, keyCode);
|
||||
}
|
||||
Point mousePos = MouseUtils.getMousePos();
|
||||
inputs.buttonPressed(mc, mousePos.getX(), mousePos.getY(), typedChar, keyCode);
|
||||
|
||||
if(keyCode == Keyboard.KEY_ESCAPE) {
|
||||
save = false;
|
||||
@@ -239,17 +259,25 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
for(GuiTextField input : inputs) {
|
||||
if(input != null) input.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
inputs.mouseClick(mc, mouseX, mouseY, mouseButton);
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
inputs.mouseDrag(mc, mouseX, mouseY, clickedMouseButton);
|
||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
inputs.mouseRelease(mc, mouseX, mouseY, state);
|
||||
super.mouseReleased(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
for(GuiTextField input : inputs) {
|
||||
if(input != null) input.updateCursorCounter();
|
||||
}
|
||||
inputs.tick(mc);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -271,28 +299,8 @@ public class GuiEditKeyframe extends GuiScreen {
|
||||
drawString(fontRendererObj, I18n.format("replaymod.gui.editkeyframe.camroll"), left+totalWidth-100-5-w2, virtualY + 87, Color.WHITE.getRGB());
|
||||
}
|
||||
|
||||
for(GuiTextField input : inputs) {
|
||||
if(input != null) input.drawTextBox();
|
||||
}
|
||||
inputs.draw(mc, mouseX, mouseY);
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if(!button.enabled) return;
|
||||
if(button.id == GuiConstants.KEYFRAME_EDITOR_SAVE_BUTTON) {
|
||||
save = true;
|
||||
mc.displayGuiScreen(null);
|
||||
} else if(button.id == GuiConstants.KEYFRAME_EDITOR_CANCEL_BUTTON) {
|
||||
save = false;
|
||||
mc.displayGuiScreen(null);
|
||||
} else if(button.id == GuiConstants.KEYFRAME_EDITOR_LEFT_BUTTON) {
|
||||
save = false;
|
||||
mc.displayGuiScreen(new GuiEditKeyframe(previous));
|
||||
} else if(button.id == GuiConstants.KEYFRAME_EDITOR_RIGHT_BUTTON) {
|
||||
save = false;
|
||||
mc.displayGuiScreen(new GuiEditKeyframe(next));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiArrowButton extends GuiButton {
|
||||
public class GuiArrowButton extends GuiAdvancedButton {
|
||||
|
||||
public enum Direction {
|
||||
UP, DOWN, RIGHT, LEFT
|
||||
|
||||
@@ -40,7 +40,7 @@ public class GuiMarkerTimeline extends GuiTimeline {
|
||||
|
||||
Keyframe<Marker> closest = null;
|
||||
if(mouseY >= positionY + BORDER_TOP + 10) {
|
||||
closest = ReplayHandler.getClosestMarkerForRealTime((int) time, tolerance);
|
||||
closest = ReplayHandler.getMarkerKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance);
|
||||
}
|
||||
|
||||
ReplayHandler.selectMarkerKeyframe(closest);
|
||||
@@ -75,7 +75,7 @@ public class GuiMarkerTimeline extends GuiTimeline {
|
||||
|
||||
Keyframe<Marker> closest = null;
|
||||
if(mouseY >= positionY + BORDER_TOP + 10) {
|
||||
closest = ReplayHandler.getClosestMarkerForRealTime((int) time, tolerance);
|
||||
closest = ReplayHandler.getMarkerKeyframes().getClosestKeyframeForTimestamp((int) time, tolerance);
|
||||
}
|
||||
|
||||
if(closest != null) {
|
||||
@@ -125,7 +125,7 @@ public class GuiMarkerTimeline extends GuiTimeline {
|
||||
drawTimelineCursor(leftTime, rightTime, bodyWidth);
|
||||
|
||||
//Draw Keyframe logos
|
||||
for(Keyframe<Marker> kf : ReplayHandler.getMarkers()) {
|
||||
for(Keyframe<Marker> kf : ReplayHandler.getMarkerKeyframes()) {
|
||||
if (kf != null && !kf.equals(ReplayHandler.getSelectedMarkerKeyframe()))
|
||||
drawKeyframe(kf, bodyWidth, leftTime, rightTime, segmentLength);
|
||||
}
|
||||
@@ -150,7 +150,7 @@ public class GuiMarkerTimeline extends GuiTimeline {
|
||||
long leftTime = Math.round(timeStart * timelineLength);
|
||||
double segmentLength = timelineLength * zoom;
|
||||
|
||||
for(Keyframe<Marker> marker : ReplayHandler.getMarkers()) {
|
||||
for(Keyframe<Marker> marker : ReplayHandler.getMarkerKeyframes()) {
|
||||
int keyframeX = getKeyframeX(marker.getRealTimestamp(), leftTime, bodyWidth, segmentLength);
|
||||
|
||||
if(MouseUtils.isMouseWithinBounds(keyframeX - 2, this.positionY + BORDER_TOP + 10 + 1, 5, 5)) {
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ReplayHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public static KeyframeList<Marker> getMarkers() {
|
||||
public static KeyframeList<Marker> getMarkerKeyframes() {
|
||||
return markerKeyframes;
|
||||
}
|
||||
|
||||
@@ -291,54 +291,6 @@ public class ReplayHandler {
|
||||
fireKeyframesModifyEvent();
|
||||
}
|
||||
|
||||
public static Keyframe<Marker> getClosestMarkerForRealTime(int realTime, int tolerance) {
|
||||
List<Keyframe<Marker>> found = new ArrayList<Keyframe<Marker>>();
|
||||
for(Keyframe<Marker> kf : markerKeyframes) {
|
||||
if(Math.abs(kf.getRealTimestamp() - realTime) <= tolerance) {
|
||||
found.add(kf);
|
||||
}
|
||||
}
|
||||
|
||||
Keyframe<Marker> closest = null;
|
||||
|
||||
for(Keyframe<Marker> kf : found) {
|
||||
if(closest == null || Math.abs(closest.getRealTimestamp() - realTime) > Math.abs(kf.getRealTimestamp() - realTime)) {
|
||||
closest = kf;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
|
||||
public static Keyframe<Marker> getPreviousMarkerKeyframe(int realTime) {
|
||||
if(markerKeyframes.isEmpty()) return null;
|
||||
Keyframe<Marker> backup = null;
|
||||
List<Keyframe<Marker>> found = new ArrayList<Keyframe<Marker>>();
|
||||
for(Keyframe<Marker> kf : markerKeyframes) {
|
||||
if(kf.getRealTimestamp() < realTime) {
|
||||
found.add((Keyframe<Marker>)kf);
|
||||
} else if(kf.getRealTimestamp() == realTime) {
|
||||
backup = (Keyframe<Marker>)kf;
|
||||
}
|
||||
}
|
||||
|
||||
if(found.size() > 0)
|
||||
return found.get(found.size() - 1); //last element is nearest
|
||||
else return backup;
|
||||
}
|
||||
|
||||
public static Keyframe<Marker> getNextMarkerKeyframe(int realTime) {
|
||||
if(markerKeyframes.isEmpty()) return null;
|
||||
Keyframe<Marker> backup = null;
|
||||
for(Keyframe<Marker> kf : markerKeyframes) {
|
||||
if(kf.getRealTimestamp() > realTime) {
|
||||
return kf; //first found element is next
|
||||
} else if(kf.getRealTimestamp() == realTime) {
|
||||
backup = kf;
|
||||
}
|
||||
}
|
||||
return backup;
|
||||
}
|
||||
|
||||
public static KeyframeList<AdvancedPosition> getPositionKeyframes() {
|
||||
return positionKeyframes;
|
||||
}
|
||||
@@ -388,8 +340,8 @@ public class ReplayHandler {
|
||||
selectedKeyframe = kf;
|
||||
}
|
||||
|
||||
public static boolean isSelected(Keyframe<Marker> kf) {
|
||||
return kf == selectedMarkerKeyframe || kf == selectedMarkerKeyframe;
|
||||
public static boolean isSelected(Keyframe kf) {
|
||||
return kf == selectedKeyframe || kf == selectedMarkerKeyframe;
|
||||
}
|
||||
|
||||
public static void selectMarkerKeyframe(Keyframe<Marker> kf) { selectedMarkerKeyframe = kf; }
|
||||
@@ -521,7 +473,7 @@ public class ReplayHandler {
|
||||
//only if Marker keyframes changed, rewrite them
|
||||
if(!initialMarkers.equals(markerKeyframes)) {
|
||||
File markerFile = File.createTempFile(ReplayFile.ENTRY_MARKERS, "json");
|
||||
ReplayFileIO.write(getMarkers(), markerFile);
|
||||
ReplayFileIO.write(getMarkerKeyframes(), markerFile);
|
||||
ReplayMod.replayFileAppender.registerModifiedFile(markerFile, ReplayFile.ENTRY_MARKERS, ReplayHandler.getReplayFile());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user