Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ConditionPresetEditDialog.h
Go to the documentation of this file.
1/**
2 * @file ConditionPresetEditDialog.h
3 * @brief Modal dialog for creating and editing Condition Presets (Phase 24.1).
4 * @author Olympe Engine
5 * @date 2026-03-16
6 *
7 * @details
8 * ConditionPresetEditDialog presents a modal form where the user can
9 * configure a condition expression by selecting:
10 * - Left operand (Variable | Const | Pin)
11 * - Comparison operator (== != < <= > >=)
12 * - Right operand (Variable | Const | Pin)
13 *
14 * Modes:
15 * - Create: opens with a blank preset; confirmed result is a new preset.
16 * - Edit: opens with an existing preset; confirmed result replaces it.
17 *
18 * Usage example:
19 * @code
20 * // Open in Edit mode:
21 * ConditionPresetEditDialog dlg(ConditionPresetEditDialog::Mode::Edit, &myPreset);
22 * dlg.Open();
23 *
24 * // In render loop:
25 * dlg.Render();
26 * if (dlg.IsConfirmed()) {
27 * ConditionPreset result = dlg.GetResult();
28 * registry.UpdatePreset(result.id, result);
29 * }
30 * @endcode
31 *
32 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
33 */
34
35#pragma once
36
37#include <string>
38#include <vector>
39
40#include "../ConditionPreset/ConditionPreset.h"
41#include "../../TaskSystem/LocalBlackboard.h"
42
43namespace Olympe {
44
45/**
46 * @class ConditionPresetEditDialog
47 * @brief Modal dialog for creating or editing a single ConditionPreset.
48 */
50public:
51
52 /**
53 * @enum Mode
54 * @brief Whether the dialog creates a new preset or edits an existing one.
55 */
56 enum class Mode {
57 Create, ///< New preset (form starts empty)
58 Edit ///< Existing preset (form pre-populated)
59 };
60
61 // -----------------------------------------------------------------------
62 // Construction
63 // -----------------------------------------------------------------------
64
65 /**
66 * @brief Constructs the dialog in Create mode with a blank preset.
67 */
69
70 /**
71 * @brief Constructs the dialog in the given mode.
72 *
73 * @param mode Create or Edit.
74 * @param existingPreset If Mode::Edit, the preset to edit (copied).
75 * If nullptr or Mode::Create, the form is blank.
76 */
77 explicit ConditionPresetEditDialog(Mode mode,
78 const ConditionPreset* existingPreset = nullptr);
79
81
82 // -----------------------------------------------------------------------
83 // Visibility
84 // -----------------------------------------------------------------------
85
86 /** @brief Returns true if the dialog is open. */
87 bool IsOpen() const { return m_isOpen; }
88
89 /** @brief Opens the dialog. */
90 void Open() { m_isOpen = true; m_isConfirmed = false; }
91
92 /** @brief Closes the dialog without confirming. */
93 void Close() { m_isOpen = false; }
94
95 // -----------------------------------------------------------------------
96 // State queries
97 // -----------------------------------------------------------------------
98
99 /**
100 * @brief Returns true if the user pressed "Save" / "OK".
101 *
102 * Reset to false each time Open() is called.
103 */
104 bool IsConfirmed() const { return m_isConfirmed; }
105
106 /**
107 * @brief Returns the dialog mode (Create or Edit).
108 */
109 Mode GetMode() const { return m_mode; }
110
111 /**
112 * @brief Returns a copy of the working preset (contains the current form state).
113 */
115
116 // -----------------------------------------------------------------------
117 // Operand accessors (also used by tests to inspect / drive state)
118 // -----------------------------------------------------------------------
119
120 /**
121 * @brief Returns the current left operand.
122 */
123 const Operand& GetLeftOperand() const { return m_workingCopy.left; }
124
125 /**
126 * @brief Returns the current right operand.
127 */
128 const Operand& GetRightOperand() const { return m_workingCopy.right; }
129
130 /**
131 * @brief Returns the current comparison operator.
132 */
134
135 // -----------------------------------------------------------------------
136 // Programmatic setters (for testing and host-driven pre-population)
137 // -----------------------------------------------------------------------
138
139 /**
140 * @brief Sets the left operand mode.
141 * @param mode "Variable", "Const", or "Pin".
142 */
143 void SetLeftMode(const std::string& mode);
144
145 /**
146 * @brief Sets the left variable name (relevant when leftMode == "Variable").
147 */
148 void SetLeftVariable(const std::string& varName);
149
150 /**
151 * @brief Sets the left constant value.
152 */
153 void SetLeftConst(double value);
154
155 /**
156 * @brief Sets the left pin reference.
157 */
158 void SetLeftPin(const std::string& pinRef);
159
160 /**
161 * @brief Sets the comparison operator.
162 * @param op One of "==", "!=", "<", "<=", ">", ">=".
163 */
164 void SetOperator(const std::string& op);
165
166 /**
167 * @brief Sets the right operand mode.
168 * @param mode "Variable", "Const", or "Pin".
169 */
170 void SetRightMode(const std::string& mode);
171
172 /**
173 * @brief Sets the right variable name.
174 */
175 void SetRightVariable(const std::string& varName);
176
177 /**
178 * @brief Sets the right constant value.
179 */
180 void SetRightConst(double value);
181
182 /**
183 * @brief Sets the right pin reference (relevant when rightMode == "Pin").
184 */
185 void SetRightPin(const std::string& pinRef);
186
187 /**
188 * @brief Sets the display name of the working preset.
189 */
190 void SetName(const std::string& name);
191
192 // -----------------------------------------------------------------------
193 // Preview
194 // -----------------------------------------------------------------------
195
196 /**
197 * @brief Returns a live preview string of the current condition.
198 *
199 * Example: "[mHealth] <= [2]"
200 */
201 std::string GetPreview() const;
202
203 // -----------------------------------------------------------------------
204 // Validation
205 // -----------------------------------------------------------------------
206
207 /**
208 * @brief Returns true if the current condition is valid and can be saved.
209 *
210 * A condition is valid when:
211 * - left mode is non-empty and the corresponding operand is filled
212 * - operator is a valid comparison string
213 * - right mode is non-empty and the corresponding operand is filled
214 */
215 bool IsValid() const;
216
217 // -----------------------------------------------------------------------
218 // Programmatic confirmation (for testing)
219 // -----------------------------------------------------------------------
220
221 /**
222 * @brief Confirms the dialog programmatically (equivalent to pressing Save).
223 *
224 * Only succeeds if IsValid() returns true.
225 * @return true if confirmation succeeded, false if the condition is invalid.
226 */
227 bool Confirm();
228
229 // -----------------------------------------------------------------------
230 // Rendering (ImGui — not called in tests)
231 // -----------------------------------------------------------------------
232
233 /**
234 * @brief Renders the modal dialog using ImGui.
235 *
236 * Must be called once per frame while the dialog is open.
237 * No-op when !IsOpen().
238 */
239 void Render();
240
241 // -----------------------------------------------------------------------
242 // Phase 24 Global Blackboard Integration
243 // -----------------------------------------------------------------------
244
245 /**
246 * @brief Sets the list of local variables from EntityBlackboard.
247 * @param localVars Vector of local variable definitions.
248 */
249 void SetLocalVariables(const std::vector<BlackboardEntry>& localVars)
250 {
252 }
253
254private:
255
256 // -----------------------------------------------------------------------
257 // ImGui rendering helpers
258 // -----------------------------------------------------------------------
259
260 void RenderOperandSelector(const char* label, bool isLeft);
262 void RenderPreview();
264
265 // -----------------------------------------------------------------------
266 // Helpers
267 // -----------------------------------------------------------------------
268
269 /** @brief Returns true if the given operator string is recognised. */
270 static bool IsValidOperator(const std::string& op);
271
272 /** @brief Returns true if the given mode string is recognised. */
273 static bool IsValidMode(const std::string& mode);
274
275 /** @brief Returns true if the operand is sufficiently filled. */
276 static bool IsOperandFilled(const Operand& operand);
277
278 // -----------------------------------------------------------------------
279 // State
280 // -----------------------------------------------------------------------
281
283 ConditionPreset m_workingCopy; ///< In-progress edits
284 bool m_isOpen = false;
285 bool m_isConfirmed = false;
286 std::vector<BlackboardEntry> m_localVariables; ///< Local variables from entity (Phase 24)
287};
288
289} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Modal dialog for creating or editing a single ConditionPreset.
void SetLocalVariables(const std::vector< BlackboardEntry > &localVars)
Sets the list of local variables from EntityBlackboard.
bool IsConfirmed() const
Returns true if the user pressed "Save" / "OK".
void SetOperator(const std::string &op)
Sets the comparison operator.
void SetName(const std::string &name)
Sets the display name of the working preset.
void Close()
Closes the dialog without confirming.
bool IsOpen() const
Returns true if the dialog is open.
ConditionPresetEditDialog()
Constructs the dialog in Create mode with a blank preset.
ConditionPreset m_workingCopy
In-progress edits.
bool Confirm()
Confirms the dialog programmatically (equivalent to pressing Save).
ConditionPreset GetResult() const
Returns a copy of the working preset (contains the current form state).
static bool IsValidOperator(const std::string &op)
Returns true if the given operator string is recognised.
void SetRightVariable(const std::string &varName)
Sets the right variable name.
void SetRightPin(const std::string &pinRef)
Sets the right pin reference (relevant when rightMode == "Pin").
std::vector< BlackboardEntry > m_localVariables
Local variables from entity (Phase 24)
static bool IsOperandFilled(const Operand &operand)
Returns true if the operand is sufficiently filled.
static bool IsValidMode(const std::string &mode)
Returns true if the given mode string is recognised.
const Operand & GetRightOperand() const
Returns the current right operand.
ComparisonOp GetOperator() const
Returns the current comparison operator.
void SetLeftPin(const std::string &pinRef)
Sets the left pin reference.
std::string GetPreview() const
Returns a live preview string of the current condition.
const Operand & GetLeftOperand() const
Returns the current left operand.
void RenderOperandSelector(const char *label, bool isLeft)
void SetLeftVariable(const std::string &varName)
Sets the left variable name (relevant when leftMode == "Variable").
void SetLeftConst(double value)
Sets the left constant value.
bool IsValid() const
Returns true if the current condition is valid and can be saved.
void Render()
Renders the modal dialog using ImGui.
Mode
Whether the dialog creates a new preset or edits an existing one.
@ Create
New preset (form starts empty)
@ Edit
Existing preset (form pre-populated)
Mode GetMode() const
Returns the dialog mode (Create or Edit).
void SetRightMode(const std::string &mode)
Sets the right operand mode.
void SetLeftMode(const std::string &mode)
Sets the left operand mode.
void SetRightConst(double value)
Sets the right constant value.
< Provides AssetID and INVALID_ASSET_ID
ComparisonOp
The relational operator used in a ConditionPreset.
A globally-stored, reusable condition expression.
One side of a ConditionPreset comparison expression.
Definition Operand.h:45