From: terencehill Date: Thu, 24 Mar 2022 19:08:18 +0000 (+0100) Subject: Allow translating active modifications in the Welcome message X-Git-Tag: xonotic-v0.8.5~81^2~11 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5c7563886285a3ccc099ef5ea33ff78712ba67e4;p=xonotic%2Fxonotic-data.pk3dir.git Allow translating active modifications in the Welcome message --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index d1f6e1b8d..cefd2c471 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -1286,12 +1286,41 @@ NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew) } } +string translate_modifications(string s) +{ + return build_mutator_list(s); +} + +string translate_weaponarena(string s) +{ + if (s == "") return s; + if (s == "All Weapons Arena") return _("All Weapons Arena"); + if (s == "Dev All Weapons Arena") return _("Dev All Weapons Arena"); + if (s == "Most Weapons Arena") return _("Most Weapons Arena"); + if (s == "All Available Weapons Arena") return _("All Available Weapons Arena"); + if (s == "Dev All Available Weapons Arena") return _("Dev All Available Weapons Arena"); + if (s == "Most Available Weapons Arena") return _("Most Available Weapons Arena"); + if (s == "No Weapons Arena") return _("No Weapons Arena"); + + int n = tokenizebyseparator(s, " & "); + string wpn_list = ""; + for (int i = 0; i < n; i++) + { + Weapon wep = Weapon_from_name(argv(i)); + if (wep == WEP_Null) + LOG_INFO("^3Warning: ^7server sent an invalid weapon name\n"); + wpn_list = cons_mid(wpn_list, " & ", wep.m_name); + } + return sprintf(_("%s Arena"), wpn_list); +} + NET_HANDLE(TE_CSQC_SERVERINFO, bool isNew) { bool force_centerprint = ReadByte(); string hostname = ReadString(); string ver = ReadString(); - string modifications = ReadString(); + string modifications = translate_modifications(ReadString()); + string weaponarena_list = translate_weaponarena(ReadString()); string cache_mutatormsg = ReadString(); string mutator_msg = ReadString(); string motd = ReadString(); @@ -1299,6 +1328,7 @@ NET_HANDLE(TE_CSQC_SERVERINFO, bool isNew) string msg = ""; msg = strcat(msg, ver); msg = strcat(msg, "^8\n\n", _("match type is "), " ^1", MapInfo_Type_ToText(gametype), "^8\n"); + modifications = cons_mid(modifications, ", ", weaponarena_list); if(modifications != "") msg = strcat(msg, "^8\n", _("active modifications:"), " ^3", modifications, "^8\n"); if (cache_mutatormsg != "") diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 469ab50d8..cea6c03ff 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -210,6 +210,48 @@ string draw_UseSkinFor(string pic) else return strcat(draw_currentSkin, "/", pic); } + +// if s == "" (MENUQC) builds the mutator list for the Mutators dialog based on local cvar values +// otherwise (CSQC) translates the mutator list (s) that client has received from server +// NOTE: this function merges MENUQC and CSQC code in order to avoid duplicating and separating strings +string build_mutator_list(string s) +{ + int i = -1, n = 0; // allow only 1 iteration in the following for loop if (s == "") + if (s != "") + { + i = 0; + n = tokenizebyseparator(s, ", "); + } + string s2 = ""; + for (string arg = ""; i < n; i++) + { + if (i >= 0) arg = argv(i); + if(arg == "Dodging" || (!n && cvar("g_dodging"))) s2 = cons_mid(s2, ", ", _("Dodging")); + if(arg == "InstaGib" || (!n && cvar("g_instagib"))) s2 = cons_mid(s2, ", ", _("InstaGib")); + if(arg == "New Toys" || (!n && cvar("g_new_toys"))) s2 = cons_mid(s2, ", ", _("New Toys")); + if(arg == "NIX" || (!n && cvar("g_nix"))) s2 = cons_mid(s2, ", ", _("NIX")); + if(arg == "Rocket Flying" || (!n && cvar("g_rocket_flying"))) s2 = cons_mid(s2, ", ", _("Rocket Flying")); + if(arg == "Invincible Projectiles" || (!n && cvar("g_invincible_projectiles"))) s2 = cons_mid(s2, ", ", _("Invincible Projectiles")); + if(arg == "Low gravity" || (!n && cvar("sv_gravity") < stof(cvar_defstring("sv_gravity")))) s2 = cons_mid(s2, ", ", _("Low gravity")); + if(arg == "Cloaked" || (!n && cvar("g_cloaked"))) s2 = cons_mid(s2, ", ", _("Cloaked")); + if(arg == "Hook" || (!n && cvar("g_grappling_hook"))) s2 = cons_mid(s2, ", ", _("Hook")); + if(arg == "Midair" || (!n && cvar("g_midair"))) s2 = cons_mid(s2, ", ", _("Midair")); + if(arg == "Melee only" || (!n && cvar("g_melee_only"))) s2 = cons_mid(s2, ", ", _("Melee only")); + if(arg == "Vampire" || (!n && cvar("g_vampire"))) s2 = cons_mid(s2, ", ", _("Vampire")); + if(arg == "Piñata" || (!n && cvar("g_pinata"))) s2 = cons_mid(s2, ", ", _("Piñata")); + if(arg == "Weapons stay" || (!n && cvar("g_weapon_stay"))) s2 = cons_mid(s2, ", ", _("Weapons stay")); + if(arg == "Blood loss" || (!n && cvar("g_bloodloss") > 0)) s2 = cons_mid(s2, ", ", _("Blood loss")); + if(arg == "Jetpack" || (!n && cvar("g_jetpack"))) s2 = cons_mid(s2, ", ", _("Jetpack")); + if(arg == "Buffs" || (!n && cvar("g_buffs") > 0)) s2 = cons_mid(s2, ", ", _("Buffs")); + if(arg == "Overkill" || (!n && cvar("g_overkill"))) s2 = cons_mid(s2, ", ", _("Overkill")); + if(arg == "No powerups" || (!n && cvar("g_powerups") == 0)) s2 = cons_mid(s2, ", ", _("No powerups")); + if(arg == "Powerups" || (!n && cvar("g_powerups") > 0)) s2 = cons_mid(s2, ", ", _("Powerups")); + if(arg == "Touch explode" || (!n && cvar("g_touchexplode") > 0)) s2 = cons_mid(s2, ", ", _("Touch explode")); + if(arg == "Wall jumping" || (!n && cvar("g_walljump"))) s2 = cons_mid(s2, ", ", _("Wall jumping")); + if(arg == "No start weapons" || (!n && cvar_string("g_weaponarena") == "0" && cvar("g_balance_blaster_weaponstartoverride") == 0)) s2 = cons_mid(s2, ", ", _("No start weapons")); + } + return s2; +} #endif void wordwrap_cb(string s, float l, void(string) callback) diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 1334f5ec3..8a6da62a6 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -44,6 +44,8 @@ void wordwrap_cb(string s, float l, void(string) callback); #ifndef SVQC string draw_currentSkin; string draw_UseSkinFor(string pic); + +string build_mutator_list(string s); #endif // iterative depth-first search, with fields that go "up", "down left" and "right" in a tree diff --git a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc index 7473e8e8d..d35415df6 100644 --- a/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc +++ b/qcsrc/menu/xonotic/dialog_multiplayer_create_mutators.qc @@ -52,55 +52,9 @@ string WeaponArenaString() string XonoticMutatorsDialog_toString(entity me) { - string s = ""; - if(cvar("g_dodging")) - s = cons_mid(s, ", ", _("Dodging")); - if(cvar("g_instagib")) - s = cons_mid(s, ", ", _("InstaGib")); - if(cvar("g_new_toys")) - s = cons_mid(s, ", ", _("New Toys")); - if(cvar("g_nix")) - s = cons_mid(s, ", ", _("NIX")); - if(cvar("g_rocket_flying")) - s = cons_mid(s, ", ", _("Rocket Flying")); - if(cvar("g_invincible_projectiles")) - s = cons_mid(s, ", ", _("Invincible Projectiles")); + string s = build_mutator_list(""); if(cvar_string("g_weaponarena") != "0") s = cons_mid(s, ", ", WeaponArenaString()); - else if(cvar("g_balance_blaster_weaponstartoverride") == 0) - s = cons_mid(s, ", ", _("No start weapons")); - if(cvar("sv_gravity") < stof(cvar_defstring("sv_gravity"))) - s = cons_mid(s, ", ", _("Low gravity")); - if(cvar("g_cloaked")) - s = cons_mid(s, ", ", _("Cloaked")); - if(cvar("g_grappling_hook")) - s = cons_mid(s, ", ", _("Hook")); - if(cvar("g_midair")) - s = cons_mid(s, ", ", _("Midair")); - if(cvar("g_melee_only")) - s = cons_mid(s, ", ", _("Melee only")); - if(cvar("g_vampire")) - s = cons_mid(s, ", ", _("Vampire")); - if(cvar("g_pinata")) - s = cons_mid(s, ", ", _("Piñata")); - if(cvar("g_weapon_stay")) - s = cons_mid(s, ", ", _("Weapons stay")); - if(cvar("g_bloodloss") > 0) - s = cons_mid(s, ", ", _("Blood loss")); - if(cvar("g_jetpack")) - s = cons_mid(s, ", ", _("Jetpack")); - if(cvar("g_buffs") > 0) - s = cons_mid(s, ", ", _("Buffs")); - if(cvar("g_overkill")) - s = cons_mid(s, ", ", _("Overkill")); - if(cvar("g_powerups") == 0) - s = cons_mid(s, ", ", _("No powerups")); - if(cvar("g_powerups") > 0) - s = cons_mid(s, ", ", _("Powerups")); - if(cvar("g_touchexplode") > 0) - s = cons_mid(s, ", ", _("Touch explode")); - if(cvar("g_walljump")) - s = cons_mid(s, ", ", _("Wall jumping")); if(s == "") return ZCTX(_("MUT^None")); else diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index a1c4c7003..c46c151f2 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1044,25 +1044,20 @@ void SendWelcomemessage(entity this, bool force_centerprint) MUTATOR_CALLHOOK(BuildMutatorsPrettyString, ""); string modifications = M_ARGV(0, string); - if(g_weaponarena) - { - if(g_weaponarena_random) - modifications = strcat(modifications, ", ", ftos(g_weaponarena_random), " of ", g_weaponarena_list, " Arena"); - else - modifications = strcat(modifications, ", ", g_weaponarena_list, " Arena"); - } - else if(cvar("g_balance_blaster_weaponstartoverride") == 0) + if (!g_weaponarena && cvar("g_balance_blaster_weaponstartoverride") == 0) modifications = strcat(modifications, ", No start weapons"); if(cvar("sv_gravity") < stof(cvar_defstring("sv_gravity"))) modifications = strcat(modifications, ", Low gravity"); if(g_weapon_stay && !g_cts) modifications = strcat(modifications, ", Weapons stay"); if(autocvar_g_jetpack) - modifications = strcat(modifications, ", Jet pack"); + modifications = strcat(modifications, ", Jetpack"); modifications = substring(modifications, 2, strlen(modifications) - 2); WriteString(MSG_ONE, modifications); + WriteString(MSG_ONE, g_weaponarena_list); + if(cache_lastmutatormsg != autocvar_g_mutatormsg) { strcpy(cache_lastmutatormsg, autocvar_g_mutatormsg); diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index ac0c17c8e..890ab1708 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -1878,25 +1878,25 @@ void readplayerstartcvars() else if (s == "all" || s == "1") { g_weaponarena = 1; - g_weaponarena_list = "All Weapons"; + g_weaponarena_list = "All Weapons Arena"; g_weaponarena_weapons = weapons_all(); } else if (s == "devall") { g_weaponarena = 1; - g_weaponarena_list = "Dev All Weapons"; + g_weaponarena_list = "Dev All Weapons Arena"; g_weaponarena_weapons = weapons_devall(); } else if (s == "most") { g_weaponarena = 1; - g_weaponarena_list = "Most Weapons"; + g_weaponarena_list = "Most Weapons Arena"; g_weaponarena_weapons = weapons_most(); } else if (s == "all_available") { g_weaponarena = 1; - g_weaponarena_list = "All Available Weapons"; + g_weaponarena_list = "All Available Weapons Arena"; // this needs to run after weaponsInMapAll is initialized InitializeEntity(NULL, weaponarena_available_all_update, INITPRIO_FINDTARGET); @@ -1904,7 +1904,7 @@ void readplayerstartcvars() else if (s == "devall_available") { g_weaponarena = 1; - g_weaponarena_list = "Dev All Available Weapons"; + g_weaponarena_list = "Dev All Available Weapons Arena"; // this needs to run after weaponsInMapAll is initialized InitializeEntity(NULL, weaponarena_available_devall_update, INITPRIO_FINDTARGET); @@ -1912,7 +1912,7 @@ void readplayerstartcvars() else if (s == "most_available") { g_weaponarena = 1; - g_weaponarena_list = "Most Available Weapons"; + g_weaponarena_list = "Most Available Weapons Arena"; // this needs to run after weaponsInMapAll is initialized InitializeEntity(NULL, weaponarena_available_most_update, INITPRIO_FINDTARGET); @@ -1920,7 +1920,7 @@ void readplayerstartcvars() else if (s == "none") { g_weaponarena = 1; - g_weaponarena_list = "No Weapons"; + g_weaponarena_list = "No Weapons Arena"; } else { @@ -1934,13 +1934,13 @@ void readplayerstartcvars() if(wep != WEP_Null) { g_weaponarena_weapons |= (wep.m_wepset); - g_weaponarena_list = strcat(g_weaponarena_list, wep.m_name, " & "); + g_weaponarena_list = strcat(g_weaponarena_list, wep.netname, " & "); } } if (g_weaponarena_list != "") // remove trailing " & " g_weaponarena_list = substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3); else // no valid weapon found - g_weaponarena_list = "No Weapons"; + g_weaponarena_list = "No Weapons Arena"; } if (g_weaponarena)