summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2025-04-03 16:09:47 +0200
committerFedja Beader <fedja@protonmail.ch>2025-04-03 16:12:04 +0200
commit70a202589046de989ef8da1549483b4b61454ebb (patch)
tree6c35a9b418e2981aed334426cae35f4006ee99fa
parent710eeb95bf0a1cf7ab2ca4b719a17596481302a3 (diff)
downloadmanaplus-shopping_list_weight.tar.gz
manaplus-shopping_list_weight.tar.bz2
manaplus-shopping_list_weight.tar.xz
manaplus-shopping_list_weight.zip
buydialog: Add free weight display to money labelshopping_list_weight
+ fix free weight going below 0
-rw-r--r--src/gui/windows/buydialog.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp
index 5084926ed..038ddb3ac 100644
--- a/src/gui/windows/buydialog.cpp
+++ b/src/gui/windows/buydialog.cpp
@@ -342,8 +342,8 @@ void BuyDialog::init()
"%d / %d", mAmountItems, mMaxItems));
mQuantityLabel->setAlignment(Graphics::CENTER);
mMoneyLabel = new Label(this, strprintf(
- // TRANSLATORS: buy dialog label
- _("Price: %s / Total: %s"), "", ""));
+ // TRANSLATORS: buy dialog label, price, remaining money & free weight
+ _("Price: %s, Remaining: %s & %s"), "", "", ""));
mAmountField = new IntTextField(this, 1, 1, 123, Enable_true, 0);
mAmountField->setActionEventId("amount");
@@ -754,6 +754,10 @@ void BuyDialog::updateButtonsAndLabels()
{
const int selectedItem = mShopItemList->getSelected();
int price = 0;
+ int freeWeight
+ = PlayerInfo::getAttribute(Attributes::MAX_WEIGHT)
+ - PlayerInfo::getAttribute(Attributes::TOTAL_WEIGHT)
+ - mTotalPurchaseWeight;
if (selectedItem > -1)
{
@@ -774,11 +778,7 @@ void BuyDialog::updateButtonsAndLabels()
const int itemWeight = item->getInfo().getWeight();
if (itemWeight != 0)
{
- const int myFreeWeight
- = PlayerInfo::getAttribute(Attributes::MAX_WEIGHT)
- - PlayerInfo::getAttribute(Attributes::TOTAL_WEIGHT)
- - mTotalPurchaseWeight;
- const int canCarry = myFreeWeight / itemWeight;
+ const int canCarry = freeWeight / itemWeight;
mMaxItems = std::min(mMaxItems, canCarry);
}
@@ -796,6 +796,7 @@ void BuyDialog::updateButtonsAndLabels()
if (mAmountItems > mMaxItems)
mAmountItems = mMaxItems;
+ freeWeight -= mAmountItems * itemWeight;
price = mAmountItems * itemPrice;
}
}
@@ -812,10 +813,11 @@ void BuyDialog::updateButtonsAndLabels()
mAmountField->setEnabled(mAmountItems > 0);
mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems));
- // TRANSLATORS: buy dialog label
- mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"),
+ // TRANSLATORS: buy dialog label, price, remaining money & free weight
+ mMoneyLabel->setCaption(strprintf(_("Price: %s, Remaining: %s & %s"),
UnitsDb::formatCurrency(mCurrency, price).c_str(),
- UnitsDb::formatCurrency(mCurrency, mMoney - price).c_str()));
+ UnitsDb::formatCurrency(mCurrency, mMoney - price).c_str(),
+ UnitsDb::formatWeight(freeWeight).c_str()));
}
void BuyDialog::setVisible(Visible visible)