This commit is contained in:
Moulberry committed 2024-09-04 22:38:45 +08:00
1 parent 9c62ea4191
commit d589647c36
49 files changed
+958 -271

No files matched your search

@@ -23,6 +23,7 @@ import imgui.flag.ImGuiMouseCursor;
import imgui.flag.ImGuiNavInput;
import imgui.flag.ImGuiViewportFlags;
import imgui.lwjgl3.glfw.ImGuiImplGlfwNative;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.world.phys.Vec2;
import org.lwjgl.PointerBuffer;
@@ -127,9 +128,7 @@ public class CustomImGuiImplGlfw {
private final double[] grabbedOriginalMouseX = new double[1];
private final double[] grabbedOriginalMouseY = new double[1];
private int grabLinkedKey = -1;
private List<Vec2> interframeMousePositions = new ArrayList<>();
private List<Vec2> capturedInterframeMousePositions = new ArrayList<>();
private boolean releaseGrabOnUp = false;
public float contentScale = 1.0f;
@@ -168,7 +167,7 @@ public class CustomImGuiImplGlfw {
GLFW.glfwSetCursorPos(this.mainWindowPtr, this.grabbedOriginalMouseX[0], this.grabbedOriginalMouseY[0]);
}
public void setGrabbed(boolean passthroughToGame, int grabLinkedKey, double x, double y) {
public void setGrabbed(boolean passthroughToGame, int grabLinkedKey, boolean releaseGrabOnUp, double x, double y) {
if (grabLinkedKey != 0) {
if (grabLinkedKey < 0) {
if (GLFW.glfwGetMouseButton(this.mainWindowPtr, -grabLinkedKey-1) == GLFW_RELEASE) {
@@ -185,6 +184,7 @@ public class CustomImGuiImplGlfw {
if (grabLinkedKey != 0) {
this.grabLinkedKey = grabLinkedKey;
this.releaseGrabOnUp = releaseGrabOnUp;
}
if (x >= 0 && y >= 0) {
this.grabbedOriginalMouseX[0] = x;
@@ -232,8 +232,10 @@ public class CustomImGuiImplGlfw {
return;
}
if (this.grabbed != null && action == GLFW_RELEASE && this.grabLinkedKey < 0 && button == -this.grabLinkedKey-1) {
this.ungrab();
if (this.grabbed != null && this.grabLinkedKey < 0 && button == -this.grabLinkedKey-1) {
if ((action == GLFW_RELEASE) == this.releaseGrabOnUp) {
this.ungrab();
}
}
MouseHandledBy handledBy = this.getMouseHandledBy();
@@ -260,7 +262,7 @@ public class CustomImGuiImplGlfw {
this.io.setMouseWheelH(this.io.getMouseWheelH() + (float) xOffset);
this.io.setMouseWheel(this.io.getMouseWheel() + (float) yOffset);
if (Minecraft.getInstance().screen == null || !ReplayUI.isMainFrameHovered()) {
if (Minecraft.getInstance().screen == null || !ReplayUI.isMainFrameActive()) {
return;
}
}
@@ -328,27 +330,46 @@ public class CustomImGuiImplGlfw {
}
}
if (action != GLFW_RELEASE && GLFW.glfwGetKey(windowId, GLFW_KEY_F3) != GLFW_RELEASE) {
boolean forcePassToGame = action != GLFW_RELEASE && ((key == GLFW_KEY_ESCAPE && !io.getWantTextInput() && !ReplayUI.hasAnyPopupOpen) ||
(key >= GLFW_KEY_F1 && key <= GLFW_KEY_F25) || GLFW.glfwGetKey(windowId, GLFW_KEY_F3) != GLFW_RELEASE);
if (forcePassToGame) {
this.prevUserCallbackKey.invoke(windowId, minecraftKey, scancode, action, mods);
if (keyInBoundsForGame) this.keyPressedGame[minecraftKey] = action != GLFW_RELEASE;
if (keyInBoundsForGame) this.keyPressedGame[minecraftKey] = true;
return;
}
boolean passToMinecraft = (ReplayUI.isMainFrameHovered() && this.io.getMouseDown(ImGuiMouseButton.Left) || !this.io.getWantCaptureKeyboard()) && !this.io.getWantTextInput();
boolean passToMinecraft = false;
boolean passToImGui = false;
if (action == GLFW_RELEASE) {
if (keyInBoundsForGame && this.keyPressedGame[minecraftKey]) passToMinecraft = true;
} else if (passToMinecraft) {
// out:
// for (KeybindCategory category : Keybinds.categories) {
// if (!category.preventPassToGame()) continue;
// for (Keybind keybind : category.keybinds()) {
// if (keybind.wouldBePressed(key, shiftMod, ctrlMod, altMod, superMod)) {
// passToMinecraft = false;
// break out;
// }
// }
// }
if (keyInBoundsForGame && this.keyPressedGame[minecraftKey]) {
passToMinecraft = true;
}
if (key >= 0 && key < this.keyOwnerWindows.length) {
passToImGui = true;
}
} else {
if (io.getWantTextInput()) {
passToMinecraft = false;
} else if (this.grabbed == MouseHandledBy.GAME) {
passToMinecraft = true;
} else if (ReplayUI.isMainFrameActive()) {
for (KeyMapping keyMapping : Minecraft.getInstance().options.keyMappings) {
if (keyMapping.matches(key, scancode)) {
passToMinecraft = true;
break;
}
}
} else if (Minecraft.getInstance().options.keyUp.matches(key, scancode) ||
Minecraft.getInstance().options.keyLeft.matches(key, scancode) ||
Minecraft.getInstance().options.keyDown.matches(key, scancode) ||
Minecraft.getInstance().options.keyRight.matches(key, scancode) ||
Minecraft.getInstance().options.keyChat.matches(key, scancode) ||
Minecraft.getInstance().options.keyCommand.matches(key, scancode)) {
passToMinecraft = true;
}
passToImGui = !passToMinecraft;
}
if (passToMinecraft && this.prevUserCallbackKey != null && windowId == this.mainWindowPtr) {
@@ -356,7 +377,7 @@ public class CustomImGuiImplGlfw {
if (keyInBoundsForGame) this.keyPressedGame[minecraftKey] = action != GLFW_RELEASE;
}
if (key >= 0 && key < this.keyOwnerWindows.length) {
if (passToImGui && key >= 0 && key < this.keyOwnerWindows.length) {
if (action == GLFW_PRESS || action == GLFW_REPEAT) {
io.setKeysDown(key, true);
this.keyOwnerWindows[key] = windowId;
@@ -392,8 +413,6 @@ public class CustomImGuiImplGlfw {
if (handledBy == MouseHandledBy.EDITOR_GRABBED) {
grabbedCurrMouseX = xpos;
grabbedCurrMouseY = ypos;
} else {
this.interframeMousePositions.add(new Vec2((float)xpos, (float)ypos));
}
}
@@ -444,7 +463,7 @@ public class CustomImGuiImplGlfw {
return;
}
if (!this.io.getWantCaptureKeyboard() && this.prevUserCallbackChar != null && windowId == this.mainWindowPtr) {
if (!this.io.getWantCaptureKeyboard() && !this.io.getWantTextInput() && this.prevUserCallbackChar != null && windowId == this.mainWindowPtr) {
this.prevUserCallbackChar.invoke(windowId, c, mods);
}
@@ -597,38 +616,12 @@ public class CustomImGuiImplGlfw {
return true;
}
public List<Vec2> getCapturedInterframeMousePositions() {
return this.capturedInterframeMousePositions;
}
/**
* Updates {@link ImGuiIO} and {@link org.lwjgl.glfw.GLFW} state.
*/
public void newFrame() {
this.io.ptr = ImGui.getIO().ptr;
if (this.interframeMousePositions.isEmpty()) {
this.capturedInterframeMousePositions.clear();
} else {
this.capturedInterframeMousePositions = this.interframeMousePositions;
this.interframeMousePositions = new ArrayList<>();
if (this.io.hasConfigFlags(ImGuiConfigFlags.ViewportsEnable)) {
// Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
long windowPtr = this.mouseWindowPtr;
if (windowPtr == 0) {
windowPtr = this.mainWindowPtr;
}
glfwGetWindowPos(windowPtr, this.windowX, this.windowY);
List<Vec2> offset = new ArrayList<>();
for (Vec2 pos : this.capturedInterframeMousePositions) {
offset.add(new Vec2(pos.x + this.windowX[0], pos.y + this.windowY[0]));
}
this.capturedInterframeMousePositions = offset;
}
}
glfwGetWindowSize(this.mainWindowPtr, this.winWidth, this.winHeight);
glfwGetFramebufferSize(this.mainWindowPtr, this.fbWidth, this.fbHeight);
@@ -6,8 +6,12 @@ import imgui.ImVec2;
import imgui.flag.ImGuiCol;
import imgui.flag.ImGuiComboFlags;
import imgui.flag.ImGuiHoveredFlags;
import imgui.flag.ImGuiInputTextFlags;
import imgui.flag.ImGuiNavInput;
import imgui.flag.ImGuiWindowFlags;
import imgui.type.ImBoolean;
import imgui.type.ImFloat;
import imgui.type.ImInt;
import imgui.type.ImString;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
@@ -132,12 +136,21 @@ public class ImGuiHelper {
private static StringBuilder specialInput = new StringBuilder();
private static int backspaceCount = 0;
private static boolean handledFocusNext = false;
private static boolean focusNext = false;
private static int focusIndex = 0;
private static int focusLastIndex = 0;
public static void endFrame() {
closeableModalOnTopLast = closeableModalOnTop;
wantSpecialInputLastFrame = wantSpecialInputThisFrame;
wantSpecialInputThisFrame = false;
handledFocusNext = false;
focusNext = false;
focusIndex = 0;
if (!wantSpecialInputLastFrame) specialInput.setLength(0);
}
@@ -316,6 +329,136 @@ public class ImGuiHelper {
ImGui.textColored(ImGui.getColorU32(ImGuiCol.TextDisabled), text);
}
public static boolean inputInt(String label, int[] value) {
if (value.length == 0) {
ImGui.text(label);
return false;
}
boolean valueChanged = false;
float availableWidth = ImGui.calcItemWidth();
float innerSpacing = ImGui.getStyle().getItemInnerSpacingX();
float widthItemOne = Math.max(1, (float) Math.floor((availableWidth - innerSpacing * (value.length - 1)) / value.length));
float widthItemLast = Math.max(1, (float) Math.floor(availableWidth - (widthItemOne + innerSpacing) * (value.length - 1)));
ImGui.beginGroup();
ImGui.pushID(label);
for (int i=0; i<value.length; i++) {
ImGui.pushID(i);
if (i > 0) {
ImGui.sameLine(0, innerSpacing);
}
ImInt imInt = new ImInt(value[i]);
if (i < value.length-1) {
ImGui.setNextItemWidth(widthItemOne);
} else {
ImGui.setNextItemWidth(widthItemLast);
}
focusIndex += 1;
if (focusIndex == focusLastIndex || focusNext) {
ImGui.setKeyboardFocusHere();
focusNext = false;
focusLastIndex = 0;
}
if (ImGui.inputInt("", imInt, 0)) {
valueChanged = true;
value[i] = imInt.get();
}
if (!handledFocusNext && ImGui.isItemActive() && ImGui.isKeyPressed(GLFW.GLFW_KEY_TAB, false)) {
handledFocusNext = true;
if (ImGui.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT) || ImGui.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) {
focusLastIndex = focusIndex - 1;
} else {
focusNext = true;
}
}
ImGui.popID();
}
ImGui.popID();
// Label
String renderedText = label.split("##")[0];
if (!renderedText.isEmpty()) {
ImGui.sameLine(0, innerSpacing);
ImGui.text(renderedText);
}
ImGui.endGroup();
return valueChanged;
}
public static boolean inputFloat(String label, float[] value) {
if (value.length == 0) {
ImGui.text(label);
return false;
}
boolean valueChanged = false;
float availableWidth = ImGui.calcItemWidth();
float innerSpacing = ImGui.getStyle().getItemInnerSpacingX();
float widthItemOne = Math.max(1, (float) Math.floor((availableWidth - innerSpacing * (value.length - 1)) / value.length));
float widthItemLast = Math.max(1, (float) Math.floor(availableWidth - (widthItemOne + innerSpacing) * (value.length - 1)));
ImGui.beginGroup();
ImGui.pushID(label);
for (int i=0; i<value.length; i++) {
ImGui.pushID(i);
if (i > 0) {
ImGui.sameLine(0, innerSpacing);
}
ImFloat imFloat = new ImFloat(value[i]);
if (i < value.length-1) {
ImGui.setNextItemWidth(widthItemOne);
} else {
ImGui.setNextItemWidth(widthItemLast);
}
focusIndex += 1;
if (focusIndex == focusLastIndex || focusNext) {
ImGui.setKeyboardFocusHere();
focusNext = false;
focusLastIndex = 0;
}
if (ImGui.inputFloat("", imFloat, 0)) {
valueChanged = true;
value[i] = imFloat.get();
}
if (!handledFocusNext && ImGui.isItemActive() && ImGui.isKeyPressed(GLFW.GLFW_KEY_TAB, false)) {
handledFocusNext = true;
if (ImGui.isKeyDown(GLFW.GLFW_KEY_LEFT_SHIFT) || ImGui.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) {
focusLastIndex = focusIndex - 1;
} else {
focusNext = true;
}
}
ImGui.popID();
}
ImGui.popID();
// Label
String renderedText = label.split("##")[0];
if (!renderedText.isEmpty()) {
ImGui.sameLine(0, innerSpacing);
ImGui.text(renderedText);
}
ImGui.endGroup();
return valueChanged;
}
public static boolean radio(String label, int[] currentItem, String[] values) {
int item = currentItem[0];
int newItem = -1;
@@ -5,6 +5,7 @@ import com.mojang.blaze3d.platform.TextureUtil;
import com.mojang.blaze3d.platform.Window;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.editor.ui.windows.ExportQueueWindow;
import com.moulberry.flashback.editor.ui.windows.MovementWindow;
import com.moulberry.flashback.editor.ui.windows.PlayerListWindow;
import com.moulberry.flashback.editor.ui.windows.SelectedEntityPopup;
import com.moulberry.flashback.state.EditorState;
@@ -25,7 +26,6 @@ import net.minecraft.client.gui.screens.ProgressScreen;
import net.minecraft.client.gui.screens.ReceivingLevelScreen;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
@@ -55,6 +55,7 @@ public class ReplayUI {
private static final CustomImGuiImplGl3 imguiGl3 = new CustomImGuiImplGl3();
private static boolean initialized = false;
private static boolean isFrameFocused = false;
private static boolean isFrameHovered = false;
public static int frameX = 0;
public static int frameY = 0;
@@ -64,6 +65,10 @@ public class ReplayUI {
public static int viewportSizeY = 1;
private static boolean activeLastFrame = false;
private static int focusMainWindowCounter = 0;
public static boolean hasAnyPopupOpen = false;
public static Matrix4f lastProjectionMatrix = null;
public static Quaternionf lastViewQuaternion = null;
@@ -126,7 +131,7 @@ public class ReplayUI {
Path relativePath = FabricLoader.getInstance().getGameDir().relativize(path);
ImGui.getIO().setIniFilename(relativePath.toString());
ImGui.getIO().addConfigFlags(ImGuiConfigFlags.NavEnableKeyboard);
// ImGui.getIO().addConfigFlags(ImGuiConfigFlags.NavEnableKeyboard);
ImGui.getIO().addConfigFlags(ImGuiConfigFlags.DockingEnable);
// ImGui.getIO().addConfigFlags(ImGuiConfigFlags.ViewportsEnable);
ImGui.getIO().setConfigMacOSXBehaviors(Minecraft.ON_OSX);
@@ -486,6 +491,7 @@ public class ReplayUI {
if (!isActiveInternal()) {
transitionActiveState(false);
imguiGlfw.updateReleaseAllKeys(true);
focusMainWindowCounter = 5;
return;
} else {
imguiGlfw.updateReleaseAllKeys(false);
@@ -513,14 +519,16 @@ public class ReplayUI {
imguiGlfw.newFrame();
ImGui.newFrame();
navClose = ImGui.getIO().getNavInputs(ImGuiNavInput.Cancel) != 0;
hasAnyPopupOpen = ImGui.isPopupOpen("", ImGuiPopupFlags.AnyPopup);
navClose = hasAnyPopupOpen && ImGui.getIO().getNavInputs(ImGuiNavInput.Cancel) != 0.0f;
if (wasNavClose != navClose) {
wasNavClose = navClose;
} else if (wasNavClose) {
navClose = false;
}
if (ImGui.isPopupOpen("", ImGuiPopupFlags.AnyPopup)) {
if (hasAnyPopupOpen) {
ImGui.getIO().addConfigFlags(ImGuiConfigFlags.NavEnableKeyboard);
} else {
ImGui.getIO().removeConfigFlags(ImGuiConfigFlags.NavEnableKeyboard);
@@ -535,6 +543,7 @@ public class ReplayUI {
int mainDock = ImGui.dockSpaceOverViewport(ImGui.getMainViewport(), ImGuiDockNodeFlags.NoDockingInCentralNode);
imgui.internal.ImGui.dockBuilderGetCentralNode(mainDock).addLocalFlags(imgui.internal.flag.ImGuiDockNodeFlags.NoTabBar);
isFrameFocused = false;
isFrameHovered = false;
ImGui.setNextWindowDockID(mainDock);
ImGuiHelper.pushStyleVar(ImGuiStyleVar.WindowPadding, 0, 0);
@@ -543,6 +552,11 @@ public class ReplayUI {
if (ImGui.begin("Main", ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoNavInputs | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.NoCollapse |
ImGuiWindowFlags.NoSavedSettings)) {
if (focusMainWindowCounter > 0) {
focusMainWindowCounter -= 1;
ImGui.setWindowFocus();
}
ImGuiHelper.popStyleVar();
float minX = ImGui.getWindowContentRegionMinX();
@@ -586,6 +600,11 @@ public class ReplayUI {
}
}
if (ImGui.isWindowFocused()) {
ImGui.getWindowDrawList().addRect(frameX+1, frameY+1, frameX+frameWidth-1, frameY+frameHeight-1, 0xFFC25823);
isFrameFocused = true;
}
if (infoOverlayText != null) {
long currentMillis = System.currentTimeMillis();
if (currentMillis < infoOverlayEndMillis - 30000 || currentMillis > infoOverlayEndMillis) {
@@ -673,7 +692,9 @@ public class ReplayUI {
if (Minecraft.getInstance().screen != null) {
ImGui.captureMouseFromApp(false);
} else if (isMovingCamera()) {
}
boolean isMovingCamera = isMovingCamera();
if (isFrameFocused || isMovingCamera) {
LocalPlayer player = Minecraft.getInstance().player;
if (player != null) {
int wheelY = (int) Math.signum(ImGui.getIO().getMouseWheel());
@@ -685,7 +706,8 @@ public class ReplayUI {
player.getAbilities().setFlyingSpeed(flyingSpeed);
}
}
} else if (ImGui.getIO().getWantCaptureMouse() && !popupOpenLastFrame && !ImGui.isPopupOpen("", ImGuiPopupFlags.AnyPopup)) {
}
if (!isMovingCamera && ImGui.getIO().getWantCaptureMouse() && !popupOpenLastFrame && !ImGui.isPopupOpen("", ImGuiPopupFlags.AnyPopup)) {
fireCancelNavInput |= handleBasicInputs();
}
}
@@ -699,6 +721,7 @@ public class ReplayUI {
StartExportWindow.render();
ExportQueueWindow.render();
PlayerListWindow.render();
MovementWindow.render();
popupOpenLastFrame = ImGui.isPopupOpen("", ImGuiPopupFlags.AnyPopup);
@@ -723,15 +746,11 @@ public class ReplayUI {
transitionActiveState(true);
}
public static boolean isMainFrameHovered() {
return isFrameHovered;
public static boolean isMainFrameActive() {
return isFrameFocused;
}
private static boolean handleBasicInputs() {
// if (ImGui.isMouseClicked(ImGuiMouseButton.Left) && UserAction.LEFT_MOUSE.call(null) == UserAction.ActionResult.USED_STOP) {
// return true;
// }
if (ImGui.isMouseClicked(GLFW.GLFW_MOUSE_BUTTON_RIGHT)) {
HitResult result = getLookTarget();
if (result instanceof EntityHitResult entityHitResult) {
@@ -747,66 +766,11 @@ public class ReplayUI {
if (ImGui.isMouseClicked(GLFW.GLFW_MOUSE_BUTTON_LEFT)) {
int key = -GLFW.GLFW_MOUSE_BUTTON_LEFT-1;
if (key != 0) {
imguiGlfw.setGrabbed(true, key, frameX + frameWidth / 2f, frameY + frameHeight / 2f);
imguiGlfw.setGrabbed(true, key, true, frameX + frameWidth / 2f, frameY + frameHeight / 2f);
}
return true;
}
// if (Keybinds.ADJUST_RADIUS.isPressed(false)) {
// if (ToolManager.isToolActive() && ToolManager.getCurrentTool().initiateAdjustment()) {
// int key = Keybinds.ADJUST_RADIUS.getKey();
// if (key != 0) {
// imguiGlfw.setGrabbed(false, key, -1, -1);
// }
//
// adjustingTool = true;
// adjustingToolOffsetX = 0;
// adjustingToolOffsetY = 0;
//
// return true;
// }
// } else if (Keybinds.ROTATE_CAMERA.isPressed(false)) {
// movementControls = EditorMovementControls.rotate();
// return true;
// } else if (Keybinds.PICK_BLOCK.isPressed(false)) {
// RayCaster.RaycastResult result = Tool.raycastBlock();
// if (result != null) {
// BlockState blockState = Minecraft.getInstance().level.getBlockState(result.blockPos());
// CustomBlockState customBlockState = ServerCustomBlocks.getCustomStateFor(blockState);
// activeBlockHistory.setActive(Objects.requireNonNullElse(customBlockState, (CustomBlockState) blockState));
// return true;
// }
// } else if (Keybinds.USE_TOOL.isPressed(false)) {
// if (UserAction.RIGHT_MOUSE.call(null) != UserAction.ActionResult.NOT_HANDLED || ToolManager.isToolActive()) {
// return true;
// }
// } else if (Keybinds.ARCBALL_CAMERA.isPressed(false)) {
// Tool currentTool = ToolManager.isToolActive() ? ToolManager.getCurrentTool() : null;
// if (currentTool instanceof RulerTool || currentTool instanceof ModifyTool || Configuration.keybind.useCenterOfScreenForArcball) {
// movementControls = EditorMovementControls.arcballFromRaycast();
// if (movementControls != EditorMovementControls.none()) {
// int key = Keybinds.ARCBALL_CAMERA.getKey();
// if (key != 0) {
// imguiGlfw.setGrabbed(false, key, frameX + frameWidth / 2f, frameY + frameHeight / 2f);
// }
// return true;
// }
// } else {
// pendingDepthActions.add(PendingDepthAction.ARCBALL);
// return true;
// }
// } else if (Keybinds.PAN_CAMERA.isPressed(false)) {
// movementControls = EditorMovementControls.pan();
// return true;
// }
// if (Keybinds.CROSSHAIR_CAMERA.isPressed(false)) {
// int key = Keybinds.CROSSHAIR_CAMERA.getKey();
// if (key != 0) {
// imguiGlfw.setGrabbed(true, key, frameX + frameWidth / 2f, frameY + frameHeight / 2f);
// }
// return true;
// }
return false;
}
@@ -15,7 +15,7 @@ public class MainMenuBar {
}
public static void renderInner() {
if (ImGui.menuItem("Export")) {
if (ImGui.menuItem("Export Video")) {
StartExportWindow.open();
}
@@ -26,20 +26,31 @@ public class MainMenuBar {
}
}
ImGui.separator();
if (ImGui.menuItem("Player List")) {
toggleWindow("player_list");
}
if (ImGui.menuItem("Movement")) {
toggleWindow("movement");
}
ImGui.separator();
if (ImGui.menuItem("Hide (F1)")) {
Minecraft.getInstance().options.hideGui = true;
}
}
if (ImGui.menuItem("Player List")) {
var openedWindows = Flashback.getConfig().openedWindows;
boolean playerListIsOpen = openedWindows.contains("player_list");
if (playerListIsOpen) {
openedWindows.remove("player_list");
} else {
openedWindows.add("player_list");
}
Flashback.getConfig().saveToDefaultFolder();
private static void toggleWindow(String windowName) {
var openedWindows = Flashback.getConfig().openedWindows;
boolean playerListIsOpen = openedWindows.contains(windowName);
if (playerListIsOpen) {
openedWindows.remove(windowName);
} else {
openedWindows.add(windowName);
}
Flashback.getConfig().saveToDefaultFolder();
}
}
@@ -0,0 +1,94 @@
package com.moulberry.flashback.editor.ui.windows;
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.WindowOpenState;
import com.moulberry.flashback.state.EditorState;
import com.moulberry.flashback.state.EditorStateManager;
import imgui.ImGui;
import imgui.ImGuiViewport;
import imgui.flag.ImGuiCond;
import imgui.flag.ImGuiWindowFlags;
import imgui.type.ImString;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
public class MovementWindow {
private static WindowOpenState wasOpen = WindowOpenState.UNKNOWN;
public static void render() {
if (!Flashback.getConfig().openedWindows.contains("movement")) {
wasOpen = WindowOpenState.CLOSED;
return;
}
if (wasOpen == WindowOpenState.CLOSED) {
ImGuiViewport viewport = ImGui.getMainViewport();
ImGui.setNextWindowPos(viewport.getCenterX(), viewport.getCenterY(), ImGuiCond.Appearing, 0.5f, 0.5f);
}
wasOpen = WindowOpenState.OPEN;
FlashbackConfig config = Flashback.getConfig();
ImGui.setNextWindowSizeConstraints(250, 50, 5000, 5000);
if (ImGui.begin("Movement###Movement", ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoFocusOnAppearing)) {
int[] direction = new int[]{config.flightCameraDirection ? 1 : 0};
ImGuiHelper.combo("Direction", direction, new String[]{
"Horizontal",
"Camera"
});
boolean flightCameraDirection = direction[0] == 1;
if (config.flightCameraDirection != flightCameraDirection) {
config.flightCameraDirection = flightCameraDirection;
config.saveToDefaultFolder();
}
float[] momentum = new float[]{config.flightMomentum};
ImGui.sliderFloat("Momentum", momentum, 0.0f, 1.0f);
if (config.flightMomentum != momentum[0]) {
config.flightMomentum = momentum[0];
config.saveToDefaultFolder();
}
if (ImGui.checkbox("Lock X", config.flightLockX)) {
config.flightLockX = !config.flightLockX;
config.saveToDefaultFolder();
}
ImGui.sameLine();
if (ImGui.checkbox("Lock Y", config.flightLockY)) {
config.flightLockY = !config.flightLockY;
config.saveToDefaultFolder();
}
ImGui.sameLine();
if (ImGui.checkbox("Lock Z", config.flightLockZ)) {
config.flightLockZ = !config.flightLockZ;
config.saveToDefaultFolder();
}
if (ImGui.checkbox("Lock Yaw", config.flightLockYaw)) {
config.flightLockYaw = !config.flightLockYaw;
config.saveToDefaultFolder();
}
ImGui.sameLine();
if (ImGui.checkbox("Lock Pitch", config.flightLockPitch)) {
config.flightLockPitch = !config.flightLockPitch;
config.saveToDefaultFolder();
}
}
ImGui.end();
}
}
@@ -1,7 +1,9 @@
package com.moulberry.flashback.editor.ui.windows;
import com.moulberry.flashback.editor.ui.ImGuiHelper;
import com.moulberry.flashback.state.EditorState;
import imgui.ImGui;
import imgui.type.ImString;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import net.minecraft.world.entity.Entity;
@@ -4,9 +4,9 @@ import com.mojang.blaze3d.platform.Window;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.combo_options.AspectRatio;
import com.moulberry.flashback.combo_options.AudioCodec;
import com.moulberry.flashback.combo_options.Sizing;
import com.moulberry.flashback.combo_options.VideoCodec;
import com.moulberry.flashback.combo_options.VideoContainer;
import com.moulberry.flashback.compat.IrisApiWrapper;
import com.moulberry.flashback.exporting.ExportJobQueue;
import com.moulberry.flashback.state.EditorState;
import com.moulberry.flashback.state.EditorStateManager;
@@ -16,12 +16,9 @@ import com.moulberry.flashback.exporting.ExportJob;
import com.moulberry.flashback.exporting.ExportSettings;
import com.moulberry.flashback.playback.ReplayServer;
import imgui.ImGui;
import imgui.flag.ImGuiPopupFlags;
import imgui.flag.ImGuiWindowFlags;
import imgui.type.ImFloat;
import imgui.type.ImString;
import net.fabricmc.loader.api.FabricLoader;
import net.irisshaders.iris.api.v0.IrisApi;
import net.minecraft.FileUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
@@ -30,6 +27,7 @@ import org.jetbrains.annotations.Nullable;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class StartExportWindow {
@@ -42,7 +40,7 @@ public class StartExportWindow {
private static final int[] resolution = new int[]{1920, 1080};
private static final int[] startEndTick = new int[]{0, 100};
private static final ImFloat framerate = new ImFloat(60);
private static final float[] framerate = new float[]{60};
private static boolean resetRng = false;
private static boolean ssaa = false;
@@ -58,10 +56,18 @@ public class StartExportWindow {
private static boolean recordAudio = false;
private static boolean transparentBackground = false;
private static AudioCodec audioCodec = AudioCodec.AAC;
private static boolean stereoAudio = false;
private static Path defaultExportPath = null;
private static final ImString jobName = ImGuiHelper.createResizableImString("");
private static String installedIncompatibleModsString = null;
private static final List<String> potentialIncompatibleMods = List.of(
"essential", // causes a crash due to casting the DeltaTracker without an instanceof
"g4mespeed", // causes rendering issues due to overriding partial tick time
"feather" // causes miscellaneous crashes and issues that are impossible to debug
);
static {
bitrate.inputData.allowedChars = "0123456789kmb";
}
@@ -70,6 +76,17 @@ public class StartExportWindow {
EditorState editorState = EditorStateManager.getCurrent();
if (open) {
installedIncompatibleModsString = null;
for (String potentialIncompatibleMod : potentialIncompatibleMods) {
if (FabricLoader.getInstance().isModLoaded(potentialIncompatibleMod)) {
if (installedIncompatibleModsString == null) {
installedIncompatibleModsString = potentialIncompatibleMod;
} else {
installedIncompatibleModsString += ", " + potentialIncompatibleMod;
}
}
}
ImGui.openPopup("###StartExport");
Window window = Minecraft.getInstance().getWindow();
@@ -82,7 +99,7 @@ public class StartExportWindow {
lastFramebufferSize[1] = window.framebufferHeight;
}
if (editorState != null) {
if (editorState != null && editorState.replayVisuals.sizing == Sizing.CHANGE_ASPECT_RATIO) {
AspectRatio aspectRatio = editorState.replayVisuals.changeAspectRatio;
if (aspectRatio != null && aspectRatio != lastCustomAspectRatio) {
switch (aspectRatio) {
@@ -128,19 +145,20 @@ public class StartExportWindow {
ImGuiHelper.separatorWithText("Capture Options");
ImGui.inputInt2("Resolution", resolution);
ImGuiHelper.inputInt("Resolution", resolution);
if (resolution[0] < 16) resolution[0] = 16;
if (resolution[1] < 16) resolution[1] = 16;
if (resolution[0] % 2 != 0) resolution[0] += 1;
if (resolution[1] % 2 != 0) resolution[1] += 1;
if (ImGui.inputInt2("Start/end tick", startEndTick)) {
if (ImGuiHelper.inputInt("Start/end tick", startEndTick)) {
ReplayServer replayServer = Flashback.getReplayServer();
if (editorState != null && replayServer != null) {
editorState.setExportTicks(startEndTick[0], startEndTick[1], replayServer.getTotalReplayTicks());
}
}
ImGui.inputFloat("Framerate", framerate);
ImGuiHelper.inputFloat("Framerate", framerate);
if (ImGui.checkbox("Reset RNG", resetRng)) {
resetRng = !resetRng;
@@ -167,6 +185,10 @@ public class StartExportWindow {
}
if (recordAudio) {
if (ImGui.checkbox("Stereo (2 channel)", stereoAudio)) {
stereoAudio = !stereoAudio;
}
AudioCodec newAudioCodec = ImGuiHelper.enumCombo("Audio Codec", audioCodec, supportedAudioCodecs);
if (newAudioCodec != audioCodec) {
audioCodec = newAudioCodec;
@@ -182,6 +204,15 @@ public class StartExportWindow {
recordAudio = false;
}
if (installedIncompatibleModsString != null) {
ImGuiHelper.separatorWithText("Incompatible Mods");
ImGui.textWrapped("You have some mods installed which are known to cause crashes/rendering issues.\n" +
"If you encounter problems exporting, please try removing the following mods:");
ImGui.pushTextWrapPos();
ImGui.textColored(0xFF0000FF, installedIncompatibleModsString);
ImGui.popTextWrapPos();
}
ImGui.dummy(0, 10);
float buttonSize = (ImGui.getContentRegionAvailX() - ImGui.getStyle().getItemSpacingX()) / 2f;
@@ -264,10 +295,12 @@ public class StartExportWindow {
videoCodec = codecs[0];
}
VideoCodec newCodec = ImGuiHelper.enumCombo("Codec", videoCodec, codecs);
if (newCodec != videoCodec) {
videoCodec = newCodec;
selectedVideoEncoder[0] = 0;
if (codecs.length > 1) {
VideoCodec newCodec = ImGuiHelper.enumCombo("Codec", videoCodec, codecs);
if (newCodec != videoCodec) {
videoCodec = newCodec;
selectedVideoEncoder[0] = 0;
}
}
String[] encoders = videoCodec.getEncoders();
@@ -275,15 +308,21 @@ public class StartExportWindow {
ImGuiHelper.combo("Encoder", selectedVideoEncoder, encoders);
}
if (ImGui.checkbox("Use Maximum Bitrate", useMaximumBitrate)) {
useMaximumBitrate = !useMaximumBitrate;
}
if (!useMaximumBitrate) {
ImGui.inputText("Bitrate", bitrate);
if (ImGui.isItemDeactivatedAfterEdit()) {
int numBitrate = stringToBitrate(ImGuiHelper.getString(bitrate));
bitrate.set(bitrateToString(numBitrate));
if (videoCodec != VideoCodec.GIF) {
if (ImGui.checkbox("Use Maximum Bitrate", useMaximumBitrate)) {
useMaximumBitrate = !useMaximumBitrate;
}
if (!useMaximumBitrate) {
ImGui.inputText("Bitrate", bitrate);
if (ImGui.isItemDeactivatedAfterEdit()) {
int numBitrate = stringToBitrate(ImGuiHelper.getString(bitrate));
bitrate.set(bitrateToString(numBitrate));
}
}
} else {
ImGui.pushTextWrapPos();
ImGui.textColored(0xFFFFFFFF, "Warning: GIF output can be extremely large. Please ensure you know the limitations of the GIF format before exporting. You might be better off using WebP which is a similar but better format");
ImGui.popTextWrapPos();
}
}
@@ -347,8 +386,9 @@ 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.get()), resetRng, container, videoCodec, encoder, numBitrate, transparent, ssaa,
recordAudio, path);
Math.max(1, framerate[0]), resetRng, container, videoCodec, encoder, numBitrate, transparent, ssaa,
recordAudio, stereoAudio, audioCodec,
path);
}
return null;
@@ -26,6 +26,8 @@ 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.ImGuiHoveredFlags;
import imgui.flag.ImGuiMouseButton;
import imgui.flag.ImGuiMouseCursor;
import imgui.flag.ImGuiPopupFlags;
@@ -58,6 +60,9 @@ public class TimelineWindow {
private static int grabbedKeyframeTick = 0;
private static int grabbedKeyframeTrack = 0;
private static boolean trackDisabledButtonDrag = false;
private static boolean trackDisabledButtonDragValue = false;
@Nullable
private static Vector2f dragSelectOrigin = null;
@@ -423,7 +428,7 @@ public class TimelineWindow {
editingKeyframeTick = -1;
}
if (mouseX > x + middleX && mouseX < x + width && mouseY > y + middleY && mouseY < y + height) {
if (mouseX > x + middleX && mouseX < x + width && mouseY > y && mouseY < y + height) {
int scroll = (int) Math.signum(ImGui.getIO().getMouseWheel());
double mousePercentage = (mouseX - (x + middleX)) / (width - middleX);
@@ -518,6 +523,9 @@ 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;
}
if (ImGui.isKeyPressed(GLFW.GLFW_KEY_LEFT, false)) {
pendingStepBackwardsTicks += 1;
} else if (pendingStepBackwardsTicks > 0 && !ImGui.isKeyDown(GLFW.GLFW_KEY_LEFT)) {
@@ -843,11 +851,18 @@ public class TimelineWindow {
}
if (leftClicked) {
grabbedKeyframe = true;
grabbedKeyframeMouseX = mouseX;
grabbedKeyframeTick = closest.getKey();
grabbedKeyframeTrack = trackIndex;
enableKeyframeMovement = false;
if (ImGui.isMouseDoubleClicked(ImGuiMouseButton.Left)) {
MinecraftKeyframeHandler minecraftKeyframeHandler = new MinecraftKeyframeHandler(Minecraft.getInstance());
if (minecraftKeyframeHandler.supportedKeyframes().contains(closest.getValue().keyframeType())) {
closest.getValue().apply(minecraftKeyframeHandler);
}
} else {
grabbedKeyframe = true;
grabbedKeyframeMouseX = mouseX;
grabbedKeyframeTick = closest.getKey();
grabbedKeyframeTrack = trackIndex;
enableKeyframeMovement = false;
}
} else if (rightClicked) {
ImGui.openPopup("##KeyframePopup");
editingKeyframeTrack = trackIndex;
@@ -945,10 +960,10 @@ public class TimelineWindow {
editorState.push(new EditorStateHistoryEntry(undo, redo, "Changed interpolation type to " + interpolationType));
}
ImInt intWrapper = new ImInt(editingKeyframeTick);
int[] intWrapper = new int[]{editingKeyframeTick};
ImGui.setNextItemWidth(160);
ImGui.inputInt("Tick", intWrapper, 0);
int newEditingKeyframeTick = intWrapper.get();
ImGuiHelper.inputInt("Tick", intWrapper);
int newEditingKeyframeTick = intWrapper[0];
if (ImGui.isItemDeactivatedAfterEdit() && newEditingKeyframeTick != editingKeyframeTick) {
for (SelectedKeyframes selectedKeyframes : selectedKeyframesList) {
@@ -996,6 +1011,9 @@ public class TimelineWindow {
grabbedZoomBarResizeRight = false;
grabbedExportBarResizeLeft = false;
grabbedExportBarResizeRight = false;
if (!ImGui.isAnyMouseDown()) {
trackDisabledButtonDrag = false;
}
if (dragSelectOrigin != null) {
float dragMinX = Math.min(dragSelectOrigin.x, mouseX);
@@ -1490,8 +1508,15 @@ public class TimelineWindow {
buttonX += buttonSize + spacingX;
ImGui.setCursorPosX(buttonX - x);
if (ImGui.button("##ToggleEnabled", buttonSize, buttonSize)) {
keyframeTrack.enabled = !keyframeTrack.enabled;
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 (keyframeTrack.enabled) {
drawList.addCircleFilled(buttonX + buttonSize/2, buttonY + buttonSize/2, buttonSize/3, -1);
@@ -1523,7 +1548,7 @@ public class TimelineWindow {
redo.add(new EditorStateHistoryAction.RemoveTrack(keyframeTrack.keyframeType, keyframeTrackToClear));
editorState.push(new EditorStateHistoryEntry(undo, redo, "Delete " + keyframeTrack.keyframeType + " track"));
editorState.push(new EditorStateHistoryEntry(undo, redo, "Delete " + keyframeTrack.keyframeType.name() + " track"));
selectedKeyframesList.clear();
}
@@ -1,16 +1,28 @@
package com.moulberry.flashback.editor.ui.windows;
import com.moulberry.flashback.Flashback;
import com.moulberry.flashback.keyframe.Keyframe;
import com.moulberry.flashback.keyframe.KeyframeType;
import com.moulberry.flashback.keyframe.impl.CameraShakeKeyframe;
import com.moulberry.flashback.keyframe.impl.FOVKeyframe;
import com.moulberry.flashback.keyframe.impl.TimeOfDayKeyframe;
import com.moulberry.flashback.keyframe.types.FOVKeyframeType;
import com.moulberry.flashback.playback.ReplayServer;
import com.moulberry.flashback.record.FlashbackMeta;
import com.moulberry.flashback.state.EditorState;
import com.moulberry.flashback.state.EditorStateHistoryAction;
import com.moulberry.flashback.state.EditorStateHistoryEntry;
import com.moulberry.flashback.state.EditorStateManager;
import com.moulberry.flashback.state.KeyframeTrack;
import com.moulberry.flashback.visuals.ReplayVisuals;
import com.moulberry.flashback.combo_options.Sizing;
import com.moulberry.flashback.editor.ui.ImGuiHelper;
import imgui.ImGui;
import imgui.flag.ImGuiColorEditFlags;
import net.minecraft.client.Minecraft;
import java.util.List;
public class VisualsWindow {
private static final float[] floatBuffer = new float[]{0};
@@ -77,6 +89,19 @@ public class VisualsWindow {
editorState.markDirty();
}
if (!visuals.renderSky) {
if (ImGui.colorButton("Sky Colour", visuals.skyColour)) {
ImGui.openPopup("##EditSkyColour");
}
ImGui.sameLine();
ImGui.text("Sky Colour");
if (ImGui.beginPopup("##EditSkyColour")) {
ImGui.colorPicker3("Sky Colour", visuals.skyColour);
ImGui.endPopup();
}
}
if (ImGui.checkbox("Render Nametags", visuals.renderNametags)) {
visuals.renderNametags = !visuals.renderNametags;
editorState.markDirty();
@@ -110,6 +135,12 @@ public class VisualsWindow {
editorState.markDirty();
}
if (visuals.overrideFov) {
ImGui.sameLine();
if (ImGui.smallButton("+")) {
addKeyframe(editorState, replayServer, new FOVKeyframe(visuals.overrideFovAmount));
}
ImGuiHelper.tooltip("Add FOV keyframe");
floatBuffer[0] = visuals.overrideFovAmount;
if (ImGui.sliderFloat("FOV", floatBuffer, 1.0f, 110.0f, "%.1f")) {
visuals.setFov(floatBuffer[0]);
@@ -127,6 +158,12 @@ public class VisualsWindow {
editorState.markDirty();
}
if (visuals.overrideTimeOfDay >= 0) {
ImGui.sameLine();
if (ImGui.smallButton("+")) {
addKeyframe(editorState, replayServer, new TimeOfDayKeyframe((int) visuals.overrideTimeOfDay));
}
ImGuiHelper.tooltip("Add Time keyframe");
intBuffer[0] = (int) visuals.overrideTimeOfDay;
if (ImGui.sliderInt("Time", intBuffer, 0, 24000)) {
visuals.overrideTimeOfDay = intBuffer[0];
@@ -140,6 +177,19 @@ public class VisualsWindow {
editorState.markDirty();
}
if (visuals.overrideCameraShake) {
ImGui.sameLine();
if (ImGui.smallButton("+")) {
if (visuals.cameraShakeSplitParams) {
addKeyframe(editorState, replayServer, new CameraShakeKeyframe(visuals.cameraShakeXFrequency, visuals.cameraShakeXAmplitude,
visuals.cameraShakeYFrequency, visuals.cameraShakeYAmplitude, true));
} else {
float frequency = (visuals.cameraShakeXFrequency + visuals.cameraShakeYFrequency)/2.0f;
float amplitude = (visuals.cameraShakeXAmplitude + visuals.cameraShakeYAmplitude)/2.0f;
addKeyframe(editorState, replayServer, new CameraShakeKeyframe(frequency, amplitude, frequency, amplitude, false));
}
}
ImGuiHelper.tooltip("Add Camera Shake keyframe");
if (ImGui.checkbox("Split Y/X", visuals.cameraShakeSplitParams)) {
visuals.cameraShakeSplitParams = !visuals.cameraShakeSplitParams;
editorState.markDirty();
@@ -239,4 +289,37 @@ public class VisualsWindow {
}
ImGui.end();
}
private static void addKeyframe(EditorState editorState, ReplayServer replayServer, Keyframe keyframe) {
KeyframeType<?> keyframeType = keyframe.keyframeType();
// Try add to existing enabled keyframe track
for (int i = 0; i < editorState.keyframeTracks.size(); i++) {
KeyframeTrack keyframeTrack = editorState.keyframeTracks.get(i);
if (keyframeTrack.enabled && keyframeTrack.keyframeType == keyframeType) {
editorState.setKeyframe(i, replayServer.getReplayTick(), keyframe);
return;
}
}
// Try add to any keyframe track
for (int i = 0; i < editorState.keyframeTracks.size(); i++) {
KeyframeTrack keyframeTrack = editorState.keyframeTracks.get(i);
if (keyframeTrack.keyframeType == keyframeType) {
editorState.setKeyframe(i, replayServer.getReplayTick(), keyframe);
return;
}
}
String description = "Added " + keyframeType.name() + " keyframe";
int newKeyframeTrackIndex = editorState.keyframeTracks.size();
editorState.push(new EditorStateHistoryEntry(
List.of(new EditorStateHistoryAction.RemoveTrack(keyframeType, newKeyframeTrackIndex)),
List.of(
new EditorStateHistoryAction.AddTrack(keyframeType, newKeyframeTrackIndex),
new EditorStateHistoryAction.SetKeyframe(keyframeType, newKeyframeTrackIndex, replayServer.getReplayTick(), keyframe)
),
description
));
}
}