Stickers: updated to BTKUIv2.3.0

This commit is contained in:
NotAKidoS 2024-09-10 20:21:41 -05:00
parent a168619d19
commit 52315f5d51
3 changed files with 13 additions and 116 deletions

View file

@ -1,103 +0,0 @@
using System.Reflection;
using BTKUILib;
using BTKUILib.UIObjects;
using BTKUILib.UIObjects.Components;
using BTKUILib.UIObjects.Objects;
using JetBrains.Annotations;
using MelonLoader;
using UnityEngine;
namespace NAK.Stickers.Integrations;
[PublicAPI]
public static class BTKUILibExtensions
{
#region Icon Utils
public static Stream GetIconStream(string iconName)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string assemblyName = assembly.GetName().Name;
return assembly.GetManifestResourceStream($"{assemblyName}.Resources.{iconName}");
}
#endregion Icon Utils
#region Enum Utils
private static class EnumUtils
{
public static string[] GetPrettyEnumNames<T>() where T : Enum
{
return Enum.GetNames(typeof(T)).Select(PrettyFormatEnumName).ToArray();
}
private static string PrettyFormatEnumName(string name)
{
// adds spaces before capital letters (excluding the first letter)
return System.Text.RegularExpressions.Regex.Replace(name, "(\\B[A-Z])", " $1");
}
public static int GetEnumIndex<T>(T value) where T : Enum
{
return Array.IndexOf(Enum.GetValues(typeof(T)), value);
}
}
#endregion Enum Utils
#region Melon Preference Extensions
public static ToggleButton AddMelonToggle(this Category category, MelonPreferences_Entry<bool> entry)
{
ToggleButton toggle = category.AddToggle(entry.DisplayName, entry.Description, entry.Value);
toggle.OnValueUpdated += b => entry.Value = b;
return toggle;
}
public static SliderFloat AddMelonSlider(this Category category, MelonPreferences_Entry<float> entry, float min,
float max, int decimalPlaces = 2, bool allowReset = true)
{
SliderFloat slider = category.AddSlider(entry.DisplayName, entry.Description,
Mathf.Clamp(entry.Value, min, max), min, max, decimalPlaces, entry.DefaultValue, allowReset);
slider.OnValueUpdated += f => entry.Value = f;
return slider;
}
public static Button AddMelonStringInput(this Category category, MelonPreferences_Entry<string> entry, string buttonIcon = "", ButtonStyle buttonStyle = ButtonStyle.TextOnly)
{
Button button = category.AddButton(entry.DisplayName, buttonIcon, entry.Description, buttonStyle);
button.OnPress += () => QuickMenuAPI.OpenKeyboard(entry.Value, s => entry.Value = s);
return button;
}
public static Button AddMelonNumberInput(this Category category, MelonPreferences_Entry<float> entry, string buttonIcon = "", ButtonStyle buttonStyle = ButtonStyle.TextOnly)
{
Button button = category.AddButton(entry.DisplayName, buttonIcon, entry.Description, buttonStyle);
button.OnPress += () => QuickMenuAPI.OpenNumberInput(entry.DisplayName, entry.Value, f => entry.Value = f);
return button;
}
public static Category AddMelonCategory(this Page page, MelonPreferences_Entry<bool> entry, bool showHeader = true)
{
Category category = page.AddCategory(entry.DisplayName, showHeader, true, !entry.Value);
category.OnCollapse += b => entry.Value = !b; // more intuitive if pref value of true means category open
return category;
}
public static MultiSelection CreateMelonMultiSelection<TEnum>(MelonPreferences_Entry<TEnum> entry) where TEnum : Enum
{
MultiSelection multiSelection = new(
entry.DisplayName,
EnumUtils.GetPrettyEnumNames<TEnum>(),
EnumUtils.GetEnumIndex(entry.Value)
)
{
OnOptionUpdated = i => entry.Value = (TEnum)Enum.Parse(typeof(TEnum), Enum.GetNames(typeof(TEnum))[i])
};
return multiSelection;
}
#endregion Melon Preference Extensions
}

View file

@ -10,13 +10,13 @@ public static partial class BTKUIAddon
private static Category _ourCategory;
private static readonly MultiSelection _sfxSelection =
BTKUILibExtensions.CreateMelonMultiSelection(ModSettings.Entry_SelectedSFX);
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_SelectedSFX);
private static readonly MultiSelection _desktopKeybindSelection =
BTKUILibExtensions.CreateMelonMultiSelection(ModSettings.Entry_PlaceBinding);
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_PlaceBinding);
private static readonly MultiSelection _tabDoubleClickSelection =
BTKUILibExtensions.CreateMelonMultiSelection(ModSettings.Entry_TabDoubleClick);
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_TabDoubleClick);
#region Category Setup

View file

@ -24,16 +24,16 @@ public static partial class BTKUIAddon
private static void Setup_Icons()
{
// All icons used - https://www.flaticon.com/authors/gohsantosadrive
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-alphabet", BTKUILibExtensions.GetIconStream("Gohsantosadrive_Icons.Stickers-alphabet.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-eraser", BTKUILibExtensions.GetIconStream("Gohsantosadrive_Icons.Stickers-eraser.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-folder", BTKUILibExtensions.GetIconStream("Gohsantosadrive_Icons.Stickers-folder.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-headset", BTKUILibExtensions.GetIconStream("Gohsantosadrive_Icons.Stickers-headset.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magnifying-glass", BTKUILibExtensions.GetIconStream("Gohsantosadrive_Icons.Stickers-magnifying-glass.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand", BTKUILibExtensions.GetIconStream("Gohsantosadrive_Icons.Stickers-magic-wand.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-mouse", BTKUILibExtensions.GetIconStream("Gohsantosadrive_Icons.Stickers-mouse.png"));
//QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-pencil", BTKUILibExtensions.GetIconStream("Gohsantosadrive_Icons.Stickers-pencil.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle", BTKUILibExtensions.GetIconStream("Gohsantosadrive_Icons.Stickers-puzzle.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-rubbish-bin", BTKUILibExtensions.GetIconStream("Gohsantosadrive_Icons.Stickers-rubbish-bin.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-alphabet", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-alphabet.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-eraser", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-eraser.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-folder", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-folder.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-headset", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-headset.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magnifying-glass", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-magnifying-glass.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-magic-wand.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-mouse", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-mouse.png"));
//QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-pencil", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-pencil.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-puzzle.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-rubbish-bin", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-rubbish-bin.png"));
}
private static void Setup_StickerModTab()