diff --git a/NoteTweaks/Managers/TextureManager.cs b/NoteTweaks/Managers/TextureManager.cs index bc76916..fa5de0f 100644 --- a/NoteTweaks/Managers/TextureManager.cs +++ b/NoteTweaks/Managers/TextureManager.cs @@ -28,8 +28,8 @@ public static Color CheckForInversion(ref this Color color, bool isBomb = false) internal abstract class Textures { - private static readonly string[] FileExtensions = { ".png", ".jpg", ".tga" }; - private static readonly string ImagePath = Path.Combine(UnityGame.UserDataPath, "NoteTweaks", "Textures", "Notes"); + internal static readonly string[] FileExtensions = { ".png", ".jpg", ".tga" }; + internal static readonly string ImagePath = Path.Combine(UnityGame.UserDataPath, "NoteTweaks", "Textures", "Notes"); private static readonly Texture2D OriginalArrowGlowTexture = Resources.FindObjectsOfTypeAll().ToList().First(x => x.name == "ArrowGlow"); internal static readonly Texture2D ReplacementArrowGlowTexture = OriginalArrowGlowTexture.PrepareTexture(); @@ -41,8 +41,8 @@ internal abstract class Textures private static readonly Cubemap OriginalNoteTexture = Resources.FindObjectsOfTypeAll().ToList().First(x => x.name == "NotesReflection"); private static Cubemap _noteTexture = OriginalNoteTexture; private static Cubemap _bombTexture = OriginalNoteTexture; - - private static readonly List> FaceNames = new List> + + internal static readonly List> FaceNames = new List> { new KeyValuePair("px", CubemapFace.PositiveX), new KeyValuePair("py", CubemapFace.PositiveY), @@ -60,55 +60,6 @@ public static string GetLoadedBombTexture() { return _bombTexture.name.Split("_"[0]).Last(); } - - internal static void LoadTextureChoices() - { - Plugin.Log.Info("Setting texture filenames for dropdown..."); - SettingsViewController.NoteTextureChoices.Clear(); - - if (!Directory.Exists(ImagePath)) - { - Directory.CreateDirectory(ImagePath); - } - - string[] dirs = Directory.GetDirectories(ImagePath); - foreach (string dir in dirs) - { - int count = 0; - - FaceNames.ForEach(pair => - { - foreach (string extension in FileExtensions) - { - string path = $"{dir}/{pair.Key}{extension}"; - if (File.Exists(path)) - { - count++; - break; - } - } - }); - - if (count == 6) - { - SettingsViewController.NoteTextureChoices.Add(dir.Split('\\').Last()); - } - } - - string[] files = Directory.GetFiles(ImagePath); - foreach (string file in files) - { - if (FileExtensions.Contains(Path.GetExtension(file).ToLower())) - { - SettingsViewController.NoteTextureChoices.Add(Path.GetFileNameWithoutExtension(file)); - } - } - - SettingsViewController.NoteTextureChoices.Sort(); - SettingsViewController.NoteTextureChoices = SettingsViewController.NoteTextureChoices.Prepend("Default").ToList(); - - Plugin.Log.Info("Set texture filenames"); - } private static void OnNoteImageLoaded(List> textures) { diff --git a/NoteTweaks/UI/PreviewViewController.cs b/NoteTweaks/UI/PreviewViewController.cs index 21596bc..5249353 100644 --- a/NoteTweaks/UI/PreviewViewController.cs +++ b/NoteTweaks/UI/PreviewViewController.cs @@ -31,7 +31,7 @@ internal class NotePreviewViewController : BSMLAutomaticViewController private static readonly int Color0 = Shader.PropertyToID("_Color"); private static readonly int Color1 = Shader.PropertyToID("_SimpleColor"); - private static readonly List FaceNames = new List { "NoteArrow", "NoteCircleGlow", "Circle" }; + internal static readonly List FaceNames = new List { "NoteArrow", "NoteCircleGlow", "Circle" }; private static readonly List GlowNames = new List { "NoteArrowGlow", "AddedNoteCircleGlow" }; public NotePreviewViewController() @@ -645,7 +645,6 @@ protected void OnEnable() NoteContainer = new GameObject("_NoteTweaks_NoteContainer"); DontDestroyOnLoad(NoteContainer); } - Managers.Textures.LoadTextureChoices(); if (HasInitialized) { diff --git a/NoteTweaks/UI/SettingsViewController.cs b/NoteTweaks/UI/SettingsViewController.cs index d397aea..3f8931f 100644 --- a/NoteTweaks/UI/SettingsViewController.cs +++ b/NoteTweaks/UI/SettingsViewController.cs @@ -1,8 +1,12 @@ using System.Collections.Generic; +using System.IO; +using System.Linq; using BeatSaberMarkupLanguage.Attributes; +using BeatSaberMarkupLanguage.Components.Settings; using BeatSaberMarkupLanguage.ViewControllers; using JetBrains.Annotations; using NoteTweaks.Configuration; +using NoteTweaks.Managers; using UnityEngine; using Zenject; @@ -481,7 +485,7 @@ protected string NoteTexture _config.NoteTexture = value; if (LoadTextures) { - _ = Managers.Textures.LoadNoteTexture(value); + _ = Textures.LoadNoteTexture(value); } } } @@ -514,7 +518,7 @@ protected string BombTexture _config.BombTexture = value; if (LoadTextures) { - _ = Managers.Textures.LoadNoteTexture(value, true); + _ = Textures.LoadNoteTexture(value, true); } } } @@ -537,7 +541,7 @@ protected bool InvertBombTexture _config.InvertBombTexture = value; if (LoadTextures) { - _ = Managers.Textures.LoadNoteTexture(Plugin.Config.BombTexture, true); + _ = Textures.LoadNoteTexture(Plugin.Config.BombTexture, true); } } } @@ -550,12 +554,83 @@ protected bool InvertNoteTexture _config.InvertNoteTexture = value; if (LoadTextures) { - _ = Managers.Textures.LoadNoteTexture(Plugin.Config.NoteTexture); + _ = Textures.LoadNoteTexture(Plugin.Config.NoteTexture); } } } + + [UIComponent("selectedNoteTexture")] + public DropDownListSetting noteTextureDropDown; [UIValue("noteTextureChoices")] - internal static List NoteTextureChoices = new List(); + private List NoteTextureChoices => LoadTextureChoices(); + + [UIAction("#post-parse")] + public void UpdateTextureList() + { + UpdateTextureChoices(); + } + + private void UpdateTextureChoices() + { + if (noteTextureDropDown == null) + { + return; + } + + noteTextureDropDown.Values = NoteTextureChoices; + noteTextureDropDown.UpdateChoices(); + } + + private List LoadTextureChoices() + { + Plugin.Log.Info("Setting texture filenames for dropdown..."); + List choices = new List(); + + if (!Directory.Exists(Textures.ImagePath)) + { + Directory.CreateDirectory(Textures.ImagePath); + } + + string[] dirs = Directory.GetDirectories(Textures.ImagePath); + foreach (string dir in dirs) + { + int count = 0; + + Textures.FaceNames.ForEach(pair => + { + foreach (string extension in Textures.FileExtensions) + { + string path = $"{dir}/{pair.Key}{extension}"; + if (File.Exists(path)) + { + count++; + break; + } + } + }); + + if (count == 6) + { + choices.Add(dir.Split('\\').Last()); + } + } + + string[] files = Directory.GetFiles(Textures.ImagePath); + foreach (string file in files) + { + if (Textures.FileExtensions.Contains(Path.GetExtension(file).ToLower())) + { + choices.Add(Path.GetFileNameWithoutExtension(file)); + } + } + + choices.Sort(); + choices = choices.Prepend("Default").ToList(); + + Plugin.Log.Info("Set texture filenames"); + + return choices; + } } } \ No newline at end of file