Skip to content
This repository was archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
SetupTheme on each enable
Browse files Browse the repository at this point in the history
To allow theme options to be changed without requiring a restart
  • Loading branch information
yobson1 committed May 31, 2022
1 parent bb57794 commit 8227987
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
16 changes: 11 additions & 5 deletions FavCat/CustomLists/CustomPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ private void OnImageDownloaded(Texture2D texture)
myImage.texture = texture;
}


private void Awake()
{
myImage = GetComponentInChildren<RawImage>();
Expand All @@ -106,19 +105,26 @@ private void Awake()
myPrivateImage = transform.Find("CornerLock").gameObject;
myLowerCornerImage = transform.Find("LowerCornerIcon").GetComponent<Image>();

if (FavCatSettings.UseCustomStyles.Value)
{
transform.Find("Panel").GetComponent<Image>().color = Color.black.AlphaMultiplied(0.8f);
}
SetupTheme();

GetComponent<Button>().onClick.AddListener(new Action(() => myOnClick?.Invoke(myListElement?.Id)));

if (myListElement != null)
Initialize(myListElement, myOnClick!);
}

[HideFromIl2Cpp]
private void SetupTheme()
{
if (FavCatSettings.UseCustomStyles.Value)
{
transform.Find("Panel").GetComponent<Image>().color = Color.black.AlphaMultiplied(0.8f);
}
}

private void OnEnable()
{
SetupTheme();
if (myTexture != null)
myImage.texture = myTexture;
else
Expand Down
46 changes: 28 additions & 18 deletions FavCat/CustomLists/CustomPickerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,24 +136,7 @@ public void Awake()
var endBtn = transform.Find("Header/EndButton").GetComponent<Button>();

// Theme elements
if (FavCatSettings.UseCustomStyles.Value)
{
if (FavCatSettings.ColorBackground.Value)
{
transform.Find("Background").GetComponent<Image>().color = FavCatSettings.BaseColor.RGBMultiplied(0.9f).AlphaMultiplied(0.9f);
}
else
{
transform.Find("Background").GetComponent<Image>().color = new Color(0.1f, 0.1f, 0.1f, 0.8f);
}
transform.Find("Header").GetComponent<Image>().color = FavCatSettings.BaseColor;
lessBtn.colors = FavCatSettings.ButtonColors;
moreBtn.colors = FavCatSettings.ButtonColors;
settingsBtn.colors = FavCatSettings.ButtonColors;
homeBtn.colors = FavCatSettings.ButtonColors;
endBtn.colors = FavCatSettings.ButtonColors;
myFavButton.colors = FavCatSettings.ButtonColors;
}
SetupTheme();

lessBtn.onClick.AddListener((Action)CollapseClick);
moreBtn.onClick.AddListener((Action)ExpandClick);
Expand All @@ -177,6 +160,33 @@ public void Awake()
}
}

[HideFromIl2Cpp]
private void SetupTheme()
{
if (FavCatSettings.UseCustomStyles.Value)
{
if (FavCatSettings.ColorBackground.Value)
{
transform.Find("Background").GetComponent<Image>().color = FavCatSettings.BaseColor.RGBMultiplied(0.9f).AlphaMultiplied(0.9f);
}
else
{
transform.Find("Background").GetComponent<Image>().color = new Color(0.1f, 0.1f, 0.1f, 0.8f);
}

transform.Find("Header").GetComponent<Image>().color = FavCatSettings.BaseColor;

myFavButton.colors = FavCatSettings.ButtonColors;
transform.Find("Header/LessButton").GetComponent<Button>().colors = FavCatSettings.ButtonColors;
transform.Find("Header/MoreButton").GetComponent<Button>().colors = FavCatSettings.ButtonColors;
transform.Find("Header/SettingsButton").GetComponent<Button>().colors = FavCatSettings.ButtonColors;
transform.Find("Header/HomeButton").GetComponent<Button>().colors = FavCatSettings.ButtonColors;
transform.Find("Header/EndButton").GetComponent<Button>().colors = FavCatSettings.ButtonColors;
}
}

private void OnEnable() => SetupTheme();

private static ScrollRectEx AddScrollRectEx(Transform scrollView)
{
var rect = scrollView.GetComponent<ScrollRectEx>();
Expand Down
6 changes: 3 additions & 3 deletions FavCat/FavCatSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private static IEnumerator RegisterStyletorSettings()
// We need to wait so that Styletor can load before us
yield return new WaitForEndOfFrame();
MelonLogger.Msg("Styletor is loaded, adding Styletor settings");
UseStyletorColors = Category.CreateEntry(nameof(UseStyletorColors), false, "Inherit color choices from Styletor (requires restart)");
UseStyletorColors = Category.CreateEntry(nameof(UseStyletorColors), false, "Inherit color choices from Styletor");
StyletorBase = MelonPreferences.GetEntry<string>("Styletor", "BaseColorString");
StyletorAccent = MelonPreferences.GetEntry<string>("Styletor", "AccentColorString");
}
Expand All @@ -89,8 +89,8 @@ internal static void RegisterSettings()

SortPlayersByJoinable = Category.CreateEntry(nameof(SortPlayersByJoinable), true, "Show players in private instances at the end of the list");

UseCustomStyles = Category.CreateEntry(nameof(UseCustomStyles), true, "Use custom styles (requires restart)");
ColorBackground = Category.CreateEntry(nameof(ColorBackground), false, "Use custom colors on the background of favorite lists (requires restart)");
UseCustomStyles = Category.CreateEntry(nameof(UseCustomStyles), true, "Use custom styles (requires restart to disable)");
ColorBackground = Category.CreateEntry(nameof(ColorBackground), false, "Use custom colors on the background of favorite lists");
if (IsStyletorLoaded)
{
MelonCoroutines.Start(RegisterStyletorSettings());
Expand Down

0 comments on commit 8227987

Please sign in to comment.