Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
HistoryPanel.cpp
Go to the documentation of this file.
1/*
2 * Olympe Blueprint Editor - History Panel Implementation
3 */
4
5#include "HistoryPanel.h"
6#include "BlueprintEditor.h"
7#include "CommandSystem.h"
8#include "../third_party/imgui/imgui.h"
9
10namespace Olympe
11{
13 : m_ShowPanel(false)
14 {
15 }
16
20
22 {
23 m_ShowPanel = false;
24 }
25
27 {
28 }
29
31 {
32 if (!m_ShowPanel)
33 {
34 return;
35 }
36
37 ImGui::Begin("History", &m_ShowPanel);
38
40 CommandStack* cmdStack = backend.GetCommandStack();
41
42 if (!cmdStack)
43 {
44 ImGui::Text("Command stack not initialized");
45 ImGui::End();
46 return;
47 }
48
49 // Display command stack info
50 ImGui::Text("Undo Stack Size: %zu", cmdStack->GetUndoStackSize());
51 ImGui::Text("Redo Stack Size: %zu", cmdStack->GetRedoStackSize());
52
53 ImGui::Separator();
54
55 // Undo stack section
56 ImGui::Text("Undo History:");
57 ImGui::BeginChild("UndoHistory", ImVec2(0, 200), true);
58
59 auto undoDescriptions = cmdStack->GetUndoStackDescriptions();
60 for (int i = static_cast<int>(undoDescriptions.size()) - 1; i >= 0; i--)
61 {
62 ImGui::PushID(i);
63
64 // Highlight the most recent command
65 if (i == static_cast<int>(undoDescriptions.size()) - 1)
66 {
67 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.4f, 1.0f, 0.4f, 1.0f));
68 ImGui::Text("-> %s", undoDescriptions[i].c_str());
69 ImGui::PopStyleColor();
70 }
71 else
72 {
73 ImGui::Text(" %s", undoDescriptions[i].c_str());
74 }
75
76 ImGui::PopID();
77 }
78
79 if (undoDescriptions.empty())
80 {
81 ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "No commands to undo");
82 }
83
84 ImGui::EndChild();
85
86 ImGui::Separator();
87
88 // Redo stack section
89 ImGui::Text("Redo History:");
90 ImGui::BeginChild("RedoHistory", ImVec2(0, 150), true);
91
92 auto redoDescriptions = cmdStack->GetRedoStackDescriptions();
93 for (int i = static_cast<int>(redoDescriptions.size()) - 1; i >= 0; i--)
94 {
95 ImGui::PushID(i + 1000);
96 ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), " %s", redoDescriptions[i].c_str());
97 ImGui::PopID();
98 }
99
100 if (redoDescriptions.empty())
101 {
102 ImGui::TextColored(ImVec4(0.7f, 0.7f, 0.7f, 1.0f), "No commands to redo");
103 }
104
105 ImGui::EndChild();
106
107 ImGui::Separator();
108
109 // Action buttons
110 ImGui::BeginDisabled(!backend.CanUndo());
111 if (ImGui::Button("Undo", ImVec2(120, 0)))
112 {
113 backend.Undo();
114 }
115 ImGui::EndDisabled();
116
117 ImGui::SameLine();
118
119 ImGui::BeginDisabled(!backend.CanRedo());
120 if (ImGui::Button("Redo", ImVec2(120, 0)))
121 {
122 backend.Redo();
123 }
124 ImGui::EndDisabled();
125
126 ImGui::SameLine();
127
128 if (ImGui::Button("Clear History", ImVec2(120, 0)))
129 {
130 if (cmdStack)
131 {
132 cmdStack->Clear();
133 }
134 }
135
136 ImGui::End();
137 }
138}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
static BlueprintEditor & Get()
CommandStack - Manages undo/redo command history Maintains two stacks for undo and redo operations.