add UI colors in config file

This commit is contained in:
choco
2025-09-09 23:55:02 +02:00
parent 25a0eeadc8
commit 1511090f63
4 changed files with 32 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
using System.Globalization;
using System.Globalization;
using System.Numerics;
using LightlessSync.LightlessConfiguration;
namespace LightlessSync.UI
{
@@ -14,12 +15,17 @@ namespace LightlessSync.UI
{ "DimRed", "#d44444" },
};
private static readonly Dictionary<string, Vector4> CustomColors = new(StringComparer.OrdinalIgnoreCase);
private static LightlessConfigService? _configService;
public static void Initialize(LightlessConfigService configService)
{
_configService = configService;
}
public static Vector4 Get(string name)
{
if (CustomColors.TryGetValue(name, out var customColor))
return customColor;
if (_configService?.Current.CustomUIColors.TryGetValue(name, out var customColorHex) == true)
return HexToRgba(customColorHex);
if (!DefaultHexColors.TryGetValue(name, out var hex))
throw new ArgumentException($"Color '{name}' not found in UIColors.");
@@ -32,17 +38,29 @@ namespace LightlessSync.UI
if (!DefaultHexColors.ContainsKey(name))
throw new ArgumentException($"Color '{name}' not found in UIColors.");
CustomColors[name] = color;
if (_configService != null)
{
_configService.Current.CustomUIColors[name] = RgbaToHex(color);
_configService.Save();
}
}
public static void Reset(string name)
{
CustomColors.Remove(name);
if (_configService != null)
{
_configService.Current.CustomUIColors.Remove(name);
_configService.Save();
}
}
public static void ResetAll()
{
CustomColors.Clear();
if (_configService != null)
{
_configService.Current.CustomUIColors.Clear();
_configService.Save();
}
}
public static Vector4 GetDefault(string name)
@@ -55,7 +73,7 @@ namespace LightlessSync.UI
public static bool IsCustom(string name)
{
return CustomColors.ContainsKey(name);
return _configService?.Current.CustomUIColors.ContainsKey(name) == true;
}
public static IEnumerable<string> GetColorNames()