uking/ui: Implement PauseMenuDataMgr::countItems

This commit is contained in:
Léo Lam 2021-01-10 19:16:00 +01:00
parent 4c171605ff
commit c28e7ace3d
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
4 changed files with 109 additions and 4 deletions

View File

@ -56327,7 +56327,7 @@
0x000000710096d72c,PauseMenuDataMgr::hasWeaponMaybe,1288,
0x000000710096dc34,PauseMenuDataMgr::getItemCategory,2004,_ZN5uking2ui16PauseMenuDataMgr7getTypeERKN4sead14SafeStringBaseIcEEPN2al9ByamlIterE
0x000000710096e408,sub_710096E408,1028,
0x000000710096e80c,sub_710096E80C,772,
0x000000710096e80c,sub_710096E80C,772,_ZNK5uking2ui16PauseMenuDataMgr10countItemsENS0_13PouchItemTypeEb
0x000000710096eb10,sub_710096EB10,1192,_ZNK5uking2ui16PauseMenuDataMgr19isWeaponSectionFullERKN4sead14SafeStringBaseIcEE
0x000000710096efb8,PauseMenuDataMgr::__auto4,688,
0x000000710096f268,PauseMenuDataMgr::increasePouchNumStackable,1876,

Can't render this file because it is too large.

@ -1 +1 @@
Subproject commit da6aede45a52978bbef99b83bda0ade4e2ddddf9
Subproject commit b36b392d9c763f7c084149824a3b5dcef4244138

View File

@ -266,6 +266,108 @@ PouchItemType PauseMenuDataMgr::getType(const sead::SafeString& item, al::ByamlI
return PouchItemType::Material;
}
int PauseMenuDataMgr::countItems(PouchItemType type, bool count_any_weapon) const {
if (isPouchItemInvalid(type) || getItems().isEmpty())
return 0;
const auto& list = getItems();
if (count_any_weapon) {
PouchItem** head = nullptr;
if (type <= PouchItemType::Shield) {
int count = 0;
for (auto* item = list.nth(0); item && item->getType() <= PouchItemType::Shield;
item = list.next(item)) {
count += item->get25();
}
return count;
} else if (type <= PouchItemType::ArmorLower) {
int count = 0;
for (auto* item = getItemHead(PouchCategory::Armor);
item && item->getType() <= PouchItemType::ArmorLower; item = list.next(item)) {
count += item->get25();
}
return count;
} else if (type == PouchItemType::Material) {
head = getItemHeadp(PouchCategory::Material);
if (!head)
return 0;
} else if (type == PouchItemType::Food) {
head = getItemHeadp(PouchCategory::Food);
if (!head)
return 0;
} else if (type == PouchItemType::KeyItem) {
head = getItemHeadp(PouchCategory::KeyItem);
if (!head)
return 0;
} else {
return 0;
}
if (!head)
return 0;
int count = 0;
for (auto* item = *head; item && item->getType() == type; item = list.next(item)) {
count += item->get25();
}
return count;
}
PouchItem* first = nullptr;
if (type == PouchItemType::Weapon) {
first = getItemHead(PouchCategory::Weapon);
} else if (type == PouchItemType::Bow) {
first = getItemHead(PouchCategory::Bow);
} else if (type == PouchItemType::Arrow) {
for (auto* item = getItemHead(PouchCategory::Bow);
item && item->getType() <= PouchItemType::Arrow; item = list.next(item)) {
if (item->getType() == PouchItemType::Arrow) {
first = item;
break;
}
}
} else if (type == PouchItemType::Shield) {
first = getItemHead(PouchCategory::Shield);
} else if (type <= PouchItemType::ArmorLower) {
int count = 0;
for (auto* item = getItemHead(PouchCategory::Armor);
item && item->getType() <= PouchItemType::ArmorLower; item = list.next(item)) {
count += item->get25();
}
return count;
} else if (type == PouchItemType::Material) {
first = getItemHead(PouchCategory::Material);
} else if (type == PouchItemType::Food) {
first = getItemHead(PouchCategory::Food);
} else if (type == PouchItemType::KeyItem) {
first = getItemHead(PouchCategory::KeyItem);
} else {
return 0;
}
int count = 0;
for (auto* item = first; item && item->getType() == type; item = list.next(item)) {
count += item->get25();
}
return count;
}
bool PauseMenuDataMgr::isWeaponSectionFull(const sead::SafeString& weapon_type) const {
const auto lock = sead::makeScopedLock(mCritSection);
@ -671,7 +773,7 @@ void PauseMenuDataMgr::updateDivineBeastClearFlags(int num_cleared_beasts) {
}
bool PauseMenuDataMgr::isOverCategoryLimit(PouchItemType type) const {
const auto count = countItemsWithType(type);
const auto count = countItems(type);
switch (type) {
case PouchItemType::Weapon:
return ksys::gdt::getFlag_WeaponPorchStockNum() <= count || count >= NumWeaponsMax;

View File

@ -174,7 +174,8 @@ public:
void initForNewSave();
static PouchItemType getType(const sead::SafeString& item, al::ByamlIter* iter = nullptr);
int countItemsWithType(PouchItemType type, bool x = false) const;
int countItems(PouchItemType type, bool count_any_weapon = false) const;
bool isWeaponSectionFull(const sead::SafeString& get_flag) const;
void removeArrow(const sead::SafeString& arrow_name, int count = 1);
@ -237,6 +238,8 @@ private:
return *p_head;
}
PouchItem** getItemHeadp(PouchCategory category) const { return mListHeads[u32(category)]; }
PouchItem* nextItem(const PouchItem* item) const { return getItems().next(item); }
void resetItem();