summaryrefslogtreecommitdiff
path: root/src/Game/UI
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-01-22 11:30:46 +0100
committerLéo Lam <leo@leolam.fr>2021-01-22 12:35:53 +0100
commitd9f7561588b99a6b90315541e39dcf32371edd01 (patch)
tree94920bbab4cbb8f8f184e5ce563632d4ce11d925 /src/Game/UI
parent48276bb4e788e28c5b53f098471f8c8af03e6315 (diff)
uking/ui: Implement food sorting in inventory
Diffstat (limited to 'src/Game/UI')
-rw-r--r--src/Game/UI/uiPauseMenuDataMgr.cpp78
-rw-r--r--src/Game/UI/uiPauseMenuDataMgr.h1
2 files changed, 79 insertions, 0 deletions
diff --git a/src/Game/UI/uiPauseMenuDataMgr.cpp b/src/Game/UI/uiPauseMenuDataMgr.cpp
index bc05a5bb..9628eee6 100644
--- a/src/Game/UI/uiPauseMenuDataMgr.cpp
+++ b/src/Game/UI/uiPauseMenuDataMgr.cpp
@@ -164,6 +164,46 @@ int getWeaponModifierSortKey(sead::TypedBitFlag<act::WeaponModifier> flags) {
return 12;
}
+int getFoodSortKey(int* effect_value, const PouchItem* item) {
+ const int type = item->getCookData().mCookEffect0.x;
+ const int value = item->getCookData().mCookEffect0.y;
+ *effect_value = value;
+ // TODO: add an enum
+ switch (type) {
+ case 1:
+ return 0;
+ case 2:
+ return 1;
+ case 14:
+ return 2;
+ case 15:
+ return 3;
+ case 13:
+ return 4;
+ case 16:
+ return 5;
+ case 5:
+ return 6;
+ case 4:
+ return 7;
+ case 6:
+ return 8;
+ case 10:
+ return 9;
+ case 11:
+ return 10;
+ case 12:
+ return 11;
+ default:
+ *effect_value = 0;
+ if (ksys::act::InfoData::instance()->hasTag(item->getName().cstr(),
+ ksys::act::tags::CookResult)) {
+ return 0;
+ }
+ return 12;
+ }
+}
+
} // namespace
int pouchItemSortPredicate(const PouchItem* lhs, const PouchItem* rhs);
@@ -1985,6 +2025,44 @@ int compareMaterial(const PouchItem* lhs, const PouchItem* rhs, ksys::act::InfoD
return compareSortKeys(lhs, rhs, data);
}
+int compareFood(const PouchItem* lhs, const PouchItem* rhs, ksys::act::InfoData* data) {
+ int e1, e2;
+ const int k1 = getFoodSortKey(&e1, lhs);
+ const int k2 = getFoodSortKey(&e2, rhs);
+ // Lower key is better
+ if (k1 < k2)
+ return -1;
+ if (k1 > k2)
+ return 1;
+
+ if (auto cmp = compareSortKeys(lhs, rhs, data))
+ return cmp;
+
+ // Higher is better
+ if (e1 > e2)
+ return -1;
+ if (e1 < e2)
+ return 1;
+
+ const int st1 = lhs->getCookData().mStaminaRecoverX;
+ const int st2 = rhs->getCookData().mStaminaRecoverX;
+ // Higher is better
+ if (st1 > st2)
+ return -1;
+ if (st1 < st2)
+ return 1;
+
+ const auto sv1 = lhs->getCookData().getStaminaRecoverValue();
+ const auto sv2 = rhs->getCookData().getStaminaRecoverValue();
+ // Higher is better
+ if (sv1 > sv2)
+ return -1;
+ if (sv1 < sv2)
+ return 1;
+
+ return 0;
+}
+
int compareKeyItem(const PouchItem* lhs, const PouchItem* rhs, ksys::act::InfoData* data) {
if (auto cmp = compareSortKeys(lhs, rhs, data))
return cmp;
diff --git a/src/Game/UI/uiPauseMenuDataMgr.h b/src/Game/UI/uiPauseMenuDataMgr.h
index 4348abbe..95fe25e2 100644
--- a/src/Game/UI/uiPauseMenuDataMgr.h
+++ b/src/Game/UI/uiPauseMenuDataMgr.h
@@ -148,6 +148,7 @@ struct CookTagInfo {
class PouchItem {
public:
struct CookData {
+ f32 getStaminaRecoverValue() const { return f32(mStaminaRecoverY) * 30.0f; }
void setStaminaRecoverX(int x) { mStaminaRecoverX = x; }
void setStaminaRecoverY(int y) { mStaminaRecoverY = y; }
void setCookEffect1(int effect) { mCookEffect1 = effect; }