mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2026-06-23 06:48:20 +00:00
[NAK_CVR_Mods] Unfucked for 2026r182
This commit is contained in:
parent
c13dc8375a
commit
281403d68b
209 changed files with 3936 additions and 1122 deletions
|
|
@ -0,0 +1,24 @@
|
|||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
using NAK.Stickers.Utilities;
|
||||
|
||||
namespace NAK.Stickers.Integrations;
|
||||
|
||||
public static partial class BTKUIAddon
|
||||
{
|
||||
private static void Setup_OtherOptionsCategory()
|
||||
{
|
||||
Category debugCategory = _rootPage.AddMelonCategory(ModSettings.Hidden_Foldout_MiscCategory);
|
||||
debugCategory.AddMelonToggle(ModSettings.Debug_NetworkInbound);
|
||||
debugCategory.AddMelonToggle(ModSettings.Debug_NetworkOutbound);
|
||||
debugCategory.AddMelonToggle(ModSettings.Entry_FriendsOnly);
|
||||
debugCategory.AddButton("Clear Thumbnail Cache", "Stickers-rubbish-bin", "Clear the cache of all loaded stickers.", ButtonStyle.TextWithIcon)
|
||||
.OnPress += () => QuickMenuAPI.ShowConfirm("Clear Thumbnail Cache", "Are you sure you want to clear the Cohtml thumbnail cache for all stickers?",
|
||||
() =>
|
||||
{
|
||||
StickerCache.ClearCache();
|
||||
QuickMenuAPI.ShowAlertToast("Thumbnail cache cleared.", 2);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
using BTKUILib.UIObjects.Objects;
|
||||
|
||||
namespace NAK.Stickers.Integrations;
|
||||
|
||||
public static partial class BTKUIAddon
|
||||
{
|
||||
private static Category _ourCategory;
|
||||
|
||||
private static Button _placeStickersButton;
|
||||
|
||||
private static readonly MultiSelection _sfxSelection =
|
||||
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_SelectedSFX);
|
||||
|
||||
private static readonly MultiSelection _desktopKeybindSelection =
|
||||
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_PlaceBinding);
|
||||
|
||||
private static readonly MultiSelection _tabDoubleClickSelection =
|
||||
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_TabDoubleClick);
|
||||
|
||||
#region Category Setup
|
||||
|
||||
private static void Setup_StickersModCategory()
|
||||
{
|
||||
_ourCategory = _rootPage.AddMelonCategory(ModSettings.Hidden_Foldout_SettingsCategory);
|
||||
|
||||
_placeStickersButton = _ourCategory.AddButton("Place Stickers", "Stickers-magic-wand", "Place stickers via raycast.", ButtonStyle.TextWithIcon);
|
||||
_placeStickersButton.OnPress += OnPlaceStickersButtonClick;
|
||||
|
||||
Button clearSelfStickersButton = _ourCategory.AddButton("Clear Self", "Stickers-eraser", "Clear own stickers.", ButtonStyle.TextWithIcon);
|
||||
clearSelfStickersButton.OnPress += OnClearSelfStickersButtonClick;
|
||||
|
||||
Button clearAllStickersButton = _ourCategory.AddButton("Clear All", "Stickers-rubbish-bin", "Clear all stickers.", ButtonStyle.TextWithIcon);
|
||||
clearAllStickersButton.OnPress += OnClearAllStickersButtonClick;
|
||||
|
||||
Button openStickersFolderButton = _ourCategory.AddButton("Open Stickers Folder", "Stickers-folder", "Open UserData/Stickers folder in explorer. If above 256kb your image will automatically be downscaled for networking reasons.", ButtonStyle.TextWithIcon);
|
||||
openStickersFolderButton.OnPress += OnOpenStickersFolderButtonClick;
|
||||
|
||||
Button openStickerSFXButton = _ourCategory.AddButton("Sticker SFX", "Stickers-headset", "Choose the SFX used when a sticker is placed.", ButtonStyle.TextWithIcon);
|
||||
openStickerSFXButton.OnPress += () => QuickMenuAPI.OpenMultiSelect(_sfxSelection);
|
||||
|
||||
ToggleButton toggleDesktopKeybindButton = _ourCategory.AddToggle("Use Desktop Keybind", "Should the Desktop keybind be active.", ModSettings.Entry_UsePlaceBinding.Value);
|
||||
Button openDesktopKeybindButton = _ourCategory.AddButton("Desktop Keybind", "Stickers-alphabet", "Choose the key binding to place stickers.", ButtonStyle.TextWithIcon);
|
||||
openDesktopKeybindButton.OnPress += () => QuickMenuAPI.OpenMultiSelect(_desktopKeybindSelection);
|
||||
toggleDesktopKeybindButton.OnValueUpdated += (b) =>
|
||||
{
|
||||
ModSettings.Entry_UsePlaceBinding.Value = b;
|
||||
openDesktopKeybindButton.Disabled = !b;
|
||||
};
|
||||
|
||||
Button openTabDoubleClickButton = _ourCategory.AddButton("Tab Double Click", "Stickers-mouse", "Choose the action to perform when double clicking the Stickers tab.", ButtonStyle.TextWithIcon);
|
||||
openTabDoubleClickButton.OnPress += () => QuickMenuAPI.OpenMultiSelect(_tabDoubleClickSelection);
|
||||
}
|
||||
|
||||
#endregion Category Setup
|
||||
|
||||
#region Button Actions
|
||||
|
||||
private static void OnPlaceStickersButtonClick()
|
||||
{
|
||||
if (!_isOurTabOpened) return;
|
||||
|
||||
if (StickerSystem.Instance.IsRestrictedInstance)
|
||||
{
|
||||
QuickMenuAPI.ShowAlertToast("Stickers are not allowed in this world!", 2);
|
||||
return;
|
||||
}
|
||||
|
||||
string mode = StickerSystem.Instance.IsInStickerMode ? "Exiting" : "Entering";
|
||||
QuickMenuAPI.ShowAlertToast($"{mode} sticker placement mode...", 2);
|
||||
StickerSystem.Instance.IsInStickerMode = !StickerSystem.Instance.IsInStickerMode;
|
||||
}
|
||||
|
||||
private static void OnClearSelfStickersButtonClick()
|
||||
{
|
||||
if (!_isOurTabOpened) return;
|
||||
QuickMenuAPI.ShowAlertToast("Clearing own stickers in world...", 2);
|
||||
StickerSystem.Instance.ClearStickersSelf();
|
||||
}
|
||||
|
||||
private static void OnClearAllStickersButtonClick()
|
||||
{
|
||||
if (!_isOurTabOpened) return;
|
||||
QuickMenuAPI.ShowAlertToast("Clearing all stickers in world...", 2);
|
||||
StickerSystem.Instance.ClearAllStickers();
|
||||
}
|
||||
|
||||
private static void OnOpenStickersFolderButtonClick()
|
||||
{
|
||||
if (!_isOurTabOpened) return;
|
||||
QuickMenuAPI.ShowAlertToast("Opening Stickers folder in Explorer...", 2);
|
||||
StickerSystem.OpenStickersFolder();
|
||||
}
|
||||
|
||||
public static void OnStickerRestrictionUpdated(bool isRestricted = false) //TODO: add Icon changing, Bono needs to expose the value first.
|
||||
{
|
||||
if (_rootPage == null || _placeStickersButton == null)
|
||||
return;
|
||||
|
||||
if (isRestricted)
|
||||
{
|
||||
_rootPage.MenuSubtitle = "Stickers... are sadly disabled in this world.";
|
||||
|
||||
_placeStickersButton.Disabled = true;
|
||||
_placeStickersButton.ButtonText = "Stickers Disabled";
|
||||
_placeStickersButton.ButtonTooltip = "This world is not allowing Stickers.";
|
||||
_placeStickersButton.ButtonIcon = "Stickers-magic-wand-broken";
|
||||
return;
|
||||
}
|
||||
|
||||
_rootPage.MenuSubtitle = "Stickers! Double-click the tab to quickly toggle Sticker Mode.";
|
||||
|
||||
_placeStickersButton.Disabled = false;
|
||||
_placeStickersButton.ButtonText = "Place Stickers";
|
||||
_placeStickersButton.ButtonTooltip = "Place stickers via raycast.";
|
||||
_placeStickersButton.ButtonIcon = "Stickers-magic-wand";
|
||||
}
|
||||
|
||||
#endregion Button Actions
|
||||
}
|
||||
116
.Deprecated/Stickers/Integrations/BTKUI/UIAddon.Main.cs
Normal file
116
.Deprecated/Stickers/Integrations/BTKUI/UIAddon.Main.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using NAK.Stickers.Networking;
|
||||
using NAK.Stickers.Utilities;
|
||||
using System.Reflection;
|
||||
|
||||
namespace NAK.Stickers.Integrations;
|
||||
|
||||
public static partial class BTKUIAddon
|
||||
{
|
||||
private static Page _rootPage;
|
||||
private static string _rootPageElementID;
|
||||
|
||||
private static bool _isOurTabOpened;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
Setup_Icons();
|
||||
Setup_StickerModTab();
|
||||
Setup_PlayerOptionsPage();
|
||||
}
|
||||
|
||||
#region Setup
|
||||
|
||||
private static void Setup_Icons()
|
||||
{
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
string assemblyName = assembly.GetName().Name;
|
||||
|
||||
// All icons used - https://www.flaticon.com/authors/gohsantosadrive
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-alphabet", GetIconStream("Gohsantosadrive_Icons.Stickers-alphabet.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-eraser", GetIconStream("Gohsantosadrive_Icons.Stickers-eraser.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-folder", GetIconStream("Gohsantosadrive_Icons.Stickers-folder.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-headset", GetIconStream("Gohsantosadrive_Icons.Stickers-headset.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magnifying-glass", GetIconStream("Gohsantosadrive_Icons.Stickers-magnifying-glass.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand", GetIconStream("Gohsantosadrive_Icons.Stickers-magic-wand.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand-broken", GetIconStream("Gohsantosadrive_Icons.Stickers-magic-wand-broken.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-mouse", GetIconStream("Gohsantosadrive_Icons.Stickers-mouse.png"));
|
||||
//QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-pencil", GetIconStream("Gohsantosadrive_Icons.Stickers-pencil.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle", GetIconStream("Gohsantosadrive_Icons.Stickers-puzzle.png"));
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle-disabled", GetIconStream("Gohsantosadrive_Icons.Stickers-puzzle-disabled.png")); // disabled Sticker Puzzle
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-rubbish-bin", GetIconStream("Gohsantosadrive_Icons.Stickers-rubbish-bin.png"));
|
||||
|
||||
return;
|
||||
Stream GetIconStream(string iconName) => assembly.GetManifestResourceStream($"{assemblyName}.Resources.{iconName}");
|
||||
}
|
||||
|
||||
private static void Setup_StickerModTab()
|
||||
{
|
||||
_rootPage = new Page(ModSettings.ModName, ModSettings.SM_SettingsCategory, true, "Stickers-Puzzle") // sticker icon will be left blank as it is updated on world join, AFTER Icon value is exposed..
|
||||
{
|
||||
MenuTitle = ModSettings.SM_SettingsCategory + $" (Network Version v{ModNetwork.NetworkVersion})",
|
||||
MenuSubtitle = "", // left this blank as it is defined when the world loads
|
||||
};
|
||||
|
||||
_rootPageElementID = _rootPage.ElementID;
|
||||
|
||||
QuickMenuAPI.OnTabChange += OnTabChange;
|
||||
ModNetwork.OnTextureOutboundStateChanged += (isSending) =>
|
||||
{
|
||||
if (_isOurTabOpened && isSending) QuickMenuAPI.ShowAlertToast("Sending Sticker over Mod Network...", 2);
|
||||
//_rootPage.Disabled = isSending; // TODO: fix being able to select stickers while sending
|
||||
};
|
||||
|
||||
StickerSystem.OnStickerLoaded += (slotIndex, imageRelativePath) =>
|
||||
{
|
||||
if (_isOurTabOpened) QuickMenuAPI.ShowAlertToast($"Sticker loaded: {imageRelativePath}", 2);
|
||||
_stickerSelectionButtons[slotIndex].ButtonIcon = StickerCache.GetBtkUiIconName(imageRelativePath);
|
||||
};
|
||||
|
||||
StickerSystem.OnStickerLoadFailed += (slotIndex, error) =>
|
||||
{
|
||||
if (_isOurTabOpened) QuickMenuAPI.ShowAlertToast(error, 3);
|
||||
};
|
||||
|
||||
Setup_StickersModCategory();
|
||||
Setup_StickerSelectionCategory();
|
||||
Setup_OtherOptionsCategory();
|
||||
}
|
||||
|
||||
#endregion Setup
|
||||
|
||||
#region Double-Click Place Sticker
|
||||
|
||||
private static DateTime lastTime = DateTime.Now;
|
||||
|
||||
private static void OnTabChange(string newTab, string previousTab)
|
||||
{
|
||||
_isOurTabOpened = newTab == _rootPageElementID;
|
||||
if (!_isOurTabOpened) return;
|
||||
|
||||
TimeSpan timeDifference = DateTime.Now - lastTime;
|
||||
if (timeDifference.TotalSeconds <= 0.5)
|
||||
{
|
||||
switch (ModSettings.Entry_TabDoubleClick.Value)
|
||||
{
|
||||
default:
|
||||
case TabDoubleClick.ToggleStickerMode:
|
||||
OnPlaceStickersButtonClick();
|
||||
break;
|
||||
case TabDoubleClick.ClearAllStickers:
|
||||
OnClearAllStickersButtonClick();
|
||||
break;
|
||||
case TabDoubleClick.ClearSelfStickers:
|
||||
OnClearSelfStickersButtonClick();
|
||||
break;
|
||||
case TabDoubleClick.None:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
lastTime = DateTime.Now;
|
||||
}
|
||||
|
||||
#endregion Double-Click Place Sticker
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
using NAK.Stickers.Networking;
|
||||
|
||||
namespace NAK.Stickers.Integrations;
|
||||
|
||||
public static partial class BTKUIAddon
|
||||
{
|
||||
#region Setup
|
||||
|
||||
private static ToggleButton _disallowForSessionButton;
|
||||
|
||||
private static void Setup_PlayerOptionsPage()
|
||||
{
|
||||
Category category = QuickMenuAPI.PlayerSelectPage.AddCategory(ModSettings.SM_SettingsCategory, ModSettings.ModName);
|
||||
|
||||
Button identifyButton = category.AddButton("Identify Stickers", "Stickers-magnifying-glass", "Identify this players stickers by making them flash.");
|
||||
identifyButton.OnPress += OnPressIdentifyPlayerStickersButton;
|
||||
|
||||
Button clearStickersButton = category.AddButton("Clear Stickers", "Stickers-eraser", "Clear this players stickers.");
|
||||
clearStickersButton.OnPress += OnPressClearSelectedPlayerStickersButton;
|
||||
|
||||
_disallowForSessionButton = category.AddToggle("Block for Session", "Disallow this player from using stickers for this session. This setting will not persist through restarts.", false);
|
||||
_disallowForSessionButton.OnValueUpdated += OnToggleDisallowForSessionButton;
|
||||
QuickMenuAPI.OnPlayerSelected += (_, id) => { _disallowForSessionButton.ToggleValue = ModNetwork.IsPlayerACriminal(id); };
|
||||
}
|
||||
|
||||
#endregion Setup
|
||||
|
||||
#region Callbacks
|
||||
|
||||
private static void OnPressIdentifyPlayerStickersButton()
|
||||
{
|
||||
if (string.IsNullOrEmpty(QuickMenuAPI.SelectedPlayerID)) return;
|
||||
StickerSystem.Instance.OnStickerIdentifyReceived(QuickMenuAPI.SelectedPlayerID);
|
||||
}
|
||||
|
||||
private static void OnPressClearSelectedPlayerStickersButton()
|
||||
{
|
||||
if (string.IsNullOrEmpty(QuickMenuAPI.SelectedPlayerID)) return;
|
||||
StickerSystem.Instance.OnStickerClearAllReceived(QuickMenuAPI.SelectedPlayerID);
|
||||
}
|
||||
|
||||
private static void OnToggleDisallowForSessionButton(bool isOn)
|
||||
{
|
||||
if (string.IsNullOrEmpty(QuickMenuAPI.SelectedPlayerID)) return;
|
||||
ModNetwork.HandleDisallowForSession(QuickMenuAPI.SelectedPlayerID, isOn);
|
||||
}
|
||||
|
||||
|
||||
#endregion Callbacks
|
||||
}
|
||||
|
|
@ -0,0 +1,287 @@
|
|||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
using MTJobSystem;
|
||||
using NAK.Stickers.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.Stickers.Integrations;
|
||||
|
||||
public static partial class BTKUIAddon
|
||||
{
|
||||
#region Constants and Fields
|
||||
|
||||
private static readonly HashSet<string> SUPPORTED_IMAGE_EXTENSIONS = new() { ".png", ".jpg", ".jpeg" };
|
||||
|
||||
private static Page _ourDirectoryBrowserPage;
|
||||
|
||||
private static Category _fileCategory;
|
||||
private static Category _folderCategory;
|
||||
private static TextBlock _noFilesTextBlock;
|
||||
|
||||
private const int MAX_BUTTONS = 512; // cohtml literally will start to explode
|
||||
private static Button[] _fileButtons = new Button[80]; // 100 files, will resize if needed
|
||||
private static Button[] _folderButtons = new Button[20]; // 20 folders, will resize if needed
|
||||
|
||||
private static readonly Button[] _stickerSelectionButtons = new Button[4];
|
||||
private static float _stickerSelectionButtonDoubleClickTime;
|
||||
|
||||
private static DirectoryInfo _curDirectoryInfo;
|
||||
private static string _initialDirectory;
|
||||
private static int _curSelectedSticker;
|
||||
|
||||
private static readonly object _isPopulatingLock = new();
|
||||
private static bool _isPopulating;
|
||||
internal static bool IsPopulatingPage {
|
||||
get { lock (_isPopulatingLock) return _isPopulating; }
|
||||
private set { lock (_isPopulatingLock) _isPopulating = value; }
|
||||
}
|
||||
|
||||
#endregion Constants and Fields
|
||||
|
||||
#region Page Setup
|
||||
|
||||
private static void Setup_StickerSelectionCategory()
|
||||
{
|
||||
_initialDirectory = StickerSystem.GetStickersFolderPath();
|
||||
_curDirectoryInfo = new DirectoryInfo(_initialDirectory);
|
||||
|
||||
// Create page
|
||||
_ourDirectoryBrowserPage = Page.GetOrCreatePage(ModSettings.ModName, "Directory Browser");
|
||||
QuickMenuAPI.AddRootPage(_ourDirectoryBrowserPage);
|
||||
|
||||
// Setup categories
|
||||
_folderCategory = _ourDirectoryBrowserPage.AddCategory("Subdirectories");
|
||||
_fileCategory = _ourDirectoryBrowserPage.AddCategory("Images");
|
||||
_noFilesTextBlock = _fileCategory.AddTextBlock("No images found in this directory. You can add your own images and subfolders to the `UserData/Stickers/` folder.");
|
||||
_noFilesTextBlock.Hidden = true;
|
||||
|
||||
SetupFolderButtons();
|
||||
SetupFileButtons();
|
||||
SetupStickerSelectionButtons();
|
||||
|
||||
_ourDirectoryBrowserPage.OnPageOpen += OnPageOpen;
|
||||
_ourDirectoryBrowserPage.OnPageClosed += OnPageClosed;
|
||||
}
|
||||
|
||||
private static void SetupFolderButtons(int startIndex = 0)
|
||||
{
|
||||
for (int i = startIndex; i < _folderButtons.Length; i++)
|
||||
{
|
||||
Button button = _folderCategory.AddButton("A", "Stickers-folder", "A");
|
||||
button.OnPress += () =>
|
||||
{
|
||||
if (IsPopulatingPage) return;
|
||||
_curDirectoryInfo = new DirectoryInfo(Path.Combine(_curDirectoryInfo.FullName, button.ButtonTooltip[5..]));
|
||||
_ourDirectoryBrowserPage.OpenPage(false, true);
|
||||
};
|
||||
_folderButtons[i] = button;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetupFileButtons(int startIndex = 0)
|
||||
{
|
||||
for (int i = startIndex; i < _fileButtons.Length; i++)
|
||||
{
|
||||
Button button = _fileCategory.AddButton(string.Empty, "Stickers-folder", "A", ButtonStyle.FullSizeImage);
|
||||
button.Hidden = true;
|
||||
button.OnPress += () =>
|
||||
{
|
||||
string absolutePath = Path.Combine(_curDirectoryInfo.FullName, button.ButtonTooltip[5..]);
|
||||
string relativePath = Path.GetRelativePath(_initialDirectory, absolutePath);
|
||||
StickerSystem.Instance.LoadImage(relativePath, _curSelectedSticker);
|
||||
_rootPage.OpenPage(true); // close the directory browser to artificially limit loading speed
|
||||
};
|
||||
_fileButtons[i] = button;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetupStickerSelectionButtons()
|
||||
{
|
||||
Category stickerSelection = _rootPage.AddMelonCategory(ModSettings.Hidden_Foldout_SelectionCategory);
|
||||
|
||||
for (int i = 0; i < _stickerSelectionButtons.Length; i++)
|
||||
{
|
||||
Button button = stickerSelection.AddButton(string.Empty, "Stickers-puzzle", "Click to select sticker for placement. Double-click or hold to select from Stickers folder.", ButtonStyle.FullSizeImage);
|
||||
var curIndex = i;
|
||||
button.OnPress += () => SelectStickerAtSlot(curIndex);
|
||||
button.OnHeld += () => OpenStickerSelectionForSlot(curIndex);
|
||||
_stickerSelectionButtons[i] = button;
|
||||
|
||||
// initial setup
|
||||
button.ButtonIcon = StickerCache.GetBtkUiIconName(ModSettings.Hidden_SelectedStickerNames.Value[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Page Setup
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static void OnPageOpen()
|
||||
{
|
||||
if (IsPopulatingPage) return; // btkui bug, page open is called twice when using OnHeld
|
||||
IsPopulatingPage = true;
|
||||
|
||||
_ourDirectoryBrowserPage.PageDisplayName = _curDirectoryInfo.Name;
|
||||
|
||||
HideAllButtons(_folderButtons);
|
||||
HideAllButtons(_fileButtons);
|
||||
|
||||
// Populate the page
|
||||
Task.Run(PopulateMenuItems);
|
||||
}
|
||||
|
||||
private static void OnPageClosed()
|
||||
{
|
||||
if (_curDirectoryInfo.FullName != _initialDirectory)
|
||||
_curDirectoryInfo = new DirectoryInfo(Path.Combine(_curDirectoryInfo.FullName, @"..\"));
|
||||
}
|
||||
|
||||
private static void HideAllButtons(Button[] buttons)
|
||||
{
|
||||
foreach (Button button in buttons)
|
||||
{
|
||||
if (button == null) break; // Array resized, excess buttons are generating
|
||||
//if (button.Hidden) break; // Reached the end of the visible buttons
|
||||
button.Hidden = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SelectStickerAtSlot(int index)
|
||||
{
|
||||
if (_curSelectedSticker != index)
|
||||
{
|
||||
_curSelectedSticker = index;
|
||||
_stickerSelectionButtonDoubleClickTime = 0f;
|
||||
}
|
||||
|
||||
StickerSystem.Instance.SelectedStickerSlot = index;
|
||||
|
||||
// double-click to open (otherwise just hold)
|
||||
if (Time.time - _stickerSelectionButtonDoubleClickTime < 0.5f)
|
||||
{
|
||||
OpenStickerSelectionForSlot(index);
|
||||
_stickerSelectionButtonDoubleClickTime = 0f;
|
||||
return;
|
||||
}
|
||||
_stickerSelectionButtonDoubleClickTime = Time.time;
|
||||
|
||||
// quick menu notification
|
||||
QuickMenuAPI.ShowAlertToast($"Selected sticker slot {index + 1}", 1);
|
||||
}
|
||||
|
||||
private static void OpenStickerSelectionForSlot(int index)
|
||||
{
|
||||
if (IsPopulatingPage) return;
|
||||
_curSelectedSticker = index;
|
||||
_initialDirectory = StickerSystem.GetStickersFolderPath(); // creates folder if needed (lazy fix)
|
||||
_curDirectoryInfo = new DirectoryInfo(_initialDirectory);
|
||||
_ourDirectoryBrowserPage.OpenPage(false, true);
|
||||
}
|
||||
|
||||
private static void PopulateMenuItems()
|
||||
{
|
||||
//StickerMod.Logger.Msg("Populating menu items.");
|
||||
try
|
||||
{
|
||||
Thread.CurrentThread.IsBackground = false; // working around bug in MTJobManager
|
||||
|
||||
var directories = _curDirectoryInfo.GetDirectories();
|
||||
var files = _curDirectoryInfo.GetFiles();
|
||||
|
||||
MTJobManager.RunOnMainThread("PopulateMenuItems", () =>
|
||||
{
|
||||
// resize the arrays to the max amount of buttons
|
||||
int foldersCount = Mathf.Min(directories.Length, MAX_BUTTONS);
|
||||
if (foldersCount > _folderButtons.Length)
|
||||
{
|
||||
int folderEndIdx = _folderButtons.Length;
|
||||
Array.Resize(ref _folderButtons, foldersCount);
|
||||
SetupFolderButtons(folderEndIdx);
|
||||
}
|
||||
|
||||
int filesCount = Mathf.Min(files.Length, MAX_BUTTONS);
|
||||
if (filesCount > _fileButtons.Length)
|
||||
{
|
||||
int fileEndIdx = _fileButtons.Length;
|
||||
Array.Resize(ref _fileButtons, filesCount);
|
||||
SetupFileButtons(fileEndIdx);
|
||||
}
|
||||
|
||||
_folderCategory.Hidden = foldersCount == 0;
|
||||
_folderCategory.CategoryName = $"Subdirectories ({foldersCount})";
|
||||
//_fileCategory.Hidden = filesCount == 0;
|
||||
_fileCategory.CategoryName = $"Images ({filesCount})";
|
||||
_noFilesTextBlock.Hidden = filesCount > 0;
|
||||
});
|
||||
|
||||
PopulateFolders(directories);
|
||||
PopulateFiles(files);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
StickerMod.Logger.Error($"Failed to populate menu items: {e.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsPopulatingPage = false;
|
||||
Thread.CurrentThread.IsBackground = true; // working around bug in MTJobManager
|
||||
}
|
||||
}
|
||||
|
||||
private static void PopulateFolders(IReadOnlyList<DirectoryInfo> directories)
|
||||
{
|
||||
for (int i = 0; i < _folderButtons.Length; i++)
|
||||
{
|
||||
if (i >= directories.Count)
|
||||
break;
|
||||
|
||||
Button button = _folderButtons[i];
|
||||
//if (button == null) continue; // Array resized, excess buttons are generating
|
||||
|
||||
button.ButtonText = directories[i].Name;
|
||||
button.ButtonTooltip = $"Open {directories[i].Name}";
|
||||
MTJobManager.RunAsyncOnMainThread("PopulateMenuItems", () => button.Hidden = false);
|
||||
|
||||
if (i <= 16) Thread.Sleep(10); // For the pop-in effect
|
||||
}
|
||||
}
|
||||
|
||||
private static void PopulateFiles(IReadOnlyList<FileInfo> files)
|
||||
{
|
||||
for (int i = 0; i < _fileButtons.Length; i++)
|
||||
{
|
||||
if (i >= files.Count)
|
||||
break;
|
||||
|
||||
FileInfo fileInfo = files[i];
|
||||
|
||||
if (!SUPPORTED_IMAGE_EXTENSIONS.Contains(fileInfo.Extension.ToLower()))
|
||||
continue;
|
||||
|
||||
string relativePath = Path.GetRelativePath(_initialDirectory, fileInfo.FullName);
|
||||
string relativePathWithoutExtension = relativePath[..^fileInfo.Extension.Length];
|
||||
|
||||
Button button = _fileButtons[i];
|
||||
//if (button == null) continue; // Array resized, excess buttons are generating
|
||||
|
||||
button.ButtonTooltip = $"Load {fileInfo.Name}"; // Do not change "Load " prefix, we extract file name
|
||||
|
||||
if (StickerCache.IsThumbnailAvailable(relativePathWithoutExtension))
|
||||
{
|
||||
button.ButtonIcon = StickerCache.GetBtkUiIconName(relativePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
button.ButtonIcon = string.Empty;
|
||||
StickerCache.EnqueueThumbnailGeneration(fileInfo, button);
|
||||
}
|
||||
|
||||
MTJobManager.RunAsyncOnMainThread("PopulateMenuItems", () => button.Hidden = false);
|
||||
|
||||
if (i <= 16) Thread.Sleep(10); // For the pop-in effect
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Icon Utils
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue