diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-06-05 19:16:37 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-06-05 19:16:37 +0000 |
commit | 7e32d2c5d49b44aae5a9581b2804a05d03490757 (patch) | |
tree | 9fd21e249ea27b8f7db79f8fd3a6cd243bab09bb /src/gui | |
parent | 53b96e03b7a5ac2f62171db328df543de908d9e3 (diff) | |
download | mana-7e32d2c5d49b44aae5a9581b2804a05d03490757.tar.gz mana-7e32d2c5d49b44aae5a9581b2804a05d03490757.tar.bz2 mana-7e32d2c5d49b44aae5a9581b2804a05d03490757.tar.xz mana-7e32d2c5d49b44aae5a9581b2804a05d03490757.zip |
Item icons now displayed as 32x32.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/inventory.h | 6 | ||||
-rw-r--r-- | src/gui/itemcontainer.cpp | 75 |
2 files changed, 50 insertions, 31 deletions
diff --git a/src/gui/inventory.h b/src/gui/inventory.h index 969424fb..a035ee50 100644 --- a/src/gui/inventory.h +++ b/src/gui/inventory.h @@ -30,7 +30,6 @@ #include "itemcontainer.h" #include "gui.h" #include "window.h" -#include "scrollarea.h" /** * Inventory dialog. @@ -99,13 +98,12 @@ class InventoryWindow : public Window, gcn::ActionListener ItemContainer *items; private: - gcn::Button *useButton, *dropButton; - ScrollArea *invenScroll; - int useItem(int index, int id); void updateWidgets(); /** Updates widgets size/position */ void updateButtons(); /** Updates button states */ + gcn::Button *useButton, *dropButton; + gcn::ScrollArea *invenScroll; gcn::Label *itemNameLabel; gcn::Label *itemDescriptionLabel; gcn::Label *weightLabel; diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index d571f739..2cc6b8e2 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -31,7 +31,7 @@ ItemContainer::ItemContainer() ResourceManager *resman = ResourceManager::getInstance(); Image *itemImg = resman->getImage("graphics/sprites/items.png", IMG_ALPHA); if (!itemImg) logger->error("Unable to load items.png"); - itemset = new Spriteset(itemImg, 20, 20); + itemset = new Spriteset(itemImg, 32, 32); itemImg->decRef(); selImg = resman->getImage("graphics/gui/selection.png", IMG_ALPHA); @@ -57,45 +57,58 @@ ItemContainer::~ItemContainer() void ItemContainer::draw(gcn::Graphics* graphics) { - int x, y, w, h; + int gridWidth = itemset->spriteset[0]->getWidth() + 4; + int gridHeight = itemset->spriteset[0]->getHeight() + 10; + int w = getWidth(); + int columns = w / gridWidth; + int x, y; getAbsolutePosition(x, y); - w = getWidth(); - h = getHeight(); - int itemWidth = getWidth() / 24; - - if (items[selectedItem].quantity <= 0) { + // Reset selected item when quantity not above 0 (should probably be made + // sure somewhere else) + if (items[selectedItem].quantity <= 0) + { selectedItem = -1; } - if (selectedItem >= 0) { - int itemX = ((selectedItem - 2) % itemWidth) * 24; - int itemY = ((selectedItem - 2) / itemWidth) * 24; - - itemX -= itemX % 24; - selImg->draw(screen, x + itemX, y+itemY); - } + /* + * eAthena seems to start inventory from the 3rd slot. Still a mystery to + * us why, make sure not to copy this oddity to our own server. + */ + for (int i = 2; i < INVENTORY_SIZE; i++) + { + if (items[i].quantity > 0) + { + int itemX = ((i - 2) % columns) * gridWidth; + int itemY = ((i - 2) / columns) * gridHeight; - for (int i = 0; i < INVENTORY_SIZE; i++) { - int itemX = ((i - 2) % itemWidth) * 24; - int itemY = ((i - 2) / itemWidth) * 24; + // Draw selection image below selected item + if (selectedItem == i) + { + selImg->draw(screen, x + itemX, y + itemY); + } - itemX -= itemX % 24; - if (items[i].quantity > 0) { - if (itemDb->getItemInfo(items[i].id)->getImage() > 0) { + // Draw item icon + if (itemDb->getItemInfo(items[i].id)->getImage() > 0) + { itemset->spriteset[itemDb->getItemInfo( items[i].id)->getImage() - 1]->draw( screen, x + itemX, y + itemY); } + // Draw item caption std::stringstream ss; - if(!items[i].equipped) + + if (!items[i].equipped) { ss << items[i].quantity; - else + } + else { ss << "Eq."; + } + graphics->drawText(ss.str(), - itemX + 12, - itemY + 16, + itemX + gridWidth / 2, + itemY + gridHeight - 11, gcn::Graphics::CENTER); } } @@ -199,10 +212,18 @@ void ItemContainer::increaseQuantity(int index, int quantity) void ItemContainer::mousePress(int mx, int my, int button) { - if (button == gcn::MouseInput::LEFT) { - selectedItem = ((mx + 48) / 24) + ((my / 24) * (getWidth() / 24)); + int gridWidth = itemset->spriteset[0]->getWidth() + 4; + int gridHeight = itemset->spriteset[0]->getHeight() + 10; + int w = getWidth(); + int columns = w / gridWidth; + + if (button == gcn::MouseInput::LEFT) + { + selectedItem = mx / gridWidth + ((my / gridHeight) * columns) + 2; } - if (selectedItem > INVENTORY_SIZE) { + + if (selectedItem > INVENTORY_SIZE) + { selectedItem = INVENTORY_SIZE; } } |