diff options
author | Ronny Pfannschmidt <r0nny@users.sourceforge.net> | 2006-01-03 21:43:54 +0000 |
---|---|---|
committer | Ronny Pfannschmidt <r0nny@users.sourceforge.net> | 2006-01-03 21:43:54 +0000 |
commit | 5bcc5490c6dd2cf5535ab283292217302e402ee7 (patch) | |
tree | d9ebdec29d65709f2aa354e450ec363f45c6af59 | |
parent | 2d58eee5901e866fe994c19d38d9dca3383fab37 (diff) | |
download | Mana-5bcc5490c6dd2cf5535ab283292217302e402ee7.tar.gz Mana-5bcc5490c6dd2cf5535ab283292217302e402ee7.tar.bz2 Mana-5bcc5490c6dd2cf5535ab283292217302e402ee7.tar.xz Mana-5bcc5490c6dd2cf5535ab283292217302e402ee7.zip |
moved network logic out of gui/trade.cpp to net/protocol_trade.{h,cpp}
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/gui/trade.cpp | 23 | ||||
-rw-r--r-- | src/net/protocol_trade.cpp | 50 | ||||
-rw-r--r-- | src/net/protocol_trade.h | 36 |
4 files changed, 97 insertions, 16 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8d446363..8a8d11a6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -126,7 +126,9 @@ tmw_SOURCES = graphic/spriteset.cpp \ net/packet.h \ net/protocol.cpp \ net/protocol.h \ - resources/image.cpp \ + net/protocol_trade.cpp \ + net/protocol_trade.h \ + resources/image.cpp \ resources/image.h \ resources/imagewriter.cpp \ resources/imagewriter.h \ diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 767888f4..359782d4 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -39,7 +39,8 @@ #include "../item.h" #include "../net/messageout.h" -#include "../net/protocol.h" +#include "../net/protocol_trade.h" + #include "../resources/iteminfo.h" @@ -227,10 +228,7 @@ void TradeWindow::receivedOk(bool own) void TradeWindow::tradeItem(Item *item, int quantity) { - MessageOut outMsg; - outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); - outMsg.writeInt16(item->getInvIndex()); - outMsg.writeInt32(quantity); + trade(*item,quantity); } void TradeWindow::mouseClick(int x, int y, int button, int count) @@ -299,8 +297,7 @@ void TradeWindow::action(const std::string &eventId) } else if (eventId == "cancel") { - MessageOut outMsg; - outMsg.writeInt16(CMSG_TRADE_CANCEL_REQUEST); + trade(cancel); } else if (eventId == "ok") { @@ -312,20 +309,16 @@ void TradeWindow::action(const std::string &eventId) tempMoney[1] << tempInt; moneyField->setText(tempMoney[1].str()); - MessageOut outMsg; - outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); - outMsg.writeInt16(0); - outMsg.writeInt32(tempInt); + trade(tempInt); + } else { moneyField->setText(""); } moneyField->setEnabled(false); - MessageOut outMsg; - outMsg.writeInt16(CMSG_TRADE_ADD_COMPLETE); + trade(complete); } else if (eventId == "trade") { - MessageOut outMsg; - outMsg.writeInt16(CMSG_TRADE_OK); + trade(); } } diff --git a/src/net/protocol_trade.cpp b/src/net/protocol_trade.cpp new file mode 100644 index 00000000..0271567e --- /dev/null +++ b/src/net/protocol_trade.cpp @@ -0,0 +1,50 @@ + +#include "protocol_trade.h" + +#include "../item.h" +#include "../gui/trade.h" + +#include "messageout.h" + +cancel_t cancel; +complete_t complete; + +/** Start trading with someone */ +void trade(Being&); + +void trade(int id,int amount) +{ + MessageOut outMsg; + outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); + outMsg.writeInt16(id); + outMsg.writeInt32(amount); +}; + +/** add trading item*/ + +void trade(Item& item,int amount) +{ +trade(item.getInvIndex(),amount); +} + +/** add money to trade */ +void trade(int i){trade(0,i);}; + +/** cancel courent trade */ +void trade(cancel_t&) +{ + MessageOut outMsg; + outMsg.writeInt16(CMSG_TRADE_CANCEL_REQUEST); +}; + +void trade() +{ + MessageOut outMsg; + outMsg.writeInt16(CMSG_TRADE_OK); +}; + +void trade(complete_t&) +{ + MessageOut outMsg; + outMsg.writeInt16(CMSG_TRADE_ADD_COMPLETE); +}; diff --git a/src/net/protocol_trade.h b/src/net/protocol_trade.h new file mode 100644 index 00000000..42908ab2 --- /dev/null +++ b/src/net/protocol_trade.h @@ -0,0 +1,36 @@ +#ifndef _TMW_PROTOCOL_HELPER_ +#define _TMW_PROTOCOL_HELPER_ + +#include "protocol.h" + + +/** + * Helper class for using <actionfunc>(cancel), to cancel stuff + */ +class cancel_t {}; +extern cancel_t cancel; + +class complete_t {}; +extern complete_t complete; + + +class Item; + +/** Start trading with someone */ +void trade(Being&); + +/** add trading item*/ +void trade(Item&,int amount); + +/** add money to trade */ +void trade(int); + +/** verify the trade */ +void trade(); + +void trade(complete_t&); + +/** cancel courent trade */ +void trade(cancel_t&); + +#endif |