diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-03-28 18:13:57 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-03-28 18:13:57 -0600 |
commit | 088c0e4680d8013f01bdc70ac4f340f98afa2394 (patch) | |
tree | d3a103c962d8c8569bfab982882953e91326da65 /src/net/ea | |
parent | d7ffc90de680965edef7aa432d3bc3fd15986850 (diff) | |
download | mana-088c0e4680d8013f01bdc70ac4f340f98afa2394.tar.gz mana-088c0e4680d8013f01bdc70ac4f340f98afa2394.tar.bz2 mana-088c0e4680d8013f01bdc70ac4f340f98afa2394.tar.xz mana-088c0e4680d8013f01bdc70ac4f340f98afa2394.zip |
Clean up eAthena party handling a bit more
Diffstat (limited to 'src/net/ea')
-rw-r--r-- | src/net/ea/gui/partytab.cpp | 4 | ||||
-rw-r--r-- | src/net/ea/gui/partytab.h | 2 | ||||
-rw-r--r-- | src/net/ea/party.cpp | 61 | ||||
-rw-r--r-- | src/net/ea/party.h | 48 | ||||
-rw-r--r-- | src/net/ea/partyhandler.cpp | 31 | ||||
-rw-r--r-- | src/net/ea/partyhandler.h | 9 | ||||
-rw-r--r-- | src/net/ea/protocol.h | 2 |
7 files changed, 67 insertions, 90 deletions
diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp index a55d2492..4e486bf0 100644 --- a/src/net/ea/gui/partytab.cpp +++ b/src/net/ea/gui/partytab.cpp @@ -44,10 +44,10 @@ PartyTab::~PartyTab() { } -void PartyTab::handleInput(std::string &msg) { +void PartyTab::handleInput(const std::string &msg) { // TODO } -void PartyTab::handleCommand(std::string &msg) { +void PartyTab::handleCommand(std::string msg) { // TODO } diff --git a/src/net/ea/gui/partytab.h b/src/net/ea/gui/partytab.h index b2aaca68..fce4b515 100644 --- a/src/net/ea/gui/partytab.h +++ b/src/net/ea/gui/partytab.h @@ -46,4 +46,6 @@ class PartyTab : public ChatTab void handleCommand(std::string msg); }; +extern PartyTab *partyTab; + #endif // CHANNELTAB_H diff --git a/src/net/ea/party.cpp b/src/net/ea/party.cpp index 2295cb81..0fbba2f1 100644 --- a/src/net/ea/party.cpp +++ b/src/net/ea/party.cpp @@ -26,19 +26,16 @@ #include "gui/widgets/chattab.h" #include "gui/chat.h" #include "gui/confirm_dialog.h" +#include "gui/partywindow.h" #include "net/messageout.h" #include "net/ea/protocol.h" +#include "net/ea/gui/partytab.h" #include "utils/gettext.h" #include "utils/strprintf.h" -Party::Party() : - mInviteListener(&mInParty) -{ -} - -void Party::respond(const std::string &command, const std::string &args) +void eAthena::Party::respond(const std::string &command, const std::string &args) { if (command == "new" || command == "create") { @@ -52,7 +49,7 @@ void Party::respond(const std::string &command, const std::string &args) } if (command == "settings") { - localChatTab->chatLog(_("Not yet implemented!"), BY_SERVER); + partyTab->chatLog(_("Not yet implemented!"), BY_SERVER); return; /* MessageOut outMsg(CMSG_PARTY_SETTINGS); @@ -60,10 +57,10 @@ void Party::respond(const std::string &command, const std::string &args) outMsg.writeInt16(0); // Item */ } - localChatTab->chatLog(_("Party command not known."), BY_SERVER); + partyTab->chatLog(_("Party command not known."), BY_SERVER); } -void Party::create(const std::string &party) +void eAthena::Party::create(const std::string &party) { if (party.empty()) { @@ -72,22 +69,21 @@ void Party::create(const std::string &party) } MessageOut outMsg(CMSG_PARTY_CREATE); outMsg.writeString(party.substr(0, 23), 24); - mCreating = true; } -void Party::leave(const std::string &args) +void eAthena::Party::leave(const std::string &args) { MessageOut outMsg(CMSG_PARTY_LEAVE); localChatTab->chatLog(_("Left party."), BY_SERVER); - mInParty = false; + player_node->setInParty(false); } -void Party::createResponse(bool ok) +void eAthena::Party::createResponse(bool ok) { if (ok) { localChatTab->chatLog(_("Party successfully created."), BY_SERVER); - mInParty = true; + player_node->setInParty(true); } else { @@ -95,58 +91,41 @@ void Party::createResponse(bool ok) } } -void Party::inviteResponse(const std::string &nick, int status) +void eAthena::Party::inviteResponse(const std::string &nick, int status) { switch (status) { case 0: - localChatTab->chatLog(strprintf(_("%s is already a member of a party."), + partyTab->chatLog(strprintf(_("%s is already a member of a party."), nick.c_str()), BY_SERVER); break; case 1: - localChatTab->chatLog(strprintf(_("%s refused your invitation."), + partyTab->chatLog(strprintf(_("%s refused your invitation."), nick.c_str()), BY_SERVER); break; case 2: - localChatTab->chatLog(strprintf(_("%s is now a member of your party."), + partyTab->chatLog(strprintf(_("%s is now a member of your party."), nick.c_str()), BY_SERVER); break; } } -void Party::invitedAsk(const std::string &nick, int gender, - const std::string &partyName) -{ - mPartyName = partyName; /* Quick and nasty - needs redoing */ - if (nick.empty()) - { - localChatTab->chatLog(_("You can\'t have a blank party name!"), BY_SERVER); - return; - } - mCreating = false; - ConfirmDialog *dlg = new ConfirmDialog(_("Invite to party"), - strprintf(_("%s invites you to join" - " the %s party, do you accept?"), - nick.c_str(), partyName.c_str())); - dlg->addActionListener(&mInviteListener); -} - -void Party::InviteListener::action(const gcn::ActionEvent &event) +void eAthena::Party::respondToInvite(bool accept) { MessageOut outMsg(CMSG_PARTY_INVITED); outMsg.writeInt32(player_node->getId()); - bool accept = event.getId() == "yes"; outMsg.writeInt32(accept ? 1 : 0); - *mInParty = *mInParty || accept; + player_node->setInParty(player_node->getInParty() || accept); } -void Party::leftResponse(const std::string &nick) +void eAthena::Party::leftResponse(const std::string &nick) { localChatTab->chatLog(strprintf(_("%s has left your party."), nick.c_str()), BY_SERVER); + partyWindow->removePartyMember(nick); } -void Party::receiveChat(Being *being, const std::string &msg) +void eAthena::Party::receiveChat(Being *being, const std::string &msg) { if (!being) { @@ -162,7 +141,7 @@ void Party::receiveChat(Being *being, const std::string &msg) localChatTab->chatLog(being->getName() + " : " + msg, BY_PARTY); } -void Party::help(const std::string &args) +void eAthena::Party::help(const std::string &args) { // Strip "party " from the front std::string msg = args.substr(6, args.length()); diff --git a/src/net/ea/party.h b/src/net/ea/party.h index 25af80b3..6907de47 100644 --- a/src/net/ea/party.h +++ b/src/net/ea/party.h @@ -22,18 +22,14 @@ #ifndef PARTY_H #define PARTY_H -#include <string> - -#include <guichan/actionlistener.hpp> +#include "being.h" -class PartyHandler; -class Being; -class ChatWindow; +#include <string> -class Party +namespace eAthena { - public: - Party(); + namespace Party + { void respond(const std::string &command, const std::string &args); void create(const std::string &party); @@ -43,32 +39,20 @@ class Party void inviteResponse(const std::string &nick, int status); void invitedAsk(const std::string &nick, int gender, const std::string &partyName); + + /** + * Send invite response to the server + */ + void respondToInvite(bool accept); + + /** + * The player has left your party + */ void leftResponse(const std::string &nick); void receiveChat(Being *being, const std::string &msg); void help(const std::string &args); - - private: - std::string mPartyName; - bool mInParty; - bool mCreating; /**< Used to give an appropriate response to - failure */ - PartyHandler *handler; - - class InviteListener : public gcn::ActionListener - { - public: - InviteListener(bool *inParty) : - mInParty(inParty) - {} - void action(const gcn::ActionEvent &event); - - private: - bool *mInParty; - }; - InviteListener mInviteListener; -}; - -extern Party *playerParty; + } +} #endif diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index d903976e..7ecf0863 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -21,21 +21,29 @@ #include "net/ea/partyhandler.h" +#include "net/ea/gui/partytab.h" + #include "net/ea/protocol.h" #include "net/messagein.h" #include "gui/chat.h" +#include "gui/partywindow.h" #include "beingmanager.h" #include "party.h" -PartyHandler::PartyHandler(Party *party) : mParty(party) +PartyTab *partyTab; + +static void newPartyTab() { partyTab = new PartyTab(); } +static void deletePartyTab() { delete partyTab ; } + +PartyHandler::PartyHandler() { static const Uint16 _messages[] = { SMSG_PARTY_CREATE, SMSG_PARTY_INFO, - SMSG_PARTY_INVITE, + SMSG_PARTY_INVITE_RESPONSE, SMSG_PARTY_INVITED, SMSG_PARTY_SETTINGS, SMSG_PARTY_MEMBER_INFO, @@ -46,6 +54,13 @@ PartyHandler::PartyHandler(Party *party) : mParty(party) 0 }; handledMessages = _messages; + + newPartyTab(); +} + +PartyHandler::~PartyHandler() +{ + deletePartyTab(); } void PartyHandler::handleMessage(MessageIn &msg) @@ -53,15 +68,15 @@ void PartyHandler::handleMessage(MessageIn &msg) switch (msg.getId()) { case SMSG_PARTY_CREATE: - mParty->createResponse(msg.readInt8()); + eAthena::Party::createResponse(msg.readInt8()); break; case SMSG_PARTY_INFO: break; - case SMSG_PARTY_INVITE: + case SMSG_PARTY_INVITE_RESPONSE: { std::string nick = msg.readString(24); int status = msg.readInt8(); - mParty->inviteResponse(nick, status); + eAthena::Party::inviteResponse(nick, status); break; } case SMSG_PARTY_INVITED: @@ -85,7 +100,7 @@ void PartyHandler::handleMessage(MessageIn &msg) gender = being->getGender(); partyName = msg.readString(24); } - mParty->invitedAsk(nick, gender, partyName); + partyWindow->showPartyInvite(nick, partyName); break; } case SMSG_PARTY_SETTINGS: @@ -97,7 +112,7 @@ void PartyHandler::handleMessage(MessageIn &msg) /*int id = */msg.readInt32(); std::string nick = msg.readString(24); /*int fail = */msg.readInt8(); - mParty->leftResponse(nick); + eAthena::Party::leftResponse(nick); break; } case SMSG_PARTY_UPDATE_HP: @@ -114,7 +129,7 @@ void PartyHandler::handleMessage(MessageIn &msg) int id = msg.readInt32(); Being *being = beingManager->findBeing(id); std::string chatMsg = msg.readString(msgLength); - mParty->receiveChat(being, chatMsg); + eAthena::Party::receiveChat(being, chatMsg); } break; } diff --git a/src/net/ea/partyhandler.h b/src/net/ea/partyhandler.h index 851c4ae3..c6ee261b 100644 --- a/src/net/ea/partyhandler.h +++ b/src/net/ea/partyhandler.h @@ -24,17 +24,14 @@ #include "net/messagehandler.h" -class Party; - class PartyHandler : public MessageHandler { public: - PartyHandler(Party *party); + PartyHandler(); - void handleMessage(MessageIn &msg); + ~PartyHandler(); - private: - Party *mParty; + void handleMessage(MessageIn &msg); }; #endif // NET_EA_PARTYHANDLER_H diff --git a/src/net/ea/protocol.h b/src/net/ea/protocol.h index a70e47b4..ff13cce9 100644 --- a/src/net/ea/protocol.h +++ b/src/net/ea/protocol.h @@ -101,7 +101,7 @@ static const int STORAGE_OFFSET = 1; #define SMSG_PARTY_CREATE 0x00fa #define SMSG_PARTY_INFO 0x00fb -#define SMSG_PARTY_INVITE 0x00fd +#define SMSG_PARTY_INVITE_RESPONSE 0x00fd #define SMSG_PARTY_INVITED 0x00fe #define SMSG_PARTY_SETTINGS 0x0102 #define SMSG_PARTY_MEMBER_INFO 0x0104 |