diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/equipment.cpp | 78 | ||||
-rw-r--r-- | src/gui/equipment.h | 22 | ||||
-rw-r--r-- | src/gui/inventory.cpp | 122 | ||||
-rw-r--r-- | src/gui/inventory.h | 28 | ||||
-rw-r--r-- | src/gui/item_amount.cpp | 6 | ||||
-rw-r--r-- | src/gui/itemcontainer.cpp | 130 | ||||
-rw-r--r-- | src/gui/itemcontainer.h | 83 | ||||
-rw-r--r-- | src/gui/sell.cpp | 13 | ||||
-rw-r--r-- | src/gui/trade.cpp | 100 | ||||
-rw-r--r-- | src/gui/trade.h | 2 | ||||
-rw-r--r-- | src/gui/updatewindow.cpp | 2 |
11 files changed, 187 insertions, 399 deletions
diff --git a/src/gui/equipment.cpp b/src/gui/equipment.cpp index 37623637..dbfc4f8d 100644 --- a/src/gui/equipment.cpp +++ b/src/gui/equipment.cpp @@ -22,16 +22,16 @@ */ #include <guichan.hpp> -#include "equipment.h" +#include "gui/equipment.h" +#include "../equipment.h" #include "../log.h" #include "../resources/resourcemanager.h" -#include "../resources/itemmanager.h" #include "../resources/image.h" #include <sstream> EquipmentWindow::EquipmentWindow(): - Window("Equipment"), arrows(0) + Window("Equipment") { setContentSize(200, 90); setPosition(40, 40); @@ -40,11 +40,6 @@ EquipmentWindow::EquipmentWindow(): Image *itemImg = resman->getImage("graphics/sprites/items.png"); if (!itemImg) logger->error("Unable to load items.png"); itemset = new Spriteset(itemImg, 32, 32); - - for (int i = 0; i < 10; i++ ) { - equipments[i].id = 0; - equipments[i].inventoryIndex = -1; - } } EquipmentWindow::~EquipmentWindow() @@ -59,62 +54,41 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) // Draw window graphics Window::draw(graphics); + Equipment *equipment = Equipment::getInstance(); + Item *item; + Image *image; + for (int i = 0; i < 8; i++) { - if (equipments[i].id > 0) { - Image *image = itemset->spriteset[itemDb->getItemInfo( - equipments[i].id)->getImage() - 1]; - dynamic_cast<Graphics*>(graphics)->drawImage( - image, x + 36 * (i % 4) + 10, y + 36 * (i / 4) + 25); - } graphics->setColor(gcn::Color(0, 0, 0)); graphics->drawRectangle(gcn::Rectangle(10 + 36 * (i % 4), 36 * (i / 4) + 25, 32, 32)); - } - graphics->setColor(gcn::Color(0, 0, 0)); - graphics->drawRectangle(gcn::Rectangle(160, 25, 32, 32)); - if (arrows) { - Image *image = itemset->spriteset[ - itemDb->getItemInfo(arrows)->getImage() - 1]; + if (!(item = equipment->getEquipment(i))) { + continue; + } + + image = itemset->spriteset[item->getInfo()->getImage() - 1]; dynamic_cast<Graphics*>(graphics)->drawImage( - image, x + 160, y + 25); - std::stringstream n; - n << arrowsNumber; - graphics->drawText(n.str(), 170, 62, - gcn::Graphics::CENTER); + image, x + 36 * (i % 4) + 10, y + 36 * (i / 4) + 25); } -} - -void EquipmentWindow::action(const std::string &eventId) -{ -} -void EquipmentWindow::addEquipment(int index, int id) -{ - equipments[index].id = id; -} - -void EquipmentWindow::removeEquipment(int index) -{ - equipments[index].id = 0; -} + graphics->setColor(gcn::Color(0, 0, 0)); + graphics->drawRectangle(gcn::Rectangle(160, 25, 32, 32)); -void EquipmentWindow::setInventoryIndex(int index, int inventoryIndex) -{ - equipments[index].inventoryIndex = inventoryIndex; -} + if (!(item = equipment->getArrows())) { + return; + } -int EquipmentWindow::getInventoryIndex(int index) -{ - return equipments[index].inventoryIndex; -} + image = itemset->spriteset[item->getInfo()->getImage() - 1]; -void EquipmentWindow::setArrows(int id) -{ - arrows = id; + dynamic_cast<Graphics*>(graphics)->drawImage( + image, x + 160, y + 25); + std::stringstream n; + n << item->getQuantity(); + graphics->drawText(n.str(), 170, 62, + gcn::Graphics::CENTER); } -int EquipmentWindow::getArrows() +void EquipmentWindow::action(const std::string &eventId) { - return arrows; } diff --git a/src/gui/equipment.h b/src/gui/equipment.h index 87f543ca..5670d065 100644 --- a/src/gui/equipment.h +++ b/src/gui/equipment.h @@ -27,11 +27,6 @@ #include "../graphic/spriteset.h" #include "window.h" -typedef struct { - int id; - int inventoryIndex; -} EQUIPMENT_HOLDER; - /** * Equipment dialog. * @@ -58,25 +53,8 @@ class EquipmentWindow : public Window, gcn::ActionListener { * Called when receiving actions from the widgets. */ void action(const std::string& eventId); - - void addEquipment(int index, int id); - - void removeEquipment(int index); - - void setInventoryIndex(int index, int inventoryIndex); - - int getInventoryIndex(int index); - void setArrows(int id); - - int getArrows(); - - EQUIPMENT_HOLDER equipments[10]; - - int arrowsNumber; - private: - int arrows; Spriteset *itemset; }; diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp index 73bf67f5..98f17134 100644 --- a/src/gui/inventory.cpp +++ b/src/gui/inventory.cpp @@ -23,12 +23,11 @@ #include "../playerinfo.h" #include "inventory.h" -#include "equipment.h" +#include "../equipment.h" #include "button.h" #include "scrollarea.h" #include "../net/network.h" #include "item_amount.h" -#include "../resources/itemmanager.h" #include <string> InventoryWindow::InventoryWindow(): @@ -97,119 +96,94 @@ void InventoryWindow::logic() weightLabel->adjustSize(); } -int InventoryWindow::addItem(int index, int id, int quantity, bool equipment) -{ - items->addItem(index, id, quantity, equipment); - return 0; -} - -int InventoryWindow::removeItem(int id) -{ - items->removeItem(id); - return 0; -} - -int InventoryWindow::changeQuantity(int index, int quantity) -{ - items->changeQuantity(index, quantity); - return 0; -} - -int InventoryWindow::increaseQuantity(int index, int quantity) -{ - items->increaseQuantity(index, quantity); - return 0; -} - -int InventoryWindow::useItem(int index, int id) +int InventoryWindow::useItem(Item *item) { WFIFOW(0) = net_w_value(0x00a7); - WFIFOW(2) = net_w_value(index); - WFIFOL(4) = net_l_value(id); + WFIFOW(2) = net_w_value(item->getInvIndex()); + WFIFOL(4) = net_l_value(item->getId()); // Note: id is dest of item, usually player_node->account_ID ?? WFIFOSET(8); while ((out_size > 0)) flush(); return 0; } -int InventoryWindow::dropItem(int index, int quantity) +int InventoryWindow::dropItem(Item *item, int quantity) { // TODO: Fix wrong coordinates of drops, serverside? WFIFOW(0) = net_w_value(0x00a2); - WFIFOW(2) = net_w_value(index); + WFIFOW(2) = net_w_value(item->getInvIndex()); WFIFOW(4) = net_w_value(quantity); WFIFOSET(6); while ((out_size > 0)) flush(); return 0; } -void InventoryWindow::equipItem(int index) +void InventoryWindow::equipItem(Item *item) { WFIFOW(0) = net_w_value(0x00a9); - WFIFOW(2) = net_w_value(index); + WFIFOW(2) = net_w_value(item->getInvIndex()); WFIFOW(4) = net_w_value(0); WFIFOSET(6); while ((out_size > 0)) flush(); } -void InventoryWindow::unequipItem(int index) +void InventoryWindow::unequipItem(Item *item) { WFIFOW(0) = net_w_value(0x00ab); - WFIFOW(2) = net_w_value(index); + WFIFOW(2) = net_w_value(item->getInvIndex()); WFIFOSET(4); while ((out_size > 0)) flush(); - + // Tidy equipment directly to avoid weapon still shown bug, by instance - for (int i = 0; i < 8; i++) - { - if ( equipmentWindow->getInventoryIndex(i) == index ) - { - equipmentWindow->removeEquipment(i); - } - } + Equipment::getInstance()->removeEquipment(item); } void InventoryWindow::action(const std::string &eventId) { - int selectedItem = items->getIndex(); - - if (selectedItem != -1) { - if (eventId == "use") { - if (items->isEquipment(selectedItem)) { - if (items->isEquipped(selectedItem)) { - unequipItem(selectedItem); - } - else { - equipItem(selectedItem); - } + Item *item = items->getItem(); + + if (!item) { + return; + } + + if (eventId == "use") { + if (item->isEquipment()) { + if (item->isEquipped()) { + unequipItem(item); } else { - useItem(selectedItem, items->getId()); + equipItem(item); } } - else if (eventId == "drop") - { - // Choose amount of items to drop - new ItemAmountWindow(AMOUNT_ITEM_DROP, this); + else { + useItem(item); } } + else if (eventId == "drop") + { + // Choose amount of items to drop + new ItemAmountWindow(AMOUNT_ITEM_DROP, this); + } } void InventoryWindow::mouseClick(int x, int y, int button, int count) { Window::mouseClick(x, y, button, count); - if (items->getIndex() != -1) - { - // Show Name and Description - std::string SomeText; - SomeText = "Name: " + itemDb->getItemInfo(items->getId())->getName(); - itemNameLabel->setCaption(SomeText); - itemNameLabel->adjustSize(); - SomeText = "Description: " + itemDb->getItemInfo(items->getId())->getDescription(); - itemDescriptionLabel->setCaption(SomeText); - itemDescriptionLabel->adjustSize(); + Item *item = items->getItem(); + + if (!item) { + return; } + + // Show Name and Description + std::string SomeText; + SomeText = "Name: " + item->getInfo()->getName(); + itemNameLabel->setCaption(SomeText); + itemNameLabel->adjustSize(); + SomeText = "Description: " + item->getInfo()->getDescription(); + itemDescriptionLabel->setCaption(SomeText); + itemDescriptionLabel->adjustSize(); } void InventoryWindow::mouseMotion(int mx, int my) @@ -245,9 +219,11 @@ void InventoryWindow::updateWidgets() void InventoryWindow::updateButtons() { - if (items->getIndex() != -1 && items->isEquipment(items->getIndex())) + Item *item; + + if ((item = items->getItem()) && item->isEquipment()) { - if (items->isEquipped(items->getIndex())) { + if (item->isEquipped()) { useButton->setCaption("Unequip"); } else { @@ -258,6 +234,6 @@ void InventoryWindow::updateButtons() useButton ->setCaption("Use"); } - useButton->setEnabled(items->getIndex() != -1); - dropButton->setEnabled(items->getIndex() != -1); + useButton->setEnabled(!!item); + dropButton->setEnabled(!!item); } diff --git a/src/gui/inventory.h b/src/gui/inventory.h index 4fcc6870..e9924ead 100644 --- a/src/gui/inventory.h +++ b/src/gui/inventory.h @@ -51,41 +51,21 @@ class InventoryWindow : public Window, gcn::ActionListener void logic(); /** - * Add an item the inventory. - */ - int addItem(int index, int id, int quantity, bool equipment); - - /** - * Remove a item from the inventory. - */ - int removeItem(int id); - - /** * Equips an item. */ - void equipItem(int index); + void equipItem(Item *item); /** * Unequips an item. */ - void unequipItem(int index); - - /** - * Change quantity of an item. - */ - int changeQuantity(int index, int quantity); - - /** - * Increase quantity of an item. - */ - int increaseQuantity(int index, int quantity); + void unequipItem(Item *item); /** * Called when receiving actions from the widgets. */ void action(const std::string& eventId); - int dropItem(int index, int quantity); + int dropItem(Item *item, int quantity); void mouseClick(int x, int y, int button, int count); @@ -94,7 +74,7 @@ class InventoryWindow : public Window, gcn::ActionListener ItemContainer *items; private: - int useItem(int index, int id); + int useItem(Item *item); void updateWidgets(); /** Updates widgets size/position */ void updateButtons(); /** Updates button states */ diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 036fdc15..021da3eb 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -38,7 +38,7 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent): itemAmountOkButton = new Button("Okay"); itemAmountCancelButton = new Button("Cancel"); - itemAmountTextBox->setRange(1, inventoryWindow->items->getQuantity()); + itemAmountTextBox->setRange(1, inventoryWindow->items->getItem()->getQuantity()); // Set button events Id itemAmountMinusButton->setEventId("Minus"); @@ -108,12 +108,12 @@ void ItemAmountWindow::action(const std::string& eventId) } else if (eventId == "Drop") { - inventoryWindow->dropItem(inventoryWindow->items->getIndex(), itemAmountTextBox->getInt()); + inventoryWindow->dropItem(inventoryWindow->items->getItem(), itemAmountTextBox->getInt()); scheduleDelete(); } else if (eventId == "AddTrade") { - tradeWindow->tradeItem(inventoryWindow->items->getIndex(), itemAmountTextBox->getInt()); + tradeWindow->tradeItem(inventoryWindow->items->getItem(), itemAmountTextBox->getInt()); scheduleDelete(); } else if (eventId == "Plus") diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 534364dc..51780fca 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -26,7 +26,6 @@ #include "../log.h" #include "../graphics.h" #include "../resources/resourcemanager.h" -#include "../resources/itemmanager.h" #include <sstream> ItemContainer::ItemContainer() @@ -40,14 +39,10 @@ ItemContainer::ItemContainer() selImg = resman->getImage("graphics/gui/selection.png"); if (!selImg) logger->error("Unable to load selection.png"); - selectedItem = -1; // No item selected + selectedItem = 0; // No item selected - for (int i = 0; i < INVENTORY_SIZE; i++) - { - items[i].id = -1; - items[i].quantity = 0; - items[i].equipment = false; - items[i].equipped = false; + for (int i = 0; i < INVENTORY_SIZE; i++) { + items[i].setInvIndex(i); } addMouseListener(this); @@ -76,9 +71,9 @@ void ItemContainer::draw(gcn::Graphics* graphics) // Reset selected item when quantity not above 0 (should probably be made // sure somewhere else) - if (items[selectedItem].quantity <= 0) + if (selectedItem && selectedItem->getQuantity() <= 0) { - selectedItem = -1; + selectedItem = 0; } /* @@ -87,32 +82,31 @@ void ItemContainer::draw(gcn::Graphics* graphics) */ for (int i = 2; i < INVENTORY_SIZE; i++) { - if (items[i].quantity > 0) + if (items[i].getQuantity() > 0) { int itemX = ((i - 2) % columns) * gridWidth; int itemY = ((i - 2) / columns) * gridHeight; // Draw selection image below selected item - if (selectedItem == i) + if (selectedItem == &items[i]) { dynamic_cast<Graphics*>(graphics)->drawImage( selImg, x + itemX, y + itemY); } // Draw item icon - if (itemDb->getItemInfo(items[i].id)->getImage() > 0) + int idx; + if ((idx = items[i].getInfo()->getImage()) > 0) { - Image *image = itemset->spriteset[itemDb->getItemInfo( - items[i].id)->getImage() - 1]; dynamic_cast<Graphics*>(graphics)->drawImage( - image, x + itemX, y + itemY); + itemset->spriteset[idx - 1], x + itemX, y + itemY); } // Draw item caption std::stringstream ss; - if (!items[i].equipped) { - ss << items[i].quantity; + if (!items[i].isEquipped()) { + ss << items[i].getQuantity(); } else { ss << "Eq."; @@ -143,63 +137,37 @@ void ItemContainer::setWidth(int width) (INVENTORY_SIZE % columns > 0 ? 1 : 0)) * gridHeight); } -int ItemContainer::getIndex() -{ - return selectedItem; -} - int ItemContainer::getIndex(int id) { for (int i = 0; i < INVENTORY_SIZE; i++) { - if (items[i].id == id) { + if (items[i].getId() == id) { return i; } } return -1; } -int ItemContainer::getId() -{ - if (selectedItem != -1) { - return items[selectedItem].id; - } - else { - return 0; - } -} - -int ItemContainer::getId(int index) -{ - return items[index].id; -} - -int ItemContainer::getQuantity() +Item* ItemContainer::getItem() { - if (selectedItem != -1) { - return items[selectedItem].quantity; - } - else { - return 0; - } - + return selectedItem; } -int ItemContainer::getQuantity(int index) +Item* ItemContainer::getItem(int index) { - return items[index].quantity; + return &items[index]; } void ItemContainer::addItem(int index, int id, int quantity, bool equipment) { - items[index].id = id; - items[index].quantity += quantity; - items[index].equipment = equipment; + items[index].setId(id); + items[index].increaseQuantity(quantity); + items[index].setEquipment(equipment); } int ItemContainer::getFreeSlot() { for (int i = 2; i < INVENTORY_SIZE; i++) { - if (items[i].id == -1) { + if (items[i].getId() == -1) { return i; } } @@ -209,37 +177,27 @@ int ItemContainer::getFreeSlot() void ItemContainer::resetItems() { for (int i = 0; i < INVENTORY_SIZE; i++) { - items[i].id = -1; - items[i].quantity = 0; - items[i].equipped = false; + items[i].setId(-1); + items[i].setQuantity(0); + items[i].setEquipped(false); } } void ItemContainer::selectNone() { - selectedItem = -1; + selectedItem = 0; } void ItemContainer::removeItem(int id) { for (int i = 0; i < INVENTORY_SIZE; i++) { - if (items[i].id == id) { - items[i].id = -1; - items[i].quantity = 0; + if (items[i].getId() == id) { + items[i].setId(-1); + items[i].setQuantity(0); } } } -void ItemContainer::changeQuantity(int index, int quantity) -{ - items[index].quantity = quantity; -} - -void ItemContainer::increaseQuantity(int index, int quantity) -{ - items[index].quantity += quantity; -} - void ItemContainer::mousePress(int mx, int my, int button) { int gridWidth = itemset->spriteset[0]->getWidth() + 4; @@ -249,41 +207,21 @@ void ItemContainer::mousePress(int mx, int my, int button) if (button == gcn::MouseInput::LEFT) { - selectedItem = mx / gridWidth + ((my / gridHeight) * columns) + 2; - } + int index = mx / gridWidth + ((my / gridHeight) * columns) + 2; - if (selectedItem > INVENTORY_SIZE) - { - selectedItem = INVENTORY_SIZE; + if (index > INVENTORY_SIZE) { + index = INVENTORY_SIZE - 1; + } + selectedItem = &items[index]; } } -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; -} - -void ItemContainer::setEquipment(int index, bool equipment) -{ - items[index].equipment = equipment; -} - int ItemContainer::getNumberOfSlotsUsed() { int NumberOfFilledSlot = 0; for (int i = 0; i < INVENTORY_SIZE; i++) { - if (items[i].id > -1 || items[i].quantity > 0) + if (items[i].getId() > -1 || items[i].getQuantity() > 0) { NumberOfFilledSlot++; } diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h index a0e3b79a..6e72eba0 100644 --- a/src/gui/itemcontainer.h +++ b/src/gui/itemcontainer.h @@ -26,36 +26,22 @@ #include <iostream> #include <guichan.hpp> + +#include "../item.h" + +#include "../item.h" #include "../resources/image.h" #include "../graphic/spriteset.h" #define INVENTORY_SIZE 100 /** - * The holder of a item. - */ -struct ITEM_HOLDER -{ - int id; /**< The id of the item */ - int quantity; /**< The number of items */ - bool equipment; /**< Whether this item is equipment */ - bool equipped; /**< Whether this item is equipped */ -}; - -/** * An item container. Used to show items in inventory and trade dialog. * * \ingroup GUI */ class ItemContainer : public gcn::Widget, public gcn::MouseListener { - private: - Spriteset *itemset; - Image *selImg; - int selectedItem; - int itemNumber; - ITEM_HOLDER items[INVENTORY_SIZE]; /**< The holder of items */ - public: /** * Constructor. Initializes the graphic. @@ -84,34 +70,19 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener void mousePress(int mx, int my, int button); /** - * Returns index of the selected item. - */ - int getIndex(); - - /** * Finds the index of an item. */ int getIndex(int id); /** - * Returns the id of the selected item. - */ - int getId(); - - /** - * Returns the id of an item. + * Returns the selected item. */ - int getId(int index); + Item* getItem(); /** - * Returns the quantity of the selected item. + * Returns the item at the specified index. */ - int getQuantity(); - - /** - * Returns the quantity of an item. - */ - int getQuantity(int index); + Item* getItem(int index); /** * Returns id of next free slot or -1 if all occupied. @@ -139,39 +110,17 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener void removeItem(int id); /** - * Change quantity of an item. - */ - void changeQuantity(int index, int quantity); - - /** - * Increase quantity of an item. - */ - void increaseQuantity(int index, int quantity); - - /** - * Returns whether the item at the specified index is equipment. - */ - bool isEquipment(int index); - - /** - * Returns whether the item at the specified index is equipped. - */ - bool isEquipped(int index); - - /** - * Sets whether the item at the specified index is equipped. - */ - void setEquipped(int index, bool equipped); - - /** - * Sets whether the item at the specified index is equipment. - */ - void setEquipment(int index, bool equipment); - - /** * Get the number of slots filled with an item */ int getNumberOfSlotsUsed(); + + private: + Spriteset *itemset; + Image *selImg; + Item *selectedItem; + int itemNumber; + Item items[INVENTORY_SIZE]; /**< The holder of items */ + }; #endif diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 5693e091..5ce56438 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -29,7 +29,6 @@ #include "listbox.h" #include "../game.h" #include "../net/network.h" -#include "../resources/itemmanager.h" #include <sstream> @@ -91,15 +90,19 @@ void SellDialog::reset() void SellDialog::addItem(short index, int price) { - int id = inventoryWindow->items->getId(index); + Item *item = inventoryWindow->items->getItem(index); + + if (!item) + return; + ITEM_SHOP item_shop; sprintf(item_shop.name, "%s %i gp", - itemDb->getItemInfo(id)->getName().c_str(), price); + item->getInfo()->getName().c_str(), price); item_shop.price = price; item_shop.index = index; - item_shop.id = id; - item_shop.quantity = inventoryWindow->items->getQuantity(index); + item_shop.id = item->getId();; + item_shop.quantity = item->getQuantity(); shopInventory.push_back(item_shop); itemList->adjustSize(); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 4516400f..ddf9bc0f 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -30,7 +30,6 @@ #include "scrollarea.h" #include "textfield.h" #include "../net/network.h" -#include "../resources/itemmanager.h" #include <sstream> TradeWindow::TradeWindow(): @@ -164,18 +163,18 @@ void TradeWindow::removeItem(int id, bool own) void TradeWindow::changeQuantity(int index, bool own, int quantity) { if (own) { - myItems->changeQuantity(index, quantity); + myItems->getItem(index)->setQuantity(quantity); } else { - partnerItems->changeQuantity(index, quantity); + partnerItems->getItem(index)->setQuantity(quantity); } } void TradeWindow::increaseQuantity(int index, bool own, int quantity) { if (own) { - myItems->increaseQuantity(index, quantity); + myItems->getItem(index)->increaseQuantity(quantity); } else { - partnerItems->increaseQuantity(index, quantity); + partnerItems->getItem(index)->increaseQuantity(quantity); } } @@ -220,10 +219,10 @@ void TradeWindow::receivedOk(bool own) } } -void TradeWindow::tradeItem(int index, int quantity) +void TradeWindow::tradeItem(Item *item, int quantity) { WFIFOW(0) = net_w_value(0x00e8); - WFIFOW(2) = net_w_value(index); + WFIFOW(2) = net_w_value(item->getInvIndex()); WFIFOL(4) = net_l_value(quantity); WFIFOSET(8); while ((out_size > 0)) flush(); @@ -231,75 +230,66 @@ void TradeWindow::tradeItem(int index, int quantity) void TradeWindow::mouseClick(int x, int y, int button, int count) { - Window::mouseClick(x, y, button, count); + Item *item; + // myItems selected if (x >= myScroll->getX() + 3 && x <= myScroll->getX() + myScroll->getWidth() - 10 && y >= myScroll->getY() + 16 - && y <= myScroll->getY() + myScroll->getHeight() + 15) + && y <= myScroll->getY() + myScroll->getHeight() + 15 + && (item = myItems->getItem())) { - if (myItems->getIndex() != -1) - { partnerItems->selectNone(); - - // Show Name and Description - std::string SomeText; - SomeText = "Name: " + - itemDb->getItemInfo(myItems->getId())->getName(); - itemNameLabel->setCaption(SomeText); - itemNameLabel->adjustSize(); - SomeText = "Description: " + - itemDb->getItemInfo(myItems->getId())->getDescription(); - itemDescriptionLabel->setCaption(SomeText); - itemDescriptionLabel->adjustSize(); - } // partnerItems selected } else if (x >= partnerScroll->getX() + 3 && x <= partnerScroll->getX() + partnerScroll->getWidth() - 20 && y >= partnerScroll->getY() + 16 - && y <= partnerScroll->getY() + partnerScroll->getHeight() + 15) + && y <= partnerScroll->getY() + partnerScroll->getHeight() + 15 + && (item = partnerItems->getItem())) { - if (partnerItems->getIndex() != -1) - { myItems->selectNone(); - - // Show Name and Description - std::string SomeText; - SomeText = "Name: " + - itemDb->getItemInfo(partnerItems->getId())->getName(); - itemNameLabel->setCaption(SomeText); - itemNameLabel->adjustSize(); - SomeText = "Description: " + - itemDb->getItemInfo(partnerItems->getId())->getDescription(); - itemDescriptionLabel->setCaption(SomeText); - itemDescriptionLabel->adjustSize(); - } + } else { + return; } + + // Show Name and Description + std::string SomeText; + SomeText = "Name: " + item->getInfo()->getName(); + itemNameLabel->setCaption(SomeText); + itemNameLabel->adjustSize(); + SomeText = "Description: " + item->getInfo()->getDescription(); + itemDescriptionLabel->setCaption(SomeText); + itemDescriptionLabel->adjustSize(); } void TradeWindow::action(const std::string &eventId) { + Item *item = inventoryWindow->items->getItem(); + if (eventId == "add") { - if (inventoryWindow->items->getIndex() >= 0 && - inventoryWindow->items->getIndex() <= INVENTORY_SIZE) { - if (tradeWindow->myItems->getFreeSlot() >= 0) { - if (tradeWindow->myItems->getIndex( - inventoryWindow->items->getId()) == -1) { - if (inventoryWindow->items->getQuantity() == 1) { - tradeItem(inventoryWindow->items->getIndex(), 1); - } - else { - // Choose amount of items to trade - new ItemAmountWindow(AMOUNT_TRADE_ADD, this); - } - } else { - chatWindow->chat_log("Failed adding item. You can not " - "overlap one kind of item on the window.", BY_SERVER); - } - } + if (!item) { + return; + } + + if (tradeWindow->myItems->getFreeSlot() < 1) { + return; + } + + if (myItems->getIndex(item->getId()) != -1) { + chatWindow->chat_log("Failed adding item. You can not " + "overlap one kind of item on the window.", BY_SERVER); + return; + } + + if (item->getQuantity() == 1) { + tradeItem(item, 1); + } + else { + // Choose amount of items to trade + new ItemAmountWindow(AMOUNT_TRADE_ADD, this); } } else if (eventId == "cancel") diff --git a/src/gui/trade.h b/src/gui/trade.h index 5b824548..6132a182 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -89,7 +89,7 @@ class TradeWindow : public Window, gcn::ActionListener /** * Send trade packet. */ - void TradeWindow::tradeItem(int index, int quantity); + void TradeWindow::tradeItem(Item *item, int quantity); /** * Called on mouse click. diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 7c925077..4911261e 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -211,7 +211,7 @@ int downloadThread(void *ptr) if (memoryTransfer) { downloadedBytes = 0; - curl_easy_setopt(curl, CURLOPT_FAILONERROR, TRUE); + curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, memoryWrite); curl_easy_setopt(curl, CURLOPT_WRITEDATA, NULL); } |