Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
MathOpPropertyPanel.cpp
Go to the documentation of this file.
1/**
2 * @file MathOpPropertyPanel.cpp
3 * @brief Implementation of MathOp properties panel with operand editors.
4 */
5
7#include "../../third_party/imgui/imgui.h"
8#include "../../BlueprintEditor/ConditionRef.h"
9#include "../../BlueprintEditor/MathOpOperand.h"
10
11namespace Olympe {
12
13// ============================================================================
14// Constructor
15// ============================================================================
16
23
24// ============================================================================
25// State accessors
26// ============================================================================
27
32
37
38void MathOpPropertyPanel::SetDynamicPins(const std::vector<DynamicDataPin>& pins)
39{
41}
42
43void MathOpPropertyPanel::SetNodeName(const std::string& name)
44{
45 m_nodeName = name;
46}
47
48// ============================================================================
49// Rendering
50// ============================================================================
51
53{
55 ImGui::Spacing();
56
58 ImGui::Spacing();
59
60 if (!m_dynamicPins.empty()) {
62 }
63}
64
66{
67 ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.2f, 0.5f, 0.9f, 1.0f));
68 ImGui::Text("MathOp: %s", m_nodeName.c_str());
69 ImGui::PopStyleColor();
70}
71
73{
74 ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.0f, 0.7f, 0.4f, 1.0f));
75 const bool editorOpen = ImGui::CollapsingHeader(
76 "Operand Editor (Inline)", ImGuiTreeNodeFlags_DefaultOpen);
77 ImGui::PopStyleColor();
78
79 if (!editorOpen) return;
80
81 ImGui::Indent();
82
83 // Left operand row
84 ImGui::Text("Left Operand (A):");
86
87 ImGui::Spacing();
88 ImGui::Separator();
89 ImGui::Spacing();
90
91 // Operator selector (centered)
92 ImGui::Text("Operator:");
94
95 ImGui::Spacing();
96 ImGui::Separator();
97 ImGui::Spacing();
98
99 // Right operand row
100 ImGui::Text("Right Operand (B):");
102
103 ImGui::Unindent();
104}
105
107{
108 // Mode selector (Variable/Const/Pin)
109 const char* modes[] = { "Variable", "Const", "Pin" };
110 int modeIdx = static_cast<int>(operand.mode);
111
112 std::string modeLabel = "Mode##operand" + std::to_string(rowIndex);
113 if (ImGui::Combo(modeLabel.c_str(), &modeIdx, modes, 3)) {
114 operand.mode = static_cast<MathOpOperand::Mode>(modeIdx);
115 m_dirty = true;
116 if (m_onOperandChange) {
118 }
119 }
120
121 ImGui::Indent();
122
123 // Render mode-specific input
124 switch (operand.mode) {
127 break;
130 break;
133 break;
134 }
135
136 ImGui::Unindent();
137}
138
140{
141 static char varNameBuf[256] = {};
142 strcpy_s(varNameBuf, sizeof(varNameBuf), operand.variableName.c_str());
143
144 std::string label = "Variable Name##var" + operand.variableName;
145 if (ImGui::InputText(label.c_str(), varNameBuf, sizeof(varNameBuf))) {
146 operand.variableName = varNameBuf;
147 m_dirty = true;
148 if (m_onOperandChange) {
150 }
151 }
152
153 ImGui::Text("(e.g., \"mSpeed\", \"mHealth\")");
154}
155
157{
158 static char constBuf[64] = {};
159 strcpy_s(constBuf, sizeof(constBuf), operand.constValue.c_str());
160
161 std::string label = "Constant Value##const" + operand.constValue;
162 if (ImGui::InputText(label.c_str(), constBuf, sizeof(constBuf))) {
163 operand.constValue = constBuf;
164 m_dirty = true;
165 }
166
167 ImGui::Text("(e.g., \"5.0\", \"100\")");
168}
169
171{
172 ImGui::Text("Pin Selection:");
173 ImGui::Indent();
174
175 if (m_dynamicPins.empty()) {
176 ImGui::Text("(No dynamic pins yet)");
177 } else {
178 for (size_t i = 0; i < m_dynamicPins.size(); ++i) {
179 std::string pinLabel = "Pin #" + std::to_string(i) + ": " +
180 m_dynamicPins[i].label;
181
182 bool selected = (operand.dynamicPinID == m_dynamicPins[i].id);
183 if (ImGui::Selectable(pinLabel.c_str(), selected)) {
184 operand.dynamicPinID = m_dynamicPins[i].id;
185 m_dirty = true;
186 if (m_onOperandChange) {
188 }
189 }
190 }
191 }
192
193 ImGui::Unindent();
194}
195
197{
198 const char* operators[] = { "+", "-", "*", "/", "%", "^" };
199 int opIdx = 0;
200
201 // Find current operator in list
202 for (int i = 0; i < 6; ++i) {
204 opIdx = i;
205 break;
206 }
207 }
208
209 if (ImGui::Combo("Math Operator##op", &opIdx, operators, 6)) {
211 m_dirty = true;
212 }
213
214 ImGui::Text("Result = [Left] %s [Right]", m_mathOpRef.mathOperator.c_str());
215}
216
218{
219 ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(1.0f, 1.0f, 0.0f, 1.0f));
220 const bool pinsOpen = ImGui::CollapsingHeader("Dynamic Pins (Read-Only)");
221 ImGui::PopStyleColor();
222
223 if (!pinsOpen) return;
224
225 ImGui::Indent();
226
227 for (size_t i = 0; i < m_dynamicPins.size(); ++i) {
228 ImGui::BulletText("%s (Pin ID: %s)",
229 m_dynamicPins[i].label.c_str(),
230 m_dynamicPins[i].id.c_str());
231 }
232
233 ImGui::Unindent();
234}
235
236} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
UI Properties panel for a MathOp node – operand editor.
Manages the global pool of ConditionPreset objects.
Generates, tracks, and invalidates DynamicDataPin objects for a node.
bool m_dirty
Changed since last ClearDirty()
void SetNodeName(const std::string &name)
Sets the node name displayed in the title section.
void SetDynamicPins(const std::vector< DynamicDataPin > &pins)
Provides the read-only list of dynamic pins for display.
MathOpRef m_mathOpRef
Current operand configuration.
void RenderPinModeSelector(MathOpOperand &operand)
Helper to render Pin mode selector (list of available pins).
std::string m_nodeName
Node name for display.
void RenderVariableModeInput(MathOpOperand &operand)
Helper to render Variable mode input field.
void RenderOperatorSelector()
Renders the operator dropdown ("+", "-", "*", "/", "%", "^").
void SetMathOpRef(const MathOpRef &ref)
Sets the MathOpRef to edit.
void RenderTitleSection()
Renders the title section (node name in blue background).
void RenderDynamicPinsSection()
Renders the dynamic pins section (read-only display).
void RenderConstModeInput(MathOpOperand &operand)
Helper to render Const mode input field.
const MathOpRef & GetMathOpRef() const
Returns the current (possibly modified) MathOpRef.
void RenderInlineOperandEditor()
Renders the operand editor (collapsible section with 3 rows).
MathOpPropertyPanel(ConditionPresetRegistry &registry, DynamicDataPinManager &dynamicPinMgr)
Constructs the panel bound to a preset registry.
void RenderOperandRow(int rowIndex, MathOpOperand &operand)
Renders one operand row with mode selector and value input.
std::vector< DynamicDataPin > m_dynamicPins
Read-only dynamic pins display.
std::function< void()> m_onOperandChange
Callback when operands change.
void Render()
Renders the panel into the current ImGui context.
< Provides AssetID and INVALID_ASSET_ID
Represents one arithmetic operand (left A, right B) in a MathOp node.
Mode
Discriminates the data source of this operand.
@ Variable
References a blackboard variable by name.
@ Const
Literal constant value.
@ Pin
External data-input pin on the owning node.
Complete reference for a MathOp node: left operand, operator, right operand.
MathOpOperand leftOperand
Left-hand side operand (A)
std::string mathOperator
Arithmetic operator: "+", "-", "*", "/", "%", "^".
MathOpOperand rightOperand
Right-hand side operand (B)