Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Olympe::BehaviorTreeRenderer Class Reference

Adapts the BTNodeGraphManager + NodeGraphPanel to IGraphRenderer. More...

#include <BehaviorTreeRenderer.h>

+ Inheritance diagram for Olympe::BehaviorTreeRenderer:
+ Collaboration diagram for Olympe::BehaviorTreeRenderer:

Classes

struct  CanvasState
 

Public Member Functions

 BehaviorTreeRenderer (NodeGraphPanel &panel)
 
 ~BehaviorTreeRenderer ()
 
void Render () override
 Renders the graph canvas into the current ImGui child window.
 
bool Load (const std::string &path) override
 Loads a graph from a file on disk.
 
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::string GetGraphType () const override
 Returns the graph type string, e.g.
 
std::string GetCurrentPath () const override
 Returns the last path successfully loaded/saved, or empty string.
 
bool CreateNew (const std::string &name="Untitled BehaviorTree")
 Create a new empty BehaviorTree graph and set it active.
 
void OnRunGraphClicked ()
 Run graph simulation via BehaviorTreeGraphAdapter + GraphExecutionSimulator Converts BT to graph format, executes, formats trace, and displays in ExecutionTestPanel.
 
- Public Member Functions inherited from Olympe::IGraphRenderer
virtual ~IGraphRenderer ()
 

Private Member Functions

void RenderLayoutWithTabs ()
 
void RenderRightPanelTabs ()
 
void AcceptNodeDrop (const std::string &nodeType, float screenX, float screenY)
 Handle drop of node type at screen position.
 
void HandleKeyboardShortcuts ()
 Handle keyboard shortcuts for copy/paste/duplicate operations Ctrl+C: Copy selected node Ctrl+V: Paste nodes from clipboard Ctrl+D: Duplicate selected node.
 
void SaveCanvasState () override
 Save the current canvas viewport state (pan, zoom, etc.) Called when tab is deactivated.
 
void RestoreCanvasState () override
 Restore previously saved canvas viewport state Called when tab is reactivated.
 
std::string GetCanvasStateJSON () const override
 Get canvas state as JSON string for persistence.
 
void SetCanvasStateJSON (const std::string &json) override
 Restore canvas state from JSON string.
 

Private Attributes

NodeGraphPanelm_panel
 Shared panel reference (not owned)
 
std::unique_ptr< AI::BTNodePalettem_palette
 BTNodePalette for drag-drop.
 
BTNodePropertyPanel m_propertyPanel
 Property editor for node properties.
 
int m_graphId
 ID in BTNodeGraphManager; -1 if not loaded.
 
std::string m_filePath
 Path that was loaded.
 
float m_canvasPanelWidth = 0.75f
 Split ratio: 75% canvas, 25% right panel.
 
int m_rightPanelTabSelection = 0
 0 = Palette, 1 = Properties
 
ImVec2 m_canvasScreenPos = ImVec2(0, 0)
 Screen position of canvas for drag-drop coordinate transformation.
 
std::unique_ptr< ExecutionTestPanelm_executionTestPanel
 REUSED: Simulation results panel.
 
std::unique_ptr< GraphExecutionTracerm_lastTracer
 Last simulation trace for results display.
 
struct Olympe::BehaviorTreeRenderer::CanvasState m_savedCanvasState
 

Detailed Description

Adapts the BTNodeGraphManager + NodeGraphPanel to IGraphRenderer.

Phase 2 Enhancement: Now includes split-panel layout with:

Each instance manages a single BT graph ID in BTNodeGraphManager. When Render() is called, this renderer sets that graph as the active one and delegates to a shared NodeGraphPanel reference for drawing.

Definition at line 44 of file BehaviorTreeRenderer.h.

Constructor & Destructor Documentation

◆ BehaviorTreeRenderer()

