diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-12-28 22:04:41 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2010-12-28 22:24:44 +0100 |
commit | 780bcbc2ea75603f2eef7369a6f7b5ddfc5888b5 (patch) | |
tree | 9fe66ca3a9b3c65d3da9490411c4a621dc9046e2 | |
parent | 6385f680fd3e42bd9137f9184e702dd36d20322f (diff) | |
download | mana-780bcbc2ea75603f2eef7369a6f7b5ddfc5888b5.tar.gz mana-780bcbc2ea75603f2eef7369a6f7b5ddfc5888b5.tar.bz2 mana-780bcbc2ea75603f2eef7369a6f7b5ddfc5888b5.tar.xz mana-780bcbc2ea75603f2eef7369a6f7b5ddfc5888b5.zip |
Revert "Remove the AFK response system"
This reverts commit 3d6a2d9c80a969c3613f567dd7029e75ef59b5cb.
I've by that readded the AFK system on master. Please, remove it
when we've got a proper replacement.
-rw-r--r-- | src/commandhandler.cpp | 20 | ||||
-rw-r--r-- | src/gui/chat.cpp | 1 | ||||
-rw-r--r-- | src/localplayer.cpp | 64 | ||||
-rw-r--r-- | src/localplayer.h | 20 |
4 files changed, 104 insertions, 1 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index f3947bd9..dcaf6f0a 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -126,6 +126,10 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab) { handleShowIp(args, tab); } + else if (type == "away") + { + handleAway(args, tab); + } else { tab->chatLog(_("Unknown command.")); @@ -173,6 +177,9 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab) "with another user")); tab->chatLog(_("/q > Alias of query")); + tab->chatLog(_("/away > Tell the other whispering players " + "you're away from keyboard.")); + tab->chatLog(_("/ignore > ignore a player")); tab->chatLog(_("/unignore > stop ignoring a player")); @@ -257,6 +264,14 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab) tab->chatLog(_("This command tries to make a tab for whispers between" "you and <nick>.")); } + else if (args == "away") + { + tab->chatLog(_("Command: /away <afk reason>")); + tab->chatLog(_("This command tells " + "you're away from keyboard with the given reason.")); + tab->chatLog(_("Command: /away")); + tab->chatLog(_("This command clears the away status and message.")); + } else if (args == "createparty") { tab->chatLog(_("Command: /createparty <name>")); @@ -545,3 +560,8 @@ void CommandHandler::handleUnignore(const std::string &args, ChatTab *tab) else tab->chatLog(_("Player could not be unignored!"), BY_SERVER); } + +void CommandHandler::handleAway(const std::string &args, ChatTab *tab) +{ + player_node->setAway(args); +} diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 7acb7de8..2ac5100d 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -482,6 +482,7 @@ void ChatWindow::whisper(const std::string &nick, else { tab->chatLog(nick, mes); + player_node->afkRespond(tab, nick); } } else diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 17641ed4..a4560030 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -80,10 +80,15 @@ LocalPlayer::LocalPlayer(int id, int subtype): mPathSetByMouse(false), mLocalWalkTime(-1), mMessageTime(0), - mShowIp(false) + mShowIp(false), + mAwayDialog(0), + mAfkTime(0), + mAwayMode(false) { listen(CHANNEL_ATTRIBUTES); + mAwayListener = new AwayListener(); + mUpdateName = true; setShowName(config.getValue("showownname", 1)); @@ -94,6 +99,8 @@ LocalPlayer::LocalPlayer(int id, int subtype): LocalPlayer::~LocalPlayer() { + delete mAwayDialog; + delete mAwayListener; } void LocalPlayer::logic() @@ -1110,3 +1117,58 @@ void LocalPlayer::event(Channels channel, const Mana::Event &event) Being::event(channel, event); } + +void LocalPlayer::changeAwayMode() +{ + mAwayMode = !mAwayMode; + mAfkTime = 0; + if (mAwayMode) + { + mAwayDialog = new OkDialog(_("Away"), + config.getValue("afkMessage", "I am away from keyboard")); + mAwayDialog->addActionListener(mAwayListener); + } + + mAwayDialog = 0; +} + +void LocalPlayer::setAway(const std::string &message) +{ + if (!message.empty()) + config.setValue("afkMessage", message); + changeAwayMode(); +} + +void LocalPlayer::afkRespond(ChatTab *tab, const std::string &nick) +{ + if (mAwayMode) + { + if (mAfkTime == 0 + || cur_time < mAfkTime + || cur_time - mAfkTime > AWAY_LIMIT_TIMER) + { + std::string msg = "*AFK*: " + + config.getValue("afkMessage", "I am away from keyboard"); + + Net::getChatHandler()->privateMessage(nick, msg); + if (!tab) + { + localChatTab->chatLog(getName() + " : " + msg, + ACT_WHISPER, false); + } + else + { + tab->chatLog(getName(), msg); + } + mAfkTime = cur_time; + } + } +} + +void AwayListener::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "ok" && player_node->getAwayMode()) + { + player_node->changeAwayMode(); + } +} diff --git a/src/localplayer.h b/src/localplayer.h index 334a2598..a5328182 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -38,6 +38,12 @@ class Item; class Map; class OkDialog; +class AwayListener : public gcn::ActionListener +{ + public: + void action(const gcn::ActionEvent &event); +}; + /** * The local player character. */ @@ -178,6 +184,15 @@ class LocalPlayer : public Being bool isPathSetByMouse() const { return mPathSetByMouse; } + void changeAwayMode(); + + bool getAwayMode() + { return mAwayMode; } + + void setAway(const std::string &message); + + void afkRespond(ChatTab *tab, const std::string &nick); + void addMessageToQueue(const std::string &message, int color = UserPalette::EXP_INFO); @@ -227,6 +242,11 @@ class LocalPlayer : public Being int mMessageTime; bool mShowIp; + + AwayListener *mAwayListener; + OkDialog *mAwayDialog; + int mAfkTime; + bool mAwayMode; }; extern LocalPlayer *player_node; |