diff options
author | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-02-20 11:32:50 +0000 |
---|---|---|
committer | Eugenio Favalli <elvenprogrammer@gmail.com> | 2005-02-20 11:32:50 +0000 |
commit | 3135c725cc37251943271cd8f939e646c9164259 (patch) | |
tree | 159ae31b1c0518d37f5bb21344fe3c72bf5cc382 /src/gui | |
parent | 54a359f67da79d97df667299ea4d91cef79c08f2 (diff) | |
download | mana-client-3135c725cc37251943271cd8f939e646c9164259.tar.gz mana-client-3135c725cc37251943271cd8f939e646c9164259.tar.bz2 mana-client-3135c725cc37251943271cd8f939e646c9164259.tar.xz mana-client-3135c725cc37251943271cd8f939e646c9164259.zip |
Finally equipment! Sometimes it works :P
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/equipment.cpp | 28 | ||||
-rw-r--r-- | src/gui/equipment.h | 8 | ||||
-rw-r--r-- | src/gui/inventory.cpp | 19 | ||||
-rw-r--r-- | src/gui/inventory.h | 1 | ||||
-rw-r--r-- | src/gui/itemcontainer.cpp | 24 | ||||
-rw-r--r-- | src/gui/itemcontainer.h | 10 |
6 files changed, 86 insertions, 4 deletions
diff --git a/src/gui/equipment.cpp b/src/gui/equipment.cpp index c34a9b30..ccc4d403 100644 --- a/src/gui/equipment.cpp +++ b/src/gui/equipment.cpp @@ -29,10 +29,17 @@ EquipmentWindow::EquipmentWindow(): Window("Equipment") { - setSize(300, 300); + setSize(70, 200); setPosition(40, 40); + ResourceManager *resman = ResourceManager::getInstance(); + Image *itemImg = resman->getImage("core/graphics/sprites/items.png"); + if (!itemImg) error("Unable to load items.png"); + itemset = new Spriteset(itemImg, 20, 20); + for (int i = 0; i < 10; i++ ) { + equipments[i] = 0; + } } EquipmentWindow::~EquipmentWindow() @@ -41,10 +48,29 @@ EquipmentWindow::~EquipmentWindow() void EquipmentWindow::draw(gcn::Graphics *graphics) { + int x, y; + getAbsolutePosition(x, y); + // Draw window graphics Window::draw(graphics); + + for (int i = 0; i < 10; i++) { + if (equipments[i] > 0) { + itemset->spriteset[equipments[i] - 501]->draw(screen, + x + 20, y + 24 * i); + } + } } void EquipmentWindow::action(const std::string &eventId) { } + +void EquipmentWindow::addEquipment(int index, int id) { + equipments[index] = id; +} + +void EquipmentWindow::removeEquipment(int index) { + equipments[index] = 0; +} + diff --git a/src/gui/equipment.h b/src/gui/equipment.h index b1b4269b..79f229d4 100644 --- a/src/gui/equipment.h +++ b/src/gui/equipment.h @@ -55,7 +55,15 @@ class EquipmentWindow : public Window, gcn::ActionListener { */ void action(const std::string& eventId); + void addEquipment(int index, int id); + + void removeEquipment(int index); + + int equipments[10]; + private: + + Spriteset *itemset; }; diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp index db5dfb54..67d6fecb 100644 --- a/src/gui/inventory.cpp +++ b/src/gui/inventory.cpp @@ -124,13 +124,28 @@ void InventoryWindow::equipItem(int index) { while ((out_size > 0)) flush(); } +void InventoryWindow::unequipItem(int index) { + WFIFOW(0) = net_w_value(0x00ab); + WFIFOW(2) = net_w_value(index); + WFIFOSET(4); + while ((out_size > 0)) flush(); + +} + void InventoryWindow::action(const std::string &eventId) { //if(selectedItem >= 0 && selectedItem <= INVENTORY_SIZE) { if (items->getIndex() != -1) { if (eventId == "use") { if(items->isEquipment(items->getIndex())) { - equipItem(items->getIndex()); + if(items->isEquipped(items->getIndex())) { + unequipItem(items->getIndex()); + std::cout << "Blah\n"; + + } + else { + equipItem(items->getIndex()); + } } else { useItem(items->getIndex(), items->getId()); @@ -138,7 +153,7 @@ void InventoryWindow::action(const std::string &eventId) } else if (eventId == "drop") { dropItem(items->getIndex(), items->getQuantity()); - // Temp: drop all the items, you should choose quantity instead + // TODO: now drop all the items, you should choose quantity instead } } } diff --git a/src/gui/inventory.h b/src/gui/inventory.h index 178c8019..f97a9b83 100644 --- a/src/gui/inventory.h +++ b/src/gui/inventory.h @@ -86,6 +86,7 @@ class InventoryWindow : public Window, gcn::ActionListener { gcn::Button *useButton, *dropButton; int useItem(int index, int id); int dropItem(int index, int quantity); + void unequipItem(int index); }; diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 0bd236e2..195f9188 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -38,6 +38,7 @@ ItemContainer::ItemContainer() items[i].id = -1; items[i].quantity = 0; items[i].equipment = false; + items[i].equipped = false; } } @@ -66,7 +67,8 @@ void ItemContainer::draw(gcn::Graphics* graphics) } std::stringstream ss; - ss << items[i].quantity; + if(!items[i].equipped) + ss << items[i].quantity; graphics->drawText(ss.str(), 24 * i + 10, 24 + 2, gcn::Graphics::CENTER); } @@ -83,6 +85,16 @@ int ItemContainer::getIndex() return selectedItem; } +int ItemContainer::getIndex(int id) +{ + for (int i = 0; i < INVENTORY_SIZE; i++) { + if (items[i].id == id) { + return i; + } + } + return -1; +} + int ItemContainer::getId() { if (selectedItem != -1) { @@ -161,3 +173,13 @@ bool ItemContainer::isEquipment(int index) { return items[index].equipment; } + +bool ItemContainer::isEquipped(int index) +{ + return items[index].equipped; +} + +void ItemContainer::setEquipped(int index, bool equipped) +{ + items[index].equipped = equipped; +} diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index 69e59149..5f7b6cbe 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -35,6 +35,7 @@ struct ITEM_HOLDER { // the holder of a item int id; // the id of the item int quantity; // number of items bool equipment; + bool equipped; }; /** @@ -80,6 +81,11 @@ class ItemContainer : public gcn::Widget int getIndex(); /** + * Finds the index of an item. + */ + int getIndex(int id); + + /** * Returns the id of the selected item. */ int getId(); @@ -122,6 +128,10 @@ class ItemContainer : public gcn::Widget void _mouseInputMessage(const gcn::MouseInput &mouseInput); bool isEquipment(int index); + + bool isEquipped(int index); + + void setEquipped(int index, bool equipped); }; #endif |