This commit is contained in:
Matthias Mailänder
2013-11-17 16:09:23 +01:00
parent d973ed307f
commit f6bd53c15e

View File

@@ -28,8 +28,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
ScrollPanelWidget assetList; ScrollPanelWidget assetList;
ScrollItemWidget template; ScrollItemWidget template;
IFolder AssetSource = null; IFolder assetSource = null;
List<string> AvailableShps = new List<string>(); List<string> availableShps = new List<string>();
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public AssetBrowserLogic(Widget widget, Action onExit, World world) public AssetBrowserLogic(Widget widget, Action onExit, World world)
@@ -40,14 +40,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
sourceDropdown.OnMouseDown = _ => ShowSourceDropdown(sourceDropdown); sourceDropdown.OnMouseDown = _ => ShowSourceDropdown(sourceDropdown);
sourceDropdown.GetText = () => sourceDropdown.GetText = () =>
{ {
var name = AssetSource != null ? AssetSource.Name : "All Packages"; var name = assetSource != null ? assetSource.Name : "All Packages";
if (name.Length > 15) if (name.Length > 15)
name = "..." + name.Substring(name.Length - 15); name = "..." + name.Substring(name.Length - 15);
return name; return name;
}; };
AssetSource = FileSystem.MountedFolders.First(); assetSource = FileSystem.MountedFolders.First();
spriteImage = panel.Get<ShpImageWidget>("SPRITE"); spriteImage = panel.Get<ShpImageWidget>("SPRITE");
@@ -136,7 +136,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
ExtractGameFilesList.Add(new string[] { "--extract", modID, palette, "--userdir" }); ExtractGameFilesList.Add(new string[] { "--extract", modID, palette, "--userdir" });
foreach (var shp in AvailableShps) foreach (var shp in availableShps)
{ {
ExtractGameFilesList.Add(new string[] { "--extract", modID, shp, "--userdir" }); ExtractGameFilesList.Add(new string[] { "--extract", modID, shp, "--userdir" });
ExportToPngList.Add(new string[] { "--png", Platform.SupportDir + shp, Platform.SupportDir + palette }); ExportToPngList.Add(new string[] { "--png", Platform.SupportDir + shp, Platform.SupportDir + palette });
@@ -157,7 +157,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
Ui.OpenWindow("CONVERT_ASSETS_PANEL", args); Ui.OpenWindow("CONVERT_ASSETS_PANEL", args);
}; };
panel.Get<ButtonWidget>("IMPORT_BUTTON").OnClick = () => panel.Get<ButtonWidget>("IMPORT_BUTTON").OnClick = () =>
{ {
var imageSizeInput = panel.Get<TextFieldWidget>("IMAGE_SIZE_INPUT"); var imageSizeInput = panel.Get<TextFieldWidget>("IMAGE_SIZE_INPUT");
@@ -211,14 +210,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
Func<IFolder, ScrollItemWidget, ScrollItemWidget> setupItem = (source, itemTemplate) => Func<IFolder, ScrollItemWidget, ScrollItemWidget> setupItem = (source, itemTemplate) =>
{ {
var item = ScrollItemWidget.Setup(itemTemplate, var item = ScrollItemWidget.Setup(itemTemplate,
() => AssetSource == source, () => assetSource == source,
() => { AssetSource = source; PopulateAssetList(); }); () => { assetSource = source; PopulateAssetList(); });
item.Get<LabelWidget>("LABEL").GetText = () => source != null ? source.Name : "All Packages"; item.Get<LabelWidget>("LABEL").GetText = () => source != null ? source.Name : "All Packages";
return item; return item;
}; };
// TODO: Re-enable "All Packages" once list generation is done in a background thread // TODO: Re-enable "All Packages" once list generation is done in a background thread
//var sources = new[] { (IFolder)null }.Concat(FileSystem.MountedFolders); ///var sources = new[] { (IFolder)null }.Concat(FileSystem.MountedFolders);
var sources = FileSystem.MountedFolders; var sources = FileSystem.MountedFolders;
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 250, sources, setupItem); dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 250, sources, setupItem);
@@ -228,22 +227,22 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void PopulateAssetList() void PopulateAssetList()
{ {
assetList.RemoveChildren(); assetList.RemoveChildren();
AvailableShps.Clear(); availableShps.Clear();
// TODO: This is too slow to run in the main thread // TODO: This is too slow to run in the main thread
//var files = AssetSource != null ? AssetSource.AllFileNames() : ///var files = AssetSource != null ? AssetSource.AllFileNames() :
// FileSystem.MountedFolders.SelectMany(f => f.AllFileNames()); /// FileSystem.MountedFolders.SelectMany(f => f.AllFileNames());
if (AssetSource == null) if (assetSource == null)
return; return;
var files = AssetSource.AllFileNames(); var files = assetSource.AllFileNames();
foreach (var file in files) foreach (var file in files)
{ {
if (file.EndsWith(".shp")) if (file.EndsWith(".shp"))
{ {
AddAsset(assetList, file, template); AddAsset(assetList, file, template);
AvailableShps.Add(file); availableShps.Add(file);
} }
} }
} }