Ember
Loading...
Searching...
No Matches
TreeSelectorTab.cpp
Go to the documentation of this file.
2#include "App/MainFrame.h"
3#include "Core/BehaviorTree.h"
4#include "Core/Node.h"
5#include <algorithm>
6#include <wx/dcbuffer.h>
7#include <wx/menu.h>
8
17
18 static const int INDENT_PX = 18;
19static const int CONNECTOR_X_OFFSET = 10;
20static const int TOGGLE_SIZE = 10;
21static const int BASE_LEFT_PAD = 10;
22
23// ============================================================================
24// TreeListBox
25// ============================================================================
26
27TreeListBox::TreeListBox(TreeSelectorTab *owner, wxWindow *parent, wxWindowID id)
28 : wxVListBox(parent, id, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE), m_owner(owner) {
29 SetBackgroundColour(wxColour(45, 45, 50));
30 Bind(wxEVT_LEFT_DOWN, &TreeListBox::OnLeftDown, this);
31 Bind(wxEVT_RIGHT_DOWN, &TreeListBox::OnRightDown, this);
32}
33
34void TreeListBox::OnDrawBackground(wxDC &dc, const wxRect &rect, size_t n) const {
35 const auto &items = m_owner->GetFlatList();
36 if (n >= items.size())
37 return;
38
39 const auto &entry = items[n];
40
41 // Section headers get a distinct background
42 if (entry.isHeader) {
43 dc.SetBrush(wxBrush(wxColour(38, 40, 45)));
44 dc.SetPen(*wxTRANSPARENT_PEN);
45 dc.DrawRectangle(rect);
46 return;
47 }
48
49 bool isSelected = IsSelected(n);
50 bool isCurrent = (entry.id == m_owner->GetCurrentTreeId());
51
52 if (isSelected) {
53 dc.SetBrush(wxBrush(wxColour(55, 75, 100)));
54 } else if (isCurrent) {
55 dc.SetBrush(wxBrush(wxColour(50, 60, 75)));
56 } else if (n % 2 == 1) {
57 dc.SetBrush(wxBrush(wxColour(48, 48, 53)));
58 } else {
59 dc.SetBrush(wxBrush(wxColour(45, 45, 50)));
60 }
61 dc.SetPen(*wxTRANSPARENT_PEN);
62 dc.DrawRectangle(rect);
63
64 if (isCurrent) {
65 dc.SetBrush(wxBrush(wxColour(80, 160, 220)));
66 dc.SetPen(*wxTRANSPARENT_PEN);
67 dc.DrawRectangle(rect.x, rect.y + 4, 3, rect.height - 8);
68 }
69}
70
71void TreeListBox::OnDrawItem(wxDC &dc, const wxRect &rect, size_t n) const {
72 const auto &items = m_owner->GetFlatList();
73 if (n >= items.size())
74 return;
75
76 const auto &entry = items[n];
77
78 // Draw section headers specially
79 if (entry.isHeader) {
80 int leftPad = BASE_LEFT_PAD;
81
82 // Draw toggle arrow for section
83 int toggleX = leftPad;
84 int toggleY = rect.y + (rect.height / 2) - (TOGGLE_SIZE / 2);
85
86 dc.SetPen(wxPen(wxColour(180, 185, 195), 1));
87 dc.SetBrush(wxBrush(wxColour(180, 185, 195)));
88
89 if (entry.isCollapsed) {
90 wxPoint tri[3] = {wxPoint(toggleX, toggleY), wxPoint(toggleX, toggleY + TOGGLE_SIZE),
91 wxPoint(toggleX + TOGGLE_SIZE - 2, toggleY + TOGGLE_SIZE / 2)};
92 dc.DrawPolygon(3, tri);
93 } else {
94 wxPoint tri[3] = {wxPoint(toggleX, toggleY + 1), wxPoint(toggleX + TOGGLE_SIZE, toggleY + 1),
95 wxPoint(toggleX + TOGGLE_SIZE / 2, toggleY + TOGGLE_SIZE - 1)};
96 dc.DrawPolygon(3, tri);
97 }
98 leftPad += TOGGLE_SIZE + 6;
99
100 // Section header title - bold and larger
101 wxFont headerFont = GetFont();
102 headerFont.SetPointSize(11);
103 headerFont.SetWeight(wxFONTWEIGHT_BOLD);
104 dc.SetFont(headerFont);
105 dc.SetTextForeground(wxColour(200, 205, 215));
106
107 wxString headerText = wxString::FromUTF8(entry.displayName);
108 int textY = rect.y + (rect.height - dc.GetTextExtent(headerText).GetHeight()) / 2;
109 dc.DrawText(headerText, rect.x + leftPad, textY);
110
111 // Item count badge - positioned on the right
112 wxFont countFont = GetFont();
113 countFont.SetPointSize(9);
114 dc.SetFont(countFont);
115 dc.SetTextForeground(wxColour(130, 135, 145));
116
117 wxString countText = wxString::Format("(%d)", entry.sectionCount);
118 int countW = dc.GetTextExtent(countText).GetWidth();
119 int countX = rect.x + rect.width - countW - 10;
120 dc.DrawText(countText, countX, textY + 1);
121
122 // Draw separator line below header
123 dc.SetPen(wxPen(wxColour(60, 65, 75), 1));
124 dc.DrawLine(rect.x + 4, rect.y + rect.height - 1, rect.x + rect.width - 4, rect.y + rect.height - 1);
125
126 return;
127 }
128
129 bool isCurrent = (entry.id == m_owner->GetCurrentTreeId());
130 int depth = entry.depth;
131 int basePad = isCurrent ? BASE_LEFT_PAD + 4 : BASE_LEFT_PAD;
132 int leftPad = basePad + depth * INDENT_PX;
133
134 if (depth > 0) {
135 wxPen connPen(wxColour(80, 85, 95), 1);
136 dc.SetPen(connPen);
137
138 for (int d = 1; d < depth; ++d) {
139 if (d - 1 < static_cast<int>(entry.parentHasMore.size()) && entry.parentHasMore[d - 1]) {
140 int lineX = basePad + d * INDENT_PX - CONNECTOR_X_OFFSET;
141 dc.DrawLine(lineX, rect.y, lineX, rect.y + rect.height);
142 }
143 }
144
145 int connX = leftPad - CONNECTOR_X_OFFSET;
146 int midY = rect.y + rect.height / 2;
147 dc.DrawLine(connX, rect.y, connX, entry.isLastChild ? midY : rect.y + rect.height);
148 dc.DrawLine(connX, midY, connX + 8, midY);
149 }
150
151 if (entry.hasChildren) {
152 int toggleX = leftPad;
153 int toggleY = rect.y + (rect.height / 2) - (TOGGLE_SIZE / 2);
154
155 dc.SetPen(wxPen(wxColour(150, 155, 165), 1));
156
157 if (entry.isCollapsed) {
158 wxPoint tri[3] = {wxPoint(toggleX, toggleY), wxPoint(toggleX, toggleY + TOGGLE_SIZE),
159 wxPoint(toggleX + TOGGLE_SIZE - 2, toggleY + TOGGLE_SIZE / 2)};
160 dc.SetBrush(wxBrush(wxColour(150, 155, 165)));
161 dc.DrawPolygon(3, tri);
162 } else {
163 wxPoint tri[3] = {wxPoint(toggleX, toggleY + 1), wxPoint(toggleX + TOGGLE_SIZE, toggleY + 1),
164 wxPoint(toggleX + TOGGLE_SIZE / 2, toggleY + TOGGLE_SIZE - 1)};
165 dc.SetBrush(wxBrush(wxColour(150, 155, 165)));
166 dc.DrawPolygon(3, tri);
167 }
168 leftPad += TOGGLE_SIZE + 4;
169 } else {
170 leftPad += 4;
171 }
172
173 wxFont nameFont = GetFont();
174 nameFont.SetPointSize(10);
175 if (isCurrent)
176 nameFont.SetWeight(wxFONTWEIGHT_BOLD);
177 dc.SetFont(nameFont);
178
179 wxColour nameColour = isCurrent ? wxColour(230, 240, 255) : wxColour(210, 210, 215);
180 if (!entry.isImplemented)
181 nameColour = wxColour(140, 140, 155);
182 dc.SetTextForeground(nameColour);
183
184 wxString name = wxString::FromUTF8(entry.displayName);
185 int nameY = rect.y + 7;
186 dc.DrawText(name, rect.x + leftPad, nameY);
187
188 wxFont subFont = GetFont();
189 subFont.SetPointSize(8);
190 dc.SetFont(subFont);
191 dc.SetTextForeground(wxColour(110, 115, 125));
192
193 wxString info;
194 if (entry.nodeCount > 0) {
195 info = wxString::Format("%d node%s", entry.nodeCount, entry.nodeCount == 1 ? "" : "s");
196 }
197 if (!entry.isImplemented) {
198 if (!info.IsEmpty())
199 info += " - ";
200 info += "unimplemented";
201 }
202 if (depth > 0) {
203 if (!info.IsEmpty())
204 info += " - ";
205 info += "subtree";
206 }
207 if (entry.hasChildren && entry.isCollapsed) {
208 if (!info.IsEmpty())
209 info += " - ";
210 info += "collapsed";
211 }
212
213 if (!info.IsEmpty()) {
214 int infoY = nameY + dc.GetCharHeight() + 1;
215 dc.DrawText(info, rect.x + leftPad, infoY);
216 }
217}
218
219wxCoord TreeListBox::OnMeasureItem(size_t n) const {
220 const auto &items = m_owner->GetFlatList();
221 if (n < items.size() && items[n].isHeader) {
222 return 32;
223 }
224 return 44;
225}
226
227void TreeListBox::OnLeftDown(wxMouseEvent &event) {
228 int item = VirtualHitTest(event.GetPosition().y);
229 if (item == wxNOT_FOUND) {
230 event.Skip();
231 return;
232 }
233
234 const auto &items = m_owner->GetFlatList();
235 if (item < 0 || item >= static_cast<int>(items.size())) {
236 event.Skip();
237 return;
238 }
239
240 const auto &entry = items[item];
241
242 // Handle section header clicks
243 if (entry.isHeader) {
244 int toggleHitX = BASE_LEFT_PAD;
245 int clickX = event.GetPosition().x;
246
247 if (clickX >= toggleHitX && clickX < toggleHitX + TOGGLE_SIZE + 6) {
248 m_owner->ToggleSectionCollapse(entry.section);
249 return;
250 }
251 // Clicking anywhere on a header toggles it
252 m_owner->ToggleSectionCollapse(entry.section);
253 return;
254 }
255
256 if (entry.hasChildren) {
257 bool isCurrent = (entry.id == m_owner->GetCurrentTreeId());
258 int toggleHitX = m_owner->GetToggleHitX(entry.depth, isCurrent);
259 int clickX = event.GetPosition().x;
260
261 if (clickX >= toggleHitX && clickX < toggleHitX + TOGGLE_SIZE + 6) {
262 m_owner->ToggleCollapse(entry.id);
263 return;
264 }
265 }
266
267 event.Skip();
268}
269
270void TreeListBox::OnRightDown(wxMouseEvent &event) {
271 int item = VirtualHitTest(event.GetPosition().y);
272 if (item == wxNOT_FOUND) {
273 event.Skip();
274 return;
275 }
276
277 const auto &items = m_owner->GetFlatList();
278 if (item < 0 || item >= static_cast<int>(items.size())) {
279 event.Skip();
280 return;
281 }
282
283 // Skip context menu for section headers
284 if (items[item].isHeader) {
285 event.Skip();
286 return;
287 }
288
289 SetSelection(item);
290 Refresh();
291 m_owner->ShowContextMenu(item, event.GetPosition());
292}
293
294// ============================================================================
295// TreeSelectorTab
296// ============================================================================
297
298TreeSelectorTab::TreeSelectorTab(wxWindow *parent, MainFrame *mainFrame)
299 : wxPanel(parent, wxID_ANY), m_searchCtrl(nullptr), m_collapseAllBtn(nullptr), m_expandAllBtn(nullptr),
301 m_mainFrame(mainFrame) {
302 SetBackgroundColour(wxColour(45, 45, 50));
303 CreateLayout();
304}
305
307 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
308
310 new wxSearchCtrl(this, ID_SEARCH_CTRL, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
311 m_searchCtrl->SetDescriptiveText("Filter trees...");
312 m_searchCtrl->ShowSearchButton(true);
313 m_searchCtrl->ShowCancelButton(true);
314 m_searchCtrl->Bind(wxEVT_TEXT, &TreeSelectorTab::OnSearchTextChanged, this);
315 m_searchCtrl->Bind(wxEVT_SEARCHCTRL_SEARCH_BTN, &TreeSelectorTab::OnSearchTextChanged, this);
316 mainSizer->Add(m_searchCtrl, 0, wxEXPAND | wxALL, 4);
317
318 // Toolbar row with expand/collapse buttons
319 wxBoxSizer *toolbarSizer = new wxBoxSizer(wxHORIZONTAL);
321 new wxButton(this, ID_COLLAPSE_ALL_BTN, "Collapse All", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
323 new wxButton(this, ID_EXPAND_ALL_BTN, "Expand All", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
324 toolbarSizer->Add(m_collapseAllBtn, 0, wxRIGHT, 4);
325 toolbarSizer->Add(m_expandAllBtn, 0);
326 toolbarSizer->AddStretchSpacer();
327 mainSizer->Add(toolbarSizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 4);
328
329 m_listBox = new TreeListBox(this, this, ID_LIST_BOX);
330 mainSizer->Add(m_listBox, 1, wxEXPAND | wxLEFT | wxRIGHT, 2);
331
332 m_statusLabel = new wxStaticText(this, wxID_ANY, "No project loaded");
333 m_statusLabel->SetForegroundColour(wxColour(120, 125, 135));
334 wxFont statusFont = m_statusLabel->GetFont();
335 statusFont.SetPointSize(8);
336 m_statusLabel->SetFont(statusFont);
337 mainSizer->Add(m_statusLabel, 0, wxEXPAND | wxALL, 6);
338
339 SetSizer(mainSizer);
340}
341
342void TreeSelectorTab::CollectSubTreeRefs(EmberCore::Node *node, std::set<std::string> &refs) const {
343 if (!node)
344 return;
345
346 std::string subtreeRef = node->GetAttribute("__subtree_ref__", "");
347 if (!subtreeRef.empty()) {
348 refs.insert(subtreeRef);
349 }
350
351 for (size_t i = 0; i < node->GetChildCount(); ++i) {
352 CollectSubTreeRefs(node->GetChild(i), refs);
353 }
354}
355
356void TreeSelectorTab::UpdateTreeList(const std::map<std::string, std::shared_ptr<EmberCore::BehaviorTree>> &trees,
357 const std::string &currentTreeId) {
358 wxLogMessage("TreeSelectorTab::UpdateTreeList called with %zu trees, currentTreeId='%s'", trees.size(),
359 wxString::FromUTF8(currentTreeId));
360
361 m_currentTreeId = currentTreeId;
362 m_treeInfoMap.clear();
363
364 for (const auto &pair : trees) {
365 TreeInfo info;
366 info.id = pair.first;
367 info.nodeCount = pair.second ? static_cast<int>(pair.second->GetNodeCount()) : 0;
368 info.isImplemented = pair.second && pair.second->HasRootNode() && pair.second->GetNodeCount() > 0;
369
370 if (pair.second && pair.second->GetRootNode()) {
371 CollectSubTreeRefs(pair.second->GetRootNode(), info.subtreeRefs);
372 }
373
374 m_treeInfoMap[pair.first] = std::move(info);
375 }
376
377 // Collapse all trees that have children by default
378 m_collapsedTrees.clear();
379 for (const auto &pair : m_treeInfoMap) {
380 if (!pair.second.subtreeRefs.empty()) {
381 m_collapsedTrees.insert(pair.first);
382 }
383 }
384
386
387 size_t total = m_treeInfoMap.size();
388 m_statusLabel->SetLabel(wxString::Format("%zu tree%s", total, total == 1 ? "" : "s"));
389
390 // Force refresh to ensure UI updates
391 m_listBox->Refresh();
392 Layout();
393}
394
396 m_flatList.clear();
397
398 if (m_treeInfoMap.empty()) {
399 m_listBox->SetItemCount(0);
400 m_listBox->Refresh();
401 return;
402 }
403
404 std::set<std::string> referencedAsChild;
405 for (const auto &pair : m_treeInfoMap) {
406 for (const auto &ref : pair.second.subtreeRefs) {
407 referencedAsChild.insert(ref);
408 }
409 }
410
411 std::vector<std::string> rootTrees;
412 std::vector<std::string> subtrees;
413 for (const auto &pair : m_treeInfoMap) {
414 if (referencedAsChild.find(pair.first) == referencedAsChild.end()) {
415 rootTrees.push_back(pair.first);
416 } else {
417 subtrees.push_back(pair.first);
418 }
419 }
420 std::sort(rootTrees.begin(), rootTrees.end());
421 std::sort(subtrees.begin(), subtrees.end());
422
423 if (!m_searchFilter.IsEmpty()) {
424 // Flat search mode - no section headers
425 std::vector<std::string> all;
426 for (const auto &pair : m_treeInfoMap) {
427 wxString lower = wxString::FromUTF8(pair.first).Lower();
428 if (lower.Find(m_searchFilter) != wxNOT_FOUND) {
429 all.push_back(pair.first);
430 }
431 }
432 std::sort(all.begin(), all.end());
433 for (const auto &id : all) {
434 const auto &info = m_treeInfoMap[id];
435 FlatEntry e;
436 e.id = info.id;
437 e.displayName = info.id;
438 e.nodeCount = info.nodeCount;
439 e.depth = 0;
440 e.isImplemented = info.isImplemented;
441 e.isLastChild = true;
442 e.hasChildren = !info.subtreeRefs.empty();
443 e.isCollapsed = false;
444 e.isHeader = false;
446 e.sectionCount = 0;
447 m_flatList.push_back(std::move(e));
448 }
449 } else {
450 // Section mode with headers
451
452 // Root Trees section header
453 if (!rootTrees.empty()) {
454 FlatEntry header;
455 header.id = "__section_root__";
456 header.displayName = "Root Trees";
457 header.nodeCount = 0;
458 header.depth = 0;
459 header.isImplemented = true;
460 header.isLastChild = false;
461 header.hasChildren = true;
463 header.isHeader = true;
465 header.sectionCount = static_cast<int>(rootTrees.size());
466 m_flatList.push_back(std::move(header));
467
469 for (size_t i = 0; i < rootTrees.size(); ++i) {
470 std::set<std::string> visited;
471 bool isLast = (i == rootTrees.size() - 1);
472 FlattenTree(rootTrees[i], 1, visited, isLast, {});
473 }
474 }
475 }
476
477 // Reusable Subtrees section header
478 if (!subtrees.empty()) {
479 FlatEntry header;
480 header.id = "__section_subtrees__";
481 header.displayName = "Reusable Subtrees";
482 header.nodeCount = 0;
483 header.depth = 0;
484 header.isImplemented = true;
485 header.isLastChild = true;
486 header.hasChildren = true;
488 header.isHeader = true;
490 header.sectionCount = static_cast<int>(subtrees.size());
491 m_flatList.push_back(std::move(header));
492
494 for (size_t i = 0; i < subtrees.size(); ++i) {
495 const auto &id = subtrees[i];
496 const auto &info = m_treeInfoMap[id];
497 FlatEntry e;
498 e.id = info.id;
499 e.displayName = info.id;
500 e.nodeCount = info.nodeCount;
501 e.depth = 1;
502 e.isImplemented = info.isImplemented;
503 e.isLastChild = (i == subtrees.size() - 1);
504 e.hasChildren = false;
505 e.isCollapsed = false;
506 e.isHeader = false;
508 e.sectionCount = 0;
509 m_flatList.push_back(std::move(e));
510 }
511 }
512 }
513 }
514
515 m_listBox->SetItemCount(m_flatList.size());
516
518 if (idx >= 0) {
519 m_listBox->SetSelection(idx);
520 } else {
521 m_listBox->SetSelection(wxNOT_FOUND);
522 }
523
524 m_listBox->Refresh();
525}
526
527void TreeSelectorTab::FlattenTree(const std::string &treeId, int depth, std::set<std::string> &visited,
528 bool isLastChild, std::vector<bool> parentHasMore) {
529 if (depth > 20)
530 return;
531
532 auto it = m_treeInfoMap.find(treeId);
533 if (it == m_treeInfoMap.end())
534 return;
535
536 bool isCircular = visited.find(treeId) != visited.end();
537 visited.insert(treeId);
538
539 const TreeInfo &info = it->second;
540 bool hasKids = !isCircular && !info.subtreeRefs.empty();
541 bool collapsed = hasKids && IsCollapsed(treeId);
542
543 FlatEntry e;
544 e.id = info.id;
545 e.displayName = info.id;
546 e.nodeCount = info.nodeCount;
547 e.depth = depth;
549 e.isLastChild = isLastChild;
550 e.hasChildren = hasKids;
551 e.isCollapsed = collapsed;
552 e.isHeader = false;
554 e.sectionCount = 0;
555 e.parentHasMore = parentHasMore;
556
557 m_flatList.push_back(std::move(e));
558
559 if (hasKids && !collapsed) {
560 std::vector<std::string> sortedRefs(info.subtreeRefs.begin(), info.subtreeRefs.end());
561 std::sort(sortedRefs.begin(), sortedRefs.end());
562
563 std::vector<bool> childParentHasMore = parentHasMore;
564 childParentHasMore.push_back(!isLastChild);
565
566 for (size_t i = 0; i < sortedRefs.size(); ++i) {
567 bool childIsLast = (i == sortedRefs.size() - 1);
568 FlattenTree(sortedRefs[i], depth + 1, visited, childIsLast, childParentHasMore);
569 }
570 }
571
572 visited.erase(treeId);
573}
574
575int TreeSelectorTab::FindItemByTreeId(const std::string &treeId) const {
576 for (size_t i = 0; i < m_flatList.size(); ++i) {
577 if (m_flatList[i].id == treeId) {
578 return static_cast<int>(i);
579 }
580 }
581 return -1;
582}
583
584void TreeSelectorTab::ToggleCollapse(const std::string &treeId) {
585 // Save scroll position before rebuilding
586 size_t firstVisible = m_listBox->GetVisibleRowsBegin();
587
588 auto it = m_collapsedTrees.find(treeId);
589 if (it != m_collapsedTrees.end()) {
590 m_collapsedTrees.erase(it);
591 } else {
592 m_collapsedTrees.insert(treeId);
593 }
595
596 // Restore scroll position
597 if (firstVisible < m_listBox->GetItemCount()) {
598 m_listBox->ScrollToRow(firstVisible);
599 }
600}
601
602bool TreeSelectorTab::IsCollapsed(const std::string &treeId) const {
603 return m_collapsedTrees.find(treeId) != m_collapsedTrees.end();
604}
605
607 // Save scroll position before rebuilding
608 size_t firstVisible = m_listBox->GetVisibleRowsBegin();
609
610 if (section == SectionType::RootTrees) {
612 } else if (section == SectionType::Subtrees) {
614 }
616
617 // Restore scroll position
618 if (firstVisible < m_listBox->GetItemCount()) {
619 m_listBox->ScrollToRow(firstVisible);
620 }
621}
622
624 if (section == SectionType::RootTrees) {
626 } else if (section == SectionType::Subtrees) {
628 }
629 return false;
630}
631
632int TreeSelectorTab::GetToggleHitX(int depth, bool isCurrent) const {
633 int basePad = isCurrent ? BASE_LEFT_PAD + 4 : BASE_LEFT_PAD;
634 return basePad + depth * INDENT_PX;
635}
636
637void TreeSelectorTab::SetCurrentTree(const std::string &treeId) {
638 m_currentTreeId = treeId;
640}
641
643 m_treeInfoMap.clear();
644 m_flatList.clear();
645 m_collapsedTrees.clear();
648 m_currentTreeId.clear();
649 m_listBox->SetItemCount(0);
650 m_listBox->Refresh();
651 m_statusLabel->SetLabel("No project loaded");
652}
653
655 if (m_mainFrame) {
656 m_mainFrame->OnTreeSelectorTabClosed();
657 }
658}
659
661 if (!m_currentTreeId.empty()) {
663 if (idx >= 0) {
664 m_listBox->SetSelection(idx);
665 m_listBox->Refresh();
666 }
667 }
668}
669
670void TreeSelectorTab::OnTreeSelected(wxCommandEvent &) {
671 // Single-click just highlights the item, no tree loading
672}
673
675 m_searchFilter = m_searchCtrl->GetValue().Lower();
677}
678
679void TreeSelectorTab::ShowContextMenu(int itemIndex, const wxPoint &pos) {
680 if (itemIndex < 0 || itemIndex >= static_cast<int>(m_flatList.size()))
681 return;
682
683 m_contextMenuTreeId = m_flatList[itemIndex].id;
684
685 wxMenu menu;
686 menu.Append(ID_CTX_VIEW_CURRENT, "View in Current Scene");
687 menu.Append(ID_CTX_OPEN_NEW_SCENE, "Open in New Scene");
688 menu.AppendSeparator();
689
690 const auto &entry = m_flatList[itemIndex];
691 if (entry.hasChildren) {
692 if (entry.isCollapsed)
693 menu.Append(ID_CTX_EXPAND_ALL, "Expand");
694 else
695 menu.Append(ID_CTX_COLLAPSE_ALL, "Collapse");
696 }
697
698 m_listBox->PopupMenu(&menu, pos);
699}
700
702 if (m_contextMenuTreeId.empty())
703 return;
704
707 m_listBox->Refresh();
710 }
711 }
712}
713
715 if (m_contextMenuTreeId.empty() || !m_mainFrame)
716 return;
717
718 m_mainFrame->OpenTreeInNewScene(m_contextMenuTreeId);
719}
720
727
734
736
737void TreeSelectorTab::OnExpandAll(wxCommandEvent &) { ExpandAllTrees(); }
738
740 m_collapsedTrees.clear();
741 for (const auto &pair : m_treeInfoMap) {
742 if (!pair.second.subtreeRefs.empty()) {
743 m_collapsedTrees.insert(pair.first);
744 }
745 }
747}
748
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
MainFrame::OnExit EVT_MENU(wxID_ABOUT, MainFrame::OnAbout) EVT_MENU(ID_NewProject
static const int CONNECTOR_X_OFFSET
static const int TOGGLE_SIZE
static const int BASE_LEFT_PAD
wxBEGIN_EVENT_TABLE(TreeSelectorTab, wxPanel) wxEND_EVENT_TABLE() static const int INDENT_PX
Represents a node in a behavior tree structure.
Definition Node.h:20
String GetAttribute(const String &name, const String &default_value="") const
Definition Node.cpp:451
Node * GetChild(size_t index) const
Definition Node.cpp:175
size_t GetChildCount() const
Definition Node.h:76
Main application window for EmberForge.
Definition MainFrame.h:65
TreeListBox(TreeSelectorTab *owner, wxWindow *parent, wxWindowID id)
void OnLeftDown(wxMouseEvent &event)
wxCoord OnMeasureItem(size_t n) const override
TreeSelectorTab * m_owner
void OnRightDown(wxMouseEvent &event)
void OnDrawItem(wxDC &dc, const wxRect &rect, size_t n) const override
void OnDrawBackground(wxDC &dc, const wxRect &rect, size_t n) const override
void ToggleCollapse(const std::string &treeId)
void OnActivated() override
Called when the tab becomes the active/visible tab.
void OnContextOpenNewScene(wxCommandEvent &event)
void OnContextExpandAll(wxCommandEvent &event)
wxButton * m_collapseAllBtn
std::string m_contextMenuTreeId
void OnExpandAll(wxCommandEvent &event)
void OnSearchTextChanged(wxCommandEvent &event)
void FlattenTree(const std::string &treeId, int depth, std::set< std::string > &visited, bool isLastChild, std::vector< bool > parentHasMore)
int GetToggleHitX(int depth, bool isCurrent) const
void SetCurrentTree(const std::string &treeId)
void OnClosed() override
Called when the tab is about to be closed/removed Use this for cleanup operations.
TreeSelectorTab(wxWindow *parent, MainFrame *mainFrame=nullptr)
void OnContextCollapseAll(wxCommandEvent &event)
std::vector< FlatEntry > m_flatList
wxSearchCtrl * m_searchCtrl
wxButton * m_expandAllBtn
std::string m_currentTreeId
void OnTreeSelected(wxCommandEvent &event)
void UpdateTreeList(const std::map< std::string, std::shared_ptr< EmberCore::BehaviorTree > > &trees, const std::string &currentTreeId)
void ShowContextMenu(int itemIndex, const wxPoint &pos)
std::set< std::string > m_collapsedTrees
MainFrame * m_mainFrame
void OnContextViewInCurrent(wxCommandEvent &event)
TreeSelectionCallback m_selectionCallback
bool IsCollapsed(const std::string &treeId) const
void OnCollapseAll(wxCommandEvent &event)
void CollectSubTreeRefs(EmberCore::Node *node, std::set< std::string > &refs) const
int FindItemByTreeId(const std::string &treeId) const
TreeListBox * m_listBox
void ToggleSectionCollapse(SectionType section)
std::map< std::string, TreeInfo > m_treeInfoMap
bool IsSectionCollapsed(SectionType section) const
wxStaticText * m_statusLabel
std::vector< bool > parentHasMore
std::set< std::string > subtreeRefs