aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2017-05-11 09:39:37 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-05-11 10:39:37 +0200
commit0e0c824ea75a812a99c7d329c3a4862d6beadf3b (patch)
tree5c56e055dde33d19aa5e9a27e77cf9dd7b9c9a85
parent441740e021f48a3c4f7595711777b7655fdd5778 (diff)
downloadminetest-0e0c824ea75a812a99c7d329c3a4862d6beadf3b.tar.gz
minetest-0e0c824ea75a812a99c7d329c3a4862d6beadf3b.tar.bz2
minetest-0e0c824ea75a812a99c7d329c3a4862d6beadf3b.zip
Rework escape/pause menu (#5719)
* Rework escape/pause menu - Remove build information - Use current controls instead of default controls - Add information about the current server in place of the build information - Add text saying the game is paused to if in singleplayer mode. rework pause/escape menu * improve consistency + display server_name
-rw-r--r--src/game.cpp78
-rw-r--r--src/util/string.h12
2 files changed, 78 insertions, 12 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 9de473231..ae5efa964 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -54,6 +54,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "sky.h"
#include "subgame.h"
#include "tool.h"
+#include "util/basic_macros.h"
#include "util/directiontables.h"
#include "util/pointedthing.h"
#include "irrlicht_changes/static_text.h"
@@ -4504,6 +4505,7 @@ void Game::extendedResourceCleanup()
<< " (note: irrlicht doesn't support removing renderers)" << std::endl;
}
+#define GET_KEY_NAME(KEY) gettext(getKeySetting(#KEY).name())
void Game::showPauseMenu()
{
#ifdef __ANDROID__
@@ -4521,21 +4523,38 @@ void Game::showPauseMenu()
" --> place single item to slot\n"
);
#else
- static const std::string control_text = strgettext("Default Controls:\n"
- "- WASD: move\n"
- "- Space: jump/climb\n"
- "- Shift: sneak/go down\n"
- "- Q: drop item\n"
- "- I: inventory\n"
+ static const std::string control_text_template = strgettext("Controls:\n"
+ "- %s%s%s%s: move\n"
+ "- %s: jump/climb\n"
+ "- %s: sneak/go down\n"
+ "- %s: drop item\n"
+ "- %s: inventory\n"
"- Mouse: turn/look\n"
"- Mouse left: dig/punch\n"
"- Mouse right: place/use\n"
"- Mouse wheel: select item\n"
- "- T: chat\n"
+ "- %s: chat\n"
);
+
+ char control_text_buf[500];
+
+ snprintf(control_text_buf, ARRLEN(control_text_buf), control_text_template.c_str(),
+ GET_KEY_NAME(keymap_forward),
+ GET_KEY_NAME(keymap_left),
+ GET_KEY_NAME(keymap_backward),
+ GET_KEY_NAME(keymap_right),
+ GET_KEY_NAME(keymap_jump),
+ GET_KEY_NAME(keymap_sneak),
+ GET_KEY_NAME(keymap_drop),
+ GET_KEY_NAME(keymap_inventory),
+ GET_KEY_NAME(keymap_chat)
+ );
+
#endif
- float ypos = simple_singleplayer_mode ? 0.5 : 0.1;
+ std::string control_text = std::string(control_text_buf);
+ str_formspec_escape(control_text);
+ float ypos = simple_singleplayer_mode ? 0.7f : 0.1f;
std::ostringstream os;
os << FORMSPEC_VERSION_STRING << SIZE_TAG
@@ -4545,6 +4564,8 @@ void Game::showPauseMenu()
if (!simple_singleplayer_mode) {
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_change_password;"
<< strgettext("Change Password") << "]";
+ } else {
+ os << "field[4.95,0;5,1.5;;" << strgettext("Game Paused") << ";]";
}
#ifndef __ANDROID__
@@ -4558,10 +4579,43 @@ void Game::showPauseMenu()
os << "button_exit[4," << (ypos++) << ";3,0.5;btn_exit_os;"
<< strgettext("Exit to OS") << "]"
<< "textarea[7.5,0.25;3.9,6.25;;" << control_text << ";]"
- << "textarea[0.4,0.25;3.5,6;;" << PROJECT_NAME_C "\n"
- << g_build_info << "\n"
- << "path_user = " << wrap_rows(porting::path_user, 20)
- << "\n;]";
+ << "textarea[0.4,0.25;3.9,6.25;;" << PROJECT_NAME_C " " VERSION_STRING "\n"
+ << "\n"
+ << strgettext("Game info:") << "\n";
+ const std::string &address = client->getAddressName();
+ static const std::string mode = strgettext("- Mode: ");
+ if (!simple_singleplayer_mode) {
+ Address serverAddress = client->getServerAddress();
+ if (address != "") {
+ os << mode << strgettext("Remote server") << "\n"
+ << strgettext("- Address: ") << address;
+ } else {
+ os << mode << strgettext("Hosting server");
+ }
+ os << "\n" << strgettext("- Port: ") << serverAddress.getPort() << "\n";
+ } else {
+ os << mode << strgettext("Singleplayer") << "\n";
+ }
+ if (simple_singleplayer_mode || address == "") {
+ static const std::string on = strgettext("On");
+ static const std::string off = strgettext("Off");
+ const std::string &damage = g_settings->getBool("enable_damage") ? on : off;
+ const std::string &creative = g_settings->getBool("creative_mode") ? on : off;
+ const std::string &announced = g_settings->getBool("server_announce") ? on : off;
+ os << strgettext("- Damage: ") << damage << "\n"
+ << strgettext("- Creative mode: ") << creative << "\n";
+ if (!simple_singleplayer_mode) {
+ const std::string &pvp = g_settings->getBool("enable_pvp") ? on : off;
+ os << strgettext("- PvP: ") << pvp << "\n"
+ << strgettext("- Public: ") << announced << "\n";
+ std::string server_name = g_settings->get("server_name");
+ str_formspec_escape(server_name);
+ if (announced == on && server_name != "")
+ os << strgettext("- Server Name: ") << server_name;
+
+ }
+ }
+ os << ";]";
/* Create menu */
/* Note: FormspecFormSource and LocalFormspecHandler *
diff --git a/src/util/string.h b/src/util/string.h
index 632dd4d7e..cc278da13 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -423,6 +423,18 @@ inline void str_replace(std::string &str, const std::string &pattern,
}
/**
+ * Escapes characters [ ] \ , ; that can not be used in formspecs
+ */
+inline void str_formspec_escape(std::string &str)
+{
+ str_replace(str, "\\", "\\\\");
+ str_replace(str, "]", "\\]");
+ str_replace(str, "[", "\\[");
+ str_replace(str, ";", "\\;");
+ str_replace(str, ",", "\\,");
+}
+
+/**
* Replace all occurrences of the character \p from in \p str with \p to.
*
* @param str The string to (potentially) modify.