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.
This commit is contained in:
penev92
2023-02-22 00:18:28 +02:00
committed by Matthias Mailänder
parent c5aee7b2cf
commit 8a59982420
4 changed files with 56 additions and 16 deletions

View File

@@ -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<string, bool> selectedPackages;
Mode visible = Mode.Progress;
[ObjectCreator.UseCtor]
@@ -144,7 +148,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
listPanel = listContainer.Get<ScrollPanelWidget>("LIST_PANEL");
listHeaderTemplate = listPanel.Get("LIST_HEADER_TEMPLATE");
listTemplate = listPanel.Get<LabelWidget>("LIST_TEMPLATE");
labelListTemplate = listPanel.Get<LabelWidget>("LABEL_LIST_TEMPLATE");
checkboxListTemplate = listPanel.Get<CheckboxWidget>("CHECKBOX_LIST_TEMPLATE");
listPanel.RemoveChildren();
listLabel = listContainer.Get<LabelWidget>("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<string> 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);
}

View File

@@ -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

View File

@@ -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.

View File

@@ -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