fix(editor): update overworld exit properties and popup handling

- Changed `x_camera_` and `y_camera_` in `OverworldExit` from `uint8_t` to `uint16_t` for consistency and to accommodate larger values.
- Updated the `DrawExitEditorPopup` function to use `InputHexWord` for camera positions, reflecting the new data type.
- Added `ImGui::PushID` and `ImGui::PopID` calls in various popup functions to resolve duplicate ID warnings, enhancing the stability of the UI.

Benefits:
- Ensures proper handling of camera coordinates in the overworld editor.
- Improves UI robustness by addressing ID conflicts in popups.
This commit is contained in:
scawful
2025-10-16 21:48:50 -04:00
parent d9e793eaea
commit 95ce221709
4 changed files with 48 additions and 26 deletions

View File

@@ -192,9 +192,9 @@ bool DrawExitEditorPopup(zelda3::OverworldExit &exit) {
SameLine();
gui::InputHex("Y Position", &exit.y_);
gui::InputHexByte("X Camera", &exit.x_camera_);
gui::InputHexWord("X Camera", &exit.x_camera_);
SameLine();
gui::InputHexByte("Y Camera", &exit.y_camera_);
gui::InputHexWord("Y Camera", &exit.y_camera_);
gui::InputHexWord("X Scroll", &exit.x_scroll_);
SameLine();

View File

@@ -540,6 +540,8 @@ void MapPropertiesSystem::SetupCanvasContextMenu(
// Private method implementations
void MapPropertiesSystem::DrawGraphicsPopup(int current_map, int game_state) {
if (ImGui::BeginPopup("GraphicsPopup")) {
ImGui::PushID("GraphicsPopup"); // Fix ImGui duplicate ID warnings
// Use theme-aware spacing instead of hardcoded constants
float spacing = gui::LayoutHelpers::GetStandardSpacing();
float padding = gui::LayoutHelpers::GetButtonPadding();
@@ -639,6 +641,7 @@ void MapPropertiesSystem::DrawGraphicsPopup(int current_map, int game_state) {
}
ImGui::PopStyleVar(2); // Pop the 2 style variables we pushed
ImGui::PopID(); // Pop GraphicsPopup ID scope
ImGui::EndPopup();
}
}
@@ -646,6 +649,8 @@ void MapPropertiesSystem::DrawGraphicsPopup(int current_map, int game_state) {
void MapPropertiesSystem::DrawPalettesPopup(int current_map, int game_state,
bool& show_custom_bg_color_editor) {
if (ImGui::BeginPopup("PalettesPopup")) {
ImGui::PushID("PalettesPopup"); // Fix ImGui duplicate ID warnings
// Use theme-aware spacing instead of hardcoded constants
float spacing = gui::LayoutHelpers::GetStandardSpacing();
float padding = gui::LayoutHelpers::GetButtonPadding();
@@ -700,6 +705,7 @@ void MapPropertiesSystem::DrawPalettesPopup(int current_map, int game_state,
HOVER_HINT("Open custom background color editor (v2+)");
ImGui::PopStyleVar(2); // Pop the 2 style variables we pushed
ImGui::PopID(); // Pop PalettesPopup ID scope
ImGui::EndPopup();
}
}
@@ -709,6 +715,8 @@ void MapPropertiesSystem::DrawPropertiesPopup(int current_map,
bool& show_overlay_preview,
int& game_state) {
if (ImGui::BeginPopup("ConfigPopup")) {
ImGui::PushID("ConfigPopup"); // Fix ImGui duplicate ID warnings
// Use theme-aware spacing instead of hardcoded constants
float spacing = gui::LayoutHelpers::GetStandardSpacing();
float padding = gui::LayoutHelpers::GetButtonPadding();
@@ -811,6 +819,7 @@ void MapPropertiesSystem::DrawPropertiesPopup(int current_map,
HOVER_HINT("Open detailed area configuration with all settings tabs");
ImGui::PopStyleVar(2); // Pop the 2 style variables we pushed
ImGui::PopID(); // Pop ConfigPopup ID scope
ImGui::EndPopup();
}
}
@@ -1649,6 +1658,8 @@ void MapPropertiesSystem::DrawOverlayPreviewOnMap(int current_map,
void MapPropertiesSystem::DrawViewPopup() {
if (ImGui::BeginPopup("ViewPopup")) {
ImGui::PushID("ViewPopup"); // Fix ImGui duplicate ID warnings
// Use theme-aware spacing instead of hardcoded constants
float spacing = gui::LayoutHelpers::GetStandardSpacing();
float padding = gui::LayoutHelpers::GetButtonPadding();
@@ -1678,12 +1689,15 @@ void MapPropertiesSystem::DrawViewPopup() {
HOVER_HINT("Toggle fullscreen canvas (F11)");
ImGui::PopStyleVar(2); // Pop the 2 style variables we pushed
ImGui::PopID(); // Pop ViewPopup ID scope
ImGui::EndPopup();
}
}
void MapPropertiesSystem::DrawQuickAccessPopup() {
if (ImGui::BeginPopup("QuickPopup")) {
ImGui::PushID("QuickPopup"); // Fix ImGui duplicate ID warnings
// Use theme-aware spacing instead of hardcoded constants
float spacing = gui::LayoutHelpers::GetStandardSpacing();
float padding = gui::LayoutHelpers::GetButtonPadding();
@@ -1715,6 +1729,7 @@ void MapPropertiesSystem::DrawQuickAccessPopup() {
HOVER_HINT("Lock/unlock current map (Ctrl+L)");
ImGui::PopStyleVar(2); // Pop the 2 style variables we pushed
ImGui::PopID(); // Pop QuickPopup ID scope
ImGui::EndPopup();
}
}

View File

@@ -912,8 +912,8 @@ void OverworldEditor::RenderUpdatedMapBitmap(
current_bitmap.set_modified(true);
// Immediately update the texture to reflect changes
// TODO: Queue texture for later rendering.
// core::Renderer::Get().UpdateBitmap(&current_bitmap);
gfx::Arena::Get().QueueTextureCommand(
gfx::Arena::TextureCommandType::UPDATE, &current_bitmap);
}
void OverworldEditor::CheckForOverworldEdits() {
@@ -3012,7 +3012,7 @@ void OverworldEditor::HandleEntityInsertion(const std::string& entity_type) {
// Get mouse position from canvas (in world coordinates)
ImVec2 mouse_pos = ow_map_canvas_.hover_mouse_pos();
LOG_DEBUG("OverworldEditor", "Inserting entity type='%s' at pos=(%f,%f) map=%d",
LOG_DEBUG("OverworldEditor", "HandleEntityInsertion called: type='%s' at pos=(%.0f,%.0f) map=%d",
entity_type.c_str(), mouse_pos.x, mouse_pos.y, current_map_);
if (entity_type == "entrance") {
@@ -3022,6 +3022,7 @@ void OverworldEditor::HandleEntityInsertion(const std::string& entity_type) {
current_entity_ = *result;
ImGui::OpenPopup("Entrance Editor");
rom_->set_dirty(true);
LOG_DEBUG("OverworldEditor", "Entrance inserted successfully at map=%d", current_map_);
} else {
LOG_ERROR("OverworldEditor", "Failed to insert entrance: %s",
result.status().message().data());
@@ -3034,6 +3035,7 @@ void OverworldEditor::HandleEntityInsertion(const std::string& entity_type) {
current_entity_ = *result;
ImGui::OpenPopup("Entrance Editor");
rom_->set_dirty(true);
LOG_DEBUG("OverworldEditor", "Hole inserted successfully at map=%d", current_map_);
} else {
LOG_ERROR("OverworldEditor", "Failed to insert hole: %s",
result.status().message().data());
@@ -3046,6 +3048,7 @@ void OverworldEditor::HandleEntityInsertion(const std::string& entity_type) {
current_entity_ = *result;
ImGui::OpenPopup("Exit editor");
rom_->set_dirty(true);
LOG_DEBUG("OverworldEditor", "Exit inserted successfully at map=%d", current_map_);
} else {
LOG_ERROR("OverworldEditor", "Failed to insert exit: %s",
result.status().message().data());
@@ -3058,6 +3061,7 @@ void OverworldEditor::HandleEntityInsertion(const std::string& entity_type) {
current_entity_ = *result;
ImGui::OpenPopup("Item editor");
rom_->set_dirty(true);
LOG_DEBUG("OverworldEditor", "Item inserted successfully at map=%d", current_map_);
} else {
LOG_ERROR("OverworldEditor", "Failed to insert item: %s",
result.status().message().data());
@@ -3070,6 +3074,7 @@ void OverworldEditor::HandleEntityInsertion(const std::string& entity_type) {
current_entity_ = *result;
ImGui::OpenPopup("Sprite editor");
rom_->set_dirty(true);
LOG_DEBUG("OverworldEditor", "Sprite inserted successfully at map=%d", current_map_);
} else {
LOG_ERROR("OverworldEditor", "Failed to insert sprite: %s",
result.status().message().data());

View File

@@ -43,10 +43,10 @@ class OverworldExit : public GameEntity {
public:
uint16_t y_scroll_;
uint16_t x_scroll_;
uint8_t y_player_;
uint8_t x_player_;
uint8_t y_camera_;
uint8_t x_camera_;
uint16_t y_player_; // CRITICAL: Changed from uint8_t to uint16_t (0-4088 range)
uint16_t x_player_; // CRITICAL: Changed from uint8_t to uint16_t (0-4088 range)
uint16_t y_camera_; // Changed from uint8_t to uint16_t for consistency
uint16_t x_camera_; // Changed from uint8_t to uint16_t for consistency
uint8_t scroll_mod_y_;
uint8_t scroll_mod_x_;
uint16_t door_type_1_;
@@ -75,17 +75,17 @@ class OverworldExit : public GameEntity {
room_id_(room_id),
y_scroll_(y_scroll),
x_scroll_(x_scroll),
y_player_(player_y),
x_player_(player_x),
y_camera_(camera_y),
x_camera_(camera_x),
y_player_(player_y), // No cast - preserve full 16-bit value
x_player_(player_x), // No cast - preserve full 16-bit value
y_camera_(camera_y), // No cast - preserve full 16-bit value
x_camera_(camera_x), // No cast - preserve full 16-bit value
scroll_mod_y_(scroll_mod_y),
scroll_mod_x_(scroll_mod_x),
door_type_1_(door_type_1),
door_type_2_(door_type_2),
is_hole_(false),
deleted_(deleted) {
// Initialize entity variables
// Initialize entity variables with full 16-bit coordinates
x_ = player_x;
y_ = player_y;
map_id_ = map_id;
@@ -150,23 +150,25 @@ class OverworldExit : public GameEntity {
int mapy = (map_id & 56) << 6;
if (is_automatic_) {
x_ = x_ - 120;
y_ = y_ - 80;
// Auto-calculate scroll and camera from player position
// Matches ZScream ExitOW.cs:256-309
x_scroll_ = x_player_ - 120;
y_scroll_ = y_player_ - 80;
if (x_ < mapx) {
x_ = mapx;
if (x_scroll_ < mapx) {
x_scroll_ = mapx;
}
if (y_ < mapy) {
y_ = mapy;
if (y_scroll_ < mapy) {
y_scroll_ = mapy;
}
if (x_ > mapx + large) {
x_ = mapx + large;
if (x_scroll_ > mapx + large) {
x_scroll_ = mapx + large;
}
if (y_ > mapy + large + 32) {
y_ = mapy + large + 32;
if (y_scroll_ > mapy + large + 32) {
y_scroll_ = mapy + large + 32;
}
x_camera_ = x_player_ + 0x07;
@@ -189,8 +191,8 @@ class OverworldExit : public GameEntity {
}
}
short vram_x_scroll = (short)(x_ - mapx);
short vram_y_scroll = (short)(y_ - mapy);
short vram_x_scroll = (short)(x_scroll_ - mapx);
short vram_y_scroll = (short)(y_scroll_ - mapy);
map_pos_ = (uint16_t)(((vram_y_scroll & 0xFFF0) << 3) |
((vram_x_scroll & 0xFFF0) >> 3));