Ember
Loading...
Searching...
No Matches
ParserConfigDialog.cpp
Go to the documentation of this file.
5#include "Utils/Logger.h"
7#include <cmath>
8#include <wx/filedlg.h>
9#include <wx/filename.h>
10#include <wx/gbsizer.h>
11#include <wx/listctrl.h>
12#include <wx/msgdlg.h>
13#include <wx/statbox.h>
14#include <wx/statline.h>
15#include <wx/stdpaths.h>
16#include <wx/textdlg.h>
17
18// Helper function to get resource path
19static wxString GetResourcePath(const wxString &relativePath) { return EmberForge::ResourcePath::Get(relativePath); }
20
21wxBEGIN_EVENT_TABLE(ParserConfigDialog, wxDialog) EVT_LIST_ITEM_SELECTED(
23 EVT_BUTTON(ID_CLONE_PROFILE, ParserConfigDialog::OnCloneProfile) EVT_BUTTON(ID_DELETE_PROFILE,
24 ParserConfigDialog::OnDeleteProfile)
25 EVT_BUTTON(ID_IMPORT_PROFILE, ParserConfigDialog::OnImportProfile) EVT_BUTTON(
26 ID_EXPORT_PROFILE, ParserConfigDialog::OnExportProfile) EVT_BUTTON(ID_SET_ACTIVE,
27 ParserConfigDialog::OnSetActiveProfile)
28 EVT_BUTTON(ID_ADD_CONTROL_TYPE,
29 ParserConfigDialog::OnAddControlType) EVT_BUTTON(ID_REMOVE_CONTROL_TYPE,
30 ParserConfigDialog::OnRemoveControlType)
31 EVT_BUTTON(ID_ADD_DECORATOR_TYPE,
32 ParserConfigDialog::OnAddDecoratorType) EVT_BUTTON(ID_REMOVE_DECORATOR_TYPE,
33 ParserConfigDialog::OnRemoveDecoratorType)
34 EVT_BUTTON(ID_ADD_ACTION_TYPE,
35 ParserConfigDialog::OnAddActionType) EVT_BUTTON(ID_REMOVE_ACTION_TYPE,
36 ParserConfigDialog::OnRemoveActionType)
37 EVT_BUTTON(ID_ADD_CONDITION_TYPE, ParserConfigDialog::OnAddConditionType)
38 EVT_BUTTON(ID_REMOVE_CONDITION_TYPE, ParserConfigDialog::OnRemoveConditionType)
39 EVT_BUTTON(ID_ADD_MAPPING, ParserConfigDialog::OnAddTypeMapping)
40 EVT_BUTTON(ID_REMOVE_MAPPING, ParserConfigDialog::OnRemoveTypeMapping)
41 EVT_CHECKBOX(ID_TOGGLE_CUSTOM_VALIDATION,
42 ParserConfigDialog::OnToggleCustomValidation)
43 EVT_BUTTON(ID_TEST_VALIDATE, ParserConfigDialog::OnTestValidate)
44 EVT_BUTTON(ID_PREVIEW_JSON, ParserConfigDialog::OnPreviewJSON)
45 EVT_BUTTON(ID_RESET_DEFAULTS, ParserConfigDialog::OnResetDefaults)
46 EVT_BUTTON(ID_SAVE, ParserConfigDialog::OnSave)
47 EVT_BUTTON(ID_SAVE_AS, ParserConfigDialog::OnSaveAs)
48 EVT_BUTTON(wxID_CANCEL, ParserConfigDialog::OnCancel)
49 EVT_TIMER(ID_PULSE_TIMER,
50 ParserConfigDialog::OnPulseTimer)
52
54 wxWindow *parent)
55 : wxDialog(parent, wxID_ANY, "Parser Configuration", wxDefaultPosition, wxSize(1400, 1000),
56 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
57 m_currentProfile(nullptr), m_modified(false), m_pulseTimer(nullptr), m_pulsePhase(0.0f),
58 m_normalBg(50, 50, 50) // Dark background
59 ,
60 m_highlightBg(255, 250, 150) // Soft yellow highlight
61{
62 CreateLayout();
63 LoadProfiles();
64 Centre();
65
66 // Start the pulse animation timer (30ms = ~33 fps for smooth animation)
67 m_pulseTimer = new wxTimer(this, ID_PULSE_TIMER);
68 m_pulseTimer->Start(30);
69}
70
72 wxBoxSizer *mainSizer = new wxBoxSizer(wxHORIZONTAL);
73
74 // Left sidebar (200px fixed width)
75 wxPanel *leftPanel = CreateLeftSidebar(this);
76 mainSizer->Add(leftPanel, 0, wxEXPAND | wxALL, 5);
77
78 // Right panel (expandable)
79 wxPanel *rightPanel = CreateRightPanel(this);
80 mainSizer->Add(rightPanel, 1, wxEXPAND | wxALL, 5);
81
82 SetSizer(mainSizer);
83}
84
85wxPanel *ParserConfigDialog::CreateLeftSidebar(wxWindow *parent) {
86 wxPanel *panel = new wxPanel(parent, wxID_ANY);
87 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
88
89 // Profile list
90 wxStaticText *label = new wxStaticText(panel, wxID_ANY, "Profiles:");
91 sizer->Add(label, 0, wxALL, 5);
92
93 // Use wxListCtrl for per-item color support
94 m_profileList = new wxListCtrl(panel, ID_PROFILE_LIST, wxDefaultPosition, wxDefaultSize,
95 wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxBORDER_SUNKEN);
96 m_profileList->SetMinSize(wxSize(200, -1));
97
98 // Set larger, bold font for profile list
99 wxFont profileFont = m_profileList->GetFont();
100 profileFont.SetPointSize(profileFont.GetPointSize() + 2); // Larger text
101 profileFont.MakeBold(); // Bold text
102 m_profileList->SetFont(profileFont);
103
104 // Add single column (header is hidden)
105 m_profileList->InsertColumn(0, "Profile", wxLIST_FORMAT_LEFT, 200);
106
107 sizer->Add(m_profileList, 1, wxEXPAND | wxALL, 5);
108
109 // Buttons
110 m_newProfileBtn = new wxButton(panel, ID_NEW_PROFILE, "New Profile");
111 sizer->Add(m_newProfileBtn, 0, wxEXPAND | wxALL, 2);
112
113 m_cloneProfileBtn = new wxButton(panel, ID_CLONE_PROFILE, "Clone Profile");
114 sizer->Add(m_cloneProfileBtn, 0, wxEXPAND | wxALL, 2);
115
116 m_deleteProfileBtn = new wxButton(panel, ID_DELETE_PROFILE, "Delete Profile");
117 sizer->Add(m_deleteProfileBtn, 0, wxEXPAND | wxALL, 2);
118
119 sizer->AddSpacer(10);
120
121 m_importProfileBtn = new wxButton(panel, ID_IMPORT_PROFILE, "Import Profile...");
122 sizer->Add(m_importProfileBtn, 0, wxEXPAND | wxALL, 2);
123
124 m_exportProfileBtn = new wxButton(panel, ID_EXPORT_PROFILE, "Export Profile...");
125 sizer->Add(m_exportProfileBtn, 0, wxEXPAND | wxALL, 2);
126
127 sizer->AddSpacer(10);
128
129 m_setActiveBtn = new wxButton(panel, ID_SET_ACTIVE, "Set as Active");
130 sizer->Add(m_setActiveBtn, 0, wxEXPAND | wxALL, 2);
131
132 panel->SetSizer(sizer);
133 return panel;
134}
135
136wxPanel *ParserConfigDialog::CreateRightPanel(wxWindow *parent) {
137 wxPanel *panel = new wxPanel(parent, wxID_ANY);
138 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
139
140 // Notebook with tabs
141 m_notebook = new wxNotebook(panel, wxID_ANY);
142
143 m_notebook->AddPage(CreateDocumentStructureTab(m_notebook), "Document Structure");
144 m_notebook->AddPage(CreateTreeElementsTab(m_notebook), "Tree Elements");
145 m_notebook->AddPage(CreateNodeElementsTab(m_notebook), "Node Elements");
146 m_notebook->AddPage(CreateNodeClassificationTab(m_notebook), "Node Classification");
147 m_notebook->AddPage(CreateBlackboardTab(m_notebook), "Blackboard");
148 m_notebook->AddPage(CreateAdvancedTab(m_notebook), "Advanced");
149
150 sizer->Add(m_notebook, 1, wxEXPAND | wxALL, 5);
151
152 // Bottom panel
153 wxPanel *bottomPanel = CreateBottomPanel(panel);
154 sizer->Add(bottomPanel, 0, wxEXPAND | wxALL, 5);
155
156 panel->SetSizer(sizer);
157 return panel;
158}
159
161 wxPanel *panel = new wxPanel(notebook);
162 wxGridBagSizer *sizer = new wxGridBagSizer(10, 10); // Increased from 5,5 to 10,10 for more spacing
163
164 int row = 0;
165
166 // Root element name
167 wxBoxSizer *labelSizer1 = new wxBoxSizer(wxHORIZONTAL);
168
169 // Create info button with all state images - positioned first (left)
170 // Get button size dynamically from image with safety check
171 wxBitmap infoNormal(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
172 wxBitmap infoHover(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
173 wxBitmap infoPressed(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
174 wxBitmap infoDisabled(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
175
176 wxBitmapButton *infoBtn1 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
177 wxBORDER_NONE | wxBU_EXACTFIT);
178 infoBtn1->SetBitmapHover(infoHover);
179 infoBtn1->SetBitmapPressed(infoPressed);
180 infoBtn1->SetBitmapDisabled(infoDisabled);
181 infoBtn1->SetToolTip("Click for detailed information");
182 infoBtn1->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
183 wxString helpText = "ROOT ELEMENT NAME\n"
184 "===========================================================\n\n"
185 "WHAT IS IT?\n"
186 "The name of the top-level XML element that wraps all behavior trees.\n"
187 "This is the outermost container in your XML file.\n\n"
188 "COMMON VALUES:\n"
189 " - 'root' - BehaviorTree.CPP standard format\n"
190 " - 'BehaviorTrees' - Some Unity implementations\n"
191 " - 'TreeCollection' - Custom formats\n\n"
192 "IMPORTANT:\n"
193 "This element MUST be present in your XML file as the outermost container.\n"
194 "All behavior tree definitions must be nested inside this root element.\n\n"
195 "EXAMPLE XML STRUCTURE:\n"
196 " <root main_tree_to_execute=\"MainTree\">\n"
197 " <BehaviorTree ID=\"MainTree\">\n"
198 " <Sequence>\n"
199 " <Action ID=\"MoveForward\"/>\n"
200 " </Sequence>\n"
201 " </BehaviorTree>\n"
202 " </root>\n\n"
203 "If your XML uses a different name (e.g., <Trees>), enter that name here.";
204 HelpDialog dlg(this, "Root Element Name - Help", helpText);
205 dlg.ShowModal();
206 });
207 labelSizer1->Add(infoBtn1, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
208 labelSizer1->Add(new wxStaticText(panel, wxID_ANY, "Root Element Name:"), 0, wxALIGN_CENTER_VERTICAL);
209 sizer->Add(labelSizer1, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
210
211 m_rootElement = new wxTextCtrl(panel, wxID_ANY);
212 m_rootElement->SetToolTip("Top-level XML element name (e.g., 'root')");
213 m_rootElement->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
214 sizer->Add(m_rootElement, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
215 row++;
216
217 // Main tree attribute
218 wxBoxSizer *labelSizer2 = new wxBoxSizer(wxHORIZONTAL);
219
220 wxBitmapButton *infoBtn2 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
221 wxBORDER_NONE | wxBU_EXACTFIT);
222 infoBtn2->SetBitmapHover(infoHover);
223 infoBtn2->SetBitmapPressed(infoPressed);
224 infoBtn2->SetBitmapDisabled(infoDisabled);
225 infoBtn2->SetToolTip("Click for detailed information");
226 infoBtn2->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
227 wxString helpText = "MAIN TREE ATTRIBUTE\n"
228 "===========================================================\n\n"
229 "WHAT IS IT?\n"
230 "The attribute on the root element that specifies which behavior tree\n"
231 "should be executed first when your XML file contains multiple trees.\n\n"
232 "COMMON VALUES:\n"
233 " - 'main_tree_to_execute' - BehaviorTree.CPP standard\n"
234 " - 'entry_point' - Alternative naming convention\n"
235 " - 'start_tree' - Some custom implementations\n\n"
236 "WHY DO YOU NEED IT?\n"
237 "When your XML file contains multiple behavior tree definitions (main tree,\n"
238 "subtrees, utility trees), this attribute tells the system which one is the\n"
239 "primary entry point.\n\n"
240 "EXAMPLE:\n"
241 " <root main_tree_to_execute=\"PlayerAI\">\n"
242 " <BehaviorTree ID=\"PlayerAI\">\n"
243 " <!-- This tree will be loaded first -->\n"
244 " </BehaviorTree>\n"
245 " <BehaviorTree ID=\"EnemyAI\">\n"
246 " <!-- This tree is available as a subtree -->\n"
247 " </BehaviorTree>\n"
248 " </root>\n\n"
249 "FALLBACK BEHAVIOR:\n"
250 "If this attribute is missing or empty, the parser will automatically\n"
251 "load the first behavior tree it finds in the file.";
252 HelpDialog dlg(this, "Main Tree Attribute - Help", helpText);
253 dlg.ShowModal();
254 });
255 labelSizer2->Add(infoBtn2, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
256 labelSizer2->Add(new wxStaticText(panel, wxID_ANY, "Main Tree Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
257 sizer->Add(labelSizer2, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
258
259 m_mainTreeAttr = new wxTextCtrl(panel, wxID_ANY);
260 m_mainTreeAttr->SetToolTip("Attribute specifying entry point tree (e.g., 'main_tree_to_execute')");
261 m_mainTreeAttr->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
262 sizer->Add(m_mainTreeAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
263 row++;
264
265 // Case sensitive
266 wxBoxSizer *caseSizer = new wxBoxSizer(wxHORIZONTAL);
267
268 wxBitmapButton *infoBtn3 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
269 wxBORDER_NONE | wxBU_EXACTFIT);
270 infoBtn3->SetBitmapHover(infoHover);
271 infoBtn3->SetBitmapPressed(infoPressed);
272 infoBtn3->SetBitmapDisabled(infoDisabled);
273 infoBtn3->SetToolTip("Click for detailed information");
274 infoBtn3->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
275 wxString helpText = "CASE SENSITIVE ELEMENT NAMES\n"
276 "===========================================================\n\n"
277 "Controls whether element and attribute names must match the exact\n"
278 "case specified in your configuration.\n\n"
279 "ENABLED (Recommended):\n"
280 " - <BehaviorTree> and <behaviortree> are treated as DIFFERENT\n"
281 " - More strict parsing - catches typos and inconsistencies\n"
282 " - Standard for most XML parsers and behavior tree formats\n"
283 " - Best for well-defined, consistent XML formats\n\n"
284 "DISABLED:\n"
285 " - <BehaviorTree>, <behaviortree>, <BEHAVIORTREE> all treated as SAME\n"
286 " - More forgiving - useful for legacy/inconsistent XML files\n"
287 " - May hide formatting issues in your XML\n"
288 " - Use ONLY if your XML has inconsistent casing\n\n"
289 "EXAMPLE:\n"
290 "If ENABLED and you configure 'BehaviorTree' as the tree element:\n"
291 " [YES] <BehaviorTree ID=\"Test\"> - ACCEPTED\n"
292 " [NO] <behaviortree ID=\"Test\"> - REJECTED (case mismatch)\n\n"
293 "If DISABLED:\n"
294 " [YES] <BehaviorTree ID=\"Test\"> - ACCEPTED\n"
295 " [YES] <behaviortree ID=\"Test\"> - ACCEPTED\n"
296 " [YES] <BEHAVIORTREE ID=\"Test\"> - ACCEPTED\n\n"
297 "RECOMMENDATION:\n"
298 "Keep this ENABLED unless working with legacy files that have\n"
299 "inconsistent casing. Strict validation helps catch errors early!";
300 HelpDialog dlg(this, "Case Sensitive - Help", helpText);
301 dlg.ShowModal();
302 });
303 caseSizer->Add(infoBtn3, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
304 m_caseSensitive = new wxCheckBox(panel, wxID_ANY, "Case Sensitive Element Names");
305 m_caseSensitive->SetToolTip("Element/attribute names must match exact case");
306 caseSizer->Add(m_caseSensitive, 0, wxALIGN_CENTER_VERTICAL);
307 sizer->Add(caseSizer, wxGBPosition(row, 0), wxGBSpan(1, 2));
308 row++;
309
310 // Allow unknown elements
311 wxBoxSizer *unknownSizer = new wxBoxSizer(wxHORIZONTAL);
312
313 wxBitmapButton *infoBtn4 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
314 wxBORDER_NONE | wxBU_EXACTFIT);
315 infoBtn4->SetBitmapHover(infoHover);
316 infoBtn4->SetBitmapPressed(infoPressed);
317 infoBtn4->SetBitmapDisabled(infoDisabled);
318 infoBtn4->SetToolTip("Click for detailed information");
319 infoBtn4->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
320 wxString helpText = "ALLOW UNKNOWN ELEMENTS\n"
321 "===========================================================\n\n"
322 "Controls how the parser handles XML elements that are NOT defined\n"
323 "in your configuration.\n\n"
324 "ENABLED:\n"
325 " - Unknown elements are SILENTLY IGNORED\n"
326 " - Parsing continues without warnings\n"
327 " - Useful for XML with documentation, metadata, or extensions\n"
328 " - More flexible for varying XML formats\n\n"
329 "DISABLED (Recommended):\n"
330 " - Unknown elements cause WARNING messages in the log\n"
331 " - Helps catch typos (e.g., 'Behaviortree' vs 'BehaviorTree')\n"
332 " - Stricter validation ensures XML matches expectations\n"
333 " - Better for catching configuration errors\n\n"
334 "EXAMPLE - XML with unknown elements:\n"
335 " <root>\n"
336 " <BehaviorTree ID=\"Test\">...</BehaviorTree>\n"
337 " <Documentation>Comment</Documentation> <- Unknown\n"
338 " <Metadata author=\"John\"/> <- Unknown\n"
339 " </root>\n\n"
340 "If ENABLED: Parser ignores <Documentation> and <Metadata>\n"
341 "If DISABLED: Parser logs warnings about unexpected elements\n\n"
342 "RECOMMENDATION:\n"
343 "Keep DISABLED during development to catch errors.\n"
344 "Enable only if you need to parse XML with extra metadata.";
345 HelpDialog dlg(this, "Allow Unknown Elements - Help", helpText);
346 dlg.ShowModal();
347 });
348 unknownSizer->Add(infoBtn4, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
349 m_allowUnknownElements = new wxCheckBox(panel, wxID_ANY, "Allow Unknown Elements");
350 m_allowUnknownElements->SetToolTip("Silently ignore unrecognized XML elements");
351 unknownSizer->Add(m_allowUnknownElements, 0, wxALIGN_CENTER_VERTICAL);
352 sizer->Add(unknownSizer, wxGBPosition(row, 0), wxGBSpan(1, 2));
353 row++;
354
355 // Whitespace handling
356 wxBoxSizer *labelSizer5 = new wxBoxSizer(wxHORIZONTAL);
357
358 wxBitmapButton *infoBtn5 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
359 wxBORDER_NONE | wxBU_EXACTFIT);
360 infoBtn5->SetBitmapHover(infoHover);
361 infoBtn5->SetBitmapPressed(infoPressed);
362 infoBtn5->SetBitmapDisabled(infoDisabled);
363 infoBtn5->SetToolTip("Click for detailed information");
364 infoBtn5->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
365 wxString helpText = "WHITESPACE HANDLING\n"
366 "===========================================================\n\n"
367 "Controls how whitespace (spaces, tabs, newlines) in attribute values\n"
368 "and text content is processed during parsing.\n\n"
369 "OPTIONS:\n\n"
370 "PRESERVE:\n"
371 " - Keeps ALL whitespace exactly as it appears\n"
372 " - ' Hello World ' stays as ' Hello World '\n"
373 " - Use if whitespace is meaningful in your data\n"
374 " - Rarely needed for behavior trees\n\n"
375 "TRIM (Recommended):\n"
376 " - Removes leading and trailing whitespace ONLY\n"
377 " - ' Hello World ' becomes 'Hello World'\n"
378 " - Internal spaces preserved: 'Hello World' stays 'Hello World'\n"
379 " - Best for most behavior tree formats\n"
380 " - Handles formatting inconsistencies gracefully\n\n"
381 "NORMALIZE:\n"
382 " - Trims AND collapses multiple spaces to single space\n"
383 " - ' Hello World ' becomes 'Hello World'\n"
384 " - Useful for cleaning poorly formatted XML\n"
385 " - May affect intentional multi-spacing\n\n"
386 "EXAMPLES:\n\n"
387 "Value: name=' Patrol Enemy '\n"
388 " - PRESERVE: ' Patrol Enemy '\n"
389 " - TRIM: 'Patrol Enemy'\n"
390 " - NORMALIZE: 'Patrol Enemy'\n\n"
391 "Value: name='Move To Target'\n"
392 " - PRESERVE: 'Move To Target'\n"
393 " - TRIM: 'Move To Target'\n"
394 " - NORMALIZE: 'Move To Target'\n\n"
395 "RECOMMENDATION:\n"
396 "Use TRIM for clean, consistent parsing that handles\n"
397 "formatting variations without losing meaningful content.";
398 HelpDialog dlg(this, "Whitespace Handling - Help", helpText);
399 dlg.ShowModal();
400 });
401 labelSizer5->Add(infoBtn5, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
402 labelSizer5->Add(new wxStaticText(panel, wxID_ANY, "Whitespace Handling:"), 0, wxALIGN_CENTER_VERTICAL);
403 sizer->Add(labelSizer5, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
404
405 wxArrayString whitespaceChoices;
406 whitespaceChoices.Add("Preserve");
407 whitespaceChoices.Add("Trim");
408 whitespaceChoices.Add("Normalize");
409 m_whitespaceHandling = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, whitespaceChoices);
410 m_whitespaceHandling->SetSelection(1); // Trim by default
411 m_whitespaceHandling->SetToolTip("How to process spaces/tabs/newlines (Trim recommended)");
412 sizer->Add(m_whitespaceHandling, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
413 row++;
414
415 // Naming Convention
416 wxBoxSizer *namingSizer = new wxBoxSizer(wxHORIZONTAL);
417
418 wxBitmapButton *infoBtn6 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
419 wxBORDER_NONE | wxBU_EXACTFIT);
420 infoBtn6->SetBitmapHover(infoHover);
421 infoBtn6->SetBitmapPressed(infoPressed);
422 infoBtn6->SetBitmapDisabled(infoDisabled);
423 infoBtn6->SetToolTip("Click for detailed information");
424 infoBtn6->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
425 wxString helpText = "NAMING CONVENTION\n"
426 "===========================================================\n\n"
427 "Controls how strictly element and attribute naming rules are enforced.\n"
428 "When you switch conventions, all fields are immediately re-validated\n"
429 "and invalid names are highlighted with a pulsing yellow background.\n\n"
430 "===========================================================\n\n"
431 "STRICT MODE:\n"
432 " Allowed: Letters (a-z, A-Z) and underscores (_) ONLY\n"
433 " Not allowed: Numbers, hyphens, dots, or any special characters\n"
434 " Must start with: Letter or underscore\n"
435 " \n"
436 " Use for: Maximum safety and consistency\n"
437 " Best for: Production environments, strict standards\n\n"
438 "===========================================================\n\n"
439 "BALANCED MODE (Recommended):\n"
440 " Allowed: Letters, underscores, digits (0-9), and hyphens (-)\n"
441 " Not allowed: Dots, spaces, or other special characters\n"
442 " Must start with: Letter or underscore (NOT a number)\n"
443 " \n"
444 " Use for: Most projects - flexible yet safe\n"
445 " Best for: Standard behavior tree projects\n\n"
446 "===========================================================\n\n"
447 "LOOSE MODE:\n"
448 " Allowed: Most characters that don't break XML\n"
449 " Includes: Letters, digits, underscores, hyphens, dots, colons\n"
450 " Not allowed: <, >, &, quotes, spaces, brackets, and other\n"
451 " XML-breaking characters\n"
452 " Must start with: Letter, underscore, or colon\n"
453 " \n"
454 " Use for: Legacy XML files, maximum compatibility\n"
455 " Best for: Working with existing/legacy systems\n\n"
456 "===========================================================\n\n"
457 "EXAMPLES:\n\n"
458 "Name: 'MyAction' All modes accept\n"
459 "Name: 'My_Action' All modes accept\n"
460 "Name: 'My-Action' STRICT rejects | BALANCED/LOOSE accept\n"
461 "Name: 'MyAction123' STRICT rejects | BALANCED/LOOSE accept\n"
462 "Name: 'My.Action' STRICT/BALANCED reject | LOOSE accepts\n"
463 "Name: 'My:Action' STRICT/BALANCED reject | LOOSE accepts\n"
464 "Name: '123Action' STRICT/BALANCED reject | LOOSE rejects\n"
465 "Name: 'My Action' All modes reject (contains space)\n"
466 "Name: 'My<Action>' All modes reject (breaks XML)\n\n"
467 "===========================================================\n\n"
468 "LIVE VALIDATION:\n"
469 " - Switch between conventions to see which fields become invalid\n"
470 " - Invalid fields pulse with yellow highlighting\n"
471 " - Fix invalid names before saving your configuration\n\n"
472 "RECOMMENDATION:\n"
473 "Start with BALANCED - it provides excellent validation while\n"
474 "supporting common naming patterns like 'Action-Name' and 'Node123'.\n"
475 "Use STRICT for maximum safety or LOOSE for legacy compatibility.";
476 HelpDialog dlg(this, "Naming Convention - Help", helpText);
477 dlg.ShowModal();
478 });
479 namingSizer->Add(infoBtn6, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
480 namingSizer->Add(new wxStaticText(panel, wxID_ANY, "Naming Convention:"), 0, wxALIGN_CENTER_VERTICAL);
481 sizer->Add(namingSizer, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
482
483 // Create a horizontal box for the three checkboxes with labels below
484 wxBoxSizer *checkboxesSizer = new wxBoxSizer(wxHORIZONTAL);
485
486 // Strict checkbox with label
487 wxBoxSizer *strictSizer = new wxBoxSizer(wxVERTICAL);
488 m_namingConventionStrict = new wxCheckBox(panel, wxID_ANY, "");
489 m_namingConventionStrict->SetToolTip("Strict naming validation");
490 strictSizer->Add(m_namingConventionStrict, 0, wxALIGN_CENTER_HORIZONTAL);
491 strictSizer->Add(new wxStaticText(panel, wxID_ANY, "Strict"), 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, 2);
492 checkboxesSizer->Add(strictSizer, 0, wxRIGHT, 15);
493
494 // Balanced checkbox with label
495 wxBoxSizer *balancedSizer = new wxBoxSizer(wxVERTICAL);
496 m_namingConventionBalanced = new wxCheckBox(panel, wxID_ANY, "");
497 m_namingConventionBalanced->SetToolTip("Balanced naming validation (recommended)");
498 balancedSizer->Add(m_namingConventionBalanced, 0, wxALIGN_CENTER_HORIZONTAL);
499 balancedSizer->Add(new wxStaticText(panel, wxID_ANY, "Balanced"), 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, 2);
500 checkboxesSizer->Add(balancedSizer, 0, wxRIGHT, 15);
501
502 // Loose checkbox with label
503 wxBoxSizer *looseSizer = new wxBoxSizer(wxVERTICAL);
504 m_namingConventionLoose = new wxCheckBox(panel, wxID_ANY, "");
505 m_namingConventionLoose->SetToolTip("Loose naming validation");
506 looseSizer->Add(m_namingConventionLoose, 0, wxALIGN_CENTER_HORIZONTAL);
507 looseSizer->Add(new wxStaticText(panel, wxID_ANY, "Loose"), 0, wxALIGN_CENTER_HORIZONTAL | wxTOP, 2);
508 checkboxesSizer->Add(looseSizer, 0);
509
510 sizer->Add(checkboxesSizer, wxGBPosition(row, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
511 row++;
512
513 // Bind checkbox events to ensure only one is selected at a time
514 // and trigger validation when convention changes
515 m_namingConventionStrict->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) {
516 if (event.IsChecked()) {
517 m_namingConventionBalanced->SetValue(false);
518 m_namingConventionLoose->SetValue(false);
519 }
521 });
522 m_namingConventionBalanced->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) {
523 if (event.IsChecked()) {
524 m_namingConventionStrict->SetValue(false);
525 m_namingConventionLoose->SetValue(false);
526 }
528 });
529 m_namingConventionLoose->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &event) {
530 if (event.IsChecked()) {
531 m_namingConventionStrict->SetValue(false);
532 m_namingConventionBalanced->SetValue(false);
533 }
535 });
536
537 sizer->AddGrowableCol(1);
538 panel->SetSizer(sizer);
539 return panel;
540}
541
542wxPanel *ParserConfigDialog::CreateTreeElementsTab(wxNotebook *notebook) {
543 wxPanel *panel = new wxPanel(notebook);
544 wxGridBagSizer *sizer = new wxGridBagSizer(5, 5);
545
546 // Load info button bitmaps
547 wxBitmap infoNormal(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
548 wxBitmap infoHover(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
549 wxBitmap infoPressed(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
550 wxBitmap infoDisabled(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
551
552 int row = 0;
553
554 // Behavior tree element
555 wxBoxSizer *labelSizer1 = new wxBoxSizer(wxHORIZONTAL);
556 wxBitmapButton *infoBtn1 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
557 wxBORDER_NONE | wxBU_EXACTFIT);
558 infoBtn1->SetBitmapHover(infoHover);
559 infoBtn1->SetBitmapPressed(infoPressed);
560 infoBtn1->SetBitmapDisabled(infoDisabled);
561 infoBtn1->SetToolTip("Click for detailed information");
562 infoBtn1->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
563 wxString helpText = "BEHAVIOR TREE ELEMENT\n"
564 "===========================================================\n\n"
565 "WHAT IS IT?\n"
566 "The XML element name that represents a behavior tree definition\n"
567 "in your XML file. This is the main container for each tree.\n\n"
568 "COMMON VALUES:\n"
569 " - 'BehaviorTree' - Standard BehaviorTree.CPP format\n"
570 " - 'Tree' - Simplified/custom format\n"
571 " - 'btree' - Alternative naming\n\n"
572 "HOW IT WORKS:\n"
573 "The parser scans your XML looking for elements with this exact name.\n"
574 "Each matching element is treated as a separate behavior tree definition.\n\n"
575 "EXAMPLE:\n"
576 " <root>\n"
577 " <BehaviorTree ID=\"MainTree\">\n"
578 " <Sequence>\n"
579 " <Action name=\"DoSomething\"/>\n"
580 " </Sequence>\n"
581 " </BehaviorTree>\n"
582 " </root>\n\n"
583 "IMPORTANT:\n"
584 " - Name must match EXACTLY (case-sensitive if enabled)\n"
585 " - All your behavior trees must use this element name\n"
586 " - Typical values: 'BehaviorTree', 'Tree', or custom names";
587 HelpDialog dlg(this, "Behavior Tree Element - Help", helpText);
588 dlg.ShowModal();
589 });
590 labelSizer1->Add(infoBtn1, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
591 labelSizer1->Add(new wxStaticText(panel, wxID_ANY, "Behavior Tree Element:"), 0, wxALIGN_CENTER_VERTICAL);
592 sizer->Add(labelSizer1, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
593 m_behaviorTreeElement = new wxTextCtrl(panel, wxID_ANY);
594 m_behaviorTreeElement->SetToolTip("Element name for behavior trees (e.g., 'BehaviorTree')");
596 sizer->Add(m_behaviorTreeElement, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
597 row++;
598
599 // Tree ID attribute
600 wxBoxSizer *labelSizer2 = new wxBoxSizer(wxHORIZONTAL);
601 wxBitmapButton *infoBtn2 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
602 wxBORDER_NONE | wxBU_EXACTFIT);
603 infoBtn2->SetBitmapHover(infoHover);
604 infoBtn2->SetBitmapPressed(infoPressed);
605 infoBtn2->SetBitmapDisabled(infoDisabled);
606 infoBtn2->SetToolTip("Click for detailed information");
607 infoBtn2->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
608 wxString helpText = "TREE ID ATTRIBUTE\n"
609 "===========================================================\n\n"
610 "WHAT IS IT?\n"
611 "The XML attribute name that contains the unique identifier for\n"
612 "each behavior tree in your file.\n\n"
613 "COMMON VALUES:\n"
614 " - 'ID' - Standard BehaviorTree.CPP format (most common)\n"
615 " - 'name' - Alternative naming convention\n"
616 " - 'id' - Lowercase variant\n"
617 " - 'tree_id' - Explicit naming\n\n"
618 "WHY DO YOU NEED IT?\n"
619 "The ID serves multiple critical purposes:\n"
620 " - Uniquely identifies each behavior tree\n"
621 " - Enables subtree references (one tree calling another)\n"
622 " - Supports multiple trees in a single XML file\n"
623 " - Used by the main tree attribute to specify entry point\n\n"
624 "EXAMPLE:\n"
625 " <BehaviorTree ID=\"MainTree\">\n"
626 " <SubTree ID=\"PatrolBehavior\"/>\n"
627 " </BehaviorTree>\n"
628 " <BehaviorTree ID=\"PatrolBehavior\">\n"
629 " <!-- This tree can be called by MainTree -->\n"
630 " </BehaviorTree>\n\n"
631 "IMPORTANT:\n"
632 " - Each tree MUST have a unique ID\n"
633 " - IDs are used for subtree references";
634 HelpDialog dlg(this, "Tree ID Attribute - Help", helpText);
635 dlg.ShowModal();
636 });
637 labelSizer2->Add(infoBtn2, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
638 labelSizer2->Add(new wxStaticText(panel, wxID_ANY, "Tree ID Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
639 sizer->Add(labelSizer2, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
640 m_treeIdAttr = new wxTextCtrl(panel, wxID_ANY);
641 m_treeIdAttr->SetToolTip("Attribute name for tree identifier (e.g., 'ID')");
642 m_treeIdAttr->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
643 sizer->Add(m_treeIdAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
644 row++;
645
646 // Allow multiple trees
647 wxBoxSizer *labelSizer3 = new wxBoxSizer(wxHORIZONTAL);
648 wxBitmapButton *infoBtn3 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
649 wxBORDER_NONE | wxBU_EXACTFIT);
650 infoBtn3->SetBitmapHover(infoHover);
651 infoBtn3->SetBitmapPressed(infoPressed);
652 infoBtn3->SetBitmapDisabled(infoDisabled);
653 infoBtn3->SetToolTip("Click for detailed information");
654 infoBtn3->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
655 wxString helpText = "ALLOW MULTIPLE TREES IN FILE\n"
656 "===========================================================\n\n"
657 "Controls whether your XML file can contain multiple behavior tree\n"
658 "definitions or just one.\n\n"
659 "ENABLED (Recommended):\n"
660 " - Multiple <BehaviorTree> elements can exist in one file\n"
661 " - Each tree MUST have a unique ID\n"
662 " - Perfect for organizing related trees together\n"
663 " - Enables subtree references within the same file\n"
664 " - Common in BehaviorTree.CPP and complex AI systems\n\n"
665 "DISABLED:\n"
666 " - Only ONE <BehaviorTree> element allowed per file\n"
667 " - Simpler structure for basic projects\n"
668 " - Parser will REJECT files with multiple trees\n"
669 " - Forces one-tree-per-file organization\n\n"
670 "EXAMPLE (ENABLED):\n"
671 " <root>\n"
672 " <BehaviorTree ID=\"MainAI\">\n"
673 " <SubTree ID=\"Patrol\"/>\n"
674 " </BehaviorTree>\n"
675 " <BehaviorTree ID=\"Patrol\">\n"
676 " <!-- Subtree definition -->\n"
677 " </BehaviorTree>\n"
678 " </root>\n\n"
679 "RECOMMENDATION:\n"
680 "Enable this for flexibility and better tree organization.";
681 HelpDialog dlg(this, "Allow Multiple Trees - Help", helpText);
682 dlg.ShowModal();
683 });
684 labelSizer3->Add(infoBtn3, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
685 m_allowMultipleTrees = new wxCheckBox(panel, wxID_ANY, "Allow Multiple Trees in File");
686 m_allowMultipleTrees->SetToolTip("Whether XML can contain multiple behavior tree definitions");
687 labelSizer3->Add(m_allowMultipleTrees, 0, wxALIGN_CENTER_VERTICAL);
688 sizer->Add(labelSizer3, wxGBPosition(row, 0), wxGBSpan(1, 2));
689 row++;
690
691 // Subtree element
692 wxBoxSizer *labelSizer4 = new wxBoxSizer(wxHORIZONTAL);
693 wxBitmapButton *infoBtn4 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
694 wxBORDER_NONE | wxBU_EXACTFIT);
695 infoBtn4->SetBitmapHover(infoHover);
696 infoBtn4->SetBitmapPressed(infoPressed);
697 infoBtn4->SetBitmapDisabled(infoDisabled);
698 infoBtn4->SetToolTip("Click for detailed information");
699 infoBtn4->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
700 wxString helpText = "SUBTREE ELEMENT\n"
701 "===========================================================\n\n"
702 "WHAT IS IT?\n"
703 "The XML element name that represents a subtree reference - a special\n"
704 "node that calls another behavior tree by its ID.\n\n"
705 "COMMON VALUES:\n"
706 " - 'SubTree' - Standard BehaviorTree.CPP format (recommended)\n"
707 " - 'CallTree' - Alternative naming\n"
708 " - 'TreeReference' - Explicit variant\n"
709 " - 'Include' - Some custom implementations\n\n"
710 "HOW IT WORKS:\n"
711 "When the execution reaches a SubTree node, it:\n"
712 " 1. Pauses the current tree\n"
713 " 2. Executes the referenced tree completely\n"
714 " 3. Returns the referenced tree's result (SUCCESS/FAILURE)\n"
715 " 4. Continues with the current tree\n\n"
716 "EXAMPLE:\n"
717 " <BehaviorTree ID=\"MainAI\">\n"
718 " <Sequence>\n"
719 " <SubTree ID=\"PatrolBehavior\"/>\n"
720 " <Action name=\"Attack\"/>\n"
721 " </Sequence>\n"
722 " </BehaviorTree>\n\n"
723 "BENEFITS:\n"
724 " - Reuse trees in multiple places\n"
725 " - Create modular, maintainable structures\n"
726 " - Break complex behaviors into components";
727 HelpDialog dlg(this, "SubTree Element - Help", helpText);
728 dlg.ShowModal();
729 });
730 labelSizer4->Add(infoBtn4, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
731 labelSizer4->Add(new wxStaticText(panel, wxID_ANY, "SubTree Element:"), 0, wxALIGN_CENTER_VERTICAL);
732 sizer->Add(labelSizer4, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
733 m_subtreeElement = new wxTextCtrl(panel, wxID_ANY);
734 m_subtreeElement->SetToolTip("Element name for subtree references (e.g., 'SubTree')");
736 sizer->Add(m_subtreeElement, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
737 row++;
738
739 // Subtree reference attribute
740 wxBoxSizer *labelSizer5 = new wxBoxSizer(wxHORIZONTAL);
741 wxBitmapButton *infoBtn5 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
742 wxBORDER_NONE | wxBU_EXACTFIT);
743 infoBtn5->SetBitmapHover(infoHover);
744 infoBtn5->SetBitmapPressed(infoPressed);
745 infoBtn5->SetBitmapDisabled(infoDisabled);
746 infoBtn5->SetToolTip("Click for detailed information");
747 infoBtn5->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
748 wxString helpText = "SUBTREE REFERENCE ATTRIBUTE\n"
749 "===========================================================\n\n"
750 "WHAT IS IT?\n"
751 "The XML attribute name on a SubTree node that contains the ID of\n"
752 "the behavior tree being referenced/called.\n\n"
753 "COMMON VALUES:\n"
754 " - 'ID' - Standard BehaviorTree.CPP format (most common)\n"
755 " - 'treeID' - Explicit variant\n"
756 " - 'ref' - Short form\n"
757 " - 'tree' - Simple naming\n\n"
758 "HOW IT WORKS:\n"
759 "When the parser encounters a SubTree node:\n"
760 " 1. Reads this attribute to get the referenced tree ID\n"
761 " 2. Searches for a BehaviorTree with matching ID\n"
762 " 3. Links them together for execution\n"
763 " 4. Validates that the reference is valid\n\n"
764 "EXAMPLE:\n"
765 " <BehaviorTree ID=\"MainAI\">\n"
766 " <SubTree ID=\"PatrolBehavior\"/>\n"
767 " ^^^^^^^^^^^^^^^^^^^^^\n"
768 " This attribute references another tree\n"
769 " </BehaviorTree>\n\n"
770 "IMPORTANT:\n"
771 " - Should typically MATCH your Tree ID Attribute setting\n"
772 " - Referenced tree must exist in the same or loaded files\n"
773 " - Parser validates references during loading";
774 HelpDialog dlg(this, "SubTree Reference Attribute - Help", helpText);
775 dlg.ShowModal();
776 });
777 labelSizer5->Add(infoBtn5, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
778 labelSizer5->Add(new wxStaticText(panel, wxID_ANY, "SubTree Reference Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
779 sizer->Add(labelSizer5, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
780 m_subtreeRefAttr = new wxTextCtrl(panel, wxID_ANY);
781 m_subtreeRefAttr->SetToolTip("Attribute containing referenced tree ID (e.g., 'ID')");
783 sizer->Add(m_subtreeRefAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
784 row++;
785
786 // Validate structure
787 wxBoxSizer *labelSizer6 = new wxBoxSizer(wxHORIZONTAL);
788 wxBitmapButton *infoBtn6 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
789 wxBORDER_NONE | wxBU_EXACTFIT);
790 infoBtn6->SetBitmapHover(infoHover);
791 infoBtn6->SetBitmapPressed(infoPressed);
792 infoBtn6->SetBitmapDisabled(infoDisabled);
793 infoBtn6->SetToolTip("Click for detailed information");
794 infoBtn6->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
795 wxString helpText = "VALIDATE TREE STRUCTURE\n"
796 "===========================================================\n\n"
797 "Enables comprehensive structural validation to ensure your behavior\n"
798 "trees follow proper hierarchical and semantic rules.\n\n"
799 "ENABLED (Recommended):\n"
800 " The parser performs these critical checks:\n"
801 " - Control nodes (Sequence, Selector, etc.) have at least one child\n"
802 " - Decorator nodes have EXACTLY one child\n"
803 " - Action/Condition nodes have NO children\n"
804 " - No circular subtree references (A->B->A)\n"
805 " - All node types are properly nested\n"
806 " - Tree structure matches behavior tree semantics\n\n"
807 "DISABLED:\n"
808 " - No structural validation performed\n"
809 " - Faster parsing (minimal performance gain)\n"
810 " - MAY allow invalid trees that crash at runtime\n"
811 " - Use ONLY if you're 100% certain trees are valid\n\n"
812 "BENEFITS OF ENABLING:\n"
813 " - Catches errors EARLY during file loading\n"
814 " - Prevents mysterious runtime crashes\n"
815 " - Provides CLEAR, actionable error messages\n"
816 " - Saves debugging time\n\n"
817 "RECOMMENDATION:\n"
818 "Keep this ENABLED, especially during development!";
819 HelpDialog dlg(this, "Validate Tree Structure - Help", helpText);
820 dlg.ShowModal();
821 });
822 labelSizer6->Add(infoBtn6, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
823 m_validateStructure = new wxCheckBox(panel, wxID_ANY, "Validate Tree Structure");
824 m_validateStructure->SetToolTip("Perform structural validation on parsed trees");
825 labelSizer6->Add(m_validateStructure, 0, wxALIGN_CENTER_VERTICAL);
826 sizer->Add(labelSizer6, wxGBPosition(row, 0), wxGBSpan(1, 2));
827 row++;
828
829 // Require root node
830 wxBoxSizer *labelSizer7 = new wxBoxSizer(wxHORIZONTAL);
831 wxBitmapButton *infoBtn7 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
832 wxBORDER_NONE | wxBU_EXACTFIT);
833 infoBtn7->SetBitmapHover(infoHover);
834 infoBtn7->SetBitmapPressed(infoPressed);
835 infoBtn7->SetBitmapDisabled(infoDisabled);
836 infoBtn7->SetToolTip("Click for detailed information");
837 infoBtn7->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
838 wxString helpText = "REQUIRE ROOT NODE\n"
839 "===========================================================\n\n"
840 "Determines whether each behavior tree must have at least one\n"
841 "root node (a direct child of the BehaviorTree element).\n\n"
842 "ENABLED (Recommended):\n"
843 " - Each tree MUST contain at least one root-level node\n"
844 " - Empty trees are REJECTED during parsing\n"
845 " - Ensures all trees are executable and meaningful\n"
846 " - Catches incomplete or placeholder trees\n"
847 " - Standard for production-ready behavior trees\n\n"
848 "DISABLED:\n"
849 " - Empty trees are ALLOWED (no root node required)\n"
850 " - Useful for template/stub trees during development\n"
851 " - May allow non-functional tree structures\n"
852 " - Could lead to runtime issues if tree is called\n\n"
853 "EXAMPLE (VALID - with root):\n"
854 " <BehaviorTree ID=\"MainTree\">\n"
855 " <Sequence> <!-- ROOT NODE (direct child) -->\n"
856 " <Action name=\"DoSomething\"/>\n"
857 " </Sequence>\n"
858 " </BehaviorTree>\n\n"
859 "EXAMPLE (INVALID - no root):\n"
860 " <BehaviorTree ID=\"EmptyTree\">\n"
861 " <!-- No nodes! -->\n"
862 " </BehaviorTree>\n\n"
863 "RECOMMENDATION:\n"
864 "Keep ENABLED to ensure all trees are complete and executable!";
865 HelpDialog dlg(this, "Require Root Node - Help", helpText);
866 dlg.ShowModal();
867 });
868 labelSizer7->Add(infoBtn7, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
869 m_requireRootNode = new wxCheckBox(panel, wxID_ANY, "Require Root Node");
870 m_requireRootNode->SetToolTip("Each tree must have at least one root node");
871 labelSizer7->Add(m_requireRootNode, 0, wxALIGN_CENTER_VERTICAL);
872 sizer->Add(labelSizer7, wxGBPosition(row, 0), wxGBSpan(1, 2));
873 row++;
874
875 sizer->AddGrowableCol(1);
876 panel->SetSizer(sizer);
877 return panel;
878}
879
880wxPanel *ParserConfigDialog::CreateNodeElementsTab(wxNotebook *notebook) {
881 wxPanel *panel = new wxPanel(notebook);
882 wxGridBagSizer *sizer = new wxGridBagSizer(5, 5);
883
884 // Load info button bitmaps
885 wxBitmap infoNormal(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
886 wxBitmap infoHover(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
887 wxBitmap infoPressed(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
888 wxBitmap infoDisabled(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
889
890 int row = 0;
891
892 // Control element
893 wxBoxSizer *labelSizer1 = new wxBoxSizer(wxHORIZONTAL);
894 wxBitmapButton *infoBtn1 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
895 wxBORDER_NONE | wxBU_EXACTFIT);
896 infoBtn1->SetBitmapHover(infoHover);
897 infoBtn1->SetBitmapPressed(infoPressed);
898 infoBtn1->SetBitmapDisabled(infoDisabled);
899 infoBtn1->SetToolTip("Click for detailed information");
900 infoBtn1->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
901 wxString helpText = "CONTROL NODE ELEMENT\n"
902 "===========================================================\n\n"
903 "WHAT IS IT?\n"
904 "The XML element name that represents control flow nodes - nodes that\n"
905 "control the execution order and logic of their children.\n\n"
906 "COMMON VALUES:\n"
907 " - 'Control' - Generic control node element\n"
908 " - Leave empty to use specific names (Sequence, Selector, etc.)\n\n"
909 "CONTROL NODE TYPES:\n"
910 "Control nodes determine HOW and WHEN child nodes execute:\n"
911 " - Sequence: Execute children in order until one fails\n"
912 " - Selector/Fallback: Execute children until one succeeds\n"
913 " - Parallel: Execute multiple children simultaneously\n"
914 " - Random: Execute children in random order\n\n"
915 "HOW IT WORKS:\n"
916 "If set to 'Control':\n"
917 " <Control type=\"Sequence\">\n"
918 " <Action name=\"Step1\"/>\n"
919 " <Action name=\"Step2\"/>\n"
920 " </Control>\n\n"
921 "If left empty (common in BehaviorTree.CPP):\n"
922 " <Sequence> <!-- Direct element name -->\n"
923 " <Action name=\"Step1\"/>\n"
924 " </Sequence>\n\n"
925 "RECOMMENDATION:\n"
926 "For BehaviorTree.CPP compatibility, leave empty and use\n"
927 "specific element names like <Sequence>, <Selector>, etc.";
928 HelpDialog dlg(this, "Control Node Element - Help", helpText);
929 dlg.ShowModal();
930 });
931 labelSizer1->Add(infoBtn1, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
932 labelSizer1->Add(new wxStaticText(panel, wxID_ANY, "Control Node Element:"), 0, wxALIGN_CENTER_VERTICAL);
933 sizer->Add(labelSizer1, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
934 m_controlElement = new wxTextCtrl(panel, wxID_ANY);
935 m_controlElement->SetToolTip("Element name for control nodes (e.g., 'Control')");
937 sizer->Add(m_controlElement, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
938 row++;
939
940 // Action element
941 wxBoxSizer *labelSizer2 = new wxBoxSizer(wxHORIZONTAL);
942 wxBitmapButton *infoBtn2 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
943 wxBORDER_NONE | wxBU_EXACTFIT);
944 infoBtn2->SetBitmapHover(infoHover);
945 infoBtn2->SetBitmapPressed(infoPressed);
946 infoBtn2->SetBitmapDisabled(infoDisabled);
947 infoBtn2->SetToolTip("Click for detailed information");
948 infoBtn2->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
949 wxString helpText = "ACTION NODE ELEMENT\n"
950 "===========================================================\n\n"
951 "WHAT IS IT?\n"
952 "The XML element name that represents action nodes - nodes that\n"
953 "perform actual tasks or operations in your behavior tree.\n\n"
954 "COMMON VALUES:\n"
955 " - 'Action' - Standard BehaviorTree.CPP format\n"
956 " - 'Task' - Alternative naming\n"
957 " - 'Do' - Simple variant\n\n"
958 "WHAT ARE ACTION NODES?\n"
959 "Actions are the LEAF NODES that do the actual work:\n"
960 " - Move to a position\n"
961 " - Play an animation\n"
962 " - Attack an enemy\n"
963 " - Wait for a duration\n"
964 " - Set a variable\n\n"
965 "CHARACTERISTICS:\n"
966 " - Have NO children (leaf nodes)\n"
967 " - Return SUCCESS, FAILURE, or RUNNING\n"
968 " - Contain the actual executable logic\n"
969 " - May take parameters via attributes\n\n"
970 "EXAMPLE:\n"
971 " <BehaviorTree ID=\"PatrolAI\">\n"
972 " <Sequence>\n"
973 " <Action name=\"MoveToWaypoint\"/>\n"
974 " <Action name=\"Wait\" duration=\"2.0\"/>\n"
975 " <Action name=\"LookAround\"/>\n"
976 " </Sequence>\n"
977 " </BehaviorTree>\n\n"
978 "RECOMMENDATION:\n"
979 "Use 'Action' for standard BehaviorTree.CPP compatibility.";
980 HelpDialog dlg(this, "Action Node Element - Help", helpText);
981 dlg.ShowModal();
982 });
983 labelSizer2->Add(infoBtn2, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
984 labelSizer2->Add(new wxStaticText(panel, wxID_ANY, "Action Node Element:"), 0, wxALIGN_CENTER_VERTICAL);
985 sizer->Add(labelSizer2, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
986 m_actionElement = new wxTextCtrl(panel, wxID_ANY);
987 m_actionElement->SetToolTip("Element name for action nodes (e.g., 'Action')");
988 m_actionElement->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
989 sizer->Add(m_actionElement, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
990 row++;
991
992 // Condition element
993 wxBoxSizer *labelSizer3 = new wxBoxSizer(wxHORIZONTAL);
994 wxBitmapButton *infoBtn3 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
995 wxBORDER_NONE | wxBU_EXACTFIT);
996 infoBtn3->SetBitmapHover(infoHover);
997 infoBtn3->SetBitmapPressed(infoPressed);
998 infoBtn3->SetBitmapDisabled(infoDisabled);
999 infoBtn3->SetToolTip("Click for detailed information");
1000 infoBtn3->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1001 wxString helpText = "CONDITION NODE ELEMENT\n"
1002 "===========================================================\n\n"
1003 "WHAT IS IT?\n"
1004 "The XML element name that represents condition nodes - nodes that\n"
1005 "check/test a state and return SUCCESS or FAILURE immediately.\n\n"
1006 "COMMON VALUES:\n"
1007 " - 'Condition' - Standard BehaviorTree.CPP format\n"
1008 " - 'Check' - Alternative naming\n"
1009 " - 'Test' - Some implementations\n\n"
1010 "WHAT ARE CONDITION NODES?\n"
1011 "Conditions are LEAF NODES that perform instant checks:\n"
1012 " - Is enemy in range?\n"
1013 " - Is health below 50%?\n"
1014 " - Is door open?\n"
1015 " - Has item in inventory?\n"
1016 " - Is time > X?\n\n"
1017 "KEY CHARACTERISTICS:\n"
1018 " - Have NO children (leaf nodes)\n"
1019 " - Execute INSTANTLY (never return RUNNING)\n"
1020 " - Return only SUCCESS or FAILURE\n"
1021 " - Used for decision-making logic\n"
1022 " - Often used with Selectors for branching\n\n"
1023 "EXAMPLE:\n"
1024 " <Selector>\n"
1025 " <Sequence>\n"
1026 " <Condition name=\"IsEnemyClose\"/>\n"
1027 " <Action name=\"Attack\"/>\n"
1028 " </Sequence>\n"
1029 " <Action name=\"Patrol\"/>\n"
1030 " </Selector>\n\n"
1031 "RECOMMENDATION:\n"
1032 "Use 'Condition' for standard BehaviorTree.CPP compatibility.";
1033 HelpDialog dlg(this, "Condition Node Element - Help", helpText);
1034 dlg.ShowModal();
1035 });
1036 labelSizer3->Add(infoBtn3, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1037 labelSizer3->Add(new wxStaticText(panel, wxID_ANY, "Condition Node Element:"), 0, wxALIGN_CENTER_VERTICAL);
1038 sizer->Add(labelSizer3, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1039 m_conditionElement = new wxTextCtrl(panel, wxID_ANY);
1040 m_conditionElement->SetToolTip("Element name for condition nodes (e.g., 'Condition')");
1042 sizer->Add(m_conditionElement, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1043 row++;
1044
1045 // Decorator element
1046 wxBoxSizer *labelSizer4 = new wxBoxSizer(wxHORIZONTAL);
1047 wxBitmapButton *infoBtn4 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1048 wxBORDER_NONE | wxBU_EXACTFIT);
1049 infoBtn4->SetBitmapHover(infoHover);
1050 infoBtn4->SetBitmapPressed(infoPressed);
1051 infoBtn4->SetBitmapDisabled(infoDisabled);
1052 infoBtn4->SetToolTip("Click for detailed information");
1053 infoBtn4->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1054 wxString helpText = "DECORATOR NODE ELEMENT\n"
1055 "===========================================================\n\n"
1056 "WHAT IS IT?\n"
1057 "The XML element name that represents decorator nodes - nodes that\n"
1058 "modify or enhance the behavior of EXACTLY ONE child node.\n\n"
1059 "COMMON VALUES:\n"
1060 " - 'Decorator' - Generic decorator element\n"
1061 " - Leave empty to use specific names (Inverter, Retry, etc.)\n\n"
1062 "WHAT ARE DECORATOR NODES?\n"
1063 "Decorators WRAP a single child and modify its behavior:\n"
1064 " - Inverter: Flip SUCCESS <-> FAILURE\n"
1065 " - Retry: Repeat child until success (N times)\n"
1066 " - Repeat: Execute child multiple times\n"
1067 " - Force Success/Failure: Override child's result\n"
1068 " - Timeout: Fail child if it takes too long\n"
1069 " - Delay: Wait before executing child\n\n"
1070 "KEY CHARACTERISTICS:\n"
1071 " - Must have EXACTLY ONE child\n"
1072 " - Act as a wrapper/modifier\n"
1073 " - Don't change the tree structure\n"
1074 " - Commonly used for logic inversion and retries\n\n"
1075 "EXAMPLE:\n"
1076 " <Sequence>\n"
1077 " <Inverter> <!-- Decorator: flips result -->\n"
1078 " <Condition name=\"IsEnemyClose\"/>\n"
1079 " </Inverter>\n"
1080 " <Action name=\"Patrol\"/>\n"
1081 " </Sequence>\n\n"
1082 "RECOMMENDATION:\n"
1083 "Leave empty and use specific names like <Inverter>, <Retry>.";
1084 HelpDialog dlg(this, "Decorator Node Element - Help", helpText);
1085 dlg.ShowModal();
1086 });
1087 labelSizer4->Add(infoBtn4, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1088 labelSizer4->Add(new wxStaticText(panel, wxID_ANY, "Decorator Node Element:"), 0, wxALIGN_CENTER_VERTICAL);
1089 sizer->Add(labelSizer4, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1090 m_decoratorElement = new wxTextCtrl(panel, wxID_ANY);
1091 m_decoratorElement->SetToolTip("Element name for decorator nodes (e.g., 'Decorator')");
1093 sizer->Add(m_decoratorElement, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1094 row++;
1095
1096 // Generic node element
1097 wxBoxSizer *labelSizer5 = new wxBoxSizer(wxHORIZONTAL);
1098 wxBitmapButton *infoBtn5 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1099 wxBORDER_NONE | wxBU_EXACTFIT);
1100 infoBtn5->SetBitmapHover(infoHover);
1101 infoBtn5->SetBitmapPressed(infoPressed);
1102 infoBtn5->SetBitmapDisabled(infoDisabled);
1103 infoBtn5->SetToolTip("Click for detailed information");
1104 infoBtn5->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1105 wxString helpText = "GENERIC NODE ELEMENT\n"
1106 "===========================================================\n\n"
1107 "WHAT IS IT?\n"
1108 "A fallback element name used when a node doesn't match any\n"
1109 "of the specific node type elements (Control, Action, etc.).\n\n"
1110 "COMMON VALUES:\n"
1111 " - 'Node' - Simple generic name\n"
1112 " - Leave empty if not needed\n\n"
1113 "WHEN IS IT USED?\n"
1114 "This acts as a catch-all for nodes that don't fit standard categories:\n"
1115 " - Custom node types specific to your implementation\n"
1116 " - Experimental or plugin nodes\n"
1117 " - Nodes that need runtime type determination\n\n"
1118 "HOW IT WORKS:\n"
1119 "Parser checks elements in this order:\n"
1120 " 1. Is it a Control node? (e.g., <Sequence>)\n"
1121 " 2. Is it an Action node? (e.g., <Action>)\n"
1122 " 3. Is it a Condition node? (e.g., <Condition>)\n"
1123 " 4. Is it a Decorator node? (e.g., <Inverter>)\n"
1124 " 5. Is it the Generic element? (e.g., <Node>)\n"
1125 " 6. Unknown element (error or ignored)\n\n"
1126 "EXAMPLE:\n"
1127 " <Node type=\"CustomPlugin\" name=\"SpecialBehavior\">\n"
1128 " <!-- Custom implementation -->\n"
1129 " </Node>\n\n"
1130 "RECOMMENDATION:\n"
1131 "Leave empty unless you have custom node types that don't\n"
1132 "fit the standard categories.";
1133 HelpDialog dlg(this, "Generic Node Element - Help", helpText);
1134 dlg.ShowModal();
1135 });
1136 labelSizer5->Add(infoBtn5, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1137 labelSizer5->Add(new wxStaticText(panel, wxID_ANY, "Generic Node Element:"), 0, wxALIGN_CENTER_VERTICAL);
1138 sizer->Add(labelSizer5, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1139 m_genericNodeElement = new wxTextCtrl(panel, wxID_ANY);
1140 m_genericNodeElement->SetToolTip("Fallback element name for generic nodes (e.g., 'Node')");
1142 sizer->Add(m_genericNodeElement, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1143 row++;
1144
1145 // Node ID attribute
1146 wxBoxSizer *labelSizer6 = new wxBoxSizer(wxHORIZONTAL);
1147 wxBitmapButton *infoBtn6 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1148 wxBORDER_NONE | wxBU_EXACTFIT);
1149 infoBtn6->SetBitmapHover(infoHover);
1150 infoBtn6->SetBitmapPressed(infoPressed);
1151 infoBtn6->SetBitmapDisabled(infoDisabled);
1152 infoBtn6->SetToolTip("Click for detailed information");
1153 infoBtn6->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1154 wxString helpText = "NODE ID ATTRIBUTE\n"
1155 "===========================================================\n\n"
1156 "WHAT IS IT?\n"
1157 "The XML attribute name that identifies the specific TYPE or\n"
1158 "CLASS of a node (e.g., 'Sequence', 'MoveToTarget', 'IsHealthLow').\n\n"
1159 "COMMON VALUES:\n"
1160 " - 'ID' - BehaviorTree.CPP standard\n"
1161 " - 'type' - Alternative common usage\n"
1162 " - 'class' - Some implementations\n\n"
1163 "WHAT DOES IT CONTAIN?\n"
1164 "The ID typically specifies the node's TYPE/CLASS:\n"
1165 " - For Control: 'Sequence', 'Selector', 'Parallel'\n"
1166 " - For Action: 'MoveToTarget', 'Attack', 'PlayAnimation'\n"
1167 " - For Condition: 'IsHealthLow', 'IsEnemyNear'\n"
1168 " - For Decorator: 'Inverter', 'Retry', 'Timeout'\n\n"
1169 "EXAMPLE (using ID='type'):\n"
1170 " <Control ID=\"Sequence\">\n"
1171 " <Action ID=\"MoveToWaypoint\" target=\"wp1\"/>\n"
1172 " <Action ID=\"Wait\" duration=\"2.0\"/>\n"
1173 " </Control>\n\n"
1174 "vs EXAMPLE (element name is type):\n"
1175 " <Sequence>\n"
1176 " <MoveToWaypoint target=\"wp1\"/>\n"
1177 " <Wait duration=\"2.0\"/>\n"
1178 " </Sequence>\n\n"
1179 "RECOMMENDATION:\n"
1180 "Use 'ID' for BehaviorTree.CPP compatibility when using\n"
1181 "generic element names. Leave empty if using specific\n"
1182 "element names for each node type.";
1183 HelpDialog dlg(this, "Node ID Attribute - Help", helpText);
1184 dlg.ShowModal();
1185 });
1186 labelSizer6->Add(infoBtn6, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1187 labelSizer6->Add(new wxStaticText(panel, wxID_ANY, "Node ID Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
1188 sizer->Add(labelSizer6, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1189 m_nodeIdAttr = new wxTextCtrl(panel, wxID_ANY);
1190 m_nodeIdAttr->SetToolTip("Attribute name for node identifier/type (e.g., 'ID')");
1191 m_nodeIdAttr->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
1192 sizer->Add(m_nodeIdAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1193 row++;
1194
1195 // Node name attribute
1196 wxBoxSizer *labelSizer7 = new wxBoxSizer(wxHORIZONTAL);
1197 wxBitmapButton *infoBtn7 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1198 wxBORDER_NONE | wxBU_EXACTFIT);
1199 infoBtn7->SetBitmapHover(infoHover);
1200 infoBtn7->SetBitmapPressed(infoPressed);
1201 infoBtn7->SetBitmapDisabled(infoDisabled);
1202 infoBtn7->SetToolTip("Click for detailed information");
1203 infoBtn7->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1204 wxString helpText = "NODE NAME ATTRIBUTE\n"
1205 "===========================================================\n\n"
1206 "WHAT IS IT?\n"
1207 "The XML attribute name that provides a human-readable display\n"
1208 "name or label for a node instance.\n\n"
1209 "COMMON VALUES:\n"
1210 " - 'name' - Most common standard\n"
1211 " - 'label' - Alternative\n"
1212 " - 'displayName' - Explicit variant\n\n"
1213 "WHAT'S THE DIFFERENCE FROM NODE ID?\n"
1214 " - Node ID: The TYPE/CLASS of the node (e.g., 'MoveToTarget')\n"
1215 " - Node Name: A specific INSTANCE label (e.g., 'Move to Enemy')\n\n"
1216 "WHY USE IT?\n"
1217 " - Provide descriptive labels in visual editors\n"
1218 " - Make trees more readable in XML\n"
1219 " - Help with debugging and logging\n"
1220 " - Distinguish between multiple instances of same node type\n\n"
1221 "EXAMPLE:\n"
1222 " <Action ID=\"MoveToTarget\" name=\"Move to Waypoint 1\">\n"
1223 " ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^\n"
1224 " Node type/class Human-readable name\n"
1225 "\n"
1226 " <Action ID=\"MoveToTarget\" name=\"Return to Base\">\n"
1227 " Same type Different instance name\n\n"
1228 "IN VISUAL EDITOR:\n"
1229 "The 'name' would be displayed on the node box, making the\n"
1230 "tree easier to understand at a glance.\n\n"
1231 "RECOMMENDATION:\n"
1232 "Use 'name' for standard compatibility and readability.";
1233 HelpDialog dlg(this, "Node Name Attribute - Help", helpText);
1234 dlg.ShowModal();
1235 });
1236 labelSizer7->Add(infoBtn7, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1237 labelSizer7->Add(new wxStaticText(panel, wxID_ANY, "Node Name Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
1238 sizer->Add(labelSizer7, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1239 m_nodeNameAttr = new wxTextCtrl(panel, wxID_ANY);
1240 m_nodeNameAttr->SetToolTip("Attribute name for node display name (e.g., 'name')");
1241 m_nodeNameAttr->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
1242 sizer->Add(m_nodeNameAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1243 row++;
1244
1245 // Node type attribute
1246 wxBoxSizer *labelSizer8 = new wxBoxSizer(wxHORIZONTAL);
1247 wxBitmapButton *infoBtn8 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1248 wxBORDER_NONE | wxBU_EXACTFIT);
1249 infoBtn8->SetBitmapHover(infoHover);
1250 infoBtn8->SetBitmapPressed(infoPressed);
1251 infoBtn8->SetBitmapDisabled(infoDisabled);
1252 infoBtn8->SetToolTip("Click for detailed information");
1253 infoBtn8->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1254 wxString helpText = "NODE TYPE ATTRIBUTE\n"
1255 "===========================================================\n\n"
1256 "WHAT IS IT?\n"
1257 "An ALTERNATIVE attribute used for by-attribute node classification,\n"
1258 "where node category is specified via attribute instead of element name.\n\n"
1259 "COMMON VALUES:\n"
1260 " - 'type' - Most common\n"
1261 " - 'category' - Alternative\n"
1262 " - 'nodeType' - Explicit variant\n\n"
1263 "WHEN IS THIS USED?\n"
1264 "Some XML formats use a SINGLE generic element with a type attribute\n"
1265 "instead of different elements for each node category:\n\n"
1266 "BY-ELEMENT APPROACH (most common):\n"
1267 " <Sequence>\n"
1268 " <Action name=\"Move\"/>\n"
1269 " <Condition name=\"IsClose\"/>\n"
1270 " </Sequence>\n\n"
1271 "BY-ATTRIBUTE APPROACH:\n"
1272 " <Node type=\"Sequence\">\n"
1273 " <Node type=\"Action\" name=\"Move\"/>\n"
1274 " <Node type=\"Condition\" name=\"IsClose\"/>\n"
1275 " </Node>\n"
1276 " ^^^^^^^^^^^^^^\n"
1277 " This attribute specifies node category\n\n"
1278 "ATTRIBUTE VALUES:\n"
1279 " - 'Control', 'Action', 'Condition', 'Decorator'\n"
1280 " - Used by parser to classify nodes\n\n"
1281 "RECOMMENDATION:\n"
1282 "Only use this if your XML format uses by-attribute\n"
1283 "classification. Leave empty for standard element-based\n"
1284 "classification (BehaviorTree.CPP style).";
1285 HelpDialog dlg(this, "Node Type Attribute - Help", helpText);
1286 dlg.ShowModal();
1287 });
1288 labelSizer8->Add(infoBtn8, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1289 labelSizer8->Add(new wxStaticText(panel, wxID_ANY, "Node Type Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
1290 sizer->Add(labelSizer8, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1291 m_nodeTypeAttr = new wxTextCtrl(panel, wxID_ANY);
1292 m_nodeTypeAttr->SetToolTip("Attribute name for node type (used in by-attribute classification)");
1293 m_nodeTypeAttr->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
1294 sizer->Add(m_nodeTypeAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1295 row++;
1296
1297 // Allow custom attributes
1298 wxBoxSizer *labelSizer9 = new wxBoxSizer(wxHORIZONTAL);
1299 wxBitmapButton *infoBtn9 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1300 wxBORDER_NONE | wxBU_EXACTFIT);
1301 infoBtn9->SetBitmapHover(infoHover);
1302 infoBtn9->SetBitmapPressed(infoPressed);
1303 infoBtn9->SetBitmapDisabled(infoDisabled);
1304 infoBtn9->SetToolTip("Click for detailed information");
1305 infoBtn9->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1306 wxString helpText = "ALLOW CUSTOM ATTRIBUTES\n"
1307 "===========================================================\n\n"
1308 "Controls whether the parser preserves and stores custom/additional\n"
1309 "attributes found on nodes beyond the standard configuration attributes.\n\n"
1310 "ENABLED (Recommended):\n"
1311 " - ALL attributes on nodes are parsed and stored\n"
1312 " - Custom parameters are preserved for runtime use\n"
1313 " - Enables flexible node parameterization\n"
1314 " - Required for most practical behavior trees\n\n"
1315 "DISABLED:\n"
1316 " - Only recognized/standard attributes are stored\n"
1317 " - Custom attributes are IGNORED during parsing\n"
1318 " - Stricter validation, but less flexible\n"
1319 " - May lose important node parameters\n\n"
1320 "EXAMPLE (custom attributes in bold concept):\n"
1321 " <Action name=\"MoveToTarget\" \n"
1322 " speed=\"5.0\" <!-- Custom attribute -->\n"
1323 " target=\"enemy\" <!-- Custom attribute -->\n"
1324 " acceptableRadius=\"2.0\"> <!-- Custom -->\n\n"
1325 "WHY ENABLE?\n"
1326 " - Actions/Conditions need parameters to work\n"
1327 " - Different node instances need different values\n"
1328 " - Runtime system reads these for behavior\n"
1329 " - Standard in BehaviorTree.CPP and most frameworks\n\n"
1330 "RECOMMENDATION:\n"
1331 "KEEP THIS ENABLED! Most behavior trees require custom\n"
1332 "attributes for node parameters, making trees functional\n"
1333 "and configurable.";
1334 HelpDialog dlg(this, "Allow Custom Attributes - Help", helpText);
1335 dlg.ShowModal();
1336 });
1337 labelSizer9->Add(infoBtn9, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1338 m_allowCustomAttrs = new wxCheckBox(panel, wxID_ANY, "Allow Custom Attributes");
1339 m_allowCustomAttrs->SetToolTip("Parse and store custom attributes on nodes");
1340 labelSizer9->Add(m_allowCustomAttrs, 0, wxALIGN_CENTER_VERTICAL);
1341 sizer->Add(labelSizer9, wxGBPosition(row, 0), wxGBSpan(1, 2));
1342 row++;
1343
1344 sizer->AddGrowableCol(1);
1345 panel->SetSizer(sizer);
1346 return panel;
1347}
1348
1350 wxPanel *panel = new wxPanel(notebook);
1351 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
1352
1353 // Load info button bitmaps
1354 wxBitmap infoNormal(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
1355 wxBitmap infoHover(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
1356 wxBitmap infoPressed(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
1357 wxBitmap infoDisabled(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
1358
1359 // Classification strategy
1360 wxBoxSizer *strategySizer = new wxBoxSizer(wxHORIZONTAL);
1361
1362 wxBitmapButton *infoBtn1 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1363 wxBORDER_NONE | wxBU_EXACTFIT);
1364 infoBtn1->SetBitmapHover(infoHover);
1365 infoBtn1->SetBitmapPressed(infoPressed);
1366 infoBtn1->SetBitmapDisabled(infoDisabled);
1367 infoBtn1->SetToolTip("Click for detailed information");
1368 infoBtn1->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1369 wxString helpText = "CLASSIFICATION STRATEGY\n"
1370 "===========================================================\n\n"
1371 "Determines HOW the parser identifies what type of node it's dealing\n"
1372 "with when reading your XML.\n\n"
1373 "THREE STRATEGIES:\n\n"
1374 "1. BY ELEMENT NAME (Most Common)\n"
1375 " - Node type is determined by the XML element name itself\n"
1376 " - Different elements for different types\n"
1377 " Example:\n"
1378 " <Sequence> <!-- Control node -->\n"
1379 " <Action name=\"Move\"/> <!-- Action node -->\n"
1380 " <Condition name=\"Check\"/> <!-- Condition node -->\n"
1381 " </Sequence>\n"
1382 " Pros: Clean, readable XML; standard in BehaviorTree.CPP\n"
1383 " Use when: You want clear, self-documenting trees\n\n"
1384 "2. BY ATTRIBUTE\n"
1385 " - Single generic element with 'type' attribute\n"
1386 " - All nodes use the same element name\n"
1387 " Example:\n"
1388 " <Node type=\"Sequence\">\n"
1389 " <Node type=\"Action\" name=\"Move\"/>\n"
1390 " <Node type=\"Condition\" name=\"Check\"/>\n"
1391 " </Node>\n"
1392 " Pros: Uniform structure; easier schema validation\n"
1393 " Use when: You need strict XML schema conformance\n\n"
1394 "3. HYBRID\n"
1395 " - Mix of both approaches\n"
1396 " - Checks element name first, falls back to attribute\n"
1397 " Example:\n"
1398 " <Sequence> <!-- By element name -->\n"
1399 " <Node type=\"Action\" name=\"Custom\"/> <!-- By attribute -->\n"
1400 " <Condition name=\"Check\"/> <!-- By element name -->\n"
1401 " </Sequence>\n"
1402 " Pros: Maximum flexibility; supports mixed formats\n"
1403 " Use when: Working with multiple XML formats\n\n"
1404 "RECOMMENDATION:\n"
1405 "Use 'By Element Name' for standard BehaviorTree.CPP compatibility\n"
1406 "and maximum readability.";
1407 HelpDialog dlg(this, "Classification Strategy - Help", helpText);
1408 dlg.ShowModal();
1409 });
1410 strategySizer->Add(infoBtn1, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1411 strategySizer->Add(new wxStaticText(panel, wxID_ANY, "Classification Strategy:"), 0,
1412 wxALIGN_CENTER_VERTICAL | wxALL, 5);
1413 wxArrayString strategyChoices;
1414 strategyChoices.Add("By Element Name");
1415 strategyChoices.Add("By Attribute");
1416 strategyChoices.Add("Hybrid");
1417 m_classificationStrategy = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, strategyChoices);
1418 m_classificationStrategy->SetSelection(0);
1419 strategySizer->Add(m_classificationStrategy, 1, wxALL, 5);
1420 mainSizer->Add(strategySizer, 0, wxEXPAND);
1421
1422 // Type lists section header with info button
1423 wxBoxSizer *listsHeaderSizer = new wxBoxSizer(wxHORIZONTAL);
1424
1425 // Reload bitmaps for this button
1426 wxBitmap infoNormal4(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
1427 wxBitmap infoHover4(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
1428 wxBitmap infoPressed4(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
1429 wxBitmap infoDisabled4(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
1430
1431 wxBitmapButton *infoBtn4 = new wxBitmapButton(panel, wxID_ANY, infoNormal4, wxDefaultPosition, wxSize(40, 40),
1432 wxBORDER_NONE | wxBU_EXACTFIT);
1433 infoBtn4->SetBitmapHover(infoHover4);
1434 infoBtn4->SetBitmapPressed(infoPressed4);
1435 infoBtn4->SetBitmapDisabled(infoDisabled4);
1436 infoBtn4->SetToolTip("Click for detailed information");
1437 infoBtn4->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1438 wxString helpText = "NODE TYPE LISTS\n"
1439 "===========================================================\n\n"
1440 "These lists define the SPECIFIC NODE TYPES recognized in each\n"
1441 "category. Used for element-name and attribute-based classification.\n\n"
1442 "HOW THEY WORK:\n"
1443 "When the parser encounters a node, it checks if the node's name\n"
1444 "(element or attribute value) appears in one of these lists to\n"
1445 "determine its category.\n\n"
1446 "FOUR CATEGORIES:\n\n"
1447 "1. CONTROL TYPES (Required)\n"
1448 " Flow control nodes that manage child execution\n"
1449 " Common examples:\n"
1450 " - Sequence, Selector, Fallback\n"
1451 " - Parallel, ParallelSequence\n"
1452 " - ReactiveSequence, ReactiveFallback\n"
1453 " - IfThenElse, Switch, WhileDoElse\n"
1454 " These nodes MUST have at least one child\n\n"
1455 "2. DECORATOR TYPES (Required)\n"
1456 " Wrapper nodes that modify a single child's behavior\n"
1457 " Common examples:\n"
1458 " - Inverter, ForceSuccess, ForceFailure\n"
1459 " - Retry, Repeat, RepeatUntilSuccess\n"
1460 " - Timeout, Delay\n"
1461 " - KeepRunningUntilFailure\n"
1462 " These nodes MUST have exactly one child\n\n"
1463 "3. ACTION TYPES (Optional)\n"
1464 " Leaf nodes that perform tasks\n"
1465 " Common examples:\n"
1466 " - MoveToTarget, Attack, Wait\n"
1467 " - PlayAnimation, SetBlackboard\n"
1468 " - Custom action nodes\n"
1469 " Leave empty to allow any non-classified leaf as Action\n\n"
1470 "4. CONDITION TYPES (Optional)\n"
1471 " Leaf nodes that check state (instant, no RUNNING)\n"
1472 " Common examples:\n"
1473 " - IsHealthLow, IsEnemyInRange\n"
1474 " - CheckBlackboard, IsBoolTrue\n"
1475 " - Custom condition nodes\n"
1476 " Leave empty to allow any non-classified leaf as Condition\n\n"
1477 "ADDING ENTRIES:\n"
1478 " 1. Click '+' button\n"
1479 " 2. Enter the exact node type name\n"
1480 " 3. Case-sensitive (usually)\n\n"
1481 "EXAMPLE CLASSIFICATION:\n"
1482 " Lists: Control=[Sequence, Selector], Decorator=[Inverter]\n"
1483 " XML: <Sequence> -> Control (in list)\n"
1484 " XML: <Inverter> -> Decorator (in list)\n"
1485 " XML: <CustomAction> -> Action (not in any list)\n\n"
1486 "RECOMMENDATION:\n"
1487 "Always define Control and Decorator types. Leave Action/Condition\n"
1488 "empty for maximum flexibility unless you need strict validation.";
1489 HelpDialog dlg(this, "Node Type Lists - Help", helpText);
1490 dlg.ShowModal();
1491 });
1492 listsHeaderSizer->Add(infoBtn4, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1493 wxStaticText *listsLabel = new wxStaticText(panel, wxID_ANY, "Node Type Recognition Lists:");
1494 wxFont font = listsLabel->GetFont();
1495 font.SetWeight(wxFONTWEIGHT_BOLD);
1496 listsLabel->SetFont(font);
1497 listsHeaderSizer->Add(listsLabel, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1498 mainSizer->Add(listsHeaderSizer, 0, wxEXPAND);
1499
1500 // Type lists in a grid
1501 wxBoxSizer *listsGrid = new wxBoxSizer(wxHORIZONTAL);
1502
1503 // Control types
1504 wxStaticBoxSizer *controlBox = new wxStaticBoxSizer(wxVERTICAL, panel, "Control Types");
1505 m_controlTypesList = new wxListBox(controlBox->GetStaticBox(), wxID_ANY);
1506 controlBox->Add(m_controlTypesList, 1, wxEXPAND | wxALL, 5);
1507 wxBoxSizer *controlBtnSizer = new wxBoxSizer(wxHORIZONTAL);
1508 m_addControlTypeBtn = new wxButton(controlBox->GetStaticBox(), ID_ADD_CONTROL_TYPE, "+");
1509 m_removeControlTypeBtn = new wxButton(controlBox->GetStaticBox(), ID_REMOVE_CONTROL_TYPE, "-");
1510 controlBtnSizer->Add(m_addControlTypeBtn, 1, wxALL, 2);
1511 controlBtnSizer->Add(m_removeControlTypeBtn, 1, wxALL, 2);
1512 controlBox->Add(controlBtnSizer, 0, wxEXPAND);
1513 listsGrid->Add(controlBox, 1, wxEXPAND | wxALL, 5);
1514
1515 // Decorator types
1516 wxStaticBoxSizer *decoratorBox = new wxStaticBoxSizer(wxVERTICAL, panel, "Decorator Types");
1517 m_decoratorTypesList = new wxListBox(decoratorBox->GetStaticBox(), wxID_ANY);
1518 decoratorBox->Add(m_decoratorTypesList, 1, wxEXPAND | wxALL, 5);
1519 wxBoxSizer *decoratorBtnSizer = new wxBoxSizer(wxHORIZONTAL);
1520 m_addDecoratorTypeBtn = new wxButton(decoratorBox->GetStaticBox(), ID_ADD_DECORATOR_TYPE, "+");
1521 m_removeDecoratorTypeBtn = new wxButton(decoratorBox->GetStaticBox(), ID_REMOVE_DECORATOR_TYPE, "-");
1522 decoratorBtnSizer->Add(m_addDecoratorTypeBtn, 1, wxALL, 2);
1523 decoratorBtnSizer->Add(m_removeDecoratorTypeBtn, 1, wxALL, 2);
1524 decoratorBox->Add(decoratorBtnSizer, 0, wxEXPAND);
1525 listsGrid->Add(decoratorBox, 1, wxEXPAND | wxALL, 5);
1526
1527 mainSizer->Add(listsGrid, 1, wxEXPAND);
1528
1529 // Second row: Action and Condition types
1530 wxBoxSizer *listsGrid2 = new wxBoxSizer(wxHORIZONTAL);
1531
1532 // Action types
1533 wxStaticBoxSizer *actionBox = new wxStaticBoxSizer(wxVERTICAL, panel, "Action Types (optional)");
1534 m_actionTypesList = new wxListBox(actionBox->GetStaticBox(), wxID_ANY);
1535 actionBox->Add(m_actionTypesList, 1, wxEXPAND | wxALL, 5);
1536 wxBoxSizer *actionBtnSizer = new wxBoxSizer(wxHORIZONTAL);
1537 m_addActionTypeBtn = new wxButton(actionBox->GetStaticBox(), ID_ADD_ACTION_TYPE, "+");
1538 m_removeActionTypeBtn = new wxButton(actionBox->GetStaticBox(), ID_REMOVE_ACTION_TYPE, "-");
1539 actionBtnSizer->Add(m_addActionTypeBtn, 1, wxALL, 2);
1540 actionBtnSizer->Add(m_removeActionTypeBtn, 1, wxALL, 2);
1541 actionBox->Add(actionBtnSizer, 0, wxEXPAND);
1542 listsGrid2->Add(actionBox, 1, wxEXPAND | wxALL, 5);
1543
1544 // Condition types
1545 wxStaticBoxSizer *conditionBox = new wxStaticBoxSizer(wxVERTICAL, panel, "Condition Types (optional)");
1546 m_conditionTypesList = new wxListBox(conditionBox->GetStaticBox(), wxID_ANY);
1547 conditionBox->Add(m_conditionTypesList, 1, wxEXPAND | wxALL, 5);
1548 wxBoxSizer *conditionBtnSizer = new wxBoxSizer(wxHORIZONTAL);
1549 m_addConditionTypeBtn = new wxButton(conditionBox->GetStaticBox(), ID_ADD_CONDITION_TYPE, "+");
1550 m_removeConditionTypeBtn = new wxButton(conditionBox->GetStaticBox(), ID_REMOVE_CONDITION_TYPE, "-");
1551 conditionBtnSizer->Add(m_addConditionTypeBtn, 1, wxALL, 2);
1552 conditionBtnSizer->Add(m_removeConditionTypeBtn, 1, wxALL, 2);
1553 conditionBox->Add(conditionBtnSizer, 0, wxEXPAND);
1554 listsGrid2->Add(conditionBox, 1, wxEXPAND | wxALL, 5);
1555
1556 mainSizer->Add(listsGrid2, 1, wxEXPAND);
1557
1558 // Unknown behavior
1559 wxBoxSizer *unknownSizer = new wxBoxSizer(wxHORIZONTAL);
1560
1561 // Reload bitmaps for this button
1562 wxBitmap infoNormal2(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
1563 wxBitmap infoHover2(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
1564 wxBitmap infoPressed2(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
1565 wxBitmap infoDisabled2(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
1566
1567 wxBitmapButton *infoBtn2 = new wxBitmapButton(panel, wxID_ANY, infoNormal2, wxDefaultPosition, wxSize(40, 40),
1568 wxBORDER_NONE | wxBU_EXACTFIT);
1569 infoBtn2->SetBitmapHover(infoHover2);
1570 infoBtn2->SetBitmapPressed(infoPressed2);
1571 infoBtn2->SetBitmapDisabled(infoDisabled2);
1572 infoBtn2->SetToolTip("Click for detailed information");
1573 infoBtn2->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1574 wxString helpText = "UNKNOWN TYPE BEHAVIOR\n"
1575 "===========================================================\n\n"
1576 "Determines what happens when the parser encounters a node type\n"
1577 "that is NOT in your defined type lists (Control, Decorator, etc.).\n\n"
1578 "THREE OPTIONS:\n\n"
1579 "1. ERROR (Strict - Recommended for Development)\n"
1580 " - Parser STOPS and reports an error\n"
1581 " - File loading FAILS\n"
1582 " - Ensures all node types are explicitly defined\n"
1583 " Example: <UnknownNode/> causes parsing to fail\n"
1584 " Use when:\n"
1585 " - Developing new trees - catch typos early\n"
1586 " - Want strict validation\n"
1587 " - Need to ensure only known types are used\n\n"
1588 "2. WARNING (Permissive)\n"
1589 " - Parser CONTINUES but logs a warning\n"
1590 " - File loads successfully\n"
1591 " - Unknown node is treated as Generic Node\n"
1592 " Example: <UnknownNode/> becomes a generic node + warning\n"
1593 " Use when:\n"
1594 " - Working with mixed/evolving formats\n"
1595 " - Want to see what's unrecognized but still load\n"
1596 " - Debugging format compatibility\n\n"
1597 "3. GENERIC NODE (Silent Fallback)\n"
1598 " - Parser treats unknown types as generic nodes\n"
1599 " - NO warning or error\n"
1600 " - Maximum compatibility\n"
1601 " Example: <UnknownNode/> silently becomes generic node\n"
1602 " Use when:\n"
1603 " - Working with highly variable XML formats\n"
1604 " - Want maximum flexibility\n"
1605 " - Already validated your trees externally\n\n"
1606 "RECOMMENDATION:\n"
1607 "Use ERROR during development to catch typos and undefined types.\n"
1608 "Use WARNING in production if you need to support evolving formats.";
1609 HelpDialog dlg(this, "Unknown Type Behavior - Help", helpText);
1610 dlg.ShowModal();
1611 });
1612 unknownSizer->Add(infoBtn2, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1613 unknownSizer->Add(new wxStaticText(panel, wxID_ANY, "Unknown Type Behavior:"), 0, wxALIGN_CENTER_VERTICAL | wxALL,
1614 5);
1615 wxArrayString unknownChoices;
1616 unknownChoices.Add("Error");
1617 unknownChoices.Add("Warning");
1618 unknownChoices.Add("Generic Node");
1619 m_unknownBehavior = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, unknownChoices);
1620 m_unknownBehavior->SetSelection(0);
1621 unknownSizer->Add(m_unknownBehavior, 1, wxALL, 5);
1622 mainSizer->Add(unknownSizer, 0, wxEXPAND);
1623
1624 // Type attribute name
1625 wxBoxSizer *typeAttrSizer = new wxBoxSizer(wxHORIZONTAL);
1626
1627 // Reload bitmaps for this button
1628 wxBitmap infoNormal3(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
1629 wxBitmap infoHover3(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
1630 wxBitmap infoPressed3(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
1631 wxBitmap infoDisabled3(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
1632
1633 wxBitmapButton *infoBtn3 = new wxBitmapButton(panel, wxID_ANY, infoNormal3, wxDefaultPosition, wxSize(40, 40),
1634 wxBORDER_NONE | wxBU_EXACTFIT);
1635 infoBtn3->SetBitmapHover(infoHover3);
1636 infoBtn3->SetBitmapPressed(infoPressed3);
1637 infoBtn3->SetBitmapDisabled(infoDisabled3);
1638 infoBtn3->SetToolTip("Click for detailed information");
1639 infoBtn3->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1640 wxString helpText = "TYPE ATTRIBUTE NAME\n"
1641 "===========================================================\n\n"
1642 "The XML attribute name used for by-attribute node classification.\n"
1643 "Only relevant when using 'By Attribute' or 'Hybrid' strategy.\n\n"
1644 "WHAT IS IT?\n"
1645 "When using attribute-based classification, this attribute specifies\n"
1646 "the node category (Control, Action, Condition, Decorator).\n\n"
1647 "COMMON VALUES:\n"
1648 " - 'type' - Most common standard\n"
1649 " - 'nodeType' - Explicit variant\n"
1650 " - 'category' - Alternative naming\n\n"
1651 "HOW IT WORKS:\n\n"
1652 "BY ATTRIBUTE STRATEGY:\n"
1653 " <Node type=\"Sequence\"> <!-- 'type' is the attribute -->\n"
1654 " <Node type=\"Action\" name=\"Move\"/>\n"
1655 " <Node type=\"Condition\" name=\"Check\"/>\n"
1656 " </Node>\n"
1657 " The parser reads the 'type' attribute to determine:\n"
1658 " - 'Sequence' -> Control node (from Control Types list)\n"
1659 " - 'Action' -> Action node (from Action Types list)\n"
1660 " - 'Condition' -> Condition node (from Condition Types list)\n\n"
1661 "HYBRID STRATEGY:\n"
1662 " <Sequence> <!-- Element name = Control -->\n"
1663 " <Node type=\"Action\" name=\"Custom\"/> <!-- Attribute -->\n"
1664 " <Condition name=\"Check\"/> <!-- Element name -->\n"
1665 " </Sequence>\n"
1666 " Parser checks element name first, falls back to attribute.\n\n"
1667 "BY ELEMENT NAME STRATEGY:\n"
1668 " This setting is IGNORED (not used)\n\n"
1669 "CLASSIFICATION FLOW:\n"
1670 " 1. Read node's type attribute value\n"
1671 " 2. Check if value is in Control Types -> Control node\n"
1672 " 3. Check if value is in Decorator Types -> Decorator node\n"
1673 " 4. Check if value is in Action Types -> Action node\n"
1674 " 5. Check if value is in Condition Types -> Condition node\n"
1675 " 6. Not found -> Apply Unknown Type Behavior\n\n"
1676 "RECOMMENDATION:\n"
1677 "Use 'type' for standard compatibility. Leave empty if using\n"
1678 "'By Element Name' strategy exclusively.";
1679 HelpDialog dlg(this, "Type Attribute Name - Help", helpText);
1680 dlg.ShowModal();
1681 });
1682 typeAttrSizer->Add(infoBtn3, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
1683 typeAttrSizer->Add(new wxStaticText(panel, wxID_ANY, "Type Attribute Name:"), 0, wxALIGN_CENTER_VERTICAL | wxALL,
1684 5);
1685 m_typeAttrName = new wxTextCtrl(panel, wxID_ANY);
1686 m_typeAttrName->SetToolTip("Attribute name used for by-attribute classification");
1687 m_typeAttrName->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
1688 typeAttrSizer->Add(m_typeAttrName, 1, wxALL, 5);
1689 mainSizer->Add(typeAttrSizer, 0, wxEXPAND);
1690
1691 panel->SetSizer(mainSizer);
1692 return panel;
1693}
1694
1695wxPanel *ParserConfigDialog::CreateBlackboardTab(wxNotebook *notebook) {
1696 wxPanel *panel = new wxPanel(notebook);
1697 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
1698
1699 // Load info button bitmaps
1700 wxBitmap infoNormal(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
1701 wxBitmap infoHover(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
1702 wxBitmap infoPressed(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
1703 wxBitmap infoDisabled(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
1704
1705 // Basic blackboard configuration
1706 wxGridBagSizer *basicSizer = new wxGridBagSizer(5, 5);
1707 int row = 0;
1708
1709 // Blackboard element
1710 wxBoxSizer *labelSizer1 = new wxBoxSizer(wxHORIZONTAL);
1711 wxBitmapButton *infoBtn1 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1712 wxBORDER_NONE | wxBU_EXACTFIT);
1713 infoBtn1->SetBitmapHover(infoHover);
1714 infoBtn1->SetBitmapPressed(infoPressed);
1715 infoBtn1->SetBitmapDisabled(infoDisabled);
1716 infoBtn1->SetToolTip("Click for detailed information");
1717 infoBtn1->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1718 wxString helpText = "BLACKBOARD ELEMENT\n"
1719 "===========================================================\n\n"
1720 "WHAT IS IT?\n"
1721 "The XML element name that represents a blackboard definition - a\n"
1722 "shared data storage that behavior trees use to store and access variables.\n\n"
1723 "COMMON VALUES:\n"
1724 " - 'BlackboardModel' - BehaviorTree.CPP standard\n"
1725 " - 'Blackboard' - Simplified variant\n"
1726 " - 'Variables' - Alternative naming\n\n"
1727 "WHAT IS A BLACKBOARD?\n"
1728 "A blackboard is a KEY-VALUE data store that:\n"
1729 " - Stores variables shared across the behavior tree\n"
1730 " - Provides data for condition checks and actions\n"
1731 " - Can be defined once and used by multiple trees\n"
1732 " - Supports typed data (int, float, string, bool, etc.)\n\n"
1733 "EXAMPLE:\n"
1734 " <root>\n"
1735 " <BlackboardModel ID=\"PlayerBlackboard\">\n"
1736 " <Entry key=\"health\" type=\"int\" value=\"100\"/>\n"
1737 " <Entry key=\"target\" type=\"string\"/>\n"
1738 " <Entry key=\"isAggressive\" type=\"bool\" value=\"false\"/>\n"
1739 " </BlackboardModel>\n\n"
1740 " <BehaviorTree ID=\"MainAI\" blackboard=\"PlayerBlackboard\">\n"
1741 " <!-- Tree uses the blackboard -->\n"
1742 " </BehaviorTree>\n"
1743 " </root>\n\n"
1744 "WHY USE BLACKBOARDS?\n"
1745 " - Share data between different parts of the tree\n"
1746 " - Parameterize behavior trees for reusability\n"
1747 " - Type-safe data access\n"
1748 " - Runtime variable inspection and debugging";
1749 HelpDialog dlg(this, "Blackboard Element - Help", helpText);
1750 dlg.ShowModal();
1751 });
1752 labelSizer1->Add(infoBtn1, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1753 labelSizer1->Add(new wxStaticText(panel, wxID_ANY, "Blackboard Element:"), 0, wxALIGN_CENTER_VERTICAL);
1754 basicSizer->Add(labelSizer1, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1755 m_blackboardElement = new wxTextCtrl(panel, wxID_ANY);
1757 basicSizer->Add(m_blackboardElement, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1758 row++;
1759
1760 // Blackboard ID attribute
1761 wxBoxSizer *labelSizer2 = new wxBoxSizer(wxHORIZONTAL);
1762 wxBitmapButton *infoBtn2 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1763 wxBORDER_NONE | wxBU_EXACTFIT);
1764 infoBtn2->SetBitmapHover(infoHover);
1765 infoBtn2->SetBitmapPressed(infoPressed);
1766 infoBtn2->SetBitmapDisabled(infoDisabled);
1767 infoBtn2->SetToolTip("Click for detailed information");
1768 infoBtn2->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1769 wxString helpText = "BLACKBOARD ID ATTRIBUTE\n"
1770 "===========================================================\n\n"
1771 "WHAT IS IT?\n"
1772 "The XML attribute name that contains the unique identifier for\n"
1773 "each blackboard definition.\n\n"
1774 "COMMON VALUES:\n"
1775 " - 'ID' - Standard naming (most common)\n"
1776 " - 'name' - Alternative\n"
1777 " - 'id' - Lowercase variant\n\n"
1778 "WHY IS IT NEEDED?\n"
1779 "The ID allows:\n"
1780 " - Multiple blackboard definitions in one file\n"
1781 " - Behavior trees to reference specific blackboards\n"
1782 " - Blackboard inheritance (one extends another)\n"
1783 " - Runtime blackboard lookup by name\n\n"
1784 "EXAMPLE:\n"
1785 " <BlackboardModel ID=\"BaseAI\">\n"
1786 " <Entry key=\"speed\" type=\"float\" value=\"5.0\"/>\n"
1787 " </BlackboardModel>\n\n"
1788 " <BlackboardModel ID=\"EnemyAI\" parent=\"BaseAI\">\n"
1789 " <Entry key=\"health\" type=\"int\" value=\"100\"/>\n"
1790 " <!-- Inherits 'speed' from BaseAI -->\n"
1791 " </BlackboardModel>\n\n"
1792 " <BehaviorTree ID=\"Enemy\" blackboard=\"EnemyAI\">\n"
1793 " ^^^^^^^^^^^^^^^^^^^\n"
1794 " References blackboard by ID\n"
1795 " </BehaviorTree>\n\n"
1796 "RECOMMENDATION:\n"
1797 "Use 'ID' for consistency with BehaviorTree.CPP standard.";
1798 HelpDialog dlg(this, "Blackboard ID Attribute - Help", helpText);
1799 dlg.ShowModal();
1800 });
1801 labelSizer2->Add(infoBtn2, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1802 labelSizer2->Add(new wxStaticText(panel, wxID_ANY, "Blackboard ID Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
1803 basicSizer->Add(labelSizer2, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1804 m_blackboardIdAttr = new wxTextCtrl(panel, wxID_ANY);
1806 basicSizer->Add(m_blackboardIdAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1807 row++;
1808
1809 // Parent attribute
1810 wxBoxSizer *labelSizer3 = new wxBoxSizer(wxHORIZONTAL);
1811 wxBitmapButton *infoBtn3 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1812 wxBORDER_NONE | wxBU_EXACTFIT);
1813 infoBtn3->SetBitmapHover(infoHover);
1814 infoBtn3->SetBitmapPressed(infoPressed);
1815 infoBtn3->SetBitmapDisabled(infoDisabled);
1816 infoBtn3->SetToolTip("Click for detailed information");
1817 infoBtn3->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1818 wxString helpText = "PARENT/INHERITANCE ATTRIBUTE\n"
1819 "===========================================================\n\n"
1820 "WHAT IS IT?\n"
1821 "The XML attribute name that specifies a parent blackboard from\n"
1822 "which the current blackboard inherits entries.\n\n"
1823 "COMMON VALUES:\n"
1824 " - 'parent' - Most common\n"
1825 " - 'extends' - Object-oriented terminology\n"
1826 " - 'inherits' - Explicit naming\n"
1827 " - 'base' - Alternative\n\n"
1828 "HOW INHERITANCE WORKS:\n"
1829 "A child blackboard:\n"
1830 " - Inherits ALL entries from its parent\n"
1831 " - Can add NEW entries not in the parent\n"
1832 " - Can OVERRIDE parent entries with different defaults\n"
1833 " - Cannot remove parent entries\n\n"
1834 "EXAMPLE:\n"
1835 " <BlackboardModel ID=\"BaseCharacter\">\n"
1836 " <Entry key=\"health\" type=\"int\" value=\"100\"/>\n"
1837 " <Entry key=\"speed\" type=\"float\" value=\"5.0\"/>\n"
1838 " </BlackboardModel>\n\n"
1839 " <BlackboardModel ID=\"Player\" parent=\"BaseCharacter\">\n"
1840 " <Entry key=\"mana\" type=\"int\" value=\"50\"/>\n"
1841 " <Entry key=\"speed\" type=\"float\" value=\"7.0\"/>\n"
1842 " <!-- Inherits: health=100 (from parent) -->\n"
1843 " <!-- Overrides: speed=7.0 (not 5.0) -->\n"
1844 " <!-- Adds: mana=50 (new entry) -->\n"
1845 " </BlackboardModel>\n\n"
1846 "BENEFITS:\n"
1847 " - Reduce duplication in blackboard definitions\n"
1848 " - Create base templates for common variables\n"
1849 " - Organize related blackboards hierarchically";
1850 HelpDialog dlg(this, "Parent/Inheritance Attribute - Help", helpText);
1851 dlg.ShowModal();
1852 });
1853 labelSizer3->Add(infoBtn3, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1854 labelSizer3->Add(new wxStaticText(panel, wxID_ANY, "Parent/Inheritance Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
1855 basicSizer->Add(labelSizer3, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1856 m_blackboardParentAttr = new wxTextCtrl(panel, wxID_ANY);
1858 basicSizer->Add(m_blackboardParentAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1859 row++;
1860
1861 // Entry element
1862 wxBoxSizer *labelSizer4 = new wxBoxSizer(wxHORIZONTAL);
1863 wxBitmapButton *infoBtn4 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1864 wxBORDER_NONE | wxBU_EXACTFIT);
1865 infoBtn4->SetBitmapHover(infoHover);
1866 infoBtn4->SetBitmapPressed(infoPressed);
1867 infoBtn4->SetBitmapDisabled(infoDisabled);
1868 infoBtn4->SetToolTip("Click for detailed information");
1869 infoBtn4->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1870 wxString helpText = "ENTRY ELEMENT\n"
1871 "===========================================================\n\n"
1872 "WHAT IS IT?\n"
1873 "The XML element name that represents a single variable/entry\n"
1874 "within a blackboard definition.\n\n"
1875 "COMMON VALUES:\n"
1876 " - 'Entry' - BehaviorTree.CPP standard\n"
1877 " - 'Variable' - Descriptive alternative\n"
1878 " - 'Field' - Object-oriented terminology\n"
1879 " - 'Property' - Another variant\n\n"
1880 "WHAT IS AN ENTRY?\n"
1881 "Each entry represents ONE variable in the blackboard:\n"
1882 " - Has a KEY (variable name)\n"
1883 " - Has a TYPE (int, float, string, bool, etc.)\n"
1884 " - May have a DEFAULT VALUE\n"
1885 " - Can be read/written by nodes during execution\n\n"
1886 "EXAMPLE:\n"
1887 " <BlackboardModel ID=\"GameAI\">\n"
1888 " <Entry key=\"playerHealth\" type=\"int\" value=\"100\"/>\n"
1889 " <Entry key=\"targetPosition\" type=\"Vector3\"/>\n"
1890 " <Entry key=\"isAlerted\" type=\"bool\" value=\"false\"/>\n"
1891 " <Entry key=\"patrolSpeed\" type=\"float\" value=\"2.5\"/>\n"
1892 " <Entry key=\"weaponName\" type=\"string\" value=\"Sword\"/>\n"
1893 " </BlackboardModel>\n\n"
1894 "USAGE IN BEHAVIOR TREE:\n"
1895 " <Condition name=\"CheckHealth\">\n"
1896 " <input key=\"health\" blackboard_key=\"playerHealth\"/>\n"
1897 " </Condition>\n\n"
1898 " <Action name=\"SetAlert\">\n"
1899 " <output key=\"isAlerted\" blackboard_key=\"isAlerted\" value=\"true\"/>\n"
1900 " </Action>";
1901 HelpDialog dlg(this, "Entry Element - Help", helpText);
1902 dlg.ShowModal();
1903 });
1904 labelSizer4->Add(infoBtn4, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1905 labelSizer4->Add(new wxStaticText(panel, wxID_ANY, "Entry Element:"), 0, wxALIGN_CENTER_VERTICAL);
1906 basicSizer->Add(labelSizer4, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1907 m_entryElement = new wxTextCtrl(panel, wxID_ANY);
1908 m_entryElement->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
1909 basicSizer->Add(m_entryElement, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1910 row++;
1911
1912 // Entry key attribute
1913 wxBoxSizer *labelSizer5 = new wxBoxSizer(wxHORIZONTAL);
1914 wxBitmapButton *infoBtn5 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1915 wxBORDER_NONE | wxBU_EXACTFIT);
1916 infoBtn5->SetBitmapHover(infoHover);
1917 infoBtn5->SetBitmapPressed(infoPressed);
1918 infoBtn5->SetBitmapDisabled(infoDisabled);
1919 infoBtn5->SetToolTip("Click for detailed information");
1920 infoBtn5->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1921 wxString helpText = "ENTRY KEY ATTRIBUTE\n"
1922 "===========================================================\n\n"
1923 "WHAT IS IT?\n"
1924 "The XML attribute name that contains the KEY (variable name)\n"
1925 "for a blackboard entry.\n\n"
1926 "COMMON VALUES:\n"
1927 " - 'key' - BehaviorTree.CPP standard\n"
1928 " - 'name' - Alternative common usage\n"
1929 " - 'id' - Some implementations\n\n"
1930 "WHAT IS A KEY?\n"
1931 "The key is the UNIQUE IDENTIFIER for a variable within a blackboard:\n"
1932 " - Acts as the variable name\n"
1933 " - Used to read/write the value at runtime\n"
1934 " - Must be unique within the blackboard\n"
1935 " - Case-sensitive (usually)\n\n"
1936 "EXAMPLE:\n"
1937 " <Entry key=\"playerHealth\" type=\"int\" value=\"100\"/>\n"
1938 " ^^^^^^^^^^^^^^^^^^^\n"
1939 " This is the key - the variable name\n\n"
1940 " <!-- In behavior tree nodes: -->\n"
1941 " <Condition name=\"IsHealthLow\">\n"
1942 " <input key=\"health\" blackboard_key=\"playerHealth\"/>\n"
1943 " ^^^^^^^^^^^^^^^^^\n"
1944 " References by key\n"
1945 " </Condition>\n\n"
1946 "NAMING CONVENTIONS:\n"
1947 " - camelCase: playerHealth, maxSpeed, isActive\n"
1948 " - snake_case: player_health, max_speed, is_active\n"
1949 " - PascalCase: PlayerHealth, MaxSpeed, IsActive\n\n"
1950 "RECOMMENDATION:\n"
1951 "Use descriptive, consistent names following your project's\n"
1952 "naming convention. Common standard is camelCase.";
1953 HelpDialog dlg(this, "Entry Key Attribute - Help", helpText);
1954 dlg.ShowModal();
1955 });
1956 labelSizer5->Add(infoBtn5, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
1957 labelSizer5->Add(new wxStaticText(panel, wxID_ANY, "Entry Key Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
1958 basicSizer->Add(labelSizer5, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
1959 m_entryKeyAttr = new wxTextCtrl(panel, wxID_ANY);
1960 m_entryKeyAttr->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
1961 basicSizer->Add(m_entryKeyAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
1962 row++;
1963
1964 // Entry type attribute
1965 wxBoxSizer *labelSizer6 = new wxBoxSizer(wxHORIZONTAL);
1966 wxBitmapButton *infoBtn6 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
1967 wxBORDER_NONE | wxBU_EXACTFIT);
1968 infoBtn6->SetBitmapHover(infoHover);
1969 infoBtn6->SetBitmapPressed(infoPressed);
1970 infoBtn6->SetBitmapDisabled(infoDisabled);
1971 infoBtn6->SetToolTip("Click for detailed information");
1972 infoBtn6->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
1973 wxString helpText = "ENTRY TYPE ATTRIBUTE\n"
1974 "===========================================================\n\n"
1975 "WHAT IS IT?\n"
1976 "The XML attribute name that specifies the DATA TYPE for a\n"
1977 "blackboard entry (int, float, string, bool, etc.).\n\n"
1978 "COMMON VALUES:\n"
1979 " - 'type' - Most common standard\n"
1980 " - 'dataType' - Explicit variant\n"
1981 " - 'valueType' - Alternative\n\n"
1982 "SUPPORTED TYPES (typical):\n"
1983 " PRIMITIVES:\n"
1984 " - 'int' / 'integer' - Whole numbers (e.g., 42, -10)\n"
1985 " - 'float' / 'double' - Decimals (e.g., 3.14, -2.5)\n"
1986 " - 'bool' / 'boolean' - true/false\n"
1987 " - 'string' - Text (e.g., \"Hello\", \"weapon_1\")\n\n"
1988 " ADVANCED (depends on implementation):\n"
1989 " - 'Vector2' / 'Vector3' - Position/direction\n"
1990 " - 'Pose' / 'Pose2D' - Position + rotation\n"
1991 " - 'array' - List of values\n"
1992 " - 'object' - Complex custom types\n\n"
1993 "EXAMPLE:\n"
1994 " <Entry key=\"health\" type=\"int\" value=\"100\"/>\n"
1995 " <Entry key=\"speed\" type=\"float\" value=\"5.5\"/>\n"
1996 " <Entry key=\"isAlive\" type=\"bool\" value=\"true\"/>\n"
1997 " <Entry key=\"name\" type=\"string\" value=\"Player\"/>\n"
1998 " <Entry key=\"position\" type=\"Vector3\"/>\n\n"
1999 "WHY TYPES MATTER:\n"
2000 " - Type safety: prevent wrong value assignments\n"
2001 " - Runtime validation\n"
2002 " - Editor support (proper UI widgets)\n"
2003 " - Performance optimization";
2004 HelpDialog dlg(this, "Entry Type Attribute - Help", helpText);
2005 dlg.ShowModal();
2006 });
2007 labelSizer6->Add(infoBtn6, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2008 labelSizer6->Add(new wxStaticText(panel, wxID_ANY, "Entry Type Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
2009 basicSizer->Add(labelSizer6, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
2010 m_entryTypeAttr = new wxTextCtrl(panel, wxID_ANY);
2011 m_entryTypeAttr->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
2012 basicSizer->Add(m_entryTypeAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
2013 row++;
2014
2015 // Entry value attribute
2016 wxBoxSizer *labelSizer7 = new wxBoxSizer(wxHORIZONTAL);
2017 wxBitmapButton *infoBtn7 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
2018 wxBORDER_NONE | wxBU_EXACTFIT);
2019 infoBtn7->SetBitmapHover(infoHover);
2020 infoBtn7->SetBitmapPressed(infoPressed);
2021 infoBtn7->SetBitmapDisabled(infoDisabled);
2022 infoBtn7->SetToolTip("Click for detailed information");
2023 infoBtn7->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
2024 wxString helpText = "ENTRY VALUE ATTRIBUTE\n"
2025 "===========================================================\n\n"
2026 "WHAT IS IT?\n"
2027 "The XML attribute name that contains the DEFAULT VALUE for a\n"
2028 "blackboard entry.\n\n"
2029 "COMMON VALUES:\n"
2030 " - 'value' - Most common\n"
2031 " - 'default' - Explicit naming\n"
2032 " - 'defaultValue' - Verbose variant\n\n"
2033 "WHAT IS A DEFAULT VALUE?\n"
2034 "The default value is the INITIAL value assigned when:\n"
2035 " - A blackboard is first created/instantiated\n"
2036 " - A behavior tree starts executing\n"
2037 " - The blackboard is reset\n\n"
2038 "OPTIONAL vs REQUIRED:\n"
2039 " - Some entries HAVE defaults (value specified)\n"
2040 " - Some entries DON'T (must be set at runtime)\n\n"
2041 "EXAMPLE:\n"
2042 " <Entry key=\"health\" type=\"int\" value=\"100\"/>\n"
2043 " ^^^^^^^^^^^^^\n"
2044 " Starts with 100\n\n"
2045 " <Entry key=\"currentTarget\" type=\"string\"/>\n"
2046 " No default - must be set\n\n"
2047 " <Entry key=\"isAlerted\" type=\"bool\" value=\"false\"/>\n"
2048 " ^^^^^^^^^^^^^^^^\n"
2049 " Starts as false\n\n"
2050 "TYPE-SPECIFIC FORMATS:\n"
2051 " - int: \"42\", \"-10\", \"0\"\n"
2052 " - float: \"3.14\", \"-2.5\", \"0.0\"\n"
2053 " - bool: \"true\", \"false\" (case-insensitive)\n"
2054 " - string: \"PlayerName\", \"idle_animation\"\n"
2055 " - Vector3: \"1.0,2.0,3.0\" (comma-separated)\n\n"
2056 "RECOMMENDATION:\n"
2057 "Provide sensible defaults when possible to make trees\n"
2058 "more self-contained and easier to test.";
2059 HelpDialog dlg(this, "Entry Value Attribute - Help", helpText);
2060 dlg.ShowModal();
2061 });
2062 labelSizer7->Add(infoBtn7, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2063 labelSizer7->Add(new wxStaticText(panel, wxID_ANY, "Entry Value Attribute:"), 0, wxALIGN_CENTER_VERTICAL);
2064 basicSizer->Add(labelSizer7, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
2065 m_entryValueAttr = new wxTextCtrl(panel, wxID_ANY);
2066 m_entryValueAttr->Bind(wxEVT_TEXT, &ParserConfigDialog::OnFieldChanged, this);
2067 basicSizer->Add(m_entryValueAttr, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
2068 row++;
2069
2070 basicSizer->AddGrowableCol(1);
2071 mainSizer->Add(basicSizer, 0, wxEXPAND | wxALL, 5);
2072
2073 // Type mappings
2074 wxStaticBoxSizer *mappingsBox = new wxStaticBoxSizer(wxVERTICAL, panel, "Data Type Mappings");
2075 m_typeMappingsGrid = new wxGrid(mappingsBox->GetStaticBox(), wxID_ANY);
2076 m_typeMappingsGrid->CreateGrid(0, 2);
2077 m_typeMappingsGrid->SetColLabelValue(0, "XML Type");
2078 m_typeMappingsGrid->SetColLabelValue(1, "Internal Type");
2079
2080 // Set wider column widths to make text fully visible
2081 m_typeMappingsGrid->SetColSize(0, 250); // XML Type column width
2082 m_typeMappingsGrid->SetColSize(1, 250); // Internal Type column width
2083
2084 m_typeMappingsGrid->SetMinSize(wxSize(-1, 150));
2085 mappingsBox->Add(m_typeMappingsGrid, 1, wxEXPAND | wxALL, 5);
2086
2087 wxBoxSizer *mappingBtnSizer = new wxBoxSizer(wxHORIZONTAL);
2088 m_addMappingBtn = new wxButton(mappingsBox->GetStaticBox(), ID_ADD_MAPPING, "Add Mapping");
2089 m_removeMappingBtn = new wxButton(mappingsBox->GetStaticBox(), ID_REMOVE_MAPPING, "Remove Selected");
2090 mappingBtnSizer->Add(m_addMappingBtn, 0, wxALL, 2);
2091 mappingBtnSizer->Add(m_removeMappingBtn, 0, wxALL, 2);
2092 mappingsBox->Add(mappingBtnSizer, 0);
2093
2094 mainSizer->Add(mappingsBox, 1, wxEXPAND | wxALL, 5);
2095
2096 // Allow undefined keys
2097 m_allowUndefinedKeys = new wxCheckBox(panel, wxID_ANY, "Allow Undefined Blackboard Keys");
2098 mainSizer->Add(m_allowUndefinedKeys, 0, wxALL, 5);
2099
2100 panel->SetSizer(mainSizer);
2101 return panel;
2102}
2103
2104wxPanel *ParserConfigDialog::CreateAdvancedTab(wxNotebook *notebook) {
2105 wxPanel *panel = new wxPanel(notebook);
2106 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
2107
2108 // Load info button bitmaps
2109 wxBitmap infoNormal(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
2110 wxBitmap infoHover(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
2111 wxBitmap infoPressed(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
2112 wxBitmap infoDisabled(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
2113
2114 // Options in grid
2115 wxGridBagSizer *sizer = new wxGridBagSizer(5, 5);
2116 int row = 0;
2117
2118 // Progress reporting
2119 wxBoxSizer *labelSizer1 = new wxBoxSizer(wxHORIZONTAL);
2120 wxBitmapButton *infoBtn1 = new wxBitmapButton(panel, wxID_ANY, infoNormal, wxDefaultPosition, wxSize(40, 40),
2121 wxBORDER_NONE | wxBU_EXACTFIT);
2122 infoBtn1->SetBitmapHover(infoHover);
2123 infoBtn1->SetBitmapPressed(infoPressed);
2124 infoBtn1->SetBitmapDisabled(infoDisabled);
2125 infoBtn1->SetToolTip("Click for detailed information");
2126 infoBtn1->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
2127 wxString helpText = "ENABLE PROGRESS REPORTING\n"
2128 "===========================================================\n\n"
2129 "WHAT IS IT?\n"
2130 "Controls whether the parser reports progress updates during XML\n"
2131 "parsing operations, especially useful for large files.\n\n"
2132 "ENABLED:\n"
2133 " - Parser emits progress callbacks during parsing\n"
2134 " - UI can show loading bars or progress indicators\n"
2135 " - Helps prevent \"app not responding\" appearance\n"
2136 " - Useful for files > 1000 nodes\n"
2137 " - Small performance overhead (~2-5%)\n\n"
2138 "DISABLED:\n"
2139 " - No progress updates\n"
2140 " - Slightly faster parsing\n"
2141 " - Simpler implementation\n"
2142 " - Best for small/medium files\n\n"
2143 "USE CASES:\n"
2144 "Enable when:\n"
2145 " - Loading very large behavior tree files\n"
2146 " - Need to show user feedback during loading\n"
2147 " - Parsing operations take > 1 second\n\n"
2148 "Disable when:\n"
2149 " - Working with small files (< 100 nodes)\n"
2150 " - Maximum parsing speed is priority\n"
2151 " - No UI for displaying progress\n\n"
2152 "RECOMMENDATION:\n"
2153 "Enable for production applications to improve user experience\n"
2154 "when loading large behavior tree files.";
2155 HelpDialog dlg(this, "Progress Reporting - Help", helpText);
2156 dlg.ShowModal();
2157 });
2158 labelSizer1->Add(infoBtn1, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2159 m_enableProgressReporting = new wxCheckBox(panel, wxID_ANY, "Enable Progress Reporting");
2160 m_enableProgressReporting->SetToolTip("Report parsing progress for large files");
2161 labelSizer1->Add(m_enableProgressReporting, 0, wxALIGN_CENTER_VERTICAL);
2162 sizer->Add(labelSizer1, wxGBPosition(row, 0), wxGBSpan(1, 2));
2163 row++;
2164
2165 // Detailed errors
2166 wxBoxSizer *labelSizer2 = new wxBoxSizer(wxHORIZONTAL);
2167 wxBitmap infoNormal2(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
2168 wxBitmap infoHover2(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
2169 wxBitmap infoPressed2(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
2170 wxBitmap infoDisabled2(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
2171 wxBitmapButton *infoBtn2 = new wxBitmapButton(panel, wxID_ANY, infoNormal2, wxDefaultPosition, wxSize(40, 40),
2172 wxBORDER_NONE | wxBU_EXACTFIT);
2173 infoBtn2->SetBitmapHover(infoHover2);
2174 infoBtn2->SetBitmapPressed(infoPressed2);
2175 infoBtn2->SetBitmapDisabled(infoDisabled2);
2176 infoBtn2->SetToolTip("Click for detailed information");
2177 infoBtn2->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
2178 wxString helpText = "DETAILED ERROR MESSAGES\n"
2179 "===========================================================\n\n"
2180 "Controls the verbosity of error messages when parsing fails.\n\n"
2181 "ENABLED (Recommended for Development):\n"
2182 " - Full error descriptions with context\n"
2183 " - Shows exact line and column numbers\n"
2184 " - Includes surrounding XML context\n"
2185 " - Lists all violated validation rules\n"
2186 " - Suggests possible fixes\n\n"
2187 "Example detailed error:\n"
2188 " ERROR at line 42, column 15:\n"
2189 " Unknown element 'Sequenc' found.\n"
2190 " Context: <Sequenc name=\"Patrol\">\n"
2191 " Did you mean: 'Sequence'?\n"
2192 " Valid elements: Sequence, Selector, Parallel\n\n"
2193 "DISABLED (Production):\n"
2194 " - Brief error messages\n"
2195 " - Just error type and location\n"
2196 " - Less information leakage\n"
2197 " - Slightly faster\n\n"
2198 "Example simple error:\n"
2199 " Parse error at line 42: Unknown element\n\n"
2200 "USE CASES:\n"
2201 "Enable when:\n"
2202 " - Developing behavior trees\n"
2203 " - Debugging XML format issues\n"
2204 " - Users need helpful error messages\n\n"
2205 "Disable when:\n"
2206 " - Production/release builds\n"
2207 " - Security concerns about information disclosure\n"
2208 " - Minimal error output desired\n\n"
2209 "RECOMMENDATION:\n"
2210 "Keep ENABLED during development. Consider disabling for\n"
2211 "production if error details are security-sensitive.";
2212 HelpDialog dlg(this, "Detailed Error Messages - Help", helpText);
2213 dlg.ShowModal();
2214 });
2215 labelSizer2->Add(infoBtn2, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2216 m_detailedErrors = new wxCheckBox(panel, wxID_ANY, "Detailed Error Messages");
2217 m_detailedErrors->SetToolTip("Include detailed context in error messages");
2218 labelSizer2->Add(m_detailedErrors, 0, wxALIGN_CENTER_VERTICAL);
2219 sizer->Add(labelSizer2, wxGBPosition(row, 0), wxGBSpan(1, 2));
2220 row++;
2221
2222 // Track line/column
2223 wxBoxSizer *labelSizer3 = new wxBoxSizer(wxHORIZONTAL);
2224 wxBitmap infoNormal3(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
2225 wxBitmap infoHover3(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
2226 wxBitmap infoPressed3(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
2227 wxBitmap infoDisabled3(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
2228 wxBitmapButton *infoBtn3 = new wxBitmapButton(panel, wxID_ANY, infoNormal3, wxDefaultPosition, wxSize(40, 40),
2229 wxBORDER_NONE | wxBU_EXACTFIT);
2230 infoBtn3->SetBitmapHover(infoHover3);
2231 infoBtn3->SetBitmapPressed(infoPressed3);
2232 infoBtn3->SetBitmapDisabled(infoDisabled3);
2233 infoBtn3->SetToolTip("Click for detailed information");
2234 infoBtn3->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
2235 wxString helpText = "TRACK LINE/COLUMN NUMBERS\n"
2236 "===========================================================\n\n"
2237 "Controls whether the parser maintains line and column position\n"
2238 "information for every parsed element.\n\n"
2239 "ENABLED:\n"
2240 " - Every node tracks its source location (line, column)\n"
2241 " - Error messages show EXACT locations\n"
2242 " - Enables \"jump to source\" in editors\n"
2243 " - Useful for debugging and validation\n"
2244 " - Small memory overhead per node (~8 bytes)\n"
2245 " - Minor performance impact (~5-10%)\n\n"
2246 "DISABLED:\n"
2247 " - No line/column tracking\n"
2248 " - Error messages less specific\n"
2249 " - Lower memory usage\n"
2250 " - Slightly faster parsing\n\n"
2251 "ERROR COMPARISON:\n\n"
2252 "With tracking enabled:\n"
2253 " ERROR at line 127, column 23:\n"
2254 " Invalid attribute 'tpye' on Action node.\n"
2255 " <Action tpye=\"Move\" target=\"enemy\"/>\n"
2256 " ^\n\n"
2257 "With tracking disabled:\n"
2258 " ERROR: Invalid attribute 'tpye' on Action node.\n"
2259 " (no location information available)\n\n"
2260 "USE CASES:\n"
2261 "Enable when:\n"
2262 " - Developing/debugging trees\n"
2263 " - Need precise error locations\n"
2264 " - Integrating with XML editors\n\n"
2265 "Disable when:\n"
2266 " - Memory is critical constraint\n"
2267 " - Maximum performance needed\n"
2268 " - Source locations not needed\n\n"
2269 "RECOMMENDATION:\n"
2270 "Keep ENABLED during development for better debugging.\n"
2271 "Consider disabling in memory-constrained environments.";
2272 HelpDialog dlg(this, "Track Line/Column Numbers - Help", helpText);
2273 dlg.ShowModal();
2274 });
2275 labelSizer3->Add(infoBtn3, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2276 m_trackLineColumn = new wxCheckBox(panel, wxID_ANY, "Track Line/Column Numbers");
2277 m_trackLineColumn->SetToolTip("Store source location for every element");
2278 labelSizer3->Add(m_trackLineColumn, 0, wxALIGN_CENTER_VERTICAL);
2279 sizer->Add(labelSizer3, wxGBPosition(row, 0), wxGBSpan(1, 2));
2280 row++;
2281
2282 // SubTree expansion
2283 wxBoxSizer *labelSizer4 = new wxBoxSizer(wxHORIZONTAL);
2284 wxBitmap infoNormal4(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
2285 wxBitmap infoHover4(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
2286 wxBitmap infoPressed4(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
2287 wxBitmap infoDisabled4(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
2288 wxBitmapButton *infoBtn4 = new wxBitmapButton(panel, wxID_ANY, infoNormal4, wxDefaultPosition, wxSize(40, 40),
2289 wxBORDER_NONE | wxBU_EXACTFIT);
2290 infoBtn4->SetBitmapHover(infoHover4);
2291 infoBtn4->SetBitmapPressed(infoPressed4);
2292 infoBtn4->SetBitmapDisabled(infoDisabled4);
2293 infoBtn4->SetToolTip("Click for detailed information");
2294 infoBtn4->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
2295 wxString helpText = "SUBTREE EXPANSION\n"
2296 "===========================================================\n\n"
2297 "Controls WHEN subtree references are resolved and loaded during\n"
2298 "parsing. Affects memory usage and loading performance.\n\n"
2299 "THREE STRATEGIES:\n\n"
2300 "1. IMMEDIATE (Default - Recommended)\n"
2301 " - All subtrees loaded and expanded during initial parse\n"
2302 " - Complete tree structure available immediately\n"
2303 " - All errors detected at load time\n"
2304 " - Higher initial memory usage\n"
2305 " - Slightly longer initial load time\n"
2306 " Pros: Simple, predictable, catches all errors early\n"
2307 " Cons: Loads trees that may never be used\n\n"
2308 "2. LAZY (On-Demand Loading)\n"
2309 " - Subtrees loaded only when first accessed\n"
2310 " - Lower initial memory footprint\n"
2311 " - Faster initial load time\n"
2312 " - Subtree errors discovered at runtime\n"
2313 " - Small performance hit on first access\n"
2314 " Pros: Efficient for large tree collections\n"
2315 " Cons: Errors may appear during gameplay/execution\n\n"
2316 "3. MANUAL (Explicit Control)\n"
2317 " - No automatic expansion\n"
2318 " - Application controls when to load\n"
2319 " - Maximum flexibility\n"
2320 " - Requires explicit API calls\n"
2321 " Pros: Full control over loading\n"
2322 " Cons: More complex application code\n\n"
2323 "EXAMPLE:\n"
2324 "Tree with subtrees: Main -> Patrol -> GuardPoint\n\n"
2325 "IMMEDIATE: Main, Patrol, GuardPoint all loaded at once\n"
2326 "LAZY: Only Main loaded, Patrol/GuardPoint on first use\n"
2327 "MANUAL: Only Main loaded, app calls LoadSubtree() explicitly\n\n"
2328 "RECOMMENDATION:\n"
2329 "Use IMMEDIATE for most cases - simple and catches errors early.\n"
2330 "Use LAZY for very large tree collections (100+ trees).";
2331 HelpDialog dlg(this, "SubTree Expansion - Help", helpText);
2332 dlg.ShowModal();
2333 });
2334 labelSizer4->Add(infoBtn4, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2335 labelSizer4->Add(new wxStaticText(panel, wxID_ANY, "SubTree Expansion:"), 0, wxALIGN_CENTER_VERTICAL);
2336 sizer->Add(labelSizer4, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
2337 wxArrayString expansionChoices;
2338 expansionChoices.Add("Immediate");
2339 expansionChoices.Add("Lazy");
2340 expansionChoices.Add("Manual");
2341 m_subtreeExpansion = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, expansionChoices);
2342 m_subtreeExpansion->SetSelection(0);
2343 m_subtreeExpansion->SetToolTip("When to load and expand subtree references");
2344 sizer->Add(m_subtreeExpansion, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
2345 row++;
2346
2347 // Max recursion depth
2348 wxBoxSizer *labelSizer5 = new wxBoxSizer(wxHORIZONTAL);
2349 wxBitmap infoNormal5(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
2350 wxBitmap infoHover5(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
2351 wxBitmap infoPressed5(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
2352 wxBitmap infoDisabled5(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
2353 wxBitmapButton *infoBtn5 = new wxBitmapButton(panel, wxID_ANY, infoNormal5, wxDefaultPosition, wxSize(40, 40),
2354 wxBORDER_NONE | wxBU_EXACTFIT);
2355 infoBtn5->SetBitmapHover(infoHover5);
2356 infoBtn5->SetBitmapPressed(infoPressed5);
2357 infoBtn5->SetBitmapDisabled(infoDisabled5);
2358 infoBtn5->SetToolTip("Click for detailed information");
2359 infoBtn5->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
2360 wxString helpText = "MAX RECURSION DEPTH\n"
2361 "===========================================================\n\n"
2362 "Maximum depth of nested subtree references allowed. Prevents\n"
2363 "infinite recursion from circular subtree references.\n\n"
2364 "WHAT IS RECURSION DEPTH?\n"
2365 "The number of levels of subtree-within-subtree nesting:\n\n"
2366 "Depth 1: MainTree -> SubTreeA (1 level)\n"
2367 "Depth 2: MainTree -> SubTreeA -> SubTreeB (2 levels)\n"
2368 "Depth 3: MainTree -> SubTreeA -> SubTreeB -> SubTreeC\n\n"
2369 "CIRCULAR REFERENCE PROTECTION:\n"
2370 "This limit prevents infinite loops from circular references:\n"
2371 " TreeA references TreeB\n"
2372 " TreeB references TreeA <- CIRCULAR!\n"
2373 "Without limit: Infinite expansion and stack overflow\n"
2374 "With limit: Stops after N levels with clear error\n\n"
2375 "VALUE GUIDELINES:\n\n"
2376 "Very Low (1-10):\n"
2377 " - Simple trees with few subtree levels\n"
2378 " - Strict control over complexity\n"
2379 " - Fast circular reference detection\n\n"
2380 "Medium (10-100): RECOMMENDED\n"
2381 " - Handles most reasonable tree structures\n"
2382 " - Default value: 100\n"
2383 " - Good balance of safety and flexibility\n\n"
2384 "High (100-1000):\n"
2385 " - Very complex nested structures\n"
2386 " - Larger memory usage\n"
2387 " - Slower to detect circular refs\n\n"
2388 "EXAMPLE ERROR:\n"
2389 "Max depth = 10, actual nesting = 12:\n"
2390 " ERROR: Max recursion depth (10) exceeded.\n"
2391 " Subtree expansion stopped at: TreeA -> TreeB -> ... (10 levels)\n"
2392 " Possible circular reference detected.\n\n"
2393 "RECOMMENDATION:\n"
2394 "Keep default 100 - catches circular refs while allowing\n"
2395 "complex legitimate nesting. Increase only if you have\n"
2396 "verified deeply nested structures.";
2397 HelpDialog dlg(this, "Max Recursion Depth - Help", helpText);
2398 dlg.ShowModal();
2399 });
2400 labelSizer5->Add(infoBtn5, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2401 labelSizer5->Add(new wxStaticText(panel, wxID_ANY, "Max Recursion Depth:"), 0, wxALIGN_CENTER_VERTICAL);
2402 sizer->Add(labelSizer5, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
2403 m_maxRecursionDepth = new wxSpinCtrl(panel, wxID_ANY);
2404 m_maxRecursionDepth->SetRange(1, 1000);
2405 m_maxRecursionDepth->SetValue(100);
2406 m_maxRecursionDepth->SetToolTip("Prevent infinite loops from circular subtree references");
2407 sizer->Add(m_maxRecursionDepth, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
2408 row++;
2409
2410 // XML namespace
2411 wxBoxSizer *labelSizer8 = new wxBoxSizer(wxHORIZONTAL);
2412 wxBitmap infoNormal8(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
2413 wxBitmap infoHover8(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
2414 wxBitmap infoPressed8(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
2415 wxBitmap infoDisabled8(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
2416 wxBitmapButton *infoBtn8 = new wxBitmapButton(panel, wxID_ANY, infoNormal8, wxDefaultPosition, wxSize(40, 40),
2417 wxBORDER_NONE | wxBU_EXACTFIT);
2418 infoBtn8->SetBitmapHover(infoHover8);
2419 infoBtn8->SetBitmapPressed(infoPressed8);
2420 infoBtn8->SetBitmapDisabled(infoDisabled8);
2421 infoBtn8->SetToolTip("Click for detailed information");
2422 infoBtn8->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
2423 wxString helpText = "XML NAMESPACE URI\n"
2424 "===========================================================\n\n"
2425 "Optional XML namespace for behavior tree elements.\n"
2426 "Used for XML schema validation and element disambiguation.\n\n"
2427 "WHAT IS AN XML NAMESPACE?\n"
2428 "A unique identifier (usually a URI) that prevents naming\n"
2429 "conflicts between XML vocabularies.\n\n"
2430 "EXAMPLE WITHOUT NAMESPACE:\n"
2431 " <root>\n"
2432 " <BehaviorTree ID=\"AI\">\n"
2433 " <Sequence>...</Sequence>\n"
2434 " </BehaviorTree>\n"
2435 " </root>\n\n"
2436 "EXAMPLE WITH NAMESPACE:\n"
2437 " <root xmlns:bt=\"http://behaviortree.dev/bt/1.0\">\n"
2438 " <bt:BehaviorTree ID=\"AI\">\n"
2439 " <bt:Sequence>...</bt:Sequence>\n"
2440 " </bt:BehaviorTree>\n"
2441 " </root>\n\n"
2442 "WHEN TO USE:\n\n"
2443 "Leave Empty (Most Common):\n"
2444 " - Simple XML files\n"
2445 " - No naming conflicts\n"
2446 " - Cleaner XML\n"
2447 " - Easier to read/write\n\n"
2448 "Specify Namespace When:\n"
2449 " - Mixing multiple XML vocabularies\n"
2450 " - Need formal XML schema validation\n"
2451 " - Working with XML tools that require it\n"
2452 " - Preventing element name collisions\n\n"
2453 "COMMON NAMESPACE FORMATS:\n"
2454 " - http://behaviortree.dev/bt/1.0\n"
2455 " - urn:behaviortree:schema:1.0\n"
2456 " - http://example.com/schemas/bt\n\n"
2457 "Note: The URI doesn't need to be a real web address.\n"
2458 "It's just a unique identifier.\n\n"
2459 "IMPACT:\n"
2460 "If specified, all behavior tree elements must use the\n"
2461 "namespace prefix in your XML files.\n\n"
2462 "RECOMMENDATION:\n"
2463 "Leave empty unless you have specific requirements for\n"
2464 "namespace-based XML validation or element disambiguation.";
2465 HelpDialog dlg(this, "XML Namespace - Help", helpText);
2466 dlg.ShowModal();
2467 });
2468 labelSizer8->Add(infoBtn8, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2469 labelSizer8->Add(new wxStaticText(panel, wxID_ANY, "XML Namespace URI:"), 0, wxALIGN_CENTER_VERTICAL);
2470 sizer->Add(labelSizer8, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
2471 m_xmlNamespace = new wxTextCtrl(panel, wxID_ANY);
2472 m_xmlNamespace->SetToolTip("Optional namespace URI (e.g., http://behaviortree.dev/bt/1.0)");
2473 sizer->Add(m_xmlNamespace, wxGBPosition(row, 1), wxDefaultSpan, wxEXPAND);
2474 row++;
2475
2476 // Preserve comments
2477 wxBoxSizer *labelSizer9 = new wxBoxSizer(wxHORIZONTAL);
2478 wxBitmap infoNormal9(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
2479 wxBitmap infoHover9(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
2480 wxBitmap infoPressed9(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
2481 wxBitmap infoDisabled9(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
2482 wxBitmapButton *infoBtn9 = new wxBitmapButton(panel, wxID_ANY, infoNormal9, wxDefaultPosition, wxSize(40, 40),
2483 wxBORDER_NONE | wxBU_EXACTFIT);
2484 infoBtn9->SetBitmapHover(infoHover9);
2485 infoBtn9->SetBitmapPressed(infoPressed9);
2486 infoBtn9->SetBitmapDisabled(infoDisabled9);
2487 infoBtn9->SetToolTip("Click for detailed information");
2488 infoBtn9->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
2489 wxString helpText = "PRESERVE XML COMMENTS\n"
2490 "===========================================================\n\n"
2491 "Controls whether XML comments are kept in memory after parsing.\n\n"
2492 "ENABLED:\n"
2493 " - Comments stored in parsed tree structure\n"
2494 " - Can be accessed programmatically\n"
2495 " - Preserved when saving/exporting trees\n"
2496 " - Useful for round-trip editing\n"
2497 " - Small memory overhead\n\n"
2498 "DISABLED (Default):\n"
2499 " - Comments discarded during parsing\n"
2500 " - Lower memory usage\n"
2501 " - Slightly faster parsing\n"
2502 " - Lost if tree is saved back to XML\n\n"
2503 "XML COMMENTS:\n"
2504 " <!-- This is a comment -->\n"
2505 " <!-- Comments can span\n"
2506 " multiple lines -->\n\n"
2507 "EXAMPLE:\n"
2508 " <BehaviorTree ID=\"AI\">\n"
2509 " <!-- This is the patrol sequence -->\n"
2510 " <Sequence>\n"
2511 " <Action name=\"Move\"/> <!-- Move forward -->\n"
2512 " </Sequence>\n"
2513 " </BehaviorTree>\n\n"
2514 "USE CASES:\n\n"
2515 "Enable when:\n"
2516 " - Building XML editor/viewer\n"
2517 " - Need to preserve documentation\n"
2518 " - Round-trip editing (load -> modify -> save)\n"
2519 " - Comments contain important metadata\n\n"
2520 "Disable when:\n"
2521 " - Only loading trees for execution\n"
2522 " - Memory is constrained\n"
2523 " - Comments are just temporary notes\n"
2524 " - Maximum parsing speed needed\n\n"
2525 "RECOMMENDATION:\n"
2526 "Enable if building an editor or if comments contain important\n"
2527 "information. Disable for runtime-only tree loading.";
2528 HelpDialog dlg(this, "Preserve Comments - Help", helpText);
2529 dlg.ShowModal();
2530 });
2531 labelSizer9->Add(infoBtn9, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2532 m_preserveComments = new wxCheckBox(panel, wxID_ANY, "Preserve XML Comments");
2533 m_preserveComments->SetToolTip("Keep comments in memory for round-trip editing");
2534 labelSizer9->Add(m_preserveComments, 0, wxALIGN_CENTER_VERTICAL);
2535 sizer->Add(labelSizer9, wxGBPosition(row, 0), wxGBSpan(1, 2));
2536 row++;
2537
2538 // Preserve attribute order
2539 wxBoxSizer *labelSizer10 = new wxBoxSizer(wxHORIZONTAL);
2540 wxBitmap infoNormal10(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
2541 wxBitmap infoHover10(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
2542 wxBitmap infoPressed10(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
2543 wxBitmap infoDisabled10(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
2544 wxBitmapButton *infoBtn10 = new wxBitmapButton(panel, wxID_ANY, infoNormal10, wxDefaultPosition, wxSize(40, 40),
2545 wxBORDER_NONE | wxBU_EXACTFIT);
2546 infoBtn10->SetBitmapHover(infoHover10);
2547 infoBtn10->SetBitmapPressed(infoPressed10);
2548 infoBtn10->SetBitmapDisabled(infoDisabled10);
2549 infoBtn10->SetToolTip("Click for detailed information");
2550 infoBtn10->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
2551 wxString helpText = "PRESERVE ATTRIBUTE ORDER\n"
2552 "===========================================================\n\n"
2553 "Controls whether the order of XML attributes is maintained\n"
2554 "exactly as they appear in the source file.\n\n"
2555 "ENABLED:\n"
2556 " - Attributes stored in original order\n"
2557 " - When saved, attributes appear in same order\n"
2558 " - Useful for version control (minimal diffs)\n"
2559 " - Slight memory/performance overhead\n"
2560 " - Better for human-edited XML\n\n"
2561 "DISABLED (Default):\n"
2562 " - Attributes may be reordered internally\n"
2563 " - Typically alphabetical order\n"
2564 " - Slightly more efficient\n"
2565 " - Doesn't affect functionality\n"
2566 " - Standard XML behavior\n\n"
2567 "XML ATTRIBUTE ORDER:\n\n"
2568 "Original XML:\n"
2569 " <Action name=\"Move\" speed=\"5.0\" target=\"enemy\"/>\n\n"
2570 "Preserved (enabled):\n"
2571 " <Action name=\"Move\" speed=\"5.0\" target=\"enemy\"/>\n"
2572 " (Exact same order)\n\n"
2573 "Not preserved (disabled):\n"
2574 " <Action name=\"Move\" speed=\"5.0\" target=\"enemy\"/>\n"
2575 " (May become: name, speed, target OR alphabetically)\n\n"
2576 "IMPORTANT NOTE:\n"
2577 "XML specification says attribute order is NOT significant.\n"
2578 "All XML parsers must work regardless of attribute order.\n\n"
2579 "USE CASES:\n\n"
2580 "Enable when:\n"
2581 " - Using version control (Git, SVN)\n"
2582 " - Want minimal diffs between versions\n"
2583 " - Hand-editing XML files\n"
2584 " - Order has semantic meaning to humans\n\n"
2585 "Disable when:\n"
2586 " - Pure runtime loading\n"
2587 " - No round-trip editing\n"
2588 " - Programmatically generated XML\n"
2589 " - Order doesn't matter\n\n"
2590 "RECOMMENDATION:\n"
2591 "Enable for editor applications and version-controlled files.\n"
2592 "Disable for runtime-only loading.";
2593 HelpDialog dlg(this, "Preserve Attribute Order - Help", helpText);
2594 dlg.ShowModal();
2595 });
2596 labelSizer10->Add(infoBtn10, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2597 m_preserveAttrOrder = new wxCheckBox(panel, wxID_ANY, "Preserve Attribute Order");
2598 m_preserveAttrOrder->SetToolTip("Maintain original attribute order for version control");
2599 labelSizer10->Add(m_preserveAttrOrder, 0, wxALIGN_CENTER_VERTICAL);
2600 sizer->Add(labelSizer10, wxGBPosition(row, 0), wxGBSpan(1, 2));
2601 row++;
2602
2603 sizer->AddGrowableCol(1);
2604 mainSizer->Add(sizer, 0, wxEXPAND | wxALL, 5);
2605
2606 // Add separator line
2607 mainSizer->Add(new wxStaticLine(panel), 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5);
2608
2609 // Custom validation rules section with toggle
2610 // Toggle checkbox for enabling/disabling custom validation
2611 m_enableCustomValidation = new wxCheckBox(panel, ID_TOGGLE_CUSTOM_VALIDATION, "Enable Custom Validation Rules");
2612 m_enableCustomValidation->SetValue(false); // Disabled by default
2613 m_enableCustomValidation->SetToolTip("Toggle custom validation rules on/off");
2614 mainSizer->Add(m_enableCustomValidation, 0, wxALL, 5);
2615
2616 // Custom validation rules (multiline)
2617 wxBoxSizer *rulesLabelSizer = new wxBoxSizer(wxHORIZONTAL);
2618 wxBitmap infoNormal11(GetResourcePath("buttons/info/Info_Normal_20.png"), wxBITMAP_TYPE_PNG);
2619 wxBitmap infoHover11(GetResourcePath("buttons/info/Info_Hovered_20.png"), wxBITMAP_TYPE_PNG);
2620 wxBitmap infoPressed11(GetResourcePath("buttons/info/Info_Pressed_20.png"), wxBITMAP_TYPE_PNG);
2621 wxBitmap infoDisabled11(GetResourcePath("buttons/info/Info_Disabled_20.png"), wxBITMAP_TYPE_PNG);
2622 wxBitmapButton *infoBtn11 = new wxBitmapButton(panel, wxID_ANY, infoNormal11, wxDefaultPosition, wxSize(40, 40),
2623 wxBORDER_NONE | wxBU_EXACTFIT);
2624 infoBtn11->SetBitmapHover(infoHover11);
2625 infoBtn11->SetBitmapPressed(infoPressed11);
2626 infoBtn11->SetBitmapDisabled(infoDisabled11);
2627 infoBtn11->SetToolTip("Click for detailed information");
2628 infoBtn11->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
2629 wxString helpText = "CUSTOM VALIDATION RULES\n"
2630 "===========================================================\n\n"
2631 "Define custom validation logic beyond standard XML schema validation.\n"
2632 "Specify rules using a simple scripting language or expressions.\n\n"
2633 "WHAT ARE VALIDATION RULES?\n"
2634 "Custom constraints that your behavior trees must satisfy:\n"
2635 " - Structural rules (e.g., Sequence must have 2+ children)\n"
2636 " - Naming conventions (e.g., Actions must start with verb)\n"
2637 " - Business logic (e.g., no more than 3 decorators deep)\n"
2638 " - Cross-tree references (e.g., all subtrees must exist)\n\n"
2639 "RULE FORMAT:\n"
2640 "One rule per line. Each rule has:\n"
2641 " - Condition: When to check\n"
2642 " - Validation: What to verify\n"
2643 " - Message: Error to show if fails\n\n"
2644 "EXAMPLE RULES:\n\n"
2645 "1. Structural Rule:\n"
2646 " node.type == 'Sequence' && node.children.count < 2:\n"
2647 " 'Sequence nodes must have at least 2 children'\n\n"
2648 "2. Naming Convention:\n"
2649 " node.type == 'Action' && !node.name.startsWithVerb():\n"
2650 " 'Action names must start with a verb'\n\n"
2651 "3. Decorator Depth:\n"
2652 " node.type == 'Decorator' && node.depth > 3:\n"
2653 " 'Decorators cannot be nested more than 3 levels'\n\n"
2654 "4. Required Attributes:\n"
2655 " node.type == 'Action' && !node.hasAttribute('timeout'):\n"
2656 " 'All actions must specify a timeout'\n\n"
2657 "5. Subtree References:\n"
2658 " node.type == 'SubTree' && !subtreeExists(node.ID):\n"
2659 " 'Referenced subtree does not exist'\n\n"
2660 "AVAILABLE PROPERTIES:\n"
2661 " - node.type: Node type (Action, Sequence, etc.)\n"
2662 " - node.name: Node name/ID\n"
2663 " - node.children.count: Number of child nodes\n"
2664 " - node.depth: Nesting level\n"
2665 " - node.attributes: Map of attributes\n"
2666 " - tree.ID: Current tree identifier\n\n"
2667 "WHEN VALIDATION RUNS:\n"
2668 " - After parsing completes\n"
2669 " - Before tree is made available to application\n"
2670 " - All rules checked, multiple errors reported\n\n"
2671 "ERROR HANDLING:\n"
2672 "If any rule fails:\n"
2673 " - Clear error message shown\n"
2674 " - Parse operation fails\n"
2675 " - Tree not loaded into memory\n\n"
2676 "PERFORMANCE:\n"
2677 " - Rules checked once at parse time\n"
2678 " - No runtime overhead\n"
2679 " - Complex rules may slow initial load\n\n"
2680 "RECOMMENDATION:\n"
2681 "Use for project-specific constraints that can't be expressed\n"
2682 "in XML schema. Keep rules simple and clear. Too many complex\n"
2683 "rules can make debugging difficult.";
2684 HelpDialog dlg(this, "Custom Validation Rules - Help", helpText);
2685 dlg.ShowModal();
2686 });
2687 rulesLabelSizer->Add(infoBtn11, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
2688 rulesLabelSizer->Add(new wxStaticText(panel, wxID_ANY, "Custom Validation Rules: ( experimental )"), 0,
2689 wxALIGN_CENTER_VERTICAL);
2690 mainSizer->Add(rulesLabelSizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 5);
2691 m_customValidation = new wxTextCtrl(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
2692 m_customValidation->SetMinSize(wxSize(-1, 100));
2693 m_customValidation->SetToolTip("Define custom validation expressions (one rule per line)");
2694 m_customValidation->Enable(false); // Disabled by default (matches checkbox state)
2695 mainSizer->Add(m_customValidation, 1, wxEXPAND | wxALL, 5);
2696
2697 panel->SetSizer(mainSizer);
2698 return panel;
2699}
2700
2701wxPanel *ParserConfigDialog::CreateBottomPanel(wxWindow *parent) {
2702 wxPanel *panel = new wxPanel(parent);
2703 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
2704
2705 // Profile metadata
2706 wxGridBagSizer *metaSizer = new wxGridBagSizer(5, 5);
2707
2708 metaSizer->Add(new wxStaticText(panel, wxID_ANY, "Profile Name:"), wxGBPosition(0, 0), wxDefaultSpan,
2709 wxALIGN_CENTER_VERTICAL);
2710 m_profileName = new wxTextCtrl(panel, wxID_ANY);
2711 metaSizer->Add(m_profileName, wxGBPosition(0, 1), wxDefaultSpan, wxEXPAND);
2712
2713 metaSizer->Add(new wxStaticText(panel, wxID_ANY, "Description:"), wxGBPosition(1, 0), wxDefaultSpan, wxALIGN_TOP);
2714 m_profileDescription = new wxTextCtrl(panel, wxID_ANY, "", wxDefaultPosition, wxSize(-1, 60), wxTE_MULTILINE);
2715 metaSizer->Add(m_profileDescription, wxGBPosition(1, 1), wxDefaultSpan, wxEXPAND);
2716
2717 metaSizer->AddGrowableCol(1);
2718 mainSizer->Add(metaSizer, 0, wxEXPAND | wxALL, 5);
2719
2720 // Buttons
2721 wxBoxSizer *btnSizer = new wxBoxSizer(wxHORIZONTAL);
2722
2723 m_testValidateBtn = new wxButton(panel, ID_TEST_VALIDATE, "Test/Validate");
2724 btnSizer->Add(m_testValidateBtn, 0, wxALL, 2);
2725
2726 m_previewJSONBtn = new wxButton(panel, ID_PREVIEW_JSON, "Preview JSON");
2727 btnSizer->Add(m_previewJSONBtn, 0, wxALL, 2);
2728
2729 m_resetDefaultsBtn = new wxButton(panel, ID_RESET_DEFAULTS, "Reset to Defaults");
2730 btnSizer->Add(m_resetDefaultsBtn, 0, wxALL, 2);
2731
2732 btnSizer->AddStretchSpacer();
2733
2734 m_saveBtn = new wxButton(panel, ID_SAVE, "Save");
2735 btnSizer->Add(m_saveBtn, 0, wxALL, 2);
2736
2737 m_saveAsBtn = new wxButton(panel, ID_SAVE_AS, "Save As...");
2738 btnSizer->Add(m_saveAsBtn, 0, wxALL, 2);
2739
2740 m_cancelBtn = new wxButton(panel, wxID_CANCEL, "Cancel");
2741 btnSizer->Add(m_cancelBtn, 0, wxALL, 2);
2742
2743 mainSizer->Add(btnSizer, 0, wxEXPAND | wxALL, 5);
2744
2745 panel->SetSizer(mainSizer);
2746 return panel;
2747}
2748
2749// This file is getting too long. I'll continue with event handlers in the next part...
2750// For now, let me add placeholder implementations
2751
2753 auto &configMgr = EmberCore::ConfigManager::GetInstance();
2754 auto profileNames = configMgr.GetProfileNames();
2755 wxString activeName(configMgr.GetActiveProfileName());
2756
2757 m_profileList->DeleteAllItems();
2758
2759 long activeIndex = -1;
2760 for (size_t i = 0; i < profileNames.size(); ++i) {
2761 const auto &name = profileNames[i];
2762
2763 // Add visual marker (*) for active profile and color it green
2764 wxString displayName = name;
2765 bool isActive = (name == activeName);
2766
2767 if (isActive) {
2768 displayName = wxString::FromUTF8("* ") + name; // Safe Unicode handling
2769 activeIndex = i;
2770 }
2771
2772 // Insert item into list
2773 long index = m_profileList->InsertItem(i, displayName);
2774
2775 // Set color: green for active, white for others
2776 if (isActive) {
2777 m_profileList->SetItemTextColour(index, wxColour(46, 125, 50)); // Dark green
2778 } else {
2779 m_profileList->SetItemTextColour(index, *wxWHITE); // White for inactive
2780 }
2781 }
2782
2783 // Select and load active profile
2784 if (activeIndex != -1) {
2785 m_profileList->SetItemState(activeIndex, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
2786 m_profileList->EnsureVisible(activeIndex);
2787 auto profile = configMgr.GetProfile(activeName.ToStdString());
2788 LoadProfileData(profile);
2789 }
2790}
2791
2792void ParserConfigDialog::LoadProfileData(std::shared_ptr<EmberCore::ParserProfile> profile) {
2793 if (!profile)
2794 return;
2795
2796 m_currentProfile = profile;
2797 m_profileName->SetValue(profile->GetName());
2798 m_profileDescription->SetValue(profile->GetDescription());
2799
2800 SetUIFromConfig(profile->GetConfig());
2801 m_modified = false;
2802}
2803
2805 // Tab 1: Document Structure
2806 const auto &docConfig = config.GetDocumentConfig();
2807 m_rootElement->SetValue(docConfig.root_element);
2808 m_mainTreeAttr->SetValue(docConfig.main_tree_attribute);
2809 m_caseSensitive->SetValue(docConfig.case_sensitive);
2810 m_allowUnknownElements->SetValue(docConfig.allow_unknown_elements);
2811 m_whitespaceHandling->SetSelection(static_cast<int>(docConfig.whitespace_handling));
2812
2813 // Set naming convention checkboxes
2814 m_namingConventionStrict->SetValue(docConfig.naming_convention ==
2816 m_namingConventionBalanced->SetValue(docConfig.naming_convention ==
2818 m_namingConventionLoose->SetValue(docConfig.naming_convention == EmberCore::ParserConfig::NamingConvention::LOOSE);
2819
2820 // Tab 2: Tree Elements
2821 const auto &treeConfig = config.GetTreeConfig();
2822 m_behaviorTreeElement->SetValue(treeConfig.behavior_tree_element);
2823 m_treeIdAttr->SetValue(treeConfig.tree_id_attribute);
2824 m_allowMultipleTrees->SetValue(treeConfig.allow_multiple_trees);
2825 m_subtreeElement->SetValue(treeConfig.subtree_element);
2826 m_subtreeRefAttr->SetValue(treeConfig.subtree_reference_attribute);
2827 m_validateStructure->SetValue(treeConfig.validate_tree_structure);
2828 m_requireRootNode->SetValue(treeConfig.require_root_node);
2829
2830 // Tab 3: Node Elements
2831 const auto &nodeConfig = config.GetNodeConfig();
2832 m_controlElement->SetValue(nodeConfig.control_element);
2833 m_actionElement->SetValue(nodeConfig.action_element);
2834 m_conditionElement->SetValue(nodeConfig.condition_element);
2835 m_decoratorElement->SetValue(nodeConfig.decorator_element);
2836 m_genericNodeElement->SetValue(nodeConfig.generic_node_element);
2837 m_nodeIdAttr->SetValue(nodeConfig.node_id_attribute);
2838 m_nodeNameAttr->SetValue(nodeConfig.node_name_attribute);
2839 m_nodeTypeAttr->SetValue(nodeConfig.node_type_attribute);
2840 m_allowCustomAttrs->SetValue(nodeConfig.allow_custom_attributes);
2841
2842 // Tab 4: Node Classification
2843 const auto &classConfig = config.GetClassificationConfig();
2844 m_classificationStrategy->SetSelection(static_cast<int>(classConfig.strategy));
2845
2846 m_controlTypesList->Clear();
2847 for (const auto &type : classConfig.control_types) {
2848 m_controlTypesList->Append(type);
2849 }
2850
2851 m_decoratorTypesList->Clear();
2852 for (const auto &type : classConfig.decorator_types) {
2853 m_decoratorTypesList->Append(type);
2854 }
2855
2856 m_actionTypesList->Clear();
2857 for (const auto &type : classConfig.action_types) {
2858 m_actionTypesList->Append(type);
2859 }
2860
2861 m_conditionTypesList->Clear();
2862 for (const auto &type : classConfig.condition_types) {
2863 m_conditionTypesList->Append(type);
2864 }
2865
2866 m_unknownBehavior->SetSelection(static_cast<int>(classConfig.unknown_behavior));
2867 m_typeAttrName->SetValue(classConfig.type_attribute_name);
2868
2869 // Tab 5: Blackboard
2870 const auto &bbConfig = config.GetBlackboardConfig();
2871 m_blackboardElement->SetValue(bbConfig.blackboard_element);
2872 m_blackboardIdAttr->SetValue(bbConfig.blackboard_id_attribute);
2873 m_blackboardParentAttr->SetValue(bbConfig.parent_attribute);
2874 m_entryElement->SetValue(bbConfig.entry_element);
2875 m_entryKeyAttr->SetValue(bbConfig.entry_key_attribute);
2876 m_entryTypeAttr->SetValue(bbConfig.entry_type_attribute);
2877 m_entryValueAttr->SetValue(bbConfig.entry_value_attribute);
2878 m_allowUndefinedKeys->SetValue(bbConfig.allow_undefined_keys);
2879
2880 // Type mappings
2881 if (m_typeMappingsGrid->GetNumberRows() > 0) {
2882 m_typeMappingsGrid->DeleteRows(0, m_typeMappingsGrid->GetNumberRows());
2883 }
2884 for (const auto &mapping : bbConfig.type_mappings) {
2885 int row = m_typeMappingsGrid->GetNumberRows();
2886 m_typeMappingsGrid->AppendRows(1);
2887 m_typeMappingsGrid->SetCellValue(row, 0, mapping.first);
2888 m_typeMappingsGrid->SetCellValue(row, 1, mapping.second);
2889 }
2890
2891 // Tab 6: Advanced
2892 const auto &advConfig = config.GetAdvancedConfig();
2893 m_enableProgressReporting->SetValue(advConfig.enable_progress_reporting);
2894 m_detailedErrors->SetValue(advConfig.detailed_error_messages);
2895 m_trackLineColumn->SetValue(advConfig.track_line_column);
2896 m_subtreeExpansion->SetSelection(static_cast<int>(advConfig.subtree_expansion));
2897 m_maxRecursionDepth->SetValue(advConfig.max_recursion_depth);
2898 m_xmlNamespace->SetValue(advConfig.xml_namespace_uri);
2899 m_preserveComments->SetValue(advConfig.preserve_comments);
2900 m_preserveAttrOrder->SetValue(advConfig.preserve_attribute_order);
2901 m_customValidation->SetValue(advConfig.custom_validation_rules);
2902
2903 // Enable the custom validation toggle if there are rules loaded
2904 bool hasCustomRules = !advConfig.custom_validation_rules.empty();
2905 m_enableCustomValidation->SetValue(hasCustomRules);
2906 m_customValidation->Enable(hasCustomRules);
2907}
2908
2909// Placeholder event handlers - full implementation would go here
2911 long selectedIndex = m_profileList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2912 if (selectedIndex == -1)
2913 return;
2914
2915 wxString profileName = m_profileList->GetItemText(selectedIndex);
2916
2917 // Remove the "* " prefix if present (active profile marker)
2918 if (profileName.StartsWith(wxString::FromUTF8("* "))) {
2919 profileName = profileName.Mid(2); // Skip first 2 characters
2920 }
2921
2922 // Save the current profile before switching if there are changes
2924
2925 // Now load the new profile
2926 auto &configMgr = EmberCore::ConfigManager::GetInstance();
2927 auto profile = configMgr.GetProfile(profileName.ToStdString());
2928 LoadProfileData(profile);
2929}
2930
2931void ParserConfigDialog::OnNewProfile(wxCommandEvent &event) {
2932 // Save current profile before creating a new one
2934
2935 wxTextEntryDialog dialog(this, "Enter new profile name:", "New Profile");
2936 if (dialog.ShowModal() == wxID_OK) {
2937 wxString name = dialog.GetValue();
2938 if (!name.IsEmpty()) {
2939 auto profile = std::make_shared<EmberCore::ParserProfile>(name.ToStdString(), "");
2940 auto &configMgr = EmberCore::ConfigManager::GetInstance();
2941 if (configMgr.AddProfile(profile)) {
2942 LoadProfiles();
2943
2944 // Find and select the new profile
2945 long index = m_profileList->FindItem(-1, name);
2946 if (index != wxNOT_FOUND) {
2947 m_profileList->SetItemState(index, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
2948 m_profileList->EnsureVisible(index);
2949 LoadProfileData(profile);
2950 }
2951 }
2952 }
2953 }
2954}
2955
2956void ParserConfigDialog::OnCloneProfile(wxCommandEvent &event) {
2957 if (!m_currentProfile)
2958 return;
2959
2960 // First, save any unsaved changes to the current profile
2962
2963 wxTextEntryDialog dialog(this, "Enter name for cloned profile:", "Clone Profile",
2964 m_currentProfile->GetName() + " (Copy)");
2965 if (dialog.ShowModal() == wxID_OK) {
2966 wxString name = dialog.GetValue();
2967 if (!name.IsEmpty()) {
2968 // Clone the profile with its current (saved) state
2969 auto cloned = m_currentProfile->Clone(name.ToStdString());
2970 auto &configMgr = EmberCore::ConfigManager::GetInstance();
2971 if (configMgr.AddProfile(cloned)) {
2972 LoadProfiles();
2973
2974 // Find and select the cloned profile
2975 long index = m_profileList->FindItem(-1, name);
2976 if (index != wxNOT_FOUND) {
2977 m_profileList->SetItemState(index, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
2978 m_profileList->EnsureVisible(index);
2979 LoadProfileData(cloned);
2980 }
2981 }
2982 }
2983 }
2984}
2985
2986void ParserConfigDialog::OnDeleteProfile(wxCommandEvent &event) {
2987 long selectedIndex = m_profileList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
2988 if (selectedIndex == -1)
2989 return;
2990
2991 wxString profileName = m_profileList->GetItemText(selectedIndex);
2992
2993 // Remove the "* " prefix if present (active profile marker)
2994 if (profileName.StartsWith(wxString::FromUTF8("* "))) {
2995 profileName = profileName.Mid(2);
2996 }
2997
2998 if (wxMessageBox("Are you sure you want to delete this profile?", "Confirm Delete", wxYES_NO | wxICON_QUESTION,
2999 this) == wxYES) {
3000 auto &configMgr = EmberCore::ConfigManager::GetInstance();
3001 if (configMgr.RemoveProfile(profileName.ToStdString())) {
3002 LoadProfiles();
3003 }
3004 }
3005}
3006
3007void ParserConfigDialog::OnImportProfile(wxCommandEvent &event) {
3008 // Save current profile before importing a new one
3010
3011 // Use the profiles directory as default
3012 auto &configMgr = EmberCore::ConfigManager::GetInstance();
3013 wxString defaultDir = wxString(configMgr.GetProfilesDirectory());
3014
3015 wxFileDialog dialog(this, "Import Profile", defaultDir, "", "JSON files (*.json)|*.json",
3016 wxFD_OPEN | wxFD_FILE_MUST_EXIST);
3017 if (dialog.ShowModal() == wxID_OK) {
3018 if (configMgr.ImportProfile(dialog.GetPath().ToStdString(), false)) {
3019 LoadProfiles();
3020 wxMessageBox("Profile imported successfully", "Success", wxOK | wxICON_INFORMATION, this);
3021 } else {
3022 wxMessageBox("Failed to import profile", "Error", wxOK | wxICON_ERROR, this);
3023 }
3024 }
3025}
3026
3027void ParserConfigDialog::OnExportProfile(wxCommandEvent &event) {
3028 if (!m_currentProfile)
3029 return;
3030
3031 // Update profile with current UI state before exporting
3033
3034 // Use the profiles directory as default
3035 auto &configMgr = EmberCore::ConfigManager::GetInstance();
3036 wxString defaultDir = wxString(configMgr.GetProfilesDirectory());
3037 wxString defaultFilename = m_currentProfile->GetName() + ".json";
3038
3039 wxFileDialog dialog(this, "Export Profile", defaultDir, defaultFilename, "JSON files (*.json)|*.json",
3040 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
3041
3042 if (dialog.ShowModal() == wxID_OK) {
3043 wxString selectedPath = dialog.GetPath();
3044 wxFileName selectedFile(selectedPath);
3045 wxFileName defaultDirPath(defaultDir);
3046
3047 // Check if export location is outside the default profiles directory
3048 bool isOutsideDefaultDir = !selectedFile.GetPath().StartsWith(defaultDirPath.GetFullPath());
3049
3050 if (isOutsideDefaultDir) {
3051 int result = wxMessageBox("You are exporting to a location outside the default profiles directory.\n\n"
3052 "Default: " +
3053 defaultDir +
3054 "\n"
3055 "Selected: " +
3056 selectedFile.GetPath() +
3057 "\n\n"
3058 "Are you sure you want to export here?",
3059 "Confirm Export Location", wxYES_NO | wxICON_QUESTION, this);
3060
3061 if (result != wxYES) {
3062 return; // User cancelled
3063 }
3064 }
3065
3066 if (configMgr.ExportProfile(m_currentProfile->GetName(), selectedPath.ToStdString())) {
3067 wxMessageBox("Profile exported successfully to:\n" + selectedPath, "Success", wxOK | wxICON_INFORMATION,
3068 this);
3069 } else {
3070 wxMessageBox("Failed to export profile", "Error", wxOK | wxICON_ERROR, this);
3071 }
3072 }
3073}
3074
3075void ParserConfigDialog::OnSetActiveProfile(wxCommandEvent &event) {
3076 if (!m_currentProfile)
3077 return;
3078
3079 // Save any changes before setting as active
3081
3082 auto &configMgr = EmberCore::ConfigManager::GetInstance();
3083 configMgr.SetActiveProfile(m_currentProfile->GetName());
3084
3085 // Refresh list to show new active marker (*)
3086 LoadProfiles();
3087
3088 wxMessageBox("Active profile set to: " + m_currentProfile->GetName(), "Success", wxOK | wxICON_INFORMATION, this);
3089}
3090
3091void ParserConfigDialog::OnTestValidate(wxCommandEvent &event) {
3092 wxString errorMsg;
3093 if (ValidateCurrentConfig(errorMsg)) {
3094 wxMessageBox("✓ Configuration is valid!\n\nAll required fields are filled and properly configured.",
3095 "Validation Success", wxOK | wxICON_INFORMATION, this);
3096 } else {
3097 // Use a custom dialog for better error display
3098 wxDialog errorDlg(this, wxID_ANY, "Configuration Validation Failed", wxDefaultPosition, wxSize(800, 600));
3099 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
3100
3101 // Title/icon row
3102 wxBoxSizer *titleSizer = new wxBoxSizer(wxHORIZONTAL);
3103 wxStaticText *titleText = new wxStaticText(&errorDlg, wxID_ANY, "âš  Configuration Validation Errors");
3104 wxFont titleFont = titleText->GetFont();
3105 titleFont.SetPointSize(12);
3106 titleFont.SetWeight(wxFONTWEIGHT_BOLD);
3107 titleText->SetFont(titleFont);
3108 titleText->SetForegroundColour(wxColour(255, 100, 100));
3109 titleSizer->Add(titleText, 0, wxALL, 10);
3110 sizer->Add(titleSizer, 0, wxEXPAND);
3111
3112 // Error message text control
3113 wxTextCtrl *textCtrl = new wxTextCtrl(&errorDlg, wxID_ANY, errorMsg, wxDefaultPosition, wxDefaultSize,
3114 wxTE_MULTILINE | wxTE_READONLY | wxTE_WORDWRAP);
3115
3116 // Use monospace font for better readability
3117 wxFont monoFont(10, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
3118 textCtrl->SetFont(monoFont);
3119
3120 // Dark theme
3121 textCtrl->SetBackgroundColour(wxColour(50, 50, 50));
3122 textCtrl->SetForegroundColour(wxColour(255, 255, 255));
3123
3124 sizer->Add(textCtrl, 1, wxEXPAND | wxALL, 10);
3125
3126 // Close button
3127 wxButton *closeBtn = new wxButton(&errorDlg, wxID_OK, "Close");
3128 sizer->Add(closeBtn, 0, wxALIGN_CENTER | wxALL, 10);
3129
3130 errorDlg.SetSizer(sizer);
3131 errorDlg.ShowModal();
3132 }
3133}
3134
3135void ParserConfigDialog::OnPreviewJSON(wxCommandEvent &event) {
3136 if (!m_currentProfile)
3137 return;
3138
3139 auto config = GetConfigFromUI();
3140 m_currentProfile->SetConfig(*config);
3141
3142 auto json = m_currentProfile->ToJson();
3143 wxString jsonStr(json.dump(4));
3144
3145 wxDialog previewDlg(this, wxID_ANY, "JSON Preview", wxDefaultPosition, wxSize(600, 500));
3146 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
3147 wxTextCtrl *textCtrl = new wxTextCtrl(&previewDlg, wxID_ANY, jsonStr, wxDefaultPosition, wxDefaultSize,
3148 wxTE_MULTILINE | wxTE_READONLY);
3149 sizer->Add(textCtrl, 1, wxEXPAND | wxALL, 10);
3150 wxButton *closeBtn = new wxButton(&previewDlg, wxID_OK, "Close");
3151 sizer->Add(closeBtn, 0, wxALIGN_CENTER | wxALL, 10);
3152 previewDlg.SetSizer(sizer);
3153 previewDlg.ShowModal();
3154}
3155
3156void ParserConfigDialog::OnResetDefaults(wxCommandEvent &event) {
3157 if (wxMessageBox("Reset current profile to default values?", "Confirm Reset", wxYES_NO | wxICON_QUESTION, this) ==
3158 wxYES) {
3159 auto defaultConfig = EmberCore::ParserConfig::CreateDefault();
3160 SetUIFromConfig(defaultConfig);
3161 m_modified = true;
3162 }
3163}
3164
3165void ParserConfigDialog::OnSave(wxCommandEvent &event) {
3167 EndModal(wxID_OK);
3168}
3169
3170void ParserConfigDialog::OnSaveAs(wxCommandEvent &event) {
3171 wxTextEntryDialog dialog(this, "Enter name for new profile:", "Save As");
3172 if (dialog.ShowModal() == wxID_OK) {
3173 wxString name = dialog.GetValue();
3174 if (!name.IsEmpty()) {
3175 auto profile = std::make_shared<EmberCore::ParserProfile>(name.ToStdString(),
3176 m_profileDescription->GetValue().ToStdString());
3177 auto config = GetConfigFromUI();
3178 profile->SetConfig(*config);
3179
3180 auto &configMgr = EmberCore::ConfigManager::GetInstance();
3181 if (configMgr.AddProfile(profile)) {
3182 m_currentProfile = profile;
3183 LoadProfiles();
3184 wxMessageBox("Profile saved as: " + name, "Success", wxOK | wxICON_INFORMATION, this);
3185 }
3186 }
3187 }
3188}
3189
3190void ParserConfigDialog::OnCancel(wxCommandEvent &event) {
3191 if (m_modified) {
3192 if (wxMessageBox("Discard unsaved changes?", "Confirm Cancel", wxYES_NO | wxICON_QUESTION, this) != wxYES) {
3193 return;
3194 }
3195 }
3196 EndModal(wxID_CANCEL);
3197}
3198
3199// Add/Remove button handlers (simplified implementations)
3200void ParserConfigDialog::OnAddControlType(wxCommandEvent &event) {
3201 wxTextEntryDialog dialog(this, "Enter control type name:", "Add Control Type");
3202 if (dialog.ShowModal() == wxID_OK && !dialog.GetValue().IsEmpty()) {
3203 m_controlTypesList->Append(dialog.GetValue());
3204 m_modified = true;
3205 }
3206}
3207
3208void ParserConfigDialog::OnRemoveControlType(wxCommandEvent &event) {
3209 int sel = m_controlTypesList->GetSelection();
3210 if (sel != wxNOT_FOUND) {
3211 m_controlTypesList->Delete(sel);
3212 m_modified = true;
3213 }
3214}
3215
3216void ParserConfigDialog::OnAddDecoratorType(wxCommandEvent &event) {
3217 wxTextEntryDialog dialog(this, "Enter decorator type name:", "Add Decorator Type");
3218 if (dialog.ShowModal() == wxID_OK && !dialog.GetValue().IsEmpty()) {
3219 m_decoratorTypesList->Append(dialog.GetValue());
3220 m_modified = true;
3221 }
3222}
3223
3225 int sel = m_decoratorTypesList->GetSelection();
3226 if (sel != wxNOT_FOUND) {
3227 m_decoratorTypesList->Delete(sel);
3228 m_modified = true;
3229 }
3230}
3231
3232void ParserConfigDialog::OnAddActionType(wxCommandEvent &event) {
3233 wxTextEntryDialog dialog(this, "Enter action type name:", "Add Action Type");
3234 if (dialog.ShowModal() == wxID_OK && !dialog.GetValue().IsEmpty()) {
3235 m_actionTypesList->Append(dialog.GetValue());
3236 m_modified = true;
3237 }
3238}
3239
3240void ParserConfigDialog::OnRemoveActionType(wxCommandEvent &event) {
3241 int sel = m_actionTypesList->GetSelection();
3242 if (sel != wxNOT_FOUND) {
3243 m_actionTypesList->Delete(sel);
3244 m_modified = true;
3245 }
3246}
3247
3248void ParserConfigDialog::OnAddConditionType(wxCommandEvent &event) {
3249 wxTextEntryDialog dialog(this, "Enter condition type name:", "Add Condition Type");
3250 if (dialog.ShowModal() == wxID_OK && !dialog.GetValue().IsEmpty()) {
3251 m_conditionTypesList->Append(dialog.GetValue());
3252 m_modified = true;
3253 }
3254}
3255
3257 int sel = m_conditionTypesList->GetSelection();
3258 if (sel != wxNOT_FOUND) {
3259 m_conditionTypesList->Delete(sel);
3260 m_modified = true;
3261 }
3262}
3263
3264void ParserConfigDialog::OnAddTypeMapping(wxCommandEvent &event) {
3265 m_typeMappingsGrid->AppendRows(1);
3266 m_modified = true;
3267}
3268
3269void ParserConfigDialog::OnRemoveTypeMapping(wxCommandEvent &event) {
3270 wxArrayInt rows = m_typeMappingsGrid->GetSelectedRows();
3271 if (rows.GetCount() > 0) {
3272 m_typeMappingsGrid->DeleteRows(rows[0], 1);
3273 m_modified = true;
3274 }
3275}
3276
3278 bool enabled = m_enableCustomValidation->GetValue();
3279 m_customValidation->Enable(enabled);
3280
3281 // If disabling, optionally clear the content to make it clear no rules are active
3282 // Uncomment the next line if you want to clear rules when disabling
3283 // if (!enabled) m_customValidation->Clear();
3284
3285 m_modified = true;
3286}
3287
3289 if (!m_currentProfile)
3290 return;
3291
3292 m_currentProfile->SetName(m_profileName->GetValue().ToStdString());
3293 m_currentProfile->SetDescription(m_profileDescription->GetValue().ToStdString());
3294
3295 auto config = GetConfigFromUI();
3296 m_currentProfile->SetConfig(*config);
3297
3298 auto &configMgr = EmberCore::ConfigManager::GetInstance();
3299 configMgr.SaveProfile(m_currentProfile->GetName());
3300
3301 m_modified = false;
3302}
3303
3309
3310std::shared_ptr<EmberCore::ParserConfig> ParserConfigDialog::GetConfigFromUI() {
3311 auto config = std::make_shared<EmberCore::ParserConfig>();
3312
3313 // Tab 1: Document Structure
3314 auto &docConfig = config->GetDocumentConfig();
3315 docConfig.root_element = m_rootElement->GetValue().ToStdString();
3316 docConfig.main_tree_attribute = m_mainTreeAttr->GetValue().ToStdString();
3317 docConfig.case_sensitive = m_caseSensitive->GetValue();
3318 docConfig.allow_unknown_elements = m_allowUnknownElements->GetValue();
3319 docConfig.whitespace_handling =
3321
3322 // Get naming convention from checkboxes
3323 if (m_namingConventionStrict->GetValue()) {
3324 docConfig.naming_convention = EmberCore::ParserConfig::NamingConvention::STRICT;
3325 } else if (m_namingConventionBalanced->GetValue()) {
3326 docConfig.naming_convention = EmberCore::ParserConfig::NamingConvention::BALANCED;
3327 } else if (m_namingConventionLoose->GetValue()) {
3328 docConfig.naming_convention = EmberCore::ParserConfig::NamingConvention::LOOSE;
3329 } else {
3330 // Default to BALANCED if none is selected
3331 docConfig.naming_convention = EmberCore::ParserConfig::NamingConvention::BALANCED;
3332 }
3333
3334 // Tab 2: Tree Elements
3335 auto &treeConfig = config->GetTreeConfig();
3336 treeConfig.behavior_tree_element = m_behaviorTreeElement->GetValue().ToStdString();
3337 treeConfig.tree_id_attribute = m_treeIdAttr->GetValue().ToStdString();
3338 treeConfig.allow_multiple_trees = m_allowMultipleTrees->GetValue();
3339 treeConfig.subtree_element = m_subtreeElement->GetValue().ToStdString();
3340 treeConfig.subtree_reference_attribute = m_subtreeRefAttr->GetValue().ToStdString();
3341 treeConfig.validate_tree_structure = m_validateStructure->GetValue();
3342 treeConfig.require_root_node = m_requireRootNode->GetValue();
3343
3344 // Tab 3: Node Elements
3345 auto &nodeConfig = config->GetNodeConfig();
3346 nodeConfig.control_element = m_controlElement->GetValue().ToStdString();
3347 nodeConfig.action_element = m_actionElement->GetValue().ToStdString();
3348 nodeConfig.condition_element = m_conditionElement->GetValue().ToStdString();
3349 nodeConfig.decorator_element = m_decoratorElement->GetValue().ToStdString();
3350 nodeConfig.generic_node_element = m_genericNodeElement->GetValue().ToStdString();
3351 nodeConfig.node_id_attribute = m_nodeIdAttr->GetValue().ToStdString();
3352 nodeConfig.node_name_attribute = m_nodeNameAttr->GetValue().ToStdString();
3353 nodeConfig.node_type_attribute = m_nodeTypeAttr->GetValue().ToStdString();
3354 nodeConfig.allow_custom_attributes = m_allowCustomAttrs->GetValue();
3355
3356 // Tab 4: Node Classification
3357 auto &classConfig = config->GetClassificationConfig();
3358 classConfig.strategy =
3360
3361 classConfig.control_types.clear();
3362 for (unsigned int i = 0; i < m_controlTypesList->GetCount(); i++) {
3363 classConfig.control_types.push_back(m_controlTypesList->GetString(i).ToStdString());
3364 }
3365
3366 classConfig.decorator_types.clear();
3367 for (unsigned int i = 0; i < m_decoratorTypesList->GetCount(); i++) {
3368 classConfig.decorator_types.push_back(m_decoratorTypesList->GetString(i).ToStdString());
3369 }
3370
3371 classConfig.action_types.clear();
3372 for (unsigned int i = 0; i < m_actionTypesList->GetCount(); i++) {
3373 classConfig.action_types.push_back(m_actionTypesList->GetString(i).ToStdString());
3374 }
3375
3376 classConfig.condition_types.clear();
3377 for (unsigned int i = 0; i < m_conditionTypesList->GetCount(); i++) {
3378 classConfig.condition_types.push_back(m_conditionTypesList->GetString(i).ToStdString());
3379 }
3380
3381 classConfig.unknown_behavior =
3383 classConfig.type_attribute_name = m_typeAttrName->GetValue().ToStdString();
3384
3385 // Tab 5: Blackboard
3386 auto &bbConfig = config->GetBlackboardConfig();
3387 bbConfig.blackboard_element = m_blackboardElement->GetValue().ToStdString();
3388 bbConfig.blackboard_id_attribute = m_blackboardIdAttr->GetValue().ToStdString();
3389 bbConfig.parent_attribute = m_blackboardParentAttr->GetValue().ToStdString();
3390 bbConfig.entry_element = m_entryElement->GetValue().ToStdString();
3391 bbConfig.entry_key_attribute = m_entryKeyAttr->GetValue().ToStdString();
3392 bbConfig.entry_type_attribute = m_entryTypeAttr->GetValue().ToStdString();
3393 bbConfig.entry_value_attribute = m_entryValueAttr->GetValue().ToStdString();
3394 bbConfig.allow_undefined_keys = m_allowUndefinedKeys->GetValue();
3395
3396 bbConfig.type_mappings.clear();
3397 for (int i = 0; i < m_typeMappingsGrid->GetNumberRows(); i++) {
3398 EmberCore::String xmlType = m_typeMappingsGrid->GetCellValue(i, 0).ToStdString();
3399 EmberCore::String internalType = m_typeMappingsGrid->GetCellValue(i, 1).ToStdString();
3400 if (!xmlType.empty() && !internalType.empty()) {
3401 bbConfig.type_mappings[xmlType] = internalType;
3402 }
3403 }
3404
3405 // Tab 6: Advanced
3406 auto &advConfig = config->GetAdvancedConfig();
3407 advConfig.enable_progress_reporting = m_enableProgressReporting->GetValue();
3408 advConfig.detailed_error_messages = m_detailedErrors->GetValue();
3409 advConfig.track_line_column = m_trackLineColumn->GetValue();
3410 advConfig.subtree_expansion =
3412 advConfig.max_recursion_depth = m_maxRecursionDepth->GetValue();
3413 advConfig.xml_namespace_uri = m_xmlNamespace->GetValue().ToStdString();
3414 advConfig.preserve_comments = m_preserveComments->GetValue();
3415 advConfig.preserve_attribute_order = m_preserveAttrOrder->GetValue();
3416
3417 // Only save custom validation rules if the toggle is enabled
3418 if (m_enableCustomValidation->GetValue()) {
3419 advConfig.custom_validation_rules = m_customValidation->GetValue().ToStdString();
3420 } else {
3421 advConfig.custom_validation_rules = "";
3422 }
3423
3424 return config;
3425}
3426
3428 bool hasErrors = false;
3429 int errorCount = 0;
3430 wxString detailedErrors;
3431
3432 // Helper lambda to add formatted error
3433 auto addError = [&](const wxString &page, const wxString &field, const wxString &issue) {
3434 errorCount++;
3435 detailedErrors += wxString::Format("%d. [Page: %s]\n"
3436 " Field: %s\n"
3437 " Issue: %s\n\n",
3438 errorCount, page, field, issue);
3439 hasErrors = true;
3440 };
3441
3442 // ========================================================================
3443 // PAGE 1: DOCUMENT STRUCTURE
3444 // ========================================================================
3445
3447 addError("Document Structure", "Root Element",
3448 "Required field is empty. Specify the XML root element name (e.g., 'root')");
3449 } else if (HasInvalidCharacters(m_rootElement)) {
3450 addError("Document Structure", "Root Element",
3451 wxString::Format("Invalid characters detected. XML names must start with a letter or underscore, "
3452 "and can ONLY contain letters (a-z, A-Z) and underscores (_). "
3453 "NO digits, hyphens, periods, or special characters allowed. Current value: '%s'",
3454 m_rootElement->GetValue()));
3455 }
3456
3458 addError("Document Structure", "Main Tree Attribute",
3459 "Required field is empty. Specify the attribute that identifies the main tree");
3461 addError(
3462 "Document Structure", "Main Tree Attribute",
3463 wxString::Format("Invalid characters detected. Only letters and underscores allowed. Current value: '%s'",
3464 m_mainTreeAttr->GetValue()));
3465 }
3466
3467 // ========================================================================
3468 // PAGE 2: TREE ELEMENTS
3469 // ========================================================================
3470
3472 addError("Tree Elements", "Behavior Tree Element",
3473 "Required field is empty. Specify the element name for behavior trees (e.g., 'BehaviorTree')");
3475 addError("Tree Elements", "Behavior Tree Element",
3476 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3477 m_behaviorTreeElement->GetValue()));
3478 }
3479
3481 addError("Tree Elements", "Tree ID Attribute",
3482 "Required field is empty. Specify the attribute that holds tree IDs (e.g., 'ID' or 'name')");
3483 } else if (HasInvalidCharacters(m_treeIdAttr)) {
3484 addError("Tree Elements", "Tree ID Attribute",
3485 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3486 m_treeIdAttr->GetValue()));
3487 }
3488
3490 addError("Tree Elements", "SubTree Element",
3491 "Required field is empty. Specify the element name for subtree references (e.g., 'SubTree')");
3493 addError("Tree Elements", "SubTree Element",
3494 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3495 m_subtreeElement->GetValue()));
3496 }
3497
3499 addError("Tree Elements", "SubTree Reference Attribute",
3500 "Required field is empty. Specify the attribute that references other trees (e.g., 'ID')");
3502 addError("Tree Elements", "SubTree Reference Attribute",
3503 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3504 m_subtreeRefAttr->GetValue()));
3505 }
3506
3507 // ========================================================================
3508 // PAGE 3: NODE ELEMENTS
3509 // ========================================================================
3510
3512 addError("Node Elements", "Control Node Element",
3513 "Required field is empty. Specify element name for control nodes (e.g., 'Control' or leave generic)");
3515 addError("Node Elements", "Control Node Element",
3516 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3517 m_controlElement->GetValue()));
3518 }
3519
3521 addError("Node Elements", "Action Node Element",
3522 "Required field is empty. Specify element name for action nodes (e.g., 'Action')");
3524 addError("Node Elements", "Action Node Element",
3525 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3526 m_actionElement->GetValue()));
3527 }
3528
3530 addError("Node Elements", "Condition Node Element",
3531 "Required field is empty. Specify element name for condition nodes (e.g., 'Condition')");
3533 addError("Node Elements", "Condition Node Element",
3534 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3535 m_conditionElement->GetValue()));
3536 }
3537
3539 addError("Node Elements", "Decorator Node Element",
3540 "Required field is empty. Specify element name for decorator nodes (e.g., 'Decorator')");
3542 addError("Node Elements", "Decorator Node Element",
3543 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3544 m_decoratorElement->GetValue()));
3545 }
3546
3548 addError("Node Elements", "Node Name Attribute",
3549 "Required field is empty. Specify the attribute for node names (e.g., 'name')");
3551 addError("Node Elements", "Node Name Attribute",
3552 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3553 m_nodeNameAttr->GetValue()));
3554 }
3555
3556 // ========================================================================
3557 // PAGE 4: BLACKBOARD
3558 // ========================================================================
3559
3561 addError("Blackboard", "Blackboard Element",
3562 "Required field is empty. Specify element name for blackboard (e.g., 'Blackboard')");
3564 addError("Blackboard", "Blackboard Element",
3565 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3566 m_blackboardElement->GetValue()));
3567 }
3568
3570 addError("Blackboard", "Blackboard ID Attribute",
3571 "Required field is empty. Specify the attribute for blackboard IDs (e.g., 'ID')");
3573 addError("Blackboard", "Blackboard ID Attribute",
3574 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3575 m_blackboardIdAttr->GetValue()));
3576 }
3577
3579 addError("Blackboard", "Entry Element",
3580 "Required field is empty. Specify element name for blackboard entries (e.g., 'Entry')");
3582 addError("Blackboard", "Entry Element",
3583 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3584 m_entryElement->GetValue()));
3585 }
3586
3588 addError("Blackboard", "Entry Key Attribute",
3589 "Required field is empty. Specify the attribute for entry keys (e.g., 'key')");
3591 addError("Blackboard", "Entry Key Attribute",
3592 wxString::Format("Invalid characters. Only letters and underscores allowed. Current value: '%s'",
3593 m_entryKeyAttr->GetValue()));
3594 }
3595
3596 // ========================================================================
3597 // PAGE 5: NODE CLASSIFICATION
3598 // ========================================================================
3599
3600 // Strategy must be selected
3601 if (m_classificationStrategy && m_classificationStrategy->GetSelection() == wxNOT_FOUND) {
3602 addError("Node Classification", "Classification Strategy",
3603 "No strategy selected. Choose: Element Name, Attribute-based, or Hybrid");
3604 }
3605
3606 // Check if type lists are needed but empty
3607 if (m_classificationStrategy && (m_classificationStrategy->GetSelection() == 0 ||
3608 m_classificationStrategy->GetSelection() == 2)) { // Element Name or Hybrid
3609
3610 if (m_controlTypesList && m_controlTypesList->GetCount() == 0) {
3611 addError("Node Classification", "Control Node Types List",
3612 "Using Element Name classification but control types list is empty. Add control node types (e.g., "
3613 "Sequence, Selector)");
3614 }
3615
3616 if (m_actionTypesList && m_actionTypesList->GetCount() == 0) {
3617 addError("Node Classification", "Action Node Types List",
3618 "Using Element Name classification but action types list is empty. Add action node types");
3619 }
3620
3621 if (m_conditionTypesList && m_conditionTypesList->GetCount() == 0) {
3622 addError("Node Classification", "Condition Node Types List",
3623 "Using Element Name classification but condition types list is empty. Add condition node types");
3624 }
3625
3626 if (m_decoratorTypesList && m_decoratorTypesList->GetCount() == 0) {
3627 addError("Node Classification", "Decorator Node Types List",
3628 "Using Element Name classification but decorator types list is empty. Add decorator node types");
3629 }
3630 }
3631
3632 // Check type attribute if using attribute-based classification
3633 if (m_classificationStrategy && (m_classificationStrategy->GetSelection() == 1 ||
3634 m_classificationStrategy->GetSelection() == 2)) { // Attribute or Hybrid
3635
3637 addError("Node Classification", "Type Attribute Name",
3638 "Using Attribute-based classification but type attribute is empty. Specify attribute name (e.g., "
3639 "'type')");
3640 }
3641 }
3642
3643 // ========================================================================
3644 // CROSS-PAGE VALIDATION
3645 // ========================================================================
3646
3647 // Check for duplicate element names across pages
3648 wxString btElement = m_behaviorTreeElement ? m_behaviorTreeElement->GetValue().Trim() : "";
3649 wxString stElement = m_subtreeElement ? m_subtreeElement->GetValue().Trim() : "";
3650 wxString bbElement = m_blackboardElement ? m_blackboardElement->GetValue().Trim() : "";
3651
3652 if (!btElement.IsEmpty() && btElement == stElement && btElement != "SubTree") {
3653 addError("Tree Elements", "Element Name Conflict",
3654 wxString::Format("BehaviorTree and SubTree use same element name '%s'. They should be different",
3655 btElement));
3656 }
3657
3658 if (!btElement.IsEmpty() && btElement == bbElement) {
3659 addError("Configuration Conflict", "Element Name Conflict",
3660 wxString::Format("BehaviorTree and Blackboard use same element name '%s'. They should be different",
3661 btElement));
3662 }
3663
3664 // ========================================================================
3665 // BUILD FINAL ERROR MESSAGE
3666 // ========================================================================
3667
3668 if (hasErrors) {
3669 errorMsg = wxString::Format("VALIDATION FAILED - Found %d error(s)\n"
3670 "========================================\n\n"
3671 "%s"
3672 "Please fix these issues before saving the configuration.\n"
3673 "Tip: Empty required fields are highlighted with a pulsing yellow background.",
3674 errorCount, detailedErrors);
3675 return false;
3676 }
3677
3678 // If UI validation passes, also run the config-level validation
3679 auto config = GetConfigFromUI();
3680 std::vector<EmberCore::String> configErrors;
3681
3682 if (!config->Validate(configErrors)) {
3683 errorMsg = "ADDITIONAL VALIDATION ERRORS\n"
3684 "========================================\n\n";
3685 for (const auto &err : configErrors) {
3686 errorMsg += wxString::Format("- %s\n", wxString(err));
3687 }
3688 return false;
3689 }
3690
3691 return true;
3692}
3693
3695
3697 m_notebook->Enable(enable);
3698 m_profileName->Enable(enable);
3699 m_profileDescription->Enable(enable);
3700 m_saveBtn->Enable(enable);
3701 m_saveAsBtn->Enable(enable);
3702}
3703
3705 long selectedIndex = m_profileList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
3706 if (selectedIndex == -1)
3707 return wxEmptyString;
3708 return m_profileList->GetItemText(selectedIndex);
3709}
3710
3711// ============================================================================
3712// PULSE ANIMATION IMPLEMENTATION
3713// ============================================================================
3714
3716 if (m_pulseTimer) {
3717 m_pulseTimer->Stop();
3718 delete m_pulseTimer;
3719 }
3720}
3721
3722void ParserConfigDialog::OnPulseTimer(wxTimerEvent &event) {
3723 // Increment phase (0.0 to 1.0, then wrap)
3724 m_pulsePhase += 0.02f; // Smooth increment
3725 if (m_pulsePhase > 1.0f) {
3726 m_pulsePhase = 0.0f;
3727 }
3728
3730}
3731
3733 // Use sinusoidal easing for smooth, natural pulse
3734 // sin gives values from 0 to 1 to 0 smoothly
3735 float t = std::sin(m_pulsePhase * 3.14159f * 2.0f) * 0.5f + 0.5f;
3736
3737 // List of all required text fields that should pulse when empty OR invalid
3738 wxTextCtrl *textFields[] = {m_rootElement, m_mainTreeAttr, m_behaviorTreeElement, m_treeIdAttr,
3744
3745 // Update each text field
3746 for (wxTextCtrl *field : textFields) {
3747 if (field && (IsFieldEmpty(field) || HasInvalidCharacters(field))) {
3748 // Field is empty OR has invalid characters - pulse yellow
3749 wxColour pulseColor = InterpolateColor(m_normalBg, m_highlightBg, t);
3750 field->SetBackgroundColour(pulseColor);
3751 field->Refresh();
3752 } else if (field) {
3753 // Field has valid content, use normal background
3754 field->SetBackgroundColour(m_normalBg);
3755 field->Refresh();
3756 }
3757 }
3758}
3759
3760wxColour ParserConfigDialog::InterpolateColor(const wxColour &color1, const wxColour &color2, float t) {
3761 // Clamp t to [0, 1]
3762 if (t < 0.0f)
3763 t = 0.0f;
3764 if (t > 1.0f)
3765 t = 1.0f;
3766
3767 // Linear interpolation of RGB components
3768 int r = static_cast<int>(color1.Red() + (color2.Red() - color1.Red()) * t);
3769 int g = static_cast<int>(color1.Green() + (color2.Green() - color1.Green()) * t);
3770 int b = static_cast<int>(color1.Blue() + (color2.Blue() - color1.Blue()) * t);
3771
3772 return wxColour(r, g, b);
3773}
3774
3775bool ParserConfigDialog::IsFieldEmpty(wxTextCtrl *field) {
3776 if (!field)
3777 return false;
3778 return field->GetValue().Trim().IsEmpty();
3779}
3780
3782 if (!field)
3783 return false;
3784 return field->GetSelection() == wxNOT_FOUND;
3785}
3786
3788 if (!field)
3789 return false;
3790
3791 wxString value = field->GetValue().Trim();
3792 if (value.IsEmpty())
3793 return false; // Empty is handled separately
3794
3795 // Use current naming convention for validation
3797}
3798
3802 } else if (m_namingConventionLoose && m_namingConventionLoose->GetValue()) {
3804 } else {
3805 // Default to BALANCED (including when m_namingConventionBalanced is checked)
3807 }
3808}
3809
3810bool ParserConfigDialog::IsValidXMLName(const wxString &name) {
3811 // Use current naming convention
3813}
3814
3816 if (name.IsEmpty())
3817 return true; // Empty is valid here (checked separately)
3818
3819 switch (convention) {
3821 // STRICT: Only letters (a-z, A-Z) and underscores (_)
3822 // - Must start with a letter or underscore
3823 // - Can ONLY contain letters and underscores
3824 // - NO digits, hyphens, or any other characters
3825 {
3826 wxChar firstChar = name[0];
3827 if (!wxIsalpha(firstChar) && firstChar != '_') {
3828 return false;
3829 }
3830
3831 for (size_t i = 0; i < name.Length(); i++) {
3832 wxChar c = name[i];
3833 if (!wxIsalpha(c) && c != '_') {
3834 return false;
3835 }
3836 }
3837 return true;
3838 }
3839
3841 // BALANCED: Letters, underscores, digits, and hyphens
3842 // - Must start with a letter or underscore
3843 // - Can contain letters, digits, underscores, and hyphens
3844 {
3845 wxChar firstChar = name[0];
3846 if (!wxIsalpha(firstChar) && firstChar != '_') {
3847 return false;
3848 }
3849
3850 for (size_t i = 0; i < name.Length(); i++) {
3851 wxChar c = name[i];
3852 if (!wxIsalpha(c) && !wxIsdigit(c) && c != '_' && c != '-') {
3853 return false;
3854 }
3855 }
3856 return true;
3857 }
3858
3860 // LOOSE: Follow XML 1.0 name rules (most permissive)
3861 // - Must start with letter, underscore, or colon
3862 // - Can contain letters, digits, underscores, hyphens, periods, colons
3863 // - Avoid only problematic characters like <, >, &, quotes, spaces
3864 {
3865 wxChar firstChar = name[0];
3866 // XML names can start with: letter, underscore, or colon
3867 if (!wxIsalpha(firstChar) && firstChar != '_' && firstChar != ':') {
3868 return false;
3869 }
3870
3871 for (size_t i = 0; i < name.Length(); i++) {
3872 wxChar c = name[i];
3873
3874 // Reject XML-breaking characters
3875 if (c == '<' || c == '>' || c == '&' || c == '"' || c == '\'' || wxIsspace(c) || c == '/' ||
3876 c == '\\' || c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}' || c == '=' ||
3877 c == '!' || c == '?' || c == '*' || c == '+' || c == '#' || c == '@' || c == '$' || c == '%' ||
3878 c == '^' || c == '~' || c == '`' || c == '|' || c == ';' || c == ',' ||
3879 c < 32) { // Also reject control characters
3880 return false;
3881 }
3882 }
3883 return true;
3884 }
3885
3886 default:
3887 return false;
3888 }
3889}
3890
3891void ParserConfigDialog::OnFieldChanged(wxCommandEvent &event) {
3892 // When a field changes, immediately update its color
3893 // (This ensures instant feedback when user starts typing)
3895 m_modified = true; // Mark profile as modified
3896 event.Skip();
3897}
3898
3899void ParserConfigDialog::OnAnyControlChanged(wxCommandEvent &event) {
3900 // Generic handler for checkboxes, choice controls, etc.
3901 m_modified = true;
3902 event.Skip();
3903}
3904
3906 // When naming convention changes, re-validate all fields with new rules
3907 // This will highlight fields that are now invalid under the new convention
3909 m_modified = true;
3910 event.Skip();
3911}
BehaviorTreeProjectDialog::OnProjectNameChanged BehaviorTreeProjectDialog::OnRemoveFiles wxEND_EVENT_TABLE() BehaviorTreeProjectDialog
MainFrame::OnExit MainFrame::OnNewProject MainFrame::OnCloseProject MainFrame::OnToggleMaximize MainFrame::OnPreviousScene MainFrame::OnPreferences MainFrame::OnEditorTool EVT_BUTTON(ID_MonitorTool, MainFrame::OnMonitorTool) EVT_PAINT(MainFrame
Definition MainFrame.cpp:63
static wxString GetResourcePath(const wxString &relativePath)
ParserConfigDialog::OnProfileSelected EVT_BUTTON(ID_NEW_PROFILE, ParserConfigDialog::OnNewProfile) EVT_BUTTON(ID_CLONE_PROFILE
wxBEGIN_EVENT_TABLE(ParserConfigDialog, wxDialog) EVT_LIST_ITEM_SELECTED(ID_PROFILE_LIST
ParserConfigDialog::OnProfileSelected ParserConfigDialog::OnCloneProfile ParserConfigDialog::OnImportProfile ParserConfigDialog::OnSetActiveProfile ParserConfigDialog::OnRemoveControlType ParserConfigDialog::OnRemoveDecoratorType ParserConfigDialog::OnRemoveActionType EVT_CHECKBOX(ID_TOGGLE_CUSTOM_VALIDATION, ParserConfigDialog::OnToggleCustomValidation) EVT_TIMER(ID_PULSE_TIMER
Centralized resource path management for EmberForge.
static ConfigManager & GetInstance()
Configuration for XML parser behavior and element/attribute mappings.
SubTreeExpansion
SubTree expansion strategy.
NamingConvention
Naming convention strictness.
DocumentConfig & GetDocumentConfig()
ClassificationStrategy
Strategy for classifying node types.
ClassificationConfig & GetClassificationConfig()
static ParserConfig CreateDefault()
AdvancedConfig & GetAdvancedConfig()
UnknownTypeBehavior
How to handle unknown/unmapped types.
WhitespaceHandling
Whitespace handling strategy.
TreeConfig & GetTreeConfig()
BlackboardConfig & GetBlackboardConfig()
NodeConfig & GetNodeConfig()
static wxString Get(const wxString &relativePath)
Get the full path to a resource file.
Simple scrollable dialog for displaying help text.
Comprehensive dialog for managing parser configuration profiles.
void OnSaveAs(wxCommandEvent &event)
wxCheckBox * m_allowUndefinedKeys
wxCheckBox * m_allowCustomAttrs
void OnAddControlType(wxCommandEvent &event)
wxTextCtrl * m_genericNodeElement
wxTextCtrl * m_blackboardParentAttr
wxPanel * CreateNodeClassificationTab(wxNotebook *notebook)
void OnRemoveConditionType(wxCommandEvent &event)
wxTextCtrl * m_entryValueAttr
void SetUIFromConfig(const EmberCore::ParserConfig &config)
wxTextCtrl * m_subtreeRefAttr
wxChoice * m_classificationStrategy
wxCheckBox * m_enableProgressReporting
wxTextCtrl * m_conditionElement
wxPanel * CreateNodeElementsTab(wxNotebook *notebook)
void OnRemoveActionType(wxCommandEvent &event)
wxTextCtrl * m_decoratorElement
void OnNewProfile(wxCommandEvent &event)
wxTextCtrl * m_blackboardElement
wxListBox * m_decoratorTypesList
void OnFieldChanged(wxCommandEvent &event)
void OnSetActiveProfile(wxCommandEvent &event)
wxTextCtrl * m_profileDescription
void OnAddActionType(wxCommandEvent &event)
wxCheckBox * m_preserveComments
wxPanel * CreateDocumentStructureTab(wxNotebook *notebook)
wxCheckBox * m_trackLineColumn
void OnExportProfile(wxCommandEvent &event)
wxString GetSelectedProfileName() const
wxCheckBox * m_namingConventionLoose
wxCheckBox * m_requireRootNode
wxListBox * m_conditionTypesList
wxTextCtrl * m_controlElement
void OnCloneProfile(wxCommandEvent &event)
wxButton * m_removeControlTypeBtn
wxButton * m_removeConditionTypeBtn
wxCheckBox * m_namingConventionStrict
void OnAnyControlChanged(wxCommandEvent &event)
void OnDeleteProfile(wxCommandEvent &event)
wxCheckBox * m_validateStructure
wxCheckBox * m_allowMultipleTrees
wxTextCtrl * m_blackboardIdAttr
wxCheckBox * m_allowUnknownElements
void OnToggleCustomValidation(wxCommandEvent &event)
bool HasInvalidCharacters(wxTextCtrl *field)
void OnPreviewJSON(wxCommandEvent &event)
void OnPulseTimer(wxTimerEvent &event)
wxTextCtrl * m_behaviorTreeElement
void OnCancel(wxCommandEvent &event)
void EnableProfileControls(bool enable)
bool IsValidXMLName(const wxString &name)
void OnRemoveTypeMapping(wxCommandEvent &event)
wxButton * m_removeDecoratorTypeBtn
wxPanel * CreateBlackboardTab(wxNotebook *notebook)
void OnAddTypeMapping(wxCommandEvent &event)
std::shared_ptr< EmberCore::ParserProfile > m_currentProfile
wxCheckBox * m_enableCustomValidation
wxCheckBox * m_preserveAttrOrder
void OnAddConditionType(wxCommandEvent &event)
bool IsFieldEmpty(wxTextCtrl *field)
void OnRemoveControlType(wxCommandEvent &event)
void OnTestValidate(wxCommandEvent &event)
EmberCore::ParserConfig::NamingConvention GetCurrentNamingConvention() const
void OnAddDecoratorType(wxCommandEvent &event)
wxPanel * CreateLeftSidebar(wxWindow *parent)
wxTextCtrl * m_subtreeElement
bool ValidateCurrentConfig(wxString &errorMsg)
wxTextCtrl * m_customValidation
wxCheckBox * m_namingConventionBalanced
void OnImportProfile(wxCommandEvent &event)
wxPanel * CreateTreeElementsTab(wxNotebook *notebook)
wxPanel * CreateBottomPanel(wxWindow *parent)
void OnNamingConventionChanged(wxCommandEvent &event)
void OnResetDefaults(wxCommandEvent &event)
wxSpinCtrl * m_maxRecursionDepth
wxColour InterpolateColor(const wxColour &color1, const wxColour &color2, float t)
void OnRemoveDecoratorType(wxCommandEvent &event)
void LoadProfileData(std::shared_ptr< EmberCore::ParserProfile > profile)
void OnSave(wxCommandEvent &event)
wxPanel * CreateAdvancedTab(wxNotebook *notebook)
wxCheckBox * m_detailedErrors
void OnProfileSelected(wxListEvent &event)
std::shared_ptr< EmberCore::ParserConfig > GetConfigFromUI()
wxPanel * CreateRightPanel(wxWindow *parent)
std::string String
Framework-agnostic string type.
Definition String.h:14