Merge pull request #9263 from penev92/assetInstallation
Move asset installation to the ModChooser
This commit is contained in:
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
public string Background = "button";
|
||||
public bool Depressed = false;
|
||||
public int VisualHeight = ChromeMetrics.Get<int>("ButtonDepth");
|
||||
public int BaseLine = 0;
|
||||
public int BaseLine = ChromeMetrics.Get<int>("ButtonBaseLine");
|
||||
public string Font = ChromeMetrics.Get<string>("ButtonFont");
|
||||
public Color TextColor = ChromeMetrics.Get<Color>("ButtonTextColor");
|
||||
public Color TextColorDisabled = ChromeMetrics.Get<Color>("ButtonTextColorDisabled");
|
||||
|
||||
@@ -9,11 +9,10 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -21,24 +20,29 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class DownloadPackagesLogic
|
||||
{
|
||||
static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
||||
readonly Widget panel;
|
||||
readonly string modId;
|
||||
readonly string mirrorListUrl;
|
||||
readonly ProgressBarWidget progressBar;
|
||||
readonly LabelWidget statusLabel;
|
||||
readonly Action afterInstall;
|
||||
string mirror;
|
||||
static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public DownloadPackagesLogic(Widget widget, Action afterInstall, string mirrorListUrl)
|
||||
public DownloadPackagesLogic(Widget widget, Action afterInstall, string mirrorListUrl, string modId)
|
||||
{
|
||||
this.mirrorListUrl = mirrorListUrl;
|
||||
this.afterInstall = afterInstall;
|
||||
this.modId = modId;
|
||||
|
||||
panel = widget.Get("INSTALL_DOWNLOAD_PANEL");
|
||||
progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR");
|
||||
statusLabel = panel.Get<LabelWidget>("STATUS_LABEL");
|
||||
|
||||
var text = "Downloading {0} assets...".F(ModMetadata.AllMods[modId].Title);
|
||||
panel.Get<LabelWidget>("TITLE").Text = text;
|
||||
|
||||
ShowDownloadDialog();
|
||||
}
|
||||
|
||||
@@ -52,9 +56,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var cancelButton = panel.Get<ButtonWidget>("CANCEL_BUTTON");
|
||||
|
||||
var mirrorsFile = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id, "mirrors.txt");
|
||||
var file = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
var dest = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id);
|
||||
var dest = Platform.ResolvePath("^", "Content", modId);
|
||||
|
||||
Action<DownloadProgressChangedEventArgs> onDownloadProgress = i =>
|
||||
{
|
||||
@@ -100,7 +103,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
onError(Download.FormatErrorMessage(i.Error));
|
||||
return;
|
||||
}
|
||||
else if (cancelled)
|
||||
|
||||
if (cancelled)
|
||||
{
|
||||
onError("Download cancelled");
|
||||
return;
|
||||
@@ -119,7 +123,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
};
|
||||
|
||||
Action<AsyncCompletedEventArgs, bool> onFetchMirrorsComplete = (i, cancelled) =>
|
||||
Action<DownloadDataCompletedEventArgs, bool> onFetchMirrorsComplete = (i, cancelled) =>
|
||||
{
|
||||
progressBar.Indeterminate = true;
|
||||
|
||||
@@ -128,21 +132,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
onError(Download.FormatErrorMessage(i.Error));
|
||||
return;
|
||||
}
|
||||
else if (cancelled)
|
||||
|
||||
if (cancelled)
|
||||
{
|
||||
onError("Download cancelled");
|
||||
return;
|
||||
}
|
||||
|
||||
var mirrorList = new List<string>();
|
||||
using (var r = new StreamReader(mirrorsFile))
|
||||
{
|
||||
string line;
|
||||
while ((line = r.ReadLine()) != null)
|
||||
if (!string.IsNullOrEmpty(line))
|
||||
mirrorList.Add(line);
|
||||
}
|
||||
|
||||
var data = Encoding.UTF8.GetString(i.Result);
|
||||
var mirrorList = data.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
mirror = mirrorList.Random(new MersenneTwister());
|
||||
|
||||
// Save the package to a temp file
|
||||
@@ -152,7 +150,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
};
|
||||
|
||||
// Get the list of mirrors
|
||||
var updateMirrors = new Download(mirrorListUrl, mirrorsFile, onDownloadProgress, onFetchMirrorsComplete);
|
||||
var updateMirrors = new Download(mirrorListUrl, onDownloadProgress, onFetchMirrorsComplete);
|
||||
cancelButton.OnClick = () => { updateMirrors.Cancel(); Ui.CloseWindow(); };
|
||||
retryButton.OnClick = () => { updateMirrors.Cancel(); ShowDownloadDialog(); };
|
||||
}
|
||||
|
||||
@@ -19,19 +19,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class InstallFromCDLogic
|
||||
{
|
||||
readonly string modId;
|
||||
readonly Widget panel;
|
||||
readonly ProgressBarWidget progressBar;
|
||||
readonly LabelWidget statusLabel;
|
||||
readonly Action continueLoading;
|
||||
readonly Action afterInstall;
|
||||
readonly ButtonWidget retryButton, backButton;
|
||||
readonly Widget installingContainer, insertDiskContainer;
|
||||
readonly ContentInstaller installData;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public InstallFromCDLogic(Widget widget, Action continueLoading)
|
||||
public InstallFromCDLogic(Widget widget, Action afterInstall, string modId)
|
||||
{
|
||||
installData = Game.ModData.Manifest.Get<ContentInstaller>();
|
||||
this.continueLoading = continueLoading;
|
||||
this.modId = modId;
|
||||
installData = ModMetadata.AllMods[modId].Content;
|
||||
this.afterInstall = afterInstall;
|
||||
panel = widget.Get("INSTALL_FROMCD_PANEL");
|
||||
progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR");
|
||||
statusLabel = panel.Get<LabelWidget>("STATUS_LABEL");
|
||||
@@ -74,6 +76,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
InstallTFD(Platform.ResolvePath(path, "data1.hdr"));
|
||||
else
|
||||
{
|
||||
var text = "Please insert a {0} install CD and click Retry.".F(ModMetadata.AllMods[modId].Title);
|
||||
insertDiskContainer.Get<LabelWidget>("INFO2").Text = text;
|
||||
|
||||
insertDiskContainer.IsVisible = () => true;
|
||||
installingContainer.IsVisible = () => false;
|
||||
}
|
||||
@@ -103,13 +108,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
var filename = cabExtractor.FileName(index);
|
||||
statusLabel.GetText = () => "Extracting {0}".F(filename);
|
||||
var dest = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id, filename.ToLowerInvariant());
|
||||
var dest = Platform.ResolvePath("^", "Content", modId, filename.ToLowerInvariant());
|
||||
cabExtractor.ExtractFile(index, dest);
|
||||
progressBar.Percentage += installPercent;
|
||||
}
|
||||
|
||||
var ArchivesToExtract = installData.InstallShieldCABFilePackageIds.Select(x => x.Split(':'));
|
||||
var destDir = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id);
|
||||
var destDir = Platform.ResolvePath("^", "Content", modId);
|
||||
var onError = (Action<string>)(s => { });
|
||||
var overwrite = installData.OverwriteFiles;
|
||||
|
||||
@@ -124,7 +129,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
var filename = cabExtractor.FileName(uint.Parse(archive[0]));
|
||||
statusLabel.GetText = () => "Extracting {0}".F(filename);
|
||||
var destFile = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id, filename.ToLowerInvariant());
|
||||
var destFile = Platform.ResolvePath("^", "Content", modId, filename.ToLowerInvariant());
|
||||
cabExtractor.ExtractFile(uint.Parse(archive[0]), destFile);
|
||||
var annotation = archive.Length > 1 ? archive[1] : null;
|
||||
InstallUtils.ExtractFromPackage(source, destFile, annotation, extractFiles, destDir, overwrite, onProgress, onError);
|
||||
@@ -132,7 +137,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
}
|
||||
|
||||
continueLoading();
|
||||
afterInstall();
|
||||
}) { IsBackground = true }.Start();
|
||||
}
|
||||
|
||||
@@ -143,7 +148,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
insertDiskContainer.IsVisible = () => false;
|
||||
installingContainer.IsVisible = () => true;
|
||||
|
||||
var dest = Platform.ResolvePath("^", "Content", Game.ModData.Manifest.Mod.Id);
|
||||
var dest = Platform.ResolvePath("^", "Content", modId);
|
||||
var copyFiles = installData.CopyFilesFromCD;
|
||||
|
||||
var packageToExtract = installData.PackageToExtractFromCD.Split(':');
|
||||
@@ -193,7 +198,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
statusLabel.GetText = () => "Game assets have been extracted.";
|
||||
Ui.CloseWindow();
|
||||
continueLoading();
|
||||
afterInstall();
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
@@ -17,31 +15,28 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public class InstallLogic : Widget
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public InstallLogic(Widget widget, Action continueLoading)
|
||||
public InstallLogic(Widget widget, string mirrorListUrl, string modId)
|
||||
{
|
||||
var installData = Game.ModData.Manifest.Get<ContentInstaller>();
|
||||
var panel = widget.Get("INSTALL_PANEL");
|
||||
var widgetArgs = new WidgetArgs()
|
||||
var widgetArgs = new WidgetArgs
|
||||
{
|
||||
{ "afterInstall", () => { Ui.CloseWindow(); continueLoading(); } },
|
||||
{ "continueLoading", continueLoading },
|
||||
{ "mirrorListUrl", installData.PackageMirrorList },
|
||||
{ "afterInstall", () => { Game.InitializeMod(modId, new Arguments()); } },
|
||||
{ "mirrorListUrl", mirrorListUrl },
|
||||
{ "modId", modId }
|
||||
};
|
||||
|
||||
panel.Get<ButtonWidget>("DOWNLOAD_BUTTON").OnClick = () =>
|
||||
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", widgetArgs);
|
||||
var mod = ModMetadata.AllMods[modId];
|
||||
var text = "OpenRA requires the original {0} game content.".F(mod.Title);
|
||||
panel.Get<LabelWidget>("DESC1").Text = text;
|
||||
|
||||
var downloadButton = panel.Get<ButtonWidget>("DOWNLOAD_BUTTON");
|
||||
downloadButton.OnClick = () => Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", widgetArgs);
|
||||
downloadButton.IsDisabled = () => string.IsNullOrEmpty(mod.Content.PackageMirrorList);
|
||||
|
||||
panel.Get<ButtonWidget>("INSTALL_BUTTON").OnClick = () =>
|
||||
Ui.OpenWindow("INSTALL_FROMCD_PANEL", widgetArgs);
|
||||
|
||||
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
|
||||
{
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
Game.Settings.Game.PreviousMod = Game.ModData.Manifest.Mod.Id;
|
||||
Game.InitializeMod("modchooser", null);
|
||||
});
|
||||
};
|
||||
panel.Get<ButtonWidget>("BACK_BUTTON").OnClick = Ui.CloseWindow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,6 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.FileSystem;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
@@ -20,38 +16,41 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public class InstallMusicLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public InstallMusicLogic(Widget widget)
|
||||
public InstallMusicLogic(Widget widget, string modId)
|
||||
{
|
||||
var installMusicContainer = widget.Get("INSTALL_MUSIC_PANEL");
|
||||
|
||||
Action loadDefaultMod = () => Game.RunAfterTick(() =>
|
||||
Game.InitializeMod(Game.Settings.Game.Mod, null));
|
||||
Action loadDefaultMod = () => Game.RunAfterTick(() => Game.InitializeMod(modId, null));
|
||||
|
||||
var cancelButton = installMusicContainer.GetOrNull<ButtonWidget>("CANCEL_BUTTON");
|
||||
var cancelButton = installMusicContainer.GetOrNull<ButtonWidget>("BACK_BUTTON");
|
||||
if (cancelButton != null)
|
||||
cancelButton.OnClick = loadDefaultMod;
|
||||
|
||||
var copyFromDiscButton = installMusicContainer.GetOrNull<ButtonWidget>("COPY_FROM_CD_BUTTON");
|
||||
var copyFromDiscButton = installMusicContainer.GetOrNull<ButtonWidget>("INSTALL_MUSIC_BUTTON");
|
||||
if (copyFromDiscButton != null)
|
||||
{
|
||||
copyFromDiscButton.OnClick = () =>
|
||||
{
|
||||
Ui.OpenWindow("INSTALL_FROMCD_PANEL", new WidgetArgs() {
|
||||
{ "continueLoading", loadDefaultMod },
|
||||
Ui.OpenWindow("INSTALL_FROMCD_PANEL", new WidgetArgs
|
||||
{
|
||||
{ "afterInstall", loadDefaultMod },
|
||||
{ "modId", modId }
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
var downloadButton = installMusicContainer.GetOrNull<ButtonWidget>("DOWNLOAD_BUTTON");
|
||||
var downloadButton = installMusicContainer.GetOrNull<ButtonWidget>("DOWNLOAD_MUSIC_BUTTON");
|
||||
if (downloadButton != null)
|
||||
{
|
||||
var installData = Game.ModData.Manifest.Get<ContentInstaller>();
|
||||
downloadButton.IsVisible = () => !string.IsNullOrEmpty(installData.MusicPackageMirrorList);
|
||||
var installData = ModMetadata.AllMods[modId].Content;
|
||||
downloadButton.IsDisabled = () => string.IsNullOrEmpty(installData.MusicPackageMirrorList);
|
||||
downloadButton.OnClick = () =>
|
||||
{
|
||||
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", new WidgetArgs() {
|
||||
Ui.OpenWindow("INSTALL_DOWNLOAD_PANEL", new WidgetArgs
|
||||
{
|
||||
{ "afterInstall", loadDefaultMod },
|
||||
{ "mirrorListUrl", installData.MusicPackageMirrorList },
|
||||
{ "modId", modId }
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
@@ -25,6 +26,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly ModMetadata[] allMods;
|
||||
readonly Dictionary<string, Sprite> previews = new Dictionary<string, Sprite>();
|
||||
readonly Dictionary<string, Sprite> logos = new Dictionary<string, Sprite>();
|
||||
readonly Cache<ModMetadata, bool> modInstallStatus;
|
||||
readonly Widget modChooserPanel;
|
||||
readonly ButtonWidget loadButton;
|
||||
readonly SheetBuilder sheetBuilder;
|
||||
ModMetadata selectedMod;
|
||||
string selectedAuthor;
|
||||
@@ -34,30 +38,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
[ObjectCreator.UseCtor]
|
||||
public ModBrowserLogic(Widget widget)
|
||||
{
|
||||
var panel = widget;
|
||||
var loadButton = panel.Get<ButtonWidget>("LOAD_BUTTON");
|
||||
modChooserPanel = widget;
|
||||
loadButton = modChooserPanel.Get<ButtonWidget>("LOAD_BUTTON");
|
||||
loadButton.OnClick = () => LoadMod(selectedMod);
|
||||
loadButton.IsDisabled = () => selectedMod.Id == Game.ModData.Manifest.Mod.Id;
|
||||
|
||||
panel.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
|
||||
modChooserPanel.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
|
||||
|
||||
modList = panel.Get("MOD_LIST");
|
||||
modList = modChooserPanel.Get("MOD_LIST");
|
||||
modTemplate = modList.Get<ButtonWidget>("MOD_TEMPLATE");
|
||||
|
||||
panel.Get<LabelWidget>("MOD_DESC").GetText = () => selectedDescription;
|
||||
panel.Get<LabelWidget>("MOD_TITLE").GetText = () => selectedMod.Title;
|
||||
panel.Get<LabelWidget>("MOD_AUTHOR").GetText = () => selectedAuthor;
|
||||
panel.Get<LabelWidget>("MOD_VERSION").GetText = () => selectedMod.Version;
|
||||
modChooserPanel.Get<LabelWidget>("MOD_DESC").GetText = () => selectedDescription;
|
||||
modChooserPanel.Get<LabelWidget>("MOD_TITLE").GetText = () => selectedMod.Title;
|
||||
modChooserPanel.Get<LabelWidget>("MOD_AUTHOR").GetText = () => selectedAuthor;
|
||||
modChooserPanel.Get<LabelWidget>("MOD_VERSION").GetText = () => selectedMod.Version;
|
||||
|
||||
var prevMod = panel.Get<ButtonWidget>("PREV_MOD");
|
||||
var prevMod = modChooserPanel.Get<ButtonWidget>("PREV_MOD");
|
||||
prevMod.OnClick = () => { modOffset -= 1; RebuildModList(); };
|
||||
prevMod.IsVisible = () => modOffset > 0;
|
||||
|
||||
var nextMod = panel.Get<ButtonWidget>("NEXT_MOD");
|
||||
var nextMod = modChooserPanel.Get<ButtonWidget>("NEXT_MOD");
|
||||
nextMod.OnClick = () => { modOffset += 1; RebuildModList(); };
|
||||
nextMod.IsVisible = () => modOffset + 5 < allMods.Length;
|
||||
|
||||
panel.Get<RGBASpriteWidget>("MOD_PREVIEW").GetSprite = () =>
|
||||
modChooserPanel.Get<RGBASpriteWidget>("MOD_PREVIEW").GetSprite = () =>
|
||||
{
|
||||
Sprite ret = null;
|
||||
previews.TryGetValue(selectedMod.Id, out ret);
|
||||
@@ -89,9 +93,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
ModMetadata initialMod = null;
|
||||
modInstallStatus = new Cache<ModMetadata, bool>(IsModInstalled);
|
||||
|
||||
ModMetadata initialMod;
|
||||
ModMetadata.AllMods.TryGetValue(Game.Settings.Game.PreviousMod, out initialMod);
|
||||
SelectMod(initialMod ?? ModMetadata.AllMods["ra"]);
|
||||
SelectMod(initialMod != null && initialMod.Id != "modchooser" ? initialMod : ModMetadata.AllMods["ra"]);
|
||||
|
||||
RebuildModList();
|
||||
}
|
||||
@@ -113,6 +119,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
break;
|
||||
|
||||
var mod = allMods[j];
|
||||
|
||||
var item = modTemplate.Clone() as ButtonWidget;
|
||||
item.Bounds = new Rectangle(outerMargin + i * stride, 0, width, height);
|
||||
item.IsHighlighted = () => selectedMod == mod;
|
||||
@@ -148,10 +155,27 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var selectedIndex = Array.IndexOf(allMods, mod);
|
||||
if (selectedIndex - modOffset > 4)
|
||||
modOffset = selectedIndex - 4;
|
||||
|
||||
loadButton.Text = modInstallStatus[mod] ? "Load Mod" : "Install Assets";
|
||||
}
|
||||
|
||||
void LoadMod(ModMetadata mod)
|
||||
{
|
||||
if (!modInstallStatus[mod])
|
||||
{
|
||||
var widgetArgs = new WidgetArgs
|
||||
{
|
||||
{ "continueLoading", () =>
|
||||
Game.RunAfterTick(() => Game.InitializeMod(Game.Settings.Game.Mod, new Arguments())) },
|
||||
{ "mirrorListUrl", mod.Content.PackageMirrorList },
|
||||
{ "modId", mod.Id }
|
||||
};
|
||||
|
||||
Ui.OpenWindow("INSTALL_PANEL", widgetArgs);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Game.RunAfterTick(() =>
|
||||
{
|
||||
Ui.CloseWindow();
|
||||
@@ -159,5 +183,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Game.InitializeMod(mod.Id, null);
|
||||
});
|
||||
}
|
||||
|
||||
static bool IsModInstalled(ModMetadata mod)
|
||||
{
|
||||
return mod.Content.TestFiles.All(file => File.Exists(Path.GetFullPath(Platform.ResolvePath(file))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,11 +90,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var installButton = widget.GetOrNull<ButtonWidget>("INSTALL_BUTTON");
|
||||
if (installButton != null)
|
||||
{
|
||||
installButton.IsDisabled = () => world == null || world.Type != WorldType.Shellmap;
|
||||
var args = new string[] { "Install.Music=true" };
|
||||
installButton.IsDisabled = () => world.Type != WorldType.Shellmap;
|
||||
var args = new[] { "installMusic={0}".F(Game.ModData.Manifest.Mod.Id) };
|
||||
installButton.OnClick = () =>
|
||||
Game.RunAfterTick(() =>
|
||||
Game.InitializeMod(Game.Settings.Game.Mod, new Arguments(args)));
|
||||
Game.RunAfterTick(() => Game.InitializeMod("modchooser", new Arguments(args)));
|
||||
|
||||
var installData = Game.ModData.Manifest.Get<ContentInstaller>();
|
||||
installButton.IsVisible = () => modRules.InstalledMusic.ToArray().Length <= installData.ShippedSoundtracks;
|
||||
|
||||
@@ -10,12 +10,17 @@
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
public class ProgressBarWidget : Widget
|
||||
{
|
||||
public string Background = "progressbar-bg";
|
||||
public string Bar = "progressbar-thumb";
|
||||
public Size BarMargin = new Size(2, 2);
|
||||
|
||||
public int Percentage = 0;
|
||||
public bool Indeterminate = false;
|
||||
|
||||
@@ -44,14 +49,16 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
var rb = RenderBounds;
|
||||
var percentage = GetPercentage();
|
||||
WidgetUtils.DrawPanel("progressbar-bg", rb);
|
||||
WidgetUtils.DrawPanel(Background, rb);
|
||||
|
||||
var barRect = wasIndeterminate ?
|
||||
new Rectangle(rb.X + 2 + (int)(0.75 * offset * (rb.Width - 4)), rb.Y + 2, (rb.Width - 4) / 4, rb.Height - 4) :
|
||||
new Rectangle(rb.X + 2, rb.Y + 2, percentage * (rb.Width - 4) / 100, rb.Height - 4);
|
||||
var minBarWidth = (int)(ChromeProvider.GetImage(Bar, "border-l").Size.X + ChromeProvider.GetImage(Bar, "border-r").Size.X);
|
||||
var maxBarWidth = rb.Width - BarMargin.Width * 2;
|
||||
var barWidth = wasIndeterminate ? maxBarWidth / 4 : percentage * maxBarWidth / 100;
|
||||
barWidth = Math.Max(barWidth, minBarWidth);
|
||||
|
||||
if (barRect.Width > 0)
|
||||
WidgetUtils.DrawPanel("progressbar-thumb", barRect);
|
||||
var barOffset = wasIndeterminate ? (int)(0.75 * offset * maxBarWidth) : 0;
|
||||
var barRect = new Rectangle(rb.X + BarMargin.Width + barOffset, rb.Y + BarMargin.Height, barWidth, rb.Height - 2 * BarMargin.Height);
|
||||
WidgetUtils.DrawPanel(Bar, barRect);
|
||||
}
|
||||
|
||||
bool wasIndeterminate;
|
||||
|
||||
Reference in New Issue
Block a user