diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-04-15 20:49:17 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-04-15 20:49:17 -0600 |
commit | 6b59adabfcf909cb02075e2fab2d715b4e34af95 (patch) | |
tree | 3ef8c4a547ad8849395055d5ac61dc2bd81a9928 | |
parent | 24fb77131bf6a56c0a9db296c21e4182e303c0cb (diff) | |
download | mana-client-6b59adabfcf909cb02075e2fab2d715b4e34af95.tar.gz mana-client-6b59adabfcf909cb02075e2fab2d715b4e34af95.tar.bz2 mana-client-6b59adabfcf909cb02075e2fab2d715b4e34af95.tar.xz mana-client-6b59adabfcf909cb02075e2fab2d715b4e34af95.zip |
Merge the trade dialog
-rw-r--r-- | src/gui/trade.cpp | 120 | ||||
-rw-r--r-- | src/gui/trade.h | 13 | ||||
-rw-r--r-- | src/net/tmwserv/tradehandler.cpp | 9 |
3 files changed, 47 insertions, 95 deletions
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 95dffdcd..899c55d5 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -39,11 +39,6 @@ #include "net/net.h" #include "net/tradehandler.h" -#ifdef TMWSERV_SUPPORT -#include "net/tmwserv/gameserver/player.h" -#else -#include "net/ea/tradehandler.h" -#endif #include "utils/gettext.h" #include "utils/stringutils.h" @@ -53,13 +48,15 @@ #include <guichan/font.hpp> +#define CAPTION_PROPOSE _("Propose trade") +#define CAPTION_WAIT _("Waiting") +#define CAPTION_ACCEPT _("Confirm trade") + TradeWindow::TradeWindow(): Window(_("Trade: You")), mMyInventory(new Inventory(INVENTORY_SIZE)), - mPartnerInventory(new Inventory(INVENTORY_SIZE)) -#ifdef TMWSERV_SUPPORT - , mStatus(PREPARING) -#endif + mPartnerInventory(new Inventory(INVENTORY_SIZE)), + mStatus(PROPOSING) { setWindowName("Trade"); setResizable(false); @@ -71,15 +68,13 @@ TradeWindow::TradeWindow(): _("OK") : _("Trade"); Button *addButton = new Button(_("Add"), "add", this); -#ifdef EATHENA_SUPPORT - mOkButton = new Button(longestName, "ok", this); -#else - Button *cancelButton = new Button(_("Cancel"), "cancel", this); -#endif - mTradeButton = new Button(_("Propose trade"), "trade", this); - mTradeButton->setWidth(8 + std::max( - mTradeButton->getFont()->getWidth(_("Propose trade")), - mTradeButton->getFont()->getWidth(_("Confirm trade")))); + mOkButton = new Button("", "", this); // Will be filled in later + + int width = std::max(mOkButton->getFont()->getWidth(CAPTION_PROPOSE), + mOkButton->getFont()->getWidth(CAPTION_WAIT)); + width = std::max(width, mOkButton->getFont()->getWidth(CAPTION_ACCEPT)); + + mOkButton->setWidth(8 + width); mMyItemContainer = new ItemContainer(mMyInventory.get(), 5, 2); mMyItemContainer->addSelectionListener(this); @@ -108,12 +103,7 @@ TradeWindow::TradeWindow(): place(2, 0, moneyChange).setHAlign(LayoutCell::LEFT); place = getPlacer(0, 2); place(0, 0, addButton); -#ifdef EATHENA_SUPPORT place(1, 0, mOkButton); -#else - place(2, 0, mTradeButton); - place(3, 0, cancelButton); -#endif Layout &layout = getLayout(); layout.extend(0, 2, 2, 1); layout.setRowHeight(1, Layout::AUTO_SET); @@ -121,11 +111,9 @@ TradeWindow::TradeWindow(): layout.setColWidth(0, Layout::AUTO_SET); layout.setColWidth(1, Layout::AUTO_SET); -#ifdef EATHENA_SUPPORT - mOkButton->setCaption(_("OK")); -#endif - loadWindowState(); + + reset(); } TradeWindow::~TradeWindow() @@ -146,7 +134,6 @@ void TradeWindow::addItem(int id, bool own, int quantity) setStatus(PREPARING); } -#ifdef EATHENA_SUPPORT void TradeWindow::addItem(int id, bool own, int quantity, bool equipment) { if (own) @@ -174,57 +161,29 @@ void TradeWindow::increaseQuantity(int index, bool own, int quantity) else mPartnerInventory->getItem(index)->increaseQuantity(quantity); } -#endif void TradeWindow::reset() { mMyInventory->clear(); mPartnerInventory->clear(); -#ifdef EATHENA_SUPPORT - mOkButton->setCaption(_("OK")); - mOkButton->setActionEventId("ok"); - mOkButton->setEnabled(true); mOkOther = false; mOkMe = false; -#endif mMoneyLabel->setCaption(strprintf(_("You get %s."), "")); mMoneyField->setEnabled(true); mMoneyField->setText(""); setStatus(PREPARING); } -#ifdef TMWSERV_SUPPORT - -void TradeWindow::receivedOk() -{ - setStatus(ACCEPTING); -} - -#else - void TradeWindow::receivedOk(bool own) { if (own) - { mOkMe = true; - if (mOkOther) - { - mOkButton->setCaption(_("Trade")); - mOkButton->setActionEventId("trade"); - } - } else - { mOkOther = true; - if (mOkMe) - { - mOkButton->setCaption(_("Trade")); - mOkButton->setActionEventId("trade"); - } - } -} -#endif + if (mOkMe && mOkOther) + setStatus(ACCEPTING); +} void TradeWindow::tradeItem(Item *item, int quantity) { @@ -247,12 +206,29 @@ void TradeWindow::valueChanged(const gcn::SelectionEvent &event) void TradeWindow::setStatus(Status s) { - if (s == mStatus) return; + if (s == mStatus) + return; mStatus = s; - mTradeButton->setCaption - (s == PREPARING ? _("Propose trade") : _("Confirm trade")); - mTradeButton->setEnabled(s != PROPOSING); + switch (s) + { + case PREPARING: + mOkButton->setCaption(CAPTION_PROPOSE); + mOkButton->setActionEventId("ok"); + break; + case PROPOSING: + mOkButton->setCaption(CAPTION_WAIT); + mOkButton->setActionEventId(""); + break; + case ACCEPTING: + mOkButton->setCaption(CAPTION_ACCEPT); + mOkButton->setActionEventId("trade"); + break; + default: + break; + } + + mOkButton->setEnabled(s != PROPOSING); } void TradeWindow::action(const gcn::ActionEvent &event) @@ -298,39 +274,23 @@ void TradeWindow::action(const gcn::ActionEvent &event) Net::getTradeHandler()->cancel(); } -#ifdef EATHENA_SUPPORT else if (event.getId() == "ok") { - std::stringstream tempMoney(mMoneyField->getText()); - int tempInt; - if (tempMoney >> tempInt) - { - mMoneyField->setText(toString(tempInt)); - - Net::getTradeHandler()->setMoney(tempInt); - } - else - { - mMoneyField->setText(""); - } mMoneyField->setEnabled(false); Net::getTradeHandler()->confirm(); } -#endif else if (event.getId() == "trade") { Net::getTradeHandler()->finish(); setStatus(PROPOSING); } -#ifdef TMWSERV_SUPPORT else if (event.getId() == "money") { int v = atoi(mMoneyField->getText().c_str()); - Net::GameServer::Player::tradeMoney(v); + Net::getTradeHandler()->setMoney(v); mMoneyField->setText(strprintf("%d", v)); setStatus(PREPARING); } -#endif } void TradeWindow::close() diff --git a/src/gui/trade.h b/src/gui/trade.h index 3493c4c6..2260dcc1 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -69,7 +69,6 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void reset(); -#ifdef EATHENA_SUPPORT /** * Add an item to the trade window. */ @@ -84,16 +83,11 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener * Increase quantity of an item. */ void increaseQuantity(int index, bool own, int quantity); -#endif /** * Player received ok message from server */ -#ifdef TMWSERV_SUPPORT - void receivedOk(); -#else void receivedOk(bool own); -#endif /** * Send trade packet. @@ -128,7 +122,7 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener /** * Sets the current status of the trade. */ - void setStatus(Status); + void setStatus(Status s); typedef const std::auto_ptr<Inventory> InventoryPtr; InventoryPtr mMyInventory; @@ -138,17 +132,12 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener ItemContainer *mPartnerItemContainer; gcn::Label *mMoneyLabel; - gcn::Button *mTradeButton; -#ifdef EATHENA_SUPPORT gcn::Button *mAddButton; gcn::Button *mOkButton; -#endif gcn::TextField *mMoneyField; Status mStatus; -#ifdef EATHENA_SUPPORT bool mOkOther, mOkMe; -#endif }; extern TradeWindow *tradeWindow; diff --git a/src/net/tmwserv/tradehandler.cpp b/src/net/tmwserv/tradehandler.cpp index 4528988b..2b10bac1 100644 --- a/src/net/tmwserv/tradehandler.cpp +++ b/src/net/tmwserv/tradehandler.cpp @@ -128,7 +128,7 @@ void TradeHandler::handleMessage(MessageIn &msg) break; case GPMSG_TRADE_ACCEPT: - tradeWindow->receivedOk(); + tradeWindow->receivedOk(false); break; case GPMSG_TRADE_CANCEL: @@ -180,7 +180,9 @@ void TradeHandler::removeItem(int slotNum, int amount) void TradeHandler::setMoney(int amount) { - // TODO + MessageOut msg(PGMSG_TRADE_SET_MONEY); + msg.writeInt32(amount); + Net::GameServer::connection->send(msg); } void TradeHandler::confirm() @@ -190,7 +192,8 @@ void TradeHandler::confirm() void TradeHandler::finish() { - // TODO + MessageOut msg(PGMSG_TRADE_ACCEPT); + Net::GameServer::connection->send(msg); } void TradeHandler::cancel() |