mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Split UserReporter JS and XML from mainmenu code and refactor it.
XML button duplication removal by bb in
62acfd74cb
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.
This commit is contained in:
parent
ef8582a7fd
commit
41395ffe5d
4 changed files with 80 additions and 108 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<script directory="gui/common/"/>
|
||||
<script directory="gui/pregame/"/>
|
||||
<script directory="gui/pregame/backgrounds/"/>
|
||||
<script directory="gui/pregame/userreport/"/>
|
||||
|
||||
<!--
|
||||
==========================================
|
||||
|
|
@ -43,65 +44,7 @@
|
|||
- MAIN MENU - USER REPORT
|
||||
==========================================
|
||||
-->
|
||||
<object
|
||||
name="userReportDisabled"
|
||||
size="100%-304 100%-154 100%-4 100%-4"
|
||||
type="image"
|
||||
style="userReportPanel"
|
||||
>
|
||||
<object
|
||||
type="text"
|
||||
style="userReportText"
|
||||
>
|
||||
<attribute id="caption">
|
||||
<keep>[font="sans-bold-16"]</keep>
|
||||
<translate>Help improve 0 A.D.!</translate>
|
||||
<keep>[/font]\n</keep>
|
||||
<translate>You can automatically send us anonymous feedback that will help us fix bugs, and improve performance and compatibility.</translate>
|
||||
</attribute>
|
||||
</object>
|
||||
<object type="button" style="StoneButton" size="8 100%-36 146 100%-8">
|
||||
<translatableAttribute id="caption">Enable Feedback</translatableAttribute>
|
||||
<action on="Press">EnableUserReport(true);</action>
|
||||
</object>
|
||||
<object type="button" style="StoneButton" size="100%-146 100%-36 100%-8 100%-8">
|
||||
<translatableAttribute id="caption">Technical Details</translatableAttribute>
|
||||
<action on="Press">
|
||||
Engine.PushGuiPage("page_manual.xml", {
|
||||
"page": "manual/userreport",
|
||||
"title": getTechnicalDetails()
|
||||
});
|
||||
</action>
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<object
|
||||
name="userReportEnabled"
|
||||
size="100%-304 100%-154 100%-4 100%-4"
|
||||
type="image"
|
||||
style="userReportPanel"
|
||||
>
|
||||
<object
|
||||
name="userReportEnabledText"
|
||||
type="text"
|
||||
style="userReportText"
|
||||
/>
|
||||
|
||||
<object type="button" style="StoneButton" size="8 100%-36 146 100%-8">
|
||||
<translatableAttribute id="caption">Disable Feedback</translatableAttribute>
|
||||
<action on="Press">EnableUserReport(false);</action>
|
||||
</object>
|
||||
<object type="button" style="StoneButton" size="100%-146 100%-36 100%-8 100%-8">
|
||||
<translatableAttribute id="caption">Technical Details</translatableAttribute>
|
||||
<action on="Press">
|
||||
Engine.PushGuiPage("page_manual.xml", {
|
||||
"page": "manual/userreport",
|
||||
"title": getTechnicalDetails()
|
||||
});
|
||||
</action>
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<include file="gui/pregame/userreport/userreport.xml"/>
|
||||
|
||||
<!--
|
||||
==========================================
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
var g_UserReportStatusFormat = {
|
||||
"disabled": data => translate("disabled"),
|
||||
"proxy": data => translate("connecting to server"),
|
||||
"waiting": data => translate("connecting to server"),
|
||||
"connecting": data => translate("connecting to server"),
|
||||
"sending": data => sprintf(translate("uploading (%f%%)"), Math.floor(100 * data[1])),
|
||||
"completed": data =>
|
||||
data[1] == 200 ?
|
||||
translate("upload succeeded") :
|
||||
sprintf(translate("upload failed (%(errorCode)s)"), {
|
||||
"errorCode": data[1]
|
||||
}),
|
||||
"failed": data => sprintf(translate("upload failed (%(errorMessage)s)"), {
|
||||
"errorMessage": uneval(data[2])
|
||||
})
|
||||
};
|
||||
|
||||
function initUserReport()
|
||||
{
|
||||
setUserReportEnabled(Engine.IsUserReportEnabled());
|
||||
}
|
||||
|
||||
function setUserReportEnabled(enabled)
|
||||
{
|
||||
Engine.SetUserReportEnabled(enabled);
|
||||
updateUserReportButtons();
|
||||
}
|
||||
|
||||
function updateUserReportButtons()
|
||||
{
|
||||
let userReportEnableButton = Engine.GetGUIObjectByName("userReportEnableButton");
|
||||
userReportEnableButton.caption = Engine.IsUserReportEnabled() ? translate("Disable Feedback") : translate("Enable Feedback");
|
||||
userReportEnableButton.onPress = () => {
|
||||
setUserReportEnabled(!Engine.IsUserReportEnabled());
|
||||
};
|
||||
|
||||
let userReportTermsButton = Engine.GetGUIObjectByName("userReportTermsButton");
|
||||
userReportTermsButton.onPress = () => {
|
||||
Engine.PushGuiPage("page_manual.xml", {
|
||||
"page": "manual/userreport",
|
||||
"title": translate("Technical Details")
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function updateUserReportStatus()
|
||||
{
|
||||
let statusData = Engine.GetUserReportStatus().split(/:/, 3);
|
||||
|
||||
Engine.GetGUIObjectByName("userReportText").caption =
|
||||
Engine.IsUserReportEnabled() ?
|
||||
setStringTags(translate("Thank you for helping improve 0 A.D.!"), { "font": "sans-bold-16" }) + "\n\n" +
|
||||
translate("Anonymous feedback is currently enabled.") + "\n" +
|
||||
sprintf(translate("Status: %(status)s."), {
|
||||
"status": g_UserReportStatusFormat[statusData[0]] ? g_UserReportStatusFormat[statusData[0]](statusData) : translate("unknown")
|
||||
}) :
|
||||
setStringTags(translate("Help improve 0 A.D.!"), { "font": "sans-bold-16" }) + "\n\n" +
|
||||
translate("You can automatically send us anonymous feedback that will help us fix bugs, and improve performance and compatibility.");
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<object name="userReport" type="image" style="userReportPanel" size="100%-304 100%-154 100%-4 100%-4">
|
||||
|
||||
<action on="Load">initUserReport();</action>
|
||||
<action on="Tick">updateUserReportStatus();</action>
|
||||
|
||||
<object type="text" name="userReportText" style="userReportText"/>
|
||||
|
||||
<object type="button" name="userReportEnableButton" style="StoneButton" size="8 100%-36 146 100%-8"/>
|
||||
|
||||
<object type="button" name="userReportTermsButton" style="StoneButton" size="100%-146 100%-36 100%-8 100%-8">
|
||||
<translatableAttribute id="caption">Technical Details</translatableAttribute>
|
||||
</object>
|
||||
|
||||
</object>
|
||||
Loading…
Reference in a new issue