summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Giagtzoglou <gnikos21@yahoo.gr>2008-11-22 11:43:53 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-11-22 11:43:53 +0100
commit991389a535985af072f830b89e5113da82650fe5 (patch)
tree071ec4153b820a9c6404d5845443403b3cda83fb
parentc79d12b91ef0e49878a8e3f10486b910184acc69 (diff)
downloadmana-client-991389a535985af072f830b89e5113da82650fe5.tar.gz
mana-client-991389a535985af072f830b89e5113da82650fe5.tar.bz2
mana-client-991389a535985af072f830b89e5113da82650fe5.tar.xz
mana-client-991389a535985af072f830b89e5113da82650fe5.zip
Inventory window now displays amount of slots used
Patch by Nikos, with some improvements by vargavind.
-rw-r--r--NEWS1
-rw-r--r--src/gui/inventorywindow.cpp19
-rw-r--r--src/gui/inventorywindow.h1
-rw-r--r--src/inventory.cpp11
-rw-r--r--src/inventory.h11
5 files changed, 33 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index e2df4964..c93575b5 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@
- Added --data parameter for developers
- Added particle effect for critical hits
- Added support for dynamic skill names and hair colors
+- Inventory window now displays amount of slots used
- Center minimap on player when it is larger than the minimap window
- Extended particle emitters with properties that can change over time
- Extended the GUI font to support more characters
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index d01a2112..6a5a8b37 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -24,11 +24,11 @@
#include <string>
#include <guichan/mouseinput.hpp>
-
#include <guichan/widgets/label.hpp>
#include "button.h"
#include "gui.h"
+#include "inventory.h"
#include "item_amount.h"
#include "itemcontainer.h"
#include "scrollarea.h"
@@ -64,10 +64,13 @@ InventoryWindow::InventoryWindow():
mItemNameLabel = new gcn::Label("Name:");
mItemDescriptionLabel = new gcn::Label("Description:");
mItemEffectLabel = new gcn::Label("Effect:");
- mWeightLabel = new gcn::Label("Total Weight: - Maximum Weight: ");
+ mWeightLabel = new gcn::Label("Weight:");
mWeightLabel->setPosition(8, 8);
mInvenScroll->setPosition(8,
mWeightLabel->getY() + mWeightLabel->getHeight() + 5);
+ mInvenSlotLabel = new gcn::Label("Slots used:");
+ mInvenSlotLabel->setPosition(mWeightLabel->getX()
+ + mWeightLabel->getWidth() + 100, 8);
add(mUseButton);
add(mDropButton);
@@ -76,6 +79,7 @@ InventoryWindow::InventoryWindow():
add(mItemDescriptionLabel);
add(mItemEffectLabel);
add(mWeightLabel);
+ add(mInvenSlotLabel);
mUseButton->setSize(60, mUseButton->getHeight());
@@ -92,8 +96,14 @@ void InventoryWindow::logic()
// Update weight information
mWeightLabel->setCaption(
- "Total Weight: " + toString(player_node->mTotalWeight) + " - "
- "Maximum Weight: " + toString(player_node->mMaxWeight));
+ "Weight: " + toString(player_node->mTotalWeight) +
+ "/" + toString(player_node->mMaxWeight));
+
+ // Update number of items in inventory
+ mInvenSlotLabel->setCaption(
+ "Slots used: "
+ + toString(player_node->getInventory()->getNumberOfSlotsUsed())
+ + "/" + toString(player_node->getInventory()->getInventorySize()));
}
void InventoryWindow::action(const gcn::ActionEvent &event)
@@ -201,6 +211,7 @@ void InventoryWindow::widgetResized(const gcn::Event &event)
mItemDescriptionLabel->getY() - mWeightLabel->getHeight() - 18);
mWeightLabel->setWidth(width - 16);
+ mInvenSlotLabel->setWidth(width - 16);
}
void InventoryWindow::updateButtons()
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 0b208bbb..b1e3ede3 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -84,6 +84,7 @@ class InventoryWindow : public Window, gcn::ActionListener,
gcn::Label *mItemDescriptionLabel;
gcn::Label *mItemEffectLabel;
gcn::Label *mWeightLabel;
+ gcn::Label *mInvenSlotLabel;
};
extern InventoryWindow *inventoryWindow;
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 5633f430..938d23d3 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -132,19 +132,19 @@ bool Inventory::contains(Item *item) const
return false;
}
-int Inventory::getFreeSlot()
+int Inventory::getFreeSlot() const
{
Item **i = std::find_if(mItems + 2, mItems + INVENTORY_SIZE,
std::not1(SlotUsed()));
return (i == mItems + INVENTORY_SIZE) ? -1 : (i - mItems);
}
-int Inventory::getNumberOfSlotsUsed()
+int Inventory::getNumberOfSlotsUsed() const
{
return count_if(mItems, mItems + INVENTORY_SIZE, SlotUsed());
}
-int Inventory::getLastUsedSlot()
+int Inventory::getLastUsedSlot() const
{
for (int i = INVENTORY_SIZE - 1; i >= 0; i--) {
if (SlotUsed()(mItems[i])) {
@@ -154,3 +154,8 @@ int Inventory::getLastUsedSlot()
return -1;
}
+
+int Inventory::getInventorySize() const
+{
+ return INVENTORY_SIZE - 2;
+}
diff --git a/src/inventory.h b/src/inventory.h
index aa5c8d1d..2fbbbf4c 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -80,7 +80,7 @@ class Inventory
/**
* Returns id of next free slot or -1 if all occupied.
*/
- int getFreeSlot();
+ int getFreeSlot() const;
/**
* Reset all item slots.
@@ -90,12 +90,17 @@ class Inventory
/**
* Get the number of slots filled with an item
*/
- int getNumberOfSlotsUsed();
+ int getNumberOfSlotsUsed() const;
/**
* Returns the index of the last occupied slot or 0 if none occupied.
*/
- int getLastUsedSlot();
+ int getLastUsedSlot() const;
+
+ /**
+ * Returns the number of slots available in the inventory.
+ */
+ int getInventorySize() const;
protected:
Item **mItems; /**< The holder of items */