diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-14 15:19:31 -0500 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-12-14 15:19:31 -0500 |
| commit | 365eb04eebf4e5fc6d1d47d55cd541eedb47f64c (patch) | |
| tree | 678564926656de469f7c3a8cb758cf43a18f1f47 /editor | |
| parent | 1af7d379467f27bdef587b27cc6e19539349e129 (diff) | |
editor save-as and other cleanup
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/editor.cpp | 70 |
1 files changed, 57 insertions, 13 deletions
diff --git a/editor/editor.cpp b/editor/editor.cpp index 4ef9b26..c4a2a20 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -17,6 +17,7 @@ #include "imgui.h" #include <GLFW/glfw3.h> +#include <compare> #include <filesystem> #include <future> #include <regex> @@ -121,6 +122,7 @@ void PkeEditor_Tick(double delta) { PkeEditor_Teardown(); } if (shouldSaveProjectFile) { + shouldSaveProjectFile = false; PkeProject_Save(); } if (shouldOpenLoadSceneDialog) { @@ -139,9 +141,21 @@ void PkeEditor_Tick(double delta) { Game_LoadSceneFile(sceneName); } + if (shouldOpenSaveSceneDialog) { + shouldOpenSaveSceneDialog = false; + PkeThreads_Enqueue(threadPoolHandle, std::packaged_task<void()>( [] { + const char * patterns[1] = {"*.pstf"}; + char *selectedScene = tinyfd_saveFileDialog(nullptr, sceneName, 1, patterns, "Pke Scene Text File"); + if (selectedScene != nullptr) { + sceneName = selectedScene; + shouldSaveScene = true; + } + })); + } if (shouldSaveScene && sceneName) { shouldSaveScene = false; Game_SaveSceneFile(sceneName); + shouldRebuildProjectDir = true; } if (EntitiesToBeRemoved.Has(selectedEntity)) { @@ -401,6 +415,24 @@ void RecordImGuiEditorWrapper() { ImGui::DockSpaceOverViewport(nullptr, ImGuiDockNodeFlags_PassthruCentralNode); ImGui::BeginMainMenuBar(); if (ImGui::BeginMenu("File")) { + if (ImGui::MenuItem("Save")) { + shouldSaveProjectFile = true; + shouldSaveScene = true; + } + if (sceneName) { + ImGui::SameLine(); + int offset = 0; + const auto *slash = strrchr(sceneName, '\\'); + slash = slash != nullptr ? slash : strrchr(sceneName, '/'); + if (slash != nullptr) { + offset = slash - sceneName; + } + ImGui::Text("%s", sceneName + offset); + } + if (ImGui::MenuItem("Save As...")) { + shouldSaveProjectFile = true; + shouldOpenSaveSceneDialog = true; + } if (ImGui::MenuItem("Exit")) { glfwSetWindowShouldClose(window, true); } @@ -806,14 +838,37 @@ struct fsEntry { }; DynArray<fsEntry> fsEntries{0, nullptr}; std::regex reg_sceneFile(".+\\.ps[tb]f$", std::regex_constants::icase); +int fsEntryComp(const void *a, const void *b) { + const auto &fsA = *static_cast<const fsEntry *>(a); + const auto &fsB = *static_cast<const fsEntry *>(b); + if (fsA.type == fsB.type) { + return strcmp(fsA.name, fsB.name); + } + auto cmp = fsA.type <=> fsB.type; + if (cmp == std::strong_ordering::less) { + return -1; + } + if (cmp == std::strong_ordering::greater) { + return 1; + } + return 0; +} +void SortRecursive(DynArray<fsEntry> &arr) { + std::qsort(arr.GetPtr(), arr.Count(), sizeof(fsEntry), fsEntryComp); + for (long i = 0; i < arr.Count(); ++i) { + SortRecursive(arr[i].children); + } +} void BuildDirRecursive(const std::filesystem::directory_entry &de, fsEntry *dirFsEntry) { auto &entry = dirFsEntry == nullptr ? fsEntries.Push() : dirFsEntry->children.Push(); auto fullPath = std::filesystem::absolute(de.path()); auto len = strlen(fullPath.c_str()); + // leaky entry.path = Pke_New<char>(len + 1); memset(entry.path, '\0', len + 1); memcpy(entry.path, fullPath.c_str(), len); len = strlen(fullPath.filename().c_str()); + // leaky entry.name = Pke_New<char>(len + 1); memset(entry.name, '\0', len + 1); memcpy(entry.name, fullPath.filename().c_str(), len); @@ -856,6 +911,7 @@ void RecordImGuiProjectBrowser() { } if (shouldRebuildProjectDir == true) { shouldRebuildProjectDir = false; + fsEntries.Resize(0); std::filesystem::directory_iterator di{std::filesystem::current_path()}; for (const std::filesystem::directory_entry &sde : di) { if (sde.is_directory() @@ -864,6 +920,7 @@ void RecordImGuiProjectBrowser() { BuildDirRecursive(sde, nullptr); } } + SortRecursive(fsEntries); } for (long i = 0; i < fsEntries.Count(); ++i) { BuildProjectMenuRecursive(fsEntries[i]); @@ -879,19 +936,6 @@ void RecordImGuiSceneEditor() { if (ImGui::Button("Create Entity Type")) { ImGui::OpenPopup("CreateEntityType"); } - if (ImGui::Button("Save")) { - shouldSaveScene = true; - } - if (sceneName) { - ImGui::SameLine(); - ImGui::Text("%s", sceneName); - } - if (ImGui::Button("Save As...")) { - shouldOpenSaveSceneDialog = true; - } - if (ImGui::Button("Load")) { - shouldOpenLoadSceneDialog = true; - } if (ImGui::Button("Clear Selection")) { selectedEntity = EntityHandle_MAX; } |
