Added file dialog to graph editor.

This commit is contained in:
Martin Felis
2025-03-11 23:02:11 +01:00
parent 6d9a6fca56
commit 0f9f9d6283
4 changed files with 82 additions and 15 deletions
+57 -14
View File
@@ -14,9 +14,11 @@
#include "imgui.h"
#include "imnodes.h"
#include "misc/cpp/imgui_stdlib.h"
#include "nfd.h"
#include "src/AnimGraph/AnimGraphResource.h"
struct EditorState {
std::string filename;
AnimGraphResource* rootGraphResource = nullptr;
std::vector<AnimGraphResource*> hierarchyStack;
@@ -381,6 +383,7 @@ void AnimGraphEditorClear() {
delete sEditorState.rootGraphResource;
}
sEditorState.filename = "";
sEditorState.rootGraphResource =
dynamic_cast<AnimGraphResource*>(AnimNodeResourceFactory("BlendTree"));
sEditorState.rootGraphResource->m_name = "Root";
@@ -452,22 +455,60 @@ void BlendTreeEditorNodePopup() {
void AnimGraphEditorMenuBar() {
ImGui::BeginMenuBar();
if (ImGui::Button("Save")) {
sEditorState.rootGraphResource->SaveToFile("editor_graph.json");
}
if (ImGui::Button("Load")) {
AnimGraphEditorClear();
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("New")) {
AnimGraphEditorClear();
}
if (ImGui::MenuItem("Load ...", "Ctrl+L")) {
nfdu8char_t* outPath;
nfdu8filteritem_t filters[1] = {{"Json files", "json"}};
nfdopendialogu8args_t args = {0};
args.filterList = filters;
args.filterCount = 1;
args.defaultPath = ".";
nfdresult_t result = NFD_OpenDialogU8_With(&outPath, &args);
delete sEditorState.rootGraphResource;
if (result == NFD_OKAY) {
AnimGraphEditorClear();
delete sEditorState.rootGraphResource;
sEditorState.rootGraphResource =
AnimGraphResource::CreateFromFile("editor_graph.json");
sEditorState.filename = outPath;
sEditorState.rootGraphResource =
AnimGraphResource::CreateFromFile(sEditorState.filename.c_str());
AnimGraphEditorResetHierarchyStack();
}
if (ImGui::Button("Clear")) {
AnimGraphEditorClear();
AnimGraphEditorResetHierarchyStack();
NFD_FreePathU8(outPath);
}
}
if (ImGui::MenuItem(
"Save",
"Ctrl+S",
nullptr,
!sEditorState.filename.empty())) {
sEditorState.rootGraphResource->SaveToFile(sEditorState.filename.c_str());
}
if (ImGui::MenuItem("Save as ...")) {
nfdu8char_t* outPath;
nfdu8filteritem_t filters[1] = {{"Json files", "json"}};
nfdsavedialogu8args_t args = {0};
args.filterList = filters;
args.filterCount = 1;
args.defaultPath = ".";
nfdresult_t result =
NFD_SaveDialogU8(&outPath, args.filterList, 1, ".", "BlendTree.json");
if (result == NFD_OKAY) {
sEditorState.filename = outPath;
sEditorState.rootGraphResource->SaveToFile(
sEditorState.filename.c_str());
NFD_FreePathU8(outPath);
}
}
ImGui::EndMenu();
}
if (ImGui::Button("Content")) {
ax::NodeEditor::NavigateToContent();
}
@@ -487,9 +528,11 @@ void AnimGraphEditorMenuBar() {
}
void AnimGraphEditorBreadcrumbNavigation() {
ImGui::Text("Navigation:");
ImGui::SameLine();
for (size_t i = 0, n = sEditorState.hierarchyStack.size(); i < n; i++) {
AnimGraphResource* graph_resource =
dynamic_cast<AnimGraphResource*>(sEditorState.hierarchyStack[i]);
AnimGraphResource* graph_resource = sEditorState.hierarchyStack[i];
ImGui::PushID(graph_resource);
bool highlight_button = i == sEditorState.hierarchyStackIndex;
+6
View File
@@ -20,6 +20,7 @@
#include "3rdparty/imgui-node-editor/imgui_node_editor.h"
#include "3rdparty/json/json.hpp"
#include "3rdparty/nativefiledialog-extended/src/include/nfd.h"
#include "AnimGraph/AnimGraphBlendTree.h"
#include "AnimGraph/AnimGraphData.h"
#include "AnimGraphEditor/AnimGraphEditor.h"
@@ -462,6 +463,8 @@ int main() {
gApplicationConfig.window_size[1]);
}
NFD_Init();
// setup sokol_gfx and sokol_time
stm_setup();
sg_desc desc = {
@@ -1065,6 +1068,9 @@ int main() {
sgl_shutdown();
sg_shutdown();
NFD_Quit();
glfwTerminate();
return 0;
}