Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BehaviorTreeRenderer.h
Go to the documentation of this file.
1/**
2 * @file BehaviorTreeRenderer.h
3 * @brief IGraphRenderer adapter for BehaviorTree graphs (wraps BTNodeGraphManager).
4 * @author Olympe Engine
5 * @date 2026-03-11
6 *
7 * @details C++14 compliant.
8 * Phase 2 (2026-04-08): Added BTNodePalette and BTNodePropertyPanel for modern UI.
9 */
10
11#pragma once
12
13#include "IGraphRenderer.h"
14#include "NodeGraphPanel.h"
15#include "BTNodePropertyPanel.h"
16#include "../third_party/imgui/imgui.h"
17
18#include <string>
19#include <memory>
20
21namespace Olympe {
22
23// Forward declarations
24class GraphExecutionTracer;
25class ExecutionTestPanel;
26namespace AI {
27 class BTNodePalette;
28}
29
30/**
31 * @class BehaviorTreeRenderer
32 * @brief Adapts the BTNodeGraphManager + NodeGraphPanel to IGraphRenderer.
33 *
34 * Phase 2 Enhancement: Now includes split-panel layout with:
35 * - 75% NodeGraphPanel (canvas rendering)
36 * - 25% Right panel with tabs:
37 * * Tab 0: BTNodePalette (node selection + drag-drop)
38 * * Tab 1: BTNodePropertyPanel (node property editing)
39 *
40 * Each instance manages a single BT graph ID in BTNodeGraphManager.
41 * When Render() is called, this renderer sets that graph as the active one and
42 * delegates to a shared NodeGraphPanel reference for drawing.
43 */
45{
46public:
47 /**
48 * @param panel Reference to the shared NodeGraphPanel owned by the editor GUI.
49 * The renderer does NOT take ownership.
50 */
53
54 void Render() override;
55 bool Load(const std::string& path) override;
56 bool Save(const std::string& path) override;
57 bool IsDirty() const override;
58 std::string GetGraphType() const override;
59 std::string GetCurrentPath() const override;
60
61 /**
62 * @brief Create a new empty BehaviorTree graph and set it active
63 * @param name Name for the new graph
64 * @return true if successful
65 */
66 bool CreateNew(const std::string& name = "Untitled BehaviorTree");
67
68 /**
69 * @brief Run graph simulation via BehaviorTreeGraphAdapter + GraphExecutionSimulator
70 * Converts BT to graph format, executes, formats trace, and displays in ExecutionTestPanel.
71 * Called by "Run Graph" toolbar button.
72 */
73 void OnRunGraphClicked();
74
75private:
76 NodeGraphPanel& m_panel; ///< Shared panel reference (not owned)
77 std::unique_ptr<AI::BTNodePalette> m_palette; ///< BTNodePalette for drag-drop
78 BTNodePropertyPanel m_propertyPanel; ///< Property editor for node properties
79 int m_graphId; ///< ID in BTNodeGraphManager; -1 if not loaded
80 std::string m_filePath; ///< Path that was loaded
81 float m_canvasPanelWidth = 0.75f; ///< Split ratio: 75% canvas, 25% right panel
82 int m_rightPanelTabSelection = 0; ///< 0 = Palette, 1 = Properties
83 ImVec2 m_canvasScreenPos = ImVec2(0, 0); ///< Screen position of canvas for drag-drop coordinate transformation
84 std::unique_ptr<ExecutionTestPanel> m_executionTestPanel; ///< REUSED: Simulation results panel
85 std::unique_ptr<GraphExecutionTracer> m_lastTracer; ///< Last simulation trace for results display
86
87 // Layout rendering helpers
90
91 /**
92 * @brief Handle drop of node type at screen position
93 * @param nodeType BT node type name
94 * @param screenX Absolute screen X coordinate
95 * @param screenY Absolute screen Y coordinate
96 */
97 void AcceptNodeDrop(const std::string& nodeType, float screenX, float screenY);
98
99 /**
100 * @brief Handle keyboard shortcuts for copy/paste/duplicate operations
101 * Ctrl+C: Copy selected node
102 * Ctrl+V: Paste nodes from clipboard
103 * Ctrl+D: Duplicate selected node
104 */
106
107 // Phase 35.0: Canvas state management
108 void SaveCanvasState() override;
109 void RestoreCanvasState() override;
110 std::string GetCanvasStateJSON() const override;
111 void SetCanvasStateJSON(const std::string& json) override;
112
113private:
114 // Canvas state snapshot (Phase 35.0)
116 {
118 // Note: BehaviorTree via imnodes doesn't have explicit zoom
120};
121
122} // namespace Olympe
Property editor panel for BehaviorTree nodes.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Abstract interface shared by all graph-renderer adapters.
UI panel for editing BehaviorTree node properties.
Adapts the BTNodeGraphManager + NodeGraphPanel to IGraphRenderer.
void SetCanvasStateJSON(const std::string &json) override
Restore canvas state from JSON string.
struct Olympe::BehaviorTreeRenderer::CanvasState m_savedCanvasState
std::string m_filePath
Path that was loaded.
std::string GetGraphType() const override
Returns the graph type string, e.g.
bool CreateNew(const std::string &name="Untitled BehaviorTree")
Create a new empty BehaviorTree graph and set it active.
float m_canvasPanelWidth
Split ratio: 75% canvas, 25% right panel.
std::unique_ptr< GraphExecutionTracer > m_lastTracer
Last simulation trace for results display.
int m_graphId
ID in BTNodeGraphManager; -1 if not loaded.
std::unique_ptr< AI::BTNodePalette > m_palette
BTNodePalette for drag-drop.
int m_rightPanelTabSelection
0 = Palette, 1 = Properties
void Render() override
Renders the graph canvas into the current ImGui child window.
void AcceptNodeDrop(const std::string &nodeType, float screenX, float screenY)
Handle drop of node type at screen position.
void OnRunGraphClicked()
Run graph simulation via BehaviorTreeGraphAdapter + GraphExecutionSimulator Converts BT to graph form...
void RestoreCanvasState() override
Restore previously saved canvas viewport state Called when tab is reactivated.
NodeGraphPanel & m_panel
Shared panel reference (not owned)
BTNodePropertyPanel m_propertyPanel
Property editor for node properties.
void SaveCanvasState() override
Save the current canvas viewport state (pan, zoom, etc.) Called when tab is deactivated.
std::string GetCurrentPath() const override
Returns the last path successfully loaded/saved, or empty string.
std::string GetCanvasStateJSON() const override
Get canvas state as JSON string for persistence.
bool Save(const std::string &path) override
Saves the current graph state to disk.
bool IsDirty() const override
Returns true when the graph has unsaved changes.
std::unique_ptr< ExecutionTestPanel > m_executionTestPanel
REUSED: Simulation results panel.
ImVec2 m_canvasScreenPos
Screen position of canvas for drag-drop coordinate transformation.
void HandleKeyboardShortcuts()
Handle keyboard shortcuts for copy/paste/duplicate operations Ctrl+C: Copy selected node Ctrl+V: Past...
bool Load(const std::string &path) override
Loads a graph from a file on disk.
Polymorphic interface for all graph editor renderers.
NodeGraphPanel - ImGui/ImNodes panel for node graph editing Provides visual editor for behavior trees...
< Provides AssetID and INVALID_ASSET_ID
nlohmann::json json