From 5607ef77028c2ad263c0e9df3cd3f3555b785458 Mon Sep 17 00:00:00 2001 From: scawful Date: Mon, 10 Mar 2025 11:25:49 -0400 Subject: [PATCH] Refactor Editor and SettingsEditor classes to manage context; update keyboard shortcuts display logic --- src/app/editor/editor.h | 6 ++++-- src/app/editor/editor_manager.h | 3 +++ src/app/editor/system/settings_editor.cc | 16 +++++++++++----- src/app/editor/system/settings_editor.h | 6 ++---- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/app/editor/editor.h b/src/app/editor/editor.h index ad6247eb..41878128 100644 --- a/src/app/editor/editor.h +++ b/src/app/editor/editor.h @@ -39,7 +39,7 @@ enum class EditorType { kSettings, }; -constexpr std::array kEditorNames = { +constexpr std::array kEditorNames = { "Assembly", "Dungeon", "Graphics", "Music", "Overworld", "Palette", "Screen", "Sprite", "Message", "Settings", }; @@ -75,9 +75,11 @@ class Editor { EditorType type() const { return type_; } + void set_context(EditorContext* context) { context_ = context; } + protected: EditorType type_; - EditorContext context_; + EditorContext* context_ = nullptr; }; } // namespace editor diff --git a/src/app/editor/editor_manager.h b/src/app/editor/editor_manager.h index 22ae21f6..c7706112 100644 --- a/src/app/editor/editor_manager.h +++ b/src/app/editor/editor_manager.h @@ -42,6 +42,9 @@ class EditorManager : public SharedRom { active_editors_ = {&overworld_editor_, &dungeon_editor_, &graphics_editor_, &palette_editor_, &sprite_editor_, &message_editor_, &screen_editor_, &settings_editor_}; + for (auto *editor : active_editors_) { + editor->set_context(&context_); + } std::stringstream ss; ss << YAZE_VERSION_MAJOR << "." << YAZE_VERSION_MINOR << "." << YAZE_VERSION_PATCH; diff --git a/src/app/editor/system/settings_editor.cc b/src/app/editor/system/settings_editor.cc index 62e1c415..be920042 100644 --- a/src/app/editor/system/settings_editor.cc +++ b/src/app/editor/system/settings_editor.cc @@ -23,9 +23,7 @@ using ImGui::TableSetupColumn; void SettingsEditor::Initialize() {} -absl::Status SettingsEditor::Load() { - return absl::OkStatus(); -} +absl::Status SettingsEditor::Load() { return absl::OkStatus(); } absl::Status SettingsEditor::Update() { if (BeginTabBar("Settings", ImGuiTabBarFlags_None)) { @@ -38,6 +36,7 @@ absl::Status SettingsEditor::Update() { EndTabItem(); } if (BeginTabItem("Keyboard Shortcuts")) { + DrawKeyboardShortcuts(); EndTabItem(); } EndTabBar(); @@ -91,8 +90,15 @@ void SettingsEditor::DrawGeneralSettings() { } } -absl::Status SettingsEditor::DrawKeyboardShortcuts() { - return absl::OkStatus(); +void SettingsEditor::DrawKeyboardShortcuts() { + for (const auto& [name, shortcut] : + context_->shortcut_manager.GetShortcuts()) { + ImGui::PushID(name.c_str()); + ImGui::Text("%s", name.c_str()); + ImGui::SameLine(ImGui::GetWindowWidth() - 100); + ImGui::Text("%s", PrintShortcut(shortcut.keys).c_str()); + ImGui::PopID(); + } } } // namespace editor diff --git a/src/app/editor/system/settings_editor.h b/src/app/editor/system/settings_editor.h index 8986213b..89ba33f0 100644 --- a/src/app/editor/system/settings_editor.h +++ b/src/app/editor/system/settings_editor.h @@ -1,10 +1,9 @@ #ifndef YAZE_APP_EDITOR_SETTINGS_EDITOR_H #define YAZE_APP_EDITOR_SETTINGS_EDITOR_H -#include "imgui/imgui.h" - #include "absl/status/status.h" #include "app/editor/editor.h" +#include "imgui/imgui.h" namespace yaze { namespace editor { @@ -220,8 +219,7 @@ class SettingsEditor : public Editor { private: void DrawGeneralSettings(); - - absl::Status DrawKeyboardShortcuts(); + void DrawKeyboardShortcuts(); }; } // namespace editor