yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
settings_editor.cc
Go to the documentation of this file.
1
3
4#include "absl/status/status.h"
7#include "app/gui/style.h"
8#include "app/gui/icons.h"
10#include "imgui/imgui.h"
11#include "util/log.h"
12
13#include <set>
14#include <filesystem>
15
16namespace yaze {
17namespace editor {
18
19using ImGui::BeginTabBar;
20using ImGui::BeginTabItem;
21using ImGui::BeginTable;
22using ImGui::EndTabBar;
23using ImGui::EndTabItem;
24using ImGui::EndTable;
25using ImGui::TableHeadersRow;
26using ImGui::TableNextColumn;
27using ImGui::TableSetupColumn;
28
30
31absl::Status SettingsEditor::Load() {
32 gfx::ScopedTimer timer("SettingsEditor::Load");
33 return absl::OkStatus();
34}
35
36absl::Status SettingsEditor::Update() {
37 if (BeginTabBar("Settings", ImGuiTabBarFlags_None)) {
38 if (BeginTabItem(ICON_MD_SETTINGS " General")) {
40 EndTabItem();
41 }
42 if (BeginTabItem(ICON_MD_FONT_DOWNLOAD " Font Manager")) {
44 EndTabItem();
45 }
46 if (BeginTabItem(ICON_MD_KEYBOARD " Keyboard Shortcuts")) {
48 EndTabItem();
49 }
50 if (BeginTabItem(ICON_MD_PALETTE " Themes")) {
52 EndTabItem();
53 }
54 if (BeginTabItem(ICON_MD_TUNE " Editor Behavior")) {
56 EndTabItem();
57 }
58 if (BeginTabItem(ICON_MD_SPEED " Performance")) {
60 EndTabItem();
61 }
62 if (BeginTabItem(ICON_MD_SMART_TOY " AI Agent")) {
64 EndTabItem();
65 }
66 EndTabBar();
67 }
68
69 return absl::OkStatus();
70}
71
73 static gui::FlagsMenu flags;
74
75 if (BeginTable("##SettingsTable", 4,
76 ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable |
77 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable)) {
78 TableSetupColumn("System Flags", ImGuiTableColumnFlags_WidthStretch);
79 TableSetupColumn("Overworld Flags", ImGuiTableColumnFlags_WidthStretch);
80 TableSetupColumn("Dungeon Flags", ImGuiTableColumnFlags_WidthStretch);
81 TableSetupColumn("Resource Flags", ImGuiTableColumnFlags_WidthStretch,
82 0.0f);
83
84 TableHeadersRow();
85
86 TableNextColumn();
87 flags.DrawSystemFlags();
88
89 TableNextColumn();
90 flags.DrawOverworldFlags();
91
92 TableNextColumn();
93 flags.DrawDungeonFlags();
94
95 TableNextColumn();
96 flags.DrawResourceFlags();
97
98 EndTable();
99 }
100}
101
103 ImGui::Text("Keyboard shortcut customization coming soon...");
104 ImGui::Separator();
105
106 // TODO: Implement keyboard shortcut editor with:
107 // - Visual shortcut conflict detection
108 // - Import/export shortcut profiles
109 // - Search and filter shortcuts
110 // - Live editing and rebinding
111}
112
114 using namespace ImGui;
115
116 auto& theme_manager = gui::ThemeManager::Get();
117
118 Text("%s Theme Management", ICON_MD_PALETTE);
119 Separator();
120
121 // Current theme selection
122 Text("Current Theme:");
123 SameLine();
124 auto current = theme_manager.GetCurrentThemeName();
125 TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f), "%s", current.c_str());
126
127 Spacing();
128
129 // Available themes grid
130 Text("Available Themes:");
131 for (const auto& theme_name : theme_manager.GetAvailableThemes()) {
132 PushID(theme_name.c_str());
133 bool is_current = (theme_name == current);
134
135 if (is_current) {
136 PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.6f, 0.8f, 1.0f));
137 }
138
139 if (Button(theme_name.c_str(), ImVec2(180, 0))) {
140 theme_manager.LoadTheme(theme_name);
141 }
142
143 if (is_current) {
144 PopStyleColor();
145 SameLine();
146 Text(ICON_MD_CHECK);
147 }
148
149 PopID();
150 }
151
152 Separator();
153 Spacing();
154
155 // Theme operations
156 if (CollapsingHeader(ICON_MD_EDIT " Theme Operations")) {
157 TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f),
158 "Theme import/export coming soon");
159 }
160}
161
163 using namespace ImGui;
164
165 if (!user_settings_) {
166 Text("No user settings available");
167 return;
168 }
169
170 Text("%s Editor Behavior Settings", ICON_MD_TUNE);
171 Separator();
172
173 // Autosave settings
174 if (CollapsingHeader(ICON_MD_SAVE " Auto-Save", ImGuiTreeNodeFlags_DefaultOpen)) {
175 if (Checkbox("Enable Auto-Save", &user_settings_->prefs().autosave_enabled)) {
177 }
178
180 int interval = static_cast<int>(user_settings_->prefs().autosave_interval);
181 if (SliderInt("Interval (seconds)", &interval, 60, 600)) {
182 user_settings_->prefs().autosave_interval = static_cast<float>(interval);
184 }
185
186 if (Checkbox("Create Backup Before Save", &user_settings_->prefs().backup_before_save)) {
188 }
189 }
190 }
191
192 // Recent files
193 if (CollapsingHeader(ICON_MD_HISTORY " Recent Files")) {
194 if (SliderInt("Recent Files Limit", &user_settings_->prefs().recent_files_limit, 5, 50)) {
196 }
197 }
198
199 // Editor defaults
200 if (CollapsingHeader(ICON_MD_EDIT " Default Editor")) {
201 Text("Editor to open on ROM load:");
202 const char* editors[] = { "None", "Overworld", "Dungeon", "Graphics" };
203 if (Combo("##DefaultEditor", &user_settings_->prefs().default_editor, editors, IM_ARRAYSIZE(editors))) {
205 }
206 }
207}
208
210 using namespace ImGui;
211
212 if (!user_settings_) {
213 Text("No user settings available");
214 return;
215 }
216
217 Text("%s Performance Settings", ICON_MD_SPEED);
218 Separator();
219
220 // Graphics settings
221 if (CollapsingHeader(ICON_MD_IMAGE " Graphics", ImGuiTreeNodeFlags_DefaultOpen)) {
222 if (Checkbox("V-Sync", &user_settings_->prefs().vsync)) {
224 }
225
226 if (SliderInt("Target FPS", &user_settings_->prefs().target_fps, 30, 144)) {
228 }
229 }
230
231 // Memory settings
232 if (CollapsingHeader(ICON_MD_MEMORY " Memory")) {
233 if (SliderInt("Cache Size (MB)", &user_settings_->prefs().cache_size_mb, 128, 2048)) {
235 }
236
237 if (SliderInt("Undo History", &user_settings_->prefs().undo_history_size, 10, 200)) {
239 }
240 }
241
242 Separator();
243 Text("Current FPS: %.1f", ImGui::GetIO().Framerate);
244 Text("Frame Time: %.3f ms", 1000.0f / ImGui::GetIO().Framerate);
245}
246
248 using namespace ImGui;
249
250 if (!user_settings_) {
251 Text("No user settings available");
252 return;
253 }
254
255 Text("%s AI Agent Configuration", ICON_MD_SMART_TOY);
256 Separator();
257
258 // Provider selection
259 if (CollapsingHeader(ICON_MD_CLOUD " AI Provider", ImGuiTreeNodeFlags_DefaultOpen)) {
260 const char* providers[] = { "Ollama (Local)", "Gemini (Cloud)", "Mock (Testing)" };
261 if (Combo("Provider", &user_settings_->prefs().ai_provider, providers, IM_ARRAYSIZE(providers))) {
263 }
264
265 Spacing();
266
267 if (user_settings_->prefs().ai_provider == 0) { // Ollama
268 char url_buffer[256];
269 strncpy(url_buffer, user_settings_->prefs().ollama_url.c_str(), sizeof(url_buffer) - 1);
270 url_buffer[sizeof(url_buffer) - 1] = '\0';
271 if (InputText("URL", url_buffer, IM_ARRAYSIZE(url_buffer))) {
272 user_settings_->prefs().ollama_url = url_buffer;
274 }
275 } else if (user_settings_->prefs().ai_provider == 1) { // Gemini
276 char key_buffer[128];
277 strncpy(key_buffer, user_settings_->prefs().gemini_api_key.c_str(), sizeof(key_buffer) - 1);
278 key_buffer[sizeof(key_buffer) - 1] = '\0';
279 if (InputText("API Key", key_buffer, IM_ARRAYSIZE(key_buffer), ImGuiInputTextFlags_Password)) {
280 user_settings_->prefs().gemini_api_key = key_buffer;
282 }
283 }
284 }
285
286 // Model parameters
287 if (CollapsingHeader(ICON_MD_TUNE " Model Parameters")) {
288 if (SliderFloat("Temperature", &user_settings_->prefs().ai_temperature, 0.0f, 2.0f)) {
290 }
291 TextDisabled("Higher = more creative");
292
293 if (SliderInt("Max Tokens", &user_settings_->prefs().ai_max_tokens, 256, 8192)) {
295 }
296 }
297
298 // Agent behavior
299 if (CollapsingHeader(ICON_MD_PSYCHOLOGY " Behavior")) {
300 if (Checkbox("Proactive Suggestions", &user_settings_->prefs().ai_proactive)) {
302 }
303
304 if (Checkbox("Auto-Learn Preferences", &user_settings_->prefs().ai_auto_learn)) {
306 }
307
308 if (Checkbox("Enable Vision/Multimodal", &user_settings_->prefs().ai_multimodal)) {
310 }
311 }
312
313 // z3ed CLI logging settings
314 if (CollapsingHeader(ICON_MD_TERMINAL " CLI Logging", ImGuiTreeNodeFlags_DefaultOpen)) {
315 Text("Configure z3ed command-line logging behavior");
316 Spacing();
317
318 // Log level selection
319 const char* log_levels[] = { "Debug (Verbose)", "Info (Normal)", "Warning (Quiet)", "Error (Critical)", "Fatal Only" };
320 if (Combo("Log Level", &user_settings_->prefs().log_level, log_levels, IM_ARRAYSIZE(log_levels))) {
321 // Apply log level immediately using existing LogManager
322 util::LogLevel level;
323 switch (user_settings_->prefs().log_level) {
324 case 0: level = util::LogLevel::YAZE_DEBUG; break;
325 case 1: level = util::LogLevel::INFO; break;
326 case 2: level = util::LogLevel::WARNING; break;
327 case 3: level = util::LogLevel::ERROR; break;
328 case 4: level = util::LogLevel::FATAL; break;
329 default: level = util::LogLevel::INFO; break;
330 }
331
332 // Get current categories
333 std::set<std::string> categories;
334 if (user_settings_->prefs().log_ai_requests) categories.insert("AI");
335 if (user_settings_->prefs().log_rom_operations) categories.insert("ROM");
336 if (user_settings_->prefs().log_gui_automation) categories.insert("GUI");
337 if (user_settings_->prefs().log_proposals) categories.insert("Proposals");
338
339 // Reconfigure with new level
342 Text("✓ Log level applied");
343 }
344 TextDisabled("Controls verbosity of YAZE and z3ed output");
345
346 Spacing();
347
348 // Logging targets
349 if (Checkbox("Log to File", &user_settings_->prefs().log_to_file)) {
351 // Set default path if empty
352 if (user_settings_->prefs().log_file_path.empty()) {
353 const char* home = std::getenv("HOME");
354 if (home) {
355 user_settings_->prefs().log_file_path = std::string(home) + "/.yaze/logs/yaze.log";
356 }
357 }
358
359 // Enable file logging
360 std::set<std::string> categories;
363 } else {
364 // Disable file logging
365 std::set<std::string> categories;
367 util::LogManager::instance().configure(level, "", categories);
368 }
370 }
371
373 Indent();
374 char path_buffer[512];
375 strncpy(path_buffer, user_settings_->prefs().log_file_path.c_str(), sizeof(path_buffer) - 1);
376 path_buffer[sizeof(path_buffer) - 1] = '\0';
377 if (InputText("Log File", path_buffer, IM_ARRAYSIZE(path_buffer))) {
378 // Update log file path
379 user_settings_->prefs().log_file_path = path_buffer;
380 std::set<std::string> categories;
384 }
385
386 TextDisabled("Log file path (supports ~ for home directory)");
387 Unindent();
388 }
389
390 Spacing();
391
392 // Log filtering
393 Text(ICON_MD_FILTER_ALT " Category Filtering");
394 Separator();
395 TextDisabled("Enable/disable specific log categories");
396 Spacing();
397
398 bool categories_changed = false;
399
400 categories_changed |= Checkbox("AI API Requests", &user_settings_->prefs().log_ai_requests);
401 categories_changed |= Checkbox("ROM Operations", &user_settings_->prefs().log_rom_operations);
402 categories_changed |= Checkbox("GUI Automation", &user_settings_->prefs().log_gui_automation);
403 categories_changed |= Checkbox("Proposal Generation", &user_settings_->prefs().log_proposals);
404
405 if (categories_changed) {
406 // Rebuild category set
407 std::set<std::string> categories;
408 if (user_settings_->prefs().log_ai_requests) categories.insert("AI");
409 if (user_settings_->prefs().log_rom_operations) categories.insert("ROM");
410 if (user_settings_->prefs().log_gui_automation) categories.insert("GUI");
411 if (user_settings_->prefs().log_proposals) categories.insert("Proposals");
412
413 // Reconfigure LogManager
417 categories);
419 }
420
421 Spacing();
422
423 // Quick actions
424 if (Button(ICON_MD_DELETE " Clear Logs")) {
426 std::filesystem::path path(user_settings_->prefs().log_file_path);
427 if (std::filesystem::exists(path)) {
428 std::filesystem::remove(path);
429 LOG_DEBUG("Settings", "Log file cleared: %s", user_settings_->prefs().log_file_path.c_str());
430 }
431 }
432 }
433 SameLine();
434 if (Button(ICON_MD_FOLDER_OPEN " Open Log Directory")) {
436 std::filesystem::path path(user_settings_->prefs().log_file_path);
437 std::filesystem::path dir = path.parent_path();
438
439 // Platform-specific command to open directory
440#ifdef _WIN32
441 std::string cmd = "explorer " + dir.string();
442#elif __APPLE__
443 std::string cmd = "open " + dir.string();
444#else
445 std::string cmd = "xdg-open " + dir.string();
446#endif
447 system(cmd.c_str());
448 }
449 }
450
451 Spacing();
452 Separator();
453
454 // Log test buttons
455 Text(ICON_MD_BUG_REPORT " Test Logging");
456 if (Button("Test Debug")) {
457 LOG_DEBUG("Settings", "This is a debug message");
458 }
459 SameLine();
460 if (Button("Test Info")) {
461 LOG_INFO("Settings", "This is an info message");
462 }
463 SameLine();
464 if (Button("Test Warning")) {
465 LOG_WARN("Settings", "This is a warning message");
466 }
467 SameLine();
468 if (Button("Test Error")) {
469 LOG_ERROR("Settings", "This is an error message");
470 }
471 }
472}
473
474} // namespace editor
475} // namespace yaze
absl::Status Update() override
absl::Status Load() override
RAII timer for automatic timing management.
static ThemeManager & Get()
static LogManager & instance()
Definition log.cc:29
void configure(LogLevel level, const std::string &file_path, const std::set< std::string > &categories)
Configures the logging system.
Definition log.cc:43
#define ICON_MD_FOLDER_OPEN
Definition icons.h:811
#define ICON_MD_SETTINGS
Definition icons.h:1697
#define ICON_MD_MEMORY
Definition icons.h:1193
#define ICON_MD_CHECK
Definition icons.h:395
#define ICON_MD_TUNE
Definition icons.h:2020
#define ICON_MD_FONT_DOWNLOAD
Definition icons.h:816
#define ICON_MD_BUG_REPORT
Definition icons.h:325
#define ICON_MD_EDIT
Definition icons.h:643
#define ICON_MD_SPEED
Definition icons.h:1815
#define ICON_MD_KEYBOARD
Definition icons.h:1026
#define ICON_MD_PSYCHOLOGY
Definition icons.h:1521
#define ICON_MD_IMAGE
Definition icons.h:980
#define ICON_MD_TERMINAL
Definition icons.h:1949
#define ICON_MD_SAVE
Definition icons.h:1642
#define ICON_MD_DELETE
Definition icons.h:528
#define ICON_MD_PALETTE
Definition icons.h:1368
#define ICON_MD_CLOUD
Definition icons.h:421
#define ICON_MD_FILTER_ALT
Definition icons.h:759
#define ICON_MD_SMART_TOY
Definition icons.h:1779
#define ICON_MD_HISTORY
Definition icons.h:944
#define LOG_DEBUG(category, format,...)
Definition log.h:104
#define LOG_ERROR(category, format,...)
Definition log.h:110
#define LOG_WARN(category, format,...)
Definition log.h:108
#define LOG_INFO(category, format,...)
Definition log.h:106
Definition input.cc:20
void DrawFontManager()
Definition style.cc:1286
LogLevel
Defines the severity levels for log messages. This allows for filtering messages based on their impor...
Definition log.h:27
Main namespace for the application.