summaryrefslogtreecommitdiff
path: root/src/gui/inventorywindow.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-01-26 11:05:46 -0700
committerIra Rice <irarice@gmail.com>2009-01-26 11:05:46 -0700
commit7a618a7f4f7c2efe2a6973cc37bc8283025e4782 (patch)
tree08a223d131f3e201ebd315bb1819804d39539728 /src/gui/inventorywindow.cpp
parent803e0dae01f09afbe529799cf89a8f57fe518ddb (diff)
downloadmana-7a618a7f4f7c2efe2a6973cc37bc8283025e4782.tar.gz
mana-7a618a7f4f7c2efe2a6973cc37bc8283025e4782.tar.bz2
mana-7a618a7f4f7c2efe2a6973cc37bc8283025e4782.tar.xz
mana-7a618a7f4f7c2efe2a6973cc37bc8283025e4782.zip
Modified the inventory window so that weight and slots used are shown as
progress bars. Suggestion made by Forge. Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/gui/inventorywindow.cpp')
-rw-r--r--src/gui/inventorywindow.cpp55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 32817479..fe3300dc 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -31,6 +31,7 @@
#include "inventorywindow.h"
#include "item_amount.h"
#include "itemcontainer.h"
+#include "progressbar.h"
#include "scrollarea.h"
#include "viewport.h"
@@ -80,23 +81,22 @@ InventoryWindow::InventoryWindow(int invSize):
mMaxWeight = toString(player_node->mMaxWeight);
mUsedSlots = toString(player_node->getInventory()->getNumberOfSlotsUsed());
- mWeight = strprintf(_("Weight: %d g / %d g"),
- atoi(mTotalWeight.c_str()), atoi(mMaxWeight.c_str()));
- mSlots = strprintf(_("Slots used: %d / %d"),
- atoi(mUsedSlots.c_str()), mMaxSlots);
+ mSlotsLabel = new gcn::Label(_("Slots: "));
+ mWeightLabel = new gcn::Label(_("Weight: "));
- mWeightLabel = new gcn::Label(mWeight + " " + mSlots);
+ mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25);
+ mWeightBar = new ProgressBar(1.0f, 100, 20, 0, 0, 255);
setMinHeight(130);
- setMinWidth(getFont()->getWidth(mWeight));
+ setMinWidth(mWeightLabel->getWidth() + mSlotsLabel->getWidth() + 310);
- ContainerPlacer place;
- place = getPlacer(0, 0);
-
- place(0, 0, mInvenScroll, 5, 4);
- place(0, 4, mWeightLabel, 5);
- place(3, 5, mDropButton);
- place(4, 5, mUseButton);
+ place(0, 0, mInvenScroll, 7, 4);
+ place(0, 4, mWeightLabel).setPadding(3);
+ place(1, 4, mWeightBar, 2);
+ place(3, 4, mSlotsLabel).setPadding(3);
+ place(4, 4, mSlotsBar, 2);
+ place(5, 5, mDropButton);
+ place(6, 5, mUseButton);
Layout &layout = getLayout();
layout.setRowHeight(0, Layout::AUTO_SET);
@@ -121,15 +121,30 @@ void InventoryWindow::logic()
mMaxWeight = toString(player_node->mMaxWeight);
mUsedSlots = toString(player_node->getInventory()->getNumberOfSlotsUsed());
- // Adjust widgets
- mWeight = strprintf(_("Weight: %d g / %d g"),
- atoi(mTotalWeight.c_str()), atoi(mMaxWeight.c_str()));
- mSlots = strprintf(_("Slots used: %d / %d"),
- atoi(mUsedSlots.c_str()), mMaxSlots);
+ // Weight Bar coloration
+ if (int(player_node->mTotalWeight) < int(player_node->mMaxWeight / 3))
+ {
+ mWeightBar->setColor(0, 0, 255); // Blue
+ }
+ else if (int(player_node->mTotalWeight) <
+ int((player_node->mMaxWeight / 3) * 2))
+ {
+ mWeightBar->setColor(255, 255, 0); // Yellow
+ }
+ else
+ {
+ mWeightBar->setColor(255, 0, 0); // Red
+ }
- mWeightLabel->setCaption(mWeight + " " + mSlots);
+ // Adjust progress bars
+ mSlotsBar->setProgress((float)
+ player_node->getInventory()->getNumberOfSlotsUsed() / mMaxSlots);
+ mWeightBar->setProgress((float) player_node->mTotalWeight /
+ player_node->mMaxWeight);
- setMinWidth(getFont()->getWidth(mWeight));
+ mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots));
+ mWeightBar->setText(strprintf("%sg/%sg", mTotalWeight.c_str(),
+ mMaxWeight.c_str()));
}
}