Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
PropertyEditorPanel.cpp
Go to the documentation of this file.
2#include "../../Source/third_party/imgui/imgui.h"
3#include "../../system/system_utils.h"
4#include <unordered_map>
5
6namespace Olympe
7{
9 {
10 m_behaviorTreeModal = std::make_unique<BehaviorTreeFilePickerModal>();
11 }
12
14
16 {
17 SYSTEM_LOG << "[PropertyEditorPanel] Initializing...\n";
18 }
19
21 {
22 if (!document) { return; }
24
26 {
27 ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "No node selected");
28 ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "Select a node to edit component properties");
29 }
30 else
31 {
33 if (node)
34 {
36 ImGui::Separator();
38 }
39 else
40 {
41 ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Selected node not found!");
43 }
44 }
45 }
46
48 {
49 m_selectedNodeId = nodeId;
50 // SYSTEM_LOG line removed to eliminate spam - logs occur every frame during rendering
51 }
52
57
62
67
75
77 {
78 // This method is kept for backward compatibility but now only shows
79 // component name since node metadata is now in NodePropertiesPanel
81 if (!node) { return; }
82
83 ImGui::TextColored(ImVec4(0.5f, 0.7f, 1.0f, 1.0f), "Component:");
84 ImGui::SameLine();
85 ImGui::TextUnformatted(node->componentType.c_str());
86 }
87
89 {
91 if (!node) { return; }
92
93 ImGui::TextUnformatted("Properties");
94 ImGui::Spacing();
95
96 if (node->properties.size() > 0)
97 {
98 for (auto it = node->properties.begin(); it != node->properties.end(); ++it)
99 {
100 ImGui::PushID(it->first.c_str());
101
102 std::string label = it->first;
103 std::string value = it->second;
104
105 // Special handling for BehaviorTree path field
106 if (label == "behaviorType")
107 {
108 // Text input for BehaviorTree path (read-only display)
109 static std::unordered_map<int, std::string> btPathBufferCache;
111 {
113 }
115 char pathBuffer[512] = "";
117
118 // Render input field with Browse button
119 ImGui::TextColored(ImVec4(0.7f, 0.9f, 1.0f, 1.0f), "BehaviorTree Path");
120 ImGui::SetNextItemWidth(-80.0f);
121 if (ImGui::InputText("##behaviorTreePath_input", pathBuffer, sizeof(pathBuffer)))
122 {
123 std::string newPath(pathBuffer);
124 node->SetProperty(it->first, newPath);
126 ApplyChanges();
127 }
128
129 // Browse button to open file picker
130 ImGui::SameLine();
131 if (ImGui::Button("Browse##bt_browse", ImVec2(75, 0)))
132 {
133 m_behaviorTreeModal->Open("./Gamedata");
134 }
135
136 // Render modal every frame
138 {
139 m_behaviorTreeModal->Render();
140
141 // Handle file selection from modal
142 if (m_behaviorTreeModal->IsConfirmed())
143 {
144 std::string selectedFile = m_behaviorTreeModal->GetSelectedFile();
145
146 // Extract relative path by removing "Gamedata/BehaviorTree/" prefix
147 std::string relativePath = selectedFile;
148 const std::string btPrefix = "Gamedata/";
149 const std::string btPrefixWin = "Gamedata\\";
150
151 if (relativePath.find(btPrefix) == 0)
152 {
153 relativePath = relativePath.substr(btPrefix.length());
154 }
155 else if (relativePath.find(btPrefixWin) == 0)
156 {
157 relativePath = relativePath.substr(btPrefixWin.length());
158 }
159
160 // Normalize path: forward slashes to backslashes for consistency
161 for (char& c : relativePath)
162 {
163 if (c == '/')
164 c = '\\';
165 }
166
167 // Update node property and cache
168 node->SetProperty(it->first, relativePath);
170 ApplyChanges();
171
172 SYSTEM_LOG << "[PropertyEditorPanel] Selected BehaviorTree: " << relativePath << "\n";
173 }
174 }
175 }
176 else
177 {
178 // Standard text input for other properties
179 static char buf[256];
180 strncpy_s(buf, sizeof(buf), value.c_str(), _TRUNCATE);
181
182 if (ImGui::InputText(label.c_str(), buf, sizeof(buf)))
183 {
184 node->SetProperty(it->first, std::string(buf));
185 ApplyChanges();
186 }
187 }
188
189 ImGui::PopID();
190 }
191 }
192 else
193 {
194 ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "No properties defined for this component");
195 ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 0.8f), "(Check ComponentsParameters.json)");
196 }
197 }
198
199} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
void Render(EntityPrefabGraphDocument *document)
std::unique_ptr< Olympe::BehaviorTreeFilePickerModal > m_behaviorTreeModal
EntityPrefabGraphDocument * m_document
< Provides AssetID and INVALID_ASSET_ID
uint32_t NodeId
const NodeId InvalidNodeId
#define SYSTEM_LOG