Olympe::BehaviorTreeRenderer::BehaviorTreeRenderer ( NodeGraphPanel panel)
explicit
Parameters
panelReference to the shared NodeGraphPanel owned by the editor GUI. The renderer does NOT take ownership.

Definition at line 28 of file BehaviorTreeRenderer.cpp.

References Olympe::BTNodePropertyPanel::Initialize(), m_executionTestPanel, m_lastTracer, m_palette, and m_propertyPanel.

+ Here is the call graph for this function:

◆ ~BehaviorTreeRenderer()

Olympe::BehaviorTreeRenderer::~BehaviorTreeRenderer ( )

Definition at line 48 of file BehaviorTreeRenderer.cpp.

References Olympe::NodeGraphManager::CloseGraph(), Olympe::NodeGraphManager::Get(), and m_graphId.

+ Here is the call graph for this function:

Member Function Documentation

◆ AcceptNodeDrop()

void Olympe::BehaviorTreeRenderer::AcceptNodeDrop ( const std::string &  nodeType,
float  screenX,
float  screenY 
)
private

Handle drop of node type at screen position.

Parameters
nodeTypeBT node type name
screenXAbsolute screen X coordinate
screenYAbsolute screen Y coordinate

Definition at line 283 of file BehaviorTreeRenderer.cpp.

References Olympe::NodeGraphManager::Get(), GetComponentTypeID_Static(), Olympe::NodeGraphManager::GetGraph(), m_canvasScreenPos, m_graphId, Olympe::StringToNodeType(), and SYSTEM_LOG.

Referenced by RenderLayoutWithTabs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateNew()

bool Olympe::BehaviorTreeRenderer::CreateNew ( const std::string &  name = "Untitled BehaviorTree")

Create a new empty BehaviorTree graph and set it active.

Parameters
nameName for the new graph
Returns
true if successful

Definition at line 57 of file BehaviorTreeRenderer.cpp.

References Olympe::NodeGraphManager::CloseGraph(), Olympe::NodeGraphManager::CreateGraph(), Olympe::NodeGraphManager::Get(), m_filePath, m_graphId, Olympe::NodeGraphManager::SetActiveGraph(), and SYSTEM_LOG.

+ Here is the call graph for this function:

◆ GetCanvasStateJSON()

std::string Olympe::BehaviorTreeRenderer::GetCanvasStateJSON ( ) const
overrideprivatevirtual

Get canvas state as JSON string for persistence.

Returns
JSON representation of current canvas state

Reimplemented from Olympe::IGraphRenderer.

Definition at line 547 of file BehaviorTreeRenderer.cpp.

◆ GetCurrentPath()

std::string Olympe::BehaviorTreeRenderer::GetCurrentPath ( ) const
overridevirtual

Returns the last path successfully loaded/saved, or empty string.

Implements Olympe::IGraphRenderer.

Definition at line 278 of file BehaviorTreeRenderer.cpp.

References m_filePath.

◆ GetGraphType()

std::string Olympe::BehaviorTreeRenderer::GetGraphType ( ) const
overridevirtual

Returns the graph type string, e.g.

"VisualScript", "BehaviorTree".

Implements Olympe::IGraphRenderer.

Definition at line 273 of file BehaviorTreeRenderer.cpp.

◆ HandleKeyboardShortcuts()

void Olympe::BehaviorTreeRenderer::HandleKeyboardShortcuts ( )
private

Handle keyboard shortcuts for copy/paste/duplicate operations Ctrl+C: Copy selected node Ctrl+V: Paste nodes from clipboard Ctrl+D: Duplicate selected node.

Definition at line 333 of file BehaviorTreeRenderer.cpp.

References Olympe::NodeGraphManager::Get(), GetComponentTypeID_Static(), Olympe::NodeGraphManager::GetGraph(), m_graphId, m_panel, Olympe::NodeGraphPanel::m_SelectedNodeId, and SYSTEM_LOG.

Referenced by RenderLayoutWithTabs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsDirty()

