diff --git a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs index 2863a39dcb..247747a8a4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MainMenuLogic.cs @@ -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> GetSystemInformation() - { - var lang = System.Globalization.CultureInfo.InstalledUICulture.TwoLetterISOLanguageName; - return new Dictionary>() - { - { "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("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("SYSINFO_CHECKBOX"); - sysInfoCheckbox.IsChecked = () => Game.Settings.Debug.SendSystemInformation; - sysInfoCheckbox.OnClick = () => Game.Settings.Debug.SendSystemInformation ^= true; - - var sysInfoData = sysInfoPrompt.Get("SYSINFO_DATA"); - var template = sysInfoData.Get("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("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, diff --git a/OpenRA.Mods.Common/Widgets/Logic/SystemInfoPromptLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SystemInfoPromptLogic.cs new file mode 100644 index 0000000000..4fb230be68 --- /dev/null +++ b/OpenRA.Mods.Common/Widgets/Logic/SystemInfoPromptLogic.cs @@ -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> GetSystemInformation() + { + var lang = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName; + return new Dictionary>() + { + { "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("SYSINFO_CHECKBOX"); + sysInfoCheckbox.IsChecked = () => Game.Settings.Debug.SendSystemInformation; + sysInfoCheckbox.OnClick = () => Game.Settings.Debug.SendSystemInformation ^= true; + + var sysInfoData = widget.Get("SYSINFO_DATA"); + var template = sysInfoData.Get("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("CONTINUE_BUTTON").OnClick = () => + { + Game.Settings.Debug.SystemInformationVersionPrompt = SystemInformationVersion; + Game.Settings.Save(); + Ui.CloseWindow(); + onComplete(); + }; + } + } +} diff --git a/mods/cnc/chrome/mainmenu-prompts.yaml b/mods/cnc/chrome/mainmenu-prompts.yaml new file mode 100644 index 0000000000..da0ea7b93d --- /dev/null +++ b/mods/cnc/chrome/mainmenu-prompts.yaml @@ -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 diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index b3501db434..b5c61008c9 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -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: diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index f86fb6348b..bb2a5eb1cf 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -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 diff --git a/mods/common/chrome/mainmenu-prompts.yaml b/mods/common/chrome/mainmenu-prompts.yaml new file mode 100644 index 0000000000..3f07fb498d --- /dev/null +++ b/mods/common/chrome/mainmenu-prompts.yaml @@ -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 diff --git a/mods/common/chrome/mainmenu.yaml b/mods/common/chrome/mainmenu.yaml index 16f81654db..5b5bee04fc 100644 --- a/mods/common/chrome/mainmenu.yaml +++ b/mods/common/chrome/mainmenu.yaml @@ -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: diff --git a/mods/d2k/chrome/mainmenu.yaml b/mods/d2k/chrome/mainmenu.yaml index 5d01a06539..cdac71bd53 100644 --- a/mods/d2k/chrome/mainmenu.yaml +++ b/mods/d2k/chrome/mainmenu.yaml @@ -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 diff --git a/mods/d2k/mod.yaml b/mods/d2k/mod.yaml index 87dd3fa9ea..a0e04388ed 100644 --- a/mods/d2k/mod.yaml +++ b/mods/d2k/mod.yaml @@ -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 diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 1abded59e0..ad9d14253d 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -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 diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index 8750b4fea4..60751704c9 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -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