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)
|
if (sourceDropdown != null)
|
||||||
{
|
{
|
||||||
sourceDropdown.OnMouseDown = _ => ShowSourceDropdown(sourceDropdown);
|
sourceDropdown.OnMouseDown = _ => ShowSourceDropdown(sourceDropdown);
|
||||||
sourceDropdown.GetText = () =>
|
var sourceName = new CachedTransform<IReadOnlyPackage, string>(GetSourceDisplayName);
|
||||||
{
|
sourceDropdown.GetText = () => sourceName.Update(assetSource);
|
||||||
var name = assetSource != null ? Platform.UnresolvePath(assetSource.Name) : "All Packages";
|
|
||||||
if (name.Length > 15)
|
|
||||||
name = "..." + name.Substring(name.Length - 15);
|
|
||||||
|
|
||||||
return name;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var spriteWidget = panel.GetOrNull<SpriteWidget>("SPRITE");
|
var spriteWidget = panel.GetOrNull<SpriteWidget>("SPRITE");
|
||||||
@@ -370,12 +364,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
bool ShowSourceDropdown(DropDownButtonWidget dropdown)
|
bool ShowSourceDropdown(DropDownButtonWidget dropdown)
|
||||||
{
|
{
|
||||||
|
var sourceName = new CachedTransform<IReadOnlyPackage, string>(GetSourceDisplayName);
|
||||||
Func<IReadOnlyPackage, ScrollItemWidget, ScrollItemWidget> setupItem = (source, itemTemplate) =>
|
Func<IReadOnlyPackage, 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 ? Platform.UnresolvePath(source.Name) : "All Packages";
|
|
||||||
|
item.Get<LabelWidget>("LABEL").GetText = () => sourceName.Update(source);
|
||||||
return item;
|
return item;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -434,5 +430,33 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 280, palettes, setupItem);
|
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 280, palettes, setupItem);
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
public readonly string DisplayName;
|
public readonly string DisplayName;
|
||||||
public readonly MapClassification Classification;
|
public readonly MapClassification Classification;
|
||||||
|
|
||||||
public SaveDirectory(Folder folder, MapClassification classification)
|
public SaveDirectory(Folder folder, string displayName, MapClassification classification)
|
||||||
{
|
{
|
||||||
Folder = folder;
|
Folder = folder;
|
||||||
DisplayName = Platform.UnresolvePath(Folder.Name);
|
DisplayName = displayName;
|
||||||
Classification = classification;
|
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
|
// 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
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user