diff --git a/MiniMapLibrary/Interactible/InteractibleSetting.cs b/MiniMapLibrary/Interactible/InteractibleSetting.cs index 512c7e8..b550300 100644 --- a/MiniMapLibrary/Interactible/InteractibleSetting.cs +++ b/MiniMapLibrary/Interactible/InteractibleSetting.cs @@ -13,6 +13,7 @@ public class InteractibleSetting public Color ActiveColor { get; set; } public Color InactiveColor { get; set; } public string Description { get; set; } + public string IconPath { get; set; } public ISettingConfigGroup Config; } } diff --git a/MiniMapLibrary/Interfaces/wrappers/SettingConfigGroup.cs b/MiniMapLibrary/Interfaces/wrappers/SettingConfigGroup.cs index af58864..9aab574 100644 --- a/MiniMapLibrary/Interfaces/wrappers/SettingConfigGroup.cs +++ b/MiniMapLibrary/Interfaces/wrappers/SettingConfigGroup.cs @@ -13,5 +13,6 @@ public interface ISettingConfigGroup IConfigEntry Width { get; } IConfigEntry ActiveColor { get; } IConfigEntry InactiveColor { get; } + IConfigEntry IconPath { get; } } } diff --git a/MiniMapLibrary/SettingConfigGroup.cs b/MiniMapLibrary/SettingConfigGroup.cs index 101e5a2..1c5a711 100644 --- a/MiniMapLibrary/SettingConfigGroup.cs +++ b/MiniMapLibrary/SettingConfigGroup.cs @@ -1,4 +1,5 @@ -using MiniMapLibrary.Interfaces; +using MiniMapLibrary; +using MiniMapLibrary.Interfaces; using System; using System.Collections.Generic; using System.Text; @@ -8,13 +9,14 @@ namespace MiniMapMod.wrappers { public class SettingConfigGroup : ISettingConfigGroup { - public SettingConfigGroup(IConfigEntry enabled, IConfigEntry height, IConfigEntry width, IConfigEntry activeColor, IConfigEntry inactiveColor) + public SettingConfigGroup(IConfigEntry enabled, IConfigEntry height, IConfigEntry width, IConfigEntry activeColor, IConfigEntry inactiveColor, IConfigEntry iconPath) { Enabled = enabled; Height = height; Width = width; ActiveColor = activeColor; InactiveColor = inactiveColor; + IconPath = iconPath; } public IConfigEntry Enabled { get; } @@ -22,5 +24,6 @@ public SettingConfigGroup(IConfigEntry enabled, IConfigEntry height public IConfigEntry Width { get; } public IConfigEntry ActiveColor { get; } public IConfigEntry InactiveColor { get; } + public IConfigEntry IconPath { get; } } } diff --git a/MiniMapLibrary/Settings.cs b/MiniMapLibrary/Settings.cs index 08b7cb4..2392be9 100644 --- a/MiniMapLibrary/Settings.cs +++ b/MiniMapLibrary/Settings.cs @@ -25,6 +25,8 @@ public static class Settings public static Color DefaultInactiveColor { get; set; } = Color.grey; + public const string DefaultResourcePath = "Textures/MiscIcons/texMysteryIcon"; + static Settings() { InitializeDefaultSettings(); @@ -32,7 +34,13 @@ static Settings() private static void InitializeDefaultSettings() { - static void AddSize(InteractableKind type, float width = -1, float height = -1, Color ActiveColor = default, Color InactiveColor = default, string description = "") + static void AddSize(InteractableKind type, + float width = -1, + float height = -1, + Color ActiveColor = default, + Color InactiveColor = default, + string description = "", + string path = DefaultResourcePath) { ActiveColor = ActiveColor == default ? DefaultActiveColor : ActiveColor; InactiveColor = InactiveColor == default ? DefaultInactiveColor : InactiveColor; @@ -52,21 +60,59 @@ static void AddSize(InteractableKind type, float width = -1, float height = -1, }; setting.Description = description; + setting.IconPath = path; InteractibleSettings.Add(type, setting); } - AddSize(InteractableKind.Chest, 10, 8, description: "Chests, including shops"); - AddSize(InteractableKind.Shrine, description: "All shrines (excluding Newt)"); - AddSize(InteractableKind.Teleporter, 15, 15, ActiveColor: Color.white, InactiveColor: Color.green, description: "Boss teleporters"); - AddSize(InteractableKind.Player, 8, 8, ActiveColor: PlayerIconColor, InactiveColor: PlayerIconColor, description: ""); - AddSize(InteractableKind.Barrel, 5, 5, description: "Barrels"); - AddSize(InteractableKind.Drone, 7, 7, description: "Drones"); - AddSize(InteractableKind.Special, 7, 7, description: "Special interactibles such as the landing pod"); - AddSize(InteractableKind.Enemy, 3, 3, ActiveColor: Color.red, description: "Enemies"); - AddSize(InteractableKind.Utility, description: "Scrappers"); - AddSize(InteractableKind.Printer, 10, 8, description: "Printers"); - AddSize(InteractableKind.LunarPod, 7, 7, description: "Lunar pods (chests)"); + AddSize(InteractableKind.Chest, 10, 8, + description: "Chests, including shops", + path: "Textures/MiscIcons/texInventoryIconOutlined"); + + AddSize(InteractableKind.Shrine, + description: "All shrines (excluding Newt)", + path: "Textures/MiscIcons/texShrineIconOutlined"); + + AddSize(InteractableKind.Teleporter, 15, 15, + ActiveColor: Color.white, + InactiveColor: Color.green, + description: "Boss teleporters", + path: "Textures/MiscIcons/texTeleporterIconOutlined"); + + AddSize(InteractableKind.Player, 8, 8, + ActiveColor: PlayerIconColor, + InactiveColor: PlayerIconColor, + description: "", + path: "Textures/MiscIcons/texBarrelIcon"); + + AddSize(InteractableKind.Barrel, 5, 5, + description: "Barrels", + path: "Textures/MiscIcons/texBarrelIcon"); + + AddSize(InteractableKind.Drone, 7, 7, + description: "Drones", + path: "Textures/MiscIcons/texDroneIconOutlined"); + + AddSize(InteractableKind.Special, 7, 7, + description: "Special interactibles such as the landing pod", + path: DefaultResourcePath); + + AddSize(InteractableKind.Enemy, 3, 3, + ActiveColor: Color.red, + description: "Enemies", + path: "Textures/MiscIcons/texBarrelIcon"); + + AddSize(InteractableKind.Utility, + description: "Scrappers", + path: "Textures/MiscIcons/texLootIconOutlined"); + + AddSize(InteractableKind.Printer, 10, 8, + description: "Printers", + path: "Textures/MiscIcons/texInventoryIconOutlined"); + + AddSize(InteractableKind.LunarPod, 7, 7, + description: "Lunar pods (chests)", + path: "Textures/MiscIcons/texLootIconOutlined"); } public static InteractibleSetting GetSetting(InteractableKind type) @@ -115,14 +161,15 @@ public static void LoadConfigEntries(InteractableKind type, IConfig config) IConfigEntry inactiveColor = config.Bind($"Icon.{type}", "inactiveColor", setting.InactiveColor, "The color the icon should be when it has used/bought"); IConfigEntry width = config.Bind($"Icon.{type}", "width", setting.Dimensions.Width, "Width of the icon"); IConfigEntry height = config.Bind($"Icon.{type}", "height", setting.Dimensions.Height, "Width of the icon"); + IConfigEntry path = config.Bind($"Icon.{type}", "icon", setting.IconPath ?? DefaultResourcePath, $"The streaming assets path of the icon"); - - InteractibleSettings[type].Config = new SettingConfigGroup(enabled, height, width, activeColor, inactiveColor); + InteractibleSettings[type].Config = new SettingConfigGroup(enabled, height, width, activeColor, inactiveColor, path); setting.ActiveColor = activeColor.Value; setting.InactiveColor = inactiveColor.Value; setting.Dimensions.Height = height.Value; setting.Dimensions.Width = width.Value; + setting.IconPath = path.Value; } public static void UpdateSetting(InteractableKind type, float width, float height, Color active, Color inactive) diff --git a/MiniMapLibrary/SpriteManager.cs b/MiniMapLibrary/SpriteManager.cs index 5cbc3cd..3149d60 100644 --- a/MiniMapLibrary/SpriteManager.cs +++ b/MiniMapLibrary/SpriteManager.cs @@ -12,36 +12,8 @@ public sealed class SpriteManager : IDisposable, ISpriteManager { public const string DefaultResourcePath = "Textures/MiscIcons/texMysteryIcon"; - private static readonly Dictionary s_ResourceDictionary = new Dictionary(); - private readonly Dictionary SpriteCache = new Dictionary(); - static SpriteManager() - { - InitializeResources(); - } - - private static void InitializeResources() - { - static void Add(InteractableKind type, string ResourcePath) - { - s_ResourceDictionary.Add(type, ResourcePath); - } - - Add(InteractableKind.Shrine, "Textures/MiscIcons/texShrineIconOutlined"); - Add(InteractableKind.Special, DefaultResourcePath); - Add(InteractableKind.Teleporter, "Textures/MiscIcons/texTeleporterIconOutlined"); - Add(InteractableKind.Chest, "Textures/MiscIcons/texInventoryIconOutlined"); - Add(InteractableKind.Drone, "Textures/MiscIcons/texDroneIconOutlined"); - Add(InteractableKind.Utility, "Textures/MiscIcons/texLootIconOutlined"); - Add(InteractableKind.Barrel, "Textures/MiscIcons/texBarrelIcon"); - Add(InteractableKind.Enemy, "Textures/MiscIcons/texBarrelIcon"); - Add(InteractableKind.Player, "Textures/MiscIcons/texBarrelIcon"); - Add(InteractableKind.Printer, "Textures/MiscIcons/texInventoryIconOutlined"); - Add(InteractableKind.LunarPod, "Textures/MiscIcons/texLootIconOutlined"); - Add(InteractableKind.All, DefaultResourcePath); - } - public void Dispose() { SpriteCache.Clear(); @@ -54,12 +26,11 @@ public void Dispose() return null; } - if (s_ResourceDictionary.TryGetValue(type, out string? path)) + string? path = Settings.GetSetting(type)?.Config?.IconPath?.Value; + + if (path != null) { - if (path != null) - { - return GetOrCache(path); - } + return GetOrCache(path); throw new Exception($"MissingTextureException: Interactible.{type} does not have a registered texture path to load."); } diff --git a/MiniMapLibrary/StubConfigEntry.cs b/MiniMapLibrary/StubConfigEntry.cs new file mode 100644 index 0000000..8d04e10 --- /dev/null +++ b/MiniMapLibrary/StubConfigEntry.cs @@ -0,0 +1,17 @@ +using MiniMapLibrary.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; + +namespace MiniMapLibrary +{ + public class StubConfigEntry : IConfigEntry + { + public T Value { get; } + + public StubConfigEntry(T value) + { + Value = value; + } + } +}