Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
ConditionPresetLibraryPanel.h
Go to the documentation of this file.
1/**
2 * @file ConditionPresetLibraryPanel.h
3 * @brief UI panel for managing Condition Presets globally (Phase 24.1).
4 * @author Olympe Engine
5 * @date 2026-03-16
6 *
7 * @details
8 * ConditionPresetLibraryPanel is the centralized editor panel where users
9 * create, edit, duplicate, delete, and search condition presets at the
10 * project level.
11 *
12 * The panel owns the ImGui window "Condition Preset Library" and delegates
13 * all data operations to the ConditionPresetRegistry it holds by reference.
14 *
15 * Layout:
16 * @code
17 * ╔══════════════════════════════════════════╗
18 * ║ Condition Preset Library ║
19 * ├──────────────────────────────────────────┤
20 * ║ [+] Add Condition Preset [Search] ║
21 * ├──────────────────────────────────────────┤
22 * ║ ▼ Condition #1 [Dup][Del] ║
23 * ║ [mHealth] <= [2] ║
24 * ║ Used by: Node_A, Node_C ║
25 * ╚══════════════════════════════════════════╝
26 * @endcode
27 *
28 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
29 */
30
31#pragma once
32
33#include <string>
34#include <vector>
35#include <functional>
36#include <map>
37
38#include "../../Editor/ConditionPreset/ConditionPreset.h"
39#include "../../Editor/ConditionPreset/ConditionPresetRegistry.h"
40
41namespace Olympe {
42
43/**
44 * @class ConditionPresetLibraryPanel
45 * @brief ImGui panel for creating, editing, duplicating, and deleting
46 * global condition presets.
47 *
48 * @details
49 * The panel uses ConditionPresetEditDialog internally for the create/edit
50 * workflow. Deletion requires confirmation via a modal dialog.
51 *
52 * Optional callbacks allow the host (e.g. the Blueprint Editor) to react to
53 * preset lifecycle events:
54 * - OnPresetCreated(id) — a new preset was added to the registry
55 * - OnPresetModified(id) — an existing preset was updated
56 * - OnPresetDeleted(id) — a preset was removed from the registry
57 */
59public:
60
61 /**
62 * @brief Constructs the panel with a reference to the preset registry.
63 * @param registry The global ConditionPresetRegistry to operate on.
64 */
66
68
69 // Non-copyable
72
73 // -----------------------------------------------------------------------
74 // Visibility
75 // -----------------------------------------------------------------------
76
77 /** @brief Returns true if the panel window is open. */
78 bool IsOpen() const { return m_isOpen; }
79
80 /** @brief Opens the panel window. */
81 void Open() { m_isOpen = true; }
82
83 /** @brief Closes the panel window. */
84 void Close() { m_isOpen = false; }
85
86 // -----------------------------------------------------------------------
87 // Rendering (ImGui — not called in tests)
88 // -----------------------------------------------------------------------
89
90 /**
91 * @brief Renders the full panel window using ImGui.
92 *
93 * Must be called once per frame while the panel is open.
94 * No-op when !IsOpen().
95 */
96 void Render();
97
98 // -----------------------------------------------------------------------
99 // Callbacks
100 // -----------------------------------------------------------------------
101
102 /** Invoked after a new preset is added. Arg: preset ID. */
103 std::function<void(const std::string&)> OnPresetCreated;
104
105 /** Invoked after an existing preset is modified. Arg: preset ID. */
106 std::function<void(const std::string&)> OnPresetModified;
107
108 /** Invoked after a preset is deleted. Arg: preset ID. */
109 std::function<void(const std::string&)> OnPresetDeleted;
110
111 // -----------------------------------------------------------------------
112 // Testable logic interface
113 // -----------------------------------------------------------------------
114
115 /**
116 * @brief Sets the search filter string (case-insensitive substring).
117 * @param filter Filter text. Empty string shows all presets.
118 */
119 void SetSearchFilter(const std::string& filter);
120
121 /**
122 * @brief Returns the current search filter string.
123 */
124 const std::string& GetSearchFilter() const { return m_searchFilter; }
125
126 /**
127 * @brief Selects the preset with the given ID.
128 * @param id Preset ID to select, or empty string to deselect.
129 */
130 void SetSelectedPresetID(const std::string& id);
131
132 /**
133 * @brief Returns the currently selected preset ID (empty if none).
134 */
135 const std::string& GetSelectedPresetID() const { return m_selectedPresetID; }
136
137 /**
138 * @brief Returns true if the delete confirmation dialog is currently shown.
139 */
141
142 /**
143 * @brief Returns the ID of the preset pending deletion confirmation.
144 */
145 const std::string& GetPresetToDelete() const { return m_presetToDelete; }
146
147 /**
148 * @brief Returns a reference to the registry managed by this panel.
149 */
151
152 /**
153 * @brief Returns filtered presets based on the current search filter.
154 *
155 * Delegates to ConditionPresetRegistry::GetFilteredPresets().
156 */
157 std::vector<ConditionPreset> GetFilteredPresets() const;
158
159 /**
160 * @brief Sets the reference analysis map (nodeID -> list of preset IDs used).
161 *
162 * This data is supplied externally by the host (e.g. Blueprint Editor)
163 * and used to display "Used by: Node_A, Node_C" in the panel.
164 *
165 * @param refMap Map from nodeID to vector of preset IDs that node uses.
166 */
167 void SetReferenceMap(const std::map<std::string, std::vector<std::string>>& refMap);
168
169 /**
170 * @brief Returns a list of node IDs that reference the given preset.
171 * @param presetID Preset ID to query.
172 */
173 std::vector<std::string> GetReferencingNodes(const std::string& presetID) const;
174
175 // -----------------------------------------------------------------------
176 // Action handlers (called from Render; also testable)
177 // -----------------------------------------------------------------------
178
179 /**
180 * @brief Handles the "Add Preset" button.
181 *
182 * Creates a new empty ConditionPreset in the registry.
183 * Fires OnPresetCreated with the new ID.
184 *
185 * @return The new preset's ID.
186 */
187 std::string OnAddPresetClicked();
188
189 /**
190 * @brief Handles the "Duplicate" button for a preset.
191 *
192 * Duplicates the preset in the registry.
193 * Fires OnPresetCreated with the new ID.
194 *
195 * @param presetID ID of the preset to duplicate.
196 * @return The new preset's ID, or empty string if presetID not found.
197 */
198 std::string OnDuplicatePresetClicked(const std::string& presetID);
199
200 /**
201 * @brief Handles the "Delete" button for a preset.
202 *
203 * Sets m_showDeleteConfirmation = true and records m_presetToDelete.
204 * Does NOT delete immediately; call OnDeleteConfirmed() to confirm.
205 *
206 * @param presetID ID of the preset the user wants to delete.
207 */
208 void OnDeletePresetClicked(const std::string& presetID);
209
210 /**
211 * @brief Confirms the pending deletion.
212 *
213 * Removes the preset from the registry and fires OnPresetDeleted.
214 * Resets m_showDeleteConfirmation to false.
215 *
216 * @param presetID ID of the preset to delete (must match m_presetToDelete).
217 */
218 void OnDeleteConfirmed(const std::string& presetID);
219
220 /**
221 * @brief Cancels the pending deletion and hides the confirmation dialog.
222 */
223 void OnDeleteCancelled();
224
225 /**
226 * @brief Selects a preset (highlights it in the list).
227 * @param presetID ID of the preset to select.
228 */
229 void OnPresetSelected(const std::string& presetID);
230
231private:
232
233 // -----------------------------------------------------------------------
234 // ImGui rendering helpers (not tested directly)
235 // -----------------------------------------------------------------------
236
237 void RenderToolbar();
238 void RenderPresetList();
239 void RenderPresetItem(const std::string& presetID, const ConditionPreset& preset);
241 void RenderReferenceAnalysis(const std::string& presetID);
242
243 // -----------------------------------------------------------------------
244 // State
245 // -----------------------------------------------------------------------
246
247 ConditionPresetRegistry& m_registry; ///< Global preset registry
248 bool m_isOpen = false;
249 std::string m_selectedPresetID; ///< Highlighted preset ID
250 std::string m_searchFilter; ///< Current search text
252 std::string m_presetToDelete; ///< ID queued for deletion
253
254 /// External reference map: nodeID -> list of preset IDs that node references
255 std::map<std::string, std::vector<std::string>> m_refMap;
256};
257
258} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
ImGui panel for creating, editing, duplicating, and deleting global condition presets.
void RenderReferenceAnalysis(const std::string &presetID)
std::vector< ConditionPreset > GetFilteredPresets() const
Returns filtered presets based on the current search filter.
void RenderPresetItem(const std::string &presetID, const ConditionPreset &preset)
std::string m_selectedPresetID
Highlighted preset ID.
ConditionPresetLibraryPanel & operator=(const ConditionPresetLibraryPanel &)=delete
std::string m_searchFilter
Current search text.
void SetSelectedPresetID(const std::string &id)
Selects the preset with the given ID.
ConditionPresetLibraryPanel(const ConditionPresetLibraryPanel &)=delete
std::string OnDuplicatePresetClicked(const std::string &presetID)
Handles the "Duplicate" button for a preset.
void OnPresetSelected(const std::string &presetID)
Selects a preset (highlights it in the list).
void OnDeleteCancelled()
Cancels the pending deletion and hides the confirmation dialog.
const std::string & GetPresetToDelete() const
Returns the ID of the preset pending deletion confirmation.
std::map< std::string, std::vector< std::string > > m_refMap
External reference map: nodeID -> list of preset IDs that node references.
ConditionPresetRegistry & m_registry
Global preset registry.
void SetSearchFilter(const std::string &filter)
Sets the search filter string (case-insensitive substring).
void SetReferenceMap(const std::map< std::string, std::vector< std::string > > &refMap)
Sets the reference analysis map (nodeID -> list of preset IDs used).
void OnDeletePresetClicked(const std::string &presetID)
Handles the "Delete" button for a preset.
const std::string & GetSelectedPresetID() const
Returns the currently selected preset ID (empty if none).
bool IsOpen() const
Returns true if the panel window is open.
void OnDeleteConfirmed(const std::string &presetID)
Confirms the pending deletion.
std::function< void(const std::string &)> OnPresetModified
Invoked after an existing preset is modified.
std::function< void(const std::string &)> OnPresetDeleted
Invoked after a preset is deleted.
std::string OnAddPresetClicked()
Handles the "Add Preset" button.
bool IsDeleteConfirmationVisible() const
Returns true if the delete confirmation dialog is currently shown.
ConditionPresetRegistry & GetRegistry()
Returns a reference to the registry managed by this panel.
void Render()
Renders the full panel window using ImGui.
std::string m_presetToDelete
ID queued for deletion.
const std::string & GetSearchFilter() const
Returns the current search filter string.
std::function< void(const std::string &)> OnPresetCreated
Invoked after a new preset is added.
std::vector< std::string > GetReferencingNodes(const std::string &presetID) const
Returns a list of node IDs that reference the given preset.
Manages the global pool of ConditionPreset objects.
< Provides AssetID and INVALID_ASSET_ID
A globally-stored, reusable condition expression.