Merge pull request #10716 from Mailaender/all-assets

Re-enabled All Packages which seems to be fast enough now.
This commit is contained in:
Oliver Brakmann
2016-02-07 21:10:31 +01:00

View File

@@ -22,7 +22,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
public class AssetBrowserLogic : ChromeLogic
{
static string[] allowedExtensions;
readonly string[] allowedExtensions;
readonly IEnumerable<IReadOnlyPackage> acceptablePackages;
readonly World world;
@@ -50,7 +51,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
this.world = world;
panel = widget;
assetSource = Game.ModData.ModFiles.MountedPackages.First();
var ticker = panel.GetOrNull<LogicTickerWidget>("ANIMATION_TICKER");
if (ticker != null)
@@ -217,6 +217,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
else
allowedExtensions = new string[0];
acceptablePackages = Game.ModData.ModFiles.MountedPackages.Where(p =>
p.Contents.Any(c => allowedExtensions.Contains(Path.GetExtension(c).ToLowerInvariant())));
assetList = panel.Get<ScrollPanelWidget>("ASSET_LIST");
template = panel.Get<ScrollItemWidget>("ASSET_TEMPLATE");
PopulateAssetList();
@@ -343,9 +346,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return item;
};
// TODO: Re-enable "All Packages" once list generation is done in a background thread
// var sources = new[] { (IPackage)null }.Concat(GlobalFileSystem.MountedFolders);
var sources = Game.ModData.ModFiles.MountedPackages;
var sources = new[] { (IReadOnlyPackage)null }.Concat(acceptablePackages);
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 280, sources, setupItem);
return true;
}
@@ -355,14 +356,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
assetList.RemoveChildren();
availableShps.Clear();
// TODO: This is too slow to run in the main thread
// var files = AssetSource != null ? AssetSource.AllFileNames() :
// GlobalFileSystem.MountedFolders.SelectMany(f => f.AllFileNames());
if (assetSource == null)
return;
var files = assetSource.Contents.OrderBy(s => s);
foreach (var file in files)
var files = assetSource != null ? assetSource.Contents : Game.ModData.ModFiles.MountedPackages.SelectMany(f => f.Contents).Distinct();
foreach (var file in files.OrderBy(s => s))
{
if (allowedExtensions.Any(ext => file.EndsWith(ext, true, CultureInfo.InvariantCulture)))
{