This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
/
ColorizerManager.cs
71 lines (59 loc) · 2.78 KB
/
ColorizerManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using MelonLoader;
using Styletor.Utils;
using UnityEngine;
namespace Styletor.Styles
{
public class ColorizerManager
{
private readonly SettingsHolder mySettings;
public string MenuColorBase { get; private set; } = "";
public string MenuColorHighlight { get; private set; } = "";
public string MenuColorBackground { get; private set; } = "";
public string MenuColorDarklight { get; private set; } = "";
public string MenuColorText { get; private set; } = "";
public string MenuColorTextHigh { get; private set; } = "";
public string MenuColorAccent { get; private set; } = "";
public string MenuColorAccentDarker { get; private set; } = "";
public ColorizerManager(SettingsHolder settings)
{
mySettings = settings;
settings.BaseColorEntry.OnValueChanged += (_, _) => { UpdateColors(); };
settings.AccentColorEntry.OnValueChanged += (_, _) => { UpdateColors(); };
settings.TextColorEntry.OnValueChanged += (_, _) => { UpdateColors(); };
UpdateColors();
}
private void UpdateColors()
{
UpdateColors(mySettings.BaseColor, mySettings.AccentColor, mySettings.TextColor);
}
public string ReplacePlaceholders(string input)
{
return input
.Replace("$BASE$", MenuColorBase)
.Replace("$HIGH$", MenuColorHighlight)
.Replace("$BG$", MenuColorBackground)
.Replace("$DARK$", MenuColorDarklight)
.Replace("$TEXT$", MenuColorText)
.Replace("$TEXTHI$", MenuColorTextHigh)
.Replace("$ACCT$", MenuColorAccent)
.Replace("$ACCDK$", MenuColorAccentDarker)
;
}
public void UpdateColors(Color @base, Color accent, Color text)
{
var highlight = @base.RGBMultipliedClamped(1.1f);
var background = @base.RGBMultipliedClamped(0.9f);
var dark = @base.RGBMultipliedClamped(0.5f);
MenuColorBase = ColorToHex(@base);
MenuColorHighlight = ColorToHex(highlight);
MenuColorBackground = ColorToHex(background);
MenuColorDarklight = ColorToHex(dark);
MenuColorText = ColorToHex(text.RGBMultipliedClamped(0.9f));
MenuColorTextHigh = ColorToHex(text);
MenuColorAccent = ColorToHex(accent);
MenuColorAccentDarker = ColorToHex(accent.RGBMultipliedClamped(0.7f));
}
private static string PartToHex(float f) => ((int)(f * 255)).ToString("x2");
private static string ColorToHex(Color c) => $"#{PartToHex(c.r)}{PartToHex(c.g)}{PartToHex(c.b)}";
}
}