From 947a97608c81163d3b346553549d13df489ee538 Mon Sep 17 00:00:00 2001 From: lilDavid <1337lilDavid@gmail.com> Date: Fri, 12 Aug 2022 15:03:37 -0500 Subject: [PATCH] Save Editor Adult Trade Shuffle bugfixes: - Having multiple items with the collapsing header open rapidly cycles trade items - Unchecking any item's checkbox cycles the trade item (it should only do so if it's the one you've selected) - Setting the adult trade slot sets the wrong items' flags - Emptying the adult trade slot doesn't reset all trade items' flags --- .../Enhancements/debugger/debugSaveEditor.cpp | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp index 90e4ca0ff6..c5cad88dd9 100644 --- a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp +++ b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp @@ -533,15 +533,18 @@ void DrawBGSItemFlag(uint8_t itemID) { ImGui::SameLine(); int tradeIndex = itemID - ITEM_POCKET_EGG; bool hasItem = (gSaveContext.adultTradeItems & (1 << tradeIndex)) != 0; - ImGui::Checkbox(("##adultTradeFlag" + std::to_string(itemID)).c_str(), &hasItem); - if (hasItem) { - gSaveContext.adultTradeItems |= (1 << tradeIndex); - if (INV_CONTENT(ITEM_TRADE_ADULT) == ITEM_NONE) { - INV_CONTENT(ITEM_TRADE_ADULT) = ITEM_POCKET_EGG + tradeIndex; + bool shouldHaveItem = hasItem; + ImGui::Checkbox(("##adultTradeFlag" + std::to_string(itemID)).c_str(), &shouldHaveItem); + if (hasItem != shouldHaveItem) { + if (shouldHaveItem) { + gSaveContext.adultTradeItems |= (1 << tradeIndex); + if (INV_CONTENT(ITEM_TRADE_ADULT) == ITEM_NONE) { + INV_CONTENT(ITEM_TRADE_ADULT) = ITEM_POCKET_EGG + tradeIndex; + } + } else { + gSaveContext.adultTradeItems &= ~(1 << tradeIndex); + Inventory_ReplaceItem(gGlobalCtx, itemID, Randomizer_GetNextAdultTradeItem()); } - } else { - gSaveContext.adultTradeItems &= ~(1 << tradeIndex); - Inventory_ReplaceItem(gGlobalCtx, INV_CONTENT(ITEM_TRADE_ADULT), Randomizer_GetNextAdultTradeItem()); } } @@ -586,6 +589,9 @@ void DrawInventoryTab() { if (ImGui::BeginPopup(itemPopupPicker)) { if (ImGui::Button("##itemNonePicker", ImVec2(32.0f, 32.0f))) { gSaveContext.inventory.items[selectedIndex] = ITEM_NONE; + if (selectedIndex == SLOT_TRADE_ADULT) { + gSaveContext.adultTradeItems = 0; + } ImGui::CloseCurrentPopup(); } SetLastItemHoverText("None"); @@ -616,17 +622,13 @@ void DrawInventoryTab() { if (ImGui::ImageButton(SohImGui::GetTextureByName(slotEntry.name), ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1), 0)) { gSaveContext.inventory.items[selectedIndex] = slotEntry.id; - // Set adult trade item flag if you're playing adult trade shuffle in rando + // Set adult trade item flag if you're playing adult trade shuffle in rando if (gSaveContext.n64ddFlag && - OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_SHUFFLE_ADULT_TRADE) && - selectedIndex == SLOT_TRADE_ADULT) { - if (slotEntry.id == ITEM_NONE) { - gSaveContext.adultTradeItems = 0; - } else if (slotEntry.id >= ITEM_POCKET_EGG && slotEntry.id <= ITEM_CLAIM_CHECK) { - uint32_t tradeID = slotEntry.id - ITEM_POCKET_EGG; - gSaveContext.adultTradeItems |= tradeID; - } - } + OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_SHUFFLE_ADULT_TRADE); + selectedIndex == SLOT_TRADE_ADULT && + slotEntry.id >= ITEM_POCKET_EGG && slotEntry.id <= ITEM_CLAIM_CHECK) { + gSaveContext.adultTradeItems |= ADULT_TRADE_FLAG(slotEntry.id); + } ImGui::CloseCurrentPopup(); } SetLastItemHoverText(SohUtils::GetItemName(slotEntry.id));