Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
VisualScriptEditorPanel.cpp
Go to the documentation of this file.
1/**
2 * @file VisualScriptEditorPanel.cpp
3 * @brief ImNodes graph editor implementation for ATS VS graphs (Phase 5).
4 * @author Olympe Engine
5 * @date 2026-03-09
6 *
7 * @details C++14 compliant — no std::optional, structured bindings, std::filesystem.
8 */
9
11#include "DebugController.h"
13#include "ConditionRegistry.h"
14#include "OperatorRegistry.h"
15#include "BBVariableRegistry.h"
16#include "MathOpOperand.h"
17#include "../system/system_utils.h"
18#include "../system/system_consts.h"
19#include "../NodeGraphCore/GlobalTemplateBlackboard.h"
20
21#include "../third_party/imgui/imgui.h"
22#include "../third_party/imnodes/imnodes.h"
23#include "../json_helper.h"
24#include "../TaskSystem/TaskGraphLoader.h"
25
26#include <fstream>
27#include <iostream>
28#include <algorithm>
29#include <cmath>
30#include <cstring>
31#include <sstream>
32#include <iomanip>
33#include <cstdlib>
34#include <unordered_set>
35
36namespace Olympe {
37
38// ============================================================================
39// Lifecycle Methods
40// ============================================================================
41// NOTE: Core lifecycle methods (Constructor, Destructor, Initialize, Shutdown)
42// have been extracted to VisualScriptEditorPanel_Core.cpp for better organization
43// and maintainability (Phase 24 refactoring).
44//
45// Methods included in VisualScriptEditorPanel_Core.cpp:
46// - VisualScriptEditorPanel() Constructor
47// - ~VisualScriptEditorPanel() Destructor
48// - Initialize() — ImNodes context, UI helpers, preset loading
49// - Shutdown() — Resource cleanup and registry management
50//
51// Implementation file: Source/BlueprintEditor/VisualScriptEditorPanel_Core.cpp
52
53// ============================================================================
54// Helper Methods
55// ============================================================================
56// NOTE: 6 helper methods have been extracted to VisualScriptEditorPanel_Helpers.cpp
57// for better code organization and maintainability (Phase 24 refactoring).
58//
59// Methods included in VisualScriptEditorPanel_Helpers.cpp:
60// - AllocNodeID() — Allocate unique node IDs
61// - AllocLinkID() — Allocate unique link IDs
62// - ExecInAttrUID(int nodeID) — UID for execution input pins
63// - ExecOutAttrUID(int nodeID, int pinIndex) — UID for execution output pins
64// - DataInAttrUID(int nodeID, int pinIndex) — UID for data input pins
65// - DataOutAttrUID(int nodeID, int pinIndex) — UID for data output pins
66//
67// UID Scheme (nodeID * 10000 + offset):
68// 0–99: Reserved for exec-in
69// 100–199: Exec-out pins
70// 200–299: Data-in pins
71// 300–399: Data-out pins
72//
73// Implementation file: Source/BlueprintEditor/VisualScriptEditorPanel_Helpers.cpp
74
75// ============================================================================
76// Pin Name Helpers
77// ============================================================================
78// NOTE: 5 pin helper methods have been extracted to VisualScriptEditorPanel_PinHelpers.cpp
79// for better code organization and maintainability (Phase 24 refactoring).
80//
81// Methods included in VisualScriptEditorPanel_PinHelpers.cpp:
82// - GetExecInputPins(TaskNodeType type) — Static exec input pins by node type
83// - GetExecOutputPins(TaskNodeType type) — Static exec output pins by node type
84// - GetExecOutputPinsForNode(const TaskNodeDefinition& def) — Inc. dynamic pins
85// - GetDataInputPins(TaskNodeType type) — Static data input pins by node type
86// - GetDataOutputPins(TaskNodeType type) — Static data output pins by node type
87//
88// Pin Categories (by node type):
89// - EntryPoint: exec-out only {"Out"}
90// - Branch: exec-out {"Then", "Else"} + dynamic data-in pins
91// - While: exec-out {"Loop", "Completed"}
92// - ForEach: exec-out {"Loop Body", "Completed"}
93// - AtomicTask: exec-in/out {"In"} / {"Completed"}
94// - MathOp: data-in {"A", "B"}, data-out {"Result"} (data-pure)
95// - GetBBValue: data-out {"Value"} (data-pure)
96// - SetBBValue: exec-in/out, data-in {"Value"}
97// - SubGraph: exec-in/out
98// - VSSequence: exec-out + dynamic pins
99// - Switch: exec-out + dynamic pins
100// - Delay: exec-in/out
101// - DoOnce: exec-in/out
102//
103// Implementation file: Source/BlueprintEditor/VisualScriptEditorPanel_PinHelpers.cpp
104
105// ============================================================================
106// Node management
107// ============================================================================
108
109// ============================================================================
110// Node Management Methods
111// ============================================================================
112// NOTE: 4 node management methods (AddNode, RemoveNode, ConnectExec, ConnectData)
113// have been extracted to VisualScriptEditorPanel_NodeManagement.cpp for better
114// code organization and maintainability (Phase 24 refactoring).
115//
116// Methods included in VisualScriptEditorPanel_NodeManagement.cpp:
117// - AddNode() — Create a new node with type-specific data pin initialization
118// - RemoveNode() — Delete a node and all associated connections
119// - ConnectExec() — Create an execution pin connection between nodes
120// - ConnectData() — Create a data pin connection between nodes
121//
122// Implementation file: Source/BlueprintEditor/VisualScriptEditorPanel_NodeManagement.cpp
123//
124// These methods integrate with the undo/redo command system (ICommand/UndoStack)
125// to ensure all graph modifications (node creation, deletion, link creation) can
126// be reversed via Ctrl+Z. All operations update both m_editorNodes (canvas state)
127// and m_template (model), with link graph rebuilding after each change.
128
129// ============================================================================
130// Template / Canvas Sync
131// ============================================================================
132// NOTE: 5 template synchronization methods have been extracted to
133// VisualScriptEditorPanel_TemplateSync.cpp (Phase 6).
134// See: Source/BlueprintEditor/VisualScriptEditorPanel_TemplateSync.cpp
135//
136// Methods included:
137// - SyncCanvasFromTemplate() — Load nodes from template into editor canvas
138// - SyncTemplateFromCanvas() — Update template with current editor node state
139// - RebuildLinks() — Rebuild all visual links from template connections
140// - SyncEditorNodesFromTemplate() — Restore editor nodes during undo/redo
141// - RemoveLink(int linkID) — Delete a link and push undo command
142
143// ============================================================================
144// Load / Save
145// ============================================================================
146// NOTE: 6 file operation methods have been extracted to
147// VisualScriptEditorPanel_FileOperations.cpp (Phase 7).
148// See: Source/BlueprintEditor/VisualScriptEditorPanel_FileOperations.cpp
149//
150// Methods included:
151// - LoadTemplate() — Load blueprint from file/memory with preset loading (Phase 24)
152// - Save() — Save current graph to m_currentPath
153// - SaveAs() — Save graph to new path
154// - SyncNodePositionsFromImNodes() — Sync grid-space positions (BUG-003 Fix)
155// - SyncPresetsFromRegistryToTemplate() — Phase 24 preset synchronization
156// - SerializeAndWrite() — Complete JSON v4 serialization with all Phase 24 features
157//
158// Implementation file: Source/BlueprintEditor/VisualScriptEditorPanel_FileOperations.cpp
159
160// ============================================================================
161// Blackboard validation helpers (BUG-002 Fix #1)
162// ============================================================================
163// NOTE: ValidateAndCleanBlackboardEntries() and CommitPendingBlackboardEdits()
164// have been extracted to VisualScriptEditorPanel_Utilities.cpp (Phase 5).
165// See: Source/BlueprintEditor/VisualScriptEditorPanel_Utilities.cpp
166
167// ============================================================================
168// BUG-003 Viewport helpers
169// ============================================================================
170// NOTE: ResetViewportBeforeSave(), AfterSave(), and ScreenToCanvasPos()
171// have been extracted to VisualScriptEditorPanel_Utilities.cpp (Phase 5).
172// See: Source/BlueprintEditor/VisualScriptEditorPanel_Utilities.cpp
173
174// ============================================================================
175// UX Enhancement #3 — Type-filtered variable utility
176// ============================================================================
177// NOTE: GetVariablesByType() has been extracted to
178// VisualScriptEditorPanel_Utilities.cpp (Phase 5).
179// See: Source/BlueprintEditor/VisualScriptEditorPanel_Utilities.cpp
180
181// ============================================================================
182// Rendering
183// ============================================================================
184
185// ============================================================================
186// Undo/Redo wrappers, Rendering (extracted to VisualScriptEditorPanel_RenderingCore.cpp)
187// ============================================================================
188// NOTE: Core rendering methods have been extracted to VisualScriptEditorPanel_RenderingCore.cpp
189// (Phase 8 refactoring).
190//
191// Methods implemented in VisualScriptEditorPanel_RenderingCore.cpp:
192// - PerformUndo() — Undo operation with position restoration
193// - PerformRedo() — Redo operation with position restoration
194// - Render() — Main render function (delegates to RenderContent)
195// - RenderContent() — Main content layout (toolbar, canvas, properties)
196// - RenderToolbar() — Toolbar with save/load/verify buttons
197// - RenderSaveAsDialog() — Save-As modal dialog
198//
199// Implementation file: Source/BlueprintEditor/VisualScriptEditorPanel_RenderingCore.cpp
200
201
202
203// ============================================================================
204// Canvas Rendering, Node Palette, Context Menus (Phase 9 Extraction)
205// ============================================================================
206// Implementation extracted to VisualScriptEditorPanel_Canvas.cpp
207//
208// Extracted methods (~1053 LOC total):
209// - void RenderCanvas() — ImNodes graph rendering, node palette detection, link management
210// - void RenderNodePalette() — Right-click context menu for adding nodes
211// - void RenderContextMenus() — Node/link right-click context menus
212//
213// See: Source/BlueprintEditor/VisualScriptEditorPanel_Canvas.cpp
214//
215// Forward declarations (implemented in Canvas.cpp):
216// void RenderCanvas();
217// void RenderNodePalette();
218// void RenderContextMenus();
219
220
221// ============================================================================
222// Branch / While node — dedicated Properties panel renderer
223// ============================================================================
224
225// ============================================================================
226// Branch node — dedicated Properties panel renderer
227// ============================================================================
228// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Properties.cpp
229// as part of Phase 10 (Properties Panel Extraction).
230// See: Source/BlueprintEditor/VisualScriptEditorPanel_Properties.cpp
231//
232// Original signature:
233// void VisualScriptEditorPanel::RenderBranchNodeProperties(VSEditorNode& eNode,
234// TaskNodeDefinition& def);
235//
236// Renders the Properties panel content for a selected Branch (or While) node.
237// Displays a blue header with the node name, then delegates to
238// NodeConditionsPanel::Render() for structured-conditions list, and finishes
239// with a Breakpoint checkbox.
240// ============================================================================
241
242// ============================================================================
243// MathOp node — dedicated Properties panel renderer
244// ============================================================================
245
246// ============================================================================
247// MathOp node — dedicated Properties panel renderer
248// ============================================================================
249// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Properties.cpp
250// as part of Phase 10 (Properties Panel Extraction).
251// See: Source/BlueprintEditor/VisualScriptEditorPanel_Properties.cpp
252//
253// Original signature:
254// void VisualScriptEditorPanel::RenderMathOpNodeProperties(VSEditorNode& eNode,
255// TaskNodeDefinition& def);
256//
257// Renders the Properties panel content for a selected MathOp node.
258// Displays a blue header with the node name, then delegates to
259// MathOpPropertyPanel::Render() for operand and operator editing.
260// ============================================================================
261
262// ============================================================================
263// Generic parameter editor for data nodes
264// ============================================================================
265// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Properties.cpp
266// as part of Phase 10 (Properties Panel Extraction).
267// See: Source/BlueprintEditor/VisualScriptEditorPanel_Properties.cpp
268//
269// Original signature:
270// void VisualScriptEditorPanel::RenderNodeDataParameters(TaskNodeDefinition& def);
271//
272// Renders node parameters for data nodes (GetBBValue, SetBBValue, MathOp).
273// Displays a parameters section that allows editing generic parameters that
274// can be stored and serialized alongside node-specific properties.
275//
276// Phase 24 — Generic parameter editor for data nodes (GetBBValue, SetBBValue, MathOp)
277// Allows storing and serializing additional parameters on data nodes
278// ============================================================================
279
280// ============================================================================
281// Main Properties panel dispatcher
282// ============================================================================
283// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Properties.cpp
284// as part of Phase 10 (Properties Panel Extraction).
285// See: Source/BlueprintEditor/VisualScriptEditorPanel_Properties.cpp
286//
287// Original signature:
288// void VisualScriptEditorPanel::RenderProperties();
289//
290// Main properties panel dispatcher (~100 LOC).
291// Renders the Properties panel content for the currently selected node.
292// Dispatches to type-specific renderers (RenderBranchNodeProperties, RenderMathOpNodeProperties, etc.).
293// Handles node name editing, type-specific field editing, breakpoint toggling, and undo/redo integration.
294// ============================================================================
295
296// ============================================================================
297// PHASE 12 — RenderBlackboard() MIGRATED
298// ============================================================================
299// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Blackboard.cpp
300// as part of Phase 12 (Blackboard Panel Extraction).
301// See: Source/BlueprintEditor/VisualScriptEditorPanel_Blackboard.cpp
302//
303// Original signature:
304// void VisualScriptEditorPanel::RenderBlackboard();
305//
306// Purpose: Render local blackboard with BUG-001 validation, variable editing.
307// ============================================================================
308
309// ============================================================================
310// PHASE 12 — RenderValidationOverlay() MIGRATED
311// ============================================================================
312// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Verification.cpp
313// as part of Phase 12 (Verification Panel Extraction).
314// See: Source/BlueprintEditor/VisualScriptEditorPanel_Verification.cpp
315//
316// Original signature:
317// void VisualScriptEditorPanel::RenderValidationOverlay();
318//
319// Purpose: Validate graph connections and SubGraph paths.
320// ============================================================================
321
322// ============================================================================
323// PHASE 12 — RunVerification() MIGRATED
324// ============================================================================
325// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Verification.cpp
326// as part of Phase 12 (Verification Panel Extraction).
327// See: Source/BlueprintEditor/VisualScriptEditorPanel_Verification.cpp
328//
329// Original signature:
330// void VisualScriptEditorPanel::RunVerification();
331//
332// Purpose: Execute VSGraphVerifier and populate verification logs for display.
333// ============================================================================
334
335// ============================================================================
336// PHASE 12 — RenderVerificationPanel() MIGRATED
337// ============================================================================
338// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Verification.cpp
339// as part of Phase 12 (Verification Panel Extraction).
340// See: Source/BlueprintEditor/VisualScriptEditorPanel_Verification.cpp
341//
342// Original signature:
343// void VisualScriptEditorPanel::RenderVerificationPanel();
344//
345// Purpose: Render verification panel with error/warning/info status and issue list.
346// ============================================================================
347
348// ============================================================================
349// PHASE 12 — RenderVerificationLogsPanel() MIGRATED
350// ============================================================================
351// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Verification.cpp
352// as part of Phase 12 (Verification Panel Extraction).
353// See: Source/BlueprintEditor/VisualScriptEditorPanel_Verification.cpp
354//
355// Original signature:
356// void VisualScriptEditorPanel::RenderVerificationLogsPanel();
357//
358// Purpose: Render verification logs panel with severity-based issue grouping.
359// ============================================================================
360
361// ============================================================================
362// Phase 23-B.4 — Condition Editor UI helpers (MIGRATED to VisualScriptEditorPanel_ConditionUI.cpp)
363// ============================================================================
364
365// ============================================================================
366// Alternative Node Properties Panel renderer
367// ============================================================================
368// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Properties.cpp
369// as part of Phase 10 (Properties Panel Extraction).
370// See: Source/BlueprintEditor/VisualScriptEditorPanel_Properties.cpp
371//
372// Original signature:
373// void VisualScriptEditorPanel::RenderNodePropertiesPanel();
374//
375// Alternative renderer for the Node Properties panel (~80 LOC).
376// Provides a second interface for editing node properties with type-specific fields
377// displayed in a more structured format.
378// ============================================================================
379
380// ============================================================================
381// PHASE 12 — RenderPresetBankPanel() MIGRATED
382// ============================================================================
383// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Verification.cpp
384// as part of Phase 12 (Verification Panel Extraction).
385// See: Source/BlueprintEditor/VisualScriptEditorPanel_Verification.cpp
386//
387// Original signature:
388// void VisualScriptEditorPanel::RenderPresetBankPanel();
389//
390// Purpose: Render preset bank panel with add/list presets functionality.
391// ============================================================================
392
393// ============================================================================
394// PHASE 12 — RenderPresetItemCompact() MIGRATED
395// ============================================================================
396// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Verification.cpp
397// as part of Phase 12 (Verification Panel Extraction).
398// See: Source/BlueprintEditor/VisualScriptEditorPanel_Verification.cpp
399//
400// Original signature:
401// void VisualScriptEditorPanel::RenderPresetItemCompact(const ConditionPreset& preset, size_t index);
402//
403// Purpose: Render single preset item in compact horizontal layout with edit/dup/delete buttons.
404// ============================================================================
405
406// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_ConditionUI.cpp
407// as part of Phase 11 (Condition UI Helpers Extraction).
408// See: Source/BlueprintEditor/VisualScriptEditorPanel_ConditionUI.cpp
409//
410// Original signature:
411// bool VisualScriptEditorPanel::RenderOperandEditor(Operand& operand, const char* labelSuffix);
412//
413// Unified operand selector (Pin/Const/Variable) with Phase 24 global support
414// ============================================================================
415// PHASE 24 Panel Integration — Part C: Local Variables Reference
416// ============================================================================
417
418// ============================================================================
419// PHASE 12 — RenderLocalVariablesPanel() MIGRATED
420// ============================================================================
421// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Blackboard.cpp
422// as part of Phase 12 (Blackboard Panel Extraction).
423// See: Source/BlueprintEditor/VisualScriptEditorPanel_Blackboard.cpp
424//
425// Original signature:
426// void VisualScriptEditorPanel::RenderLocalVariablesPanel();
427//
428// Purpose: Render local variables panel with BUG-001 validation and type-aware editing.
429// ============================================================================
430
431// ============================================================================
432// PHASE 12 — RenderGlobalVariablesPanel() MIGRATED
433// ============================================================================
434// NOTE: This method has been MIGRATED to VisualScriptEditorPanel_Blackboard.cpp
435// as part of Phase 12 (Blackboard Panel Extraction).
436// See: Source/BlueprintEditor/VisualScriptEditorPanel_Blackboard.cpp
437//
438// Original signature:
439// void VisualScriptEditorPanel::RenderGlobalVariablesPanel();
440//
441// Purpose: Render global variables panel with Phase 24 registry integration.
442// ============================================================================
443
444} // namespace Olympe
UI-side registry of available atomic tasks with display metadata.
Wrapper around the graph blackboard entries for dropdown editors.
Registry of available condition types for Branch/While node dropdowns.
Runtime debug controller for ATS Visual Scripting (Phase 5).
Defines MathOpOperand — operand references for MathOp nodes.
Hardcoded lists of math and comparison operators for dropdown editors.
ImNodes-based graph editor for ATS Visual Script graphs (Phase 5).
< Provides AssetID and INVALID_ASSET_ID