From 31217e1c5c22ef445c16161286a37bd63128f4f8 Mon Sep 17 00:00:00 2001 From: Justin Scofield <47263509+scawful@users.noreply.github.com> Date: Sun, 5 Jan 2025 11:58:45 -0500 Subject: [PATCH] Refactor flags and add Font Manager to settings editor Simplified `ExperimentFlags` by removing unused flags and updated `Controller` to no longer inherit from it. Refactored `FlagsMenu` to separate flag categories into individual methods for better organization. Enhanced settings editor with a new "Font Manager" tab and updated `DrawGeneralSettings` to use the new flag category methods. Added `DrawFontManager` function for font management. --- src/app/core/common.h | 10 ---- src/app/core/controller.h | 2 +- src/app/editor/system/flags.h | 65 +++++++++++------------- src/app/editor/system/settings_editor.cc | 41 +++++++++++---- src/app/gui/style.cc | 29 +++++++++++ src/app/gui/style.h | 2 + 6 files changed, 94 insertions(+), 55 deletions(-) diff --git a/src/app/core/common.h b/src/app/core/common.h index a09723c9..9110cbb7 100644 --- a/src/app/core/common.h +++ b/src/app/core/common.h @@ -56,12 +56,6 @@ class ExperimentFlags { // Attempt to run the dungeon room draw routine when opening a room. bool kDrawDungeonRoomGraphics = true; - // Use the new platform specific file dialog wrappers. - bool kNewFileDialogWrapper = true; - - // Uses texture streaming from SDL for my dynamic updates. - bool kLoadTexturesAsStreaming = true; - // Save dungeon map edits to the Rom. bool kSaveDungeonMaps = false; @@ -113,10 +107,6 @@ class ExperimentFlags { "\n"; result += "kDrawDungeonRoomGraphics: " + std::to_string(get().kDrawDungeonRoomGraphics) + "\n"; - result += "kNewFileDialogWrapper: " + - std::to_string(get().kNewFileDialogWrapper) + "\n"; - result += "kLoadTexturesAsStreaming: " + - std::to_string(get().kLoadTexturesAsStreaming) + "\n"; result += "kSaveDungeonMaps: " + std::to_string(get().kSaveDungeonMaps) + "\n"; result += "kLogToConsole: " + std::to_string(get().kLogToConsole) + "\n"; diff --git a/src/app/core/controller.h b/src/app/core/controller.h index 99654d15..41f22106 100644 --- a/src/app/core/controller.h +++ b/src/app/core/controller.h @@ -26,7 +26,7 @@ namespace core { * This class is responsible for managing the main window and the * main editor. It is the main entry point for the application. */ -class Controller : public ExperimentFlags { +class Controller { public: bool IsActive() const { return active_; } absl::Status OnEntry(std::string filename = ""); diff --git a/src/app/editor/system/flags.h b/src/app/editor/system/flags.h index fbada123..94970415 100644 --- a/src/app/editor/system/flags.h +++ b/src/app/editor/system/flags.h @@ -15,45 +15,42 @@ using ImGui::MenuItem; using ImGui::Separator; struct FlagsMenu { - void Draw() { - if (BeginMenu("Overworld Flags")) { - Checkbox("Enable Overworld Sprites", - &ExperimentFlags::get().overworld.kDrawOverworldSprites); - Separator(); - Checkbox("Save Overworld Maps", - &ExperimentFlags::get().overworld.kSaveOverworldMaps); - Checkbox("Save Overworld Entrances", - &ExperimentFlags::get().overworld.kSaveOverworldEntrances); - Checkbox("Save Overworld Exits", - &ExperimentFlags::get().overworld.kSaveOverworldExits); - Checkbox("Save Overworld Items", - &ExperimentFlags::get().overworld.kSaveOverworldItems); - Checkbox("Save Overworld Properties", - &ExperimentFlags::get().overworld.kSaveOverworldProperties); - Checkbox("Load Custom Overworld", - &ExperimentFlags::get().overworld.kLoadCustomOverworld); - ImGui::EndMenu(); - } + void DrawOverworldFlags() { + Checkbox("Enable Overworld Sprites", + &ExperimentFlags::get().overworld.kDrawOverworldSprites); + Separator(); + Checkbox("Save Overworld Maps", + &ExperimentFlags::get().overworld.kSaveOverworldMaps); + Checkbox("Save Overworld Entrances", + &ExperimentFlags::get().overworld.kSaveOverworldEntrances); + Checkbox("Save Overworld Exits", + &ExperimentFlags::get().overworld.kSaveOverworldExits); + Checkbox("Save Overworld Items", + &ExperimentFlags::get().overworld.kSaveOverworldItems); + Checkbox("Save Overworld Properties", + &ExperimentFlags::get().overworld.kSaveOverworldProperties); + Checkbox("Load Custom Overworld", + &ExperimentFlags::get().overworld.kLoadCustomOverworld); + } - if (BeginMenu("Dungeon Flags")) { - Checkbox("Draw Dungeon Room Graphics", - &ExperimentFlags::get().kDrawDungeonRoomGraphics); - Separator(); - Checkbox("Save Dungeon Maps", &ExperimentFlags::get().kSaveDungeonMaps); - ImGui::EndMenu(); - } + void DrawDungeonFlags() { + Checkbox("Draw Dungeon Room Graphics", + &ExperimentFlags::get().kDrawDungeonRoomGraphics); + Separator(); + Checkbox("Save Dungeon Maps", &ExperimentFlags::get().kSaveDungeonMaps); + } - Checkbox("Use built-in file dialog", - &ExperimentFlags::get().kNewFileDialogWrapper); - Checkbox("Enable Console Logging", &ExperimentFlags::get().kLogToConsole); - Checkbox("Enable Texture Streaming", - &ExperimentFlags::get().kLoadTexturesAsStreaming); - Checkbox("Log Instructions to Debugger", - &ExperimentFlags::get().kLogInstructions); + void DrawResourceFlags() { Checkbox("Save All Palettes", &ExperimentFlags::get().kSaveAllPalettes); Checkbox("Save Gfx Groups", &ExperimentFlags::get().kSaveGfxGroups); Checkbox("Save Graphics Sheets", - &ExperimentFlags::get().kSaveGraphicsSheet); + &ExperimentFlags::get().kSaveGraphicsSheet); + } + + void DrawSystemFlags() { + Checkbox("Enable Console Logging", &ExperimentFlags::get().kLogToConsole); + Checkbox("Log Instructions to Emulator Debugger", + &ExperimentFlags::get().kLogInstructions); } }; diff --git a/src/app/editor/system/settings_editor.cc b/src/app/editor/system/settings_editor.cc index 89157d72..5a2bc4c2 100644 --- a/src/app/editor/system/settings_editor.cc +++ b/src/app/editor/system/settings_editor.cc @@ -1,6 +1,7 @@ #include "app/editor/system/settings_editor.h" +#include "app/gui/style.h" #include "absl/status/status.h" #include "app/editor/system/flags.h" #include "imgui/imgui.h" @@ -34,6 +35,10 @@ absl::Status SettingsEditor::Update() { DrawGeneralSettings(); EndTabItem(); } + if (BeginTabItem("Font Manager")) { + gui::DrawFontManager(); + EndTabItem(); + } if (BeginTabItem("Keyboard Shortcuts")) { EndTabItem(); } @@ -44,28 +49,44 @@ absl::Status SettingsEditor::Update() { } void SettingsEditor::DrawGeneralSettings() { - if (BeginTable("##SettingsTable", 2, + static FlagsMenu flags; + + if (BeginTable("##SettingsTable", 4, ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable)) { - TableSetupColumn("Experiment Flags", ImGuiTableColumnFlags_WidthFixed, - 250.0f); - TableSetupColumn("General Setting", ImGuiTableColumnFlags_WidthStretch, + TableSetupColumn("System Flags", ImGuiTableColumnFlags_WidthStretch); + TableSetupColumn("Overworld Flags", ImGuiTableColumnFlags_WidthStretch); + TableSetupColumn("Dungeon Flags", ImGuiTableColumnFlags_WidthStretch); + TableSetupColumn("Resource Flags", ImGuiTableColumnFlags_WidthStretch, 0.0f); TableHeadersRow(); TableNextColumn(); - if (BeginChild("##GeneralSettingsStyleWrapper", ImVec2(0, 0), + if (BeginChild("##SystemFlags", ImVec2(0, 0), ImGuiChildFlags_FrameStyle)) { - static FlagsMenu flags; - flags.Draw(); + flags.DrawSystemFlags(); EndChild(); } TableNextColumn(); - if (BeginChild("##GeneralSettingsWrapper", ImVec2(0, 0), - ImGuiChildFlags_FrameStyle)) { - Text("TODO: Add some settings here"); + if (BeginChild("##OverworldFlags", ImVec2(0, 0), + ImGuiChildFlags_FrameStyle)) { + flags.DrawOverworldFlags(); + EndChild(); + } + + TableNextColumn(); + if (BeginChild("##DungeonFlags", ImVec2(0, 0), + ImGuiChildFlags_FrameStyle)) { + flags.DrawDungeonFlags(); + EndChild(); + } + + TableNextColumn(); + if (BeginChild("##ResourceFlags", ImVec2(0, 0), + ImGuiChildFlags_FrameStyle)) { + flags.DrawResourceFlags(); EndChild(); } diff --git a/src/app/gui/style.cc b/src/app/gui/style.cc index 537caac3..a63860b1 100644 --- a/src/app/gui/style.cc +++ b/src/app/gui/style.cc @@ -749,5 +749,34 @@ void TextWithSeparators(const absl::string_view &text) { ImGui::Separator(); } +void DrawFontManager() { + ImGuiIO& io = ImGui::GetIO(); + ImFontAtlas* atlas = io.Fonts; + static ImFont* current_font = atlas->Fonts[0]; + static int current_font_index = 0; + static int font_size = 16; + static bool font_selected = false; + ImGui::Text("Current Font: %s", current_font->GetDebugName()); + ImGui::Text("Font Size: %d", font_size); + if (ImGui::BeginCombo("Fonts", current_font->GetDebugName())) { + for (int i = 0; i < atlas->Fonts.Size; i++) { + bool is_selected = (current_font == atlas->Fonts[i]); + if (ImGui::Selectable(atlas->Fonts[i]->GetDebugName(), is_selected)) { + current_font = atlas->Fonts[i]; + current_font_index = i; + font_selected = true; + } + if (is_selected) { + ImGui::SetItemDefaultFocus(); + } + } + ImGui::EndCombo(); + } + ImGui::Separator(); + if (ImGui::SliderInt("Font Size", &font_size, 8, 32)) { + current_font->Scale = font_size / 16.0f; + } +} + } // namespace gui } // namespace yaze diff --git a/src/app/gui/style.h b/src/app/gui/style.h index d21a7144..54ce806a 100644 --- a/src/app/gui/style.h +++ b/src/app/gui/style.h @@ -66,6 +66,8 @@ void DrawDisplaySettings(ImGuiStyle *ref = nullptr); void TextWithSeparators(const absl::string_view &text); +void DrawFontManager(); + static const char *ExampleNames[] = { "Artichoke", "Arugula", "Asparagus", "Avocado", "Bamboo Shoots", "Bean Sprouts", "Beans", "Beet",