Ember
Loading...
Searching...
No Matches
BehaviorTreeProjectDialog.h
Go to the documentation of this file.
1#pragma once
2
4#include <memory>
5#include <string>
6#include <vector>
7#include <wx/listctrl.h>
8#include <wx/notebook.h>
9#include <wx/scrolwin.h>
10#include <wx/splitter.h>
11#include <wx/stc/stc.h>
12#include <wx/timer.h>
13#include <wx/treectrl.h>
14#include <wx/wx.h>
15
16// Forward declarations
17namespace EmberCore {
20} // namespace EmberCore
21
33 public:
39 explicit BehaviorTreeProjectDialog(wxWindow *parent,
40 std::shared_ptr<EmberCore::BehaviorTreeProject> project = nullptr);
42
46 std::shared_ptr<EmberCore::BehaviorTreeProject> GetProject() const { return m_project; }
47
51 bool IsProjectValid() const { return m_isValid; }
52
53 private:
54 // UI Creation methods
55 void CreateLayout();
56 wxPanel *CreateLeftPanel(wxWindow *parent);
57 wxPanel *CreateRightPanel(wxWindow *parent);
58
59 // Tab creation methods
60 wxPanel *CreateResourcesTab(wxNotebook *notebook);
61 wxPanel *CreateValidationTab(wxNotebook *notebook);
62 wxPanel *CreatePreviewTab(wxNotebook *notebook);
63 wxPanel *CreateBlackboardTab(wxNotebook *notebook);
64
65 // Event handlers - Project settings
66 void OnProjectNameChanged(wxCommandEvent &event);
67 void OnDescriptionChanged(wxCommandEvent &event);
68 void OnProfileSelected(wxCommandEvent &event);
69
70 // Event handlers - Resource management
71 void OnAddFiles(wxCommandEvent &event);
72 void OnAddFolder(wxCommandEvent &event);
73 void OnRemoveFiles(wxCommandEvent &event);
74 void OnClearFiles(wxCommandEvent &event);
75 void OnResourceSelected(wxListEvent &event);
76 void OnResourceActivated(wxListEvent &event);
77
78 // Event handlers - Validation
79 void OnValidate(wxCommandEvent &event);
80 void OnRefreshPreview(wxCommandEvent &event);
81
82 // Event handlers - Dialog buttons
83 void OnCreate(wxCommandEvent &event);
84 void OnCancel(wxCommandEvent &event);
85 void OnSave(wxCommandEvent &event);
86
87 // Helper methods
88 void LoadProfileList();
89 void UpdateResourceList();
91 void UpdateTreePreview();
95 void DrawFileStructureDiagram(wxDC &dc);
96 void DrawBlackboardDiagram(wxDC &dc);
97 void OnStructurePanelClick(wxMouseEvent &event);
98 void LoadXMLPreview(const std::string &filepath, int highlightLine = -1);
99 void LoadTreePreview(const std::string &filepath, const std::string &treeId);
100 void LoadBlackboardPreview(const std::string &filepath, const std::string &blackboardId);
101 void OnPreviewFilterChanged(wxCommandEvent &event);
102 void UpdateBlackboardTab();
103
104 // Validation helpers
105 bool IsValidProjectName(const wxString &name) const;
106 void OnPulseTimer(wxTimerEvent &event);
108 wxColour InterpolateColor(const wxColour &color1, const wxColour &color2, float t);
109
110 // Resource validation helpers
111 wxString GetResourceStatusIcon(bool valid) const;
112 void SetResourceItemStatus(long item, bool valid, int treeCount);
113
114 // Populate from existing project
115 void PopulateFromProject();
116
117 private:
118 // Project data
119 std::shared_ptr<EmberCore::BehaviorTreeProject> m_project;
121 bool m_isEditMode; // true if editing existing project
122
123 // Left panel - Project settings
124 wxTextCtrl *m_projectName;
127
128 // Right panel - Tabs
129 wxNotebook *m_notebook;
130
131 // Resources tab
132 wxListCtrl *m_resourceList;
133 wxButton *m_addFilesBtn;
134 wxButton *m_addFolderBtn;
137 wxStaticText *m_resourceCountLabel;
138
139 // Validation tab
141 wxButton *m_validateBtn;
142 wxStaticText *m_validationStatus;
143 wxStaticBitmap *m_validationIcon;
146
147 // Preview tab
148 wxScrolledWindow *m_fileStructurePanel; // File structure diagram (scrollable)
149 wxStyledTextCtrl *m_xmlPreviewPanel; // XML content preview (read-only with line numbers)
150 wxTextCtrl *m_warningDetailsPanel; // Warning/Error details (only visible when warning clicked)
151
152 // Preview filters
160 wxStaticText *m_treeCountLabel;
161
162 // Clickable item tracking
166 wxRect rect;
167 std::string identifier; // filename, tree_id, blackboard_id, or warning text
168 std::string filepath; // for trees, blackboards, and warnings
169 int line_number; // for warnings (-1 if not applicable)
170 };
171 std::vector<ClickableItem> m_clickableItems;
172
173 // Blackboard tab
174 wxScrolledWindow *m_blackboardPanel;
175
176 // Bottom buttons
177 wxButton *m_createBtn;
178 wxButton *m_cancelBtn;
179
180 // Validation state
181 std::unique_ptr<EmberCore::ProjectValidationReport> m_lastValidationReport;
182 bool m_validationStale; // true if resources/profile changed since last validation
183 wxString m_lastValidatedParserProfile; // track parser profile changes
184
185 // Image list for resource status icons
187
188 // Last used directory for file dialogs (persists across dialog opens)
189 static wxString s_lastUsedDirectory;
190
191 // Field highlighting for validation
192 wxTimer *m_pulseTimer;
194 wxColour m_normalBg;
196
197 int m_selectedItemIndex; // Index of currently selected item (-1 if none)
198
200
201 // Control IDs
202 enum {
206
212
215
218
220 };
221};
BehaviorTreeProjectDialog(wxWindow *parent, std::shared_ptr< EmberCore::BehaviorTreeProject > project=nullptr)
Construct a new dialog for creating/editing a project.
void OnResourceSelected(wxListEvent &event)
void SetResourceItemStatus(long item, bool valid, int treeCount)
void OnProfileSelected(wxCommandEvent &event)
void LoadTreePreview(const std::string &filepath, const std::string &treeId)
void OnClearFiles(wxCommandEvent &event)
wxPanel * CreatePreviewTab(wxNotebook *notebook)
wxPanel * CreateValidationTab(wxNotebook *notebook)
void OnValidate(wxCommandEvent &event)
wxColour InterpolateColor(const wxColour &color1, const wxColour &color2, float t)
wxPanel * CreateBlackboardTab(wxNotebook *notebook)
void OnDescriptionChanged(wxCommandEvent &event)
wxPanel * CreateRightPanel(wxWindow *parent)
void OnCancel(wxCommandEvent &event)
void OnSave(wxCommandEvent &event)
void OnPulseTimer(wxTimerEvent &event)
void OnProjectNameChanged(wxCommandEvent &event)
std::vector< ClickableItem > m_clickableItems
void OnStructurePanelClick(wxMouseEvent &event)
void OnResourceActivated(wxListEvent &event)
void OnRefreshPreview(wxCommandEvent &event)
void LoadBlackboardPreview(const std::string &filepath, const std::string &blackboardId)
std::unique_ptr< EmberCore::ProjectValidationReport > m_lastValidationReport
void GenerateColoredValidationReport(const EmberCore::ProjectValidationReport &report)
void LoadXMLPreview(const std::string &filepath, int highlightLine=-1)
void OnCreate(wxCommandEvent &event)
bool IsProjectValid() const
Check if the project configuration is valid.
void OnPreviewFilterChanged(wxCommandEvent &event)
std::shared_ptr< EmberCore::BehaviorTreeProject > m_project
void OnAddFolder(wxCommandEvent &event)
std::shared_ptr< EmberCore::BehaviorTreeProject > GetProject() const
Get the configured project (after dialog is closed with OK)
wxPanel * CreateLeftPanel(wxWindow *parent)
bool IsValidProjectName(const wxString &name) const
wxPanel * CreateResourcesTab(wxNotebook *notebook)
void OnAddFiles(wxCommandEvent &event)
wxString GetResourceStatusIcon(bool valid) const
void OnRemoveFiles(wxCommandEvent &event)
Represents a BehaviorTree project containing multiple XML resources.
DPI-aware dialog base class for scalable layouts.
Main types header for EmberCore.
Complete validation report for a project.