refactor: Update ASM Version Handling in MapPropertiesSystem and OverworldEditor
- Changed static asm_version declarations to non-static to ensure fresh reads from ROM, reflecting upgrades accurately. - Improved comments to clarify the importance of reading the asm_version dynamically. - Enhanced the DrawToolset method in OverworldEditor to include a new ROM Upgrade Popup for applying ASM patches, improving user experience and functionality.
This commit is contained in:
@@ -59,8 +59,8 @@ void MapPropertiesSystem::DrawSimplifiedMapSettings(
|
|||||||
ImGui::Text("%d (0x%02X)", current_map, current_map);
|
ImGui::Text("%d (0x%02X)", current_map, current_map);
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
static uint8_t asm_version =
|
// IMPORTANT: Don't cache - read fresh to reflect ROM upgrades
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
|
|
||||||
// ALL ROMs support Small/Large. Only v3+ supports Wide/Tall.
|
// ALL ROMs support Small/Large. Only v3+ supports Wide/Tall.
|
||||||
int current_area_size =
|
int current_area_size =
|
||||||
@@ -222,7 +222,7 @@ void MapPropertiesSystem::DrawMapPropertiesPanel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Custom Overworld Features Tab
|
// Custom Overworld Features Tab
|
||||||
static uint8_t asm_version =
|
uint8_t asm_version =
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
if (asm_version != 0xFF && ImGui::BeginTabItem("Custom Features")) {
|
if (asm_version != 0xFF && ImGui::BeginTabItem("Custom Features")) {
|
||||||
DrawCustomFeaturesTab(current_map);
|
DrawCustomFeaturesTab(current_map);
|
||||||
@@ -253,7 +253,7 @@ void MapPropertiesSystem::DrawCustomBackgroundColorEditor(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t asm_version =
|
uint8_t asm_version =
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
if (asm_version < 2) {
|
if (asm_version < 2) {
|
||||||
Text("Custom background colors require ZSCustomOverworld v2+");
|
Text("Custom background colors require ZSCustomOverworld v2+");
|
||||||
@@ -308,7 +308,7 @@ void MapPropertiesSystem::DrawOverlayEditor(int current_map,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t asm_version =
|
uint8_t asm_version =
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
|
|
||||||
ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f),
|
ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f),
|
||||||
@@ -432,7 +432,7 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
|
|||||||
canvas.AddContextMenuItem(properties_item);
|
canvas.AddContextMenuItem(properties_item);
|
||||||
|
|
||||||
// Custom overworld features (only show if v3+)
|
// Custom overworld features (only show if v3+)
|
||||||
static uint8_t asm_version =
|
uint8_t asm_version =
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
if (asm_version >= 3 && asm_version != 0xFF) {
|
if (asm_version >= 3 && asm_version != 0xFF) {
|
||||||
// Custom Background Color
|
// Custom Background Color
|
||||||
@@ -518,7 +518,7 @@ void MapPropertiesSystem::DrawGraphicsPopup(int current_map, int game_state) {
|
|||||||
}
|
}
|
||||||
HOVER_HINT("Sprite graphics sheet for current game state");
|
HOVER_HINT("Sprite graphics sheet for current game state");
|
||||||
|
|
||||||
static uint8_t asm_version =
|
uint8_t asm_version =
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
if (asm_version >= 3) {
|
if (asm_version >= 3) {
|
||||||
if (gui::InputHexByte(ICON_MD_ANIMATION " Animated GFX",
|
if (gui::InputHexByte(ICON_MD_ANIMATION " Animated GFX",
|
||||||
@@ -596,8 +596,8 @@ void MapPropertiesSystem::DrawPalettesPopup(int current_map, int game_state,
|
|||||||
}
|
}
|
||||||
HOVER_HINT("Main color palette for background tiles");
|
HOVER_HINT("Main color palette for background tiles");
|
||||||
|
|
||||||
static uint8_t asm_version =
|
// Read fresh to reflect ROM upgrades
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
if (asm_version >= 2) {
|
if (asm_version >= 2) {
|
||||||
if (gui::InputHexByte(ICON_MD_COLOR_LENS " Main Palette",
|
if (gui::InputHexByte(ICON_MD_COLOR_LENS " Main Palette",
|
||||||
overworld_->mutable_overworld_map(current_map)
|
overworld_->mutable_overworld_map(current_map)
|
||||||
@@ -686,7 +686,7 @@ void MapPropertiesSystem::DrawPropertiesPopup(int current_map,
|
|||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
// ALL ROMs support Small/Large. Only v3+ supports Wide/Tall.
|
// ALL ROMs support Small/Large. Only v3+ supports Wide/Tall.
|
||||||
static uint8_t asm_version =
|
uint8_t asm_version =
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
|
|
||||||
int current_area_size =
|
int current_area_size =
|
||||||
@@ -957,7 +957,7 @@ void MapPropertiesSystem::DrawCustomFeaturesTab(int current_map) {
|
|||||||
ImGui::Text(ICON_MD_PHOTO_SIZE_SELECT_LARGE " Area Size");
|
ImGui::Text(ICON_MD_PHOTO_SIZE_SELECT_LARGE " Area Size");
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
// ALL ROMs support Small/Large. Only v3+ supports Wide/Tall.
|
// ALL ROMs support Small/Large. Only v3+ supports Wide/Tall.
|
||||||
static uint8_t asm_version =
|
uint8_t asm_version =
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
|
|
||||||
int current_area_size =
|
int current_area_size =
|
||||||
@@ -1051,7 +1051,7 @@ void MapPropertiesSystem::DrawCustomFeaturesTab(int current_map) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MapPropertiesSystem::DrawTileGraphicsTab(int current_map) {
|
void MapPropertiesSystem::DrawTileGraphicsTab(int current_map) {
|
||||||
static uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
|
|
||||||
// Only show custom tile graphics for v1+ ROMs
|
// Only show custom tile graphics for v1+ ROMs
|
||||||
if (asm_version >= 1 && asm_version != 0xFF) {
|
if (asm_version >= 1 && asm_version != 0xFF) {
|
||||||
@@ -1270,7 +1270,7 @@ void MapPropertiesSystem::RefreshSiblingMapGraphics(int map_index, bool include_
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MapPropertiesSystem::DrawMosaicControls(int current_map) {
|
void MapPropertiesSystem::DrawMosaicControls(int current_map) {
|
||||||
static uint8_t asm_version =
|
uint8_t asm_version =
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
if (asm_version >= 2) {
|
if (asm_version >= 2) {
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
@@ -1299,7 +1299,7 @@ void MapPropertiesSystem::DrawMosaicControls(int current_map) {
|
|||||||
|
|
||||||
void MapPropertiesSystem::DrawOverlayControls(int current_map,
|
void MapPropertiesSystem::DrawOverlayControls(int current_map,
|
||||||
bool& show_overlay_preview) {
|
bool& show_overlay_preview) {
|
||||||
static uint8_t asm_version =
|
uint8_t asm_version =
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
|
|
||||||
// Determine if this is a special overworld map (0x80-0x9F)
|
// Determine if this is a special overworld map (0x80-0x9F)
|
||||||
@@ -1512,7 +1512,7 @@ void MapPropertiesSystem::DrawOverlayPreviewOnMap(int current_map,
|
|||||||
uint16_t overlay_id = 0x00FF;
|
uint16_t overlay_id = 0x00FF;
|
||||||
bool has_subscreen_overlay = false;
|
bool has_subscreen_overlay = false;
|
||||||
|
|
||||||
static uint8_t asm_version =
|
uint8_t asm_version =
|
||||||
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
(*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
bool is_special_overworld_map = (current_map >= 0x80 && current_map < 0xA0);
|
bool is_special_overworld_map = (current_map >= 0x80 && current_map < 0xA0);
|
||||||
|
|
||||||
|
|||||||
@@ -272,7 +272,9 @@ void OverworldEditor::DrawFullscreenCanvas() {
|
|||||||
void OverworldEditor::DrawToolset() {
|
void OverworldEditor::DrawToolset() {
|
||||||
// Modern adaptive toolbar with inline mode switching and properties
|
// Modern adaptive toolbar with inline mode switching and properties
|
||||||
static gui::Toolset toolbar;
|
static gui::Toolset toolbar;
|
||||||
static uint8_t asm_version = 0xFF;
|
|
||||||
|
// IMPORTANT: Don't make asm_version static - it needs to update after ROM upgrade
|
||||||
|
uint8_t asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
|
|
||||||
// Don't use WidgetIdScope here - it conflicts with ImGui::Begin/End ID stack in cards
|
// Don't use WidgetIdScope here - it conflicts with ImGui::Begin/End ID stack in cards
|
||||||
// Widgets register themselves individually instead
|
// Widgets register themselves individually instead
|
||||||
@@ -317,8 +319,7 @@ void OverworldEditor::DrawToolset() {
|
|||||||
|
|
||||||
toolbar.EndModeGroup();
|
toolbar.EndModeGroup();
|
||||||
|
|
||||||
// ROM version badge
|
// ROM version badge (already read above)
|
||||||
asm_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
|
||||||
toolbar.AddRomBadge(asm_version, [this]() {
|
toolbar.AddRomBadge(asm_version, [this]() {
|
||||||
ImGui::OpenPopup("UpgradeROMVersion");
|
ImGui::OpenPopup("UpgradeROMVersion");
|
||||||
});
|
});
|
||||||
@@ -417,6 +418,46 @@ void OverworldEditor::DrawToolset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toolbar.End();
|
toolbar.End();
|
||||||
|
|
||||||
|
// ROM Upgrade Popup (rendered outside toolbar to avoid ID conflicts)
|
||||||
|
if (ImGui::BeginPopupModal("UpgradeROMVersion", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
|
||||||
|
ImGui::Text(ICON_MD_UPGRADE " Upgrade ROM to ZSCustomOverworld");
|
||||||
|
ImGui::Separator();
|
||||||
|
ImGui::TextWrapped(
|
||||||
|
"This will apply the ZSCustomOverworld ASM patch to your ROM,\n"
|
||||||
|
"enabling advanced features like custom tile graphics, animated GFX,\n"
|
||||||
|
"wide/tall areas, and more.");
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
uint8_t current_version = (*rom_)[zelda3::OverworldCustomASMHasBeenApplied];
|
||||||
|
ImGui::Text("Current Version: %s",
|
||||||
|
current_version == 0xFF ? "Vanilla" : absl::StrFormat("v%d", current_version).c_str());
|
||||||
|
|
||||||
|
static int target_version = 3;
|
||||||
|
ImGui::RadioButton("v2 (Basic features)", &target_version, 2);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::RadioButton("v3 (All features)", &target_version, 3);
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
|
if (ImGui::Button(ICON_MD_CHECK " Apply Upgrade", ImVec2(150, 0))) {
|
||||||
|
auto status = ApplyZSCustomOverworldASM(target_version);
|
||||||
|
if (status.ok()) {
|
||||||
|
// CRITICAL: Reload the editor to reflect changes
|
||||||
|
status_ = Clear();
|
||||||
|
status_ = Load();
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
} else {
|
||||||
|
LOG_ERROR("OverworldEditor", "Upgrade failed: %s", status.message().data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button(ICON_MD_CANCEL " Cancel", ImVec2(150, 0))) {
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
|
||||||
// All editor windows are now rendered in Update() using either EditorCard system
|
// All editor windows are now rendered in Update() using either EditorCard system
|
||||||
// or MapPropertiesSystem for map-specific panels. This keeps the toolset clean
|
// or MapPropertiesSystem for map-specific panels. This keeps the toolset clean
|
||||||
|
|||||||
Reference in New Issue
Block a user