diff --git a/core/story-manager/interfaces/i_story_manager.h b/core/story-manager/interfaces/i_story_manager.h index cb0502e..5d34576 100644 --- a/core/story-manager/interfaces/i_story_manager.h +++ b/core/story-manager/interfaces/i_story_manager.h @@ -52,11 +52,6 @@ public: virtual void LoadBinaryStory(const std::string &filename) = 0; virtual void ToggleBreakpoint(int line) = 0; virtual uint32_t GetRegister(int reg) = 0; - - // Variables management - virtual void ScanVariable(const std::function element)>& operation) = 0; - virtual void AddVariable() = 0; - virtual void DeleteVariable(int i) = 0; virtual void Play() = 0; virtual void Step() = 0; diff --git a/core/story-manager/interfaces/i_story_project.h b/core/story-manager/interfaces/i_story_project.h index f12727c..e20edc3 100644 --- a/core/story-manager/interfaces/i_story_project.h +++ b/core/story-manager/interfaces/i_story_project.h @@ -4,6 +4,7 @@ #include #include "connection.h" #include "story_options.h" +#include "variable.h" class IStoryProject { @@ -36,7 +37,10 @@ public: virtual void SetName(const std::string &name) = 0; virtual void SetUuid(const std::string &uuid) = 0; - + virtual void ScanVariable(const std::function element)>& operation) = 0; + virtual void AddVariable() = 0; + virtual void DeleteVariable(int i) = 0; + }; diff --git a/core/story-manager/src/nodes/compare_node.cpp b/core/story-manager/src/nodes/compare_node.cpp index 9d9bdd6..9048320 100644 --- a/core/story-manager/src/nodes/compare_node.cpp +++ b/core/story-manager/src/nodes/compare_node.cpp @@ -5,7 +5,7 @@ CompareNode::CompareNode(const std::string &type) - : BaseNode(type, "Branch Node") + : BaseNode(type, "Compare Node") { } diff --git a/core/story-manager/src/story_primitive.h b/core/story-manager/src/story_primitive.h index 90ce5e1..1e388b2 100644 --- a/core/story-manager/src/story_primitive.h +++ b/core/story-manager/src/story_primitive.h @@ -76,6 +76,16 @@ public: m_uuid = uuid; } + virtual void ScanVariable(const std::function element)>& operation) override { + + } + virtual void AddVariable() override { + + } + virtual void DeleteVariable(int i) override { + + } + private: std::string m_name; std::string m_description; diff --git a/core/story-manager/src/story_project.h b/core/story-manager/src/story_project.h index 0008961..7b26618 100644 --- a/core/story-manager/src/story_project.h +++ b/core/story-manager/src/story_project.h @@ -112,10 +112,10 @@ public: std::pair>::iterator, std::list>::iterator> Links(const std::string_view &page_uuid); - void ScanVariable(const std::function element)>& operation); - void AddVariable(); - void DeleteVariable(int i); - + void ScanVariable(const std::function element)>& operation) override; + void AddVariable() override; + void DeleteVariable(int i) override; + private: ILogger &m_log; diff --git a/story-editor/imgui.ini b/story-editor/imgui.ini index 169a589..a68d4ea 100644 --- a/story-editor/imgui.ini +++ b/story-editor/imgui.ini @@ -9,32 +9,32 @@ Size=400,400 Collapsed=0 [Window][Library Manager] -Pos=878,26 -Size=402,694 +Pos=591,26 +Size=689,224 Collapsed=0 DockId=0x00000003,0 [Window][Console] -Pos=60,735 -Size=610,253 +Pos=60,533 +Size=610,187 Collapsed=0 DockId=0x00000004,0 [Window][Emulator] -Pos=878,26 -Size=402,403 +Pos=591,26 +Size=689,224 Collapsed=0 DockId=0x00000003,5 [Window][Code viewer] -Pos=878,26 -Size=402,403 +Pos=591,26 +Size=689,224 Collapsed=0 DockId=0x00000003,4 [Window][Resources] -Pos=878,26 -Size=402,403 +Pos=591,26 +Size=689,224 Collapsed=0 DockId=0x00000003,1 @@ -50,32 +50,32 @@ Size=150,42 Collapsed=0 [Window][Variables] -Pos=672,735 -Size=608,253 +Pos=672,533 +Size=608,187 Collapsed=0 DockId=0x00000005,0 [Window][CPU] -Pos=878,26 -Size=402,403 +Pos=591,26 +Size=689,224 Collapsed=0 DockId=0x00000003,2 [Window][RAM view] -Pos=878,26 -Size=402,403 +Pos=591,26 +Size=689,224 Collapsed=0 DockId=0x00000003,3 [Window][Properties] -Pos=878,431 -Size=402,302 +Pos=591,252 +Size=689,279 Collapsed=0 DockId=0x00000006,0 [Window][ToolBar] Pos=0,26 -Size=60,962 +Size=60,694 Collapsed=0 [Window][QuitConfirm] @@ -90,16 +90,21 @@ Collapsed=0 [Window][Module editor] Pos=60,26 -Size=816,707 +Size=529,505 Collapsed=0 DockId=0x00000001,1 [Window][Story editor] Pos=60,26 -Size=816,707 +Size=529,505 Collapsed=0 DockId=0x00000001,0 +[Window][Choose a library directory##ChooseLibraryDirDialog] +Pos=490,260 +Size=687,422 +Collapsed=0 + [Table][0x7728942D,5] RefScale=20 Column 0 Width=44 Sort=0v @@ -132,14 +137,18 @@ Column 0 Width=120 Sort=0v Column 1 Width=104 Column 2 Width=120 +[Table][0x874E6ACA,4] +RefScale=20 +Column 0 Sort=0v + [Docking][Data] DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=60,26 Size=1220,694 Split=Y - DockNode ID=0x00000007 Parent=0x08BD597D SizeRef=1220,439 Split=X - DockNode ID=0x00000001 Parent=0x00000007 SizeRef=816,694 CentralNode=1 Selected=0x93ADCAAB - DockNode ID=0x00000002 Parent=0x00000007 SizeRef=402,694 Split=Y Selected=0x52EB28B5 - DockNode ID=0x00000003 Parent=0x00000002 SizeRef=718,250 Selected=0x63869CAF - DockNode ID=0x00000006 Parent=0x00000002 SizeRef=718,187 Selected=0x8C72BEA8 - DockNode ID=0x00000008 Parent=0x08BD597D SizeRef=1220,253 Split=X Selected=0xEA83D666 + DockNode ID=0x00000007 Parent=0x08BD597D SizeRef=1220,505 Split=X + DockNode ID=0x00000001 Parent=0x00000007 SizeRef=721,694 CentralNode=1 Selected=0x93ADCAAB + DockNode ID=0x00000002 Parent=0x00000007 SizeRef=689,694 Split=Y Selected=0x52EB28B5 + DockNode ID=0x00000003 Parent=0x00000002 SizeRef=718,224 Selected=0x63869CAF + DockNode ID=0x00000006 Parent=0x00000002 SizeRef=718,279 Selected=0x8C72BEA8 + DockNode ID=0x00000008 Parent=0x08BD597D SizeRef=1220,187 Split=X Selected=0xEA83D666 DockNode ID=0x00000004 Parent=0x00000008 SizeRef=610,192 Selected=0xEA83D666 DockNode ID=0x00000005 Parent=0x00000008 SizeRef=608,192 Selected=0x6DE9B20C diff --git a/story-editor/src/app/app_controller.cpp b/story-editor/src/app/app_controller.cpp index 40dd953..96fd30b 100644 --- a/story-editor/src/app/app_controller.cpp +++ b/story-editor/src/app/app_controller.cpp @@ -404,36 +404,6 @@ uint32_t AppController::GetRegister(int reg) return regVal; } -void AppController::ScanVariable(const std::function element)>& operation) -{ - if (m_story) - { - m_story->ScanVariable(operation); - } -} - -void AppController::AddVariable() -{ - if (m_story) - { - m_story->AddVariable(); - m_logger.Log("Variable added to project: " + m_story->GetProjectFilePath()); - } else { - m_logger.Log("No project open to add a variable.", true); - } -} - -void AppController::DeleteVariable(int i) -{ - if (m_story) - { - m_story->DeleteVariable(i); - m_logger.Log("Variable deleted from project: " + m_story->GetProjectFilePath()); - } else { - m_logger.Log("No project open to delete a variable.", true); - } -} - void AppController::Play() { @@ -903,14 +873,17 @@ std::shared_ptr AppController::OpenModule(const std::string &uuid m_module = m_nodesFactory.GetModule(uuid); if (!m_module) { + m_eventBus.Emit(std::make_shared(false, "Cannot find module: " + uuid)); m_logger.Log("Cannot find module: " + uuid, true); } else if (m_module->Load(m_resources, m_nodesFactory)) { + m_eventBus.Emit(std::make_shared(ModuleEvent::Type::Opened, uuid)); m_logger.Log("Open module success: " + uuid); } else { + m_eventBus.Emit(std::make_shared(false, "Failed to open module: " + uuid)); m_logger.Log("Open module error: " + uuid, true); } return m_module; diff --git a/story-editor/src/app/app_controller.h b/story-editor/src/app/app_controller.h index 3278d38..7831bdc 100644 --- a/story-editor/src/app/app_controller.h +++ b/story-editor/src/app/app_controller.h @@ -66,7 +66,7 @@ public: void SaveStory(const std::string &path = ""); void ExportStory(const std::string &filename); std::shared_ptr GetCurrentStory() const { return m_story; } - std::shared_ptr GetModuleStory() const { return m_module; } + std::shared_ptr GetCurrentModule() const { return m_module; } void BuildNodes(IStoryProject::Type type); void Build(bool compileonly); void BuildCode(std::shared_ptr story, bool compileonly, bool force = false); @@ -76,9 +76,6 @@ public: virtual void LoadBinaryStory(const std::string &filename) override; virtual void ToggleBreakpoint(int line) override; virtual uint32_t GetRegister(int reg) override; - virtual void ScanVariable(const std::function element)>& operation) override; - virtual void AddVariable() override; - virtual void DeleteVariable(int i) override; virtual void Play() override; virtual void Step() override; virtual void Run() override; diff --git a/story-editor/src/events/all_events.h b/story-editor/src/events/all_events.h index ff96cfc..946641b 100644 --- a/story-editor/src/events/all_events.h +++ b/story-editor/src/events/all_events.h @@ -55,4 +55,24 @@ private: std::string m_message; }; +class ModuleEvent : public Event +{ +public: + enum class Type + { + Opened, + Closed, + }; + + ModuleEvent(Type type, const std::string &uuid) + : m_type(type), m_uuid(uuid) {} + + Type GetType() const { return m_type; } + const std::string& GetUuid() const { return m_uuid; } + +private: + Type m_type; + std::string m_uuid; +}; + #endif // ALL_EVENTS_H \ No newline at end of file diff --git a/story-editor/src/main.cpp b/story-editor/src/main.cpp index 1a0005c..7ba6b7e 100644 --- a/story-editor/src/main.cpp +++ b/story-editor/src/main.cpp @@ -16,6 +16,7 @@ int main(int, char**) bool done = false; + appController.Initialize(); if (w->Initialize()) { while (!done) diff --git a/story-editor/src/main_window.cpp b/story-editor/src/main_window.cpp index 2d51660..ff1479b 100644 --- a/story-editor/src/main_window.cpp +++ b/story-editor/src/main_window.cpp @@ -36,7 +36,6 @@ MainWindow::MainWindow(ILogger& logger, EventBus& eventBus, AppController& appCo , m_nodeEditorWindow(appController, appController.GetNodesFactory(), IStoryProject::PROJECT_TYPE_STORY) , m_moduleEditorWindow(appController, appController.GetNodesFactory(), IStoryProject::PROJECT_TYPE_MODULE) , m_libraryWindow(appController, appController.GetLibraryManager(), appController.GetNodesFactory()) - , m_variablesWindow(appController) , m_projectPropertiesDialog(appController, appController.GetResourceManager()) { CloseProject(); @@ -58,8 +57,6 @@ MainWindow::MainWindow(ILogger& logger, EventBus& eventBus, AppController& appCo m_eventBus.Subscribe([this](const GenericResultEvent &event) { - // FIXME: ImGui notification widget - if (event.IsSuccess()) { m_logger.Log("Operation successful: " + event.GetMessage()); m_toastNotifier.addToast("Success", event.GetMessage(), ToastType::Success); @@ -68,12 +65,19 @@ MainWindow::MainWindow(ILogger& logger, EventBus& eventBus, AppController& appCo m_toastNotifier.addToast("Error", event.GetMessage(), ToastType::Error); } }); + + m_eventBus.Subscribe([this](const ModuleEvent &event) { + if (event.GetType() == ModuleEvent::Type::Opened) { + OpenModule(event.GetUuid()); + } else if (event.GetType() == ModuleEvent::Type::Closed) { + CloseModule(); + } + }); } MainWindow::~MainWindow() { m_gui.Destroy(); - m_appController.SaveParams(); } @@ -102,19 +106,6 @@ float MainWindow::DrawMainMenuBar() } } - if (ImGui::MenuItem("New module")) - { - // Current module project - CloseModule(); - showNewProject = true; - NewModule(); - } - - if (ImGui::MenuItem("Save module")) - { - SaveModule(); - } - /* if (ImGui::BeginMenu("Open Recent")) { @@ -137,7 +128,6 @@ float MainWindow::DrawMainMenuBar() if (!init) ImGui::BeginDisabled(); - ImGui::Separator(); if (ImGui::MenuItem("Save project")) { m_appController.SaveProject(); @@ -153,13 +143,30 @@ float MainWindow::DrawMainMenuBar() m_projectPropertiesDialog.Show(); } + + if (!init) + ImGui::EndDisabled(); + + ImGui::Separator(); + + if (ImGui::MenuItem("New module")) + { + // Current module project + CloseModule(); + showNewProject = true; + NewModule(); + } + + if (ImGui::MenuItem("Save module")) + { + SaveModule(); + } + if (ImGui::MenuItem("Close module")) { CloseModule(); } - if (!init) - ImGui::EndDisabled(); ImGui::EndMenu(); } @@ -201,7 +208,7 @@ bool MainWindow::Initialize() m_emulatorDock.Initialize(); m_nodeEditorWindow.Initialize(); m_moduleEditorWindow.Initialize(); - m_PropertiesWindow.Initialize(); + m_propertiesWindow.Initialize(); m_libraryWindow.Initialize(); success = true; @@ -266,7 +273,7 @@ void MainWindow::OpenProject(const std::string &uuid) m_consoleWindow.Enable(); m_debuggerWindow.Enable(); m_resourcesDock.Enable(); - m_PropertiesWindow.Enable(); + m_propertiesWindow.Enable(); m_variablesWindow.Enable(); m_cpuWindow.Enable(); @@ -293,16 +300,24 @@ void MainWindow::SaveModule() { m_appController.SaveModule(); m_logger.Log("Modules saved"); + m_toastNotifier.addToast("Module", "Module saved", ToastType::Success); } void MainWindow::OpenModule(const std::string &uuid) { - auto module = m_appController.OpenModule(uuid); + auto module = m_appController.GetCurrentModule(); if (module) { - std::shared_ptr modulePtr = std::dynamic_pointer_cast(module); - m_moduleEditorWindow.Load(modulePtr); + m_moduleEditorWindow.Load(module); m_moduleEditorWindow.Enable(); + + m_emulatorDock.Enable(); + m_consoleWindow.Enable(); + m_debuggerWindow.Enable(); + m_resourcesDock.Enable(); + m_propertiesWindow.Enable(); + m_variablesWindow.Enable(); + m_cpuWindow.Enable(); } } @@ -329,7 +344,7 @@ void MainWindow::CloseProject() m_emulatorDock.Disable(); m_debuggerWindow.Disable(); m_resourcesDock.Disable(); - m_PropertiesWindow.Disable(); + m_propertiesWindow.Disable(); m_variablesWindow.Disable(); m_cpuWindow.Disable(); @@ -421,20 +436,26 @@ bool MainWindow::Loop() if (m_appController.IsLibraryManagerInitialized()) { + bool nodeEditorFocused = m_nodeEditorWindow.IsFocused(); m_consoleWindow.Draw(); m_emulatorDock.Draw(); m_debuggerWindow.Draw(); m_resourcesDock.Draw(); m_nodeEditorWindow.Draw(); m_moduleEditorWindow.Draw(); - m_variablesWindow.Draw(); + + + auto currentStory = nodeEditorFocused ? m_nodeEditorWindow.GetCurrentStory() : m_moduleEditorWindow.GetCurrentStory(); + m_variablesWindow.Draw(currentStory); m_cpuWindow.Draw(); static MemoryEditor mem_edit_1; mem_edit_1.DrawWindow("RAM view", m_appController.GetChip32Context()->ram.mem, m_appController.GetChip32Context()->ram.size); - m_PropertiesWindow.SetSelectedNode(m_nodeEditorWindow.GetSelectedNode()); - m_PropertiesWindow.Draw(); + auto selectedNode = nodeEditorFocused ? m_nodeEditorWindow.GetSelectedNode() : m_moduleEditorWindow.GetSelectedNode(); + m_propertiesWindow.SetSelectedNode(selectedNode); + + m_propertiesWindow.Draw(currentStory); // static ImGuiAxis toolbar2_axis = ImGuiAxis_Y; diff --git a/story-editor/src/main_window.h b/story-editor/src/main_window.h index 123b534..7c979ac 100644 --- a/story-editor/src/main_window.h +++ b/story-editor/src/main_window.h @@ -54,7 +54,7 @@ private: ResourcesDock m_resourcesDock; NodeEditorWindow m_nodeEditorWindow; NodeEditorWindow m_moduleEditorWindow; - PropertiesWindow m_PropertiesWindow; + PropertiesWindow m_propertiesWindow; LibraryWindow m_libraryWindow; VariablesWindow m_variablesWindow; diff --git a/story-editor/src/node_editor/base_node_widget.h b/story-editor/src/node_editor/base_node_widget.h index b6326ad..a592d66 100644 --- a/story-editor/src/node_editor/base_node_widget.h +++ b/story-editor/src/node_editor/base_node_widget.h @@ -104,7 +104,7 @@ public: virtual void Initialize(); virtual void Draw() = 0; - virtual void DrawProperties() = 0; + virtual void DrawProperties(std::shared_ptr story) = 0; void SetInputPinName(int pinIndex, const std::string &name); void SetOutPinName(int pinIndex, const std::string &name); diff --git a/story-editor/src/node_editor/call_function_node_widget.cpp b/story-editor/src/node_editor/call_function_node_widget.cpp index d1ad553..4a6c921 100644 --- a/story-editor/src/node_editor/call_function_node_widget.cpp +++ b/story-editor/src/node_editor/call_function_node_widget.cpp @@ -41,7 +41,7 @@ void CallFunctionNodeWidget::Initialize() m_functionName = "Function"; } -void CallFunctionNodeWidget::DrawProperties() +void CallFunctionNodeWidget::DrawProperties(std::shared_ptr story) { diff --git a/story-editor/src/node_editor/call_function_node_widget.h b/story-editor/src/node_editor/call_function_node_widget.h index bcf5c6c..51c66cf 100644 --- a/story-editor/src/node_editor/call_function_node_widget.h +++ b/story-editor/src/node_editor/call_function_node_widget.h @@ -20,7 +20,7 @@ public: void Draw() override; - virtual void DrawProperties() override; + virtual void DrawProperties(std::shared_ptr story) override; virtual void Initialize() override; private: diff --git a/story-editor/src/node_editor/media_node_widget.cpp b/story-editor/src/node_editor/media_node_widget.cpp index 03ec2e1..5ff87c3 100644 --- a/story-editor/src/node_editor/media_node_widget.cpp +++ b/story-editor/src/node_editor/media_node_widget.cpp @@ -108,7 +108,7 @@ void MediaNodeWidget::Initialize() m_soundPath = m_manager.BuildFullAssetsPath(m_mediaNode->GetSound()); } -void MediaNodeWidget::DrawProperties() +void MediaNodeWidget::DrawProperties(std::shared_ptr story) { ImGui::AlignTextToFramePadding(); ImGui::Text("Image"); diff --git a/story-editor/src/node_editor/media_node_widget.h b/story-editor/src/node_editor/media_node_widget.h index e00da7a..85c11b2 100644 --- a/story-editor/src/node_editor/media_node_widget.h +++ b/story-editor/src/node_editor/media_node_widget.h @@ -19,7 +19,7 @@ public: void Draw() override; - virtual void DrawProperties() override; + virtual void DrawProperties(std::shared_ptr story) override; virtual void Initialize() override; private: diff --git a/story-editor/src/node_editor/module_node_widget.cpp b/story-editor/src/node_editor/module_node_widget.cpp index 5fff5ed..bfd7508 100644 --- a/story-editor/src/node_editor/module_node_widget.cpp +++ b/story-editor/src/node_editor/module_node_widget.cpp @@ -37,7 +37,7 @@ void ModuleNodeWidget::Initialize() m_functionName = "Function"; } -void ModuleNodeWidget::DrawProperties() +void ModuleNodeWidget::DrawProperties(std::shared_ptr story) { diff --git a/story-editor/src/node_editor/module_node_widget.h b/story-editor/src/node_editor/module_node_widget.h index b808b5c..9ad20a1 100644 --- a/story-editor/src/node_editor/module_node_widget.h +++ b/story-editor/src/node_editor/module_node_widget.h @@ -19,7 +19,7 @@ public: void Draw() override; - virtual void DrawProperties() override; + virtual void DrawProperties(std::shared_ptr story) override; virtual void Initialize() override; private: diff --git a/story-editor/src/node_editor/node_editor_window.cpp b/story-editor/src/node_editor/node_editor_window.cpp index 8c7303a..e93d03a 100644 --- a/story-editor/src/node_editor/node_editor_window.cpp +++ b/story-editor/src/node_editor/node_editor_window.cpp @@ -65,7 +65,7 @@ void NodeEditorWindow::Clear() void NodeEditorWindow::Initialize() { - Clear(); + Clear(); } void NodeEditorWindow::InitializeProject() @@ -139,7 +139,7 @@ void NodeEditorWindow::Load(std::shared_ptr story) if (n) { n->Initialize(); - n->SetOutputs(m_story->OutputsCount((*it)->GetId())); // il faut que les noeuds aient une bonne taille de outputs avant de créer les liens + // n->SetOutputs(m_story->OutputsCount((*it)->GetId())); // il faut que les noeuds aient une bonne taille de outputs avant de créer les liens m_currentPage->AddNode(n); } else @@ -250,7 +250,6 @@ void NodeEditorWindow::Draw() if (WindowBase::BeginDraw()) { - if (m_currentPage) { m_currentPage->Select(); diff --git a/story-editor/src/node_editor/node_editor_window.h b/story-editor/src/node_editor/node_editor_window.h index bc6bb24..66bc960 100644 --- a/story-editor/src/node_editor/node_editor_window.h +++ b/story-editor/src/node_editor/node_editor_window.h @@ -41,12 +41,12 @@ public: void OpenFunction(const std::string &uuid, const std::string &name); std::shared_ptr GetSelectedNode(); + std::shared_ptr GetCurrentStory() { return m_story; } private: IStoryManager &m_manager; NodesFactory &m_nodesFactory; IStoryProject::Type m_editorType{IStoryProject::Type::PROJECT_TYPE_STORY}; - bool m_loaded{false}; // "MainUuid" is the entry point editor context. You always need to create one. diff --git a/story-editor/src/node_editor/operator_node_widget.cpp b/story-editor/src/node_editor/operator_node_widget.cpp index 4f82935..f9d4109 100644 --- a/story-editor/src/node_editor/operator_node_widget.cpp +++ b/story-editor/src/node_editor/operator_node_widget.cpp @@ -28,7 +28,7 @@ void OperatorNodeWidget::Initialize() -void OperatorNodeWidget::DrawProperties() +void OperatorNodeWidget::DrawProperties(std::shared_ptr story) { ImGui::AlignTextToFramePadding(); static ImGuiComboFlags flags = 0; diff --git a/story-editor/src/node_editor/operator_node_widget.h b/story-editor/src/node_editor/operator_node_widget.h index 6bebe37..a54bd14 100644 --- a/story-editor/src/node_editor/operator_node_widget.h +++ b/story-editor/src/node_editor/operator_node_widget.h @@ -20,7 +20,7 @@ public: void Draw() override; - virtual void DrawProperties() override; + virtual void DrawProperties(std::shared_ptr story) override; virtual void Initialize() override; private: diff --git a/story-editor/src/node_editor/print_node_widget.cpp b/story-editor/src/node_editor/print_node_widget.cpp index d0dbc64..de651aa 100644 --- a/story-editor/src/node_editor/print_node_widget.cpp +++ b/story-editor/src/node_editor/print_node_widget.cpp @@ -27,7 +27,7 @@ void PrintNodeWidget::Initialize() } -void PrintNodeWidget::DrawProperties() +void PrintNodeWidget::DrawProperties(std::shared_ptr story) { ImGui::AlignTextToFramePadding(); @@ -38,7 +38,7 @@ void PrintNodeWidget::DrawProperties() bool edited = ImGui::InputText("##edit", m_buffer, sizeof(m_buffer), ImGuiInputTextFlags_EnterReturnsTrue); - if (edited) + // if (edited) { m_printNode->SetText(m_buffer); } diff --git a/story-editor/src/node_editor/print_node_widget.h b/story-editor/src/node_editor/print_node_widget.h index b98923b..fe35e18 100644 --- a/story-editor/src/node_editor/print_node_widget.h +++ b/story-editor/src/node_editor/print_node_widget.h @@ -22,7 +22,7 @@ public: void Draw() override; - virtual void DrawProperties() override; + virtual void DrawProperties(std::shared_ptr story) override; virtual void Initialize() override; private: diff --git a/story-editor/src/node_editor/syscall_node_widget.cpp b/story-editor/src/node_editor/syscall_node_widget.cpp index e75aeb9..cfc3da3 100644 --- a/story-editor/src/node_editor/syscall_node_widget.cpp +++ b/story-editor/src/node_editor/syscall_node_widget.cpp @@ -27,7 +27,7 @@ void SyscallNodeWidget::Initialize() BaseNodeWidget::Initialize(); } -void SyscallNodeWidget::DrawProperties() +void SyscallNodeWidget::DrawProperties(std::shared_ptr story) { ImGui::AlignTextToFramePadding(); static ImGuiComboFlags flags = 0; diff --git a/story-editor/src/node_editor/syscall_node_widget.h b/story-editor/src/node_editor/syscall_node_widget.h index 29ac1d8..730d0fd 100644 --- a/story-editor/src/node_editor/syscall_node_widget.h +++ b/story-editor/src/node_editor/syscall_node_widget.h @@ -20,7 +20,7 @@ public: void Draw() override; - virtual void DrawProperties() override; + virtual void DrawProperties(std::shared_ptr story) override; virtual void Initialize() override; private: diff --git a/story-editor/src/node_editor/variable_node_widget.cpp b/story-editor/src/node_editor/variable_node_widget.cpp index adcc4f7..e7a92d3 100644 --- a/story-editor/src/node_editor/variable_node_widget.cpp +++ b/story-editor/src/node_editor/variable_node_widget.cpp @@ -23,25 +23,31 @@ void VariableNodeWidget::Initialize() BaseNodeWidget::Initialize(); m_selectedVariableUuid = m_variableNode->GetVariableUuid(); - - m_manager.ScanVariable([this] (std::shared_ptr var) { - if (var->GetUuid() == m_selectedVariableUuid) - { - m_selectedVariableName = var->GetVariableName(); - } - }); } -void VariableNodeWidget::DrawProperties() +void VariableNodeWidget::DrawProperties(std::shared_ptr story) { + if (!m_isInitialized) + { + m_isInitialized = true; + story->ScanVariable([this] (std::shared_ptr var) { + if (var->GetUuid() == m_selectedVariableUuid) + { + m_selectedVariableName = var->GetVariableName(); + } + }); + } + ImGui::AlignTextToFramePadding(); static ImGuiComboFlags flags = 0; + ImGui::SetNextItemOpen(true, ImGuiCond_Once); + if (ImGui::BeginCombo("Variables list", m_selectedVariableName.c_str(), flags)) { int i = 0; - m_manager.ScanVariable([&i, this] (std::shared_ptr var) { + story->ScanVariable([&i, this] (std::shared_ptr var) { // ImGui::PushID(static_cast(i)); // Assure l'unicité des widgets diff --git a/story-editor/src/node_editor/variable_node_widget.h b/story-editor/src/node_editor/variable_node_widget.h index 1a185d7..9562119 100644 --- a/story-editor/src/node_editor/variable_node_widget.h +++ b/story-editor/src/node_editor/variable_node_widget.h @@ -20,11 +20,12 @@ public: void Draw() override; - virtual void DrawProperties() override; + virtual void DrawProperties(std::shared_ptr story) override; virtual void Initialize() override; private: IStoryManager &m_manager; + bool m_isInitialized{false}; std::shared_ptr m_variableNode; int m_selectedIndex{-1}; std::string m_selectedVariableUuid; diff --git a/story-editor/src/windows/properties_window.cpp b/story-editor/src/windows/properties_window.cpp index b6a4efd..eac1f64 100644 --- a/story-editor/src/windows/properties_window.cpp +++ b/story-editor/src/windows/properties_window.cpp @@ -13,7 +13,11 @@ void PropertiesWindow::Initialize() { } -void PropertiesWindow::Draw() +void PropertiesWindow::Draw() { + +} + +void PropertiesWindow::Draw(std::shared_ptr story) { WindowBase::BeginDraw(); ImGui::SetWindowSize(ImVec2(626, 744), ImGuiCond_FirstUseEver); @@ -36,7 +40,7 @@ void PropertiesWindow::Draw() ImGui::InputText("Title", buf1, 32); m_selectedNode->Base()->SetTitle(buf1); ImGui::Text("Node ID: %s", m_selectedNode->Base()->GetId().data()); - m_selectedNode->DrawProperties(); + m_selectedNode->DrawProperties(story); } WindowBase::EndDraw(); diff --git a/story-editor/src/windows/properties_window.h b/story-editor/src/windows/properties_window.h index ff9cc9d..efb8919 100644 --- a/story-editor/src/windows/properties_window.h +++ b/story-editor/src/windows/properties_window.h @@ -11,7 +11,8 @@ public: PropertiesWindow(); void Initialize(); - virtual void Draw() override; + void Draw() override; + void Draw(std::shared_ptr story); void SetSelectedNode(std::shared_ptr node); diff --git a/story-editor/src/windows/variables_window.cpp b/story-editor/src/windows/variables_window.cpp index eb0bc0b..7cb22b0 100644 --- a/story-editor/src/windows/variables_window.cpp +++ b/story-editor/src/windows/variables_window.cpp @@ -5,9 +5,8 @@ #include "chip32_vm.h" #include "variable.h" -VariablesWindow::VariablesWindow(IStoryManager &proj) +VariablesWindow::VariablesWindow() : WindowBase("Variables") - , m_story(proj) { } @@ -29,18 +28,18 @@ int64_t FloatToScaled(float floatValue, int scalePower) { } -void VariablesWindow::ShowRAMEditor() +void VariablesWindow::ShowRAMEditor(std::shared_ptr story) { - if (ImGui::Button("Add Variable")) { + if (ImGui::Button("Add variable")) { // Ajouter une nouvelle variable par défaut - m_story.AddVariable(); + story->AddVariable(); } ImGui::Separator(); int i = 0; - m_story.ScanVariable([&i, this] (std::shared_ptr var) { + story->ScanVariable([&i, story] (std::shared_ptr var) { ImGui::PushID(static_cast(i)); // Assure l'unicité des widgets std::string l = var->GetVariableName(); @@ -91,7 +90,7 @@ void VariablesWindow::ShowRAMEditor() // Bouton pour supprimer la variable if (ImGui::Button("Delete")) { - m_story.DeleteVariable(i); + story->DeleteVariable(i); ImGui::TreePop(); ImGui::PopID(); @@ -106,11 +105,17 @@ void VariablesWindow::ShowRAMEditor() } void VariablesWindow::Draw() +{ +} + +void VariablesWindow::Draw(std::shared_ptr story) { WindowBase::BeginDraw(); - - ShowRAMEditor(); + if (story) + { + ShowRAMEditor(story); + } WindowBase::EndDraw(); } diff --git a/story-editor/src/windows/variables_window.h b/story-editor/src/windows/variables_window.h index 347503d..89d3150 100644 --- a/story-editor/src/windows/variables_window.h +++ b/story-editor/src/windows/variables_window.h @@ -1,22 +1,19 @@ #pragma once #include "window_base.h" -#include "i_story_manager.h" +#include "i_story_project.h" #include "gui.h" class VariablesWindow : public WindowBase { public: - VariablesWindow(IStoryManager &proj); + VariablesWindow(); void Initialize(); - virtual void Draw() override; + void Draw() override; + void Draw(std::shared_ptr story); private: - IStoryManager &m_story; - - - void ShowRAMEditor(); - + void ShowRAMEditor(std::shared_ptr story); }; diff --git a/story-editor/src/windows/window_base.cpp b/story-editor/src/windows/window_base.cpp index 3872886..dcd4fcc 100644 --- a/story-editor/src/windows/window_base.cpp +++ b/story-editor/src/windows/window_base.cpp @@ -11,6 +11,8 @@ bool WindowBase::BeginDraw() { bool ok = ImGui::Begin(m_title.c_str(), nullptr, m_windowFlags); + m_focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows); + if (m_disabled) { ImGui::BeginDisabled(); diff --git a/story-editor/src/windows/window_base.h b/story-editor/src/windows/window_base.h index f8d5cc7..9c20f9f 100644 --- a/story-editor/src/windows/window_base.h +++ b/story-editor/src/windows/window_base.h @@ -23,6 +23,10 @@ public: m_disabled = true; } + bool IsFocused() const { + return m_focused; + } + void Enable() { m_disabled = false; } @@ -34,6 +38,7 @@ public: private: bool m_disabled{false}; + bool m_focused{false}; std::string m_title; ImGuiWindowFlags m_windowFlags = 0; };