From 18da4361f97a27ce2197cb6c5672914385d6bf32 Mon Sep 17 00:00:00 2001 From: johni0702 Date: Mon, 22 Aug 2016 12:24:59 +0200 Subject: [PATCH] Add guis for editing keyframes --- .../simplepathing/gui/GuiEditKeyframe.java | 213 ++++++++++++++++++ .../gui/GuiKeyframeTimeline.java | 5 +- .../simplepathing/gui/GuiPathing.java | 15 +- 3 files changed, 226 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/replaymod/simplepathing/gui/GuiEditKeyframe.java diff --git a/src/main/java/com/replaymod/simplepathing/gui/GuiEditKeyframe.java b/src/main/java/com/replaymod/simplepathing/gui/GuiEditKeyframe.java new file mode 100644 index 00000000..335d79cf --- /dev/null +++ b/src/main/java/com/replaymod/simplepathing/gui/GuiEditKeyframe.java @@ -0,0 +1,213 @@ +package com.replaymod.simplepathing.gui; + +import com.replaymod.pathing.properties.CameraProperties; +import com.replaymod.pathing.properties.TimestampProperty; +import com.replaymod.replay.ReplayModReplay; +import com.replaymod.replaystudio.pathing.change.Change; +import com.replaymod.replaystudio.pathing.change.CombinedChange; +import com.replaymod.replaystudio.pathing.change.UpdateKeyframeProperties; +import com.replaymod.replaystudio.pathing.path.Keyframe; +import com.replaymod.replaystudio.pathing.path.Path; +import de.johni0702.minecraft.gui.container.GuiPanel; +import de.johni0702.minecraft.gui.element.GuiButton; +import de.johni0702.minecraft.gui.element.GuiLabel; +import de.johni0702.minecraft.gui.element.GuiNumberField; +import de.johni0702.minecraft.gui.element.IGuiLabel; +import de.johni0702.minecraft.gui.layout.GridLayout; +import de.johni0702.minecraft.gui.layout.HorizontalLayout; +import de.johni0702.minecraft.gui.layout.VerticalLayout; +import de.johni0702.minecraft.gui.popup.AbstractGuiPopup; +import de.johni0702.minecraft.gui.utils.Colors; +import org.apache.commons.lang3.tuple.Triple; + +import static de.johni0702.minecraft.gui.utils.Utils.link; + +public abstract class GuiEditKeyframe> extends AbstractGuiPopup { + private static GuiNumberField newGuiNumberField() { + return new GuiNumberField().setPrecision(0).setValidateOnFocusChange(true); + } + + protected final Keyframe keyframe; + protected final Path path; + + public final GuiLabel title = new GuiLabel(); + + public final GuiPanel inputs = new GuiPanel(); + + public final GuiNumberField timeMinField = newGuiNumberField().setSize(30, 20).setMinValue(0); + public final GuiNumberField timeSecField = newGuiNumberField().setSize(20, 20).setMinValue(0).setMaxValue(59); + public final GuiNumberField timeMSecField = newGuiNumberField().setSize(30, 20).setMinValue(0).setMaxValue(999); + + public final GuiPanel timePanel = new GuiPanel() + .setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(3)) + .addElements(new HorizontalLayout.Data(0.5), + new GuiLabel().setI18nText("replaymod.gui.editkeyframe.timelineposition"), + timeMinField, new GuiLabel().setI18nText("replaymod.gui.minutes"), + timeSecField, new GuiLabel().setI18nText("replaymod.gui.seconds"), + timeMSecField, new GuiLabel().setI18nText("replaymod.gui.milliseconds")); + + public final GuiButton saveButton = new GuiButton().setSize(150, 20).setI18nLabel("replaymod.gui.save"); + + public final GuiButton cancelButton = new GuiButton() + .onClick(this::close).setSize(150, 20).setI18nLabel("replaymod.gui.cancel"); + + public final GuiPanel buttons = new GuiPanel() + .setLayout(new HorizontalLayout(HorizontalLayout.Alignment.CENTER).setSpacing(7)) + .addElements(new HorizontalLayout.Data(0.5), saveButton, cancelButton); + + { + setBackgroundColor(Colors.DARK_TRANSPARENT); + + popup.setLayout(new VerticalLayout().setSpacing(10)) + .addElements(new VerticalLayout.Data(0.5), title, inputs, timePanel, buttons); + } + + public GuiEditKeyframe(GuiPathing gui, Path path, Keyframe keyframe, String type) { + super(ReplayModReplay.instance.getReplayHandler().getOverlay()); + this.keyframe = keyframe; + this.path = path; + + long time = keyframe.getTime(); + timeMinField.setValue(time / 1000 / 60); + timeSecField.setValue(time / 1000 % 60); + timeMSecField.setValue(time % 1000); + + title.setI18nText("replaymod.gui.editkeyframe.title." + type); + saveButton.onClick(() -> { + Change change = save(); + long newTime = (timeMinField.getInteger() * 60 + timeSecField.getInteger()) * 1000 + timeMSecField.getInteger(); + if (newTime != keyframe.getTime()) { + change = CombinedChange.createFromApplied(change, gui.moveKeyframe(path, keyframe, newTime)); + } + path.getTimeline().pushChange(change); + close(); + }); + } + + @Override + public void open() { + super.open(); + } + + protected abstract Change save(); + + public static class Spectator extends GuiEditKeyframe { + public Spectator(GuiPathing gui, Path path, Keyframe keyframe) { + super(gui, path, keyframe, "spec"); + + link(timeMinField, timeSecField, timeMSecField); + + popup.forEach(IGuiLabel.class).setColor(Colors.BLACK); + } + + @Override + protected Change save() { + return CombinedChange.createFromApplied(); + } + + @Override + protected Spectator getThis() { + return this; + } + } + + public static class Time extends GuiEditKeyframe