Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
InspectorPanel.cpp
Go to the documentation of this file.
1/*
2 * Olympe Blueprint Editor - Inspector Panel Implementation
3 */
4
5#include "InspectorPanel.h"
6#include "BlueprintEditor.h"
10#include "../Editor/Panels/ActionParametersPanel.h"
11#include "../TaskSystem/LocalBlackboard.h"
12#include "../TaskSystem/TaskGraphTypes.h"
13#include "../third_party/imgui/imgui.h"
14#include <iostream>
15#include <string>
16#include <cstring>
17
18namespace Olympe
19{
20 // Static member definitions
21 const LocalBlackboard* InspectorPanel::s_DebugBlackboard = nullptr;
22 InspectorPanel* InspectorPanel::s_Instance = nullptr;
23
28
30 : m_actionPanel(nullptr)
31 , m_hasSelectedAction(false)
32 {
33 }
34
38
40 {
41 m_actionPanel = std::make_unique<ActionParametersPanel>();
43 std::cout << "[InspectorPanel] Initialized\n";
44 }
45
47 {
49 m_actionPanel.reset();
50 std::cout << "[InspectorPanel] Shutdown\n";
51 }
52
54 {
55 ImGui::Begin("Inspector");
57 ImGui::End();
58 }
59
61 const std::string& nodeName,
62 const std::unordered_map<std::string, std::string>& parameters)
63 {
64 if (!m_actionPanel)
65 return;
66
67 m_actionPanel->SetActionTaskID(taskID);
68 m_actionPanel->SetNodeName(nodeName);
69 m_actionPanel->SetParameters(parameters);
71 }
72
74 {
75 m_hasSelectedAction = false;
76 if (m_actionPanel)
77 {
78 m_actionPanel->SetActionTaskID("");
79 m_actionPanel->SetNodeName("");
80 }
81 }
82
84 {
85 // If an action node is selected, show its parameters
87 {
89 return;
90 }
91
93
94 switch (context)
95 {
98 break;
99
102 break;
103
106 break;
107
109 default:
110 ImGui::Text("No selection");
111 ImGui::TextWrapped("Select an entity or asset file to inspect its properties.");
112 break;
113 }
114
115 // Runtime debug overlay: always shown when a debug blackboard is registered
117 }
118
120 {
121 // C) Priority 1: Entity selection from BlueprintEditor backend
122 if (BlueprintEditor::Get().HasSelectedEntity())
123 {
125 }
126
127 // Priority 2: Asset file selection from BlueprintEditor backend
128 if (BlueprintEditor::Get().HasSelectedAsset())
129 {
131 }
132
133 // Check if a graph node is selected
134 // For now, we'll assume no node selection (would need to track in NodeGraphPanel)
135
137 }
138
140 {
141 ImGui::Text("Node Properties");
142 ImGui::Separator();
143
144 // This would show properties of the selected graph node
145 // Would require selected node tracking in NodeGraphPanel
146
147 ImGui::Text("Node inspector coming soon...");
148 }
149
151 {
152 // C) Get selected entity from BlueprintEditor backend
154
155 if (selectedEntity == 0) // INVALID_ENTITY_ID
156 {
157 ImGui::Text("No entity selected");
158 ImGui::TextWrapped("Select an entity from the Asset Browser or Entities panel to inspect its properties.");
159 return;
160 }
161
163
164 ImGui::Text("Entity: %s", info.name.c_str());
165 ImGui::Text("ID: %llu", selectedEntity);
166 ImGui::Separator();
167
168 // Show components
169 ImGui::Text("Components:");
170
172
173 if (components.empty())
174 {
175 ImGui::Text(" (no components)");
176 }
177 else
178 {
179 for (const auto& componentType : components)
180 {
181 if (ImGui::CollapsingHeader(componentType.c_str()))
182 {
184 }
185 }
186 }
187 }
188
189 void InspectorPanel::RenderComponentProperties(uint64_t entityId, const std::string& componentType)
190 {
191 auto properties = EntityInspectorManager::Get().GetComponentProperties(entityId, componentType);
192
193 if (properties.empty())
194 {
195 ImGui::Text(" (no editable properties)");
196 return;
197 }
198
199 for (auto& prop : properties)
200 {
201 ImGui::PushID(prop.name.c_str());
202
203 if (prop.type == "float")
204 {
205 float value = std::stof(prop.value);
206 if (ImGui::DragFloat(prop.name.c_str(), &value, 1.0f))
207 {
208 // Update property
210 entityId, componentType, prop.name, std::to_string(value)
211 );
212 }
213 }
214 else if (prop.type == "int")
215 {
216 int value = std::stoi(prop.value);
217 if (ImGui::DragInt(prop.name.c_str(), &value))
218 {
220 entityId, componentType, prop.name, std::to_string(value)
221 );
222 }
223 }
224 else if (prop.type == "bool")
225 {
226 bool value = (prop.value == "true" || prop.value == "1");
227 if (ImGui::Checkbox(prop.name.c_str(), &value))
228 {
230 entityId, componentType, prop.name, value ? "true" : "false"
231 );
232 }
233 }
234 else if (prop.type == "string")
235 {
236 char buffer[256];
237 strncpy_s(buffer, prop.value.c_str(), sizeof(buffer) - 1);
238 buffer[sizeof(buffer) - 1] = '\0';
239
240 if (ImGui::InputText(prop.name.c_str(), buffer, sizeof(buffer)))
241 {
243 entityId, componentType, prop.name, buffer
244 );
245 }
246 }
247 else
248 {
249 // Default: display as text
250 ImGui::Text("%s: %s", prop.name.c_str(), prop.value.c_str());
251 }
252
253 ImGui::PopID();
254 }
255 }
256
258 {
259 // Get selected asset path from BlueprintEditor backend
261
262 if (selectedAssetPath.empty())
263 {
264 ImGui::Text("No asset selected");
265 return;
266 }
267
268 // Get asset metadata from backend
270
271 // Extract filename from path
272 size_t lastSlash = selectedAssetPath.find_last_of("/\\");
273 std::string filename = (lastSlash != std::string::npos)
274 ? selectedAssetPath.substr(lastSlash + 1)
276
277 ImGui::TextColored(ImVec4(0.5f, 0.8f, 1.0f, 1.0f), "Asset: %s", filename.c_str());
278 ImGui::Separator();
279
280 if (!metadata.isValid)
281 {
282 ImGui::TextColored(ImVec4(1.0f, 0.3f, 0.3f, 1.0f), "Invalid or malformed asset");
283 if (!metadata.errorMessage.empty())
284 {
285 ImGui::TextWrapped("Error: %s", metadata.errorMessage.c_str());
286 }
287 return;
288 }
289
290 // Display asset type
291 ImGui::Text("Type: %s", metadata.type.c_str());
292
293 // Display name and description if available
294 if (!metadata.name.empty())
295 {
296 ImGui::Text("Name: %s", metadata.name.c_str());
297 }
298
299 if (!metadata.description.empty())
300 {
301 ImGui::Separator();
302 ImGui::TextWrapped("Description: %s", metadata.description.c_str());
303 }
304
305 ImGui::Separator();
306
307 // Type-specific information
308 if (metadata.type == "BehaviorTree" || metadata.type == "HFSM")
309 {
310 ImGui::Text("Nodes: %d", metadata.nodeCount);
311
312 if (!metadata.nodes.empty() && ImGui::CollapsingHeader("Node List"))
313 {
314 ImGui::Indent();
315 for (const auto& node : metadata.nodes)
316 {
317 ImGui::BulletText("%s", node.c_str());
318 }
319 ImGui::Unindent();
320 }
321
322 ImGui::Separator();
323 if (ImGui::Button("Open in Node Graph Editor"))
324 {
326 }
327 }
328 else if (metadata.type == "EntityBlueprint")
329 {
330 ImGui::Text("Components: %d", metadata.componentCount);
331
332 if (!metadata.components.empty() && ImGui::CollapsingHeader("Component List"))
333 {
334 ImGui::Indent();
335 for (const auto& comp : metadata.components)
336 {
337 ImGui::BulletText("%s", comp.c_str());
338 }
339 ImGui::Unindent();
340 }
341 }
342
343 // Full file path at the bottom
344 ImGui::Separator();
345 ImGui::TextDisabled("Path: %s", selectedAssetPath.c_str());
346 }
347
348 // =========================================================================
349 // RenderDebugBlackboard
350 // =========================================================================
351
353 {
354 if (s_DebugBlackboard == nullptr)
355 return;
356
357 ImGui::Separator();
358 ImGui::TextColored(ImVec4(0.4f, 0.9f, 0.4f, 1.0f), "Runtime Blackboard");
359 ImGui::Separator();
360
361 std::vector<std::string> varNames = s_DebugBlackboard->GetVariableNames();
362 if (varNames.empty())
363 {
364 ImGui::TextDisabled("(no variables)");
365 return;
366 }
367
368 for (const auto& varName : varNames)
369 {
371 switch (val.GetType())
372 {
374 ImGui::Text(" %s: %s", varName.c_str(), val.AsBool() ? "true" : "false");
375 break;
377 ImGui::Text(" %s: %d", varName.c_str(), val.AsInt());
378 break;
380 ImGui::Text(" %s: %.4f", varName.c_str(), val.AsFloat());
381 break;
383 ImGui::Text(" %s: \"%s\"", varName.c_str(), val.AsString().c_str());
384 break;
386 ImGui::Text(" %s: entity(%llu)", varName.c_str(),
387 static_cast<unsigned long long>(val.AsEntityID()));
388 break;
390 {
391 ::Vector v = val.AsVector();
392 ImGui::Text(" %s: (%.2f, %.2f, %.2f)", varName.c_str(), v.x, v.y, v.z);
393 break;
394 }
395 default:
396 ImGui::Text(" %s: (none)", varName.c_str());
397 break;
398 }
399 }
400 }
401
403 {
404 if (!m_actionPanel)
405 return;
406
407 ImGui::TextColored(ImVec4(0.5f, 0.8f, 1.0f, 1.0f), "Action Node Properties");
408 ImGui::Separator();
409
410 m_actionPanel->Render();
411
412 ImGui::Spacing();
413 if (ImGui::Button("Clear Selection"))
414 {
416 }
417 }
418}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
std::string GetSelectedAssetPath() const
AssetMetadata GetAssetMetadata(const std::string &filepath)
uint64_t GetSelectedEntity() const
void OpenGraphInEditor(const std::string &assetPath)
static BlueprintEditor & Get()
std::vector< std::string > GetEntityComponents(EntityID entity) const
static EntityInspectorManager & Get()
EntityInfo GetEntityInfo(EntityID entity) const
std::vector< ComponentPropertyInfo > GetComponentProperties(EntityID entity, const std::string &componentType)
bool SetComponentProperty(EntityID entity, const std::string &componentType, const std::string &propertyName, const std::string &value)
static void SetInstance(InspectorPanel *instance)
Set the active InspectorPanel instance.
void RenderComponentProperties(uint64_t entityId, const std::string &componentType)
void ClearSelectedActionNode()
Clear the current action node selection.
static const LocalBlackboard * s_DebugBlackboard
void SetSelectedActionNode(const std::string &taskID, const std::string &nodeName, const std::unordered_map< std::string, std::string > &parameters)
Set the currently selected action node for parameter editing.
static void SetDebugBlackboard(const LocalBlackboard *bb)
Register a live LocalBlackboard to display in the inspector.
static InspectorPanel * s_Instance
std::unique_ptr< ActionParametersPanel > m_actionPanel
InspectorContext DetermineContext()
Simple map-based blackboard for task graph runtime state.
TaskValue GetValue(const std::string &varName) const
Returns the current value of a variable.
std::vector< std::string > GetVariableNames() const
Returns all registered variable names (useful for debugging / editor).
C++14-compliant type-safe value container for task parameters.
< Provides AssetID and INVALID_ASSET_ID
@ Int
32-bit signed integer
@ Float
Single-precision float.
@ String
std::string
@ Vector
3-component vector (Vector from vector.h)
@ EntityID
Entity identifier (uint64_t)
std::vector< std::string > components
std::vector< std::string > nodes