Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
SwitchCaseEditorModal.h
Go to the documentation of this file.
1/**
2 * @file SwitchCaseEditorModal.h
3 * @brief Dedicated modal dialog for editing a Switch node's case definitions (Phase 26).
4 * @author Olympe Engine
5 * @date 2026-03-20
6 *
7 * @details
8 * SwitchCaseEditorModal provides a modal overlay to add, remove, reorder, and
9 * configure the case definitions on a Switch node. Each case maps a value to a pin.
10 * It is separate from the properties panel so that edits are confirmed in one atomic
11 * Apply step.
12 *
13 * Usage:
14 * @code
15 * SwitchCaseEditorModal modal;
16 *
17 * // When user clicks "Edit Switch Cases" in the Properties panel:
18 * modal.Open(node.switchCases);
19 *
20 * // In render loop:
21 * modal.Render();
22 * if (modal.IsConfirmed()) {
23 * node.switchCases = modal.GetSwitchCases();
24 * modal.Close();
25 * }
26 * @endcode
27 *
28 * The modal works on a COPY of the node's switch cases. On "Apply" it marks
29 * itself as confirmed; on "Cancel" the copy is discarded.
30 *
31 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
32 */
33
34#pragma once
35
36#include <string>
37#include <vector>
38
39#include "../../TaskSystem/TaskGraphTypes.h"
40
41namespace Olympe {
42
43/**
44 * @class SwitchCaseEditorModal
45 * @brief Modal dialog for adding, removing, and reordering switch cases on a node.
46 *
47 * @details
48 * The modal contains:
49 * - A scrollable list of current cases, each with:
50 * - Value input field (match value as string)
51 * - Custom label input field (optional display name)
52 * - Delete [X] button
53 * - Move Up / Move Down buttons
54 * - An "Add Case" button
55 * - Apply and Cancel buttons at the bottom
56 */
58public:
59
60 /**
61 * @brief Constructs the modal.
62 */
64
66
67 // Non-copyable
70
71 // -----------------------------------------------------------------------
72 // Visibility / lifecycle
73 // -----------------------------------------------------------------------
74
75 /**
76 * @brief Returns true if the modal is currently open.
77 */
78 bool IsOpen() const { return m_isOpen; }
79
80 /**
81 * @brief Opens the modal, loading the given switch cases for editing.
82 *
83 * Resets the confirmed flag and takes a COPY of the cases to edit.
84 *
85 * @param currentCases Switch cases from the selected node.
86 * @param switchVarName Name of the variable being switched (e.g. "mHealth")
87 * @param switchVarType Type of the variable (e.g. "Int")
88 * @param currentVarValue Current value of the variable for display (optional)
89 */
90 void Open(const std::vector<SwitchCaseDefinition>& currentCases,
91 const std::string& switchVarName = "",
92 const std::string& switchVarType = "",
93 const std::string& currentVarValue = "");
94
95 /**
96 * @brief Closes the modal without confirming changes.
97 */
98 void Close();
99
100 /**
101 * @brief Returns true if the modal was closed via "Apply" rather than "Cancel".
102 * After reading, call Close() to reset the flag for the next edit.
103 */
104 bool IsConfirmed() const { return m_confirmed; }
105
106 /**
107 * @brief Returns the edited switch cases (only valid after IsConfirmed() == true).
108 */
109 const std::vector<SwitchCaseDefinition>& GetSwitchCases() const { return m_editingCases; }
110
111 // -----------------------------------------------------------------------
112 // Rendering
113 // -----------------------------------------------------------------------
114
115 /**
116 * @brief Renders the modal dialog. Must be called once per frame while IsOpen().
117 * Handles ImGui::OpenPopupOnItemClick, ImGui::BeginPopupModal, etc.
118 */
119 void Render();
120
121private:
122
123 // -----------------------------------------------------------------------
124 // Render helpers
125 // -----------------------------------------------------------------------
126
127 /**
128 * @brief Renders the scrollable list of case rows.
129 */
130 void RenderCaseList();
131
132 /**
133 * @brief Renders a single case row with all controls.
134 * @param caseIndex 0-based index in m_editingCases
135 * @return True if any field was modified
136 */
137 bool RenderCaseRow(size_t caseIndex);
138
139 /**
140 * @brief Renders the "Add Case" and action buttons (Apply / Cancel).
141 */
142 void RenderActionButtons();
143
144 // -----------------------------------------------------------------------
145 // State
146 // -----------------------------------------------------------------------
147
148 /// True if the modal is currently open
149 bool m_isOpen = false;
150
151 /// True if the user clicked "Apply" (set to false on Close)
152 bool m_confirmed = false;
153
154 /// Working copy of switch cases being edited
155 std::vector<SwitchCaseDefinition> m_editingCases;
156
157 /// Temporary edit buffers for value and label fields
158 std::vector<std::string> m_caseValueBuffers; ///< One per case, synced before render
159 std::vector<std::string> m_caseLabelBuffers; ///< One per case, synced before render
160
161 // Phase 26-A: Context information for better UX
162 std::string m_switchVarName; ///< Variable being switched (e.g. "mHealth")
163 std::string m_switchVarType; ///< Variable type (e.g. "Int", "String")
164 std::string m_currentVarValue; ///< Current value for context display
165 bool m_hasValidationError = false; ///< Set to true if any case has errors (prevents Apply)
166};
167
168} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Modal dialog for adding, removing, and reordering switch cases on a node.
std::string m_currentVarValue
Current value for context display.
std::vector< SwitchCaseDefinition > m_editingCases
Working copy of switch cases being edited.
void RenderCaseList()
Renders the scrollable list of case rows.
SwitchCaseEditorModal & operator=(const SwitchCaseEditorModal &)=delete
bool m_confirmed
True if the user clicked "Apply" (set to false on Close)
std::vector< std::string > m_caseLabelBuffers
One per case, synced before render.
const std::vector< SwitchCaseDefinition > & GetSwitchCases() const
Returns the edited switch cases (only valid after IsConfirmed() == true).
SwitchCaseEditorModal()
Constructs the modal.
SwitchCaseEditorModal(const SwitchCaseEditorModal &)=delete
std::vector< std::string > m_caseValueBuffers
Temporary edit buffers for value and label fields.
std::string m_switchVarName
Variable being switched (e.g. "mHealth")
bool IsOpen() const
Returns true if the modal is currently open.
void RenderActionButtons()
Renders the "Add Case" and action buttons (Apply / Cancel).
bool m_hasValidationError
Set to true if any case has errors (prevents Apply)
std::string m_switchVarType
Variable type (e.g. "Int", "String")
void Open(const std::vector< SwitchCaseDefinition > &currentCases, const std::string &switchVarName="", const std::string &switchVarType="", const std::string &currentVarValue="")
Opens the modal, loading the given switch cases for editing.
void Close()
Closes the modal without confirming changes.
void Render()
Renders the modal dialog.
bool IsConfirmed() const
Returns true if the modal was closed via "Apply" rather than "Cancel".
bool m_isOpen
True if the modal is currently open.
bool RenderCaseRow(size_t caseIndex)
Renders a single case row with all controls.
< Provides AssetID and INVALID_ASSET_ID