Skip to content

Commit

Permalink
Add logNotFound parameter to image search functions
Browse files Browse the repository at this point in the history
  • Loading branch information
PunkPun committed Sep 12, 2022
1 parent 7f404f6 commit f23dd28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions OpenRA.Game/Graphics/ChromeProvider.cs
Expand Up @@ -143,7 +143,7 @@ static void LoadCollection(string name, MiniYaml yaml)
return sheetDensity;
}

public static Sprite GetImage(string collectionName, string imageName)
public static Sprite GetImage(string collectionName, string imageName, bool logNotFound = true)
{
if (string.IsNullOrEmpty(collectionName))
return null;
Expand All @@ -154,12 +154,17 @@ public static Sprite GetImage(string collectionName, string imageName)

if (!collections.TryGetValue(collectionName, out var collection))
{
Log.Write("debug", "Could not find collection '{0}'", collectionName);
Log.Write("debug", $"Could not find collection '{collectionName}'");
return null;
}

if (!collection.Regions.TryGetValue(imageName, out var mi))
{
if (logNotFound)
Log.Write("debug", $"Could not find image '{imageName}' in collection '{collectionName}'");

return null;
}

// Cache the sprite
var sheetDensity = SheetForCollection(collection);
Expand All @@ -175,7 +180,7 @@ public static Sprite GetImage(string collectionName, string imageName)
return image;
}

public static Sprite[] GetPanelImages(string collectionName)
public static Sprite[] GetPanelImages(string collectionName, bool logNotFound = true)
{
if (string.IsNullOrEmpty(collectionName))
return null;
Expand All @@ -186,7 +191,9 @@ public static Sprite[] GetPanelImages(string collectionName)

if (!collections.TryGetValue(collectionName, out var collection))
{
Log.Write("debug", "Could not find collection '{0}'", collectionName);
if (logNotFound)
Log.Write("debug", $"Could not find collection '{collectionName}'");

return null;
}

Expand All @@ -195,7 +202,7 @@ public static Sprite[] GetPanelImages(string collectionName)
{
if (collection.PanelRegion.Length != 8)
{
Log.Write("debug", "Collection '{0}' does not define a valid PanelRegion", collectionName);
Log.Write("debug", $"Collection '{collectionName}' does not define a valid PanelRegion");
return null;
}

Expand All @@ -222,6 +229,9 @@ public static Sprite[] GetPanelImages(string collectionName)
}
else
{
if (!collection.Regions.Any())
return null;

// Support manual definitions for unusual dialog layouts
sprites = new[]
{
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Widgets/WidgetUtils.cs
Expand Up @@ -37,7 +37,7 @@ public static CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Foc
((bool Disabled, bool Pressed, bool Hover, bool Focused) args) =>
{
var imageName = GetStatefulImageName(baseName, args.Disabled, args.Pressed, args.Hover, args.Focused);
return ChromeProvider.GetImage(collection, imageName) ?? ChromeProvider.GetImage(collection, baseName);
return ChromeProvider.GetImage(collection, imageName, false) ?? ChromeProvider.GetImage(collection, baseName);
});
}

Expand All @@ -49,7 +49,7 @@ public static CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Foc
{
var collectionName = collection + (args.Highlighted ? "-highlighted" : "");
var variantCollectionName = GetStatefulImageName(collectionName, args.Disabled, args.Pressed, args.Hover, args.Focused);
return ChromeProvider.GetPanelImages(variantCollectionName) ?? ChromeProvider.GetPanelImages(collectionName);
return ChromeProvider.GetPanelImages(variantCollectionName, false) ?? ChromeProvider.GetPanelImages(collectionName);
});
}

Expand Down

0 comments on commit f23dd28

Please sign in to comment.