From 4daf4f0135fe3a6f65ea09d423fdea0d2815dcfc Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 31 Dec 2023 17:04:34 -0600 Subject: [PATCH] Corrected GetInventorySlot() to return actual slot when there are multiple unique instances of an item instead of just the first index. --- Crawler/CharacterMenuWindow.cpp | 10 ++++++++++ Crawler/Item.cpp | 12 +++++++++++- Crawler/Version.h | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Crawler/CharacterMenuWindow.cpp b/Crawler/CharacterMenuWindow.cpp index c9377f0e..f48cb8d8 100644 --- a/Crawler/CharacterMenuWindow.cpp +++ b/Crawler/CharacterMenuWindow.cpp @@ -169,7 +169,12 @@ void Menu::InitializeCharacterMenuWindow(){ for(const std::string&attribute:displayAttrs){ statsBeforeEquip.push_back(game->GetPlayer()->GetStat(attribute)); } + std::weak_ptrequippedItem=Inventory::GetEquip(slot); + std::weak_ptrotherItem; + if(slot==EquipSlot::RING1)otherItem=Inventory::GetEquip(EquipSlot::RING2); + else + if(slot==EquipSlot::RING2)otherItem=Inventory::GetEquip(EquipSlot::RING1); Inventory::EquipItem(buttonItem,slot); for(int counter=0;const std::string&attribute:displayAttrs){ StatLabel*statDisplayLabel=Component(CHARACTER_MENU,"Attribute "+std::string(ItemAttribute::Get(attribute).Name())+" Label"); @@ -181,6 +186,11 @@ void Menu::InitializeCharacterMenuWindow(){ if(!ISBLANK(equippedItem)){ Inventory::EquipItem(equippedItem,slot); } + if(!ISBLANK(otherItem)){ + if(slot==EquipSlot::RING1)Inventory::EquipItem(otherItem,EquipSlot::RING2); + else + if(slot==EquipSlot::RING2)Inventory::EquipItem(otherItem,EquipSlot::RING1); + } }else{ ERR("WARNING! Attempting to cast a button that isn't a RowItemDisplay!"); } diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index e6621921..e435e34e 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -919,7 +919,17 @@ void Item::SetAmt(uint32_t newAmt){ } const std::weak_ptrInventory::GetInventorySlot(ITCategory itemCategory,size_t slot){ - return GetItem(get(itemCategory).at(slot)->ActualName())[0]; + auto GetFirstIndex = [](ITCategory itemCategory,size_t slot){ + auto firstIter=std::find_if(get(itemCategory).begin(),get(itemCategory).end(),[&](std::shared_ptritem){ + if(item->ActualName()==get(itemCategory).at(slot)->ActualName())return true; + return false; + }); + size_t firstIndex=firstIter-get(itemCategory).begin(); + if(firstIter==get(itemCategory).end())ERR(std::format("Invalid slot {} for category {} specified!",slot,itemCategory)); + return firstIndex; + }; + + return GetItem(get(itemCategory).at(slot)->ActualName())[slot-GetFirstIndex(itemCategory,slot)]; } bool Item::IsBlank(std::shared_ptritem){ diff --git a/Crawler/Version.h b/Crawler/Version.h index 60a678fd..781decd3 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 5140 +#define VERSION_BUILD 5143 #define stringify(a) stringify_(a) #define stringify_(a) #a