From 41395ffe5dd086ca7a222eda1eb2274dccc6125b Mon Sep 17 00:00:00 2001 From: elexis Date: Thu, 13 Sep 2018 12:46:08 +0000 Subject: [PATCH] Split UserReporter JS and XML from mainmenu code and refactor it. XML button duplication removal by bb in https://github.com/bb-bb/0ad/commit/62acfd74cb3efdb517db537bd4e62fa0ba6c304d Write formatUserReportStatus in object-oriented style, refs irc discussion with Vladislav on 2018-08-10. Add the two missing cases "proxy" and "waiting" from UserReport.cpp and reuse the "connecting to server" string. No messages.json changes needed for the new directory, no string changes. This was SVN commit r21886. --- .../data/mods/public/gui/pregame/mainmenu.js | 52 +--------------- .../data/mods/public/gui/pregame/mainmenu.xml | 61 +------------------ .../gui/pregame/userreport/userreport.js | 59 ++++++++++++++++++ .../gui/pregame/userreport/userreport.xml | 16 +++++ 4 files changed, 80 insertions(+), 108 deletions(-) create mode 100644 binaries/data/mods/public/gui/pregame/userreport/userreport.js create mode 100644 binaries/data/mods/public/gui/pregame/userreport/userreport.xml diff --git a/binaries/data/mods/public/gui/pregame/mainmenu.js b/binaries/data/mods/public/gui/pregame/mainmenu.js index 028741bd13..ee53830724 100644 --- a/binaries/data/mods/public/gui/pregame/mainmenu.js +++ b/binaries/data/mods/public/gui/pregame/mainmenu.js @@ -24,8 +24,6 @@ function init(initData, hotloadData) // Initialize currentSubmenuType with placeholder to avoid null when switching currentSubmenuType = "submenuSinglePlayer"; - EnableUserReport(Engine.IsUserReportEnabled()); - // Only show splash screen(s) once at startup, but not again after hotloading g_ShowSplashScreens = hotloadData ? hotloadData.showSplashScreens : initData && initData.isStartup; @@ -38,12 +36,15 @@ function init(initData, hotloadData) guiObj.sprite = g_BackgroundLayerset[i].sprite; guiObj.z = i; } + Engine.GetGUIObjectByName("structreeButton").tooltip = colorizeHotkey( translate("%(hotkey)s: View the structure tree of civilizations featured in 0 A.D."), "structree"); + Engine.GetGUIObjectByName("civInfoButton").tooltip = colorizeHotkey( translate("%(hotkey)s: Learn about the many civilizations featured in 0 A.D."), "civinfo"); + Engine.GetGUIObjectByName("lobbyButton").tooltip = colorizeHotkey( translate("%(hotkey)s: Launch the multiplayer lobby to join and host publicly visible games and chat with other players."), "lobby"); @@ -79,33 +80,6 @@ function scrollBackgrounds() } } -function formatUserReportStatus(status) -{ - let d = status.split(/:/, 3); - - if (d[0] == "disabled") - return translate("disabled"); - - if (d[0] == "connecting") - return translate("connecting to server"); - - if (d[0] == "sending") - return sprintf(translate("uploading (%f%%)"), Math.floor(100 * d[1])); - - if (d[0] == "completed") - { - let httpCode = d[1]; - if (httpCode == 200) - return translate("upload succeeded"); - return sprintf(translate("upload failed (%(errorCode)s)"), { "errorCode": httpCode }); - } - - if (d[0] == "failed") - return sprintf(translate("upload failed (%(errorMessage)s)"), { "errorMessage": d[2] }); - - return translate("unknown"); -} - function onTick() { let now = Date.now(); @@ -116,14 +90,6 @@ function onTick() updateMenuPosition(tickLength); - if (Engine.IsUserReportEnabled()) - Engine.GetGUIObjectByName("userReportEnabledText").caption = - '[font="sans-bold-16"]' + translate("Thank you for helping improve 0 A.D.!") + "[/font]\n\n" + - translate("Anonymous feedback is currently enabled.") + "\n" + - sprintf(translate("Status: %(status)s."), { - "status": formatUserReportStatus(Engine.GetUserReportStatus()) - }); - // Show splash screens here, so we don't interfere with main menu hotloading if (g_ShowSplashScreens) { @@ -164,13 +130,6 @@ function SplashScreenClosedCallback() ShowRenderPathMessage(); } -function EnableUserReport(Enabled) -{ - Engine.GetGUIObjectByName("userReportDisabled").hidden = Enabled; - Engine.GetGUIObjectByName("userReportEnabled").hidden = !Enabled; - Engine.SetUserReportEnabled(Enabled); -} - /** * Slide menu. */ @@ -280,11 +239,6 @@ function getLobbyDisabledByBuild() return translate("Launch the multiplayer lobby to join and host publicly visible games and chat with other players. \\[DISABLED BY BUILD]"); } -function getTechnicalDetails() -{ - return translate("Technical Details"); -} - function getManual() { return translate("Manual"); diff --git a/binaries/data/mods/public/gui/pregame/mainmenu.xml b/binaries/data/mods/public/gui/pregame/mainmenu.xml index 4643c1345f..679c65eb67 100644 --- a/binaries/data/mods/public/gui/pregame/mainmenu.xml +++ b/binaries/data/mods/public/gui/pregame/mainmenu.xml @@ -5,6 +5,7 @@