From 48c5a3bcf33a7a4343dd7c1e228874bfde00ac4b Mon Sep 17 00:00:00 2001 From: austin Date: Sun, 18 May 2025 12:15:01 -0400 Subject: [PATCH] fab-saving work --- assets/Data/fab/defaultHouse.fab | Bin 0 -> 580 bytes docs/src/progress/renderertodo.md | 2 + .../ui/menu/editor/ImGuiStructureTab.java | 7 +- .../data/block/fab/BlockFab.java | 5 ++ .../renderer/pipelines/ImGuiPipeline.java | 2 + .../filediag/ImGuiFileDialogManager.java | 79 ++++++++++++++++++ 6 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 assets/Data/fab/defaultHouse.fab create mode 100644 src/main/java/electrosphere/renderer/ui/imgui/filediag/ImGuiFileDialogManager.java diff --git a/assets/Data/fab/defaultHouse.fab b/assets/Data/fab/defaultHouse.fab new file mode 100644 index 0000000000000000000000000000000000000000..7af7619e56cb5a9dbcb0acd7c0b4d12eb0900cf2 GIT binary patch literal 580 zcmb2|=3oGW|8FCGvky6l@N_J{_e=Pjj$`sAr@Twk;=DBfGHk8rm?gH**K3#4+8_6K z&wi7Yb6urw!GFOXIUArOFQr8*;ALz+J*k5$K3dN`uI_A&#A|bie{PjbLVe6 zE&5+|&)nR$S9h0f-L(9MQS8<)PdnD+TU5Ty+ { + currentFab.write(target); + }); } } } diff --git a/src/main/java/electrosphere/data/block/fab/BlockFab.java b/src/main/java/electrosphere/data/block/fab/BlockFab.java index 316e85a8..63d18613 100644 --- a/src/main/java/electrosphere/data/block/fab/BlockFab.java +++ b/src/main/java/electrosphere/data/block/fab/BlockFab.java @@ -33,6 +33,11 @@ public class BlockFab implements BlockMeshgenData { 1 * 4 + 3 * 4 ; + + /** + * Default file ending for block fabs + */ + public static final String DEFAULT_FILE_ENDING = ".fab"; /** * Dimensions of the block fab diff --git a/src/main/java/electrosphere/renderer/pipelines/ImGuiPipeline.java b/src/main/java/electrosphere/renderer/pipelines/ImGuiPipeline.java index b7c36aee..bd68b084 100644 --- a/src/main/java/electrosphere/renderer/pipelines/ImGuiPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/ImGuiPipeline.java @@ -10,6 +10,7 @@ import electrosphere.logger.LoggerInterface; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; import electrosphere.renderer.ui.imgui.ImGuiWindow; +import electrosphere.renderer.ui.imgui.filediag.ImGuiFileDialogManager; import imgui.ImGui; import imgui.ImGuiViewport; import imgui.extension.implot.ImPlot; @@ -64,6 +65,7 @@ public class ImGuiPipeline implements RenderPipeline { if(ImGuiPipeline.shouldRenderDragAndDropTarget()){ ImGuiPipeline.renderDragAndDropTarget(); } + ImGuiFileDialogManager.handleFileDialogs(); for(ImGuiWindow window : imGuiWindows){ window.draw(); } diff --git a/src/main/java/electrosphere/renderer/ui/imgui/filediag/ImGuiFileDialogManager.java b/src/main/java/electrosphere/renderer/ui/imgui/filediag/ImGuiFileDialogManager.java new file mode 100644 index 00000000..bbfa77f1 --- /dev/null +++ b/src/main/java/electrosphere/renderer/ui/imgui/filediag/ImGuiFileDialogManager.java @@ -0,0 +1,79 @@ +package electrosphere.renderer.ui.imgui.filediag; + +import java.io.File; +import java.util.function.Consumer; + +import imgui.extension.imguifiledialog.ImGuiFileDialog; + +/** + * Manages file dialogs created with imgui + */ +public class ImGuiFileDialogManager { + + /** + * Key for the file dialog + */ + public static final String key = "fileDiagKey"; + + /** + * Minimum width of the file modal + */ + public static final int MIN_WIDTH = 500; + + /** + * Minimum height of the file modal + */ + public static final int MIN_HEIGHT = 500; + + /** + * Maximum width of the file modal + */ + public static final int MAX_WIDTH = 1000; + + /** + * Maximum height of the file modal + */ + public static final int MAX_HEIGHT = 1000; + + /** + * Filter for any file ending + */ + public static final String ANY_FILE_ENDING = ".*"; + + /** + * The consumer of the selected path when a selection is made in the dialog + */ + private static Consumer onAccept = null; + + /** + * Opens the file dialog + * @param onAccept The consumer for the path when a file is selected + */ + public static void open(String title, String fileDefaultName, String fileEndings, Consumer onAccept){ + ImGuiFileDialogManager.onAccept = onAccept; + ImGuiFileDialog.openModal(key, title, fileEndings, fileDefaultName, 0, 0, 0); + } + + /** + * Opens the file dialog + * @param onAccept The consumer for the path when a file is selected + */ + public static void openDirSelect(String title, String fileDefaultName, Consumer onAccept){ + ImGuiFileDialogManager.onAccept = onAccept; + ImGuiFileDialog.openModal(key, title, null, fileDefaultName, 0, 0, 0); + } + + /** + * Handles rendering file dialog + */ + public static void handleFileDialogs(){ + if(ImGuiFileDialog.display(key, 0, MIN_WIDTH, MIN_HEIGHT, MAX_WIDTH, MAX_HEIGHT)){ + if(ImGuiFileDialog.isOk()){ + File file = new File(ImGuiFileDialog.getCurrentPath() + "/" + ImGuiFileDialog.getCurrentFileName()); + onAccept.accept(file); + } + ImGuiFileDialog.close(); + } + } + +}