Working variable edior for modules
Some checks failed
Build-StoryEditor / build_linux (push) Has been cancelled
Build-StoryEditor / build_win32 (push) Has been cancelled
Deploy-Documentation / deploy (push) Has been cancelled

This commit is contained in:
Anthony Rabine 2025-08-26 22:49:37 +02:00
parent 6ec0740345
commit 6459dba5c3
35 changed files with 200 additions and 150 deletions

View file

@ -53,11 +53,6 @@ public:
virtual void ToggleBreakpoint(int line) = 0; virtual void ToggleBreakpoint(int line) = 0;
virtual uint32_t GetRegister(int reg) = 0; virtual uint32_t GetRegister(int reg) = 0;
// Variables management
virtual void ScanVariable(const std::function<void(std::shared_ptr<Variable> element)>& operation) = 0;
virtual void AddVariable() = 0;
virtual void DeleteVariable(int i) = 0;
virtual void Play() = 0; virtual void Play() = 0;
virtual void Step() = 0; virtual void Step() = 0;
virtual void Run() = 0; virtual void Run() = 0;

View file

@ -4,6 +4,7 @@
#include <string> #include <string>
#include "connection.h" #include "connection.h"
#include "story_options.h" #include "story_options.h"
#include "variable.h"
class IStoryProject class IStoryProject
{ {
@ -36,6 +37,9 @@ public:
virtual void SetName(const std::string &name) = 0; virtual void SetName(const std::string &name) = 0;
virtual void SetUuid(const std::string &uuid) = 0; virtual void SetUuid(const std::string &uuid) = 0;
virtual void ScanVariable(const std::function<void(std::shared_ptr<Variable> element)>& operation) = 0;
virtual void AddVariable() = 0;
virtual void DeleteVariable(int i) = 0;
}; };

View file

@ -5,7 +5,7 @@
CompareNode::CompareNode(const std::string &type) CompareNode::CompareNode(const std::string &type)
: BaseNode(type, "Branch Node") : BaseNode(type, "Compare Node")
{ {
} }

View file

@ -76,6 +76,16 @@ public:
m_uuid = uuid; m_uuid = uuid;
} }
virtual void ScanVariable(const std::function<void(std::shared_ptr<Variable> element)>& operation) override {
}
virtual void AddVariable() override {
}
virtual void DeleteVariable(int i) override {
}
private: private:
std::string m_name; std::string m_name;
std::string m_description; std::string m_description;

View file

@ -112,9 +112,9 @@ public:
std::pair<std::list<std::shared_ptr<Connection>>::iterator, std::list<std::shared_ptr<Connection>>::iterator> Links(const std::string_view &page_uuid); std::pair<std::list<std::shared_ptr<Connection>>::iterator, std::list<std::shared_ptr<Connection>>::iterator> Links(const std::string_view &page_uuid);
void ScanVariable(const std::function<void(std::shared_ptr<Variable> element)>& operation); void ScanVariable(const std::function<void(std::shared_ptr<Variable> element)>& operation) override;
void AddVariable(); void AddVariable() override;
void DeleteVariable(int i); void DeleteVariable(int i) override;
private: private:
ILogger &m_log; ILogger &m_log;

View file

