diff --git a/assets/Data/fab/defaultHouse.fab b/assets/Data/fab/defaultHouse.fab new file mode 100644 index 00000000..7af7619e Binary files /dev/null and b/assets/Data/fab/defaultHouse.fab differ diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 11deba59..53e8f2b5 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1863,6 +1863,8 @@ Visualize furniture placement slots AssetDataStrings work Invert rotation calculation for fab cursor BlockFab io work +File dialog support +Editor structure tab uses file dialog to save fabs diff --git a/src/main/java/electrosphere/client/ui/menu/editor/ImGuiStructureTab.java b/src/main/java/electrosphere/client/ui/menu/editor/ImGuiStructureTab.java index b6104c19..6ebdc87f 100644 --- a/src/main/java/electrosphere/client/ui/menu/editor/ImGuiStructureTab.java +++ b/src/main/java/electrosphere/client/ui/menu/editor/ImGuiStructureTab.java @@ -12,6 +12,7 @@ import electrosphere.data.block.fab.BlockFabMetadata; import electrosphere.data.block.fab.RoomMetadata; import electrosphere.data.block.fab.StructureMetadata; import electrosphere.engine.Globals; +import electrosphere.renderer.ui.imgui.filediag.ImGuiFileDialogManager; import imgui.ImGui; /** @@ -44,8 +45,10 @@ public class ImGuiStructureTab { RoomSolver.computeRoomsFromSelection(Globals.cursorState.getAreaSelection(),currentFab.getFabMetadata().getStructureData()); } if(ImGui.button("Save")){ - File exportLoc = new File("./assets/Data/fab/struct.block"); - currentFab.write(exportLoc); + String defaultName = "struct"; + ImGuiFileDialogManager.open("Save Fab", defaultName, ".fab", (File target) -> { + 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(); + } + } + +}