Ember
Loading...
Searching...
No Matches
TreeSelectorTab.h
Go to the documentation of this file.
1#pragma once
2
3#include "Tabs/ITab.h"
4#include <functional>
5#include <map>
6#include <memory>
7#include <set>
8#include <string>
9#include <vector>
10#include <wx/srchctrl.h>
11#include <wx/vlbox.h>
12#include <wx/wx.h>
13
14class MainFrame;
15class TreeListBox;
16
17namespace EmberCore {
18class BehaviorTree;
19class Node;
20} // namespace EmberCore
21
22class TreeSelectorTab : public wxPanel, public ITab {
23 public:
24 using TreeSelectionCallback = std::function<void(const std::string &treeId)>;
25
26 TreeSelectorTab(wxWindow *parent, MainFrame *mainFrame = nullptr);
27
28 // ITab interface
29 wxWindow *GetWidget() override { return this; }
30 wxString GetTitle() const override { return "Tree Selector"; }
31 wxString GetTabType() const override { return "TreeSelector"; }
32 void OnClosed() override;
33 void OnActivated() override;
34
35 void UpdateTreeList(const std::map<std::string, std::shared_ptr<EmberCore::BehaviorTree>> &trees,
36 const std::string &currentTreeId);
37
38 void SetCurrentTree(const std::string &treeId);
39 void ClearTreeList();
40
41 void SetTreeSelectionCallback(TreeSelectionCallback callback) { m_selectionCallback = std::move(callback); }
42
44
45 struct FlatEntry {
46 std::string id;
47 std::string displayName;
49 int depth;
57 std::vector<bool> parentHasMore;
58 };
59
60 const std::vector<FlatEntry> &GetFlatList() const { return m_flatList; }
61 const std::string &GetCurrentTreeId() const { return m_currentTreeId; }
62
63 void ToggleCollapse(const std::string &treeId);
65 bool IsCollapsed(const std::string &treeId) const;
66 bool IsSectionCollapsed(SectionType section) const;
67 int GetToggleHitX(int depth, bool isCurrent) const;
68
69 void ShowContextMenu(int itemIndex, const wxPoint &pos);
70
71 private:
72 void CreateLayout();
73 void CollectSubTreeRefs(EmberCore::Node *node, std::set<std::string> &refs) const;
74 void BuildFlatList();
75 void FlattenTree(const std::string &treeId, int depth, std::set<std::string> &visited, bool isLastChild,
76 std::vector<bool> parentHasMore);
77 int FindItemByTreeId(const std::string &treeId) const;
78
79 // Event handlers
80 void OnSearchTextChanged(wxCommandEvent &event);
81 void OnTreeSelected(wxCommandEvent &event);
82
83 // Context menu handlers
84 void OnContextViewInCurrent(wxCommandEvent &event);
85 void OnContextOpenNewScene(wxCommandEvent &event);
86 void OnContextExpandAll(wxCommandEvent &event);
87 void OnContextCollapseAll(wxCommandEvent &event);
88
89 // Toolbar button handlers
90 void OnCollapseAll(wxCommandEvent &event);
91 void OnExpandAll(wxCommandEvent &event);
92
93 // Expand/collapse all trees
94 void CollapseAllTrees();
95 void ExpandAllTrees();
96
97 wxSearchCtrl *m_searchCtrl;
99 wxButton *m_expandAllBtn;
101 wxStaticText *m_statusLabel;
102
103 struct TreeInfo {
104 std::string id;
107 std::set<std::string> subtreeRefs;
108 };
109
110 std::map<std::string, TreeInfo> m_treeInfoMap;
111 std::vector<FlatEntry> m_flatList;
112 std::set<std::string> m_collapsedTrees;
115 std::string m_currentTreeId;
118
121
122 enum {
123 ID_LIST_BOX = wxID_HIGHEST + 1,
131 };
132
134};
135
136class TreeListBox : public wxVListBox {
137 public:
138 TreeListBox(TreeSelectorTab *owner, wxWindow *parent, wxWindowID id);
139
140 private:
141 void OnDrawItem(wxDC &dc, const wxRect &rect, size_t n) const override;
142 wxCoord OnMeasureItem(size_t n) const override;
143 void OnDrawBackground(wxDC &dc, const wxRect &rect, size_t n) const override;
144 void OnLeftDown(wxMouseEvent &event);
145 void OnRightDown(wxMouseEvent &event);
146
148};
Represents a complete behavior tree data structure.
Represents a node in a behavior tree structure.
Definition Node.h:20
Abstract interface for individual tabs that can be moved between panels.
Definition ITab.h:28
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.
wxString GetTabType() const override
Get a unique identifier for this tab type.
void OnContextOpenNewScene(wxCommandEvent &event)
void OnContextExpandAll(wxCommandEvent &event)
wxButton * m_collapseAllBtn
std::string m_contextMenuTreeId
void OnExpandAll(wxCommandEvent &event)
wxString GetTitle() const override
Get the display title for this tab.
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.
wxWindow * GetWidget() override
Get the main widget for this tab.
TreeSelectorTab(wxWindow *parent, MainFrame *mainFrame=nullptr)
const std::vector< FlatEntry > & GetFlatList() const
void OnContextCollapseAll(wxCommandEvent &event)
std::vector< FlatEntry > m_flatList
wxSearchCtrl * m_searchCtrl
wxButton * m_expandAllBtn
std::string m_currentTreeId
void SetTreeSelectionCallback(TreeSelectionCallback callback)
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)
std::function< void(const std::string &treeId)> TreeSelectionCallback
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
const std::string & GetCurrentTreeId() const
wxStaticText * m_statusLabel
Main types header for EmberCore.
std::vector< bool > parentHasMore
std::set< std::string > subtreeRefs