diff --git a/src/main/java/com/moulberry/flashback/editor/ui/ImGuiHelper.java b/src/main/java/com/moulberry/flashback/editor/ui/ImGuiHelper.java index cb95b2e..4c459c5 100644 --- a/src/main/java/com/moulberry/flashback/editor/ui/ImGuiHelper.java +++ b/src/main/java/com/moulberry/flashback/editor/ui/ImGuiHelper.java @@ -8,6 +8,7 @@ import imgui.flag.ImGuiComboFlags; import imgui.flag.ImGuiHoveredFlags; import imgui.flag.ImGuiInputTextFlags; import imgui.flag.ImGuiNavInput; +import imgui.flag.ImGuiStyleVar; import imgui.flag.ImGuiWindowFlags; import imgui.type.ImBoolean; import imgui.type.ImFloat; diff --git a/src/main/java/com/moulberry/flashback/editor/ui/ReplayUI.java b/src/main/java/com/moulberry/flashback/editor/ui/ReplayUI.java index 0e31601..4339d0c 100644 --- a/src/main/java/com/moulberry/flashback/editor/ui/ReplayUI.java +++ b/src/main/java/com/moulberry/flashback/editor/ui/ReplayUI.java @@ -216,10 +216,16 @@ public class ReplayUI { fontConfig.setOversampleV(2); fontConfig.setName("Inter (Medium), 16px"); + fontConfig.setGlyphOffset(0, 0); font = fonts.addFontFromMemoryTTF(loadFont("inter-medium.ttf"), size, fontConfig, glyphRanges); // Merge in Japanese/Korean/Chinese/etc. characters if needed fontConfig.setMergeMode(true); + + fontConfig.setGlyphOffset(0, (int)(5 * getUiScale())); + io.getFonts().addFontFromMemoryTTF(loadFont("materialiconsround-regular.otf"), (int)(20 * getUiScale()), fontConfig, buildMaterialIconRanges()); + fontConfig.setGlyphOffset(0, 0); + if (languageCode.startsWith("he")) { short[] hebrewRanges = new short[]{(short)'\u0590', (short)'\u05FF', (short)'\uFB1D', (short)'\uFB4F', 0}; io.getFonts().addFontFromMemoryTTF(loadFont("heebo-medium.ttf"), size, fontConfig, hebrewRanges); @@ -241,6 +247,25 @@ public class ReplayUI { fonts.clearTexData(); } + private static short[] buildMaterialIconRanges() { + ImFontGlyphRangesBuilder builder = new ImFontGlyphRangesBuilder(); + builder.addChar('\ue04b'); + builder.addChar('\ue577'); + builder.addChar('\uefeb'); + builder.addChar('\ue3af'); + builder.addChar('\ue9e4'); + builder.addChar('\ue422'); + builder.addChar('\ue518'); + builder.addChar('\ue945'); + builder.addChar('\ue8f4'); + builder.addChar('\ue8f5'); + builder.addChar('\ue148'); + builder.addChar('\ue5d2'); + builder.addChar('\ue872'); + builder.addChar('\ue3c9'); + return builder.buildRanges(); + } + private static byte[] loadFont(String name) { try { var resource = Minecraft.getInstance().getResourceManager().getResource(Flashback.createResourceLocation(name)); diff --git a/src/main/java/com/moulberry/flashback/editor/ui/windows/TimelineWindow.java b/src/main/java/com/moulberry/flashback/editor/ui/windows/TimelineWindow.java index 463dc26..1eddff4 100644 --- a/src/main/java/com/moulberry/flashback/editor/ui/windows/TimelineWindow.java +++ b/src/main/java/com/moulberry/flashback/editor/ui/windows/TimelineWindow.java @@ -27,12 +27,18 @@ import com.moulberry.flashback.record.FlashbackMeta; import com.moulberry.flashback.state.KeyframeTrack; import imgui.ImDrawList; import imgui.ImGui; +import imgui.flag.ImGuiButtonFlags; +import imgui.flag.ImGuiComboFlags; +import imgui.flag.ImGuiCond; +import imgui.flag.ImGuiDragDropFlags; import imgui.flag.ImGuiHoveredFlags; +import imgui.flag.ImGuiInputTextFlags; import imgui.flag.ImGuiMouseButton; import imgui.flag.ImGuiMouseCursor; import imgui.flag.ImGuiPopupFlags; import imgui.flag.ImGuiStyleVar; import imgui.flag.ImGuiWindowFlags; +import imgui.type.ImString; import it.unimi.dsi.fastutil.ints.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; @@ -58,6 +64,7 @@ public class TimelineWindow { private static int grabbedKeyframeTick = 0; private static int grabbedKeyframeTrack = 0; private static int draggingMouseButton = ImGuiMouseButton.Left; + private static int repositioningKeyframeTrack = 0; private static float dragStartMouseX = 0; private static float dragStartMouseY = 0; @@ -84,6 +91,9 @@ public class TimelineWindow { private static int pendingStepBackwardsTicks = 0; private static int cursorTicks; + private static long lastRenderNanos = 0; + private static long renderDeltaNanos = 0; + private static boolean hoveredControls; private static boolean hoveredSkipBackwards; private static boolean hoveredSlowDown; @@ -174,6 +184,10 @@ public class TimelineWindow { } } + long currentTime = System.nanoTime(); + renderDeltaNanos = Math.max(0, Math.min(1_000_000_000, currentTime - lastRenderNanos)); + lastRenderNanos = currentTime; + mouseX = ImGui.getMousePosX(); mouseY = ImGui.getMousePosY(); @@ -457,6 +471,38 @@ public class TimelineWindow { dragStartMouseX = mouseX; dragStartMouseY = mouseY; } else if (ImGui.isMouseDragging(draggingMouseButton)) { + if (repositioningKeyframeTrack >= 0 && repositioningKeyframeTrack < editorState.keyframeTracks.size()) { + float lineHeight = ImGui.getTextLineHeightWithSpacing() + ImGui.getStyle().getItemSpacingY(); + + float mouseDeltaY = mouseY - dragStartMouseY; + if (mouseDeltaY > lineHeight/2) { + if (repositioningKeyframeTrack < editorState.keyframeTracks.size()-1) { + selectedKeyframesList.clear(); + editingKeyframeTrack = -1; + editingKeyframeTick = -1; + + dragStartMouseY += lineHeight; + + var track = editorState.keyframeTracks.remove(repositioningKeyframeTrack); + editorState.keyframeTracks.get(repositioningKeyframeTrack).animatedOffsetInUi += lineHeight; + repositioningKeyframeTrack += 1; + editorState.keyframeTracks.add(repositioningKeyframeTrack, track); + } + } else if (mouseDeltaY < -lineHeight/2) { + if (repositioningKeyframeTrack > 0) { + selectedKeyframesList.clear(); + editingKeyframeTrack = -1; + editingKeyframeTick = -1; + + dragStartMouseY -= lineHeight; + + var track = editorState.keyframeTracks.remove(repositioningKeyframeTrack); + repositioningKeyframeTrack -= 1; + editorState.keyframeTracks.get(repositioningKeyframeTrack).animatedOffsetInUi -= lineHeight; + editorState.keyframeTracks.add(repositioningKeyframeTrack, track); + } + } + } if (grabbedExportBarResizeLeft) { ImGui.setMouseCursor(ImGuiMouseCursor.ResizeEW); @@ -1078,8 +1124,10 @@ public class TimelineWindow { grabbedZoomBarResizeRight = false; grabbedExportBarResizeLeft = false; grabbedExportBarResizeRight = false; + if (!ImGui.isAnyMouseDown()) { trackDisabledButtonDrag = false; + repositioningKeyframeTrack = -1; } if (dragSelectOrigin != null) { @@ -1511,6 +1559,8 @@ public class TimelineWindow { boolean hasOpenPopup = false; + double animationMultiplier = Math.pow(0.9D, renderDeltaNanos / 10_000_000D); + for (int trackIndex = 0; trackIndex < editorState.keyframeTracks.size(); trackIndex++) { KeyframeTrack keyframeTrack = editorState.keyframeTracks.get(trackIndex); KeyframeType keyframeType = keyframeTrack.keyframeType; @@ -1533,12 +1583,68 @@ public class TimelineWindow { } } - ImGui.setCursorPosX(8); + String icon = keyframeType.icon(); + String name = keyframeTrack.customName; + if (name == null) { + name = keyframeType.name(); + } + String nameWithIcon = name; + if (icon != null) { + nameWithIcon = icon + " " + name; + } - if (keyframeTrack.enabled) { - ImGui.text(keyframeType.name()); + keyframeTrack.animatedOffsetInUi *= animationMultiplier; + if (Math.abs(keyframeTrack.animatedOffsetInUi) < 1) { + keyframeTrack.animatedOffsetInUi = 0; + } + + float trackOffset = repositioningKeyframeTrack == trackIndex ? mouseY - dragStartMouseY : (int) keyframeTrack.animatedOffsetInUi; + ImGui.setCursorPosX(repositioningKeyframeTrack == trackIndex ? 3 : 2); + ImGui.setCursorPosY(ImGui.getCursorPosY() + trackOffset); + + ImGui.pushStyleVar(ImGuiStyleVar.ItemSpacing, 0, 0); + if (repositioningKeyframeTrack == trackIndex) { + ImGui.text("\ue945"); } else { - ImGui.textDisabled(keyframeType.name()); + ImGui.textDisabled("\ue945"); + if (ImGui.isItemClicked(ImGuiMouseButton.Left)) { + repositioningKeyframeTrack = trackIndex; + } + } + ImGui.sameLine(); + ImGui.popStyleVar(); + + if (keyframeTrack.nameEditField != null) { + ImGui.pushStyleVar(ImGuiStyleVar.ItemSpacing, 0, 0); + ImGui.pushStyleVar(ImGuiStyleVar.FramePadding, 0, 0); + if (icon != null) { + ImGui.text(icon + " "); + ImGui.sameLine(); + } + ImGui.setNextItemWidth(120); + if (keyframeTrack.forceFocusTrack) { + keyframeTrack.forceFocusTrack = false; + ImGui.setKeyboardFocusHere(); + } + boolean returnValue = ImGui.inputText("##TrackName", keyframeTrack.nameEditField, ImGuiInputTextFlags.EnterReturnsTrue | ImGuiInputTextFlags.AutoSelectAll); + if (returnValue || ImGui.isItemDeactivated()) { + keyframeTrack.customName = ImGuiHelper.getString(keyframeTrack.nameEditField).trim(); + if (keyframeTrack.customName.isEmpty() || keyframeTrack.customName.equals(keyframeType.name())) { + keyframeTrack.customName = null; + } + keyframeTrack.nameEditField = null; + } + ImGui.popStyleVar(2); + } else { + if (keyframeTrack.enabled) { + ImGui.text(nameWithIcon); + } else { + ImGui.textDisabled(nameWithIcon); + } + if (ImGui.isItemClicked(ImGuiMouseButton.Left) && ImGui.isMouseDoubleClicked(ImGuiMouseButton.Left)) { + keyframeTrack.nameEditField = ImGuiHelper.createResizableImString(name); + keyframeTrack.forceFocusTrack = true; + } } ImGui.sameLine(); @@ -1546,11 +1652,41 @@ public class TimelineWindow { float buttonX = x + middleX - (buttonSize + spacingX) * 3; float buttonY = ImGui.getCursorScreenPosY(); ImGui.setCursorPosX(buttonX - x); - if (ImGui.button("##Add", buttonSize, buttonSize)) { + if (ImGui.invisibleButton("##TrackOptions", buttonSize, buttonSize) || ImGui.isItemClicked(ImGuiMouseButton.Right)) { + ImGui.openPopup("##TrackPopup"); + } + drawList.addText(buttonX - 2, buttonY, -1, "\ue5d2"); + ImGuiHelper.tooltip("Open track options"); + + ImGui.sameLine(); + + buttonX += buttonSize + spacingX; + ImGui.setCursorPosX(buttonX - x); + ImGui.invisibleButton("##ToggleEnabled", buttonSize, buttonSize); + if (ImGui.isItemHovered(trackDisabledButtonDrag ? ImGuiHoveredFlags.AllowWhenBlockedByActiveItem : 0)) { + if (trackDisabledButtonDrag) { + keyframeTrack.enabled = trackDisabledButtonDragValue; + } else if (ImGui.isMouseClicked(ImGuiMouseButton.Left, false)) { + keyframeTrack.enabled = !keyframeTrack.enabled; + trackDisabledButtonDragValue = keyframeTrack.enabled; + trackDisabledButtonDrag = true; + } + } + if (keyframeTrack.enabled) { + drawList.addText(buttonX - 2, buttonY, -1, "\ue8f4"); + ImGuiHelper.tooltip("Disable keyframe track"); + } else { + drawList.addText(buttonX - 2, buttonY, -1, "\ue8f5"); + ImGuiHelper.tooltip("Enable keyframe track"); + } + ImGui.sameLine(); + + buttonX += buttonSize + spacingX; + ImGui.setCursorPosX(buttonX - x); + if (ImGui.invisibleButton("##Add", buttonSize, buttonSize)) { createNewKeyframe(editorState, trackIndex, cursorTicks, keyframeType, keyframeTrack); } - drawList.addRectFilled(buttonX + 2, buttonY + buttonSize/2 - 1, buttonX + buttonSize - 2, buttonY + buttonSize/2 + 1, -1); - drawList.addRectFilled(buttonX + buttonSize/2 - 1, buttonY + 2, buttonX + buttonSize/2 + 1, buttonY + buttonSize - 2, -1); + drawList.addText(buttonX - 2, buttonY, -1, "\ue148"); ImGuiHelper.tooltip("Add keyframe"); if (ImGui.beginPopup("##CreateKeyframe")) { @@ -1566,38 +1702,18 @@ public class TimelineWindow { } ImGui.endPopup(); } - - ImGui.sameLine(); - - buttonX += buttonSize + spacingX; - ImGui.setCursorPosX(buttonX - x); - if (ImGui.button("##Clear", buttonSize, buttonSize)) { - keyframeTrackToClear = trackIndex; - } - drawList.addRectFilled(buttonX + 2, buttonY + buttonSize/2 - 1, buttonX + buttonSize - 2, buttonY + buttonSize/2 + 1, -1); - ImGuiHelper.tooltip("Remove all keyframes"); - - ImGui.sameLine(); - - buttonX += buttonSize + spacingX; - ImGui.setCursorPosX(buttonX - x); - ImGui.button("##ToggleEnabled", buttonSize, buttonSize); - if (ImGui.isItemHovered(trackDisabledButtonDrag ? ImGuiHoveredFlags.AllowWhenBlockedByActiveItem : 0)) { - if (trackDisabledButtonDrag) { - keyframeTrack.enabled = trackDisabledButtonDragValue; - } else if (ImGui.isMouseClicked(ImGuiMouseButton.Left, false)) { - keyframeTrack.enabled = !keyframeTrack.enabled; - trackDisabledButtonDragValue = keyframeTrack.enabled; - trackDisabledButtonDrag = true; + if (ImGui.beginPopup("##TrackPopup")) { + if (ImGui.menuItem("\ue3c9 Rename")) { + keyframeTrack.nameEditField = ImGuiHelper.createResizableImString(name); + keyframeTrack.forceFocusTrack = true; } + if (ImGui.menuItem("\ue872 Delete track")) { + keyframeTrackToClear = trackIndex; + } + ImGui.endPopup(); } - if (keyframeTrack.enabled) { - drawList.addCircleFilled(buttonX + buttonSize/2, buttonY + buttonSize/2, buttonSize/3, -1); - ImGuiHelper.tooltip("Disable keyframe track"); - } else { - drawList.addCircle(buttonX + buttonSize/2, buttonY + buttonSize/2, buttonSize/3, -1, 16, 2); - ImGuiHelper.tooltip("Enable keyframe track"); - } + + ImGui.setCursorPosY(ImGui.getCursorPosY() - trackOffset); ImGui.separator(); @@ -1631,6 +1747,16 @@ public class TimelineWindow { if (ImGui.smallButton("Add Element")) { ImGui.openPopup("##AddKeyframeElement"); } + + ImGui.sameLine(); + + ImGui.setNextItemWidth(middleX - ImGui.getCursorPosX() - spacingX); + ImGui.pushStyleVar(ImGuiStyleVar.FramePadding, 4, 0); + ImGuiHelper.combo("##SceneSwitcher", new int[]{0}, new String[]{ + "Scene 1", "\ue148 New Scene" + }); + ImGui.popStyleVar(); + if (ImGui.beginPopup("##AddKeyframeElement")) { for (KeyframeType type : KeyframeRegistry.getTypes()) { if (ImGui.selectable(type.name())) { diff --git a/src/main/java/com/moulberry/flashback/keyframe/KeyframeType.java b/src/main/java/com/moulberry/flashback/keyframe/KeyframeType.java index 91a2712..af24a69 100644 --- a/src/main/java/com/moulberry/flashback/keyframe/KeyframeType.java +++ b/src/main/java/com/moulberry/flashback/keyframe/KeyframeType.java @@ -1,13 +1,12 @@ package com.moulberry.flashback.keyframe; -import com.moulberry.flashback.keyframe.handler.KeyframeHandler; -import com.moulberry.flashback.state.KeyframeTrack; import org.jetbrains.annotations.Nullable; -import java.util.function.Consumer; - public interface KeyframeType { + default @Nullable String icon() { + return null; + } String name(); String id(); @Nullable T createDirect(); diff --git a/src/main/java/com/moulberry/flashback/keyframe/types/CameraKeyframeType.java b/src/main/java/com/moulberry/flashback/keyframe/types/CameraKeyframeType.java index a743f7d..235d736 100644 --- a/src/main/java/com/moulberry/flashback/keyframe/types/CameraKeyframeType.java +++ b/src/main/java/com/moulberry/flashback/keyframe/types/CameraKeyframeType.java @@ -14,6 +14,11 @@ public class CameraKeyframeType implements KeyframeType { private CameraKeyframeType() { } + @Override + public @Nullable String icon() { + return "\ue04b"; + } + @Override public String name() { return "Camera"; diff --git a/src/main/java/com/moulberry/flashback/keyframe/types/CameraOrbitKeyframeType.java b/src/main/java/com/moulberry/flashback/keyframe/types/CameraOrbitKeyframeType.java index c7ca82e..98a1466 100644 --- a/src/main/java/com/moulberry/flashback/keyframe/types/CameraOrbitKeyframeType.java +++ b/src/main/java/com/moulberry/flashback/keyframe/types/CameraOrbitKeyframeType.java @@ -22,6 +22,11 @@ public class CameraOrbitKeyframeType implements KeyframeType { private FOVKeyframeType() { } + @Override + public @Nullable String icon() { + return "\ue3af"; + } + @Override public String name() { return "FOV"; diff --git a/src/main/java/com/moulberry/flashback/keyframe/types/SpeedKeyframeType.java b/src/main/java/com/moulberry/flashback/keyframe/types/SpeedKeyframeType.java index 107209d..c96e965 100644 --- a/src/main/java/com/moulberry/flashback/keyframe/types/SpeedKeyframeType.java +++ b/src/main/java/com/moulberry/flashback/keyframe/types/SpeedKeyframeType.java @@ -20,6 +20,11 @@ public class SpeedKeyframeType implements KeyframeType { private SpeedKeyframeType() { } + @Override + public @Nullable String icon() { + return "\ue9e4"; + } + @Override public String name() { return "Speed"; diff --git a/src/main/java/com/moulberry/flashback/keyframe/types/TimeOfDayKeyframeType.java b/src/main/java/com/moulberry/flashback/keyframe/types/TimeOfDayKeyframeType.java index ca67224..563fd83 100644 --- a/src/main/java/com/moulberry/flashback/keyframe/types/TimeOfDayKeyframeType.java +++ b/src/main/java/com/moulberry/flashback/keyframe/types/TimeOfDayKeyframeType.java @@ -20,6 +20,11 @@ public class TimeOfDayKeyframeType implements KeyframeType { private TimeOfDayKeyframeType() { } + @Override + public @Nullable String icon() { + return "\ue518"; + } + @Override public String name() { return "Time of day"; diff --git a/src/main/java/com/moulberry/flashback/keyframe/types/TimelapseKeyframeType.java b/src/main/java/com/moulberry/flashback/keyframe/types/TimelapseKeyframeType.java index 2bf7814..e3efae4 100644 --- a/src/main/java/com/moulberry/flashback/keyframe/types/TimelapseKeyframeType.java +++ b/src/main/java/com/moulberry/flashback/keyframe/types/TimelapseKeyframeType.java @@ -15,6 +15,11 @@ public class TimelapseKeyframeType implements KeyframeType { private TimelapseKeyframeType() { } + @Override + public @Nullable String icon() { + return "\ue422"; + } + @Override public String name() { return "Timelapse"; diff --git a/src/main/java/com/moulberry/flashback/state/KeyframeTrack.java b/src/main/java/com/moulberry/flashback/state/KeyframeTrack.java index 28d5f21..1e59de0 100644 --- a/src/main/java/com/moulberry/flashback/state/KeyframeTrack.java +++ b/src/main/java/com/moulberry/flashback/state/KeyframeTrack.java @@ -9,6 +9,7 @@ import com.moulberry.flashback.keyframe.handler.ReplayServerKeyframeHandler; import com.moulberry.flashback.keyframe.impl.TimelapseKeyframe; import com.moulberry.flashback.keyframe.interpolation.SidedInterpolationType; import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType; +import imgui.type.ImString; import java.util.Map; import java.util.TreeMap; @@ -18,6 +19,11 @@ public class KeyframeTrack { public final KeyframeType keyframeType; public TreeMap keyframesByTick = new TreeMap<>(); public boolean enabled = true; + public String customName = null; + + public transient ImString nameEditField = null; + public transient boolean forceFocusTrack = false; + public transient float animatedOffsetInUi = 0.0f; public KeyframeTrack(KeyframeType keyframeType) { this.keyframeType = keyframeType; diff --git a/src/main/java/com/moulberry/flashback/visuals/ShaderManager.java b/src/main/java/com/moulberry/flashback/visuals/ShaderManager.java index 7681f94..11aa2cb 100644 --- a/src/main/java/com/moulberry/flashback/visuals/ShaderManager.java +++ b/src/main/java/com/moulberry/flashback/visuals/ShaderManager.java @@ -10,8 +10,6 @@ import net.minecraft.client.renderer.ShaderInstance; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.resources.ResourceManager; -import java.io.IOException; - public class ShaderManager { public static final ShaderManager INSTANCE = new ShaderManager(); diff --git a/src/main/resources/assets/flashback/materialiconsround-regular.otf b/src/main/resources/assets/flashback/materialiconsround-regular.otf new file mode 100644 index 0000000..dacf094 Binary files /dev/null and b/src/main/resources/assets/flashback/materialiconsround-regular.otf differ