瀏覽代碼

check if GD is running before saving

____tbvns____ 5 月之前
父節點
當前提交
544775063c

+ 16 - 0
PowerGDEditor/src/main/java/xyz/tbvns/GeometryDash/GeometryDashProcess.java

@@ -0,0 +1,16 @@
+package xyz.tbvns.GeometryDash;
+
+import oshi.SystemInfo;
+import oshi.software.os.OSProcess;
+
+public class GeometryDashProcess {
+    public static boolean isRunning() {
+        SystemInfo info = new SystemInfo();
+        for (OSProcess process : info.getOperatingSystem().getProcesses()) {
+            if (process.getName().contains("GeometryDash")) {
+                return true;
+            }
+        }
+        return false;
+    }
+}

+ 2 - 1
PowerGDEditor/src/main/java/xyz/tbvns/Main.java

@@ -20,6 +20,7 @@ import org.joml.Vector4d;
 import org.joml.Vector4dc;
 import org.lwjgl.opengl.GL11;
 import xyz.tbvns.Editor.ModelsManager;
+import xyz.tbvns.GeometryDash.GeometryDashProcess;
 import xyz.tbvns.Inputs.Shortcut;
 import xyz.tbvns.Inputs.inputManager;
 import xyz.tbvns.LWJGL3.CustomViewport;
@@ -53,7 +54,7 @@ public class Main extends ApplicationAdapter {
         Ui.initImGui();
         UIManager.loadUi();
         UIManager.getActiveUI().put(LevelSelector.class, true);
-        TexturesManager.idFileMap.size();
+
         batch = new ModelBatch();
         camera = new PerspectiveCamera(80, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
         camera.far = 1000;

+ 9 - 3
PowerGDEditor/src/main/java/xyz/tbvns/ui/MenuBarTabs/SaveMenu.java

@@ -3,11 +3,13 @@ package xyz.tbvns.ui.MenuBarTabs;
 import imgui.ImGui;
 import xyz.tbvns.DataManager;
 import xyz.tbvns.Decoder;
+import xyz.tbvns.GeometryDash.GeometryDashProcess;
 import xyz.tbvns.GeometryDash.Render;
 import xyz.tbvns.LevelInfo;
 import xyz.tbvns.Main;
 import xyz.tbvns.ui.MenuBarTab;
 import xyz.tbvns.ui.UIManager;
+import xyz.tbvns.ui.Windows.GDRunningErrorWindow;
 import xyz.tbvns.ui.Windows.LevelSelector;
 
 public class SaveMenu implements MenuBarTab {
@@ -16,9 +18,13 @@ public class SaveMenu implements MenuBarTab {
         if (ImGui.beginMenu("Files")) {
             if (ImGui.menuItem("Save", "CTRL S")) {
                 try {
-                    LevelInfo.setLevelString(new Render().fullRender(24));
-                    LevelInfo.getLevel().setEncodedLevelString(Decoder.encodeLevel(LevelInfo.getLevelString()));
-                    DataManager.saveLevel(LevelInfo.getLevel());
+                    if (!GeometryDashProcess.isRunning()) {
+                        LevelInfo.setLevelString(new Render().fullRender(24));
+                        LevelInfo.getLevel().setEncodedLevelString(Decoder.encodeLevel(LevelInfo.getLevelString()));
+                        DataManager.saveLevel(LevelInfo.getLevel());
+                    } else {
+                        UIManager.getActiveUI().put(GDRunningErrorWindow.class, true);
+                    }
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }

+ 23 - 0
PowerGDEditor/src/main/java/xyz/tbvns/ui/Windows/GDRunningErrorWindow.java

@@ -0,0 +1,23 @@
+package xyz.tbvns.ui.Windows;
+
+import imgui.ImGui;
+import imgui.ImGuiStyle;
+import imgui.flag.ImGuiCol;
+import xyz.tbvns.ui.Element;
+import xyz.tbvns.ui.UIManager;
+
+public class GDRunningErrorWindow implements Element {
+    @Override
+    public void render() {
+        ImGui.pushStyleColor(ImGuiCol.TitleBgActive, 255, 0, 0, 255);
+        ImGui.pushStyleColor(ImGuiCol.TitleBg, 150, 0, 0, 255);
+        ImGui.pushStyleColor(ImGuiCol.TitleBgCollapsed, 100, 50, 50, 255);
+        ImGui.begin("Error:");
+        ImGui.text("GeometryDash is running !\nPlease close GeometryDash before saving.");
+        if (ImGui.button("Close")) {
+            UIManager.getActiveUI().put(GDRunningErrorWindow.class, false);
+        }
+        ImGui.end();
+        ImGui.popStyleColor(3);
+    }
+}