Ember
Loading...
Searching...
No Matches
PropertiesTab.cpp
Go to the documentation of this file.
2#include "App/MainFrame.h"
5#include "Utils/Logger.h"
6#include <wx/aui/auibook.h>
7
8// Event table
10 EVT_PG_CHANGING(wxID_ANY, PropertiesTab::OnPropertyChanging) wxEND_EVENT_TABLE()
11
12 PropertiesTab::PropertiesTab(wxWindow *parent, MainFrame *mainFrame)
13 : wxPanel(parent, wxID_ANY), m_notebook(nullptr), m_nodePanel(nullptr), m_nodePropertyGrid(nullptr),
14 m_blackboardPanel(nullptr), m_blackboardList(nullptr), m_selectedNode(nullptr), m_selectedBlackboard(nullptr),
15 m_mainFrame(mainFrame) {
16 SetBackgroundColour(wxColour(70, 70, 70)); // Dark gray
17 CreateLayout();
18}
19
21 // Notify MainFrame that this tab is being closed
22 if (m_mainFrame) {
23 m_mainFrame->OnPropertiesTabClosed();
24 }
25}
26
28 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
29
30 // Create notebook for different property categories
32 new wxAuiNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_FIXED_WIDTH);
33 m_notebook->SetBackgroundColour(wxColour(70, 70, 70));
34
35 // Set custom tab art to use accent color
36 m_notebook->SetArtProvider(new EmberForge::CustomTabArt());
37
38 // ====== NODE PROPERTIES TAB ======
39 m_nodePanel = new wxPanel(m_notebook, wxID_ANY);
40 m_nodePanel->SetBackgroundColour(wxColour(70, 70, 70));
41
42 // Create property grid for node properties
43 m_nodePropertyGrid = new wxPropertyGrid(m_nodePanel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
44 wxPG_SPLITTER_AUTO_CENTER | wxPG_DEFAULT_STYLE);
45
46 // Set property grid colors for dark theme
47 m_nodePropertyGrid->SetBackgroundColour(wxColour(60, 60, 60));
48 m_nodePropertyGrid->SetForegroundColour(wxColour(200, 200, 200));
49 m_nodePropertyGrid->SetCaptionBackgroundColour(wxColour(80, 80, 80));
50 m_nodePropertyGrid->SetCaptionTextColour(wxColour(220, 220, 220));
52
53 wxBoxSizer *nodeSizer = new wxBoxSizer(wxVERTICAL);
54 nodeSizer->Add(m_nodePropertyGrid, 1, wxEXPAND | wxALL, 5);
55 m_nodePanel->SetSizer(nodeSizer);
56
57 m_notebook->AddPage(m_nodePanel, "Node Properties", true);
58
59 // ====== BLACKBOARD TAB ======
60 m_blackboardPanel = new wxPanel(m_notebook, wxID_ANY);
61 m_blackboardPanel->SetBackgroundColour(wxColour(70, 70, 70));
62
63 // Create list control for blackboard entries
65 new wxListCtrl(m_blackboardPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
66
67 // Set up blackboard list columns
68 m_blackboardList->AppendColumn("Key", wxLIST_FORMAT_LEFT, 120);
69 m_blackboardList->AppendColumn("Type", wxLIST_FORMAT_LEFT, 100);
70 m_blackboardList->AppendColumn("Value", wxLIST_FORMAT_LEFT, 150);
71
72 // Set colors for dark theme
73 m_blackboardList->SetBackgroundColour(wxColour(60, 60, 60));
74 m_blackboardList->SetForegroundColour(wxColour(200, 200, 200));
75
76 wxBoxSizer *blackboardSizer = new wxBoxSizer(wxVERTICAL);
77
78 // Add info label
79 wxStaticText *bbLabel =
80 new wxStaticText(m_blackboardPanel, wxID_ANY, "Blackboard entries available to selected node:");
81 bbLabel->SetForegroundColour(wxColour(200, 200, 200));
82 blackboardSizer->Add(bbLabel, 0, wxALL, 5);
83
84 blackboardSizer->Add(m_blackboardList, 1, wxEXPAND | wxALL, 5);
85 m_blackboardPanel->SetSizer(blackboardSizer);
86
87 m_notebook->AddPage(m_blackboardPanel, "Blackboard", false);
88
89 // ====== MAIN LAYOUT ======
90 mainSizer->Add(m_notebook, 1, wxEXPAND | wxALL, 5);
91
92 // Add status text for when no node is selected
93 wxStaticText *statusText = new wxStaticText(this, wxID_ANY, "Select a node to view its properties");
94 statusText->SetForegroundColour(wxColour(150, 150, 150));
95 mainSizer->Add(statusText, 0, wxALIGN_CENTER | wxALL, 10);
96
97 SetSizer(mainSizer);
98
99 // Initially show "no selection" state
101}
102
104 m_selectedNode = node;
105
106 if (node) {
107 LOG_INFO("Properties",
108 wxString::Format("Selected node: %s (ID: %zu)", node->GetName(), node->GetId()).ToStdString());
110 m_notebook->Show(true);
111 } else {
113 }
114}
115
117 m_selectedBlackboard = blackboard;
118
119 if (blackboard) {
120 LOG_INFO("Properties", wxString::Format("Selected blackboard: %s", blackboard->GetId()).ToStdString());
122 }
123}
124
126 m_selectedNode = nullptr;
127 m_selectedBlackboard = nullptr;
129 m_notebook->Show(false);
130 Layout();
131}
132
135 return;
136 }
137
138 // Clear existing properties
139 m_nodePropertyGrid->Clear();
140
141 // Add basic node properties
143
144 // Add custom attributes
146
147 // Refresh the grid
148 m_nodePropertyGrid->Refresh();
149}
150
152 if (!m_blackboardList) {
153 return;
154 }
155
156 // Clear existing entries
157 m_blackboardList->DeleteAllItems();
158
161 }
162}
163
165 if (m_nodePropertyGrid) {
166 m_nodePropertyGrid->Clear();
167 }
168
169 if (m_blackboardList) {
170 m_blackboardList->DeleteAllItems();
171 }
172}
173
175 if (!m_selectedNode)
176 return;
177
178 // Create property categories
179 m_nodePropertyGrid->Append(new wxPropertyCategory("Basic Properties"));
180
181 // Node Name
182 auto nameProp = new wxStringProperty("Name", "name", m_selectedNode->GetName());
183 nameProp->SetClientData(reinterpret_cast<void *>(PROP_NODE_NAME));
184 m_nodePropertyGrid->Append(nameProp);
185
186 // Node ID (read-only)
187 auto idProp = new wxUIntProperty("ID", "id", static_cast<unsigned int>(m_selectedNode->GetId()));
188 idProp->SetClientData(reinterpret_cast<void *>(PROP_NODE_ID));
189 idProp->ChangeFlag(wxPGPropertyFlags::ReadOnly, true);
190 m_nodePropertyGrid->Append(idProp);
191
192 // Node Type (read-only for now)
193 auto typeProp = new wxStringProperty("Type", "type", GetNodeTypeDisplayName(m_selectedNode->GetType()));
194 typeProp->SetClientData(reinterpret_cast<void *>(PROP_NODE_TYPE));
195 typeProp->ChangeFlag(wxPGPropertyFlags::ReadOnly, true);
196 m_nodePropertyGrid->Append(typeProp);
197
198 // Node Status
199 wxArrayString statusChoices;
200 statusChoices.Add("Idle");
201 statusChoices.Add("Running");
202 statusChoices.Add("Success");
203 statusChoices.Add("Failure");
204
205 wxPGChoices statusPGChoices(statusChoices);
206 auto statusProp =
207 new wxEnumProperty("Status", "status", statusPGChoices, static_cast<int>(m_selectedNode->GetStatus()));
208 statusProp->SetClientData(reinterpret_cast<void *>(PROP_NODE_STATUS));
209 m_nodePropertyGrid->Append(statusProp);
210
211 // Visual Properties
212 m_nodePropertyGrid->Append(new wxPropertyCategory("Visual Properties"));
213
214 // Children Visible
215 auto childrenVisibleProp =
216 new wxBoolProperty("Children Visible", "children_visible", m_selectedNode->AreChildrenVisible());
217 childrenVisibleProp->SetClientData(reinterpret_cast<void *>(PROP_NODE_CHILDREN_VISIBLE));
218 m_nodePropertyGrid->Append(childrenVisibleProp);
219}
220
222 if (!m_selectedNode)
223 return;
224
225 const auto &attributes = m_selectedNode->GetAllAttributes();
226 if (attributes.empty()) {
227 return;
228 }
229
230 // Add custom attributes category
231 m_nodePropertyGrid->Append(new wxPropertyCategory("Custom Attributes"));
232
233 int propId = PROP_CUSTOM_ATTRIBUTES_START;
234 for (const auto &pair : attributes) {
235 auto attrProp = new wxStringProperty(pair.first, wxString::Format("attr_%s", pair.first), pair.second);
236 attrProp->SetClientData(reinterpret_cast<void *>(propId++));
237 attrProp->SetHelpString(wxString::Format("Custom attribute from XML: %s", pair.first));
238 m_nodePropertyGrid->Append(attrProp);
239 }
240}
241
244 return;
245
246 const auto &entries = m_selectedBlackboard->GetEntries();
247
248 int index = 0;
249 for (const auto &pair : entries) {
250 const EmberCore::BlackboardEntry *entry = pair.second.get();
251 if (!entry)
252 continue;
253
254 long itemIndex = m_blackboardList->InsertItem(index, entry->GetKey());
255 m_blackboardList->SetItem(itemIndex, 1, entry->GetTypeString());
256 m_blackboardList->SetItem(itemIndex, 2, entry->GetValue());
257
258 index++;
259 }
260}
261
263 switch (type) {
265 return "Control";
267 return "Action";
269 return "Condition";
271 return "Decorator";
273 return "BehaviorTree";
275 return "None";
276 default:
277 return "Unknown";
278 }
279}
280
282 switch (status) {
284 return "Idle";
286 return "Running";
288 return "Success";
290 return "Failure";
291 default:
292 return "Unknown";
293 }
294}
295
296void PropertiesTab::OnPropertyChanged(wxPropertyGridEvent &event) {
297 if (!m_selectedNode) {
298 return;
299 }
300
301 wxPGProperty *prop = event.GetProperty();
302 if (!prop)
303 return;
304
305 int propId = reinterpret_cast<intptr_t>(prop->GetClientData());
306 wxVariant value = prop->GetValue();
307
308 LOG_INFO("Properties",
309 wxString::Format("Property changed: %s = %s", prop->GetName(), value.GetString()).ToStdString());
310
311 // Handle different property types
312 switch (propId) {
313 case PROP_NODE_NAME:
314 m_selectedNode->SetName(value.GetString().ToStdString());
315 break;
316
317 case PROP_NODE_STATUS:
318 m_selectedNode->SetStatus(static_cast<EmberCore::Node::Status>(value.GetLong()));
319 break;
320
322 m_selectedNode->SetChildrenVisible(value.GetBool());
323 break;
324
325 default:
326 // Handle custom attributes
327 if (propId >= PROP_CUSTOM_ATTRIBUTES_START) {
328 wxString attrName = prop->GetName();
329 m_selectedNode->SetAttribute(attrName.ToStdString(), value.GetString().ToStdString());
330 }
331 break;
332 }
333}
334
335void PropertiesTab::OnPropertyChanging(wxPropertyGridEvent &event) {
336 // This event is called before the property value changes
337 // We can use it for validation if needed
338 wxPGProperty *prop = event.GetProperty();
339 if (!prop)
340 return;
341
342 // For now, allow all changes
343 // In the future, we could add validation here
344}
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
#define LOG_INFO(category, message)
Definition Logger.h:114
wxBEGIN_EVENT_TABLE(PropertiesTab, wxPanel) EVT_PG_CHANGED(wxID_ANY
PropertiesTab::OnPropertyChanged EVT_PG_CHANGING(wxID_ANY, PropertiesTab::OnPropertyChanging) wxEND_EVENT_TABLE() PropertiesTab
Represents a single entry in a behavior tree blackboard.
const EmberCore::String & GetValue() const
EmberCore::String GetTypeString() const
const EmberCore::String & GetKey() const
Represents a blackboard containing multiple entries.
const EmberCore::String & GetId() const
Represents a node in a behavior tree structure.
Definition Node.h:20
Status
Node status for runtime execution tracking.
Definition Node.h:37
Type
Node types for behavior tree classification.
Definition Node.h:25
size_t GetId() const
Definition Node.h:80
const String & GetName() const
Definition Node.h:81
static wxColour GetAccentColor()
Get the accent color as a wxColour for UI elements.
Custom tab art provider that uses the application's accent color.
Main application window for EmberForge.
Definition MainFrame.h:65
Tab for editing node properties and blackboard entries.
MainFrame * m_mainFrame
wxPanel * m_blackboardPanel
void OnClosed() override
Called when the tab is about to be closed/removed Use this for cleanup operations.
void ClearAllProperties()
void SetSelectedNode(EmberCore::Node *node)
void OnPropertyChanged(wxPropertyGridEvent &event)
void SetSelectedBlackboard(EmberCore::Blackboard *blackboard)
wxString GetNodeTypeDisplayName(EmberCore::Node::Type type) const
wxString GetNodeStatusDisplayName(EmberCore::Node::Status status) const
void UpdateNodeProperties()
void AddNodeBasicProperties()
wxListCtrl * m_blackboardList
void OnPropertyChanging(wxPropertyGridEvent &event)
void AddNodeCustomAttributes()
EmberCore::Blackboard * m_selectedBlackboard
void AddBlackboardEntries()
wxPanel * m_nodePanel
@ PROP_CUSTOM_ATTRIBUTES_START
wxAuiNotebook * m_notebook
void UpdateBlackboardProperties()
EmberCore::Node * m_selectedNode
wxPropertyGrid * m_nodePropertyGrid