refactor: Enhance Map Properties System and Overworld Configuration
- Updated MapPropertiesSystem to support area size selection for all ROM versions, introducing logic for Wide and Tall options in v3+. - Improved UI elements with tooltips and organized layouts for better user experience when configuring map sizes. - Added ConfigureMultiAreaMap method in Overworld class to manage sibling relationships and update ROM data based on area size. - Implemented safety checks for palette setting in OverworldEditor to ensure valid bitmap surfaces before applying changes. - Cleaned up related code and comments for clarity and maintainability.
This commit is contained in:
@@ -61,17 +61,42 @@ void MapPropertiesSystem::DrawSimplifiedMapSettings(
|
||||
TableNextColumn();
|
||||
static uint8_t asm_version =
|
||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||
if (asm_version != 0xFF) {
|
||||
int current_area_size =
|
||||
static_cast<int>(overworld_->overworld_map(current_map)->area_size());
|
||||
ImGui::SetNextItemWidth(kComboAreaSizeWidth);
|
||||
|
||||
// ALL ROMs support Small/Large. Only v3+ supports Wide/Tall.
|
||||
int current_area_size =
|
||||
static_cast<int>(overworld_->overworld_map(current_map)->area_size());
|
||||
ImGui::SetNextItemWidth(kComboAreaSizeWidth);
|
||||
|
||||
if (asm_version >= 3 && asm_version != 0xFF) {
|
||||
// v3+ ROM: Show all 4 area size options
|
||||
if (ImGui::Combo("##AreaSize", ¤t_area_size, kAreaSizeNames, 4)) {
|
||||
overworld_->mutable_overworld_map(current_map)
|
||||
->SetAreaSize(static_cast<zelda3::AreaSizeEnum>(current_area_size));
|
||||
RefreshOverworldMap();
|
||||
auto status = overworld_->ConfigureMultiAreaMap(
|
||||
current_map,
|
||||
static_cast<zelda3::AreaSizeEnum>(current_area_size));
|
||||
if (status.ok()) {
|
||||
RefreshSiblingMapGraphics(current_map, true);
|
||||
RefreshOverworldMap();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ImGui::Text("N/A");
|
||||
// Vanilla/v1/v2 ROM: Show only Small/Large (first 2 options)
|
||||
const char* limited_names[] = {"Small (1x1)", "Large (2x2)"};
|
||||
int limited_size = (current_area_size == 0 || current_area_size == 1) ? current_area_size : 0;
|
||||
|
||||
if (ImGui::Combo("##AreaSize", &limited_size, limited_names, 2)) {
|
||||
// limited_size is 0 (Small) or 1 (Large)
|
||||
auto size = (limited_size == 1) ? zelda3::AreaSizeEnum::LargeArea
|
||||
: zelda3::AreaSizeEnum::SmallArea;
|
||||
auto status = overworld_->ConfigureMultiAreaMap(current_map, size);
|
||||
if (status.ok()) {
|
||||
RefreshSiblingMapGraphics(current_map, true);
|
||||
RefreshOverworldMap();
|
||||
}
|
||||
}
|
||||
|
||||
if (asm_version == 0xFF || asm_version < 3) {
|
||||
HOVER_HINT("Small (1x1) and Large (2x2) maps. Wide/Tall require v3+");
|
||||
}
|
||||
}
|
||||
|
||||
TableNextColumn();
|
||||
@@ -660,32 +685,41 @@ void MapPropertiesSystem::DrawPropertiesPopup(int current_map,
|
||||
ImGui::Text(ICON_MD_ASPECT_RATIO " Area Configuration");
|
||||
ImGui::Separator();
|
||||
|
||||
// ALL ROMs support Small/Large. Only v3+ supports Wide/Tall.
|
||||
static uint8_t asm_version =
|
||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||
if (asm_version != 0xFF) {
|
||||
int current_area_size =
|
||||
static_cast<int>(overworld_->overworld_map(current_map)->area_size());
|
||||
ImGui::SetNextItemWidth(kComboAreaSizeWidth);
|
||||
|
||||
int current_area_size =
|
||||
static_cast<int>(overworld_->overworld_map(current_map)->area_size());
|
||||
ImGui::SetNextItemWidth(kComboAreaSizeWidth);
|
||||
|
||||
if (asm_version >= 3 && asm_version != 0xFF) {
|
||||
// v3+ ROM: Show all 4 area size options
|
||||
if (ImGui::Combo(ICON_MD_PHOTO_SIZE_SELECT_LARGE " Size", ¤t_area_size, kAreaSizeNames, 4)) {
|
||||
overworld_->mutable_overworld_map(current_map)
|
||||
->SetAreaSize(static_cast<zelda3::AreaSizeEnum>(current_area_size));
|
||||
RefreshOverworldMap();
|
||||
auto status = overworld_->ConfigureMultiAreaMap(
|
||||
current_map,
|
||||
static_cast<zelda3::AreaSizeEnum>(current_area_size));
|
||||
if (status.ok()) {
|
||||
RefreshSiblingMapGraphics(current_map, true);
|
||||
RefreshOverworldMap();
|
||||
}
|
||||
}
|
||||
HOVER_HINT("Map area size (1x1, 2x2, 2x1, 1x2 screens)");
|
||||
} else {
|
||||
// Vanilla ROM - show small/large map controls
|
||||
auto* map = overworld_->mutable_overworld_map(current_map);
|
||||
bool is_small = !map->is_large_map();
|
||||
if (ImGui::Checkbox(ICON_MD_CROP_SQUARE " Small Map", &is_small)) {
|
||||
if (is_small) {
|
||||
map->SetAsSmallMap();
|
||||
} else {
|
||||
// For vanilla, use default parent and quadrant values
|
||||
map->SetAsLargeMap(0, 0);
|
||||
// Vanilla/v1/v2 ROM: Show only Small/Large
|
||||
const char* limited_names[] = {"Small (1x1)", "Large (2x2)"};
|
||||
int limited_size = (current_area_size == 0 || current_area_size == 1) ? current_area_size : 0;
|
||||
|
||||
if (ImGui::Combo(ICON_MD_PHOTO_SIZE_SELECT_LARGE " Size", &limited_size, limited_names, 2)) {
|
||||
auto size = (limited_size == 1) ? zelda3::AreaSizeEnum::LargeArea
|
||||
: zelda3::AreaSizeEnum::SmallArea;
|
||||
auto status = overworld_->ConfigureMultiAreaMap(current_map, size);
|
||||
if (status.ok()) {
|
||||
RefreshSiblingMapGraphics(current_map, true);
|
||||
RefreshOverworldMap();
|
||||
}
|
||||
RefreshOverworldMap();
|
||||
}
|
||||
HOVER_HINT("Small (1x1) vs Large (2x2) map size");
|
||||
HOVER_HINT("Small (1x1) and Large (2x2) maps. Wide/Tall require v3+");
|
||||
}
|
||||
|
||||
// Visual Effects Section
|
||||
@@ -922,22 +956,49 @@ void MapPropertiesSystem::DrawCustomFeaturesTab(int current_map) {
|
||||
TableNextColumn();
|
||||
ImGui::Text(ICON_MD_PHOTO_SIZE_SELECT_LARGE " Area Size");
|
||||
TableNextColumn();
|
||||
static const char* area_size_names[] = {"Small (1x1)", "Large (2x2)",
|
||||
"Wide (2x1)", "Tall (1x2)"};
|
||||
// ALL ROMs support Small/Large. Only v3+ supports Wide/Tall.
|
||||
static uint8_t asm_version =
|
||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||
|
||||
int current_area_size =
|
||||
static_cast<int>(overworld_->overworld_map(current_map)->area_size());
|
||||
ImGui::SetNextItemWidth(130.f);
|
||||
if (ImGui::Combo("##AreaSize", ¤t_area_size, area_size_names, 4)) {
|
||||
overworld_->mutable_overworld_map(current_map)
|
||||
->SetAreaSize(static_cast<zelda3::AreaSizeEnum>(current_area_size));
|
||||
RefreshOverworldMap();
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("Map size in screens (ZSCustomOverworld feature)");
|
||||
|
||||
if (asm_version >= 3 && asm_version != 0xFF) {
|
||||
// v3+ ROM: Show all 4 area size options
|
||||
static const char* all_sizes[] = {"Small (1x1)", "Large (2x2)",
|
||||
"Wide (2x1)", "Tall (1x2)"};
|
||||
if (ImGui::Combo("##AreaSize", ¤t_area_size, all_sizes, 4)) {
|
||||
auto status = overworld_->ConfigureMultiAreaMap(
|
||||
current_map,
|
||||
static_cast<zelda3::AreaSizeEnum>(current_area_size));
|
||||
if (status.ok()) {
|
||||
RefreshSiblingMapGraphics(current_map, true);
|
||||
RefreshOverworldMap();
|
||||
}
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("Map size: Small (1x1), Large (2x2), Wide (2x1), Tall (1x2)");
|
||||
}
|
||||
} else {
|
||||
// Vanilla/v1/v2 ROM: Show only Small/Large
|
||||
static const char* limited_sizes[] = {"Small (1x1)", "Large (2x2)"};
|
||||
int limited_size = (current_area_size == 0 || current_area_size == 1) ? current_area_size : 0;
|
||||
|
||||
if (ImGui::Combo("##AreaSize", &limited_size, limited_sizes, 2)) {
|
||||
auto size = (limited_size == 1) ? zelda3::AreaSizeEnum::LargeArea
|
||||
: zelda3::AreaSizeEnum::SmallArea;
|
||||
auto status = overworld_->ConfigureMultiAreaMap(current_map, size);
|
||||
if (status.ok()) {
|
||||
RefreshSiblingMapGraphics(current_map, true);
|
||||
RefreshOverworldMap();
|
||||
}
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("Map size: Small (1x1), Large (2x2). Wide/Tall require v3+");
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t asm_version =
|
||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||
if (asm_version >= 2) {
|
||||
TableNextColumn();
|
||||
ImGui::Text(ICON_MD_COLOR_LENS " Main Palette");
|
||||
|
||||
@@ -1741,8 +1741,11 @@ void OverworldEditor::RefreshMultiAreaMapsSafely(int map_index,
|
||||
overworld_.GetMapTiles(current_world_));
|
||||
if (status.ok()) {
|
||||
maps_bmp_[sibling].set_data(sibling_map->bitmap_data());
|
||||
maps_bmp_[sibling].SetPalette(
|
||||
overworld_.current_area_palette());
|
||||
|
||||
// SAFETY: Only set palette if bitmap has a valid surface
|
||||
if (maps_bmp_[sibling].is_active() && maps_bmp_[sibling].surface()) {
|
||||
maps_bmp_[sibling].SetPalette(overworld_.current_area_palette());
|
||||
}
|
||||
maps_bmp_[sibling].set_modified(false);
|
||||
|
||||
// Update texture if it exists
|
||||
@@ -1836,10 +1839,18 @@ absl::Status OverworldEditor::RefreshMapPalette() {
|
||||
sibling_index += 6;
|
||||
RETURN_IF_ERROR(
|
||||
overworld_.mutable_overworld_map(sibling_index)->LoadPalette());
|
||||
maps_bmp_[sibling_index].SetPalette(current_map_palette);
|
||||
|
||||
// SAFETY: Only set palette if bitmap has a valid surface
|
||||
if (maps_bmp_[sibling_index].is_active() && maps_bmp_[sibling_index].surface()) {
|
||||
maps_bmp_[sibling_index].SetPalette(current_map_palette);
|
||||
}
|
||||
}
|
||||
}
|
||||
maps_bmp_[current_map_].SetPalette(current_map_palette);
|
||||
|
||||
// SAFETY: Only set palette if bitmap has a valid surface
|
||||
if (maps_bmp_[current_map_].is_active() && maps_bmp_[current_map_].surface()) {
|
||||
maps_bmp_[current_map_].SetPalette(current_map_palette);
|
||||
}
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
|
||||
@@ -337,9 +337,6 @@ class OverworldEditor : public Editor, public gfx::GfxContext {
|
||||
gui::Canvas properties_canvas_;
|
||||
gui::Canvas scratch_canvas_{"ScratchSpace", ImVec2(320, 480), gui::CanvasGridSize::k32x32};
|
||||
|
||||
gui::Table map_settings_table_{kOWMapTable.data(), 8, kOWMapFlags,
|
||||
ImVec2(0, 0)};
|
||||
|
||||
absl::Status status_;
|
||||
};
|
||||
} // namespace editor
|
||||
|
||||
@@ -13,12 +13,12 @@ namespace editor {
|
||||
|
||||
using namespace ImGui;
|
||||
|
||||
// Entity colors - these could be theme-dependent in the future
|
||||
// Entity colors - solid with good visibility
|
||||
namespace {
|
||||
ImVec4 GetEntranceColor() { return ImVec4(0.0f, 1.0f, 0.0f, 0.5f); } // Green
|
||||
ImVec4 GetExitColor() { return ImVec4(1.0f, 0.0f, 0.0f, 0.5f); } // Red
|
||||
ImVec4 GetItemColor() { return ImVec4(1.0f, 1.0f, 0.0f, 0.5f); } // Yellow
|
||||
ImVec4 GetSpriteColor() { return ImVec4(1.0f, 0.5f, 0.0f, 0.5f); } // Orange
|
||||
ImVec4 GetEntranceColor() { return ImVec4(0.0f, 255.0f, 0.0f, 255.0f); } // Solid green
|
||||
ImVec4 GetExitColor() { return ImVec4(255.0f, 0.0f, 0.0f, 255.0f); } // Solid red
|
||||
ImVec4 GetItemColor() { return ImVec4(255.0f, 255.0f, 0.0f, 255.0f); } // Solid yellow
|
||||
ImVec4 GetSpriteColor() { return ImVec4(255.0f, 128.0f, 0.0f, 255.0f); } // Solid orange
|
||||
} // namespace
|
||||
|
||||
void OverworldEntityRenderer::DrawEntrances(ImVec2 canvas_p0, ImVec2 scrolling,
|
||||
|
||||
Reference in New Issue
Block a user