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 <ftxui/component/component.hpp>
4#include <ftxui/dom/elements.hpp>
5#include <chrono>
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({
71 });
72
73 return Renderer(container, [this] {
74 return vbox({
75 text("📊 Status Panel") | bold | center,
76 separator(),
77 rom_info_section_->Render(),
78 separator(),
79 system_info_section_->Render(),
80 separator(),
81 layout_info_section_->Render(),
82 separator(),
83 error_section_->Render(),
84 separator(),
86 }) | border;
87 });
88}
89
91 return Renderer([this] {
92 return RenderRomInfo();
93 });
94}
95
97 return Renderer([this] {
98 return RenderSystemInfo();
99 });
100}
101
103 return Renderer([this] {
104 return RenderLayoutInfo();
105 });
106}
107
109 return Renderer([this] {
110 return RenderErrorInfo();
111 });
112}
113
115 if (event == Event::Character('e')) {
117 return true;
118 }
119
120 if (event == Event::Character('d')) {
122 return true;
123 }
124
125 return false;
126}
127
129 if (!rom_info_.loaded) {
130 return vbox({
131 text("🎮 ROM Information") | bold | color(Color::Red),
132 text("No ROM loaded") | color(Color::Red),
133 text("Load a ROM to see information") | dim
134 });
135 }
136
137 return vbox({
138 text("🎮 ROM Information") | bold | color(Color::Green),
139 text(absl::StrFormat("Title: %s", rom_info_.title)) | color(Color::White),
140 text(absl::StrFormat("Size: %s", rom_info_.size)) | color(Color::Cyan),
141 text(absl::StrFormat("Checksum: %s", rom_info_.checksum)) | color(Color::Yellow),
142 text(absl::StrFormat("Region: %s", rom_info_.region)) | color(Color::Magenta)
143 });
144}
145
147 return vbox({
148 text("💻 System Information") | bold | color(Color::Blue),
149 text(absl::StrFormat("Time: %s", system_info_.current_time)) | color(Color::White),
150 text(absl::StrFormat("Memory: %s", system_info_.memory_usage)) | color(Color::Cyan),
151 text(absl::StrFormat("CPU: %s", system_info_.cpu_usage)) | color(Color::Yellow),
152 text(absl::StrFormat("Disk: %s", system_info_.disk_space)) | color(Color::Green)
153 });
154}
155
157 return vbox({
158 text("🖥️ Layout Information") | bold | color(Color::Magenta),
159 text(absl::StrFormat("Active Panel: %s", layout_info_.active_panel)) | color(Color::White),
160 text(absl::StrFormat("Panel Count: %s", layout_info_.panel_count)) | color(Color::Cyan),
161 text(absl::StrFormat("Layout Mode: %s", layout_info_.layout_mode)) | color(Color::Yellow),
162 text(absl::StrFormat("Focus State: %s", layout_info_.focus_state)) | color(Color::Green)
163 });
164}
165
167 if (current_error_.empty()) {
168 return vbox({
169 text("✅ No Errors") | color(Color::Green)
170 });
171 }
172
173 return vbox({
174 text("⚠️ Error") | bold | color(Color::Red),
175 text(current_error_) | color(Color::Yellow)
176 });
177}
178
180 return hbox({
181 text("e: Expand | d: Details | q: Quit") | dim,
182 filler(),
183 text(expanded_ ? "EXPANDED" : "COLLAPSED") | color(Color::Cyan),
184 filler(),
185 text(show_detailed_info_ ? "DETAILED" : "SIMPLE") | color(Color::Yellow)
186 });
187}
188
190 if (!rom_context_) {
191 rom_info_.loaded = false;
192 rom_info_.title = "No ROM";
193 rom_info_.size = "0 bytes";
194 rom_info_.checksum = "N/A";
195 rom_info_.region = "N/A";
196 return;
197 }
198
199 rom_info_.loaded = true;
201 rom_info_.size = absl::StrFormat("%d bytes", rom_context_->size());
202
203 // Calculate checksum (simplified)
204 uint32_t checksum = 0;
205 if (rom_context_->size() > 0) {
206 for (size_t i = 0; i < std::min(rom_context_->size(), size_t(1024)); ++i) {
207 checksum += rom_context_->vector()[i];
208 }
209 }
210 rom_info_.checksum = absl::StrFormat("0x%08X", checksum);
211
212 // Determine region (simplified)
213 if (rom_context_->size() > 0) {
214 uint8_t region_byte = rom_context_->vector()[0x7FD9]; // SNES region byte
215 switch (region_byte) {
216 case 0x00: rom_info_.region = "NTSC"; break;
217 case 0x01: rom_info_.region = "PAL"; break;
218 default: rom_info_.region = "Unknown"; break;
219 }
220 } else {
221 rom_info_.region = "Unknown";
222 }
223}
224
226 // Get current time
227 auto now = std::chrono::system_clock::now();
228 auto time_t = std::chrono::system_clock::to_time_t(now);
229 auto tm = *std::localtime(&time_t);
230
231 std::stringstream ss;
232 ss << std::put_time(&tm, "%H:%M:%S");
233 system_info_.current_time = ss.str();
234
235 // Placeholder system info (in a real implementation, you'd query the system)
236 system_info_.memory_usage = "Unknown";
237 system_info_.cpu_usage = "Unknown";
238 system_info_.disk_space = "Unknown";
239}
240
242 // Placeholder layout info (in a real implementation, you'd get this from the layout manager)
243 layout_info_.active_panel = "Main Menu";
245 layout_info_.layout_mode = "Unified";
246 layout_info_.focus_state = "Chat";
247}
248
249} // namespace cli
250} // namespace yaze
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
auto vector() const
Definition rom.h:207
auto size() const
Definition rom.h:202
auto title() const
Definition rom.h:201
std::function< bool(const ftxui::Event &)> status_event_handler_
struct yaze::cli::EnhancedStatusPanel::LayoutInfo layout_info_
bool HandleStatusEvents(const ftxui::Event &event)
struct yaze::cli::EnhancedStatusPanel::SystemInfo system_info_
void SetError(const std::string &error)
EnhancedStatusPanel(Rom *rom_context=nullptr)
struct yaze::cli::EnhancedStatusPanel::RomInfo rom_info_
Definition cli.h:21
Main namespace for the application.