diff --git a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp index fda6624076..074b4ed2e5 100644 --- a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp +++ b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp @@ -522,6 +522,19 @@ void DrawBGSItemFlag(uint8_t itemID) { ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1)); } +// Re-sync any C/D-pad button that mirrors an edited inventory slot (buttonItems[i] == items[cButtonSlots[i-1]]), +// so a raw item edit doesn't leave the button showing stale contents. +static void SyncButtonItemsForSlot(uint8_t slot) { + for (size_t i = 1; i < ARRAY_COUNT(gSaveContext.equips.buttonItems); i++) { + if (gSaveContext.equips.cButtonSlots[i - 1] == slot) { + gSaveContext.equips.buttonItems[i] = gSaveContext.inventory.items[slot]; + if (gPlayState != nullptr) { + Interface_LoadItemIcon1(gPlayState, static_cast(i)); + } + } + } +} + void DrawInventoryTab() { static bool restrictToValid = true; @@ -529,6 +542,11 @@ void DrawInventoryTab() { "Restrict to valid items", &restrictToValid, checkboxOptionsBase.Tooltip("Restricts items and ammo to only what is possible to legally acquire in-game")); + static bool syncButtons = true; + Checkbox("Keep C/D-pad buttons in sync", &syncButtons, + checkboxOptionsBase.Tooltip("Refresh a C or D-pad button when its inventory slot is edited. Disable to " + "leave a slot and its button out of sync (e.g. to set up RBA).")); + for (int y = 0; y < 4; y++) { for (int x = 0; x < 6; x++) { static_assert(5 + 3 * 6 < sizeof(gSaveContext.inventory.items) / sizeof(gSaveContext.inventory.items[0])); @@ -579,8 +597,12 @@ void DrawInventoryTab() { PushStyleButton(Colors::DarkGray); if (ImGui::Button("##itemNonePicker", ImVec2(IMAGE_SIZE, IMAGE_SIZE) + ImGui::GetStyle().FramePadding * 2)) { - if (selectedIndex != SLOT_NONE) + if (selectedIndex != SLOT_NONE) { gSaveContext.inventory.items[selectedIndex] = ITEM_NONE; + if (syncButtons) { + SyncButtonItemsForSlot(selectedIndex); + } + } ImGui::CloseCurrentPopup(); } PopStyleButton(); @@ -619,6 +641,9 @@ void DrawInventoryTab() { PopStyleButton(); if (ret) { gSaveContext.inventory.items[selectedIndex] = slotEntry.id; + if (syncButtons) { + SyncButtonItemsForSlot(selectedIndex); + } ImGui::CloseCurrentPopup(); } UIWidgets::Tooltip(SohUtils::GetItemName(slotEntry.id).c_str());