Fix asset browser displaying wrong file
If multiple files with same filename are present.
This commit is contained in:
@@ -315,5 +315,10 @@ namespace OpenRA.FileSystem
|
|||||||
var resolvedPath = Platform.ResolvePath(path);
|
var resolvedPath = Platform.ResolvePath(path);
|
||||||
return File.Exists(resolvedPath) ? resolvedPath : null;
|
return File.Exists(resolvedPath) ? resolvedPath : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetPrefix(IReadOnlyPackage package)
|
||||||
|
{
|
||||||
|
return explicitMounts.ContainsValue(package) ? explicitMounts.First(f => f.Value == package).Key : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,11 +37,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
ScrollItemWidget template;
|
ScrollItemWidget template;
|
||||||
|
|
||||||
IReadOnlyPackage assetSource = null;
|
IReadOnlyPackage assetSource = null;
|
||||||
List<string> availableShps = new List<string>();
|
|
||||||
bool animateFrames = false;
|
bool animateFrames = false;
|
||||||
|
|
||||||
string currentPalette;
|
string currentPalette;
|
||||||
string currentFilename;
|
string currentFilename;
|
||||||
|
IReadOnlyPackage currentPackage;
|
||||||
Sprite[] currentSprites;
|
Sprite[] currentSprites;
|
||||||
VqaPlayerWidget player = null;
|
VqaPlayerWidget player = null;
|
||||||
bool isVideoLoaded = false;
|
bool isVideoLoaded = false;
|
||||||
@@ -116,7 +116,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
}
|
}
|
||||||
|
|
||||||
filenameInput = panel.Get<TextFieldWidget>("FILENAME_INPUT");
|
filenameInput = panel.Get<TextFieldWidget>("FILENAME_INPUT");
|
||||||
filenameInput.OnTextEdited = () => ApplyFilter(filenameInput.Text);
|
filenameInput.OnTextEdited = () => ApplyFilter();
|
||||||
filenameInput.OnEscKey = filenameInput.YieldKeyboardFocus;
|
filenameInput.OnEscKey = filenameInput.YieldKeyboardFocus;
|
||||||
|
|
||||||
var frameContainer = panel.GetOrNull("FRAME_SELECTOR");
|
var frameContainer = panel.GetOrNull("FRAME_SELECTOR");
|
||||||
@@ -266,7 +266,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyFilter(string filename)
|
void ApplyFilter()
|
||||||
{
|
{
|
||||||
assetVisByName.Clear();
|
assetVisByName.Clear();
|
||||||
assetList.Layout.AdjustChildren();
|
assetList.Layout.AdjustChildren();
|
||||||
@@ -274,16 +274,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
// Select the first visible
|
// Select the first visible
|
||||||
var firstVisible = assetVisByName.FirstOrDefault(kvp => kvp.Value);
|
var firstVisible = assetVisByName.FirstOrDefault(kvp => kvp.Value);
|
||||||
if (firstVisible.Key != null)
|
IReadOnlyPackage package;
|
||||||
LoadAsset(firstVisible.Key);
|
string filename;
|
||||||
|
|
||||||
|
if (firstVisible.Key != null && modData.DefaultFileSystem.TryGetPackageContaining(firstVisible.Key, out package, out filename))
|
||||||
|
LoadAsset(package, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddAsset(ScrollPanelWidget list, string filepath, ScrollItemWidget template)
|
void AddAsset(ScrollPanelWidget list, string filepath, IReadOnlyPackage package, ScrollItemWidget template)
|
||||||
{
|
{
|
||||||
var filename = Path.GetFileName(filepath);
|
|
||||||
var item = ScrollItemWidget.Setup(template,
|
var item = ScrollItemWidget.Setup(template,
|
||||||
() => currentFilename == filename,
|
() => currentFilename == filepath && currentPackage == package,
|
||||||
() => { LoadAsset(filename); });
|
() => { LoadAsset(package, filepath); });
|
||||||
|
|
||||||
item.Get<LabelWidget>("TITLE").GetText = () => filepath;
|
item.Get<LabelWidget>("TITLE").GetText = () => filepath;
|
||||||
item.IsVisible = () =>
|
item.IsVisible = () =>
|
||||||
@@ -300,7 +302,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
list.AddChild(item);
|
list.AddChild(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoadAsset(string filename)
|
bool LoadAsset(IReadOnlyPackage package, string filename)
|
||||||
{
|
{
|
||||||
if (isVideoLoaded)
|
if (isVideoLoaded)
|
||||||
{
|
{
|
||||||
@@ -312,18 +314,29 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (string.IsNullOrEmpty(filename))
|
if (string.IsNullOrEmpty(filename))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!modData.DefaultFileSystem.Exists(filename))
|
if (!package.Contains(filename))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
isLoadError = false;
|
isLoadError = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
currentPackage = package;
|
||||||
|
currentFilename = filename;
|
||||||
|
var prefix = "";
|
||||||
|
var fs = modData.DefaultFileSystem as OpenRA.FileSystem.FileSystem;
|
||||||
|
|
||||||
|
if (fs != null)
|
||||||
|
{
|
||||||
|
prefix = fs.GetPrefix(package);
|
||||||
|
if (prefix != null)
|
||||||
|
prefix += "|";
|
||||||
|
}
|
||||||
|
|
||||||
if (Path.GetExtension(filename.ToLowerInvariant()) == ".vqa")
|
if (Path.GetExtension(filename.ToLowerInvariant()) == ".vqa")
|
||||||
{
|
{
|
||||||
player = panel.Get<VqaPlayerWidget>("PLAYER");
|
player = panel.Get<VqaPlayerWidget>("PLAYER");
|
||||||
currentFilename = filename;
|
player.Load(prefix + filename);
|
||||||
player.Load(filename);
|
|
||||||
player.DrawOverlay = false;
|
player.DrawOverlay = false;
|
||||||
isVideoLoaded = true;
|
isVideoLoaded = true;
|
||||||
frameSlider.MaximumValue = (float)player.Video.Frames - 1;
|
frameSlider.MaximumValue = (float)player.Video.Frames - 1;
|
||||||
@@ -331,8 +344,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFilename = filename;
|
currentSprites = world.Map.Rules.Sequences.SpriteCache[prefix + filename];
|
||||||
currentSprites = world.Map.Rules.Sequences.SpriteCache[filename];
|
|
||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
frameSlider.MaximumValue = (float)currentSprites.Length - 1;
|
frameSlider.MaximumValue = (float)currentSprites.Length - 1;
|
||||||
frameSlider.Ticks = currentSprites.Length;
|
frameSlider.Ticks = currentSprites.Length;
|
||||||
@@ -368,19 +380,36 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
void PopulateAssetList()
|
void PopulateAssetList()
|
||||||
{
|
{
|
||||||
assetList.RemoveChildren();
|
assetList.RemoveChildren();
|
||||||
availableShps.Clear();
|
|
||||||
|
|
||||||
var files = assetSource != null ? assetSource.Contents : modData.ModFiles.MountedPackages.SelectMany(f => f.Contents).Distinct();
|
var files = new SortedList<string, List<IReadOnlyPackage>>();
|
||||||
foreach (var file in files.OrderBy(s => s))
|
|
||||||
|
if (assetSource != null)
|
||||||
|
foreach (var content in assetSource.Contents)
|
||||||
|
files.Add(content, new List<IReadOnlyPackage> { assetSource });
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (allowedExtensions.Any(ext => file.EndsWith(ext, true, CultureInfo.InvariantCulture)))
|
foreach (var mountedPackage in modData.ModFiles.MountedPackages)
|
||||||
{
|
{
|
||||||
AddAsset(assetList, file, template);
|
foreach (var content in mountedPackage.Contents)
|
||||||
availableShps.Add(file);
|
{
|
||||||
|
if (!files.ContainsKey(content))
|
||||||
|
files.Add(content, new List<IReadOnlyPackage> { mountedPackage });
|
||||||
|
else
|
||||||
|
files[content].Add(mountedPackage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var file in files.OrderBy(s => s.Key))
|
||||||
|
{
|
||||||
|
if (!allowedExtensions.Any(ext => file.Key.EndsWith(ext, true, CultureInfo.InvariantCulture)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var package in file.Value)
|
||||||
|
AddAsset(assetList, file.Key, package, template);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool ShowPaletteDropdown(DropDownButtonWidget dropdown, World world)
|
bool ShowPaletteDropdown(DropDownButtonWidget dropdown, World world)
|
||||||
{
|
{
|
||||||
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (name, itemTemplate) =>
|
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (name, itemTemplate) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user