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,
};
constexpr std::array<const char *, 10> kEditorNames = {
constexpr std::array<const char*, 10> 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

View File

@@ -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;

View File

@@ -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

View File

@@ -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