Extract sysinfo logic to its own class.

This commit is contained in:
Paul Chote
2020-02-08 18:17:27 +00:00
committed by abcdefg30
parent 98aef70e88
commit e8df28c518
11 changed files with 232 additions and 230 deletions

View File

@@ -22,11 +22,9 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
{
[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields",
Justification = "SystemInformation version should be defined next to the dictionary it refers to.")]
public class MainMenuLogic : ChromeLogic
{
protected enum MenuType { Main, Singleplayer, Extras, MapEditor, SystemInfoPrompt, None }
protected enum MenuType { Main, Singleplayer, Extras, MapEditor, StartupPrompts, None }
protected enum MenuPanel { None, Missions, Skirmish, Multiplayer, MapEditor, Replays, GameSaves }
@@ -43,27 +41,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
bool newsOpen;
// Increment the version number when adding new stats
const int SystemInformationVersion = 4;
Dictionary<string, Pair<string, string>> GetSystemInformation()
{
var lang = System.Globalization.CultureInfo.InstalledUICulture.TwoLetterISOLanguageName;
return new Dictionary<string, Pair<string, string>>()
{
{ "id", Pair.New("Anonymous ID", Game.Settings.Debug.UUID) },
{ "platform", Pair.New("OS Type", Platform.CurrentPlatform.ToString()) },
{ "os", Pair.New("OS Version", Environment.OSVersion.ToString()) },
{ "x64", Pair.New("OS is 64 bit", Environment.Is64BitOperatingSystem.ToString()) },
{ "x64process", Pair.New("Process is 64 bit", Environment.Is64BitProcess.ToString()) },
{ "runtime", Pair.New(".NET Runtime", Platform.RuntimeVersion) },
{ "gl", Pair.New("OpenGL Version", Game.Renderer.GLVersion) },
{ "windowsize", Pair.New("Window Size", "{0}x{1}".F(Game.Renderer.NativeResolution.Width, Game.Renderer.NativeResolution.Height)) },
{ "windowscale", Pair.New("Window Scale", Game.Renderer.NativeWindowScale.ToString("F2", CultureInfo.InvariantCulture)) },
{ "uiscale", Pair.New("UI Scale", Game.Settings.Graphics.UIScale.ToString("F2", CultureInfo.InvariantCulture)) },
{ "lang", Pair.New("System Language", lang) }
};
}
void SwitchMenu(MenuType type)
{
menuType = type;
@@ -215,7 +192,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var newsBG = widget.GetOrNull("NEWS_BG");
if (newsBG != null)
{
newsBG.IsVisible = () => Game.Settings.Game.FetchNews && menuType != MenuType.None && menuType != MenuType.SystemInfoPrompt;
newsBG.IsVisible = () => Game.Settings.Game.FetchNews && menuType != MenuType.None && menuType != MenuType.StartupPrompts;
newsPanel = Ui.LoadWidget<ScrollPanelWidget>("NEWS_PANEL", null, new WidgetArgs());
newsTemplate = newsPanel.Get("NEWS_ITEM_TEMPLATE");
@@ -235,7 +212,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var updateLabel = rootMenu.GetOrNull("UPDATE_NOTICE");
if (updateLabel != null)
updateLabel.IsVisible = () => !newsOpen && menuType != MenuType.None &&
menuType != MenuType.SystemInfoPrompt &&
menuType != MenuType.StartupPrompts &&
webServices.ModVersionStatus == ModVersionStatus.Outdated;
var playerProfile = widget.GetOrNull("PLAYER_PROFILE_CONTAINER");
@@ -248,39 +225,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
});
}
// System information opt-out prompt
var sysInfoPrompt = widget.Get("SYSTEM_INFO_PROMPT");
sysInfoPrompt.IsVisible = () => menuType == MenuType.SystemInfoPrompt;
if (Game.Settings.Debug.SystemInformationVersionPrompt < SystemInformationVersion)
menuType = MenuType.StartupPrompts;
Action onSysInfoComplete = () =>
{
menuType = MenuType.SystemInfoPrompt;
LoadAndDisplayNews(webServices.GameNews, newsBG);
SwitchMenu(MenuType.Main);
};
var sysInfoCheckbox = sysInfoPrompt.Get<CheckboxWidget>("SYSINFO_CHECKBOX");
sysInfoCheckbox.IsChecked = () => Game.Settings.Debug.SendSystemInformation;
sysInfoCheckbox.OnClick = () => Game.Settings.Debug.SendSystemInformation ^= true;
var sysInfoData = sysInfoPrompt.Get<ScrollPanelWidget>("SYSINFO_DATA");
var template = sysInfoData.Get<LabelWidget>("DATA_TEMPLATE");
sysInfoData.RemoveChildren();
foreach (var info in GetSystemInformation().Values)
if (SystemInfoPromptLogic.ShouldShowPrompt())
{
Ui.OpenWindow("MAINMENU_SYSTEM_INFO_PROMPT", new WidgetArgs
{
var label = template.Clone() as LabelWidget;
var text = info.First + ": " + info.Second;
label.GetText = () => text;
sysInfoData.AddChild(label);
}
sysInfoPrompt.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
{
Game.Settings.Debug.SystemInformationVersionPrompt = SystemInformationVersion;
Game.Settings.Save();
SwitchMenu(MenuType.Main);
LoadAndDisplayNews(webServices.GameNews, newsBG);
};
{ "onComplete", onSysInfoComplete }
});
}
else
LoadAndDisplayNews(webServices.GameNews, newsBG);
onSysInfoComplete();
Game.OnShellmapLoaded += OpenMenuBasedOnLastGame;
}
@@ -305,12 +265,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Uri.EscapeUriString(Game.ModData.Manifest.Id),
Uri.EscapeUriString(Game.ModData.Manifest.Metadata.Version));
// Append system profile data if the player has opted in
if (Game.Settings.Debug.SendSystemInformation)
newsURL += "&sysinfoversion={0}&".F(SystemInformationVersion)
+ GetSystemInformation()
.Select(kv => kv.Key + "=" + Uri.EscapeUriString(kv.Value.Second))
.JoinWith("&");
// Parameter string is blank if the player has opted out
newsURL += SystemInfoPromptLogic.CreateParameterString();
new Download(newsURL, cacheFile, e => { },
e => NewsDownloadComplete(e, cacheFile, currentNews,

View File

@@ -0,0 +1,95 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using OpenRA.Primitives;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
{
[SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields",
Justification = "SystemInformation version should be defined next to the dictionary it refers to.")]
public class SystemInfoPromptLogic : ChromeLogic
{
// Increment the version number when adding new stats
const int SystemInformationVersion = 4;
static Dictionary<string, Pair<string, string>> GetSystemInformation()
{
var lang = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName;
return new Dictionary<string, Pair<string, string>>()
{
{ "id", Pair.New("Anonymous ID", Game.Settings.Debug.UUID) },
{ "platform", Pair.New("OS Type", Platform.CurrentPlatform.ToString()) },
{ "os", Pair.New("OS Version", Environment.OSVersion.ToString()) },
{ "x64", Pair.New("OS is 64 bit", Environment.Is64BitOperatingSystem.ToString()) },
{ "x64process", Pair.New("Process is 64 bit", Environment.Is64BitProcess.ToString()) },
{ "runtime", Pair.New(".NET Runtime", Platform.RuntimeVersion) },
{ "gl", Pair.New("OpenGL Version", Game.Renderer.GLVersion) },
{ "windowsize", Pair.New("Window Size", "{0}x{1}".F(Game.Renderer.NativeResolution.Width, Game.Renderer.NativeResolution.Height)) },
{ "windowscale", Pair.New("Window Scale", Game.Renderer.NativeWindowScale.ToString("F2", CultureInfo.InvariantCulture)) },
{ "uiscale", Pair.New("UI Scale", Game.Settings.Graphics.UIScale.ToString("F2", CultureInfo.InvariantCulture)) },
{ "lang", Pair.New("System Language", lang) }
};
}
public static bool ShouldShowPrompt()
{
return Game.Settings.Debug.SystemInformationVersionPrompt < SystemInformationVersion;
}
public static string CreateParameterString()
{
if (!Game.Settings.Debug.SendSystemInformation)
return "";
return "&sysinfoversion={0}&".F(SystemInformationVersion)
+ GetSystemInformation()
.Select(kv => kv.Key + "=" + Uri.EscapeUriString(kv.Value.Second))
.JoinWith("&");
}
[ObjectCreator.UseCtor]
public SystemInfoPromptLogic(Widget widget, Action onComplete)
{
var sysInfoCheckbox = widget.Get<CheckboxWidget>("SYSINFO_CHECKBOX");
sysInfoCheckbox.IsChecked = () => Game.Settings.Debug.SendSystemInformation;
sysInfoCheckbox.OnClick = () => Game.Settings.Debug.SendSystemInformation ^= true;
var sysInfoData = widget.Get<ScrollPanelWidget>("SYSINFO_DATA");
var template = sysInfoData.Get<LabelWidget>("DATA_TEMPLATE");
sysInfoData.RemoveChildren();
foreach (var info in GetSystemInformation().Values)
{
var label = template.Clone() as LabelWidget;
var text = info.First + ": " + info.Second;
label.GetText = () => text;
sysInfoData.AddChild(label);
}
widget.Get<ButtonWidget>("CONTINUE_BUTTON").OnClick = () =>
{
Game.Settings.Debug.SystemInformationVersionPrompt = SystemInformationVersion;
Game.Settings.Save();
Ui.CloseWindow();
onComplete();
};
}
}
}

View File

@@ -0,0 +1,61 @@
Container@MAINMENU_SYSTEM_INFO_PROMPT:
Logic: SystemInfoPromptLogic
X: (WINDOW_RIGHT - WIDTH) / 2
Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 490
Height: 222
Children:
Label@TITLE:
Width: PARENT_RIGHT
Y: 0 - 25
Font: BigBold
Contrast: true
Align: Center
Text: System Information
Background@bg:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Background: panel-black
Children:
Label@PROMPT_TEXT_A:
X: 15
Y: 15
Width: PARENT_RIGHT - 30
Height: 16
Align: Center
Text: We would like to collect some details that will help us optimize OpenRA.
Label@PROMPT_TEXT_B:
X: 15
Y: 33
Width: PARENT_RIGHT - 30
Height: 16
Align: Center
Text: With your permission, the following anonymous system data will be sent:
ScrollPanel@SYSINFO_DATA:
X: 15
Y: 63
Width: PARENT_RIGHT - 30
TopBottomSpacing: 4
ItemSpacing: 4
Height: 110
Children:
Label@DATA_TEMPLATE:
X: 8
Height: 13
VAlign: Top
Font: Small
Checkbox@SYSINFO_CHECKBOX:
X: PARENT_RIGHT - 15 - WIDTH
Y: PARENT_BOTTOM - 35
Width: 190
Height: 20
Font: Regular
Text: Send System Information
Button@CONTINUE_BUTTON:
X: PARENT_RIGHT - WIDTH
Y: PARENT_BOTTOM - 1
Width: 140
Height: 35
Text: Continue
Font: Bold
Key: return

View File

@@ -218,66 +218,6 @@ Container@MENU_BACKGROUND:
Text: Back
Font: Bold
Key: escape
Container@SYSTEM_INFO_PROMPT:
X: (WINDOW_RIGHT - WIDTH) / 2
Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 490
Height: 222
Children:
Label@TITLE:
Width: PARENT_RIGHT
Y: 0 - 25
Font: BigBold
Contrast: true
Align: Center
Text: System Information
Background@bg:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Background: panel-black
Children:
Label@PROMPT_TEXT_A:
X: 15
Y: 15
Width: PARENT_RIGHT - 30
Height: 16
Align: Center
Text: We would like to collect some details that will help us optimize OpenRA.
Label@PROMPT_TEXT_B:
X: 15
Y: 33
Width: PARENT_RIGHT - 30
Height: 16
Align: Center
Text: With your permission, the following anonymous system data will be sent:
ScrollPanel@SYSINFO_DATA:
X: 15
Y: 63
Width: PARENT_RIGHT - 30
TopBottomSpacing: 4
ItemSpacing: 4
Height: 110
Children:
Label@DATA_TEMPLATE:
X: 8
Height: 13
VAlign: Top
Font: Small
Checkbox@SYSINFO_CHECKBOX:
X: PARENT_RIGHT - 15 - WIDTH
Y: PARENT_BOTTOM - 35
Width: 190
Height: 20
Font: Regular
Text: Send System Information
Button@BACK_BUTTON:
X: PARENT_RIGHT - WIDTH
Y: PARENT_BOTTOM - 1
Width: 140
Height: 35
Text: Continue
Font: Bold
Key: return
Container@NEWS_BG:
Children:
DropDownButton@NEWS_BUTTON:

View File

@@ -92,6 +92,7 @@ Assemblies:
ChromeLayout:
cnc|chrome/mainmenu.yaml
cnc|chrome/mainmenu-prompts.yaml
cnc|chrome/playerprofile.yaml
cnc|chrome/multiplayer-browser.yaml
cnc|chrome/multiplayer-browserpanels.yaml

View File

@@ -0,0 +1,56 @@
Background@MAINMENU_SYSTEM_INFO_PROMPT:
Logic: SystemInfoPromptLogic
X: (WINDOW_RIGHT - WIDTH) / 2
Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 520
Height: 260
Children:
Label@PROMPT_TITLE:
Width: PARENT_RIGHT
Y: 20
Height: 25
Font: Bold
Align: Center
Text: System Information
Label@PROMPT_TEXT_A:
X: 15
Y: 50
Width: PARENT_RIGHT - 30
Height: 16
Align: Center
Text: We would like to collect some details that will help us optimize OpenRA.
Label@PROMPT_TEXT_B:
X: 15
Y: 68
Width: PARENT_RIGHT - 30
Height: 16
Align: Center
Text: With your permission, the following anonymous system data will be sent:
ScrollPanel@SYSINFO_DATA:
X: 20
Y: 98
Width: PARENT_RIGHT - 40
TopBottomSpacing: 4
ItemSpacing: 4
Height: 110
Children:
Label@DATA_TEMPLATE:
X: 8
Height: 13
VAlign: Top
Font: Small
Checkbox@SYSINFO_CHECKBOX:
X: 40
Y: PARENT_BOTTOM - 42
Width: 200
Height: 20
Font: Regular
Text: Send System Information
Button@CONTINUE_BUTTON:
X: PARENT_RIGHT - WIDTH - 20
Y: PARENT_BOTTOM - 45
Width: 120
Height: 25
Text: Continue
Font: Bold
Key: return

View File

@@ -218,61 +218,6 @@ Container@MAINMENU:
Height: 30
Text: Back
Font: Bold
Background@SYSTEM_INFO_PROMPT:
X: (WINDOW_RIGHT - WIDTH) / 2
Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 520
Height: 260
Children:
Label@PROMPT_TITLE:
Width: PARENT_RIGHT
Y: 20
Height: 25
Font: Bold
Align: Center
Text: System Information
Label@PROMPT_TEXT_A:
X: 15
Y: 50
Width: PARENT_RIGHT - 30
Height: 16
Align: Center
Text: We would like to collect some details that will help us optimize OpenRA.
Label@PROMPT_TEXT_B:
X: 15
Y: 68
Width: PARENT_RIGHT - 30
Height: 16
Align: Center
Text: With your permission, the following anonymous system data will be sent:
ScrollPanel@SYSINFO_DATA:
X: 20
Y: 98
Width: PARENT_RIGHT - 40
TopBottomSpacing: 4
ItemSpacing: 4
Height: 110
Children:
Label@DATA_TEMPLATE:
X: 8
Height: 13
VAlign: Top
Font: Small
Checkbox@SYSINFO_CHECKBOX:
X: 40
Y: PARENT_BOTTOM - 42
Width: 200
Height: 20
Font: Regular
Text: Send System Information
Button@BACK_BUTTON:
X: PARENT_RIGHT - WIDTH - 20
Y: PARENT_BOTTOM - 45
Width: 120
Height: 25
Text: Continue
Font: Bold
Key: return
Container@PERFORMANCE_INFO:
Logic: PerfDebugLogic
Children:

View File

@@ -205,61 +205,6 @@ Container@MAINMENU:
Height: 30
Text: Back
Font: Bold
Background@SYSTEM_INFO_PROMPT:
X: (WINDOW_RIGHT - WIDTH) / 2
Y: (WINDOW_BOTTOM - HEIGHT) / 2
Width: 520
Height: 260
Children:
Label@PROMPT_TITLE:
Width: PARENT_RIGHT
Y: 21
Height: 25
Font: Bold
Align: Center
Text: System Information
Label@PROMPT_TEXT_A:
X: 15
Y: 51
Width: PARENT_RIGHT - 30
Height: 16
Align: Center
Text: We would like to collect some details that will help us optimize OpenRA.
Label@PROMPT_TEXT_B:
X: 15
Y: 69
Width: PARENT_RIGHT - 30
Height: 16
Align: Center
Text: With your permission, the following anonymous system data will be sent:
ScrollPanel@SYSINFO_DATA:
X: 20
Y: 98
Width: PARENT_RIGHT - 40
TopBottomSpacing: 4
ItemSpacing: 4
Height: 110
Children:
Label@DATA_TEMPLATE:
X: 8
Height: 13
VAlign: Top
Font: Small
Checkbox@SYSINFO_CHECKBOX:
X: 40
Y: PARENT_BOTTOM - 42
Width: 200
Height: 20
Font: Regular
Text: Send System Information
Button@BACK_BUTTON:
X: PARENT_RIGHT - WIDTH - 20
Y: PARENT_BOTTOM - 45
Width: 120
Height: 25
Text: Continue
Font: Bold
Key: return
Background@NEWS_BG:
X: (WINDOW_RIGHT - WIDTH) / 2
Y: 35

View File

@@ -82,6 +82,7 @@ ChromeLayout:
common|chrome/ingame-debuginfo.yaml
common|chrome/ingame-infochat.yaml
d2k|chrome/mainmenu.yaml
common|chrome/mainmenu-prompts.yaml
common|chrome/settings.yaml
common|chrome/credits.yaml
common|chrome/lobby.yaml

View File

@@ -97,6 +97,7 @@ ChromeLayout:
common|chrome/ingame-debuginfo.yaml
common|chrome/ingame-infochat.yaml
common|chrome/mainmenu.yaml
common|chrome/mainmenu-prompts.yaml
common|chrome/settings.yaml
common|chrome/credits.yaml
common|chrome/lobby.yaml

View File

@@ -144,6 +144,7 @@ ChromeLayout:
common|chrome/ingame-debuginfo.yaml
common|chrome/ingame-infochat.yaml
common|chrome/mainmenu.yaml
common|chrome/mainmenu-prompts.yaml
ts|chrome/mainmenu-prerelease-notification.yaml
common|chrome/settings.yaml
common|chrome/credits.yaml