diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index 5b4df869b5..df8eb82bb9 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -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(GetSourceDisplayName); + sourceDropdown.GetText = () => sourceName.Update(assetSource); } var spriteWidget = panel.GetOrNull("SPRITE"); @@ -370,12 +364,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic bool ShowSourceDropdown(DropDownButtonWidget dropdown) { + var sourceName = new CachedTransform(GetSourceDisplayName); Func setupItem = (source, itemTemplate) => { var item = ScrollItemWidget.Setup(itemTemplate, () => assetSource == source, () => { assetSource = source; PopulateAssetList(); }); - item.Get("LABEL").GetText = () => source != null ? Platform.UnresolvePath(source.Name) : "All Packages"; + + item.Get("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; + } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs index 8e2ab79c7e..bf025bb783 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/SaveMapLogic.cs @@ -34,10 +34,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic public readonly string DisplayName; public readonly MapClassification Classification; - public SaveDirectory(Folder folder, MapClassification classification) + public SaveDirectory(Folder folder, string displayName, MapClassification classification) { Folder = folder; - DisplayName = Platform.UnresolvePath(Folder.Name); + DisplayName = displayName; Classification = classification; } } @@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Do nothing: we just want to test whether we can create the file } - writableDirectories.Add(new SaveDirectory(folder, kv.Value)); + writableDirectories.Add(new SaveDirectory(folder, kv.Value.ToString(), kv.Value)); } catch {