Refactor editor includes and update source files for improved organization

This commit is contained in:
scawful
2024-11-18 14:05:08 -05:00
parent 9f4756a853
commit 731eb456ab
23 changed files with 165 additions and 82 deletions

View File

@@ -5,7 +5,7 @@
#include "ImGuiColorTextEdit/TextEditor.h"
#include "app/core/common.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gui/style.h"
namespace yaze {

View File

@@ -14,7 +14,7 @@
#include "app/editor/music/music_editor.h"
#include "app/editor/overworld/overworld_editor.h"
#include "app/editor/sprite/sprite_editor.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/editor/utils/gfx_context.h"
#include "app/emu/emulator.h"
#include "app/gfx/snes_palette.h"

View File

@@ -1,5 +1,6 @@
#include "dungeon_editor.h"
#include "absl/container/flat_hash_map.h"
#include "app/core/platform/renderer.h"
#include "app/gfx/snes_palette.h"
#include "app/gui/canvas.h"

View File

@@ -2,9 +2,10 @@
#define YAZE_APP_EDITOR_DUNGEONEDITOR_H
#include "app/core/common.h"
#include "absl/container/flat_hash_map.h"
#include "app/editor/graphics/gfx_group_editor.h"
#include "app/editor/graphics/palette_editor.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gui/canvas.h"
#include "app/rom.h"
#include "imgui/imgui.h"

52
src/app/editor/editor.cc Normal file
View File

@@ -0,0 +1,52 @@
#include "editor.h"
#include "app/core/constants.h"
#include "imgui/imgui.h"
namespace yaze {
namespace app {
namespace editor {
absl::Status DrawEditor(EditorLayoutParams *params) {
if (params->editor == nullptr) {
return absl::InternalError("Editor is not initialized");
}
// Draw the editors based on h_split and v_split in a recursive manner
if (params->v_split) {
ImGui::BeginTable("##VerticalSplitTable", 2);
ImGui::TableNextColumn();
if (params->left)
RETURN_IF_ERROR(DrawEditor(params->left));
ImGui::TableNextColumn();
if (params->right)
RETURN_IF_ERROR(DrawEditor(params->right));
ImGui::EndTable();
} else if (params->h_split) {
ImGui::BeginTable("##HorizontalSplitTable", 1);
ImGui::TableNextColumn();
if (params->top)
RETURN_IF_ERROR(DrawEditor(params->top));
ImGui::TableNextColumn();
if (params->bottom)
RETURN_IF_ERROR(DrawEditor(params->bottom));
ImGui::EndTable();
} else {
// No split, just draw the single editor
ImGui::Text("%s Editor",
kEditorNames[static_cast<int>(params->editor->type())]);
RETURN_IF_ERROR(params->editor->Update());
}
return absl::OkStatus();
}
} // namespace editor
} // namespace app
} // namespace yaze

View File

@@ -1,5 +1,6 @@
set(
YAZE_APP_EDITOR_SRC
app/editor/editor.cc
app/editor/editor_manager.cc
app/editor/dungeon/dungeon_editor.cc
app/editor/overworld/overworld_editor.cc

View File

@@ -58,8 +58,32 @@ class Editor {
EditorType type_;
};
/**
* @brief Dynamic Editor Layout Parameters
*/
typedef struct EditorLayoutParams {
bool v_split;
bool h_split;
int v_split_pos;
int h_split_pos;
Editor *editor = nullptr;
EditorLayoutParams *left = nullptr;
EditorLayoutParams *right = nullptr;
EditorLayoutParams *top = nullptr;
EditorLayoutParams *bottom = nullptr;
EditorLayoutParams() {
v_split = false;
h_split = false;
v_split_pos = 0;
h_split_pos = 0;
}
} EditorLayoutParams;
absl::Status DrawEditor(EditorLayoutParams *params);
} // namespace editor
} // namespace app
} // namespace yaze
#endif // YAZE_APP_CORE_EDITOR_H
#endif // YAZE_APP_CORE_EDITOR_H

View File

@@ -22,7 +22,6 @@
#include "app/emu/emulator.h"
#include "app/gui/input.h"
#include "app/rom.h"
#include "imgui/imgui.h"
#include "yaze.h"
namespace yaze {
@@ -57,6 +56,7 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
active_editors_.push_back(&palette_editor_);
active_editors_.push_back(&sprite_editor_);
active_editors_.push_back(&message_editor_);
active_editors_.push_back(&screen_editor_);
}
void SetupScreen(std::string filename = "");

View File

@@ -1,7 +1,6 @@
#include "gfx_group_editor.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"

View File

@@ -1,20 +1,10 @@
#ifndef YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H
#define YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H
#include <cmath>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "app/editor/utils/editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"
#include "app/gui/canvas.h"
#include "app/gui/icons.h"
#include "app/gui/style.h"
#include "app/rom.h"
#include "app/zelda3/overworld/overworld.h"
#include "imgui/imgui.h"
namespace yaze {
namespace app {
@@ -55,4 +45,4 @@ class GfxGroupEditor : public SharedRom {
} // namespace editor
} // namespace app
} // namespace yaze
#endif // YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H
#endif // YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H

