summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan-Fabian Humann <malastare@gmx.net>2005-05-12 18:34:52 +0000
committerJan-Fabian Humann <malastare@gmx.net>2005-05-12 18:34:52 +0000
commit308e722a1b3fc34ade98e88b050a024cbd2c9f78 (patch)
treeb7228180c846751ac44d792c415442f77acecdb6 /src
parentabe13c1a2b9338e9a3001128954cc9fb6125ce0f (diff)
downloadmana-client-308e722a1b3fc34ade98e88b050a024cbd2c9f78.tar.gz
mana-client-308e722a1b3fc34ade98e88b050a024cbd2c9f78.tar.bz2
mana-client-308e722a1b3fc34ade98e88b050a024cbd2c9f78.tar.xz
mana-client-308e722a1b3fc34ade98e88b050a024cbd2c9f78.zip
trade fixes as usual + quit dialog pops up now instead of being under other windows
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp2
-rw-r--r--src/game.cpp5
-rw-r--r--src/gui/inventory.cpp4
-rw-r--r--src/gui/item_amount.cpp53
-rw-r--r--src/gui/item_amount.h10
-rw-r--r--src/gui/trade.cpp47
-rw-r--r--src/gui/trade.h5
7 files changed, 76 insertions, 50 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index fc88aff4..52f1d11e 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -200,7 +200,7 @@ Engine::Engine()
screen->h - chargeDialog->getHeight() - 15);
tradeWindow->setPosition(screen->w - statusWindow->getWidth() -
tradeWindow->getWidth() - 10,
- chatWindow->getHeight() + 15);
+ inventoryWindow->getY() + inventoryWindow->getHeight());
buddyWindow->setPosition(10,
minimap->getHeight() + 30);
requestTradeDialog->setPosition(screen->w - statusWindow->getWidth() -
diff --git a/src/game.cpp b/src/game.cpp
index 18ef46a0..1ec08e0c 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -289,6 +289,7 @@ void do_input()
if (event.key.keysym.sym == SDLK_ESCAPE)
{
quitDialog->setVisible(true);
+ quitDialog->requestMoveToTop();
}
if (keysym.sym == SDLK_g && !chatWindow->isFocused())
@@ -815,7 +816,7 @@ void do_parse()
break;
// Trade: Item added on trade partner's side
case 0x00e9:
- // todo:
+ // TODO:
// Maybe also handle identified, etc
// handle zeny as well
@@ -835,7 +836,7 @@ void do_parse()
inventoryWindow->unequipItem(RFIFOW(2));
}
}
-
+ //TODO: Fix this lines (to handle correct quantity)
tradeWindow->addItem(
tradeWindow->myItems->getFreeSlot(),
inventoryWindow->items->getId(RFIFOW(2)),
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);