rename MasterEditor to EditorManager

This commit is contained in:
scawful
2024-08-10 12:23:28 -04:00
parent 94a0fd02f6
commit 20289483ab
7 changed files with 43 additions and 43 deletions

View File

@@ -53,7 +53,7 @@ For developers to reference.
- Updates `editor::MasterEditor` - Updates `editor::MasterEditor`
- Renders the output to the screen. - Renders the output to the screen.
- Handles the teardown of SDL and ImGui resources. - Handles the teardown of SDL and ImGui resources.
- [app/editor/master_editor.cc](../src/app/editor/master_editor.cc) - [app/editor/editor_manager.cc](../src/app/editor/editor_manager.cc)
- Handles the main menu bar - Handles the main menu bar
- Handles `absl::Status` errors as popups delivered to the user. - Handles `absl::Status` errors as popups delivered to the user.
- Update all the editors in a tab view. - Update all the editors in a tab view.

View File

@@ -13,7 +13,7 @@
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "app/core/platform/file_path.h" #include "app/core/platform/file_path.h"
#include "app/core/platform/font_loader.h" #include "app/core/platform/font_loader.h"
#include "app/editor/master_editor.h" #include "app/editor/editor_manager.h"
#include "app/gui/icons.h" #include "app/gui/icons.h"
#include "app/gui/style.h" #include "app/gui/style.h"
@@ -133,7 +133,7 @@ void InitializeClipboard() {
io.ClipboardUserData = nullptr; io.ClipboardUserData = nullptr;
} }
void HandleKeyDown(SDL_Event &event, editor::MasterEditor &editor) { void HandleKeyDown(SDL_Event &event, editor::EditorManager &editor) {
ImGuiIO &io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
io.KeysDown[event.key.keysym.scancode] = (event.type == SDL_KEYDOWN); io.KeysDown[event.key.keysym.scancode] = (event.type == SDL_KEYDOWN);
io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0); io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
@@ -189,7 +189,7 @@ void HandleKeyDown(SDL_Event &event, editor::MasterEditor &editor) {
} }
} }
void HandleKeyUp(SDL_Event &event, editor::MasterEditor &editor) { void HandleKeyUp(SDL_Event &event, editor::EditorManager &editor) {
ImGuiIO &io = ImGui::GetIO(); ImGuiIO &io = ImGui::GetIO();
int key = event.key.keysym.scancode; int key = event.key.keysym.scancode;
IM_ASSERT(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown)); IM_ASSERT(key >= 0 && key < IM_ARRAYSIZE(io.KeysDown));
@@ -282,11 +282,11 @@ absl::Status Controller::OnEntry(std::string filename) {
RETURN_IF_ERROR(CreateGuiContext()) RETURN_IF_ERROR(CreateGuiContext())
if (flags()->kLoadAudioDevice) { if (flags()->kLoadAudioDevice) {
RETURN_IF_ERROR(LoadAudioDevice()) RETURN_IF_ERROR(LoadAudioDevice())
master_editor_.emulator().set_audio_buffer(audio_buffer_); editor_manager_.emulator().set_audio_buffer(audio_buffer_);
master_editor_.emulator().set_audio_device_id(audio_device_); editor_manager_.emulator().set_audio_device_id(audio_device_);
} }
InitializeKeymap(); InitializeKeymap();
master_editor_.SetupScreen(filename); editor_manager_.SetupScreen(filename);
active_ = true; active_ = true;
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -299,10 +299,10 @@ void Controller::OnInput() {
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
switch (event.type) { switch (event.type) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
HandleKeyDown(event, master_editor_); HandleKeyDown(event, editor_manager_);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
HandleKeyUp(event, master_editor_); HandleKeyUp(event, editor_manager_);
break; break;
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
io.AddInputCharactersUTF8(event.text.text); io.AddInputCharactersUTF8(event.text.text);
@@ -331,7 +331,7 @@ void Controller::OnInput() {
} }
absl::Status Controller::OnLoad() { absl::Status Controller::OnLoad() {
if (master_editor_.quit()) { if (editor_manager_.quit()) {
active_ = false; active_ = false;
} }
#if TARGET_OS_IPHONE != 1 #if TARGET_OS_IPHONE != 1
@@ -339,7 +339,7 @@ absl::Status Controller::OnLoad() {
NewMasterFrame(); NewMasterFrame();
} }
#endif #endif
RETURN_IF_ERROR(master_editor_.Update()); RETURN_IF_ERROR(editor_manager_.Update());
#if TARGET_OS_IPHONE != 1 #if TARGET_OS_IPHONE != 1
if (platform_ != Platform::kiOS) { if (platform_ != Platform::kiOS) {
End(); End();
@@ -544,7 +544,7 @@ absl::Status Controller::LoadAudioDevice() {
absl::StrFormat("Failed to open audio: %s\n", SDL_GetError())); absl::StrFormat("Failed to open audio: %s\n", SDL_GetError()));
} }
audio_buffer_ = new int16_t[audio_frequency_ / 50 * 4]; audio_buffer_ = new int16_t[audio_frequency_ / 50 * 4];
master_editor_.emulator().set_audio_buffer(audio_buffer_); editor_manager_.emulator().set_audio_buffer(audio_buffer_);
SDL_PauseAudioDevice(audio_device_, 0); SDL_PauseAudioDevice(audio_device_, 0);
return absl::OkStatus(); return absl::OkStatus();
} }

View File

@@ -13,7 +13,7 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/core/common.h" #include "app/core/common.h"
#include "app/core/platform/renderer.h" #include "app/core/platform/renderer.h"
#include "app/editor/master_editor.h" #include "app/editor/editor_manager.h"
#include "app/editor/utils/editor.h" #include "app/editor/utils/editor.h"
#include "app/gui/icons.h" #include "app/gui/icons.h"
#include "app/gui/style.h" #include "app/gui/style.h"
@@ -47,8 +47,8 @@ class Controller : public ExperimentFlags {
absl::Status LoadFontFamilies() const; absl::Status LoadFontFamilies() const;
absl::Status LoadAudioDevice(); absl::Status LoadAudioDevice();
void SetupScreen() { master_editor_.SetupScreen(); } void SetupScreen() { editor_manager_.SetupScreen(); }
auto master_editor() -> editor::MasterEditor & { return master_editor_; } auto editor_manager() -> editor::EditorManager & { return editor_manager_; }
auto renderer() -> SDL_Renderer * { auto renderer() -> SDL_Renderer * {
return Renderer::GetInstance().renderer(); return Renderer::GetInstance().renderer();
} }
@@ -59,7 +59,7 @@ class Controller : public ExperimentFlags {
bool active_; bool active_;
Platform platform_; Platform platform_;
editor::MasterEditor master_editor_; editor::EditorManager editor_manager_;
int audio_frequency_ = 48000; int audio_frequency_ = 48000;
int16_t *audio_buffer_; int16_t *audio_buffer_;

View File

@@ -1,7 +1,7 @@
set( set(
YAZE_APP_EDITOR_SRC YAZE_APP_EDITOR_SRC
app/editor/editor_manager.cc
app/editor/dungeon/dungeon_editor.cc app/editor/dungeon/dungeon_editor.cc
app/editor/master_editor.cc
app/editor/settings_editor.cc app/editor/settings_editor.cc
app/editor/overworld/overworld_editor.cc app/editor/overworld/overworld_editor.cc
app/editor/sprite/sprite_editor.cc app/editor/sprite/sprite_editor.cc

View File

@@ -1,4 +1,4 @@
#include "master_editor.h" #include "editor_manager.h"
#include "ImGuiColorTextEdit/TextEditor.h" #include "ImGuiColorTextEdit/TextEditor.h"
#include "ImGuiFileDialog/ImGuiFileDialog.h" #include "ImGuiFileDialog/ImGuiFileDialog.h"
@@ -59,14 +59,14 @@ bool IsEditorActive(Editor* editor, std::vector<Editor*>& active_editors) {
} // namespace } // namespace
void MasterEditor::SetupScreen(std::string filename) { void EditorManager::SetupScreen(std::string filename) {
if (!filename.empty()) { if (!filename.empty()) {
PRINT_IF_ERROR(rom()->LoadFromFile(filename)); PRINT_IF_ERROR(rom()->LoadFromFile(filename));
} }
overworld_editor_.InitializeZeml(); overworld_editor_.InitializeZeml();
} }
absl::Status MasterEditor::Update() { absl::Status EditorManager::Update() {
ManageKeyboardShortcuts(); ManageKeyboardShortcuts();
DrawYazeMenu(); DrawYazeMenu();
@@ -88,7 +88,7 @@ absl::Status MasterEditor::Update() {
return absl::OkStatus(); return absl::OkStatus();
} }
void MasterEditor::ManageActiveEditors() { void EditorManager::ManageActiveEditors() {
// Show popup pane to select an editor to add // Show popup pane to select an editor to add
static bool show_add_editor = false; static bool show_add_editor = false;
if (show_add_editor) OpenPopup("AddEditor"); if (show_add_editor) OpenPopup("AddEditor");
@@ -251,7 +251,7 @@ void MasterEditor::ManageActiveEditors() {
} }
} }
void MasterEditor::ManageKeyboardShortcuts() { void EditorManager::ManageKeyboardShortcuts() {
bool ctrl_or_super = (GetIO().KeyCtrl || GetIO().KeySuper); bool ctrl_or_super = (GetIO().KeyCtrl || GetIO().KeySuper);
// If CMD + R is pressed, reload the top result of recent files // If CMD + R is pressed, reload the top result of recent files
@@ -309,7 +309,7 @@ void MasterEditor::ManageKeyboardShortcuts() {
} }
} }
void MasterEditor::DrawFileDialog() { void EditorManager::DrawFileDialog() {
gui::FileDialogPipeline("ChooseFileDlgKey", ".sfc,.smc", std::nullopt, [&]() { gui::FileDialogPipeline("ChooseFileDlgKey", ".sfc,.smc", std::nullopt, [&]() {
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName(); std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
status_ = rom()->LoadFromFile(filePathName); status_ = rom()->LoadFromFile(filePathName);
@@ -326,7 +326,7 @@ void MasterEditor::DrawFileDialog() {
}); });
} }
void MasterEditor::DrawStatusPopup() { void EditorManager::DrawStatusPopup() {
if (!status_.ok()) { if (!status_.ok()) {
show_status_ = true; show_status_ = true;
prev_status_ = status_; prev_status_ = status_;
@@ -354,7 +354,7 @@ void MasterEditor::DrawStatusPopup() {
} }
} }
void MasterEditor::DrawAboutPopup() { void EditorManager::DrawAboutPopup() {
if (about_) OpenPopup("About"); if (about_) OpenPopup("About");
if (BeginPopupModal("About", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { if (BeginPopupModal("About", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
Text("Yet Another Zelda3 Editor - v%s", core::kYazeVersion.data()); Text("Yet Another Zelda3 Editor - v%s", core::kYazeVersion.data());
@@ -371,7 +371,7 @@ void MasterEditor::DrawAboutPopup() {
} }
} }
void MasterEditor::DrawInfoPopup() { void EditorManager::DrawInfoPopup() {
if (rom_info_) OpenPopup("ROM Information"); if (rom_info_) OpenPopup("ROM Information");
if (BeginPopupModal("ROM Information", nullptr, if (BeginPopupModal("ROM Information", nullptr,
ImGuiWindowFlags_AlwaysAutoResize)) { ImGuiWindowFlags_AlwaysAutoResize)) {
@@ -387,7 +387,7 @@ void MasterEditor::DrawInfoPopup() {
} }
} }
void MasterEditor::DrawYazeMenu() { void EditorManager::DrawYazeMenu() {
static bool show_display_settings = false; static bool show_display_settings = false;
static bool show_command_line_interface = false; static bool show_command_line_interface = false;
@@ -426,7 +426,7 @@ void MasterEditor::DrawYazeMenu() {
} }
} }
void MasterEditor::OpenRomOrProject(const std::string& filename) { void EditorManager::OpenRomOrProject(const std::string& filename) {
if (absl::StrContains(filename, ".yaze")) { if (absl::StrContains(filename, ".yaze")) {
status_ = current_project_.Open(filename); status_ = current_project_.Open(filename);
if (status_.ok()) { if (status_.ok()) {
@@ -437,7 +437,7 @@ void MasterEditor::OpenRomOrProject(const std::string& filename) {
} }
} }
void MasterEditor::DrawYazeMenuBar() { void EditorManager::DrawYazeMenuBar() {
static bool save_as_menu = false; static bool save_as_menu = false;
static bool new_project_menu = false; static bool new_project_menu = false;
@@ -755,7 +755,7 @@ void MasterEditor::DrawYazeMenuBar() {
} }
} }
void MasterEditor::LoadRom() { void EditorManager::LoadRom() {
if (flags()->kNewFileDialogWrapper) { if (flags()->kNewFileDialogWrapper) {
auto file_name = FileDialogWrapper::ShowOpenFileDialog(); auto file_name = FileDialogWrapper::ShowOpenFileDialog();
PRINT_IF_ERROR(rom()->LoadFromFile(file_name)); PRINT_IF_ERROR(rom()->LoadFromFile(file_name));
@@ -769,7 +769,7 @@ void MasterEditor::LoadRom() {
} }
} }
void MasterEditor::SaveRom() { void EditorManager::SaveRom() {
if (flags()->kSaveDungeonMaps) { if (flags()->kSaveDungeonMaps) {
status_ = screen_editor_.SaveDungeonMaps(); status_ = screen_editor_.SaveDungeonMaps();
RETURN_VOID_IF_ERROR(status_); RETURN_VOID_IF_ERROR(status_);
@@ -804,7 +804,7 @@ void MasterEditor::SaveRom() {
status_ = rom()->SaveToFile(backup_rom_, save_new_auto_); status_ = rom()->SaveToFile(backup_rom_, save_new_auto_);
} }
absl::Status MasterEditor::OpenProject() { absl::Status EditorManager::OpenProject() {
RETURN_IF_ERROR(rom()->LoadFromFile(current_project_.rom_filename_)); RETURN_IF_ERROR(rom()->LoadFromFile(current_project_.rom_filename_));
if (!rom()->resource_label()->LoadLabels(current_project_.labels_filename_)) { if (!rom()->resource_label()->LoadLabels(current_project_.labels_filename_)) {

View File

@@ -1,5 +1,5 @@
#ifndef YAZE_APP_EDITOR_MASTER_EDITOR_H #ifndef YAZE_APP_EDITOR_EDITOR_MANAGER_H
#define YAZE_APP_EDITOR_MASTER_EDITOR_H #define YAZE_APP_EDITOR_EDITOR_MANAGER_H
#define IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS
@@ -39,8 +39,8 @@ namespace app {
namespace editor { namespace editor {
/** /**
* @class MasterEditor * @class EditorManager
* @brief The MasterEditor class represents the main editor for a Rom in the * @brief The EditorManager class represents the main editor for a Rom in the
* Yaze application. * Yaze application.
* *
* This class inherits from SharedRom, GfxContext, and ExperimentFlags, and * This class inherits from SharedRom, GfxContext, and ExperimentFlags, and
@@ -48,7 +48,7 @@ namespace editor {
* shutting down the editor. It also includes methods for drawing various menus * shutting down the editor. It also includes methods for drawing various menus
* and popups, saving the Rom, and managing editor-specific flags. * and popups, saving the Rom, and managing editor-specific flags.
* *
* The MasterEditor class contains instances of various editor classes such as * The EditorManager class contains instances of various editor classes such as
* AssemblyEditor, DungeonEditor, GraphicsEditor, MusicEditor, OverworldEditor, * AssemblyEditor, DungeonEditor, GraphicsEditor, MusicEditor, OverworldEditor,
* PaletteEditor, ScreenEditor, and SpriteEditor. The current_editor_ member * PaletteEditor, ScreenEditor, and SpriteEditor. The current_editor_ member
* variable points to the currently active editor in the tab view. * variable points to the currently active editor in the tab view.
@@ -56,11 +56,11 @@ namespace editor {
* @note This class assumes the presence of an SDL_Renderer object for rendering * @note This class assumes the presence of an SDL_Renderer object for rendering
* graphics. * graphics.
*/ */
class MasterEditor : public SharedRom, class EditorManager : public SharedRom,
public context::GfxContext, public context::GfxContext,
public core::ExperimentFlags { public core::ExperimentFlags {
public: public:
MasterEditor() { EditorManager() {
current_editor_ = &overworld_editor_; current_editor_ = &overworld_editor_;
active_editors_.push_back(&overworld_editor_); active_editors_.push_back(&overworld_editor_);
active_editors_.push_back(&dungeon_editor_); active_editors_.push_back(&dungeon_editor_);
@@ -133,4 +133,4 @@ class MasterEditor : public SharedRom,
} // namespace app } // namespace app
} // namespace yaze } // namespace yaze
#endif // YAZE_APP_EDITOR_MASTER_EDITOR_H #endif // YAZE_APP_EDITOR_EDITOR_MANAGER_H

View File

@@ -90,7 +90,7 @@
ImGui_ImplSDL2_InitForSDLRenderer(_controller->window(), _controller->renderer()); ImGui_ImplSDL2_InitForSDLRenderer(_controller->window(), _controller->renderer());
ImGui_ImplSDLRenderer2_Init(_controller->renderer()); ImGui_ImplSDLRenderer2_Init(_controller->renderer());
_controller->master_editor().overworld_editor().InitializeZeml(); _controller->editor_manager().overworld_editor().InitializeZeml();
if (!_controller->LoadFontFamilies().ok()) { if (!_controller->LoadFontFamilies().ok()) {
abort(); abort();
} }