From 8672fc7e3dccfe224b51496cd8ad6abbfff8b354 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Sun, 28 May 2023 16:57:24 +0200 Subject: [PATCH] Allows to translate default playername --- Mods/vcmi/config/vcmi/english.json | 1 + Mods/vcmi/config/vcmi/german.json | 1 + client/mainmenu/CMainMenu.cpp | 14 +++++++++++--- client/mainmenu/CMainMenu.h | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Mods/vcmi/config/vcmi/english.json b/Mods/vcmi/config/vcmi/english.json index 1f87e2933..8bd3e83c9 100644 --- a/Mods/vcmi/config/vcmi/english.json +++ b/Mods/vcmi/config/vcmi/english.json @@ -37,6 +37,7 @@ "vcmi.mainMenu.serverClosing" : "Closing...", "vcmi.mainMenu.hostTCP" : "Host TCP/IP game", "vcmi.mainMenu.joinTCP" : "Join TCP/IP game", + "vcmi.mainMenu.playerName" : "Player", "vcmi.server.errors.existingProcess" : "Another VCMI server process is running. Please terminate it before starting a new game.", "vcmi.server.errors.modsIncompatibility" : "The following mods are required to load the game:", diff --git a/Mods/vcmi/config/vcmi/german.json b/Mods/vcmi/config/vcmi/german.json index 4cb949f1a..8cf77ffbc 100644 --- a/Mods/vcmi/config/vcmi/german.json +++ b/Mods/vcmi/config/vcmi/german.json @@ -37,6 +37,7 @@ "vcmi.mainMenu.serverClosing" : "Trenne...", "vcmi.mainMenu.hostTCP" : "Hoste TCP/IP Spiel", "vcmi.mainMenu.joinTCP" : "Trete TCP/IP Spiel bei", + "vcmi.mainMenu.playerName" : "Spieler", "vcmi.server.errors.existingProcess" : "Es läuft ein weiterer vcmiserver-Prozess, bitte beendet diesen zuerst", "vcmi.server.errors.modsIncompatibility" : "Erforderliche Mods um das Spiel zu laden:", diff --git a/client/mainmenu/CMainMenu.cpp b/client/mainmenu/CMainMenu.cpp index c05fadc5b..2bc67d6c1 100644 --- a/client/mainmenu/CMainMenu.cpp +++ b/client/mainmenu/CMainMenu.cpp @@ -400,7 +400,7 @@ CMultiMode::CMultiMode(ESelectionScreen ScreenType) statusBar = CGStatusBar::create(std::make_shared(background->getSurface(), Rect(7, 465, 440, 18), 7, 465)); playerName = std::make_shared(Rect(19, 436, 334, 16), background->getSurface()); - playerName->setText(settings["general"]["playerName"].String()); + playerName->setText(getDefaultPlayerName()); playerName->cb += std::bind(&CMultiMode::onNameChange, this, _1); buttonHotseat = std::make_shared(Point(373, 78), "MUBHOT.DEF", CGI->generaltexth->zelp[266], std::bind(&CMultiMode::hostTCP, this)); @@ -413,14 +413,22 @@ void CMultiMode::hostTCP() { auto savedScreenType = screenType; close(); - GH.windows().createAndPushWindow(settings["general"]["playerName"].String(), savedScreenType, true, ELoadMode::MULTI); + GH.windows().createAndPushWindow(getDefaultPlayerName(), savedScreenType, true, ELoadMode::MULTI); } void CMultiMode::joinTCP() { auto savedScreenType = screenType; close(); - GH.windows().createAndPushWindow(settings["general"]["playerName"].String(), savedScreenType, false, ELoadMode::MULTI); + GH.windows().createAndPushWindow(getDefaultPlayerName(), savedScreenType, false, ELoadMode::MULTI); +} + +std::string CMultiMode::getDefaultPlayerName() +{ + std::string name = settings["general"]["playerName"].String(); + if(name == "Player") + name = CGI->generaltexth->translate("vcmi.mainMenu.playerName"); + return name; } void CMultiMode::onNameChange(std::string newText) diff --git a/client/mainmenu/CMainMenu.h b/client/mainmenu/CMainMenu.h index 0f7d79dc3..f0285bb65 100644 --- a/client/mainmenu/CMainMenu.h +++ b/client/mainmenu/CMainMenu.h @@ -91,6 +91,7 @@ public: CMultiMode(ESelectionScreen ScreenType); void hostTCP(); void joinTCP(); + getDefaultPlayerName() void onNameChange(std::string newText); };