@ -9,32 +9,32 @@ Size=400,400
Collapsed=0 Collapsed=0
[Window][Library Manager] [Window][Library Manager]
Pos=878,26 Pos=591,26
Size=402,694 Size=689,224
Collapsed=0 Collapsed=0
DockId=0x00000003,0 DockId=0x00000003,0
[Window][Console] [Window][Console]
Pos=60,735 Pos=60,533
Size=610,253 Size=610,187
Collapsed=0 Collapsed=0
DockId=0x00000004,0 DockId=0x00000004,0
[Window][Emulator] [Window][Emulator]
Pos=878,26 Pos=591,26
Size=402,403 Size=689,224
Collapsed=0 Collapsed=0
DockId=0x00000003,5 DockId=0x00000003,5
[Window][Code viewer] [Window][Code viewer]
Pos=878,26 Pos=591,26
Size=402,403 Size=689,224
Collapsed=0 Collapsed=0
DockId=0x00000003,4 DockId=0x00000003,4
[Window][Resources] [Window][Resources]
Pos=878,26 Pos=591,26
Size=402,403 Size=689,224
Collapsed=0 Collapsed=0
DockId=0x00000003,1 DockId=0x00000003,1
@ -50,32 +50,32 @@ Size=150,42
Collapsed=0 Collapsed=0
[Window][Variables] [Window][Variables]
Pos=672,735 Pos=672,533
Size=608,253 Size=608,187
Collapsed=0 Collapsed=0
DockId=0x00000005,0 DockId=0x00000005,0
[Window][CPU] [Window][CPU]
Pos=878,26 Pos=591,26
Size=402,403 Size=689,224
Collapsed=0 Collapsed=0
DockId=0x00000003,2 DockId=0x00000003,2
[Window][RAM view] [Window][RAM view]
Pos=878,26 Pos=591,26
Size=402,403 Size=689,224
Collapsed=0 Collapsed=0
DockId=0x00000003,3 DockId=0x00000003,3
[Window][Properties] [Window][Properties]
Pos=878,431 Pos=591,252
Size=402,302 Size=689,279
Collapsed=0 Collapsed=0
DockId=0x00000006,0 DockId=0x00000006,0
[Window][ToolBar] [Window][ToolBar]
Pos=0,26 Pos=0,26
Size=60,962 Size=60,694
Collapsed=0 Collapsed=0
[Window][QuitConfirm] [Window][QuitConfirm]
@ -90,16 +90,21 @@ Collapsed=0
[Window][Module editor] [Window][Module editor]
Pos=60,26 Pos=60,26
Size=816,707 Size=529,505
Collapsed=0 Collapsed=0
DockId=0x00000001,1 DockId=0x00000001,1
[Window][Story editor] [Window][Story editor]
Pos=60,26 Pos=60,26
Size=816,707 Size=529,505
Collapsed=0 Collapsed=0
DockId=0x00000001,0 DockId=0x00000001,0
[Window][Choose a library directory##ChooseLibraryDirDialog]
Pos=490,260
Size=687,422
Collapsed=0
[Table][0x7728942D,5] [Table][0x7728942D,5]
RefScale=20 RefScale=20
Column 0 Width=44 Sort=0v Column 0 Width=44 Sort=0v
@ -132,14 +137,18 @@ Column 0 Width=120 Sort=0v
Column 1 Width=104 Column 1 Width=104
Column 2 Width=120 Column 2 Width=120
[Table][0x874E6ACA,4]
RefScale=20
Column 0 Sort=0v
[Docking][Data] [Docking][Data]
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=60,26 Size=1220,694 Split=Y 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=0x00000007 Parent=0x08BD597D SizeRef=1220,505 Split=X
DockNode ID=0x00000001 Parent=0x00000007 SizeRef=816,694 CentralNode=1 Selected=0x93ADCAAB DockNode ID=0x00000001 Parent=0x00000007 SizeRef=721,694 CentralNode=1 Selected=0x93ADCAAB
DockNode ID=0x00000002 Parent=0x00000007 SizeRef=402,694 Split=Y Selected=0x52EB28B5 DockNode ID=0x00000002 Parent=0x00000007 SizeRef=689,694 Split=Y Selected=0x52EB28B5
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=718,250 Selected=0x63869CAF DockNode ID=0x00000003 Parent=0x00000002 SizeRef=718,224 Selected=0x63869CAF
DockNode ID=0x00000006 Parent=0x00000002 SizeRef=718,187 Selected=0x8C72BEA8 DockNode ID=0x00000006 Parent=0x00000002 SizeRef=718,279 Selected=0x8C72BEA8
DockNode ID=0x00000008 Parent=0x08BD597D SizeRef=1220,253 Split=X Selected=0xEA83D666 DockNode ID=0x00000008 Parent=0x08BD597D SizeRef=1220,187 Split=X Selected=0xEA83D666
DockNode ID=0x00000004 Parent=0x00000008 SizeRef=610,192 Selected=0xEA83D666 DockNode ID=0x00000004 Parent=0x00000008 SizeRef=610,192 Selected=0xEA83D666
DockNode ID=0x00000005 Parent=0x00000008 SizeRef=608,192 Selected=0x6DE9B20C DockNode ID=0x00000005 Parent=0x00000008 SizeRef=608,192 Selected=0x6DE9B20C

View file

@ -404,36 +404,6 @@ uint32_t AppController::GetRegister(int reg)
return regVal; return regVal;
} }
void AppController::ScanVariable(const std::function<void(std::shared_ptr<Variable> 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() void AppController::Play()
{ {
@ -903,14 +873,17 @@ std::shared_ptr<IStoryProject> AppController::OpenModule(const std::string &uuid
m_module = m_nodesFactory.GetModule(uuid); m_module = m_nodesFactory.GetModule(uuid);
if (!m_module) if (!m_module)
{ {
m_eventBus.Emit(std::make_shared<GenericResultEvent>(false, "Cannot find module: " + uuid));
m_logger.Log("Cannot find module: " + uuid, true); m_logger.Log("Cannot find module: " + uuid, true);
} }
else if (m_module->Load(m_resources, m_nodesFactory)) else if (m_module->Load(m_resources, m_nodesFactory))
{ {
m_eventBus.Emit(std::make_shared<ModuleEvent>(ModuleEvent::Type::Opened, uuid));
m_logger.Log("Open module success: " + uuid); m_logger.Log("Open module success: " + uuid);
} }
else else
{ {
m_eventBus.Emit(std::make_shared<GenericResultEvent>(false, "Failed to open module: " + uuid));
m_logger.Log("Open module error: " + uuid, true); m_logger.Log("Open module error: " + uuid, true);
} }
return m_module; return m_module;

View file

@ -66,7 +66,7 @@ public:
void SaveStory(const std::string &path = ""); void SaveStory(const std::string &path = "");
void ExportStory(const std::string &filename); void ExportStory(const std::string &filename);
std::shared_ptr<StoryProject> GetCurrentStory() const { return m_story; } std::shared_ptr<StoryProject> GetCurrentStory() const { return m_story; }
std::shared_ptr<StoryProject> GetModuleStory() const { return m_module; } std::shared_ptr<StoryProject> GetCurrentModule() const { return m_module; }
void BuildNodes(IStoryProject::Type type); void BuildNodes(IStoryProject::Type type);
void Build(bool compileonly); void Build(bool compileonly);
void BuildCode(std::shared_ptr<StoryProject> story, bool compileonly, bool force = false); void BuildCode(std::shared_ptr<StoryProject> story, bool compileonly, bool force = false);
@ -76,9 +76,6 @@ public:
virtual void LoadBinaryStory(const std::string &filename) override; virtual void LoadBinaryStory(const std::string &filename) override;
virtual void ToggleBreakpoint(int line) override; virtual void ToggleBreakpoint(int line) override;
virtual uint32_t GetRegister(int reg) override; virtual uint32_t GetRegister(int reg) override;
virtual void ScanVariable(const std::function<void(std::shared_ptr<Variable> element)>& operation) override;
virtual void AddVariable() override;
virtual void DeleteVariable(int i) override;
virtual void Play() override; virtual void Play() override;
virtual void Step() override; virtual void Step() override;
virtual void Run() override; virtual void Run() override;

View file

@ -55,4 +55,24 @@ private:
std::string m_message; 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 #endif // ALL_EVENTS_H

View file

@ -16,6 +16,7 @@ int main(int, char**)
bool done = false; bool done = false;
appController.Initialize();
if (w->Initialize()) if (w->Initialize())
{ {
while (!done) while (!done)

View file

@ -36,7 +36,6 @@ MainWindow::MainWindow(ILogger& logger, EventBus& eventBus, AppController& appCo
, m_nodeEditorWindow(appController, appController.GetNodesFactory(), IStoryProject::PROJECT_TYPE_STORY) , m_nodeEditorWindow(appController, appController.GetNodesFactory(), IStoryProject::PROJECT_TYPE_STORY)
, m_moduleEditorWindow(appController, appController.GetNodesFactory(), IStoryProject::PROJECT_TYPE_MODULE) , m_moduleEditorWindow(appController, appController.GetNodesFactory(), IStoryProject::PROJECT_TYPE_MODULE)
, m_libraryWindow(appController, appController.GetLibraryManager(), appController.GetNodesFactory()) , m_libraryWindow(appController, appController.GetLibraryManager(), appController.GetNodesFactory())
, m_variablesWindow(appController)
, m_projectPropertiesDialog(appController, appController.GetResourceManager()) , m_projectPropertiesDialog(appController, appController.GetResourceManager())
{ {
CloseProject(); CloseProject();
@ -58,8 +57,6 @@ MainWindow::MainWindow(ILogger& logger, EventBus& eventBus, AppController& appCo
m_eventBus.Subscribe<GenericResultEvent>([this](const GenericResultEvent &event) { m_eventBus.Subscribe<GenericResultEvent>([this](const GenericResultEvent &event) {
// FIXME: ImGui notification widget
if (event.IsSuccess()) { if (event.IsSuccess()) {
m_logger.Log("Operation successful: " + event.GetMessage()); m_logger.Log("Operation successful: " + event.GetMessage());
m_toastNotifier.addToast("Success", event.GetMessage(), ToastType::Success); 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_toastNotifier.addToast("Error", event.GetMessage(), ToastType::Error);
} }
}); });
m_eventBus.Subscribe<ModuleEvent>([this](const ModuleEvent &event) {
if (event.GetType() == ModuleEvent::Type::Opened) {
OpenModule(event.GetUuid());
} else if (event.GetType() == ModuleEvent::Type::Closed) {
CloseModule();
}
});
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
m_gui.Destroy(); 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")) if (ImGui::BeginMenu("Open Recent"))
{ {
@ -137,7 +128,6 @@ float MainWindow::DrawMainMenuBar()
if (!init) if (!init)
ImGui::BeginDisabled(); ImGui::BeginDisabled();
ImGui::Separator();
if (ImGui::MenuItem("Save project")) if (ImGui::MenuItem("Save project"))
{ {
m_appController.SaveProject(); m_appController.SaveProject();
@ -153,13 +143,30 @@ float MainWindow::DrawMainMenuBar()
m_projectPropertiesDialog.Show(); 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")) if (ImGui::MenuItem("Close module"))
{ {
CloseModule(); CloseModule();
} }
if (!init)
ImGui::EndDisabled();
ImGui::EndMenu(); ImGui::EndMenu();
} }
@ -201,7 +208,7 @@ bool MainWindow::Initialize()
m_emulatorDock.Initialize(); m_emulatorDock.Initialize();
m_nodeEditorWindow.Initialize(); m_nodeEditorWindow.Initialize();
m_moduleEditorWindow.Initialize(); m_moduleEditorWindow.Initialize();
m_PropertiesWindow.Initialize(); m_propertiesWindow.Initialize();
m_libraryWindow.Initialize(); m_libraryWindow.Initialize();
success = true; success = true;
@ -266,7 +273,7 @@ void MainWindow::OpenProject(const std::string &uuid)
m_consoleWindow.Enable(); m_consoleWindow.Enable();
m_debuggerWindow.Enable(); m_debuggerWindow.Enable();
m_resourcesDock.Enable(); m_resourcesDock.Enable();
m_PropertiesWindow.Enable(); m_propertiesWindow.Enable();
m_variablesWindow.Enable(); m_variablesWindow.Enable();
m_cpuWindow.Enable(); m_cpuWindow.Enable();
@ -293,16 +300,24 @@ void MainWindow::SaveModule()
{ {
m_appController.SaveModule(); m_appController.SaveModule();
m_logger.Log("Modules saved"); m_logger.Log("Modules saved");
m_toastNotifier.addToast("Module", "Module saved", ToastType::Success);
} }
void MainWindow::OpenModule(const std::string &uuid) void MainWindow::OpenModule(const std::string &uuid)
{ {
auto module = m_appController.OpenModule(uuid); auto module = m_appController.GetCurrentModule();
if (module) if (module)
{ {
std::shared_ptr<StoryProject> modulePtr = std::dynamic_pointer_cast<StoryProject>(module); m_moduleEditorWindow.Load(module);
m_moduleEditorWindow.Load(modulePtr);
m_moduleEditorWindow.Enable(); 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_emulatorDock.Disable();
m_debuggerWindow.Disable(); m_debuggerWindow.Disable();
m_resourcesDock.Disable(); m_resourcesDock.Disable();
m_PropertiesWindow.Disable(); m_propertiesWindow.Disable();
m_variablesWindow.Disable(); m_variablesWindow.Disable();
m_cpuWindow.Disable(); m_cpuWindow.Disable();
@ -421,20 +436,26 @@ bool MainWindow::Loop()
if (m_appController.IsLibraryManagerInitialized()) if (m_appController.IsLibraryManagerInitialized())
{ {
bool nodeEditorFocused = m_nodeEditorWindow.IsFocused();
m_consoleWindow.Draw(); m_consoleWindow.Draw();
m_emulatorDock.Draw(); m_emulatorDock.Draw();
m_debuggerWindow.Draw(); m_debuggerWindow.Draw();
m_resourcesDock.Draw(); m_resourcesDock.Draw();
m_nodeEditorWindow.Draw(); m_nodeEditorWindow.Draw();
m_moduleEditorWindow.Draw(); m_moduleEditorWindow.Draw();
m_variablesWindow.Draw();
auto currentStory = nodeEditorFocused ? m_nodeEditorWindow.GetCurrentStory() : m_moduleEditorWindow.GetCurrentStory();
m_variablesWindow.Draw(currentStory);
m_cpuWindow.Draw(); m_cpuWindow.Draw();
static MemoryEditor mem_edit_1; static MemoryEditor mem_edit_1;
mem_edit_1.DrawWindow("RAM view", m_appController.GetChip32Context()->ram.mem, m_appController.GetChip32Context()->ram.size); mem_edit_1.DrawWindow("RAM view", m_appController.GetChip32Context()->ram.mem, m_appController.GetChip32Context()->ram.size);
m_PropertiesWindow.SetSelectedNode(m_nodeEditorWindow.GetSelectedNode()); auto selectedNode = nodeEditorFocused ? m_nodeEditorWindow.GetSelectedNode() : m_moduleEditorWindow.GetSelectedNode();
m_PropertiesWindow.Draw(); m_propertiesWindow.SetSelectedNode(selectedNode);
m_propertiesWindow.Draw(currentStory);
// static ImGuiAxis toolbar2_axis = ImGuiAxis_Y; // static ImGuiAxis toolbar2_axis = ImGuiAxis_Y;

View file

@ -54,7 +54,7 @@ private:
ResourcesDock m_resourcesDock; ResourcesDock m_resourcesDock;
NodeEditorWindow m_nodeEditorWindow; NodeEditorWindow m_nodeEditorWindow;
NodeEditorWindow m_moduleEditorWindow; NodeEditorWindow m_moduleEditorWindow;
PropertiesWindow m_PropertiesWindow; PropertiesWindow m_propertiesWindow;
LibraryWindow m_libraryWindow; LibraryWindow m_libraryWindow;
VariablesWindow m_variablesWindow; VariablesWindow m_variablesWindow;

View file

@ -104,7 +104,7 @@ public:
virtual void Initialize(); virtual void Initialize();
virtual void Draw() = 0; virtual void Draw() = 0;
virtual void DrawProperties() = 0; virtual void DrawProperties(std::shared_ptr<IStoryProject> story) = 0;
void SetInputPinName(int pinIndex, const std::string &name); void SetInputPinName(int pinIndex, const std::string &name);
void SetOutPinName(int pinIndex, const std::string &name); void SetOutPinName(int pinIndex, const std::string &name);

View file

@ -41,7 +41,7 @@ void CallFunctionNodeWidget::Initialize()
m_functionName = "Function"; m_functionName = "Function";
} }
void CallFunctionNodeWidget::DrawProperties() void CallFunctionNodeWidget::DrawProperties(std::shared_ptr<IStoryProject> story)
{ {

View file

@ -20,7 +20,7 @@ public:
void Draw() override; void Draw() override;
virtual void DrawProperties() override; virtual void DrawProperties(std::shared_ptr<IStoryProject> story) override;
virtual void Initialize() override; virtual void Initialize() override;
private: private:

View file

@ -108,7 +108,7 @@ void MediaNodeWidget::Initialize()
m_soundPath = m_manager.BuildFullAssetsPath(m_mediaNode->GetSound()); m_soundPath = m_manager.BuildFullAssetsPath(m_mediaNode->GetSound());
} }
void MediaNodeWidget::DrawProperties() void MediaNodeWidget::DrawProperties(std::shared_ptr<IStoryProject> story)
{ {
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
ImGui::Text("Image"); ImGui::Text("Image");

View file

@ -19,7 +19,7 @@ public:
void Draw() override; void Draw() override;
virtual void DrawProperties() override; virtual void DrawProperties(std::shared_ptr<IStoryProject> story) override;
virtual void Initialize() override; virtual void Initialize() override;
private: private:

View file

@ -37,7 +37,7 @@ void ModuleNodeWidget::Initialize()
m_functionName = "Function"; m_functionName = "Function";
} }
void ModuleNodeWidget::DrawProperties() void ModuleNodeWidget::DrawProperties(std::shared_ptr<IStoryProject> story)
{ {

View file

@ -19,7 +19,7 @@ public:
void Draw() override; void Draw() override;
virtual void DrawProperties() override; virtual void DrawProperties(std::shared_ptr<IStoryProject> story) override;
virtual void Initialize() override; virtual void Initialize() override;
private: private:

View file

@ -139,7 +139,7 @@ void NodeEditorWindow::Load(std::shared_ptr<StoryProject> story)
if (n) if (n)
{ {
n->Initialize(); 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); m_currentPage->AddNode(n);
} }
else else
@ -250,7 +250,6 @@ void NodeEditorWindow::Draw()
if (WindowBase::BeginDraw()) if (WindowBase::BeginDraw())
{ {
if (m_currentPage) if (m_currentPage)
{ {
m_currentPage->Select(); m_currentPage->Select();

View file

@ -41,12 +41,12 @@ public:
void OpenFunction(const std::string &uuid, const std::string &name); void OpenFunction(const std::string &uuid, const std::string &name);
std::shared_ptr<BaseNodeWidget> GetSelectedNode(); std::shared_ptr<BaseNodeWidget> GetSelectedNode();
std::shared_ptr<StoryProject> GetCurrentStory() { return m_story; }
private: private:
IStoryManager &m_manager; IStoryManager &m_manager;
NodesFactory &m_nodesFactory; NodesFactory &m_nodesFactory;
IStoryProject::Type m_editorType{IStoryProject::Type::PROJECT_TYPE_STORY}; IStoryProject::Type m_editorType{IStoryProject::Type::PROJECT_TYPE_STORY};
bool m_loaded{false}; bool m_loaded{false};
// "MainUuid" is the entry point editor context. You always need to create one. // "MainUuid" is the entry point editor context. You always need to create one.

View file

@ -28,7 +28,7 @@ void OperatorNodeWidget::Initialize()
void OperatorNodeWidget::DrawProperties() void OperatorNodeWidget::DrawProperties(std::shared_ptr<IStoryProject> story)
{ {
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
static ImGuiComboFlags flags = 0; static ImGuiComboFlags flags = 0;

View file

@ -20,7 +20,7 @@ public:
void Draw() override; void Draw() override;
virtual void DrawProperties() override; virtual void DrawProperties(std::shared_ptr<IStoryProject> story) override;
virtual void Initialize() override; virtual void Initialize() override;
private: private:

View file

@ -27,7 +27,7 @@ void PrintNodeWidget::Initialize()
} }
void PrintNodeWidget::DrawProperties() void PrintNodeWidget::DrawProperties(std::shared_ptr<IStoryProject> story)
{ {
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
@ -38,7 +38,7 @@ void PrintNodeWidget::DrawProperties()
bool edited = ImGui::InputText("##edit", m_buffer, sizeof(m_buffer), ImGuiInputTextFlags_EnterReturnsTrue); bool edited = ImGui::InputText("##edit", m_buffer, sizeof(m_buffer), ImGuiInputTextFlags_EnterReturnsTrue);
if (edited) // if (edited)
{ {
m_printNode->SetText(m_buffer); m_printNode->SetText(m_buffer);
} }

View file

@ -22,7 +22,7 @@ public:
void Draw() override; void Draw() override;
virtual void DrawProperties() override; virtual void DrawProperties(std::shared_ptr<IStoryProject> story) override;
virtual void Initialize() override; virtual void Initialize() override;
private: private:

View file

@ -27,7 +27,7 @@ void SyscallNodeWidget::Initialize()
BaseNodeWidget::Initialize(); BaseNodeWidget::Initialize();
} }
void SyscallNodeWidget::DrawProperties() void SyscallNodeWidget::DrawProperties(std::shared_ptr<IStoryProject> story)
{ {
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
static ImGuiComboFlags flags = 0; static ImGuiComboFlags flags = 0;

View file

@ -20,7 +20,7 @@ public:
void Draw() override; void Draw() override;
virtual void DrawProperties() override; virtual void DrawProperties(std::shared_ptr<IStoryProject> story) override;
virtual void Initialize() override; virtual void Initialize() override;
private: private:

View file

@ -23,25 +23,31 @@ void VariableNodeWidget::Initialize()
BaseNodeWidget::Initialize(); BaseNodeWidget::Initialize();
m_selectedVariableUuid = m_variableNode->GetVariableUuid(); m_selectedVariableUuid = m_variableNode->GetVariableUuid();
m_manager.ScanVariable([this] (std::shared_ptr<Variable> var) {
if (var->GetUuid() == m_selectedVariableUuid)
{
m_selectedVariableName = var->GetVariableName();
}
});
} }
void VariableNodeWidget::DrawProperties() void VariableNodeWidget::DrawProperties(std::shared_ptr<IStoryProject> story)
{ {
if (!m_isInitialized)
{
m_isInitialized = true;
story->ScanVariable([this] (std::shared_ptr<Variable> var) {
if (var->GetUuid() == m_selectedVariableUuid)
{
m_selectedVariableName = var->GetVariableName();
}
});
}
ImGui::AlignTextToFramePadding(); ImGui::AlignTextToFramePadding();
static ImGuiComboFlags flags = 0; static ImGuiComboFlags flags = 0;
ImGui::SetNextItemOpen(true, ImGuiCond_Once);
if (ImGui::BeginCombo("Variables list", m_selectedVariableName.c_str(), flags)) if (ImGui::BeginCombo("Variables list", m_selectedVariableName.c_str(), flags))
{ {
int i = 0; int i = 0;
m_manager.ScanVariable([&i, this] (std::shared_ptr<Variable> var) { story->ScanVariable([&i, this] (std::shared_ptr<Variable> var) {
// ImGui::PushID(static_cast<int>(i)); // Assure l'unicité des widgets // ImGui::PushID(static_cast<int>(i)); // Assure l'unicité des widgets

View file

@ -20,11 +20,12 @@ public:
void Draw() override; void Draw() override;
virtual void DrawProperties() override; virtual void DrawProperties(std::shared_ptr<IStoryProject> story) override;
virtual void Initialize() override; virtual void Initialize() override;
private: private:
IStoryManager &m_manager; IStoryManager &m_manager;
bool m_isInitialized{false};
std::shared_ptr<VariableNode> m_variableNode; std::shared_ptr<VariableNode> m_variableNode;
int m_selectedIndex{-1}; int m_selectedIndex{-1};
std::string m_selectedVariableUuid; std::string m_selectedVariableUuid;

View file

@ -13,7 +13,11 @@ void PropertiesWindow::Initialize() {
} }
void PropertiesWindow::Draw() void PropertiesWindow::Draw() {
}
void PropertiesWindow::Draw(std::shared_ptr<IStoryProject> story)
{ {
WindowBase::BeginDraw(); WindowBase::BeginDraw();
ImGui::SetWindowSize(ImVec2(626, 744), ImGuiCond_FirstUseEver); ImGui::SetWindowSize(ImVec2(626, 744), ImGuiCond_FirstUseEver);
@ -36,7 +40,7 @@ void PropertiesWindow::Draw()
ImGui::InputText("Title", buf1, 32); ImGui::InputText("Title", buf1, 32);
m_selectedNode->Base()->SetTitle(buf1); m_selectedNode->Base()->SetTitle(buf1);
ImGui::Text("Node ID: %s", m_selectedNode->Base()->GetId().data()); ImGui::Text("Node ID: %s", m_selectedNode->Base()->GetId().data());
m_selectedNode->DrawProperties(); m_selectedNode->DrawProperties(story);
} }
WindowBase::EndDraw(); WindowBase::EndDraw();

View file

@ -11,7 +11,8 @@ public:
PropertiesWindow(); PropertiesWindow();
void Initialize(); void Initialize();
virtual void Draw() override; void Draw() override;
void Draw(std::shared_ptr<IStoryProject> story);
void SetSelectedNode(std::shared_ptr<BaseNodeWidget> node); void SetSelectedNode(std::shared_ptr<BaseNodeWidget> node);

View file

@ -5,9 +5,8 @@
#include "chip32_vm.h" #include "chip32_vm.h"
#include "variable.h" #include "variable.h"
VariablesWindow::VariablesWindow(IStoryManager &proj) VariablesWindow::VariablesWindow()
: WindowBase("Variables") : 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<IStoryProject> story)
{ {
if (ImGui::Button("Add Variable")) { if (ImGui::Button("Add variable")) {
// Ajouter une nouvelle variable par défaut // Ajouter une nouvelle variable par défaut
m_story.AddVariable(); story->AddVariable();
} }
ImGui::Separator(); ImGui::Separator();
int i = 0; int i = 0;
m_story.ScanVariable([&i, this] (std::shared_ptr<Variable> var) { story->ScanVariable([&i, story] (std::shared_ptr<Variable> var) {
ImGui::PushID(static_cast<int>(i)); // Assure l'unicité des widgets ImGui::PushID(static_cast<int>(i)); // Assure l'unicité des widgets
std::string l = var->GetVariableName(); std::string l = var->GetVariableName();
@ -91,7 +90,7 @@ void VariablesWindow::ShowRAMEditor()
// Bouton pour supprimer la variable // Bouton pour supprimer la variable
if (ImGui::Button("Delete")) { if (ImGui::Button("Delete")) {
m_story.DeleteVariable(i); story->DeleteVariable(i);
ImGui::TreePop(); ImGui::TreePop();
ImGui::PopID(); ImGui::PopID();
@ -106,11 +105,17 @@ void VariablesWindow::ShowRAMEditor()
} }
void VariablesWindow::Draw() void VariablesWindow::Draw()
{
}
void VariablesWindow::Draw(std::shared_ptr<IStoryProject> story)
{ {
WindowBase::BeginDraw(); WindowBase::BeginDraw();
if (story)
ShowRAMEditor(); {
ShowRAMEditor(story);
}
WindowBase::EndDraw(); WindowBase::EndDraw();
} }

View file

@ -1,22 +1,19 @@
#pragma once #pragma once
#include "window_base.h" #include "window_base.h"
#include "i_story_manager.h" #include "i_story_project.h"
#include "gui.h" #include "gui.h"
class VariablesWindow : public WindowBase class VariablesWindow : public WindowBase
{ {
public: public:
VariablesWindow(IStoryManager &proj); VariablesWindow();
void Initialize(); void Initialize();
virtual void Draw() override; void Draw() override;
void Draw(std::shared_ptr<IStoryProject> story);
private: private:
IStoryManager &m_story; void ShowRAMEditor(std::shared_ptr<IStoryProject> story);
void ShowRAMEditor();
}; };

View file

@ -11,6 +11,8 @@ bool WindowBase::BeginDraw()
{ {
bool ok = ImGui::Begin(m_title.c_str(), nullptr, m_windowFlags); bool ok = ImGui::Begin(m_title.c_str(), nullptr, m_windowFlags);
m_focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows);
if (m_disabled) if (m_disabled)
{ {
ImGui::BeginDisabled(); ImGui::BeginDisabled();

View file

@ -23,6 +23,10 @@ public:
m_disabled = true; m_disabled = true;
} }
bool IsFocused() const {
return m_focused;
}
void Enable() { void Enable() {
m_disabled = false; m_disabled = false;
} }
@ -34,6 +38,7 @@ public:
private: private:
bool m_disabled{false}; bool m_disabled{false};
bool m_focused{false};
std::string m_title; std::string m_title;
ImGuiWindowFlags m_windowFlags = 0; ImGuiWindowFlags m_windowFlags = 0;
}; };