Ember
Loading...
Searching...
No Matches
BehaviorTreeScene.cpp
Go to the documentation of this file.
3#include "App/App.h"
4#include "App/MainFrame.h"
6
7BehaviorTreeScene::BehaviorTreeScene(wxWindow *parent, const wxString &title)
8 : m_panel(nullptr), m_treeVisualization(nullptr), m_behaviorTreeRoot(nullptr), m_treeAdapter(nullptr),
9 m_title(title), m_hasUnsavedChanges(false) {
10 m_panel = new wxPanel(parent, wxID_ANY);
11 m_panel->SetBackgroundColour(wxColour(45, 45, 50));
12
13 MainFrame *mainFrame = dynamic_cast<MainFrame *>(wxGetApp().GetTopWindow());
14 if (mainFrame) {
15 m_panel->SetDropTarget(
16 new EmberForge::XMLFileDropTarget([mainFrame](const wxString &filePath, bool loadInCurrentScene) {
17 if (loadInCurrentScene) {
18 mainFrame->LoadXMLFile(filePath, true);
19 } else {
20 mainFrame->LoadXMLFileInNewScene(filePath);
21 }
22 }));
23 }
24
26}
27
30 m_treeVisualization->SetNodeSelectionCallback(nullptr);
31 }
33}
34
36 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
37
39
40 m_treeVisualization->SetNodeSelectionCallback([this](EmberCore::ITreeNode *node) {
43 }
44 });
45
46 if (m_treeAdapter) {
47 m_treeVisualization->SetBehaviorTree(m_treeAdapter);
48 }
49
50 sizer->Add(m_treeVisualization, 1, wxEXPAND | wxALL, 5);
51
52 m_panel->SetSizer(sizer);
53}
54
57 m_treeVisualization->RefreshVisualization();
58 m_treeVisualization->SetFocus();
59 }
60}
61
63
66 m_treeVisualization->RefreshVisualization();
67 }
68}
69
71 m_hasUnsavedChanges = false;
72 return true;
73}
74
75void BehaviorTreeScene::SetBehaviorTree(std::shared_ptr<EmberCore::Node> root) {
76 m_behaviorTreeRoot = root;
77
79 auto behaviorTree = std::make_shared<EmberCore::BehaviorTree>("Scene Tree");
80 behaviorTree->SetRootNode(m_behaviorTreeRoot);
81 m_treeAdapter = std::make_shared<EmberCore::DirectTreeAdapter>(behaviorTree);
82 wxLogMessage("Using DirectTreeAdapter with BehaviorTree wrapper: %s", m_behaviorTreeRoot->GetName());
83 } else {
84 m_treeAdapter = nullptr;
85 }
86
88 m_treeVisualization->SetBehaviorTree(m_treeAdapter);
90 }
91
92 wxLogMessage("Behavior tree updated with shared root node: %s",
93 m_behaviorTreeRoot ? m_behaviorTreeRoot->GetName() : "null");
94}
95
96void BehaviorTreeScene::SetBehaviorTree(std::shared_ptr<EmberCore::ITreeStructure> tree) {
97 m_treeAdapter = tree;
98 m_behaviorTreeRoot = nullptr;
99
101 m_treeVisualization->SetBehaviorTree(m_treeAdapter);
102 m_hasUnsavedChanges = true;
103 }
104
105 wxLogMessage("Behavior tree updated with abstracted tree: %s", tree ? tree->GetName() : "null");
106}
107
110 m_behaviorTreeRoot = std::shared_ptr<EmberCore::Node>(uniqueTree.release());
111
112 if (m_behaviorTreeRoot) {
113 auto behaviorTree = std::make_shared<EmberCore::BehaviorTree>("Sample Tree");
114 behaviorTree->SetRootNode(m_behaviorTreeRoot);
115 m_treeAdapter = std::make_shared<EmberCore::DirectTreeAdapter>(behaviorTree);
116 wxLogMessage("Using DirectTreeAdapter with BehaviorTree wrapper for sample tree: %s",
117 m_behaviorTreeRoot->GetName());
118 }
119
121 m_treeVisualization->SetBehaviorTree(m_treeAdapter);
122 }
123
124 m_hasUnsavedChanges = true;
125
126 wxLogMessage("Created sample behavior tree with %lu nodes",
127 m_behaviorTreeRoot ? static_cast<unsigned long>(m_behaviorTreeRoot->GetSubtreeNodeCount()) : 0UL);
128}
129
130void BehaviorTreeScene::SetTitle(const wxString &title) { m_title = title; }
131
133 if (m_panel) {
134 m_panel->SetBackgroundColour(color);
135 m_panel->Refresh();
136 }
137}
NodeSelectionCallback m_nodeSelectionCallback
BehaviorTreeScene(wxWindow *parent, const wxString &title="Behavior Tree")
Construct a new BehaviorTreeScene.
std::shared_ptr< EmberCore::ITreeStructure > m_treeAdapter
void OnDeactivated() override
Called when this scene is no longer the active tab.
void CreateSampleBehaviorTree()
Create a sample behavior tree for testing/demo purposes.
std::shared_ptr< EmberCore::Node > m_behaviorTreeRoot
void Refresh() override
Called when the scene should refresh its display.
void OnActivated() override
Called when this scene becomes the active tab.
void SetTitle(const wxString &title)
Set the title of this scene.
void SetCanvasBackgroundColor(const wxColour &color)
Set the canvas background color.
EmberCore::TreeVisualization * m_treeVisualization
void SetBehaviorTree(std::shared_ptr< EmberCore::Node > root)
Set the behavior tree for this scene using legacy Node interface.
bool Save() override
Save the scene (if applicable)
Abstract interface for tree nodes that can be visualized.
Definition ITreeNode.h:31
static std::unique_ptr< Node > CreateSampleTree()
Definition Node.cpp:420
Tree visualization panel that renders behavior trees in a grid-based layout.
File drop target for XML files.
Main application window for EmberForge.
Definition MainFrame.h:65
void LoadXMLFile(const wxString &filePath, bool confirmOverride=false)
void LoadXMLFileInNewScene(const wxString &filePath)