Swap item slot function implemented.

pull/28/head
sigonasr2 1 year ago
parent 82848df963
commit 819f5845b1
  1. 3
      Crawler/InventoryWindow.cpp
  2. 15
      Crawler/Item.cpp
  3. 4
      Crawler/Item.h

@ -16,9 +16,6 @@ const Menu Menu::InitializeInventoryWindow(){
Menu inventoryWindow(CENTERED,{24*invWidth,24*(invHeight+1)});
for(auto&key:Inventory::get()){
}
for(int i=0;i<totalItemSlots;i++){
inventoryWindow.GetStringVec(A::INDEXED_ITEMS).push_back();
}

@ -161,4 +161,19 @@ void Inventory::InsertIntoSortedInv(IT item){
bool Inventory::ExecuteAction(IT item){
return ITEM_SCRIPTS.at(ITEM_DATA.at(item).useFunc)(game,ITEM_DATA[item].customProps);
}
bool Inventory::SwapItems(IT it,IT it2){
ItemInfo&itemInfo1=ITEM_DATA.at(it);
ItemInfo&itemInfo2=ITEM_DATA.at(it2);
if(itemInfo1.category!=itemInfo2.category)return false;
ITCategory category=itemInfo1.category;
Item item1=GetItem(it);
Item item2=GetItem(it2);
if(item1.Amt()<=0&&item2.Amt()<=0)return false;
std::vector<IT>inv=sortedInv.at(category);
auto index1=std::find(inv.begin(),inv.end(),it);
auto index2=std::find(inv.begin(),inv.end(),it2);
std::swap(*index1,*index2);
return true;
}

@ -31,11 +31,13 @@ class Inventory{
public:
static void AddItem(IT it,int amt=1);
static uint32_t GetItemCount(IT it);
static Item GetItem(IT it);
static Item GetItem(IT it)const;
//Auto-executes its use function and removes the amt specified from the inventory. Multiple amounts will cause the item to execute its useFunc multiple times.
static void UseItem(IT it,int amt=1);
static void RemoveItem(IT it,int amt=1);
static std::vector<IT>&get(ITCategory itemCategory);
static bool SwapItems(IT it,IT it2);
private:
static void InsertIntoSortedInv(IT item);
static bool ExecuteAction(IT item);

Loading…
Cancel
Save