From aca306abdee1921d5536fc1e10aea110f599d471 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 1 Feb 2017 01:26:24 +0300 Subject: Use npc currency in buy dialog. --- src/gui/windows/buydialog.cpp | 5 +++-- src/resources/db/unitsdb.cpp | 8 ++++++++ src/resources/db/unitsdb.h | 6 ++++++ 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index 620c95817..797edd1ab 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -194,6 +194,7 @@ BuyDialog::BuyDialog() : this, "namefilter", true)), mFilterLabel(nullptr), mNick(), + mCurrency(), mNpcId(fromInt(Items, BeingId)), mMoney(0), mAmountItems(0), @@ -745,8 +746,8 @@ void BuyDialog::updateButtonsAndLabels() mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems)); // TRANSLATORS: buy dialog label mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"), - UnitsDb::formatCurrency(price).c_str(), - UnitsDb::formatCurrency(mMoney - price).c_str())); + UnitsDb::formatCurrency(mCurrency, price).c_str(), + UnitsDb::formatCurrency(mCurrency, mMoney - price).c_str())); } void BuyDialog::setVisible(Visible visible) diff --git a/src/resources/db/unitsdb.cpp b/src/resources/db/unitsdb.cpp index 7b56e8721..8746753c6 100644 --- a/src/resources/db/unitsdb.cpp +++ b/src/resources/db/unitsdb.cpp @@ -322,6 +322,14 @@ std::string UnitsDb::formatCurrency(const int value) return formatUnit(value, defaultCurrency); } +std::string UnitsDb::formatCurrency(std::string name, + const int value) +{ + if (mCurrencies.find(name) == mCurrencies.end()) + name = DEFAULT_CURRENCY; + return formatUnit(value, mCurrencies[name]); +} + std::string UnitsDb::formatWeight(const int value) { return formatUnit(value, defaultWeight); diff --git a/src/resources/db/unitsdb.h b/src/resources/db/unitsdb.h index 7a913cc16..689e7a6ad 100644 --- a/src/resources/db/unitsdb.h +++ b/src/resources/db/unitsdb.h @@ -47,6 +47,12 @@ class UnitsDb final */ static std::string formatCurrency(const int value) A_WARN_UNUSED; + /** + * Formats the given number in the correct currency format. + */ + static std::string formatCurrency(std::string name, + const int value) A_WARN_UNUSED; + /** * Formats the given number in the correct weight/mass format. */ -- cgit v1.2.3-70-g09d2