Allow AssetBrowserLogic's allowed extentions to be loaded from YAML

Keep the default list of file formats as a fallback for thirdparty mods, but still add it to YAML to show off the functionality and to make it more transparent what formats are supported.
This commit is contained in:
Pavel Penev
2015-11-13 03:26:39 +02:00
parent 5b185f93a1
commit 8f85794a52
3 changed files with 10 additions and 3 deletions

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
public class AssetBrowserLogic : ChromeLogic public class AssetBrowserLogic : ChromeLogic
{ {
static readonly string[] AllowedExtensions = { ".shp", ".r8", "tmp", ".tem", ".des", ".sno", ".int", ".jun", ".vqa" }; static string[] allowedExtensions;
readonly World world; readonly World world;
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
int currentFrame; int currentFrame;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public AssetBrowserLogic(Widget widget, Action onExit, World world) public AssetBrowserLogic(Widget widget, Action onExit, World world, Dictionary<string, MiniYaml> logicArgs)
{ {
this.world = world; this.world = world;
@@ -212,6 +212,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
prevButton.IsVisible = () => !isVideoLoaded; prevButton.IsVisible = () => !isVideoLoaded;
} }
if (logicArgs.ContainsKey("SupportedFormats"))
allowedExtensions = FieldLoader.GetValue<string[]>("SupportedFormats", logicArgs["SupportedFormats"].Value);
else
allowedExtensions = new string[0];
assetList = panel.Get<ScrollPanelWidget>("ASSET_LIST"); assetList = panel.Get<ScrollPanelWidget>("ASSET_LIST");
template = panel.Get<ScrollItemWidget>("ASSET_TEMPLATE"); template = panel.Get<ScrollItemWidget>("ASSET_TEMPLATE");
PopulateAssetList(); PopulateAssetList();
@@ -359,7 +364,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var files = assetSource.AllFileNames().OrderBy(s => s); var files = assetSource.AllFileNames().OrderBy(s => s);
foreach (var file in files) foreach (var file in files)
{ {
if (AllowedExtensions.Any(ext => file.EndsWith(ext, true, CultureInfo.InvariantCulture))) if (allowedExtensions.Any(ext => file.EndsWith(ext, true, CultureInfo.InvariantCulture)))
{ {
AddAsset(assetList, file, template); AddAsset(assetList, file, template);
availableShps.Add(file); availableShps.Add(file);

View File

@@ -1,5 +1,6 @@
Container@ASSETBROWSER_PANEL: Container@ASSETBROWSER_PANEL:
Logic: AssetBrowserLogic Logic: AssetBrowserLogic
SupportedFormats: .shp, .tem, .des, .sno, .jun, .vqa
X: (WINDOW_RIGHT - WIDTH)/2 X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - HEIGHT)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2
Width: 695 Width: 695

View File

@@ -1,5 +1,6 @@
Background@ASSETBROWSER_PANEL: Background@ASSETBROWSER_PANEL:
Logic: AssetBrowserLogic Logic: AssetBrowserLogic
SupportedFormats: .shp, .r8, .tmp, .tem, .des, .sno, .int, .vqa
X: (WINDOW_RIGHT - WIDTH)/2 X: (WINDOW_RIGHT - WIDTH)/2
Y: (WINDOW_BOTTOM - HEIGHT)/2 Y: (WINDOW_BOTTOM - HEIGHT)/2
Width: 700 Width: 700