yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
enhanced_status_panel.cc
Go to the documentation of this file.
2
3#include <chrono>
4#include <ftxui/component/component.hpp>
5#include <ftxui/dom/elements.hpp>
6#include <iomanip>
7#include <sstream>
8
9#include "absl/strings/str_format.h"
10
11namespace yaze {
12namespace cli {
13
14using namespace ftxui;
15
17 : rom_context_(rom_context) {
18 // Initialize status data
22
23 // Create components
29
30 // Set up event handlers
31 status_event_handler_ = [this](const Event& event) {
32 return HandleStatusEvents(event);
33 };
34}
35
39
41 rom_context_ = rom_context;
43}
44
48
52
56
57void EnhancedStatusPanel::SetError(const std::string& error) {
58 current_error_ = error;
59}
60
64
66 auto container = Container::Vertical({rom_info_section_, system_info_section_,
68
69 return Renderer(container, [this] {
70 return vbox({text("📊 Status Panel") | bold | center, separator(),
71 rom_info_section_->Render(), separator(),
72 system_info_section_->Render(), separator(),
73 layout_info_section_->Render(), separator(),
74 error_section_->Render(), separator(), RenderStatusBar()}) |
75 border;
76 });
77}
78
80 return Renderer([this] { return RenderRomInfo(); });
81}
82
84 return Renderer([this] { return RenderSystemInfo(); });
85}
86
88 return Renderer([this] { return RenderLayoutInfo(); });
89}
90
92 return Renderer([this] { return RenderErrorInfo(); });
93}
94
96 if (event == Event::Character('e')) {
98 return true;
99 }
100
101 if (event == Event::Character('d')) {
103 return true;
104 }
105
106 return false;
107}
108
110 if (!rom_info_.loaded) {
111 return vbox({text("🎮 ROM Information") | bold | color(Color::Red),
112 text("No ROM loaded") | color(Color::Red),
113 text("Load a ROM to see information") | dim});
114 }
115
116 return vbox(
117 {text("🎮 ROM Information") | bold | color(Color::Green),
118 text(absl::StrFormat("Title: %s", rom_info_.title)) |
119 color(Color::White),
120 text(absl::StrFormat("Size: %s", rom_info_.size)) | color(Color::Cyan),
121 text(absl::StrFormat("Checksum: %s", rom_info_.checksum)) |
122 color(Color::Yellow),
123 text(absl::StrFormat("Region: %s", rom_info_.region)) |
124 color(Color::Magenta)});
125}
126
128 return vbox({text("💻 System Information") | bold | color(Color::Blue),
129 text(absl::StrFormat("Time: %s", system_info_.current_time)) |
130 color(Color::White),
131 text(absl::StrFormat("Memory: %s", system_info_.memory_usage)) |
132 color(Color::Cyan),
133 text(absl::StrFormat("CPU: %s", system_info_.cpu_usage)) |
134 color(Color::Yellow),
135 text(absl::StrFormat("Disk: %s", system_info_.disk_space)) |
136 color(Color::Green)});
137}
138
140 return vbox(
141 {text("🖥️ Layout Information") | bold | color(Color::Magenta),
142 text(absl::StrFormat("Active Panel: %s", layout_info_.active_panel)) |
143 color(Color::White),
144 text(absl::StrFormat("Panel Count: %s", layout_info_.panel_count)) |
145 color(Color::Cyan),
146 text(absl::StrFormat("Layout Mode: %s", layout_info_.layout_mode)) |
147 color(Color::Yellow),
148 text(absl::StrFormat("Focus State: %s", layout_info_.focus_state)) |
149 color(Color::Green)});
150}
151
153 if (current_error_.empty()) {
154 return vbox({text("✅ No Errors") | color(Color::Green)});
155 }
156
157 return vbox({text("⚠️ Error") | bold | color(Color::Red),
158 text(current_error_) | color(Color::Yellow)});
159}
160
162 return hbox({text("e: Expand | d: Details | q: Quit") | dim, filler(),
163 text(expanded_ ? "EXPANDED" : "COLLAPSED") | color(Color::Cyan),
164 filler(),
165 text(show_detailed_info_ ? "DETAILED" : "SIMPLE") |
166 color(Color::Yellow)});
167}
168
170 if (!rom_context_) {
171 rom_info_.loaded = false;
172 rom_info_.title = "No ROM";
173 rom_info_.size = "0 bytes";
174 rom_info_.checksum = "N/A";
175 rom_info_.region = "N/A";
176 return;
177 }
178
179 rom_info_.loaded = true;
181 rom_info_.size = absl::StrFormat("%d bytes", rom_context_->size());
182
183 // Calculate checksum (simplified)
184 uint32_t checksum = 0;
185 if (rom_context_->size() > 0) {
186 for (size_t i = 0; i < std::min(rom_context_->size(), size_t(1024)); ++i) {
187 checksum += rom_context_->vector()[i];
188 }
189 }
190 rom_info_.checksum = absl::StrFormat("0x%08X", checksum);
191
192 // Determine region (simplified)
193 if (rom_context_->size() > 0) {
194 uint8_t region_byte = rom_context_->vector()[0x7FD9]; // SNES region byte
195 switch (region_byte) {
196 case 0x00:
197 rom_info_.region = "NTSC";
198 break;
199 case 0x01:
200 rom_info_.region = "PAL";
201 break;
202 default:
203 rom_info_.region = "Unknown";
204 break;
205 }
206 } else {
207 rom_info_.region = "Unknown";
208 }
209}
210
212 // Get current time
213 auto now = std::chrono::system_clock::now();
214 auto time_t = std::chrono::system_clock::to_time_t(now);
215 auto tm = *std::localtime(&time_t);
216
217 std::stringstream ss;
218 ss << std::put_time(&tm, "%H:%M:%S");
219 system_info_.current_time = ss.str();
220
221 // Placeholder system info (in a real implementation, you'd query the system)
222 system_info_.memory_usage = "Unknown";
223 system_info_.cpu_usage = "Unknown";
224 system_info_.disk_space = "Unknown";
225}
226
228 // Placeholder layout info (in a real implementation, you'd get this from the
229 // layout manager)
230 layout_info_.active_panel = "Main Menu";
232 layout_info_.layout_mode = "Unified";
233 layout_info_.focus_state = "Chat";
234}
235
236} // namespace cli
237} // namespace yaze
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
const auto & vector() const
Definition rom.h:139
auto size() const
Definition rom.h:134
auto title() const
Definition rom.h:133
struct yaze::cli::EnhancedStatusPanel::LayoutInfo layout_info_
bool HandleStatusEvents(const ftxui::Event &event)
struct yaze::cli::EnhancedStatusPanel::SystemInfo system_info_
std::function< bool(const ftxui::Event &) status_event_handler_)
void SetError(const std::string &error)
EnhancedStatusPanel(Rom *rom_context=nullptr)
struct yaze::cli::EnhancedStatusPanel::RomInfo rom_info_
Definition cli.h:17