Add Rom dependency injection to OverworldEditor
This commit is contained in:
@@ -48,12 +48,11 @@ bool IsEditorActive(Editor *editor, std::vector<Editor *> &active_editors) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void EditorManager::SetupScreen(std::string filename) {
|
void EditorManager::Initialize(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_.Initialize();
|
||||||
InitializeCommands();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status EditorManager::Update() {
|
absl::Status EditorManager::Update() {
|
||||||
@@ -298,11 +297,6 @@ void EditorManager::ManageKeyboardShortcuts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::InitializeCommands() {
|
|
||||||
editor_context_.command_manager.RegisterPrefix("window", 'w',
|
|
||||||
"window management", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorManager::DrawStatusPopup() {
|
void EditorManager::DrawStatusPopup() {
|
||||||
static absl::Status prev_status;
|
static absl::Status prev_status;
|
||||||
if (!status_.ok()) {
|
if (!status_.ok()) {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
|
|||||||
active_editors_.push_back(&screen_editor_);
|
active_editors_.push_back(&screen_editor_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupScreen(std::string filename = "");
|
void Initialize(std::string filename = "");
|
||||||
absl::Status Update();
|
absl::Status Update();
|
||||||
|
|
||||||
auto emulator() -> emu::Emulator & { return emulator_; }
|
auto emulator() -> emu::Emulator & { return emulator_; }
|
||||||
@@ -56,7 +56,6 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
|
|||||||
private:
|
private:
|
||||||
void ManageActiveEditors();
|
void ManageActiveEditors();
|
||||||
void ManageKeyboardShortcuts();
|
void ManageKeyboardShortcuts();
|
||||||
void InitializeCommands();
|
|
||||||
|
|
||||||
void DrawStatusPopup();
|
void DrawStatusPopup();
|
||||||
void DrawAboutPopup();
|
void DrawAboutPopup();
|
||||||
@@ -91,7 +90,7 @@ class EditorManager : public SharedRom, public core::ExperimentFlags {
|
|||||||
DungeonEditor dungeon_editor_;
|
DungeonEditor dungeon_editor_;
|
||||||
GraphicsEditor graphics_editor_;
|
GraphicsEditor graphics_editor_;
|
||||||
MusicEditor music_editor_;
|
MusicEditor music_editor_;
|
||||||
OverworldEditor overworld_editor_;
|
OverworldEditor overworld_editor_{*rom()};
|
||||||
PaletteEditor palette_editor_;
|
PaletteEditor palette_editor_;
|
||||||
ScreenEditor screen_editor_;
|
ScreenEditor screen_editor_;
|
||||||
SpriteEditor sprite_editor_;
|
SpriteEditor sprite_editor_;
|
||||||
|
|||||||
@@ -58,12 +58,11 @@ constexpr int kTile16Size = 0x10;
|
|||||||
|
|
||||||
absl::Status OverworldEditor::Update() {
|
absl::Status OverworldEditor::Update() {
|
||||||
status_ = absl::OkStatus();
|
status_ = absl::OkStatus();
|
||||||
if (rom()->is_loaded() && !all_gfx_loaded_) {
|
if (rom_.is_loaded() && !all_gfx_loaded_) {
|
||||||
RETURN_IF_ERROR(tile16_editor_.InitBlockset(
|
RETURN_IF_ERROR(tile16_editor_.InitBlockset(
|
||||||
tile16_blockset_bmp_, current_gfx_bmp_, tile16_individual_,
|
tile16_blockset_bmp_, current_gfx_bmp_, tile16_individual_,
|
||||||
*overworld_.mutable_all_tiles_types()));
|
*overworld_.mutable_all_tiles_types()));
|
||||||
ASSIGN_OR_RETURN(entrance_tiletypes_,
|
ASSIGN_OR_RETURN(entrance_tiletypes_, zelda3::LoadEntranceTileTypes(rom_));
|
||||||
zelda3::LoadEntranceTileTypes(*rom()));
|
|
||||||
all_gfx_loaded_ = true;
|
all_gfx_loaded_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,21 +98,17 @@ void OverworldEditor::DrawToolset() {
|
|||||||
|
|
||||||
if (toolset_table_.column_contents.empty()) {
|
if (toolset_table_.column_contents.empty()) {
|
||||||
gui::AddTableColumn(toolset_table_, "##Undo", [&]() {
|
gui::AddTableColumn(toolset_table_, "##Undo", [&]() {
|
||||||
if (Button(ICON_MD_UNDO))
|
if (Button(ICON_MD_UNDO)) status_ = Undo();
|
||||||
status_ = Undo();
|
|
||||||
});
|
});
|
||||||
gui::AddTableColumn(toolset_table_, "##Redo", [&]() {
|
gui::AddTableColumn(toolset_table_, "##Redo", [&]() {
|
||||||
if (Button(ICON_MD_REDO))
|
if (Button(ICON_MD_REDO)) status_ = Redo();
|
||||||
status_ = Redo();
|
|
||||||
});
|
});
|
||||||
gui::AddTableColumn(toolset_table_, "##Sep1", ICON_MD_MORE_VERT);
|
gui::AddTableColumn(toolset_table_, "##Sep1", ICON_MD_MORE_VERT);
|
||||||
gui::AddTableColumn(toolset_table_, "##ZoomOut", [&]() {
|
gui::AddTableColumn(toolset_table_, "##ZoomOut", [&]() {
|
||||||
if (Button(ICON_MD_ZOOM_OUT))
|
if (Button(ICON_MD_ZOOM_OUT)) ow_map_canvas_.ZoomOut();
|
||||||
ow_map_canvas_.ZoomOut();
|
|
||||||
});
|
});
|
||||||
gui::AddTableColumn(toolset_table_, "##ZoomIn", [&]() {
|
gui::AddTableColumn(toolset_table_, "##ZoomIn", [&]() {
|
||||||
if (Button(ICON_MD_ZOOM_IN))
|
if (Button(ICON_MD_ZOOM_IN)) ow_map_canvas_.ZoomIn();
|
||||||
ow_map_canvas_.ZoomIn();
|
|
||||||
});
|
});
|
||||||
gui::AddTableColumn(toolset_table_, "##Fullscreen", [&]() {
|
gui::AddTableColumn(toolset_table_, "##Fullscreen", [&]() {
|
||||||
if (Button(ICON_MD_OPEN_IN_FULL))
|
if (Button(ICON_MD_OPEN_IN_FULL))
|
||||||
@@ -168,13 +163,11 @@ void OverworldEditor::DrawToolset() {
|
|||||||
HOVER_HINT("Music");
|
HOVER_HINT("Music");
|
||||||
});
|
});
|
||||||
gui::AddTableColumn(toolset_table_, "##Tile16Editor", [&]() {
|
gui::AddTableColumn(toolset_table_, "##Tile16Editor", [&]() {
|
||||||
if (Button(ICON_MD_GRID_VIEW))
|
if (Button(ICON_MD_GRID_VIEW)) show_tile16_editor_ = !show_tile16_editor_;
|
||||||
show_tile16_editor_ = !show_tile16_editor_;
|
|
||||||
HOVER_HINT("Tile16 Editor");
|
HOVER_HINT("Tile16 Editor");
|
||||||
});
|
});
|
||||||
gui::AddTableColumn(toolset_table_, "##GfxGroupEditor", [&]() {
|
gui::AddTableColumn(toolset_table_, "##GfxGroupEditor", [&]() {
|
||||||
if (Button(ICON_MD_TABLE_CHART))
|
if (Button(ICON_MD_TABLE_CHART)) show_gfx_group = !show_gfx_group;
|
||||||
show_gfx_group = !show_gfx_group;
|
|
||||||
HOVER_HINT("Gfx Group Editor");
|
HOVER_HINT("Gfx Group Editor");
|
||||||
});
|
});
|
||||||
gui::AddTableColumn(toolset_table_, "##sep3", ICON_MD_MORE_VERT);
|
gui::AddTableColumn(toolset_table_, "##sep3", ICON_MD_MORE_VERT);
|
||||||
@@ -503,12 +496,10 @@ void OverworldEditor::CheckForOverworldEdits() {
|
|||||||
int end_x = std::floor(end.x / kTile16Size) * kTile16Size;
|
int end_x = std::floor(end.x / kTile16Size) * kTile16Size;
|
||||||
int end_y = std::floor(end.y / kTile16Size) * kTile16Size;
|
int end_y = std::floor(end.y / kTile16Size) * kTile16Size;
|
||||||
|
|
||||||
if (start_x > end_x)
|
if (start_x > end_x) std::swap(start_x, end_x);
|
||||||
std::swap(start_x, end_x);
|
if (start_y > end_y) std::swap(start_y, end_y);
|
||||||
if (start_y > end_y)
|
|
||||||
std::swap(start_y, end_y);
|
|
||||||
|
|
||||||
constexpr int local_map_size = 512; // Size of each local map
|
constexpr int local_map_size = 512; // Size of each local map
|
||||||
// Number of tiles per local map (since each tile is 16x16)
|
// Number of tiles per local map (since each tile is 16x16)
|
||||||
constexpr int tiles_per_local_map = local_map_size / kTile16Size;
|
constexpr int tiles_per_local_map = local_map_size / kTile16Size;
|
||||||
|
|
||||||
@@ -659,8 +650,7 @@ void OverworldEditor::DrawOverworldCanvas() {
|
|||||||
if (current_mode == EditingMode::DRAW_TILE) {
|
if (current_mode == EditingMode::DRAW_TILE) {
|
||||||
CheckForOverworldEdits();
|
CheckForOverworldEdits();
|
||||||
}
|
}
|
||||||
if (IsItemHovered())
|
if (IsItemHovered()) status_ = CheckForCurrentMap();
|
||||||
status_ = CheckForCurrentMap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ow_map_canvas_.DrawGrid();
|
ow_map_canvas_.DrawGrid();
|
||||||
@@ -715,7 +705,7 @@ void OverworldEditor::DrawTile8Selector() {
|
|||||||
graphics_bin_canvas_.DrawContextMenu();
|
graphics_bin_canvas_.DrawContextMenu();
|
||||||
if (all_gfx_loaded_) {
|
if (all_gfx_loaded_) {
|
||||||
int key = 0;
|
int key = 0;
|
||||||
for (auto &value : rom()->gfx_sheets()) {
|
for (auto &value : rom_.gfx_sheets()) {
|
||||||
int offset = 0x40 * (key + 1);
|
int offset = 0x40 * (key + 1);
|
||||||
int top_left_y = graphics_bin_canvas_.zero_point().y + 2;
|
int top_left_y = graphics_bin_canvas_.zero_point().y + 2;
|
||||||
if (key >= 1) {
|
if (key >= 1) {
|
||||||
@@ -1041,7 +1031,7 @@ absl::Status OverworldEditor::Save() {
|
|||||||
|
|
||||||
absl::Status OverworldEditor::LoadGraphics() {
|
absl::Status OverworldEditor::LoadGraphics() {
|
||||||
// Load the Link to the Past overworld.
|
// Load the Link to the Past overworld.
|
||||||
RETURN_IF_ERROR(overworld_.Load(*rom()))
|
RETURN_IF_ERROR(overworld_.Load(rom_))
|
||||||
palette_ = overworld_.current_area_palette();
|
palette_ = overworld_.current_area_palette();
|
||||||
|
|
||||||
// Create the area graphics image
|
// Create the area graphics image
|
||||||
@@ -1146,8 +1136,7 @@ void OverworldEditor::RefreshOverworldMap() {
|
|||||||
// We need to update the map and its siblings if it's a large map
|
// We need to update the map and its siblings if it's a large map
|
||||||
for (int i = 1; i < 4; i++) {
|
for (int i = 1; i < 4; i++) {
|
||||||
int sibling_index = overworld_.overworld_map(source_map_id)->parent() + i;
|
int sibling_index = overworld_.overworld_map(source_map_id)->parent() + i;
|
||||||
if (i >= 2)
|
if (i >= 2) sibling_index += 6;
|
||||||
sibling_index += 6;
|
|
||||||
futures.push_back(
|
futures.push_back(
|
||||||
std::async(std::launch::async, refresh_map_async, sibling_index));
|
std::async(std::launch::async, refresh_map_async, sibling_index));
|
||||||
indices[i] = sibling_index;
|
indices[i] = sibling_index;
|
||||||
@@ -1176,8 +1165,7 @@ absl::Status OverworldEditor::RefreshMapPalette() {
|
|||||||
// We need to update the map and its siblings if it's a large map
|
// We need to update the map and its siblings if it's a large map
|
||||||
for (int i = 1; i < 4; i++) {
|
for (int i = 1; i < 4; i++) {
|
||||||
int sibling_index = overworld_.overworld_map(current_map_)->parent() + i;
|
int sibling_index = overworld_.overworld_map(current_map_)->parent() + i;
|
||||||
if (i >= 2)
|
if (i >= 2) sibling_index += 6;
|
||||||
sibling_index += 6;
|
|
||||||
RETURN_IF_ERROR(
|
RETURN_IF_ERROR(
|
||||||
overworld_.mutable_overworld_map(sibling_index)->LoadPalette());
|
overworld_.mutable_overworld_map(sibling_index)->LoadPalette());
|
||||||
RETURN_IF_ERROR(
|
RETURN_IF_ERROR(
|
||||||
@@ -1378,7 +1366,7 @@ absl::Status OverworldEditor::UpdateUsageStats() {
|
|||||||
if (BeginChild("UnusedSpritesetScroll", ImVec2(0, 0), true,
|
if (BeginChild("UnusedSpritesetScroll", ImVec2(0, 0), true,
|
||||||
ImGuiWindowFlags_HorizontalScrollbar)) {
|
ImGuiWindowFlags_HorizontalScrollbar)) {
|
||||||
for (int i = 0; i < 0x81; i++) {
|
for (int i = 0; i < 0x81; i++) {
|
||||||
auto entrance_name = rom()->resource_label()->GetLabel(
|
auto entrance_name = rom_.resource_label()->GetLabel(
|
||||||
"Dungeon Entrance Names", core::HexByte(i));
|
"Dungeon Entrance Names", core::HexByte(i));
|
||||||
std::string str = absl::StrFormat("%#x - %s", i, entrance_name);
|
std::string str = absl::StrFormat("%#x - %s", i, entrance_name);
|
||||||
if (Selectable(str.c_str(), selected_entrance_ == i,
|
if (Selectable(str.c_str(), selected_entrance_ == i,
|
||||||
@@ -1420,7 +1408,7 @@ void OverworldEditor::DrawUsageGrid() {
|
|||||||
int totalSquares = 128;
|
int totalSquares = 128;
|
||||||
int squaresWide = 8;
|
int squaresWide = 8;
|
||||||
int squaresTall = (totalSquares + squaresWide - 1) /
|
int squaresTall = (totalSquares + squaresWide - 1) /
|
||||||
squaresWide; // Ceiling of totalSquares/squaresWide
|
squaresWide; // Ceiling of totalSquares/squaresWide
|
||||||
|
|
||||||
// Loop through each row
|
// Loop through each row
|
||||||
for (int row = 0; row < squaresTall; ++row) {
|
for (int row = 0; row < squaresTall; ++row) {
|
||||||
@@ -1435,8 +1423,9 @@ void OverworldEditor::DrawUsageGrid() {
|
|||||||
|
|
||||||
// Set highlight color if needed
|
// Set highlight color if needed
|
||||||
if (highlight) {
|
if (highlight) {
|
||||||
PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 0.5f, 0.0f,
|
PushStyleColor(ImGuiCol_Button,
|
||||||
1.0f)); // Or any highlight color
|
ImVec4(1.0f, 0.5f, 0.0f,
|
||||||
|
1.0f)); // Or any highlight color
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a button or selectable for each square
|
// Create a button or selectable for each square
|
||||||
@@ -1492,7 +1481,7 @@ void OverworldEditor::DrawDebugWindow() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverworldEditor::InitializeZeml() {
|
void OverworldEditor::Initialize() {
|
||||||
// Load zeml string from layouts/overworld.zeml
|
// Load zeml string from layouts/overworld.zeml
|
||||||
std::string layout = gui::zeml::LoadFile("overworld.zeml");
|
std::string layout = gui::zeml::LoadFile("overworld.zeml");
|
||||||
// Parse the zeml string into a Node object
|
// Parse the zeml string into a Node object
|
||||||
@@ -1503,23 +1492,23 @@ void OverworldEditor::InitializeZeml() {
|
|||||||
gui::zeml::Bind(&*layout_node_.GetNode("OverworldTileSelector"),
|
gui::zeml::Bind(&*layout_node_.GetNode("OverworldTileSelector"),
|
||||||
[this]() { status_ = DrawTileSelector(); });
|
[this]() { status_ = DrawTileSelector(); });
|
||||||
gui::zeml::Bind(&*layout_node_.GetNode("OwUsageStats"), [this]() {
|
gui::zeml::Bind(&*layout_node_.GetNode("OwUsageStats"), [this]() {
|
||||||
if (rom()->is_loaded()) {
|
if (rom_.is_loaded()) {
|
||||||
status_ = UpdateUsageStats();
|
status_ = UpdateUsageStats();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
gui::zeml::Bind(&*layout_node_.GetNode("owToolset"),
|
gui::zeml::Bind(&*layout_node_.GetNode("owToolset"),
|
||||||
[this]() { DrawToolset(); });
|
[this]() { DrawToolset(); });
|
||||||
gui::zeml::Bind(&*layout_node_.GetNode("OwTile16Editor"), [this]() {
|
gui::zeml::Bind(&*layout_node_.GetNode("OwTile16Editor"), [this]() {
|
||||||
if (rom()->is_loaded()) {
|
if (rom_.is_loaded()) {
|
||||||
status_ = tile16_editor_.Update();
|
status_ = tile16_editor_.Update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
gui::zeml::Bind(&*layout_node_.GetNode("OwGfxGroupEditor"), [this]() {
|
gui::zeml::Bind(&*layout_node_.GetNode("OwGfxGroupEditor"), [this]() {
|
||||||
if (rom()->is_loaded()) {
|
if (rom_.is_loaded()) {
|
||||||
status_ = gfx_group_editor_.Update();
|
status_ = gfx_group_editor_.Update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace editor
|
} // namespace editor
|
||||||
} // namespace yaze
|
} // namespace yaze
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
#include "app/gfx/bitmap.h"
|
#include "app/gfx/bitmap.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gui/canvas.h"
|
#include "app/gui/canvas.h"
|
||||||
#include "app/gui/zeml.h"
|
|
||||||
#include "app/gui/input.h"
|
#include "app/gui/input.h"
|
||||||
|
#include "app/gui/zeml.h"
|
||||||
#include "app/rom.h"
|
#include "app/rom.h"
|
||||||
#include "app/zelda3/overworld/overworld.h"
|
#include "app/zelda3/overworld/overworld.h"
|
||||||
#include "imgui/imgui.h"
|
#include "imgui/imgui.h"
|
||||||
@@ -56,8 +56,6 @@ constexpr absl::string_view kTileSelectorTab = "##TileSelectorTabBar";
|
|||||||
constexpr absl::string_view kOWEditTable = "##OWEditTable";
|
constexpr absl::string_view kOWEditTable = "##OWEditTable";
|
||||||
constexpr absl::string_view kOWMapTable = "#MapSettingsTable";
|
constexpr absl::string_view kOWMapTable = "#MapSettingsTable";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class OverworldEditor
|
* @class OverworldEditor
|
||||||
* @brief Manipulates the Overworld and OverworldMap data in a Rom.
|
* @brief Manipulates the Overworld and OverworldMap data in a Rom.
|
||||||
@@ -75,13 +73,12 @@ constexpr absl::string_view kOWMapTable = "#MapSettingsTable";
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class OverworldEditor : public Editor,
|
class OverworldEditor : public Editor,
|
||||||
public SharedRom,
|
|
||||||
public gfx::GfxContext,
|
public gfx::GfxContext,
|
||||||
public core::ExperimentFlags {
|
public core::ExperimentFlags {
|
||||||
public:
|
public:
|
||||||
OverworldEditor() { type_ = EditorType::kOverworld; }
|
OverworldEditor(Rom& rom) : rom_(rom) { type_ = EditorType::kOverworld; }
|
||||||
|
|
||||||
void InitializeZeml();
|
void Initialize();
|
||||||
|
|
||||||
absl::Status Update() final;
|
absl::Status Update() final;
|
||||||
absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
|
absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
|
||||||
@@ -244,6 +241,8 @@ class OverworldEditor : public Editor,
|
|||||||
std::vector<std::vector<uint8_t>> tile8_individual_data_;
|
std::vector<std::vector<uint8_t>> tile8_individual_data_;
|
||||||
std::vector<gfx::Bitmap> tile8_individual_;
|
std::vector<gfx::Bitmap> tile8_individual_;
|
||||||
|
|
||||||
|
Rom& rom_;
|
||||||
|
|
||||||
Tile16Editor tile16_editor_;
|
Tile16Editor tile16_editor_;
|
||||||
GfxGroupEditor gfx_group_editor_;
|
GfxGroupEditor gfx_group_editor_;
|
||||||
PaletteEditor palette_editor_;
|
PaletteEditor palette_editor_;
|
||||||
@@ -283,7 +282,8 @@ class OverworldEditor : public Editor,
|
|||||||
gui::Canvas properties_canvas_;
|
gui::Canvas properties_canvas_;
|
||||||
|
|
||||||
gui::Table toolset_table_{"##ToolsetTable0", 22, kToolsetTableFlags};
|
gui::Table toolset_table_{"##ToolsetTable0", 22, kToolsetTableFlags};
|
||||||
gui::Table map_settings_table_{kOWMapTable.data(), 8, kOWMapFlags, ImVec2(0,0)};
|
gui::Table map_settings_table_{kOWMapTable.data(), 8, kOWMapFlags,
|
||||||
|
ImVec2(0, 0)};
|
||||||
|
|
||||||
gui::zeml::Node layout_node_;
|
gui::zeml::Node layout_node_;
|
||||||
absl::Status status_;
|
absl::Status status_;
|
||||||
|
|||||||
Reference in New Issue
Block a user