From 1d6113f5306923c162a5d770ba268103a732e06b Mon Sep 17 00:00:00 2001 From: Eugenio Favalli Date: Sun, 6 Feb 2005 14:37:26 +0000 Subject: Completed inventory fix, now selection works --- The Mana World.dev | 10 +++---- src/gui/inventory.cpp | 77 +++++++++++++-------------------------------------- src/gui/inventory.h | 20 ++----------- src/gui/sell.cpp | 4 +-- 4 files changed, 30 insertions(+), 81 deletions(-) diff --git a/The Mana World.dev b/The Mana World.dev index 4565b425..dd92f4e5 100644 --- a/The Mana World.dev +++ b/The Mana World.dev @@ -1,7 +1,7 @@ [Project] FileName=The Mana World.dev Name=tmw -UnitCount=94 +UnitCount=96 Type=0 Ver=1 ObjFiles= @@ -977,9 +977,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit95] -FileName=src\graphic\spriteset.cpp +FileName=src\gui\itemcontainer.h CompileCpp=1 -Folder=graphic +Folder=gui Compile=1 Link=1 Priority=1000 @@ -987,9 +987,9 @@ OverrideBuildCmd=0 BuildCmd= [Unit96] -FileName=src\graphic\spriteset.h +FileName=src\gui\itemcontainer.cpp CompileCpp=1 -Folder=graphic +Folder=gui Compile=1 Link=1 Priority=1000 diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp index 08a308df..259f728d 100644 --- a/src/gui/inventory.cpp +++ b/src/gui/inventory.cpp @@ -44,19 +44,14 @@ InventoryWindow::InventoryWindow(): dropButton->addActionListener(this); add(useButton); - add(dropButton); - - ResourceManager *resman = ResourceManager::getInstance(); - Image *itemImg = resman->getImage("graphic/items.bmp"); - if (!itemImg) error("Unable to load items.bmp"); - itemset = new Spriteset(itemImg, 20, 20); + add(dropButton); + + items = new ItemContainer(); + items->setSize(318, 40); + items->setPosition(2, 2); + add(items); - for (int i = 0; i < INVENTORY_SIZE; i++) { - items[i].id = -1; - items[i].quantity = 0; - } - selectedItem = 4; /**< No item selected */ } InventoryWindow::~InventoryWindow() @@ -67,61 +62,38 @@ InventoryWindow::~InventoryWindow() void InventoryWindow::draw(gcn::Graphics *graphics) { - int x, y; - getAbsolutePosition(x, y); - - if(items[selectedItem].quantity <= 0) - selectedItem = -1; - // Draw window graphics Window::draw(graphics); - - for (int i = 0; i < INVENTORY_SIZE; i++) { - if (items[i].quantity > 0) { - if (items[i].id >= 501 && items[i].id <= 511) { - itemset->spriteset[items[i].id - 501]->draw(screen, - x + 24 * i, - y + 26); - } - - std::stringstream ss; - ss << items[i].quantity; - graphics->drawText(ss.str(), 24 * i + 10, 54, - gcn::Graphics::CENTER); - } - } - - if (selectedItem >= 0) { - graphics->drawRectangle(gcn::Rectangle(24 * selectedItem + 1, 26, - 22, 22)); - } - } int InventoryWindow::addItem(int index, int id, int quantity) { - items[index].id = id; - items[index].quantity += quantity; + /*items[index].id = id; + items[index].quantity += quantity;*/ + items->addItem(index, id, quantity); return 0; } int InventoryWindow::removeItem(int id) { - for (int i = 0; i < INVENTORY_SIZE; i++) { + /*for (int i = 0; i < INVENTORY_SIZE; i++) { if (items[i].id == id) { items[i].id = -1; items[i].quantity = 0; } - } + }*/ + items->removeItem(id); return 0; } int InventoryWindow::changeQuantity(int index, int quantity) { - items[index].quantity = quantity; + //items[index].quantity = quantity; + items->changeQuantity(index, quantity); return 0; } int InventoryWindow::increaseQuantity(int index, int quantity) { - items[index].quantity += quantity; + //items[index].quantity += quantity; + items->increaseQuantity(index, quantity); return 0; } @@ -146,22 +118,13 @@ int InventoryWindow::dropItem(int index, int quantity) { void InventoryWindow::action(const std::string &eventId) { - if(selectedItem >= 0 && selectedItem <= INVENTORY_SIZE) { + //if(selectedItem >= 0 && selectedItem <= INVENTORY_SIZE) { + if (items->getIndex() != -1) { if (eventId == "use") { - useItem(selectedItem, items[selectedItem].id); + useItem(items->getIndex(), items->getId()); } else if (eventId == "drop") { - dropItem(selectedItem, items[selectedItem].quantity); + dropItem(items->getIndex(), items->getQuantity()); // Temp: drop all the items, you should choose quantity instead } } } - -void InventoryWindow::mousePress(int mx, int my, int button) { - if (button == gcn::MouseInput::LEFT) - selectedItem = mx / 24; - if (selectedItem > INVENTORY_SIZE) - selectedItem = INVENTORY_SIZE; - - Window::mousePress(mx, my, button); -} - diff --git a/src/gui/inventory.h b/src/gui/inventory.h index 4248bfdb..e48d5477 100644 --- a/src/gui/inventory.h +++ b/src/gui/inventory.h @@ -27,17 +27,10 @@ #include "../log.h" #include "../net/network.h" #include "../graphic/spriteset.h" +#include "itemcontainer.h" #include "gui.h" #include "window.h" -#define INVENTORY_SIZE 12 - -struct ITEM_HOLDER { // the holder of a item - int id; // the id of the item - int quantity; // number of items - //int index; // item position -}; - /** * Inventory dialog. * @@ -85,20 +78,13 @@ class InventoryWindow : public Window, gcn::ActionListener { */ void action(const std::string& eventId); - /** - * Handles mouse events - */ - void mousePress(int mx, int my, int button); - - ITEM_HOLDER items[INVENTORY_SIZE]; /**< this is the holder of items */ - + ItemContainer *items; + private: gcn::Button *useButton, *dropButton; int useItem(int index, int id); int dropItem(int index, int amunt); - Spriteset *itemset; - int selectedItem; }; #endif diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index d24daff3..b914d814 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -85,7 +85,7 @@ void SellDialog::reset() void SellDialog::addItem(short index, int price) { - int id = inventoryWindow->items[index].id; + int id = inventoryWindow->items->getId(index); ITEM_SHOP item_shop; if (id >= 501 && id <= 511) { @@ -97,7 +97,7 @@ void SellDialog::addItem(short index, int price) item_shop.price = price; item_shop.index = index; item_shop.id = id; - item_shop.quantity = inventoryWindow->items[index].quantity; + item_shop.quantity = inventoryWindow->items->getQuantity(index); shopInventory.push_back(item_shop); itemList->adjustSize(); -- cgit v1.2.3-70-g09d2