summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-08-26 21:29:18 +0300
committerAndrei Karas <akaras@inbox.ru>2014-08-26 21:29:18 +0300
commit17a96c972cd483fa556a79c4cd60e5d7490177a4 (patch)
treefc745dec71523b49428838582a5aa40712538140
parentc06c787acceec22845f023b2f849858d36af6585 (diff)
downloadmanaplus-17a96c972cd483fa556a79c4cd60e5d7490177a4.tar.gz
manaplus-17a96c972cd483fa556a79c4cd60e5d7490177a4.tar.bz2
manaplus-17a96c972cd483fa556a79c4cd60e5d7490177a4.tar.xz
manaplus-17a96c972cd483fa556a79c4cd60e5d7490177a4.zip
Move chat command /uptime into actions.
-rw-r--r--src/actions/actions.cpp71
-rw-r--r--src/actions/actions.h1
-rw-r--r--src/commands.cpp69
-rw-r--r--src/commands.h5
-rw-r--r--src/input/inputaction.h1
-rw-r--r--src/input/inputactionmap.h11
-rw-r--r--src/input/pages/other.cpp6
7 files changed, 90 insertions, 74 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index 65f6e366c..fd71b5bf5 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -85,6 +85,7 @@
#include "resources/map/map.h"
#include "utils/gettext.h"
+#include "utils/timer.h"
#ifdef ANDROID
#ifndef USE_SDL2
@@ -97,6 +98,7 @@
extern ShortcutWindow *spellShortcutWindow;
extern std::string tradePartnerName;
extern QuitDialog *quitDialog;
+extern int start_time;
namespace Actions
{
@@ -718,4 +720,73 @@ impHandler0(dirs)
return true;
}
+impHandler0(uptime)
+{
+ if (!debugChatTab)
+ return false;
+
+ if (cur_time < start_time)
+ {
+ // TRANSLATORS: uptime command
+ debugChatTab->chatLog(strprintf(_("Client uptime: %s"), "unknown"));
+ }
+ else
+ {
+ std::string str;
+ int timeDiff = cur_time - start_time;
+
+ const int weeks = timeDiff / 60 / 60 / 24 / 7;
+ if (weeks > 0)
+ {
+ // TRANSLATORS: uptime command
+ str = strprintf(ngettext(N_("%d week"), N_("%d weeks"),
+ weeks), weeks);
+ timeDiff -= weeks * 60 * 60 * 24 * 7;
+ }
+
+ const int days = timeDiff / 60 / 60 / 24;
+ if (days > 0)
+ {
+ if (!str.empty())
+ str.append(", ");
+ // TRANSLATORS: uptime command
+ str.append(strprintf(ngettext(N_("%d day"), N_("%d days"),
+ days), days));
+ timeDiff -= days * 60 * 60 * 24;
+ }
+ const int hours = timeDiff / 60 / 60;
+ if (hours > 0)
+ {
+ if (!str.empty())
+ str.append(", ");
+ // TRANSLATORS: uptime command
+ str.append(strprintf(ngettext(N_("%d hour"), N_("%d hours"),
+ hours), hours));
+ timeDiff -= hours * 60 * 60;
+ }
+ const int min = timeDiff / 60;
+ if (min > 0)
+ {
+ if (!str.empty())
+ str.append(", ");
+ // TRANSLATORS: uptime command
+ str.append(strprintf(ngettext(N_("%d minute"), N_("%d minutes"),
+ min), min));
+ timeDiff -= min * 60;
+ }
+
+ if (timeDiff > 0)
+ {
+ if (!str.empty())
+ str.append(", ");
+ // TRANSLATORS: uptime command
+ str.append(strprintf(ngettext(N_("%d second"), N_("%d seconds"),
+ timeDiff), timeDiff));
+ }
+ // TRANSLATORS: uptime command
+ debugChatTab->chatLog(strprintf(_("Client uptime: %s"), str.c_str()));
+ }
+ return true;
+}
+
} // namespace Actions
diff --git a/src/actions/actions.h b/src/actions/actions.h
index f80c4f8e6..9258a289b 100644
--- a/src/actions/actions.h
+++ b/src/actions/actions.h
@@ -67,6 +67,7 @@ namespace Actions
decHandler(disconnect);
decHandler(undress);
decHandler(dirs);
+ decHandler(uptime);
} // namespace Actions
#undef decHandler
diff --git a/src/commands.cpp b/src/commands.cpp
index 8f89d59be..29e850208 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -157,75 +157,6 @@ impHandler(hack)
return true;
}
-impHandler0(uptime)
-{
- if (!debugChatTab)
- return false;
-
- if (cur_time < start_time)
- {
- // TRANSLATORS: uptime command
- debugChatTab->chatLog(strprintf(_("Client uptime: %s"), "unknown"));
- }
- else
- {
- std::string str;
- int timeDiff = cur_time - start_time;
-
- const int weeks = timeDiff / 60 / 60 / 24 / 7;
- if (weeks > 0)
- {
- // TRANSLATORS: uptime command
- str = strprintf(ngettext(N_("%d week"), N_("%d weeks"),
- weeks), weeks);
- timeDiff -= weeks * 60 * 60 * 24 * 7;
- }
-
- const int days = timeDiff / 60 / 60 / 24;
- if (days > 0)
- {
- if (!str.empty())
- str.append(", ");
- // TRANSLATORS: uptime command
- str.append(strprintf(ngettext(N_("%d day"), N_("%d days"),
- days), days));
- timeDiff -= days * 60 * 60 * 24;
- }
- const int hours = timeDiff / 60 / 60;
- if (hours > 0)
- {
- if (!str.empty())
- str.append(", ");
- // TRANSLATORS: uptime command
- str.append(strprintf(ngettext(N_("%d hour"), N_("%d hours"),
- hours), hours));
- timeDiff -= hours * 60 * 60;
- }
- const int min = timeDiff / 60;
- if (min > 0)
- {
- if (!str.empty())
- str.append(", ");
- // TRANSLATORS: uptime command
- str.append(strprintf(ngettext(N_("%d minute"), N_("%d minutes"),
- min), min));
- timeDiff -= min * 60;
- }
-
- if (timeDiff > 0)
- {
- if (!str.empty())
- str.append(", ");
- // TRANSLATORS: uptime command
- str.append(strprintf(ngettext(N_("%d second"), N_("%d seconds"),
- timeDiff), timeDiff));
- }
- // TRANSLATORS: uptime command
- debugChatTab->chatLog(strprintf(_("Client uptime: %s"), str.c_str()));
- }
- return true;
-}
-
impHandler(addPriorityAttack)
{
if (!actorManager
diff --git a/src/commands.h b/src/commands.h
index c5104ee5c..ce517c047 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -52,7 +52,6 @@ struct CommandInfo final
namespace Commands
{
decHandler(hack);
- decHandler(uptime);
decHandler(addAttack);
decHandler(addPriorityAttack);
decHandler(removeAttack);
@@ -93,8 +92,7 @@ namespace Commands
enum
{
- COMMAND_UPTIME = 0,
- COMMAND_ADDPRIORITYATTACK,
+ COMMAND_ADDPRIORITYATTACK = 0,
COMMAND_ADDATTACK,
COMMAND_REMOVEATTACK,
COMMAND_REMOVEIGNOREATTACK,
@@ -135,7 +133,6 @@ enum
static const CommandInfo commands[] =
{
- {"uptime", &Commands::uptime, -1, false},
{"addpriorityattack", &Commands::addPriorityAttack, -1, true},
{"addattack", &Commands::addAttack, -1, true},
{"removeattack", Commands::removeAttack, -1, true},
diff --git a/src/input/inputaction.h b/src/input/inputaction.h
index ec410f8f0..028b384bb 100644
--- a/src/input/inputaction.h
+++ b/src/input/inputaction.h
@@ -388,6 +388,7 @@ namespace InputAction
DIRS,
INFO,
WAIT,
+ UPTIME,
TOTAL
};
} // namespace InputAction
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index 7a7b148cd..ce06d13fe 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -3261,7 +3261,16 @@ static const InputActionData inputActionData[InputAction::TOTAL] = {
InputAction::NO_VALUE, 50,
InputCondition::INGAME,
"wait",
- true}
+ true},
+ {"keyUptime",
+ InputType::UNKNOWN, InputAction::NO_VALUE,
+ InputType::UNKNOWN, InputAction::NO_VALUE,
+ Input::GRP_DEFAULT,
+ &Actions::uptime,
+ InputAction::NO_VALUE, 50,
+ InputCondition::INGAME,
+ "uptime",
+ false},
};
#endif // INPUT_INPUTACTIONMAP_H
diff --git a/src/input/pages/other.cpp b/src/input/pages/other.cpp
index f730db629..4931c1216 100644
--- a/src/input/pages/other.cpp
+++ b/src/input/pages/other.cpp
@@ -274,6 +274,12 @@ SetupActionData setupActionDataOther[] =
"",
},
{
+ // TRANSLATORS: input action name
+ N_("Print client uptime in chat"),
+ InputAction::UPTIME,
+ "",
+ },
+ {
"",
InputAction::NO_VALUE,
""