summaryrefslogtreecommitdiff
path: root/src/localplayer.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2010-04-19 20:05:35 +0300
committerBertram <yohanndotferreiraatorange.fr>2010-04-19 23:19:03 +0200
commit959708c60c119e03183ba97177f13e92d61e342c (patch)
tree86c8803ed1751dcf84a4feec9c05e47a695f78d8 /src/localplayer.cpp
parentd5390fa51b47cc70052902301ade7d137eff9d61 (diff)
downloadmana-959708c60c119e03183ba97177f13e92d61e342c.tar.gz
mana-959708c60c119e03183ba97177f13e92d61e342c.tar.bz2
mana-959708c60c119e03183ba97177f13e92d61e342c.tar.xz
mana-959708c60c119e03183ba97177f13e92d61e342c.zip
Add afk mode for player.
Add variable cur_time for current time. Add command /away [text] Reviewed by: Bertram
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r--src/localplayer.cpp69
1 files changed, 68 insertions, 1 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index ff7961b9..9729f55d 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -42,6 +42,7 @@
#include "gui/gui.h"
#include "gui/inventorywindow.h"
#include "gui/ministatus.h"
+#include "gui/okdialog.h"
#include "gui/skilldialog.h"
#include "gui/statuswindow.h"
#include "gui/theme.h"
@@ -49,6 +50,7 @@
#include "gui/widgets/chattab.h"
+#include "net/chathandler.h"
#include "net/guildhandler.h"
#include "net/inventoryhandler.h"
#include "net/net.h"
@@ -73,6 +75,8 @@
// TODO: This can fine tuned later on when running is added...
const short walkingKeyboardDelay = 1000;
+#define AWAY_LIMIT_TIMER 60
+
LocalPlayer *player_node = NULL;
LocalPlayer::LocalPlayer(int id, int subtype):
@@ -100,8 +104,13 @@ LocalPlayer::LocalPlayer(int id, int subtype):
mPathSetByMouse(false),
mInventory(new Inventory(Inventory::INVENTORY)),
mLocalWalkTime(-1),
- mMessageTime(0)
+ mMessageTime(0),
+ mAwayDialog(0),
+ mAfkTime(0),
+ mAwayMode(false)
{
+ mAwayListener = new AwayListener();
+
mUpdateName = true;
mTextColor = &Theme::getThemeColor(Theme::PLAYER);
@@ -1414,3 +1423,61 @@ void LocalPlayer::optionChanged(const std::string &value)
setShowName(config.getValue("showownname", 1));
}
}
+
+void LocalPlayer::changeAwayMode()
+{
+ mAwayMode = !mAwayMode;
+ mAfkTime = 0;
+ if (mAwayMode)
+ {
+ cancelFollow();
+ mAwayDialog = new OkDialog(_("Away"),
+ config.getValue("afkMessage", "I am away from keyboard"));
+ mAwayDialog->addActionListener(mAwayListener);
+ }
+ else
+ {
+ 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();
+ }
+} \ No newline at end of file