Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
PresetDropdownHelper.cpp
Go to the documentation of this file.
1/**
2 * @file PresetDropdownHelper.cpp
3 * @brief Implementation of PresetDropdownHelper (Phase 24).
4 * @author Olympe Engine
5 * @date 2026-03-20
6 *
7 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
8 */
9
11
12#include <algorithm>
13
14// ImGui is only available in the full editor build.
15#ifndef OLYMPE_HEADLESS
16# include "../../third_party/imgui/imgui.h"
17#endif
18
19namespace Olympe {
20
21// ============================================================================
22// Constructor
23// ============================================================================
24
26 : m_registry(registry)
27 , m_label("Select Preset")
28{
29}
30
31// ============================================================================
32// Rendering & Interaction
33// ============================================================================
34
36{
37 bool changed = false;
38
39#ifndef OLYMPE_HEADLESS
40 // Get filtered presets based on m_filter
41 std::vector<ConditionPreset> presets = m_registry.GetFilteredPresets(m_filter);
42
43 // Combo box label: display selected preset name or placeholder
44 std::string comboLabel = "None";
45 if (!selectedPresetID.empty())
46 {
48 if (selected)
49 comboLabel = selected->name;
50 }
51
52 // Render combo box header
53 if (ImGui::BeginCombo(m_label.c_str(), comboLabel.c_str()))
54 {
55 // Optional: Add search field at top of dropdown
56 static char searchBuf[128] = {0};
57 ImGui::InputTextWithHint("##search", "Filter...", searchBuf, sizeof(searchBuf));
58 std::string newFilter(searchBuf);
59 if (newFilter != m_filter)
60 {
63 }
64
65 ImGui::Separator();
66
67 // Special "None" option
68 if (ImGui::Selectable("(None)", selectedPresetID.empty()))
69 {
70 selectedPresetID.clear();
71 changed = true;
72 }
73
74 // List all presets
75 for (size_t i = 0; i < presets.size(); ++i)
76 {
78 bool isSelected = (selectedPresetID == preset.id);
79
80 // Format: "Condition #1 [mHealth] <= [2]"
81 std::string itemLabel = preset.name + " " + preset.GetPreview();
82
83 if (ImGui::Selectable(itemLabel.c_str(), isSelected))
84 {
86 changed = true;
87 }
88
89 // Highlight selected item
90 if (isSelected)
91 ImGui::SetItemDefaultFocus();
92
93 // Tooltip on hover
94 if (ImGui::IsItemHovered())
95 {
96 ImGui::BeginTooltip();
97 ImGui::Text("ID: %s", preset.id.c_str());
98 ImGui::Text("Name: %s", preset.name.c_str());
99 ImGui::Text("Expr: %s", preset.GetPreview().c_str());
100 ImGui::EndTooltip();
101 }
102 }
103
104 ImGui::EndCombo();
105 }
106
107#endif
108
109 return changed;
110}
111
112// ============================================================================
113// Query
114// ============================================================================
115
117{
118 std::vector<ConditionPreset> filtered = m_registry.GetFilteredPresets(m_filter);
119 return filtered.size();
120}
121
122std::string PresetDropdownHelper::GetPresetDisplayName(const std::string& presetID) const
123{
124 const ConditionPreset* preset = m_registry.GetPreset(presetID);
125 if (preset)
126 return preset->name;
127 return "";
128}
129
130} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Reusable ImGui dropdown component for ConditionPreset selection (Phase 24).
Manages the global pool of ConditionPreset objects.
std::vector< ConditionPreset > GetFilteredPresets(const std::string &filter) const
Returns all presets whose name contains the filter substring.
ConditionPreset * GetPreset(const std::string &id)
Returns a mutable pointer to the preset, or nullptr if not found.
PresetDropdownHelper(ConditionPresetRegistry &registry)
Constructs the dropdown helper bound to the preset registry.
size_t GetVisiblePresetCount() const
Returns the number of presets visible after filtering.
std::string GetPresetDisplayName(const std::string &presetID) const
Returns the display name of a preset, or empty if not found.
ConditionPresetRegistry & m_registry
bool Render(std::string &selectedPresetID)
Renders the dropdown widget and handles selection.
< Provides AssetID and INVALID_ASSET_ID
A globally-stored, reusable condition expression.
std::string name
Human-readable display name (e.g. "Condition #1")