summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp24
-rw-r--r--src/gui/trade.cpp63
-rw-r--r--src/gui/trade.h13
3 files changed, 96 insertions, 4 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 3082ff05..40118805 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -799,6 +799,8 @@ void do_parse() {
break;
// Trade: Item add response
case 0x00ea:
+ tradeWindow->setTradeButton(false);
+ //chatWindow->chat_log("add response got", BY_SERVER);
switch (RFIFOB(4)) {
case 0:
// Successfully added item
@@ -827,13 +829,32 @@ void do_parse() {
break;
}
break;
-
+ // Trade: Received Ok message
+ case 0x00ec:
+ switch (RFIFOB(2)) {
+ // Received ok from myself
+ case 0:
+ tradeWindow->receivedOk(true);
+ break;
+ // Received ok from the other
+ case 1:
+ tradeWindow->receivedOk(false);
+ break;
+ }
+ break;
// Trade: Trade cancelled
case 0x00ee:
chatWindow->chat_log("Trade cancelled.", BY_SERVER);
tradeWindow->setVisible(false);
tradeWindow->reset();
break;
+
+ // Trade: Trade completed
+ case 0x00f0:
+ chatWindow->chat_log("Trade completed.", BY_SERVER);
+ tradeWindow->setVisible(false);
+ tradeWindow->reset();
+ break;
// Get the items
// Only called on map load / warp
@@ -854,6 +875,7 @@ void do_parse() {
chatWindow->chat_log(info, BY_SERVER);*/
}
break;
+
// Get the equipments
case 0x00a4:
for (int loop = 0; loop < (RFIFOW(2) - 4) / 20; loop++) {
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index d4c5e0f6..8da3ba1a 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -36,17 +36,31 @@ TradeWindow::TradeWindow():
setContentSize(322, 130);
addButton = new Button("Add");
+ okButton = new Button("Ok");
cancelButton = new Button("Cancel");
+ tradeButton = new Button("Trade");
+
addButton->setPosition(2, 105);
- cancelButton->setPosition(200, 105);
+ okButton->setPosition(30, 105);
+ cancelButton->setPosition(270, 105);
+ tradeButton->setPosition(230,105);
addButton->setEventId("add");
+ okButton->setEventId("ok");
cancelButton->setEventId("cancel");
+ tradeButton->setEventId("trade");
+
addButton->addActionListener(this);
+ okButton->addActionListener(this);
cancelButton->addActionListener(this);
+ tradeButton->addActionListener(this);
+
+ tradeButton->setEnabled(false);
add(addButton);
+ add(okButton);
add(cancelButton);
+ add(tradeButton);
nameLabel = new gcn::Label("Other one");
nameLabel->setPosition(2, 45);
@@ -68,7 +82,9 @@ TradeWindow::TradeWindow():
TradeWindow::~TradeWindow()
{
delete addButton;
+ delete okButton;
delete cancelButton;
+ delete tradeButton;
delete nameLabel;
}
@@ -119,6 +135,38 @@ int TradeWindow::increaseQuantity(int index, bool own, int quantity) {
int TradeWindow::reset() {
my_items->resetItems();
trade_items->resetItems();
+ tradeButton->setEnabled(false);
+ okButton->setEnabled(true);
+ ok_other = false;
+ ok_me = false;
+ return 0;
+}
+
+int TradeWindow::setTradeButton(bool enabled) {
+ tradeButton->setEnabled(enabled);
+ return 0;
+}
+
+int TradeWindow::receivedOk(bool own) {
+ if (own) {
+ ok_me = true;
+ if (ok_other) {
+ tradeButton->setEnabled(true);
+ okButton->setEnabled(false);
+ } else {
+ tradeButton->setEnabled(false);
+ okButton->setEnabled(false);
+ }
+ } else {
+ ok_other = true;
+ if (ok_me) {
+ tradeButton->setEnabled(true);
+ okButton->setEnabled(false);
+ } else {
+ tradeButton->setEnabled(false);
+ okButton->setEnabled(true);
+ }
+ }
return 0;
}
@@ -161,6 +209,8 @@ void TradeWindow::action(const std::string &eventId)
{
if (eventId == "add") {
+ // This is still kinda buggy, when ok is clicked, will need to play
+ // RO a bit to review its trade behaviour
if (inventoryWindow->items->getIndex() >= 0 &&
inventoryWindow->items->getIndex() <= INVENTORY_SIZE) {
if (tradeWindow->my_items->getFreeSlot() >= 0) {
@@ -169,14 +219,23 @@ void TradeWindow::action(const std::string &eventId)
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();
-
+
}
}
} else if (eventId == "cancel") {
WFIFOW(0) = net_w_value(0x00ed);
WFIFOSET(2);
while ((out_size > 0)) flush();
+ } else if (eventId == "ok") {
+ WFIFOW(0) = net_w_value(0x00eb);
+ WFIFOSET(2);
+ while ((out_size > 0)) flush();
+ } else if (eventId == "trade") {
+ WFIFOW(0) = net_w_value(0x00ef);
+ WFIFOSET(2);
+ while ((out_size > 0)) flush();
}
//if(selectedItem >= 0 && selectedItem <= INVENTORY_SIZE) {
diff --git a/src/gui/trade.h b/src/gui/trade.h
index 256f051d..8eca64eb 100644
--- a/src/gui/trade.h
+++ b/src/gui/trade.h
@@ -77,6 +77,16 @@ class TradeWindow : public Window, gcn::ActionListener {
* Increase quantity of an item.
*/
int increaseQuantity(int index, bool own, int quantity);
+
+ /**
+ * Set trade Button disabled
+ */
+ int setTradeButton(bool enabled);
+
+ /**
+ * Player received ok message from server
+ */
+ int receivedOk(bool own);
/**
* Called when receiving actions from the widgets.
@@ -88,7 +98,8 @@ class TradeWindow : public Window, gcn::ActionListener {
private:
gcn::Label *nameLabel;
- gcn::Button *addButton, *cancelButton;
+ gcn::Button *addButton, *okButton, *cancelButton, *tradeButton;
+ bool ok_other, ok_me;
};
#endif