This commit is contained in:
Moulberry committed 2024-09-15 11:35:31 +08:00
1 parent 7f1d199704
commit be99313e81
47 files changed
+1247 -337

No files matched your search

@@ -130,6 +130,9 @@ public class CustomImGuiImplGlfw {
private int grabLinkedKey = -1;
private boolean releaseGrabOnUp = false;
public double rawMouseX;
public double rawMouseY;
public float contentScale = 1.0f;
public enum MouseHandledBy {
@@ -391,6 +394,9 @@ public class CustomImGuiImplGlfw {
public void cursorPosCallback(final long windowId, final double xpos, final double ypos) {
if (AsyncFileDialogs.hasDialog()) return;
this.rawMouseX = xpos;
this.rawMouseY = ypos;
if (!ReplayUI.isActive()) {
if (this.prevUserCallbackCursorPos != null && windowId == this.mainWindowPtr) this.prevUserCallbackCursorPos.invoke(windowId, xpos, ypos);
return;
@@ -94,6 +94,7 @@ public class ReplayUI {
private static String infoOverlayText = null;
private static long infoOverlayEndMillis = 0;
public static boolean recordCameraMovement = false;
private static UUID selectedEntity = null;
private static boolean openSelectedEntityPopup = false;
@@ -605,29 +606,40 @@ public class ReplayUI {
isFrameFocused = true;
}
String showText = null;
int showTextBorderColour = -1;
if (infoOverlayText != null) {
long currentMillis = System.currentTimeMillis();
if (currentMillis < infoOverlayEndMillis - 30000 || currentMillis > infoOverlayEndMillis) {
infoOverlayText = null;
infoOverlayEndMillis = 0;
} else {
ImGui.setNextWindowPos(frameX + frameWidth*0.5f, frameY + frameHeight*0.75f, ImGuiCond.Always, 0.5f, 0.5f);
ImGui.setNextWindowSizeConstraints(0, 0, 550, frameHeight*0.45f);
ImGuiHelper.pushStyleVar(ImGuiStyleVar.WindowBorderSize, 2);
ImGuiHelper.pushStyleColor(ImGuiCol.Border, 0xFF00FFFF);
if (ImGui.begin("##InfoOverlay", ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoFocusOnAppearing |
ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse |
ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoSavedSettings)) {
ImGui.text(infoOverlayText);
}
ImGui.end();
ImGuiHelper.popStyleColor();
ImGuiHelper.popStyleVar();
showText = infoOverlayText;
showTextBorderColour = 0xFF00FFFF;
}
} else if (recordCameraMovement) {
showText = "Recording Movement as Keyframes...";
showTextBorderColour = 0xFF0000FF;
}
if (showText != null) {
ImGui.setNextWindowPos(frameX + frameWidth*0.5f, frameY + frameHeight*0.75f, ImGuiCond.Always, 0.5f, 0.5f);
ImGui.setNextWindowSizeConstraints(0, 0, 550, frameHeight*0.45f);
ImGuiHelper.pushStyleVar(ImGuiStyleVar.WindowBorderSize, 2);
ImGuiHelper.pushStyleColor(ImGuiCol.Border, showTextBorderColour);
if (ImGui.begin("##InfoOverlay", ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoFocusOnAppearing |
ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse |
ImGuiWindowFlags.NoDocking | ImGuiWindowFlags.NoSavedSettings)) {
ImGui.text(showText);
}
ImGui.end();
ImGuiHelper.popStyleColor();
ImGuiHelper.popStyleVar();
}
if (sizing == Sizing.UNDERLAY) {
@@ -637,10 +649,6 @@ public class ReplayUI {
frameHeight = Minecraft.getInstance().getWindow().getScreenHeight();
}
if (frameX != oldFrameX || frameY != oldFrameY || frameWidth != oldFrameWidth || frameHeight != oldFrameHeight) {
Minecraft.getInstance().resizeDisplay();
}
if (Minecraft.getInstance().screen == null && Minecraft.getInstance().getOverlay() == null) {
if (editorState != null && editorState.replayVisuals.ruleOfThirdsGuide) {
ImDrawList drawList = ImGui.getBackgroundDrawList();
@@ -744,6 +752,10 @@ public class ReplayUI {
imguiGl3.renderDrawData(drawData);
}
if (frameX != oldFrameX || frameY != oldFrameY || frameWidth != oldFrameWidth || frameHeight != oldFrameHeight) {
Minecraft.getInstance().resizeDisplay();
}
transitionActiveState(true);
}
@@ -4,6 +4,7 @@ import com.mojang.authlib.GameProfile;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.configuration.FlashbackConfig;
import com.moulberry.flashback.editor.ui.ImGuiHelper;
import com.moulberry.flashback.editor.ui.ReplayUI;
import com.moulberry.flashback.editor.ui.WindowOpenState;
import com.moulberry.flashback.state.EditorState;
import com.moulberry.flashback.state.EditorStateManager;
@@ -87,6 +88,11 @@ public class MovementWindow {
config.saveToDefaultFolder();
}
// todo: record movement: can we make this smoother?
// if (ImGui.checkbox("Record Movement as Keyframes", ReplayUI.recordCameraMovement)) {
// ReplayUI.recordCameraMovement = !ReplayUI.recordCameraMovement;
// }
}
ImGui.end();
}
@@ -44,6 +44,7 @@ public class StartExportWindow {
private static final float[] framerate = new float[]{60};
private static boolean resetRng = false;
private static boolean ssaa = false;
private static boolean noGui = false;
private static VideoContainer[] supportedContainers = null;
private static VideoContainer[] supportedContainersWithTransparency = null;
@@ -173,6 +174,13 @@ public class StartExportWindow {
}
ImGuiHelper.tooltip("Supersampling Anti-Aliasing: Remove jagged edges by rendering the game at double resolution and downscaling");
ImGui.sameLine();
if (ImGui.checkbox("No GUI", noGui)) {
noGui = !noGui;
}
ImGuiHelper.tooltip("Removes all UI from the screen, rendering only the world");
ImGuiHelper.separatorWithText("Video Options");
renderVideoOptions(editorState);
@@ -257,8 +265,12 @@ public class StartExportWindow {
}
private static void renderVideoOptions(EditorState editorState) {
if (editorState != null && !editorState.replayVisuals.renderSky && ImGui.checkbox("Transparent Sky", transparentBackground)) {
transparentBackground = !transparentBackground;
if (editorState != null && !editorState.replayVisuals.renderSky) {
if (ImGui.checkbox("Transparent Sky", transparentBackground)) {
transparentBackground = !transparentBackground;
}
} else {
transparentBackground = false;
}
VideoContainer[] containers;
@@ -402,7 +414,7 @@ public class StartExportWindow {
return new ExportSettings(name, editorState.copy(),
player.position(), player.getYRot(), player.getXRot(),
resolution[0], resolution[1], start, end,
Math.max(1, framerate[0]), resetRng, container, useVideoCodec, encoder, numBitrate, transparent, ssaa,
Math.max(1, framerate[0]), resetRng, container, useVideoCodec, encoder, numBitrate, transparent, ssaa, noGui,
shouldRecordAudio, stereoAudio, useAudioCodec,
path);
}
@@ -10,6 +10,7 @@ import com.moulberry.flashback.editor.ui.ReplayUI;
import com.moulberry.flashback.keyframe.KeyframeType;
import com.moulberry.flashback.keyframe.KeyframeRegistry;
import com.moulberry.flashback.keyframe.handler.MinecraftKeyframeHandler;
import com.moulberry.flashback.keyframe.types.CameraKeyframeType;
import com.moulberry.flashback.keyframe.types.TimelapseKeyframeType;
import com.moulberry.flashback.record.ReplayMarker;
import com.moulberry.flashback.state.EditorStateHistoryAction;
@@ -67,6 +68,7 @@ public class TimelineWindow {
private static Vector2f dragSelectOrigin = null;
private static KeyframeType.KeyframeCreatePopup<?> createKeyframeWithPopup = null;
private static int createKeyframeWithPopupTick = 0;
private static float mouseX;
private static float mouseY;
@@ -105,6 +107,10 @@ public class TimelineWindow {
private static int editingKeyframeTrack = 0;
private static int editingKeyframeTick = 0;
private static int createKeyframeAtTick = 0;
private static int openCreateKeyframeAtTickTrack = -1;
private static final float[] replayTickSpeeds = new float[]{1.0f, 2.0f, 4.0f, 10.0f, 20.0f, 40.0f, 100.0f, 200.0f, 400.0f};
private static final int KEYFRAME_SIZE = 10;
@@ -523,7 +529,7 @@ public class TimelineWindow {
boolean pressedDelete = ImGui.isKeyPressed(GLFW.GLFW_KEY_DELETE, false) || ImGui.isKeyPressed(GLFW.GLFW_KEY_BACKSPACE, false);
if (ImGui.isKeyPressed(GLFW.GLFW_KEY_SPACE, false)) {
replayServer.replayPaused = !replayServer.replayPaused;
togglePaused(replayServer, editorState);
}
if (ImGui.isKeyPressed(GLFW.GLFW_KEY_LEFT, false)) {
pendingStepBackwardsTicks += 1;
@@ -720,13 +726,7 @@ public class TimelineWindow {
// Pause button
if (hoveredPause) {
replayServer.replayPaused = !replayServer.replayPaused;
if (!replayServer.replayPaused) {
Screen screen = Minecraft.getInstance().screen;
if (screen != null && screen.isPauseScreen()) {
Minecraft.getInstance().setScreen(null);
}
}
togglePaused(replayServer, editorState);
return;
}
@@ -870,6 +870,9 @@ public class TimelineWindow {
}
return;
} else if (rightClicked) {
createKeyframeAtTick = tick;
openCreateKeyframeAtTickTrack = trackIndex;
}
}
@@ -877,6 +880,31 @@ public class TimelineWindow {
}
}
private static void togglePaused(ReplayServer replayServer, EditorState editorState) {
if (replayServer.getReplayTick() >= replayServer.getTotalReplayTicks()) {
replayServer.jumpToTick = 0;
}
replayServer.replayPaused = !replayServer.replayPaused;
if (!replayServer.replayPaused) {
Screen screen = Minecraft.getInstance().screen;
if (screen != null && screen.isPauseScreen()) {
Minecraft.getInstance().setScreen(null);
}
if (ReplayUI.recordCameraMovement) {
editorState.recordingCameraMovementTrack = -1;
for (int i = 0; i < editorState.keyframeTracks.size(); i++) {
KeyframeTrack keyframeTrack = editorState.keyframeTracks.get(i);
if (keyframeTrack.enabled && keyframeTrack.keyframeType == CameraKeyframeType.INSTANCE) {
editorState.recordingCameraMovementTrack = i;
break;
}
}
}
}
}
private static void renderExportBar(EditorState editorState, ImDrawList drawList) {
if (editorState.exportStartTicks >= 0 && editorState.exportEndTicks >= 0) {
int exportStartX = replayTickToTimelineX(editorState.exportStartTicks);
@@ -932,7 +960,7 @@ public class TimelineWindow {
}
});
if (!(editingKeyframe instanceof TimelapseKeyframe)) {
if (editingKeyframe.keyframeType().allowChangingInterpolationType()) {
int[] type = new int[]{editingKeyframe.interpolationType().ordinal()};
ImGui.setNextItemWidth(160);
if (ImGuiHelper.combo("Type", type, InterpolationType.NAMES)) {
@@ -958,7 +986,8 @@ public class TimelineWindow {
editorState.push(new EditorStateHistoryEntry(undo, redo, "Changed interpolation type to " + interpolationType));
}
}
if (editingKeyframe.keyframeType().allowChangingTimelineTick()) {
int[] intWrapper = new int[]{editingKeyframeTick};
ImGui.setNextItemWidth(160);
ImGuiHelper.inputInt("Tick", intWrapper);
@@ -1247,9 +1276,6 @@ public class TimelineWindow {
float lineHeight = ImGui.getTextLineHeightWithSpacing() + ImGui.getStyle().getItemSpacingY();
ImDrawList drawList = ImGui.getWindowDrawList();
ImDrawList foregroundDrawList = ImGui.getForegroundDrawList();
foregroundDrawList.pushClipRect(x + middleX, y, x + width, y + height);
GrabMovementInfo grabMovementInfo = null;
if (grabbedKeyframe) {
@@ -1269,6 +1295,13 @@ public class TimelineWindow {
}
}
if (editorState.recordingCameraMovementTrack == trackIndex && editorState.recordingCameraMovementMinTick >= 0 && editorState.recordingCameraMovementMaxTick >= 0) {
float fromX = x + replayTickToTimelineX(editorState.recordingCameraMovementMinTick);
float toX = x + replayTickToTimelineX(editorState.recordingCameraMovementMaxTick);
float topY = y + 2 + trackIndex * lineHeight;
drawList.addRectFilled(fromX, topY, toX, topY + lineHeight, 0xFF4040FF);
}
for (int tick = minTicks - 10; tick <= minTicks + availableTicks + 10; tick++) {
var entry = keyframeTimes.ceilingEntry(tick);
if (entry == null || entry.getKey() > minTicks + availableTicks + 10) {
@@ -1298,7 +1331,7 @@ public class TimelineWindow {
float midX = x + keyframeX;
drawKeyframe(foregroundDrawList, keyframe.interpolationType(), midX, midY, keyframeTrack.enabled ? 0xFF0000FF : 0x800000FF);
drawKeyframe(drawList, keyframe.interpolationType(), midX, midY, keyframeTrack.enabled ? 0xFF0000FF : 0x800000FF);
} else {
int keyframeX = replayTickToTimelineX(tick);
@@ -1381,8 +1414,6 @@ public class TimelineWindow {
}
}
}
foregroundDrawList.popClipRect();
}
private static void drawKeyframe(ImDrawList drawList, InterpolationType interpolationType, float x, float y, int colour) {
@@ -1447,6 +1478,22 @@ public class TimelineWindow {
ImGui.pushID(trackIndex);
if (trackIndex == openCreateKeyframeAtTickTrack) {
ImGui.openPopup("##CreateKeyframeAtTickPopup");
openCreateKeyframeAtTickTrack = -1;
}
if (ImGui.beginPopup("##CreateKeyframeAtTickPopup")) {
if (ImGui.menuItem("Create Keyframe at " + createKeyframeAtTick)) {
ImGui.closeCurrentPopup();
ImGui.endPopup();
createNewKeyframe(editorState, trackIndex, createKeyframeAtTick, keyframeType, keyframeTrack);
} else {
ImGui.endPopup();
}
}
ImGui.setCursorPosX(8);
if (keyframeTrack.enabled) {
@@ -1461,19 +1508,7 @@ public class TimelineWindow {
float buttonY = ImGui.getCursorScreenPosY();
ImGui.setCursorPosX(buttonX - x);
if (ImGui.button("##Add", buttonSize, buttonSize)) {
Keyframe keyframe = keyframeType.createDirect();
if (keyframe != null) {
editorState.setKeyframe(trackIndex, cursorTicks, keyframe);
} else {
if (keyframeType == TimelapseKeyframeType.INSTANCE && keyframeTrack.keyframesByTick.isEmpty()) {
editorState.setKeyframe(trackIndex, cursorTicks, new TimelapseKeyframe(0));
} else {
createKeyframeWithPopup = keyframeType.createPopup();
if (createKeyframeWithPopup != null) {
ImGui.openPopup("##CreateKeyframe");
}
}
}
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);
@@ -1484,7 +1519,7 @@ public class TimelineWindow {
hasOpenPopup = true;
Keyframe keyframe = createKeyframeWithPopup.render();
if (keyframe != null) {
editorState.setKeyframe(trackIndex, cursorTicks, keyframe);
editorState.setKeyframe(trackIndex, createKeyframeWithPopupTick, keyframe);
ImGui.closeCurrentPopup();
}
} else {
@@ -1532,7 +1567,9 @@ public class TimelineWindow {
if (!hasOpenPopup) {
createKeyframeWithPopup = null;
createKeyframeWithPopupTick = cursorTicks;
}
openCreateKeyframeAtTickTrack = -1;
if (keyframeTrackToClear >= 0) {
List<EditorStateHistoryAction> undo = new ArrayList<>();
@@ -1573,6 +1610,23 @@ public class TimelineWindow {
}
}
private static void createNewKeyframe(EditorState editorState, int trackIndex, int tick, KeyframeType<?> keyframeType, KeyframeTrack keyframeTrack) {
Keyframe keyframe = keyframeType.createDirect();
if (keyframe != null) {
editorState.setKeyframe(trackIndex, tick, keyframe);
} else {
if (keyframeType == TimelapseKeyframeType.INSTANCE && keyframeTrack.keyframesByTick.isEmpty()) {
editorState.setKeyframe(trackIndex, tick, new TimelapseKeyframe(0));
} else {
createKeyframeWithPopup = keyframeType.createPopup();
if (createKeyframeWithPopup != null) {
ImGui.openPopup("##CreateKeyframe");
createKeyframeWithPopupTick = tick;
}
}
}
}
private static void renderSeparators(int minorsPerMajor, float x, int middleX, float minorSeparatorWidth, int errorOffset, float width, ImDrawList drawList, float y, int timestampHeight, int middleY, int minTicks, int ticksPerMinor, boolean showSubSeconds, int majorSeparatorHeight, int minorSeparatorHeight) {
int minor = -minorsPerMajor;
while (true) {
@@ -63,6 +63,13 @@ public class VisualsWindow {
editorState.markDirty();
}
if (Minecraft.getInstance().cameraEntity != null && Minecraft.getInstance().cameraEntity != Minecraft.getInstance().player) {
if (ImGui.checkbox("Hotbar", visuals.showHotbar)) {
visuals.showHotbar = !visuals.showHotbar;
editorState.markDirty();
}
}
ImGuiHelper.separatorWithText("World");
if (ImGui.checkbox("Render Blocks", visuals.renderBlocks)) {