Refactor Editor and SettingsEditor classes to manage context; update keyboard shortcuts display logic

This commit is contained in:
scawful
2025-03-10 11:25:49 -04:00
parent ecac4e5b60
commit 5607ef7702
4 changed files with 20 additions and 11 deletions

View File

@@ -39,7 +39,7 @@ enum class EditorType {
kSettings, kSettings,
}; };
constexpr std::array<const char *, 10> kEditorNames = { constexpr std::array<const char*, 10> kEditorNames = {
"Assembly", "Dungeon", "Graphics", "Music", "Overworld", "Assembly", "Dungeon", "Graphics", "Music", "Overworld",
"Palette", "Screen", "Sprite", "Message", "Settings", "Palette", "Screen", "Sprite", "Message", "Settings",
}; };
@@ -75,9 +75,11 @@ class Editor {
EditorType type() const { return type_; } EditorType type() const { return type_; }
void set_context(EditorContext* context) { context_ = context; }
protected: protected:
EditorType type_; EditorType type_;
EditorContext context_; EditorContext* context_ = nullptr;
}; };
} // namespace editor } // namespace editor

View File

@@ -42,6 +42,9 @@ class EditorManager : public SharedRom {
active_editors_ = {&overworld_editor_, &dungeon_editor_, &graphics_editor_, active_editors_ = {&overworld_editor_, &dungeon_editor_, &graphics_editor_,
&palette_editor_, &sprite_editor_, &message_editor_, &palette_editor_, &sprite_editor_, &message_editor_,
&screen_editor_, &settings_editor_}; &screen_editor_, &settings_editor_};
for (auto *editor : active_editors_) {
editor->set_context(&context_);
}
std::stringstream ss; std::stringstream ss;
ss << YAZE_VERSION_MAJOR << "." << YAZE_VERSION_MINOR << "." ss << YAZE_VERSION_MAJOR << "." << YAZE_VERSION_MINOR << "."
<< YAZE_VERSION_PATCH; << YAZE_VERSION_PATCH;

View File

@@ -23,9 +23,7 @@ using ImGui::TableSetupColumn;
void SettingsEditor::Initialize() {} void SettingsEditor::Initialize() {}
absl::Status SettingsEditor::Load() { absl::Status SettingsEditor::Load() { return absl::OkStatus(); }
return absl::OkStatus();
}
absl::Status SettingsEditor::Update() { absl::Status SettingsEditor::Update() {
if (BeginTabBar("Settings", ImGuiTabBarFlags_None)) { if (BeginTabBar("Settings", ImGuiTabBarFlags_None)) {
@@ -38,6 +36,7 @@ absl::Status SettingsEditor::Update() {
EndTabItem(); EndTabItem();
} }
if (BeginTabItem("Keyboard Shortcuts")) { if (BeginTabItem("Keyboard Shortcuts")) {
DrawKeyboardShortcuts();
EndTabItem(); EndTabItem();
} }
EndTabBar(); EndTabBar();
@@ -91,8 +90,15 @@ void SettingsEditor::DrawGeneralSettings() {
} }
} }
absl::Status SettingsEditor::DrawKeyboardShortcuts() { void SettingsEditor::DrawKeyboardShortcuts() {
return absl::OkStatus(); 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 } // namespace editor

View File

@@ -1,10 +1,9 @@
#ifndef YAZE_APP_EDITOR_SETTINGS_EDITOR_H #ifndef YAZE_APP_EDITOR_SETTINGS_EDITOR_H
#define YAZE_APP_EDITOR_SETTINGS_EDITOR_H #define YAZE_APP_EDITOR_SETTINGS_EDITOR_H
#include "imgui/imgui.h"
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/editor/editor.h" #include "app/editor/editor.h"
#include "imgui/imgui.h"
namespace yaze { namespace yaze {
namespace editor { namespace editor {
@@ -220,8 +219,7 @@ class SettingsEditor : public Editor {
private: private:
void DrawGeneralSettings(); void DrawGeneralSettings();
void DrawKeyboardShortcuts();
absl::Status DrawKeyboardShortcuts();
}; };
} // namespace editor } // namespace editor