diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-01-25 01:10:09 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-01-25 01:10:09 +0300 |
commit | cc2c18c2b41e5409a0762b538568b41e9147c6e9 (patch) | |
tree | 473c763012a3a99fbaa4873e25332b6a71d504d1 /src/gui/windows/inventorywindow.cpp | |
parent | e94119a81652c829c31f52cbc1ae0bce586f1483 (diff) | |
download | mv-cc2c18c2b41e5409a0762b538568b41e9147c6e9.tar.gz mv-cc2c18c2b41e5409a0762b538568b41e9147c6e9.tar.bz2 mv-cc2c18c2b41e5409a0762b538568b41e9147c6e9.tar.xz mv-cc2c18c2b41e5409a0762b538568b41e9147c6e9.zip |
Add weight bar into cart window.
Diffstat (limited to 'src/gui/windows/inventorywindow.cpp')
-rw-r--r-- | src/gui/windows/inventorywindow.cpp | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp index 7ea15ebc9..712ba7981 100644 --- a/src/gui/windows/inventorywindow.cpp +++ b/src/gui/windows/inventorywindow.cpp @@ -264,12 +264,18 @@ InventoryWindow::InventoryWindow(Inventory *const inventory) : // TRANSLATORS: storage button mInvCloseButton = new Button(this, _("Close"), "close", this); - mSlotsBarCell = &place(0, 0, mSlotsBar, 6); + mWeightBar = new ProgressBar(this, 0.0F, 100, 0, Theme::PROG_WEIGHT, + "weightprogressbar.xml", "weightprogressbar_fill.xml"); + mWeightBar->setColor(getThemeColor(Theme::WEIGHT_BAR), + getThemeColor(Theme::WEIGHT_BAR_OUTLINE)); + + mSlotsBarCell = &place(3, 0, mSlotsBar, 3); mSortDropDownCell = &place(6, 0, mSortDropDown, 1); mFilterCell = &place(0, 1, mFilter, 7).setPadding(3); mNameFilterCell = &place(6, 1, mNameFilter, 1); + place(0, 0, mWeightBar, 3); place(0, 2, invenScroll, 7, 4); place(0, 6, mStoreButton); place(1, 6, mRetrieveButton); @@ -755,11 +761,17 @@ void InventoryWindow::close() void InventoryWindow::updateWeight() { - if (!isMainInventory() || !mWeightBar) + if (!mInventory || !mWeightBar) + return; + const InventoryType::Type type = mInventory->getType(); + if (type != InventoryType::INVENTORY && type != InventoryType::CART) return; - const int total = PlayerInfo::getAttribute(Attributes::TOTAL_WEIGHT); - const int max = PlayerInfo::getAttribute(Attributes::MAX_WEIGHT); + const bool isInv = type != InventoryType::INVENTORY; + const int total = PlayerInfo::getAttribute(isInv + ? Attributes::TOTAL_WEIGHT : Attributes::CART_TOTAL_WEIGHT); + const int max = PlayerInfo::getAttribute(isInv + ? Attributes::MAX_WEIGHT : Attributes::CART_MAX_WEIGHT); if (max <= 0) return; @@ -767,8 +779,9 @@ void InventoryWindow::updateWeight() // Adjust progress bar mWeightBar->setProgress(static_cast<float>(total) / static_cast<float>(max)); - mWeightBar->setText(strprintf("%s/%s", Units::formatWeight(total).c_str(), - Units::formatWeight(max).c_str())); + mWeightBar->setText(strprintf("%s/%s", + Units::formatWeight(total).c_str(), + Units::formatWeight(max).c_str())); } void InventoryWindow::slotsChanged(Inventory *const inventory) @@ -905,6 +918,11 @@ void InventoryWindow::attributeChanged(const int id, const int oldVal A_UNUSED, const int newVal A_UNUSED) { - if (id == Attributes::TOTAL_WEIGHT || id == Attributes::MAX_WEIGHT) + if (id == Attributes::TOTAL_WEIGHT + || id == Attributes::MAX_WEIGHT + || id == Attributes::CART_TOTAL_WEIGHT + || id == Attributes::CART_MAX_WEIGHT) + { updateWeight(); + } } |