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 "ImGuiColorTextEdit/TextEditor.h"
#include "app/core/common.h" #include "app/core/common.h"
#include "app/editor/utils/editor.h" #include "app/editor/editor.h"
#include "app/gui/style.h" #include "app/gui/style.h"
namespace yaze { namespace yaze {

View File

@@ -14,7 +14,7 @@
#include "app/editor/music/music_editor.h" #include "app/editor/music/music_editor.h"
#include "app/editor/overworld/overworld_editor.h" #include "app/editor/overworld/overworld_editor.h"
#include "app/editor/sprite/sprite_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/editor/utils/gfx_context.h"
#include "app/emu/emulator.h" #include "app/emu/emulator.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"

View File

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

View File

@@ -2,9 +2,10 @@
#define YAZE_APP_EDITOR_DUNGEONEDITOR_H #define YAZE_APP_EDITOR_DUNGEONEDITOR_H
#include "app/core/common.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/gfx_group_editor.h"
#include "app/editor/graphics/palette_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/gui/canvas.h"
#include "app/rom.h" #include "app/rom.h"
#include "imgui/imgui.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( set(
YAZE_APP_EDITOR_SRC YAZE_APP_EDITOR_SRC
app/editor/editor.cc
app/editor/editor_manager.cc app/editor/editor_manager.cc
app/editor/dungeon/dungeon_editor.cc app/editor/dungeon/dungeon_editor.cc
app/editor/overworld/overworld_editor.cc app/editor/overworld/overworld_editor.cc

View File

@@ -58,6 +58,30 @@ class Editor {
EditorType type_; 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 editor
} // namespace app } // namespace app
} // namespace yaze } // namespace yaze

View File

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

View File

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

View File

@@ -1,20 +1,10 @@
#ifndef YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H #ifndef YAZE_APP_EDITOR_GFX_GROUP_EDITOR_H
#define 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/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_palette.h"
#include "app/gfx/snes_tile.h"
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/gui/icons.h"
#include "app/gui/style.h"
#include "app/rom.h" #include "app/rom.h"
#include "app/zelda3/overworld/overworld.h"
#include "imgui/imgui.h"
namespace yaze { namespace yaze {
namespace app { namespace app {

View File

@@ -3,7 +3,7 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/editor/graphics/palette_editor.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/bitmap.h"
#include "app/gfx/snes_tile.h" #include "app/gfx/snes_tile.h"
#include "app/gui/modules/asset_browser.h" #include "app/gui/modules/asset_browser.h"

View File

@@ -1,12 +1,15 @@
#ifndef YAZE_APP_EDITOR_PALETTE_EDITOR_H #ifndef YAZE_APP_EDITOR_PALETTE_EDITOR_H
#define 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 "absl/status/status.h"
#include "app/editor/graphics/gfx_group_editor.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/gfx/snes_palette.h"
#include "app/gui/canvas.h" #include "app/gfx/snes_color.h"
#include "app/gui/icons.h"
#include "app/rom.h" #include "app/rom.h"
#include "imgui/imgui.h" #include "imgui/imgui.h"

View File

@@ -4,7 +4,7 @@
#include <array> #include <array>
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/editor/utils/editor.h" #include "app/editor/editor.h"
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gfx/tilesheet.h" #include "app/gfx/tilesheet.h"
@@ -68,6 +68,10 @@ class ScreenEditor : public SharedRom, public Editor {
void LoadBinaryGfx(); void LoadBinaryGfx();
enum class EditingMode { DRAW, EDIT };
EditingMode current_mode_ = EditingMode::DRAW;
bool dungeon_maps_loaded_ = false; bool dungeon_maps_loaded_ = false;
bool binary_gfx_loaded_ = false; bool binary_gfx_loaded_ = false;
@@ -75,6 +79,7 @@ class ScreenEditor : public SharedRom, public Editor {
uint8_t boss_room = 0; uint8_t boss_room = 0;
int selected_tile16_ = 0; int selected_tile16_ = 0;
int selected_tile8_ = 0;
int selected_dungeon = 0; int selected_dungeon = 0;
int floor_number = 1; int floor_number = 1;
@@ -98,7 +103,9 @@ class ScreenEditor : public SharedRom, public Editor {
gui::Canvas current_tile_canvas_{"##CurrentTileCanvas"}; gui::Canvas current_tile_canvas_{"##CurrentTileCanvas"};
gui::Canvas screen_canvas_; gui::Canvas screen_canvas_;
gui::Canvas tilesheet_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_; zelda3::screen::Inventory inventory_;
}; };

View File

@@ -7,7 +7,7 @@
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
#include "app/core/platform/renderer.h" #include "app/core/platform/renderer.h"
#include "app/editor/graphics/palette_editor.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/bitmap.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h" #include "app/gfx/snes_tile.h"

View File

@@ -6,7 +6,7 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/editor/message/message_data.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/gfx/bitmap.h"
#include "app/gui/canvas.h" #include "app/gui/canvas.h"
#include "app/rom.h" #include "app/rom.h"

View File

@@ -3,7 +3,7 @@
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "app/editor/code/assembly_editor.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/canvas.h"
#include "app/gui/icons.h" #include "app/gui/icons.h"
#include "app/gui/input.h" #include "app/gui/input.h"

View File

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

View File

@@ -3,7 +3,7 @@
#include "absl/status/status.h" #include "absl/status/status.h"
#include "app/editor/sprite/zsprite.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/gui/canvas.h"
#include "app/rom.h" #include "app/rom.h"

View File

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

View File

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

View File

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

View File

@@ -4,7 +4,6 @@
#include <string> #include <string>
#include "app/core/platform/renderer.h" #include "app/core/platform/renderer.h"
#include "app/editor/graphics/graphics_editor.h"
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gui/color.h" #include "app/gui/color.h"
#include "app/gui/input.h" #include "app/gui/input.h"
@@ -19,7 +18,6 @@ namespace gui {
using core::Renderer; using core::Renderer;
using ImGui::BeginMenu; using ImGui::BeginMenu;
using ImGui::BeginPopup;
using ImGui::EndMenu; using ImGui::EndMenu;
using ImGui::GetContentRegionAvail; using ImGui::GetContentRegionAvail;
using ImGui::GetCursorScreenPos; using ImGui::GetCursorScreenPos;
@@ -33,7 +31,6 @@ using ImGui::IsMouseDragging;
using ImGui::MenuItem; using ImGui::MenuItem;
using ImGui::OpenPopupOnItemClick; using ImGui::OpenPopupOnItemClick;
using ImGui::Selectable; using ImGui::Selectable;
using ImGui::Separator;
using ImGui::Text; using ImGui::Text;
constexpr uint32_t kBlackColor = IM_COL32(0, 0, 0, 255); constexpr uint32_t kBlackColor = IM_COL32(0, 0, 0, 255);

View File

@@ -1,7 +1,6 @@
#ifndef YAZE_GUI_CANVAS_H #ifndef YAZE_GUI_CANVAS_H
#define YAZE_GUI_CANVAS_H #define YAZE_GUI_CANVAS_H
#include <cmath>
#include <string> #include <string>
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
@@ -46,6 +45,15 @@ class Canvas : public SharedRom {
CanvasGridSize grid_size) CanvasGridSize grid_size)
: canvas_id_(id), custom_canvas_size_(true), canvas_sz_(canvas_size) { : canvas_id_(id), custom_canvas_size_(true), canvas_sz_(canvas_size) {
context_id_ = id + "Context"; context_id_ = id + "Context";
SetCanvasGridSize(grid_size);
}
explicit Canvas(const std::string &id, ImVec2 canvas_size, CanvasGridSize grid_size, float global_scale)
: canvas_id_(id), custom_canvas_size_(true), canvas_sz_(canvas_size), global_scale_(global_scale) {
context_id_ = id + "Context";
SetCanvasGridSize(grid_size);
}
void SetCanvasGridSize(CanvasGridSize grid_size) {
switch (grid_size) { switch (grid_size) {
case CanvasGridSize::k8x8: case CanvasGridSize::k8x8:
custom_step_ = 8.0f; custom_step_ = 8.0f;
@@ -125,8 +133,8 @@ class Canvas : public SharedRom {
int GetTileIdFromMousePos() { int GetTileIdFromMousePos() {
int x = mouse_pos_in_canvas_.x; int x = mouse_pos_in_canvas_.x;
int y = mouse_pos_in_canvas_.y; int y = mouse_pos_in_canvas_.y;
int num_columns = canvas_sz_.x / custom_step_; int num_columns = (canvas_sz_.x / global_scale_) / custom_step_;
int num_rows = canvas_sz_.y / custom_step_; int num_rows = (canvas_sz_.y / global_scale_) / custom_step_;
int tile_id = (x / custom_step_) + (y / custom_step_) * num_columns; int tile_id = (x / custom_step_) + (y / custom_step_) * num_columns;
if (tile_id >= num_columns * num_rows) { if (tile_id >= num_columns * num_rows) {
tile_id = -1; // Invalid tile ID tile_id = -1; // Invalid tile ID