diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/inventory.cpp | 4 | ||||
-rw-r--r-- | src/gui/item_amount.cpp | 53 | ||||
-rw-r--r-- | src/gui/item_amount.h | 10 | ||||
-rw-r--r-- | src/gui/trade.cpp | 47 | ||||
-rw-r--r-- | src/gui/trade.h | 5 |
5 files changed, 72 insertions, 47 deletions
diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp index 38537eb7..088cb81c 100644 --- a/src/gui/inventory.cpp +++ b/src/gui/inventory.cpp @@ -160,8 +160,9 @@ void InventoryWindow::action(const std::string &eventId) } } else if (eventId == "drop") { - itemAmountWindow->resetAmount(); + itemAmountWindow->setUsage(AMOUNT_ITEM_DROP); itemAmountWindow->setVisible(true); + itemAmountWindow->requestMoveToTop(); } } } @@ -214,4 +215,3 @@ void InventoryWindow::updateWidgets() setContentSize(getWidth(), getHeight()); } - diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index a63d5a8e..7f609a6c 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -80,9 +80,28 @@ ItemAmountWindow::~ItemAmountWindow() { void ItemAmountWindow::resetAmount() { amount = 1; - itemAmountLabel->setCaption("1"); + itemAmountLabel->setCaption("1"); } +void ItemAmountWindow::setUsage(int usage) { + resetAmount(); + switch (usage) { + case AMOUNT_TRADE_ADD: + setCaption("Select amount of items to trade."); + itemAmountOkButton->setEventId("AddTrade"); + break; + case AMOUNT_ITEM_DROP: + setCaption("Select amount of items to drop."); + itemAmountOkButton->setEventId("Drop"); + break; + default: + + break; + } + +} + + void ItemAmountWindow::action(const std::string& eventId) { if (eventId == "Cancel") { @@ -93,6 +112,11 @@ void ItemAmountWindow::action(const std::string& eventId) { inventoryWindow->dropItem(inventoryWindow->items->getIndex(), amount); resetAmount(); setVisible(false); + } else if (eventId == "AddTrade") + { + tradeWindow->tradeItem(inventoryWindow->items->getIndex(), amount); + resetAmount(); + setVisible(false); } else if (eventId == "Plus") { if (amount < inventoryWindow->items->getQuantity()) @@ -108,35 +132,10 @@ void ItemAmountWindow::action(const std::string& eventId) { if (amount > 1) { char tmpminus[128]; - amount = amount - 1; + amount--; sprintf(tmpminus, "%i", amount); itemAmountLabel->setCaption(tmpminus); itemAmountLabel->adjustSize(); } } - - /*WFIFOW(0) = net_w_value(0x00bb); - - if (eventId == "STR") { - WFIFOW(2) = net_w_value(0x000d); - } - if (eventId == "AGI") { - WFIFOW(2) = net_w_value(0x000e); - } - if (eventId == "VIT") { - WFIFOW(2) = net_w_value(0x000f); - } - if (eventId == "INT") { - WFIFOW(2) = net_w_value(0x0010); - } - if (eventId == "DEX") { - WFIFOW(2) = net_w_value(0x0011); - } - if (eventId == "LUK") { - WFIFOW(2) = net_w_value(0x0012); - } - - flush(); - WFIFOW(4) = net_b_value(1); - WFIFOSET(5); */ } diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index c3a06ef1..e0faf5de 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -28,6 +28,9 @@ #include <string> #include <sstream> +#define AMOUNT_TRADE_ADD 1 +#define AMOUNT_ITEM_DROP 2 + class ItemAmountWindow : public Window, public gcn::ActionListener { public: /** @@ -46,13 +49,18 @@ class ItemAmountWindow : public Window, public gcn::ActionListener { void action(const std::string& eventId); /** + * Has to be called before setVisible(true). + */ + void ItemAmountWindow::setUsage(int usage); + + /** * Sets default amount value. */ void resetAmount(); private: /** - * Amount of items to be dropped + * Amount of items to be dropped. */ int amount; diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 859731a3..78d15e3d 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -24,6 +24,7 @@ #include "../main.h" #include "../graphics.h" #include "trade.h" +#include "item_amount.h" #include "../resources/resourcemanager.h" #include "../resources/image.h" #include "button.h" @@ -50,7 +51,7 @@ TradeWindow::TradeWindow(): partnerItems = new ItemContainer(); partnerItems->setPosition(2, 58); - + partnerScroll = new ScrollArea(partnerItems); partnerScroll->setPosition(8, 64); @@ -83,14 +84,18 @@ TradeWindow::TradeWindow(): tradeButton->setPosition(getWidth() - 92, getHeight() - 24); cancelButton->setPosition(getWidth() - 52, getHeight() - 24); - myItems->setSize(getWidth() - 24 - 12 - 1, (INVENTORY_SIZE * 24) / (getWidth() / 24) - 1); + myItems->setSize(getWidth() - 24 - 12 - 1, + (INVENTORY_SIZE * 24) / (getWidth() / 24) - 1); myScroll->setSize(getWidth() - 16, (getHeight() - 76) / 2); - partnerItems->setSize(getWidth() - 24 - 12 - 1, (INVENTORY_SIZE * 24) / (getWidth() / 24) - 1); + partnerItems->setSize(getWidth() - 24 - 12 - 1, + (INVENTORY_SIZE * 24) / (getWidth() / 24) - 1); partnerScroll->setSize(getWidth() - 16, (getHeight() - 76) / 2); - itemNameLabel->setPosition(8, partnerScroll->getY() + partnerScroll->getHeight() + 4); - itemDescriptionLabel->setPosition(8, itemNameLabel->getY() + itemNameLabel->getHeight() + 4); + itemNameLabel->setPosition(8, + partnerScroll->getY() + partnerScroll->getHeight() + 4); + itemDescriptionLabel->setPosition(8, + itemNameLabel->getY() + itemNameLabel->getHeight() + 4); setContentSize(getWidth(), getHeight()); } @@ -180,6 +185,15 @@ void TradeWindow::receivedOk(bool own) { } } +void TradeWindow::tradeItem(int index, int quantity) +{ + WFIFOW(0) = net_w_value(0x00e8); + WFIFOW(2) = net_w_value(index); + WFIFOL(4) = net_l_value(quantity); + WFIFOSET(8); + while ((out_size > 0)) flush(); +} + void TradeWindow::mouseClick(int x, int y, int button, int count) { @@ -197,10 +211,12 @@ void TradeWindow::mouseClick(int x, int y, int button, int count) // Show Name and Description std::string SomeText; - SomeText = "Name: " + itemDb->getItemInfo(myItems->getId())->getName(); + SomeText = "Name: " + + itemDb->getItemInfo(myItems->getId())->getName(); itemNameLabel->setCaption(SomeText); itemNameLabel->adjustSize(); - SomeText = "Description: " + itemDb->getItemInfo(myItems->getId())->getDescription(); + SomeText = "Description: " + + itemDb->getItemInfo(myItems->getId())->getDescription(); itemDescriptionLabel->setCaption(SomeText); itemDescriptionLabel->adjustSize(); } @@ -216,10 +232,12 @@ void TradeWindow::mouseClick(int x, int y, int button, int count) // Show Name and Description std::string SomeText; - SomeText = "Name: " + itemDb->getItemInfo(partnerItems->getId())->getName(); + SomeText = "Name: " + + itemDb->getItemInfo(partnerItems->getId())->getName(); itemNameLabel->setCaption(SomeText); itemNameLabel->adjustSize(); - SomeText = "Description: " + itemDb->getItemInfo(partnerItems->getId())->getDescription(); + SomeText = "Description: " + + itemDb->getItemInfo(partnerItems->getId())->getDescription(); itemDescriptionLabel->setCaption(SomeText); itemDescriptionLabel->adjustSize(); } @@ -233,14 +251,9 @@ void TradeWindow::action(const std::string &eventId) if (inventoryWindow->items->getIndex() >= 0 && inventoryWindow->items->getIndex() <= INVENTORY_SIZE) { if (tradeWindow->myItems->getFreeSlot() >= 0) { - - WFIFOW(0) = net_w_value(0x00e8); - WFIFOW(2) = net_w_value(inventoryWindow->items->getIndex()); - WFIFOL(4) = net_l_value(inventoryWindow->items->getQuantity()); - WFIFOSET(8); - //chatWindow->chat_log("add packet sent", BY_SERVER); - while ((out_size > 0)) flush(); - + itemAmountWindow->setUsage(AMOUNT_TRADE_ADD); + itemAmountWindow->setVisible(true); + itemAmountWindow->requestMoveToTop(); } } } else if (eventId == "cancel") { diff --git a/src/gui/trade.h b/src/gui/trade.h index d977efb4..d1b293cf 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -90,6 +90,11 @@ class TradeWindow : public Window, gcn::ActionListener { void receivedOk(bool own); /** + * Send trade packet. + */ + void TradeWindow::tradeItem(int index, int quantity); + + /** * Called on mouse click. */ void mouseClick(int x, int y, int button, int count); |