diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/gui/itemcontainer.cpp | 19 | ||||
-rw-r--r-- | src/gui/itemcontainer.h | 7 | ||||
-rw-r--r-- | src/inventory.cpp | 13 | ||||
-rw-r--r-- | src/inventory.h | 5 |
5 files changed, 47 insertions, 3 deletions
@@ -1,3 +1,9 @@ +2005-08-01 Björn Steinbrink <B.Steinbrink@gmx.de> + + * src/inventory.cpp, src/inventory.h, + src/gui/itemcontainer.cpp, src/gui/itemcontainer.h: Added a logic function + to dynamically adjust the size of the itemcontainer. + 2005-07-31 Andrej Sinicyn <andrej4000@gmail.com> * src/game.cpp, src/game.h, src/gui/popupmenu.cpp: Show the name of the diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 8fd3a23e..a4e7a7d0 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -41,6 +41,7 @@ ItemContainer::ItemContainer(Inventory *inventory): if (!selImg) logger->error("Unable to load selection.png"); selectedItem = 0; // No item selected + maxItems = inventory->getLastUsedSlot(); addMouseListener(this); } @@ -51,6 +52,18 @@ ItemContainer::~ItemContainer() selImg->decRef(); } +void ItemContainer::logic() +{ + gcn::Widget::logic(); + + int i = inventory->getLastUsedSlot(); + + if (i != maxItems) { + maxItems = i; + setWidth(getWidth()); + } +} + void ItemContainer::draw(gcn::Graphics* graphics) { int gridWidth = itemset->spriteset[0]->getWidth() + 4; @@ -125,7 +138,7 @@ void ItemContainer::setWidth(int width) gcn::Widget::setWidth(width); int gridWidth = itemset->spriteset[0]->getWidth() + 4; - int gridHeight = itemset->spriteset[0]->getHeight() + 10; + int gridHeight = itemset->spriteset[0]->getHeight() + 14; int columns = getWidth() / gridWidth; if (columns < 1) @@ -133,8 +146,8 @@ void ItemContainer::setWidth(int width) columns = 1; } - setHeight(((INVENTORY_SIZE / columns) + - (INVENTORY_SIZE % columns > 0 ? 1 : 0)) * gridHeight); + setHeight(((maxItems / columns) + + (maxItems % columns > 0 ? 1 : 0)) * gridHeight); } Item* ItemContainer::getItem() diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index 6def991a..6c1834ef 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -51,6 +51,11 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener virtual ~ItemContainer(); /** + * Handles the logic of the ItemContainer + */ + void logic(); + + /** * Draws the items. */ void draw(gcn::Graphics *graphics); @@ -81,6 +86,8 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener Spriteset *itemset; Image *selImg; Item *selectedItem; + + int maxItems; }; #endif diff --git a/src/inventory.cpp b/src/inventory.cpp index c0ddd888..30763622 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -132,3 +132,16 @@ int Inventory::getNumberOfSlotsUsed() return NumberOfFilledSlot; } + +int Inventory::getLastUsedSlot() +{ + int i; + + for (i = INVENTORY_SIZE - 1; i >= 0; i--) { + if ((items[i].getId() != -1) && (items[i].getQuantity() > 0)) { + break; + } + } + + return --i; +} diff --git a/src/inventory.h b/src/inventory.h index f5c47c4f..c31f4fd4 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -88,6 +88,11 @@ class Inventory */ int getNumberOfSlotsUsed(); + /** + * Returns the index of the last occupied slot or 0 if none occupied. + */ + int getLastUsedSlot(); + protected: Item items[INVENTORY_SIZE]; /**< The holder of items */ }; |