diff options
author | Aaron Marks <nymacro@gmail.com> | 2005-04-09 12:48:06 +0000 |
---|---|---|
committer | Aaron Marks <nymacro@gmail.com> | 2005-04-09 12:48:06 +0000 |
commit | 0a93e5f7e5170127d63a3d8aecab960ac13cf81f (patch) | |
tree | f32b302fcd3e2b86e4e629e8379617d48df05129 /src | |
parent | 5825ea30189a028006de117bbdc62a6d7acaa919 (diff) | |
download | mana-0a93e5f7e5170127d63a3d8aecab960ac13cf81f.tar.gz mana-0a93e5f7e5170127d63a3d8aecab960ac13cf81f.tar.bz2 mana-0a93e5f7e5170127d63a3d8aecab960ac13cf81f.tar.xz mana-0a93e5f7e5170127d63a3d8aecab960ac13cf81f.zip |
Added better support for inventory (currently its resizable by dragging the top
right of the window).
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/inventory.cpp | 41 | ||||
-rw-r--r-- | src/gui/inventory.h | 4 | ||||
-rw-r--r-- | src/gui/itemcontainer.cpp | 22 |
3 files changed, 53 insertions, 14 deletions
diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp index 21724927..17903ba3 100644 --- a/src/gui/inventory.cpp +++ b/src/gui/inventory.cpp @@ -36,9 +36,15 @@ InventoryWindow::InventoryWindow(): { setContentSize(322, 100); useButton = new Button("Use"); - useButton->setPosition(20, 50); + useButton->setPosition(20, getHeight() - 48); dropButton = new Button("Drop"); - dropButton->setPosition(60, 50); + dropButton->setPosition(60, getHeight() - 48); + + items = new ItemContainer(); + items->setPosition(2, 2); + + invenScroll = new gcn::ScrollArea(items); + invenScroll->setPosition(4, 4); useButton->setEventId("use"); dropButton->setEventId("drop"); @@ -47,11 +53,13 @@ InventoryWindow::InventoryWindow(): add(useButton); add(dropButton); - - items = new ItemContainer(); - items->setSize(318, 40); - items->setPosition(2, 2); - add(items); + add(invenScroll); + + setResizeable(true); + setMinWidth(240); + setMinHeight(96); + + updateWidgets(); } InventoryWindow::~InventoryWindow() @@ -147,3 +155,22 @@ void InventoryWindow::action(const std::string &eventId) } } } + +void InventoryWindow::mouseMotion(int mx, int my) +{ + int tmpWidth = getWidth(), tmpHeight = getHeight(); + Window::mouseMotion(mx, my); + if (getWidth() != tmpWidth || getHeight() != tmpHeight) { + updateWidgets(); + } +} + +void InventoryWindow::updateWidgets() +{ + //resize widgets + useButton->setPosition(20, getHeight() - 48); + dropButton->setPosition(60, getHeight() - 48); + items->setSize(getWidth() - 24 - 12 - 8 - 1, (getHeight() - 40 - 8 - 1) + items->getQuantity() * 24 - 1); + invenScroll->setSize(getWidth() - 32, getHeight() - 48 - 8); + setContentSize(getWidth(), getHeight()); +} diff --git a/src/gui/inventory.h b/src/gui/inventory.h index 591e316e..ab65c122 100644 --- a/src/gui/inventory.h +++ b/src/gui/inventory.h @@ -86,12 +86,16 @@ class InventoryWindow : public Window, gcn::ActionListener { void action(const std::string& eventId); int dropItem(int index, int quantity); + + void mouseMotion(int mx, int my); ItemContainer *items; private: gcn::Button *useButton, *dropButton; + gcn::ScrollArea *invenScroll; int useItem(int index, int id); + void updateWidgets(); }; diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 3f03bbb3..0694fc2e 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -61,24 +61,32 @@ void ItemContainer::draw(gcn::Graphics* graphics) selectedItem = -1; for (int i = 0; i < INVENTORY_SIZE; i++) { + int itemX = (((i - 2) * 24) % (getWidth() - 24)); + int itemY = (((i - 2) * 24) / (getWidth() - 24)) * 24; + itemX -= itemX % 24; if (items[i].quantity > 0) { if (items[i].id >= 501 && items[i].id <= 1202) { itemset->spriteset[items[i].id - 501]->draw(screen, - x + 24 * i, y + 2); - + x + itemX, + y + itemY); } std::stringstream ss; if(!items[i].equipped) ss << items[i].quantity; - graphics->drawText(ss.str(), 24 * i + 10, 24 + 2, - gcn::Graphics::CENTER); + graphics->drawText(ss.str(), + itemX + 12, + itemY + 16, + gcn::Graphics::CENTER); } } if (selectedItem >= 0) { - graphics->drawRectangle(gcn::Rectangle(24 * selectedItem + 1, 2, - 20, 20)); + int itemX = (((selectedItem - 2) * 24) % (getWidth() - 24)); + int itemY = (((selectedItem - 2) * 24) / (getWidth() - 24)) * 24; + itemX -= itemX % 24; + graphics->drawRectangle(gcn::Rectangle(itemX, itemY, + 24, 24)); } } @@ -176,7 +184,7 @@ void ItemContainer::increaseQuantity(int index, int quantity) void ItemContainer::mousePress(int mx, int my, int button) { if (button == gcn::MouseInput::LEFT) - selectedItem = mx / 24; + selectedItem = ((mx + 48) / 24) + ((my / 24) * (getWidth() / 24)); if (selectedItem > INVENTORY_SIZE) selectedItem = INVENTORY_SIZE; } |