View File

@@ -3,7 +3,7 @@
#include "absl/status/status.h"
#include "app/editor/graphics/palette_editor.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_tile.h"
#include "app/gui/modules/asset_browser.h"

View File

@@ -1,12 +1,15 @@
#ifndef YAZE_APP_EDITOR_PALETTE_EDITOR_H
#define YAZE_APP_EDITOR_PALETTE_EDITOR_H
#include <deque>
#include <string>
#include <vector>
#include "absl/status/status.h"
#include "app/editor/graphics/gfx_group_editor.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gfx/snes_palette.h"
#include "app/gui/canvas.h"
#include "app/gui/icons.h"
#include "app/gfx/snes_color.h"
#include "app/rom.h"
#include "imgui/imgui.h"
@@ -120,4 +123,4 @@ class PaletteEditor : public SharedRom, public Editor {
} // namespace app
} // namespace yaze
#endif
#endif

View File

@@ -4,7 +4,7 @@
#include <array>
#include "absl/status/status.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/tilesheet.h"
@@ -33,7 +33,7 @@ namespace editor {
* The class inherits from the SharedRom class.
*/
class ScreenEditor : public SharedRom, public Editor {
public:
public:
ScreenEditor() {
screen_canvas_.SetCanvasSize(ImVec2(512, 512));
type_ = EditorType::kScreen;
@@ -50,7 +50,7 @@ class ScreenEditor : public SharedRom, public Editor {
absl::Status SaveDungeonMaps();
private:
private:
void DrawTitleScreenEditor();
void DrawNamingScreenEditor();
void DrawOverworldMapEditor();
@@ -60,7 +60,7 @@ class ScreenEditor : public SharedRom, public Editor {
void DrawInventoryToolset();
absl::Status LoadDungeonMaps();
absl::Status LoadDungeonMapTile16(const std::vector<uint8_t>& gfx_data,
absl::Status LoadDungeonMapTile16(const std::vector<uint8_t> &gfx_data,
bool bin_mode = false);
absl::Status SaveDungeonMapTile16();
void DrawDungeonMapsTabs();
@@ -68,6 +68,10 @@ class ScreenEditor : public SharedRom, public Editor {
void LoadBinaryGfx();
enum class EditingMode { DRAW, EDIT };
EditingMode current_mode_ = EditingMode::DRAW;
bool dungeon_maps_loaded_ = false;
bool binary_gfx_loaded_ = false;
@@ -75,6 +79,7 @@ class ScreenEditor : public SharedRom, public Editor {
uint8_t boss_room = 0;
int selected_tile16_ = 0;
int selected_tile8_ = 0;
int selected_dungeon = 0;
int floor_number = 1;
@@ -98,13 +103,15 @@ class ScreenEditor : public SharedRom, public Editor {
gui::Canvas current_tile_canvas_{"##CurrentTileCanvas"};
gui::Canvas screen_canvas_;
gui::Canvas tilesheet_canvas_;
gui::Canvas tilemap_canvas_;
gui::Canvas tilemap_canvas_{"##TilemapCanvas",
ImVec2(128 + 2, (192) + 4),
gui::CanvasGridSize::k8x8, 2.f};
zelda3::screen::Inventory inventory_;
};
} // namespace editor
} // namespace app
} // namespace yaze
} // namespace editor
} // namespace app
} // namespace yaze
#endif

View File

@@ -7,7 +7,7 @@
#include "absl/status/statusor.h"
#include "app/core/platform/renderer.h"
#include "app/editor/graphics/palette_editor.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"

View File

@@ -6,7 +6,7 @@
#include "absl/status/status.h"
#include "app/editor/message/message_data.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gfx/bitmap.h"
#include "app/gui/canvas.h"
#include "app/rom.h"

View File

@@ -3,7 +3,7 @@
#include "absl/strings/str_format.h"
#include "app/editor/code/assembly_editor.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gui/canvas.h"
#include "app/gui/icons.h"
#include "app/gui/input.h"

View File

@@ -12,7 +12,7 @@
#include "app/editor/graphics/palette_editor.h"
#include "app/editor/graphics/tile16_editor.h"
#include "app/editor/overworld/entity.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/editor/utils/gfx_context.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"

View File

@@ -3,7 +3,7 @@
#include "absl/status/status.h"
#include "app/editor/sprite/zsprite.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gui/canvas.h"
#include "app/rom.h"

View File

@@ -4,7 +4,7 @@
#include "imgui/imgui.h"
#include "absl/status/status.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
namespace yaze {
namespace app {

View File

@@ -5,7 +5,7 @@
#include <cmath>
#include "app/editor/graphics/palette_editor.h"
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"

View File

@@ -6,7 +6,7 @@
#include <cmath>
#include <vector>
#include "app/editor/utils/editor.h"
#include "app/editor/editor.h"
#include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h"