summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/being.cpp12
-rw-r--r--src/being.h3
-rw-r--r--src/engine.cpp9
-rw-r--r--src/engine.h2
-rw-r--r--src/game.cpp65
-rw-r--r--src/gui/requesttrade.cpp100
-rw-r--r--src/gui/requesttrade.h69
-rw-r--r--src/gui/trade.cpp22
-rw-r--r--src/gui/trade.h2
10 files changed, 282 insertions, 4 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index ef915046..3c7628fc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,6 +51,8 @@ tmw_SOURCES = graphic/spriteset.cpp \
gui/progressbar.h \
gui/radiobutton.cpp \
gui/radiobutton.h \
+ gui/requesttrade.cpp \
+ gui/requesttrade.h \
gui/scrollarea.cpp \
gui/scrollarea.h \
gui/sell.cpp \
diff --git a/src/being.cpp b/src/being.cpp
index 687cd5a3..1f8cbd40 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -63,6 +63,18 @@ unsigned int find_npc(unsigned short x, unsigned short y) {
return 0;
}
+unsigned int find_pc(unsigned short x, unsigned short y) {
+ std::list<Being *>::iterator i;
+ for (i = beings.begin(); i != beings.end(); i++) {
+ Being *being = (*i);
+ // Check if is a player
+ if (being->job < 10 && being->x == x && being->y == y) {
+ return being->id;
+ }
+ }
+ return 0;
+}
+
unsigned int find_monster(unsigned short x, unsigned short y) {
std::list<Being*>::iterator i;
for (i = beings.begin(); i != beings.end(); i++) {
diff --git a/src/being.h b/src/being.h
index cc357ff3..7c816cee 100644
--- a/src/being.h
+++ b/src/being.h
@@ -130,6 +130,9 @@ void remove_node(unsigned int id);
/** Find a NPC id based on its coordinates */
unsigned int find_npc(unsigned short x, unsigned short y);
+/** Find a PC id based on its coordinates */
+unsigned int find_pc(unsigned short x, unsigned short y);
+
/** Find a MONSTER id based on its coordinates */
unsigned int find_monster(unsigned short x, unsigned short y);
diff --git a/src/engine.cpp b/src/engine.cpp
index 40aea669..7ea5a91b 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -33,6 +33,7 @@
#include "main.h"
#include "being.h"
#include "floor_item.h"
+#include "gui/requesttrade.h"
char itemCurrenyQ[10] = "0";
int map_x, map_y, camera_x, camera_y;
@@ -62,6 +63,7 @@ Minimap *minimap;
EquipmentWindow *equipmentWindow;
ChargeDialog *chargeDialog;
TradeWindow *tradeWindow;
+RequestTradeDialog *requestTradeDialog;
char hairtable[16][4][2] = {
// S(x,y) W(x,y) N(x,y) E(x,y)
@@ -157,6 +159,7 @@ Engine::Engine()
equipmentWindow = new EquipmentWindow();
chargeDialog = new ChargeDialog();
tradeWindow = new TradeWindow();
+ requestTradeDialog = new RequestTradeDialog();
// Initialize window posisitons
chatWindow->setPosition(0, screen->h - chatWindow->getHeight());
statusWindow->setPosition(screen->w - statusWindow->getWidth() - 5, 5);
@@ -174,6 +177,10 @@ Engine::Engine()
tradeWindow->setPosition(screen->w - statusWindow->getWidth() -
tradeWindow->getWidth() - 10,
chatWindow->getHeight() + 15);
+ requestTradeDialog->setPosition(screen->w - statusWindow->getWidth() -
+ requestTradeDialog->getWidth() - 10,
+ chatWindow->getHeight() + 15);
+
// Set initial window visibility
chatWindow->setVisible(true);
statusWindow->setVisible(true);
@@ -191,6 +198,7 @@ Engine::Engine()
equipmentWindow->setVisible(false);
chargeDialog->setVisible(false);
tradeWindow->setVisible(false);
+ requestTradeDialog->setVisible(false);
// Do not focus any text field
gui->focusNone();
@@ -238,6 +246,7 @@ Engine::~Engine()
delete newSkillWindow;
delete itemAmountWindow;
delete tradeWindow;
+ delete requestTradeDialog;
// Delete sprite sets
delete monsterset;
diff --git a/src/engine.h b/src/engine.h
index 48909f60..86be708c 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -43,6 +43,7 @@
#include "gui/chargedialog.h"
#include "gui/item_amount.h"
#include "gui/trade.h"
+#include "gui/requesttrade.h"
#include "resources/resourcemanager.h"
#include "map.h"
#include "graphic/spriteset.h"
@@ -70,6 +71,7 @@ extern StatsWindow *statsWindow;
extern Setup *setupWindow;
extern EquipmentWindow *equipmentWindow;
extern ChargeDialog* chargeDialog;
+extern RequestTradeDialog *requestTradeDialog;
extern TradeWindow *tradeWindow;
char get_x_offset(char, char);
char get_y_offset(char, char);
diff --git a/src/game.cpp b/src/game.cpp
index 118e6d3d..f4ecd0b7 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -358,6 +358,14 @@ void do_input()
WFIFOSET(7);
current_npc = id;
}
+ } else {
+ id = find_pc(mx, my);
+ if (id != 0) {
+ // Begin a trade
+ WFIFOW(0) = net_w_value(0x00e4);
+ WFIFOL(2) = net_l_value(id);
+ WFIFOSET(6);
+ }
}
}
}
@@ -740,7 +748,62 @@ void do_parse() {
npcTextDialog->setVisible(true);
current_npc = RFIFOL(4);
break;
-
+
+ // Trade: Receiving a request to trade
+ case 0x00e5:
+ //printf("Getting a call from %s\n", RFIFOP(2));
+ requestTradeDialog->request(RFIFOP(2));
+ break;
+
+ // Trade: Response
+ case 0x00e7:
+ switch (RFIFOB(2)) {
+ case 0:
+ // too far away
+ chatWindow->chat_log("Trading isn't possible. Trade partner is too far away.", BY_SERVER);
+ break;
+ case 1:
+ // Character doesn't exist
+ chatWindow->chat_log("Trading isn't possible. Character doesn't exist.", BY_SERVER);
+ break;
+ case 2:
+ // invite request check failed...
+ chatWindow->chat_log("Trade cancelled due to an unknown reason.", BY_SERVER);
+ break;
+ case 3:
+ // Trade accepted
+ tradeWindow->setVisible(true);
+ break;
+ case 4:
+ // Trade cancelled
+ chatWindow->chat_log("Trade cancelled.", BY_SERVER);
+ break;
+ default:
+ // Shouldn't happen as well, but to be sure
+ chatWindow->chat_log("Unhandled trade cancel packet",
+ BY_SERVER);
+ break;
+ }
+ break;
+ // Trade: Item successfully added
+ case 0x00ea:
+ switch (RFIFOB(4)) {
+ case 0:
+ //printf("Item successfully added\n");
+ // Add code to be added
+ break;
+ default:
+ //printf("Unhandled 0x00ea byte!\n");
+ break;
+ }
+ break;
+
+ // Trade: Trade cancelled
+ case 0x00ee:
+ chatWindow->chat_log("Trade cancelled.", BY_SERVER);
+ tradeWindow->setVisible(false);
+ break;
+
// Get the items
// Only called on map load / warp
case 0x01ee:
diff --git a/src/gui/requesttrade.cpp b/src/gui/requesttrade.cpp
new file mode 100644
index 00000000..431f6922
--- /dev/null
+++ b/src/gui/requesttrade.cpp
@@ -0,0 +1,100 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "requesttrade.h"
+#include "button.h"
+#include "../game.h"
+#include "../net/network.h"
+
+RequestTradeDialog::RequestTradeDialog():
+ Window("Request for Trade")
+{
+ nameLabel[0] = new gcn::Label("");
+ nameLabel[1] = new gcn::Label("");
+ acceptButton = new Button("Accept");
+ cancelButton = new Button("Cancel");
+
+ setContentSize(260, 75);
+
+ nameLabel[0]->setPosition(5, 30);
+ nameLabel[1]->setPosition(5, 40);
+ cancelButton->setPosition(
+ 260 - 5 - cancelButton->getWidth(),
+ 75 - 5 - cancelButton->getHeight());
+ acceptButton->setPosition(
+ cancelButton->getX() - 5 - acceptButton->getWidth(),
+ cancelButton->getY());
+
+ acceptButton->setEventId("accept");
+ cancelButton->setEventId("cancel");
+
+ acceptButton->addActionListener(this);
+ cancelButton->addActionListener(this);
+
+ add(nameLabel[0]);
+ add(nameLabel[1]);
+ add(acceptButton);
+ add(cancelButton);
+
+ setLocationRelativeTo(getParent());
+}
+
+RequestTradeDialog::~RequestTradeDialog()
+{
+ delete acceptButton;
+ delete cancelButton;
+ for (int i = 0; i < 2; i++) {
+ delete nameLabel[i];
+ }
+}
+
+void RequestTradeDialog::request(const char *name)
+{
+ std::stringstream cap;
+ std::stringstream captwo;
+ cap << name << " wants to trade with you.";
+ captwo << "Do you want to accept?";
+ nameLabel[0]->setCaption(cap.str());
+ nameLabel[0]->adjustSize();
+ nameLabel[1]->setCaption(captwo.str());
+ nameLabel[1]->adjustSize();
+ setVisible(true);
+}
+
+void RequestTradeDialog::action(const std::string& eventId)
+{
+ if (eventId == "accept") {
+ // Send the selected index back to the server
+ WFIFOW(0) = net_w_value(0x00e6);
+ WFIFOB(2) = net_b_value(3);
+ WFIFOSET(3);
+ setVisible(false);
+ }
+ else if (eventId == "cancel") {
+ // 0xff packet means cancel
+ WFIFOW(0) = net_w_value(0x00e6);
+ WFIFOB(2) = net_b_value(4);
+ WFIFOSET(3);
+ setVisible(false);
+ }
+}
diff --git a/src/gui/requesttrade.h b/src/gui/requesttrade.h
new file mode 100644
index 00000000..cb4362c4
--- /dev/null
+++ b/src/gui/requesttrade.h
@@ -0,0 +1,69 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_REQUESTTRADE_H
+#define _TMW_REQUESTTRADE_H
+
+#include <guichan.hpp>
+#include <vector>
+#include <string>
+#include <sstream>
+#include "window.h"
+
+/**
+ * The request trade dialog.
+ *
+ * \ingroup GUI
+ */
+class RequestTradeDialog : public Window, public gcn::ActionListener
+{
+ public:
+ /**
+ * Constructor.
+ *
+ * @see Window::Window
+ */
+ RequestTradeDialog();
+
+ /**
+ * Destructor.
+ */
+ ~RequestTradeDialog();
+
+ /**
+ * Changes caption and brings window to the top
+ */
+ void request(const char *name);
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const std::string& eventId);
+
+ private:
+ gcn::Button *acceptButton;
+ gcn::Button *cancelButton;
+ gcn::Label *nameLabel[1];
+};
+
+#endif
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 43bbd79d..66394ddb 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -34,13 +34,19 @@ TradeWindow::TradeWindow():
Window("Trade: You")
{
setContentSize(322, 130);
+
addButton = new Button("Add");
+ cancelButton = new Button("Cancel");
addButton->setPosition(2, 105);
+ cancelButton->setPosition(200, 105);
addButton->setEventId("add");
+ cancelButton->setEventId("cancel");
addButton->addActionListener(this);
+ cancelButton->addActionListener(this);
add(addButton);
+ add(cancelButton);
nameLabel = new gcn::Label("Other one");
nameLabel->setPosition(2, 45);
@@ -62,6 +68,7 @@ TradeWindow::TradeWindow():
TradeWindow::~TradeWindow()
{
delete addButton;
+ delete cancelButton;
delete nameLabel;
}
@@ -149,8 +156,15 @@ void TradeWindow::action(const std::string &eventId)
if (i >= 0) {
printf("successfull\n");
- addItem(i, inventoryWindow->items->getId(), true, inventoryWindow->items->getQuantity(), inventoryWindow->items->isEquipment(inventoryWindow->items->getIndex()));
- inventoryWindow->changeQuantity(inventoryWindow->items->getIndex(), 0);
+ //addItem(i, inventoryWindow->items->getId(), true, inventoryWindow->items->getQuantity(), inventoryWindow->items->isEquipment(inventoryWindow->items->getIndex()));
+
+ WFIFOW(0) = net_w_value(0x00e8);
+ WFIFOW(2) = net_w_value(inventoryWindow->items->getIndex());
+ WFIFOL(4) = net_l_value(inventoryWindow->items->getQuantity());
+ WFIFOSET(8);
+ while ((out_size > 0)) flush();
+
+ //inventoryWindow->changeQuantity(inventoryWindow->items->getIndex(), 0);
} else {
printf("not successfull\n");
@@ -158,6 +172,10 @@ void TradeWindow::action(const std::string &eventId)
}
+ } else if (eventId == "cancel") {
+ WFIFOW(0) = net_w_value(0x00ed);
+ 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 3b863e64..e6b31678 100644
--- a/src/gui/trade.h
+++ b/src/gui/trade.h
@@ -83,7 +83,7 @@ class TradeWindow : public Window, gcn::ActionListener {
private:
gcn::Label *nameLabel;
- gcn::Button *addButton;
+ gcn::Button *addButton, *cancelButton;
};
#endif