bool Olympe::BehaviorTreeRenderer::IsDirty ( ) const
overridevirtual

Returns true when the graph has unsaved changes.

Implements Olympe::IGraphRenderer.

Definition at line 264 of file BehaviorTreeRenderer.cpp.

References Olympe::NodeGraphManager::Get(), GetComponentTypeID_Static(), Olympe::NodeGraphManager::GetGraph(), Olympe::NodeGraph::IsDirty(), and m_graphId.

+ Here is the call graph for this function:

◆ Load()

bool Olympe::BehaviorTreeRenderer::Load ( const std::string &  path)
overridevirtual

Loads a graph from a file on disk.

Parameters
pathAbsolute or relative path to the .ats / .json file.
Returns
true on success.

Implements Olympe::IGraphRenderer.

Definition at line 222 of file BehaviorTreeRenderer.cpp.

References Olympe::NodeGraphManager::CloseGraph(), Olympe::NodeGraphManager::Get(), GetComponentTypeID_Static(), Olympe::NodeGraphManager::LoadGraph(), m_filePath, m_graphId, Olympe::NodeGraphManager::SetActiveGraph(), and SYSTEM_LOG.

+ Here is the call graph for this function:

◆ OnRunGraphClicked()

void Olympe::BehaviorTreeRenderer::OnRunGraphClicked ( )

◆ Render()

void Olympe::BehaviorTreeRenderer::Render ( )
overridevirtual

Renders the graph canvas into the current ImGui child window.

Implements Olympe::IGraphRenderer.

Definition at line 81 of file BehaviorTreeRenderer.cpp.

References Olympe::NodeGraphManager::Get(), DataManager::Get(), m_executionTestPanel, m_graphId, DataManager::RenderFilePickerModal(), RenderLayoutWithTabs(), and Olympe::NodeGraphManager::SetActiveGraph().

+ Here is the call graph for this function:

◆ RenderLayoutWithTabs()

void Olympe::BehaviorTreeRenderer::RenderLayoutWithTabs ( )
private

◆ RenderRightPanelTabs()

void Olympe::BehaviorTreeRenderer::RenderRightPanelTabs ( )
private

◆ RestoreCanvasState()

void Olympe::BehaviorTreeRenderer::RestoreCanvasState ( )
overrideprivatevirtual

Restore previously saved canvas viewport state Called when tab is reactivated.

Ensures smooth tab switching without losing layout.

Reimplemented from Olympe::IGraphRenderer.

Definition at line 541 of file BehaviorTreeRenderer.cpp.

References Olympe::BehaviorTreeRenderer::CanvasState::canvasOffset, m_canvasScreenPos, and m_savedCanvasState.

◆ Save()

bool Olympe::BehaviorTreeRenderer::Save ( const std::string &  path)
overridevirtual

Saves the current graph state to disk.

Parameters
pathDestination path. If empty, save to the path passed to Load().
Returns
true on success.

Implements Olympe::IGraphRenderer.

Definition at line 249 of file BehaviorTreeRenderer.cpp.

References Olympe::NodeGraphManager::Get(), GetComponentTypeID_Static(), m_filePath, m_graphId, and Olympe::NodeGraphManager::SaveGraph().

+ Here is the call graph for this function:

◆ SaveCanvasState()

void Olympe::BehaviorTreeRenderer::SaveCanvasState ( )
overrideprivatevirtual

Save the current canvas viewport state (pan, zoom, etc.) Called when tab is deactivated.

Used to preserve viewport when switching between multiple tabs.

Reimplemented from Olympe::IGraphRenderer.

Definition at line 534 of file BehaviorTreeRenderer.cpp.

References Olympe::BehaviorTreeRenderer::CanvasState::canvasOffset, m_canvasScreenPos, and m_savedCanvasState.

◆ SetCanvasStateJSON()

