Add OverworldEntranceTileTypes and remove EntranceContext boiler plate

This commit is contained in:
scawful
2024-12-30 19:04:51 -05:00
parent 96095969c6
commit 19deca88ab
3 changed files with 54 additions and 45 deletions

View File

@@ -62,7 +62,8 @@ absl::Status OverworldEditor::Update() {
RETURN_IF_ERROR(tile16_editor_.InitBlockset(
tile16_blockset_bmp_, current_gfx_bmp_, tile16_individual_,
*overworld_.mutable_all_tiles_types()));
RETURN_IF_ERROR(LoadEntranceTileTypes(*rom()));
ASSIGN_OR_RETURN(entrance_tiletypes_,
zelda3::LoadEntranceTileTypes(*rom()));
all_gfx_loaded_ = true;
}
@@ -98,17 +99,21 @@ void OverworldEditor::DrawToolset() {
if (toolset_table_.column_contents.empty()) {
gui::AddTableColumn(toolset_table_, "##Undo", [&]() {
if (Button(ICON_MD_UNDO)) status_ = Undo();
if (Button(ICON_MD_UNDO))
status_ = Undo();
});
gui::AddTableColumn(toolset_table_, "##Redo", [&]() {
if (Button(ICON_MD_REDO)) status_ = Redo();
if (Button(ICON_MD_REDO))
status_ = Redo();
});
gui::AddTableColumn(toolset_table_, "##Sep1", ICON_MD_MORE_VERT);
gui::AddTableColumn(toolset_table_, "##ZoomOut", [&]() {
if (Button(ICON_MD_ZOOM_OUT)) ow_map_canvas_.ZoomOut();
if (Button(ICON_MD_ZOOM_OUT))
ow_map_canvas_.ZoomOut();
});
gui::AddTableColumn(toolset_table_, "##ZoomIn", [&]() {
if (Button(ICON_MD_ZOOM_IN)) ow_map_canvas_.ZoomIn();
if (Button(ICON_MD_ZOOM_IN))
ow_map_canvas_.ZoomIn();
});
gui::AddTableColumn(toolset_table_, "##Fullscreen", [&]() {
if (Button(ICON_MD_OPEN_IN_FULL))
@@ -163,11 +168,13 @@ void OverworldEditor::DrawToolset() {
HOVER_HINT("Music");
});
gui::AddTableColumn(toolset_table_, "##Tile16Editor", [&]() {
if (Button(ICON_MD_GRID_VIEW)) show_tile16_editor_ = !show_tile16_editor_;
if (Button(ICON_MD_GRID_VIEW))
show_tile16_editor_ = !show_tile16_editor_;
HOVER_HINT("Tile16 Editor");
});
gui::AddTableColumn(toolset_table_, "##GfxGroupEditor", [&]() {
if (Button(ICON_MD_TABLE_CHART)) show_gfx_group = !show_gfx_group;
if (Button(ICON_MD_TABLE_CHART))
show_gfx_group = !show_gfx_group;
HOVER_HINT("Gfx Group Editor");
});
gui::AddTableColumn(toolset_table_, "##sep3", ICON_MD_MORE_VERT);
@@ -496,10 +503,12 @@ void OverworldEditor::CheckForOverworldEdits() {
int end_x = std::floor(end.x / kTile16Size) * kTile16Size;
int end_y = std::floor(end.y / kTile16Size) * kTile16Size;
if (start_x > end_x) std::swap(start_x, end_x);
if (start_y > end_y) std::swap(start_y, end_y);
if (start_x > end_x)
std::swap(start_x, end_x);
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)
constexpr int tiles_per_local_map = local_map_size / kTile16Size;
@@ -650,7 +659,8 @@ void OverworldEditor::DrawOverworldCanvas() {
if (current_mode == EditingMode::DRAW_TILE) {
CheckForOverworldEdits();
}
if (IsItemHovered()) status_ = CheckForCurrentMap();
if (IsItemHovered())
status_ = CheckForCurrentMap();
}
ow_map_canvas_.DrawGrid();
@@ -1136,7 +1146,8 @@ void OverworldEditor::RefreshOverworldMap() {
// We need to update the map and its siblings if it's a large map
for (int i = 1; i < 4; i++) {
int sibling_index = overworld_.overworld_map(source_map_id)->parent() + i;
if (i >= 2) sibling_index += 6;
if (i >= 2)
sibling_index += 6;
futures.push_back(
std::async(std::launch::async, refresh_map_async, sibling_index));
indices[i] = sibling_index;
@@ -1165,7 +1176,8 @@ absl::Status OverworldEditor::RefreshMapPalette() {
// We need to update the map and its siblings if it's a large map
for (int i = 1; i < 4; i++) {
int sibling_index = overworld_.overworld_map(current_map_)->parent() + i;
if (i >= 2) sibling_index += 6;
if (i >= 2)
sibling_index += 6;
RETURN_IF_ERROR(
overworld_.mutable_overworld_map(sibling_index)->LoadPalette());
RETURN_IF_ERROR(
@@ -1408,7 +1420,7 @@ void OverworldEditor::DrawUsageGrid() {
int totalSquares = 128;
int squaresWide = 8;
int squaresTall = (totalSquares + squaresWide - 1) /
squaresWide; // Ceiling of totalSquares/squaresWide
squaresWide; // Ceiling of totalSquares/squaresWide
// Loop through each row
for (int row = 0; row < squaresTall; ++row) {
@@ -1423,9 +1435,8 @@ void OverworldEditor::DrawUsageGrid() {
// Set highlight color if needed
if (highlight) {
PushStyleColor(ImGuiCol_Button,
ImVec4(1.0f, 0.5f, 0.0f,
1.0f)); // Or any highlight color
PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 0.5f, 0.0f,
1.0f)); // Or any highlight color
}
// Create a button or selectable for each square
@@ -1510,5 +1521,5 @@ void OverworldEditor::InitializeZeml() {
});
}
} // namespace editor
} // namespace yaze
} // namespace editor
} // namespace yaze

View File

@@ -56,31 +56,7 @@ constexpr absl::string_view kTileSelectorTab = "##TileSelectorTabBar";
constexpr absl::string_view kOWEditTable = "##OWEditTable";
constexpr absl::string_view kOWMapTable = "#MapSettingsTable";
constexpr int kEntranceTileTypePtrLow = 0xDB8BF;
constexpr int kEntranceTileTypePtrHigh = 0xDB917;
constexpr int kNumEntranceTileTypes = 0x2C;
class EntranceContext {
public:
absl::Status LoadEntranceTileTypes(Rom& rom) {
int offset_low = kEntranceTileTypePtrLow;
int offset_high = kEntranceTileTypePtrHigh;
for (int i = 0; i < kNumEntranceTileTypes; i++) {
// Load entrance tile types
ASSIGN_OR_RETURN(auto value_low, rom.ReadWord(offset_low + i));
entrance_tile_types_low_.push_back(value_low);
ASSIGN_OR_RETURN(auto value_high, rom.ReadWord(offset_high + i));
entrance_tile_types_low_.push_back(value_high);
}
return absl::OkStatus();
}
private:
std::vector<uint16_t> entrance_tile_types_low_;
std::vector<uint16_t> entrance_tile_types_high_;
};
/**
* @class OverworldEditor
@@ -100,8 +76,7 @@ class EntranceContext {
*/
class OverworldEditor : public Editor,
public SharedRom,
public EntranceContext,
public GfxContext,
public gfx::GfxContext,
public core::ExperimentFlags {
public:
OverworldEditor() { type_ = EditorType::kOverworld; }
@@ -292,6 +267,7 @@ class OverworldEditor : public Editor,
zelda3::OverworldEntrance current_entrance_;
zelda3::OverworldExit current_exit_;
zelda3::OverworldItem current_item_;
zelda3::OverworldEntranceTileTypes entrance_tiletypes_;
zelda3::GameEntity* current_entity_;
zelda3::GameEntity* dragged_entity_;