diff options
Diffstat (limited to 'src/gui/windows/buydialog.cpp')
-rw-r--r-- | src/gui/windows/buydialog.cpp | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index b17064e45..a9ea274ae 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -1,11 +1,11 @@ /* - * The ManaPlus Client + * The ManaVerse Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers * Copyright (C) 2011-2020 The ManaPlus Developers - * Copyright (C) 2020-2023 The ManaVerse Developers + * Copyright (C) 2020-2025 The ManaVerse Developers * - * This file is part of The ManaPlus Client. + * This file is part of The ManaVerse Client. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ #include "configuration.h" #include "being/being.h" +#include "being/playerinfo.h" #include "enums/gui/layouttype.h" @@ -225,6 +226,7 @@ BuyDialog::BuyDialog() : mMoney(0), mAmountItems(0), mMaxItems(0), + mTotalPurchaseWeight(0), mAdvanced(false) { init(); @@ -247,6 +249,7 @@ BuyDialog::BuyDialog(const BeingId npcId, mMoney(0), mAmountItems(0), mMaxItems(0), + mTotalPurchaseWeight(0), mAdvanced(Net::getNetworkType() != ServerType::TMWATHENA) { init(); @@ -271,6 +274,7 @@ BuyDialog::BuyDialog(const std::string &nick, mMoney(0), mAmountItems(0), mMaxItems(0), + mTotalPurchaseWeight(0), mAdvanced(false) { init(); @@ -295,6 +299,7 @@ BuyDialog::BuyDialog(const Being *const being, mMoney(0), mAmountItems(0), mMaxItems(0), + mTotalPurchaseWeight(0), mAdvanced(true) { init(); @@ -337,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"); @@ -472,6 +477,7 @@ void BuyDialog::reset() mShopItemList->setSelected(-1); mSlider->setValue(0); + mTotalPurchaseWeight = 0; setMoney(0); } @@ -636,6 +642,8 @@ void BuyDialog::action(const ActionEvent &event) else if (mNpcId == fromInt(Vending, BeingId)) { item->increaseUsedQuantity(mAmountItems); + const int itemWeight = item->getInfo().getWeight(); + mTotalPurchaseWeight += mAmountItems * itemWeight; item->update(); if (mConfirmButton != nullptr) mConfirmButton->setEnabled(true); @@ -649,6 +657,8 @@ void BuyDialog::action(const ActionEvent &event) if (mAdvanced) { item->increaseUsedQuantity(mAmountItems); + const int itemWeight = item->getInfo().getWeight(); + mTotalPurchaseWeight += mAmountItems * itemWeight; item->update(); if (mConfirmButton != nullptr) mConfirmButton->setEnabled(true); @@ -744,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) { @@ -753,13 +767,21 @@ void BuyDialog::updateButtonsAndLabels() const int itemPrice = item->getPrice(); // Calculate how many the player can afford - if (mNpcId == fromInt(Items, BeingId)) + if (mNpcId == fromInt(Items, BeingId)) // /createitems "shop" mMaxItems = 100; else if (itemPrice != 0) mMaxItems = mMoney / itemPrice; else mMaxItems = 1; + // Calculate how many the player can carry + const int itemWeight = item->getInfo().getWeight(); + if (itemWeight != 0) + { + const int canCarry = freeWeight / itemWeight; + mMaxItems = std::min(mMaxItems, canCarry); + } + if (mNpcId == fromInt(Market, BeingId)) { if (mMaxItems > item->getQuantity()) @@ -774,6 +796,7 @@ void BuyDialog::updateButtonsAndLabels() if (mAmountItems > mMaxItems) mAmountItems = mMaxItems; + freeWeight -= mAmountItems * itemWeight; price = mAmountItems * itemPrice; } } @@ -790,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) |