void Olympe::BehaviorTreeRenderer::SetCanvasStateJSON ( const std::string &  json)
overrideprivatevirtual

Restore canvas state from JSON string.

Parameters
jsonJSON representation of saved canvas state

Reimplemented from Olympe::IGraphRenderer.

Definition at line 553 of file BehaviorTreeRenderer.cpp.

References GetComponentTypeID_Static().

+ Here is the call graph for this function:

Member Data Documentation

◆ m_canvasPanelWidth

float Olympe::BehaviorTreeRenderer::m_canvasPanelWidth = 0.75f
private

Split ratio: 75% canvas, 25% right panel.

Definition at line 81 of file BehaviorTreeRenderer.h.

Referenced by RenderLayoutWithTabs().

◆ m_canvasScreenPos

ImVec2 Olympe::BehaviorTreeRenderer::m_canvasScreenPos = ImVec2(0, 0)
private

Screen position of canvas for drag-drop coordinate transformation.

Definition at line 83 of file BehaviorTreeRenderer.h.

Referenced by AcceptNodeDrop(), RenderLayoutWithTabs(), RestoreCanvasState(), and SaveCanvasState().

◆ m_executionTestPanel

std::unique_ptr<ExecutionTestPanel> Olympe::BehaviorTreeRenderer::m_executionTestPanel
private

REUSED: Simulation results panel.

Definition at line 84 of file BehaviorTreeRenderer.h.

Referenced by BehaviorTreeRenderer(), OnRunGraphClicked(), and Render().

◆ m_filePath

std::string Olympe::BehaviorTreeRenderer::m_filePath
private

Path that was loaded.

Definition at line 80 of file BehaviorTreeRenderer.h.

Referenced by CreateNew(), GetCurrentPath(), Load(), and Save().

◆ m_graphId

int Olympe::BehaviorTreeRenderer::m_graphId
private

ID in BTNodeGraphManager; -1 if not loaded.

Definition at line 79 of file BehaviorTreeRenderer.h.

Referenced by AcceptNodeDrop(), CreateNew(), HandleKeyboardShortcuts(), IsDirty(), Load(), OnRunGraphClicked(), Render(), RenderRightPanelTabs(), Save(), and ~BehaviorTreeRenderer().

◆ m_lastTracer

std::unique_ptr<GraphExecutionTracer> Olympe::BehaviorTreeRenderer::m_lastTracer
private

Last simulation trace for results display.

Definition at line 85 of file BehaviorTreeRenderer.h.

Referenced by BehaviorTreeRenderer().

◆ m_palette

std::unique_ptr<AI::BTNodePalette> Olympe::BehaviorTreeRenderer::m_palette
private

BTNodePalette for drag-drop.

Definition at line 77 of file BehaviorTreeRenderer.h.

Referenced by BehaviorTreeRenderer(), and RenderRightPanelTabs().

◆ m_panel

NodeGraphPanel& Olympe::BehaviorTreeRenderer::m_panel
private

Shared panel reference (not owned)

Definition at line 76 of file BehaviorTreeRenderer.h.

Referenced by HandleKeyboardShortcuts(), RenderLayoutWithTabs(), and RenderRightPanelTabs().

◆ m_propertyPanel

BTNodePropertyPanel Olympe::BehaviorTreeRenderer::m_propertyPanel
private

Property editor for node properties.

Definition at line 78 of file BehaviorTreeRenderer.h.

Referenced by BehaviorTreeRenderer(), and RenderRightPanelTabs().

◆ m_rightPanelTabSelection

int Olympe::BehaviorTreeRenderer::m_rightPanelTabSelection = 0
private

0 = Palette, 1 = Properties

Definition at line 82 of file BehaviorTreeRenderer.h.

◆ m_savedCanvasState

struct Olympe::BehaviorTreeRenderer::CanvasState Olympe::BehaviorTreeRenderer::m_savedCanvasState
private

The documentation for this class was generated from the following files: