Refactor editor classes to accept a ROM pointer in constructors, enhancing dependency management and initialization across all editor types.
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "app/editor/editor.h"
|
#include "app/editor/editor.h"
|
||||||
#include "app/gui/modules/text_editor.h"
|
#include "app/gui/modules/text_editor.h"
|
||||||
#include "app/gui/style.h"
|
#include "app/gui/style.h"
|
||||||
|
#include "app/rom.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
namespace editor {
|
namespace editor {
|
||||||
@@ -22,7 +23,7 @@ struct FolderItem {
|
|||||||
*/
|
*/
|
||||||
class AssemblyEditor : public Editor {
|
class AssemblyEditor : public Editor {
|
||||||
public:
|
public:
|
||||||
AssemblyEditor() {
|
explicit AssemblyEditor(Rom* rom = nullptr) : rom_(rom) {
|
||||||
text_editor_.SetLanguageDefinition(gui::GetAssemblyLanguageDef());
|
text_editor_.SetLanguageDefinition(gui::GetAssemblyLanguageDef());
|
||||||
text_editor_.SetPalette(TextEditor::GetDarkPalette());
|
text_editor_.SetPalette(TextEditor::GetDarkPalette());
|
||||||
text_editor_.SetShowWhitespaces(false);
|
text_editor_.SetShowWhitespaces(false);
|
||||||
@@ -54,6 +55,12 @@ class AssemblyEditor : public Editor {
|
|||||||
|
|
||||||
void OpenFolder(const std::string &folder_path);
|
void OpenFolder(const std::string &folder_path);
|
||||||
|
|
||||||
|
// Set the ROM pointer
|
||||||
|
void set_rom(Rom* rom) { rom_ = rom; }
|
||||||
|
|
||||||
|
// Get the ROM pointer
|
||||||
|
Rom* rom() const { return rom_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DrawFileMenu();
|
void DrawFileMenu();
|
||||||
void DrawEditMenu();
|
void DrawEditMenu();
|
||||||
@@ -71,6 +78,8 @@ class AssemblyEditor : public Editor {
|
|||||||
std::string current_file_;
|
std::string current_file_;
|
||||||
FolderItem current_folder_;
|
FolderItem current_folder_;
|
||||||
TextEditor text_editor_;
|
TextEditor text_editor_;
|
||||||
|
|
||||||
|
Rom* rom_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
#define YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H
|
#define YAZE_APP_EDITOR_CODE_MEMORY_EDITOR_H
|
||||||
|
|
||||||
#include "app/core/platform/file_dialog.h"
|
#include "app/core/platform/file_dialog.h"
|
||||||
#include "app/editor/code/memory_editor.h"
|
|
||||||
#include "app/gui/input.h"
|
#include "app/gui/input.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
@@ -15,7 +14,9 @@ namespace editor {
|
|||||||
using ImGui::SameLine;
|
using ImGui::SameLine;
|
||||||
using ImGui::Text;
|
using ImGui::Text;
|
||||||
|
|
||||||
struct MemoryEditorWithDiffChecker : public SharedRom {
|
struct MemoryEditorWithDiffChecker {
|
||||||
|
explicit MemoryEditorWithDiffChecker(Rom* rom = nullptr) : rom_(rom) {}
|
||||||
|
|
||||||
void Update(bool &show_memory_editor) {
|
void Update(bool &show_memory_editor) {
|
||||||
static MemoryEditor mem_edit;
|
static MemoryEditor mem_edit;
|
||||||
static MemoryEditor comp_edit;
|
static MemoryEditor comp_edit;
|
||||||
@@ -56,6 +57,15 @@ struct MemoryEditorWithDiffChecker : public SharedRom {
|
|||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the ROM pointer
|
||||||
|
void set_rom(Rom* rom) { rom_ = rom; }
|
||||||
|
|
||||||
|
// Get the ROM pointer
|
||||||
|
Rom* rom() const { return rom_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Rom* rom_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
|
|||||||
@@ -38,9 +38,11 @@ constexpr ImGuiTableFlags kDungeonTableFlags =
|
|||||||
* tile selector, and object renderer. Additionally, it handles loading room
|
* tile selector, and object renderer. Additionally, it handles loading room
|
||||||
* entrances, calculating usage statistics, and rendering set usage.
|
* entrances, calculating usage statistics, and rendering set usage.
|
||||||
*/
|
*/
|
||||||
class DungeonEditor : public Editor, public SharedRom {
|
class DungeonEditor : public Editor {
|
||||||
public:
|
public:
|
||||||
DungeonEditor() { type_ = EditorType::kDungeon; }
|
explicit DungeonEditor(Rom* rom = nullptr) : rom_(rom) {
|
||||||
|
type_ = EditorType::kDungeon;
|
||||||
|
}
|
||||||
|
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
absl::Status Load() override;
|
absl::Status Load() override;
|
||||||
@@ -55,6 +57,12 @@ class DungeonEditor : public Editor, public SharedRom {
|
|||||||
|
|
||||||
void add_room(int i) { active_rooms_.push_back(i); }
|
void add_room(int i) { active_rooms_.push_back(i); }
|
||||||
|
|
||||||
|
// Set the ROM pointer
|
||||||
|
void set_rom(Rom* rom) { rom_ = rom; }
|
||||||
|
|
||||||
|
// Get the ROM pointer
|
||||||
|
Rom* rom() const { return rom_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
absl::Status RefreshGraphics();
|
absl::Status RefreshGraphics();
|
||||||
|
|
||||||
@@ -138,6 +146,8 @@ class DungeonEditor : public Editor, public SharedRom {
|
|||||||
std::unordered_map<int, ImVec4> room_palette_;
|
std::unordered_map<int, ImVec4> room_palette_;
|
||||||
|
|
||||||
absl::Status status_;
|
absl::Status status_;
|
||||||
|
|
||||||
|
Rom* rom_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
|
|||||||
@@ -112,17 +112,17 @@ class EditorManager {
|
|||||||
class EditorSet {
|
class EditorSet {
|
||||||
public:
|
public:
|
||||||
explicit EditorSet(Rom* rom)
|
explicit EditorSet(Rom* rom)
|
||||||
: assembly_editor_(),
|
: assembly_editor_(rom),
|
||||||
dungeon_editor_(),
|
dungeon_editor_(rom),
|
||||||
graphics_editor_(),
|
graphics_editor_(rom),
|
||||||
music_editor_(),
|
music_editor_(rom),
|
||||||
overworld_editor_(*rom),
|
overworld_editor_(*rom),
|
||||||
palette_editor_(),
|
palette_editor_(rom),
|
||||||
screen_editor_(),
|
screen_editor_(rom),
|
||||||
sprite_editor_(),
|
sprite_editor_(rom),
|
||||||
settings_editor_(),
|
settings_editor_(rom),
|
||||||
message_editor_(),
|
message_editor_(rom),
|
||||||
memory_editor_() {
|
memory_editor_(rom) {
|
||||||
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_,
|
||||||
&music_editor_, &screen_editor_, &settings_editor_,
|
&music_editor_, &screen_editor_, &settings_editor_,
|
||||||
|
|||||||
@@ -54,20 +54,28 @@ const std::string kSuperDonkeySprites[] = {
|
|||||||
* drawing toolsets, palette controls, clipboard imports, experimental features,
|
* drawing toolsets, palette controls, clipboard imports, experimental features,
|
||||||
* and memory editor.
|
* and memory editor.
|
||||||
*/
|
*/
|
||||||
class GraphicsEditor : public SharedRom, public Editor {
|
class GraphicsEditor : public Editor {
|
||||||
public:
|
public:
|
||||||
GraphicsEditor() { type_ = EditorType::kGraphics; }
|
explicit GraphicsEditor(Rom* rom = nullptr) : rom_(rom) {
|
||||||
|
type_ = EditorType::kGraphics;
|
||||||
|
}
|
||||||
|
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
absl::Status Load() override;
|
absl::Status Load() override;
|
||||||
|
absl::Status Save() override { return absl::UnimplementedError("Save"); }
|
||||||
absl::Status Update() override;
|
absl::Status Update() override;
|
||||||
absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
|
|
||||||
absl::Status Redo() override { return absl::UnimplementedError("Redo"); }
|
|
||||||
absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
|
absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
|
||||||
absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
|
absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
|
||||||
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
|
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
|
||||||
|
absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
|
||||||
|
absl::Status Redo() override { return absl::UnimplementedError("Redo"); }
|
||||||
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
||||||
absl::Status Save() override { return absl::UnimplementedError("Save"); }
|
|
||||||
|
// Set the ROM pointer
|
||||||
|
void set_rom(Rom* rom) { rom_ = rom; }
|
||||||
|
|
||||||
|
// Get the ROM pointer
|
||||||
|
Rom* rom() const { return rom_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class GfxEditMode {
|
enum class GfxEditMode {
|
||||||
@@ -195,6 +203,8 @@ class GraphicsEditor : public SharedRom, public Editor {
|
|||||||
ImVec2(gfx::kTilesheetWidth * 4, gfx::kTilesheetHeight * 0x10 * 4),
|
ImVec2(gfx::kTilesheetWidth * 4, gfx::kTilesheetHeight * 0x10 * 4),
|
||||||
gui::CanvasGridSize::k16x16};
|
gui::CanvasGridSize::k16x16};
|
||||||
absl::Status status_;
|
absl::Status status_;
|
||||||
|
|
||||||
|
Rom* rom_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
|
|||||||
@@ -77,9 +77,9 @@ absl::Status DisplayPalette(gfx::SnesPalette& palette, bool loaded);
|
|||||||
* @class PaletteEditor
|
* @class PaletteEditor
|
||||||
* @brief Allows the user to view and edit in game palettes.
|
* @brief Allows the user to view and edit in game palettes.
|
||||||
*/
|
*/
|
||||||
class PaletteEditor : public SharedRom, public Editor {
|
class PaletteEditor : public Editor {
|
||||||
public:
|
public:
|
||||||
PaletteEditor() {
|
explicit PaletteEditor(Rom* rom = nullptr) : rom_(rom) {
|
||||||
type_ = EditorType::kPalette;
|
type_ = EditorType::kPalette;
|
||||||
custom_palette_.push_back(gfx::SnesColor(0x7FFF));
|
custom_palette_.push_back(gfx::SnesColor(0x7FFF));
|
||||||
}
|
}
|
||||||
@@ -106,6 +106,12 @@ class PaletteEditor : public SharedRom, public Editor {
|
|||||||
|
|
||||||
void DrawModifiedColors();
|
void DrawModifiedColors();
|
||||||
|
|
||||||
|
// Set the ROM pointer
|
||||||
|
void set_rom(Rom* rom) { rom_ = rom; }
|
||||||
|
|
||||||
|
// Get the ROM pointer
|
||||||
|
Rom* rom() const { return rom_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
absl::Status HandleColorPopup(gfx::SnesPalette& palette, int i, int j, int n);
|
absl::Status HandleColorPopup(gfx::SnesPalette& palette, int i, int j, int n);
|
||||||
|
|
||||||
@@ -119,6 +125,8 @@ class PaletteEditor : public SharedRom, public Editor {
|
|||||||
ImVec4 saved_palette_[256] = {};
|
ImVec4 saved_palette_[256] = {};
|
||||||
|
|
||||||
palette_internal::PaletteEditorHistory history_;
|
palette_internal::PaletteEditorHistory history_;
|
||||||
|
|
||||||
|
Rom* rom_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
|
|||||||
@@ -28,12 +28,10 @@ namespace editor {
|
|||||||
*
|
*
|
||||||
* The screens that can be edited include the title screen, naming screen,
|
* The screens that can be edited include the title screen, naming screen,
|
||||||
* overworld map, inventory menu, and more.
|
* overworld map, inventory menu, and more.
|
||||||
*
|
|
||||||
* The class inherits from the SharedRom class.
|
|
||||||
*/
|
*/
|
||||||
class ScreenEditor : public SharedRom, public Editor {
|
class ScreenEditor : public Editor {
|
||||||
public:
|
public:
|
||||||
ScreenEditor() {
|
explicit ScreenEditor(Rom* rom = nullptr) : rom_(rom) {
|
||||||
screen_canvas_.SetCanvasSize(ImVec2(512, 512));
|
screen_canvas_.SetCanvasSize(ImVec2(512, 512));
|
||||||
type_ = EditorType::kScreen;
|
type_ = EditorType::kScreen;
|
||||||
}
|
}
|
||||||
@@ -48,10 +46,17 @@ class ScreenEditor : public SharedRom, public Editor {
|
|||||||
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
|
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
|
||||||
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
||||||
absl::Status Save() override { return absl::UnimplementedError("Save"); }
|
absl::Status Save() override { return absl::UnimplementedError("Save"); }
|
||||||
|
|
||||||
|
// Set the ROM pointer
|
||||||
|
void set_rom(Rom* rom) { rom_ = rom; }
|
||||||
|
|
||||||
|
// Get the ROM pointer
|
||||||
|
Rom* rom() const { return rom_; }
|
||||||
|
|
||||||
absl::Status SaveDungeonMaps();
|
absl::Status SaveDungeonMaps();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Rom* rom_;
|
||||||
void DrawTitleScreenEditor();
|
void DrawTitleScreenEditor();
|
||||||
void DrawNamingScreenEditor();
|
void DrawNamingScreenEditor();
|
||||||
void DrawOverworldMapEditor();
|
void DrawOverworldMapEditor();
|
||||||
|
|||||||
@@ -54,22 +54,31 @@ const ImGuiTableFlags music_editor_flags_ = ImGuiTableFlags_SizingFixedFit |
|
|||||||
* @class MusicEditor
|
* @class MusicEditor
|
||||||
* @brief A class for editing music data in a Rom.
|
* @brief A class for editing music data in a Rom.
|
||||||
*/
|
*/
|
||||||
class MusicEditor : public SharedRom, public Editor {
|
class MusicEditor : public Editor {
|
||||||
public:
|
public:
|
||||||
MusicEditor() { type_ = EditorType::kMusic; }
|
explicit MusicEditor(Rom* rom = nullptr) : rom_(rom) {
|
||||||
|
type_ = EditorType::kMusic;
|
||||||
|
}
|
||||||
|
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
absl::Status Load() override;
|
absl::Status Load() override;
|
||||||
|
absl::Status Save() override { return absl::UnimplementedError("Save"); }
|
||||||
absl::Status Update() override;
|
absl::Status Update() override;
|
||||||
absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
|
|
||||||
absl::Status Redo() override { return absl::UnimplementedError("Redo"); }
|
|
||||||
absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
|
absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
|
||||||
absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
|
absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
|
||||||
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
|
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
|
||||||
|
absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
|
||||||
|
absl::Status Redo() override { return absl::UnimplementedError("Redo"); }
|
||||||
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
||||||
absl::Status Save() override { return absl::UnimplementedError("Save"); }
|
|
||||||
|
// Set the ROM pointer
|
||||||
|
void set_rom(Rom* rom) { rom_ = rom; }
|
||||||
|
|
||||||
|
// Get the ROM pointer
|
||||||
|
Rom* rom() const { return rom_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Rom* rom_;
|
||||||
void DrawChannels();
|
void DrawChannels();
|
||||||
void DrawPianoStaff();
|
void DrawPianoStaff();
|
||||||
void DrawPianoRoll();
|
void DrawPianoRoll();
|
||||||
|
|||||||
@@ -33,9 +33,11 @@ constexpr ImGuiTableFlags kSpriteTableFlags =
|
|||||||
* This class provides functionality for updating the sprite editor, drawing the
|
* This class provides functionality for updating the sprite editor, drawing the
|
||||||
* editor table, drawing the sprite canvas, and drawing the current sheets.
|
* editor table, drawing the sprite canvas, and drawing the current sheets.
|
||||||
*/
|
*/
|
||||||
class SpriteEditor : public SharedRom, public Editor {
|
class SpriteEditor : public Editor {
|
||||||
public:
|
public:
|
||||||
SpriteEditor() { type_ = EditorType::kSprite; }
|
explicit SpriteEditor(Rom* rom = nullptr) : rom_(rom) {
|
||||||
|
type_ = EditorType::kSprite;
|
||||||
|
}
|
||||||
|
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
absl::Status Load() override;
|
absl::Status Load() override;
|
||||||
@@ -47,6 +49,12 @@ class SpriteEditor : public SharedRom, public Editor {
|
|||||||
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
|
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
|
||||||
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
||||||
absl::Status Save() override { return absl::UnimplementedError("Save"); }
|
absl::Status Save() override { return absl::UnimplementedError("Save"); }
|
||||||
|
|
||||||
|
// Set the ROM pointer
|
||||||
|
void set_rom(Rom* rom) { rom_ = rom; }
|
||||||
|
|
||||||
|
// Get the ROM pointer
|
||||||
|
Rom* rom() const { return rom_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DrawVanillaSpriteEditor();
|
void DrawVanillaSpriteEditor();
|
||||||
@@ -105,6 +113,8 @@ class SpriteEditor : public SharedRom, public Editor {
|
|||||||
std::vector<zsprite::ZSprite> custom_sprites_; /**< Sprites. */
|
std::vector<zsprite::ZSprite> custom_sprites_; /**< Sprites. */
|
||||||
|
|
||||||
absl::Status status_; /**< Status. */
|
absl::Status status_; /**< Status. */
|
||||||
|
|
||||||
|
Rom* rom_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "absl/status/status.h"
|
#include "absl/status/status.h"
|
||||||
#include "app/editor/editor.h"
|
#include "app/editor/editor.h"
|
||||||
|
#include "app/rom.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
|
|
||||||
namespace yaze {
|
namespace yaze {
|
||||||
@@ -206,19 +207,29 @@ static void ShowExampleAppPropertyEditor(bool* p_open) {
|
|||||||
|
|
||||||
class SettingsEditor : public Editor {
|
class SettingsEditor : public Editor {
|
||||||
public:
|
public:
|
||||||
SettingsEditor() : Editor() { type_ = EditorType::kSettings; }
|
explicit SettingsEditor(Rom* rom = nullptr) : rom_(rom) {
|
||||||
|
type_ = EditorType::kSettings;
|
||||||
|
}
|
||||||
|
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
absl::Status Load() override;
|
absl::Status Load() override;
|
||||||
|
absl::Status Save() override { return absl::UnimplementedError("Save"); }
|
||||||
absl::Status Update() override;
|
absl::Status Update() override;
|
||||||
absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
|
|
||||||
absl::Status Redo() override { return absl::UnimplementedError("Redo"); }
|
|
||||||
absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
|
absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
|
||||||
absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
|
absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
|
||||||
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
|
absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
|
||||||
|
absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
|
||||||
|
absl::Status Redo() override { return absl::UnimplementedError("Redo"); }
|
||||||
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
absl::Status Find() override { return absl::UnimplementedError("Find"); }
|
||||||
absl::Status Save() override { return absl::UnimplementedError("Save"); }
|
|
||||||
|
// Set the ROM pointer
|
||||||
|
void set_rom(Rom* rom) { rom_ = rom; }
|
||||||
|
|
||||||
|
// Get the ROM pointer
|
||||||
|
Rom* rom() const { return rom_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Rom* rom_;
|
||||||
void DrawGeneralSettings();
|
void DrawGeneralSettings();
|
||||||
void DrawKeyboardShortcuts();
|
void DrawKeyboardShortcuts();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user