From 8a5998242040ffd57eb601f318740888cf9006c1 Mon Sep 17 00:00:00 2001 From: penev92 Date: Wed, 22 Feb 2023 00:18:28 +0200 Subject: [PATCH] Made Advanced installation offer optional packages Previously all detected content would be installed. Now the user can choose whether they want to install the optional packages like music and videos. --- .../Installation/InstallFromSourceLogic.cs | 41 ++++++++++++------- mods/common/languages/en.ftl | 2 +- mods/modcontent/chrome.yaml | 23 +++++++++++ mods/modcontent/content.yaml | 6 ++- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromSourceLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromSourceLogic.cs index eed21fc83a..fe7cf637c7 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromSourceLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromSourceLogic.cs @@ -105,9 +105,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic readonly Widget listContainer; readonly ScrollPanelWidget listPanel; readonly Widget listHeaderTemplate; - readonly LabelWidget listTemplate; + readonly LabelWidget labelListTemplate; + readonly CheckboxWidget checkboxListTemplate; readonly LabelWidget listLabel; + ModContent.ModPackage[] availablePackages; + IDictionary selectedPackages; + Mode visible = Mode.Progress; [ObjectCreator.UseCtor] @@ -144,7 +148,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic listPanel = listContainer.Get("LIST_PANEL"); listHeaderTemplate = listPanel.Get("LIST_HEADER_TEMPLATE"); - listTemplate = listPanel.Get("LIST_TEMPLATE"); + labelListTemplate = listPanel.Get("LABEL_LIST_TEMPLATE"); + checkboxListTemplate = listPanel.Get("CHECKBOX_LIST_TEMPLATE"); listPanel.RemoveChildren(); listLabel = listContainer.Get("LIST_MESSAGE"); @@ -171,16 +176,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic { Log.Write("install", $"Using installer `{kv.Key}: {kv.Value.Title}` of type `{kv.Value.Type.Value}`:"); - var packages = content.Packages.Values + availablePackages = content.Packages.Values .Where(p => p.Sources.Contains(kv.Key) && !p.IsInstalled()) - .Select(p => p.Title); + .ToArray(); + + selectedPackages = availablePackages.ToDictionary(x => x.Identifier, y => y.Required); // Ignore source if content is already installed - if (packages.Any()) + if (availablePackages.Any()) { Game.RunAfterTick(() => { - ShowList(kv.Value.Title, modData.Translation.GetString(ContentPackageInstallation), packages); + ShowList(kv.Value.Title, modData.Translation.GetString(ContentPackageInstallation)); ShowContinueCancel(() => InstallFromSource(path, kv.Value)); }); @@ -255,7 +262,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic RunSourceActions(beforeInstall); foreach (var packageInstallationNode in modSource.Install.Where(x => x.Key == "ContentPackage")) - RunSourceActions(packageInstallationNode); + { + var packageName = packageInstallationNode.Value.Nodes.SingleOrDefault(x => x.Key == "Name")?.Value.Value; + if (!string.IsNullOrEmpty(packageName) && selectedPackages.ContainsKey(packageName) && selectedPackages[packageName]) + RunSourceActions(packageInstallationNode); + } var afterInstall = modSource.Install.FirstOrDefault(x => x.Key == "AfterInstall"); if (afterInstall != null) @@ -310,19 +321,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic panel.Bounds.Height = progressContainer.Bounds.Height; } - void ShowList(string title, string message, IEnumerable items) + void ShowList(string title, string message) { visible = Mode.List; titleLabel.Text = title; listLabel.Text = message; listPanel.RemoveChildren(); - foreach (var i in items) + foreach (var package in availablePackages) { - var item = i; - var labelWidget = (LabelWidget)listTemplate.Clone(); - labelWidget.GetText = () => item; - listPanel.AddChild(labelWidget); + var checkboxWidget = (CheckboxWidget)checkboxListTemplate.Clone(); + checkboxWidget.GetText = () => package.Title; + checkboxWidget.IsDisabled = () => package.Required; + checkboxWidget.IsChecked = () => selectedPackages[package.Identifier]; + checkboxWidget.OnClick = () => selectedPackages[package.Identifier] = !selectedPackages[package.Identifier]; + listPanel.AddChild(checkboxWidget); } primaryButton.Bounds.Y += listContainer.Bounds.Height - panel.Bounds.Height; @@ -353,7 +366,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic foreach (var i in kv.Value) { var item = i; - var labelWidget = (LabelWidget)listTemplate.Clone(); + var labelWidget = (LabelWidget)labelListTemplate.Clone(); labelWidget.GetText = () => item; listPanel.AddChild(labelWidget); } diff --git a/mods/common/languages/en.ftl b/mods/common/languages/en.ftl index 6032da6c23..05043f5d6b 100644 --- a/mods/common/languages/en.ftl +++ b/mods/common/languages/en.ftl @@ -260,7 +260,7 @@ label-mirror-selection-failed = Online mirror is not available. Please install f label-detecting-sources = Detecting drives label-checking-sources = Checking Sources label-searching-source-for = Searching for { $title } -label-content-package-installation = The following content packages will be installed: +label-content-package-installation = Select which content packages you want to install: label-game-sources = Game Sources label-digital-installs = Digital Installs label-game-content-not-found = Game Content Not Found diff --git a/mods/modcontent/chrome.yaml b/mods/modcontent/chrome.yaml index 698699b827..cd9de8874c 100644 --- a/mods/modcontent/chrome.yaml +++ b/mods/modcontent/chrome.yaml @@ -109,3 +109,26 @@ scrollpanel-decorations: down-pressed: 453, 512, 16, 16 up: 470, 512, 16, 16 up-pressed: 470, 512, 16, 16 + + +# Checkbox-related definitions: + +checkbox: + Inherits: ^Chrome + PanelRegion: 512, 512, 10, 10, 44, 44, 10, 10 + +checkbox-hover: + Inherits: checkbox + +checkbox-pressed: + Inherits: checkbox + +checkbox-disabled: + Inherits: checkbox + +checkmark-tick: + Inherits: ^Chrome + Regions: + checked: 455, 526, 16, 16 + checked-disabled: 474, 526, 16, 16 + unchecked: 0, 0, 0, 0 # Empty placeholder to appease the missing-sprite-exception gods. diff --git a/mods/modcontent/content.yaml b/mods/modcontent/content.yaml index ef6616083a..b154bcb1c2 100644 --- a/mods/modcontent/content.yaml +++ b/mods/modcontent/content.yaml @@ -264,7 +264,11 @@ Background@SOURCE_INSTALL_PANEL: Width: PARENT_RIGHT Height: 1 Background: panel-rule - Label@LIST_TEMPLATE: + Label@LABEL_LIST_TEMPLATE: + X: 6 + Width: PARENT_RIGHT - 16 + Height: 23 + Checkbox@CHECKBOX_LIST_TEMPLATE: X: 6 Width: PARENT_RIGHT - 16 Height: 23