Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
NodeStyleRegistry.h
Go to the documentation of this file.
1/**
2 * @file NodeStyleRegistry.h
3 * @brief Per-NodeType visual style registry (header colour, icon, pin colours).
4 * @author Olympe Engine
5 *
6 * @details
7 * NodeStyleRegistry provides a singleton that maps NodeType values to
8 * NodeStyle descriptors used when rendering nodes in the editor. The
9 * registry is populated once at construction and queried every frame; no
10 * heap allocations occur during rendering.
11 *
12 * C++14 compliant - no C++17/20 features.
13 */
14
15#pragma once
16
17#include <string>
18#include <unordered_map>
19
20#include "../third_party/imgui/imgui.h"
21#include "BTNodeGraphManager.h"
22
23namespace Olympe
24{
25
26/**
27 * @struct NodeStyle
28 * @brief Visual descriptor for a single node type.
29 */
31{
32 /// Title-bar background colour (ImNodes TitleBar colour slot).
33 ImU32 headerColor = IM_COL32(80, 80, 80, 255);
34 /// Title-bar colour when the node is hovered.
35 ImU32 headerHoveredColor = IM_COL32(100, 100, 100, 255);
36 /// Title-bar colour when the node is selected.
37 ImU32 headerSelectedColor = IM_COL32(120, 120, 120, 255);
38 /// Short ASCII icon displayed before the node title (no emoji/extended chars).
39 const char* icon = "";
40};
41
42/**
43 * @class NodeStyleRegistry
44 * @brief Singleton providing NodeStyle descriptors per NodeType.
45 *
46 * @details
47 * Usage:
48 * @code
49 * const NodeStyle& style = NodeStyleRegistry::Get().GetStyle(node->type);
50 * ImNodes::PushColorStyle(ImNodesCol_TitleBar, style.headerColor);
51 * ImNodes::PushColorStyle(ImNodesCol_TitleBarHovered, style.headerHoveredColor);
52 * ImNodes::PushColorStyle(ImNodesCol_TitleBarSelected, style.headerSelectedColor);
53 * ImNodes::BeginNode(id);
54 * // ...
55 * ImNodes::EndNode();
56 * ImNodes::PopColorStyle();
57 * ImNodes::PopColorStyle();
58 * ImNodes::PopColorStyle();
59 * @endcode
60 *
61 * For exec-flow pins use GetExecPinColor(); for data pins GetDataPinColor().
62 */
64{
65public:
66 /// Returns the singleton instance.
67 static NodeStyleRegistry& Get();
68
69 /**
70 * @brief Returns the style for the given node type.
71 * Falls back to the default grey style for unknown types.
72 */
73 const NodeStyle& GetStyle(NodeType type) const;
74
75 /**
76 * @brief Returns the style to use for an atomic-task node identified by ID.
77 * Currently returns the BT_Action style for all task IDs.
78 */
79 const NodeStyle& GetStyleByTaskID(const std::string& taskId) const;
80
81 /**
82 * @brief Returns the style for a VS node type identified by string.
83 *
84 * Used by the VS graph renderer which uses TaskNodeType, not the legacy
85 * NodeType enum.
86 *
87 * @param vsTypeName String form of TaskNodeType (e.g. "EntryPoint", "Branch", "Delay").
88 * @return NodeStyle for the given type, or default grey if unknown.
89 */
90 const NodeStyle& GetStyleByVSTypeName(const std::string& vsTypeName) const;
91
92 /// Colour for execution-flow (exec) pins — white.
93 static ImU32 GetExecPinColor();
94
95 /// Colour for data pins — green.
96 static ImU32 GetDataPinColor();
97
98private:
100
102
103 /// Key is the underlying int value of NodeType.
104 std::unordered_map<int, NodeStyle> m_styles;
105
106 /// Key is the VS type name string (TaskNodeType as string).
107 std::unordered_map<std::string, NodeStyle> m_vsStyles;
108};
109
110} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Singleton providing NodeStyle descriptors per NodeType.
const NodeStyle & GetStyleByTaskID(const std::string &taskId) const
Returns the style to use for an atomic-task node identified by ID.
std::unordered_map< int, NodeStyle > m_styles
Key is the underlying int value of NodeType.
static ImU32 GetExecPinColor()
Colour for execution-flow (exec) pins — white.
const NodeStyle & GetStyle(NodeType type) const
Returns the style for the given node type.
static NodeStyleRegistry & Get()
Returns the singleton instance.
std::unordered_map< std::string, NodeStyle > m_vsStyles
Key is the VS type name string (TaskNodeType as string).
static ImU32 GetDataPinColor()
Colour for data pins — green.
const NodeStyle & GetStyleByVSTypeName(const std::string &vsTypeName) const
Returns the style for a VS node type identified by string.
< Provides AssetID and INVALID_ASSET_ID
Visual descriptor for a single node type.
ImU32 headerColor
Title-bar background colour (ImNodes TitleBar colour slot).
ImU32 headerSelectedColor
Title-bar colour when the node is selected.
const char * icon
Short ASCII icon displayed before the node title (no emoji/extended chars).
ImU32 headerHoveredColor
Title-bar colour when the node is hovered.