Fix asset browser and map editor paths for SDK-based mods.
This commit is contained in:
@@ -69,14 +69,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (sourceDropdown != null)
|
||||
{
|
||||
sourceDropdown.OnMouseDown = _ => ShowSourceDropdown(sourceDropdown);
|
||||
sourceDropdown.GetText = () =>
|
||||
{
|
||||
var name = assetSource != null ? Platform.UnresolvePath(assetSource.Name) : "All Packages";
|
||||
if (name.Length > 15)
|
||||
name = "..." + name.Substring(name.Length - 15);
|
||||
|
||||
return name;
|
||||
};
|
||||
var sourceName = new CachedTransform<IReadOnlyPackage, string>(GetSourceDisplayName);
|
||||
sourceDropdown.GetText = () => sourceName.Update(assetSource);
|
||||
}
|
||||
|
||||
var spriteWidget = panel.GetOrNull<SpriteWidget>("SPRITE");
|
||||
@@ -370,12 +364,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
bool ShowSourceDropdown(DropDownButtonWidget dropdown)
|
||||
{
|
||||
var sourceName = new CachedTransform<IReadOnlyPackage, string>(GetSourceDisplayName);
|
||||
Func<IReadOnlyPackage, ScrollItemWidget, ScrollItemWidget> setupItem = (source, itemTemplate) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(itemTemplate,
|
||||
() => assetSource == source,
|
||||
() => { assetSource = source; PopulateAssetList(); });
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => source != null ? Platform.UnresolvePath(source.Name) : "All Packages";
|
||||
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => sourceName.Update(source);
|
||||
return item;
|
||||
};
|
||||
|
||||
@@ -434,5 +430,33 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 280, palettes, setupItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
string GetSourceDisplayName(IReadOnlyPackage source)
|
||||
{
|
||||
if (source == null)
|
||||
return "All Packages";
|
||||
|
||||
// Packages that are explicitly mounted in the filesystem use their explicit mount name
|
||||
var fs = (OpenRA.FileSystem.FileSystem)modData.DefaultFileSystem;
|
||||
var name = fs.GetPrefix(source);
|
||||
|
||||
// Fall back to the path relative to the mod, engine, or support dir
|
||||
if (name == null)
|
||||
{
|
||||
name = source.Name;
|
||||
var compare = Platform.CurrentPlatform == PlatformType.Windows ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
|
||||
if (name.StartsWith(modData.Manifest.Package.Name, compare))
|
||||
name = "$" + modData.Manifest.Id + "/" + name.Substring(modData.Manifest.Package.Name.Length + 1);
|
||||
else if (name.StartsWith(Platform.GameDir, compare))
|
||||
name = "./" + name.Substring(Platform.GameDir.Length);
|
||||
else if (name.StartsWith(Platform.SupportDir, compare))
|
||||
name = "^" + name.Substring(Platform.SupportDir.Length);
|
||||
}
|
||||
|
||||
if (name.Length > 18)
|
||||
name = "..." + name.Substring(name.Length - 15);
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user