summaryrefslogtreecommitdiff
path: root/src/Game/UI/uiPauseMenuDataMgr.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-01-10 19:16:00 +0100
committerLéo Lam <leo@leolam.fr>2021-01-11 15:51:22 +0100
commitc28e7ace3d85820fb2a1bdd010bffbfc371a24a3 (patch)
treef1a0ddd0a930ec92dca3e94e92edddd654f6b867 /src/Game/UI/uiPauseMenuDataMgr.cpp
parent4c171605ff18e1eed4c6fe516e3b7b6d6034ce22 (diff)
uking/ui: Implement PauseMenuDataMgr::countItems
Diffstat (limited to 'src/Game/UI/uiPauseMenuDataMgr.cpp')
-rw-r--r--src/Game/UI/uiPauseMenuDataMgr.cpp104
1 files changed, 103 insertions, 1 deletions
diff --git a/src/Game/UI/uiPauseMenuDataMgr.cpp b/src/Game/UI/uiPauseMenuDataMgr.cpp
index cc7d0815..d8d200d0 100644
--- a/src/Game/UI/uiPauseMenuDataMgr.cpp
+++ b/src/Game/UI/uiPauseMenuDataMgr.cpp
@@ -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;