World Restriction Checks

Updated the UI based on the world restriction.
This commit is contained in:
SketchFoxsky 2024-09-20 18:14:03 -04:00 committed by GitHub
parent 498dcff8b9
commit be05c04e72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 235 additions and 194 deletions

View file

@ -1,89 +1,123 @@
using BTKUILib; using BTKUILib;
using BTKUILib.UIObjects; using BTKUILib.UIObjects;
using BTKUILib.UIObjects.Components; using BTKUILib.UIObjects.Components;
using BTKUILib.UIObjects.Objects; using BTKUILib.UIObjects.Objects;
namespace NAK.Stickers.Integrations; namespace NAK.Stickers.Integrations;
public static partial class BTKUIAddon public static partial class BTKUIAddon
{ {
private static Category _ourCategory; private static Category _ourCategory;
private static readonly MultiSelection _sfxSelection = private static readonly MultiSelection _sfxSelection =
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_SelectedSFX); MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_SelectedSFX);
private static readonly MultiSelection _desktopKeybindSelection = private static readonly MultiSelection _desktopKeybindSelection =
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_PlaceBinding); MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_PlaceBinding);
private static readonly MultiSelection _tabDoubleClickSelection = private static readonly MultiSelection _tabDoubleClickSelection =
MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_TabDoubleClick); MultiSelection.CreateMultiSelectionFromMelonPref(ModSettings.Entry_TabDoubleClick);
#region Category Setup public static Button placeStickersButton;
private static void Setup_StickersModCategory() #region Category Setup
{
_ourCategory = _rootPage.AddMelonCategory(ModSettings.Hidden_Foldout_SettingsCategory); private static void Setup_StickersModCategory()
{
Button placeStickersButton = _ourCategory.AddButton("Place Stickers", "Stickers-magic-wand", "Place stickers via raycast.", ButtonStyle.TextWithIcon); _ourCategory = _rootPage.AddMelonCategory(ModSettings.Hidden_Foldout_SettingsCategory);
placeStickersButton.OnPress += OnPlaceStickersButtonClick;
placeStickersButton = _ourCategory.AddButton("Place Stickers", "Stickers-magic-wand", "Place stickers via raycast.", ButtonStyle.TextWithIcon);
Button clearSelfStickersButton = _ourCategory.AddButton("Clear Self", "Stickers-eraser", "Clear own stickers.", ButtonStyle.TextWithIcon); placeStickersButton.OnPress += OnPlaceStickersButtonClick;
clearSelfStickersButton.OnPress += OnClearSelfStickersButtonClick;
Button clearSelfStickersButton = _ourCategory.AddButton("Clear Self", "Stickers-eraser", "Clear own stickers.", ButtonStyle.TextWithIcon);
Button clearAllStickersButton = _ourCategory.AddButton("Clear All", "Stickers-rubbish-bin", "Clear all stickers.", ButtonStyle.TextWithIcon); clearSelfStickersButton.OnPress += OnClearSelfStickersButtonClick;
clearAllStickersButton.OnPress += OnClearAllStickersButtonClick;
Button clearAllStickersButton = _ourCategory.AddButton("Clear All", "Stickers-rubbish-bin", "Clear all stickers.", ButtonStyle.TextWithIcon);
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); clearAllStickersButton.OnPress += OnClearAllStickersButtonClick;
openStickersFolderButton.OnPress += OnOpenStickersFolderButtonClick;
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);
Button openStickerSFXButton = _ourCategory.AddButton("Sticker SFX", "Stickers-headset", "Choose the SFX used when a sticker is placed.", ButtonStyle.TextWithIcon); openStickersFolderButton.OnPress += OnOpenStickersFolderButtonClick;
openStickerSFXButton.OnPress += () => QuickMenuAPI.OpenMultiSelect(_sfxSelection);
Button openStickerSFXButton = _ourCategory.AddButton("Sticker SFX", "Stickers-headset", "Choose the SFX used when a sticker is placed.", ButtonStyle.TextWithIcon);
ToggleButton toggleDesktopKeybindButton = _ourCategory.AddToggle("Use Desktop Keybind", "Should the Desktop keybind be active.", ModSettings.Entry_UsePlaceBinding.Value); openStickerSFXButton.OnPress += () => QuickMenuAPI.OpenMultiSelect(_sfxSelection);
Button openDesktopKeybindButton = _ourCategory.AddButton("Desktop Keybind", "Stickers-alphabet", "Choose the key binding to place stickers.", ButtonStyle.TextWithIcon);
openDesktopKeybindButton.OnPress += () => QuickMenuAPI.OpenMultiSelect(_desktopKeybindSelection); ToggleButton toggleDesktopKeybindButton = _ourCategory.AddToggle("Use Desktop Keybind", "Should the Desktop keybind be active.", ModSettings.Entry_UsePlaceBinding.Value);
toggleDesktopKeybindButton.OnValueUpdated += (b) => Button openDesktopKeybindButton = _ourCategory.AddButton("Desktop Keybind", "Stickers-alphabet", "Choose the key binding to place stickers.", ButtonStyle.TextWithIcon);
{ openDesktopKeybindButton.OnPress += () => QuickMenuAPI.OpenMultiSelect(_desktopKeybindSelection);
ModSettings.Entry_UsePlaceBinding.Value = b; toggleDesktopKeybindButton.OnValueUpdated += (b) =>
openDesktopKeybindButton.Disabled = !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);
} 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 #endregion Category Setup
private static void OnPlaceStickersButtonClick() #region Button Actions
{
if (!_isOurTabOpened) return; private static void OnPlaceStickersButtonClick()
string mode = StickerSystem.Instance.IsInStickerMode ? "Exiting" : "Entering"; {
QuickMenuAPI.ShowAlertToast($"{mode} sticker placement mode...", 2); if (!_isOurTabOpened) return;
StickerSystem.Instance.IsInStickerMode = !StickerSystem.Instance.IsInStickerMode;
} if (StickerSystem.RestrictedInstance == false)
{
private static void OnClearSelfStickersButtonClick() string mode = StickerSystem.Instance.IsInStickerMode ? "Exiting" : "Entering";
{ QuickMenuAPI.ShowAlertToast($"{mode} sticker placement mode...", 2);
if (!_isOurTabOpened) return; StickerSystem.Instance.IsInStickerMode = !StickerSystem.Instance.IsInStickerMode;
QuickMenuAPI.ShowAlertToast("Clearing own stickers in world...", 2); }
StickerSystem.Instance.ClearStickersSelf(); else
} {
QuickMenuAPI.ShowAlertToast("Stickers are not allowed in this world!", 2);
private static void OnClearAllStickersButtonClick() }
{ }
if (!_isOurTabOpened) return;
QuickMenuAPI.ShowAlertToast("Clearing all stickers in world...", 2); private static void OnClearSelfStickersButtonClick()
StickerSystem.Instance.ClearAllStickers(); {
} if (!_isOurTabOpened) return;
QuickMenuAPI.ShowAlertToast("Clearing own stickers in world...", 2);
private static void OnOpenStickersFolderButtonClick() StickerSystem.Instance.ClearStickersSelf();
{ }
if (!_isOurTabOpened) return;
QuickMenuAPI.ShowAlertToast("Opening Stickers folder in Explorer...", 2); private static void OnClearAllStickersButtonClick()
StickerSystem.OpenStickersFolder(); {
} if (!_isOurTabOpened) return;
QuickMenuAPI.ShowAlertToast("Clearing all stickers in world...", 2);
#endregion Button Actions StickerSystem.Instance.ClearAllStickers();
}
private static void OnOpenStickersFolderButtonClick()
{
if (!_isOurTabOpened) return;
QuickMenuAPI.ShowAlertToast("Opening Stickers folder in Explorer...", 2);
StickerSystem.OpenStickersFolder();
}
public static void UpdateStickerMenu() //TODO: add Icon changing, Bono needs to expose the value first.
{
if (StickerSystem.RestrictedInstance == true)
{
_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";
}
else
{
_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
} }

View file

@ -1,107 +1,114 @@
using BTKUILib; using BTKUILib;
using BTKUILib.UIObjects; using BTKUILib.UIObjects;
using NAK.Stickers.Networking; using NAK.Stickers.Networking;
using NAK.Stickers.Utilities; using NAK.Stickers.Utilities;
using System.Reflection;
namespace NAK.Stickers.Integrations; using System.Runtime.InteropServices;
public static partial class BTKUIAddon namespace NAK.Stickers.Integrations;
{
private static Page _rootPage; public static partial class BTKUIAddon
private static string _rootPageElementID; {
private static Page _rootPage;
private static bool _isOurTabOpened; private static string _rootPageElementID;
public static void Initialize() private static bool _isOurTabOpened;
{
Setup_Icons(); public static void Initialize()
Setup_StickerModTab(); {
Setup_PlayerOptionsPage(); Setup_Icons();
} Setup_StickerModTab();
Setup_PlayerOptionsPage();
#region Setup }
private static void Setup_Icons() #region Setup
{
// All icons used - https://www.flaticon.com/authors/gohsantosadrive private static void Setup_Icons()
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")); // All icons used - https://www.flaticon.com/authors/gohsantosadrive
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-folder", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-folder.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-alphabet", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-alphabet.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-headset", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-headset.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-eraser", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-eraser.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magnifying-glass", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-magnifying-glass.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-folder", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-folder.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-magic-wand.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-headset", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-headset.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-mouse", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-mouse.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magnifying-glass", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-magnifying-glass.png"));
//QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-pencil", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-pencil.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-magic-wand.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-puzzle.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-magic-wand-broken", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-magic-wand-broken.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-rubbish-bin", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-rubbish-bin.png")); QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-mouse", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-mouse.png"));
} //QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-pencil", UIUtils.GetIconStream("Gohsantosadrive_Icons.Stickers-pencil.png"));
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-puzzle.png"));
private static void Setup_StickerModTab() QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-puzzle-disabled", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-puzzle-disabled.png")); //Disabled Sticker Puzzle
{ QuickMenuAPI.PrepareIcon(ModSettings.ModName, "Stickers-rubbish-bin", Assembly.GetExecutingAssembly().GetManifestResourceStream("Stickers.Resources.Gohsantosadrive_Icons.Stickers-rubbish-bin.png"));
_rootPage = new Page(ModSettings.ModName, ModSettings.SM_SettingsCategory, true, "Stickers-puzzle") }
{
MenuTitle = ModSettings.SM_SettingsCategory, private static void Setup_StickerModTab()
MenuSubtitle = "Stickers! Double-click the tab to quickly toggle Sticker Mode.", {
}; _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..
{
_rootPageElementID = _rootPage.ElementID; MenuTitle = ModSettings.SM_SettingsCategory,
MenuSubtitle = "", //Left this blank as it is defined when the world loads
QuickMenuAPI.OnTabChange += OnTabChange; };
ModNetwork.OnTextureOutboundStateChanged += (isSending) =>
{ _rootPageElementID = _rootPage.ElementID;
if (_isOurTabOpened && isSending) QuickMenuAPI.ShowAlertToast("Sending Sticker over Mod Network...", 2);
//_rootPage.Disabled = isSending; // TODO: fix being able to select stickers while sending QuickMenuAPI.OnTabChange += OnTabChange;
}; ModNetwork.OnTextureOutboundStateChanged += (isSending) =>
{
StickerSystem.OnStickerLoaded += (slotIndex, imageRelativePath) => if (_isOurTabOpened && isSending) QuickMenuAPI.ShowAlertToast("Sending Sticker over Mod Network...", 2);
{ //_rootPage.Disabled = isSending; // TODO: fix being able to select stickers while sending
if (_isOurTabOpened) QuickMenuAPI.ShowAlertToast($"Sticker loaded: {imageRelativePath}", 2); };
_stickerSelectionButtons[slotIndex].ButtonIcon = StickerCache.GetBtkUiIconName(imageRelativePath);
}; StickerSystem.OnStickerLoaded += (slotIndex, imageRelativePath) =>
{
StickerSystem.OnStickerLoadFailed += (slotIndex, error) => if (_isOurTabOpened) QuickMenuAPI.ShowAlertToast($"Sticker loaded: {imageRelativePath}", 2);
{ _stickerSelectionButtons[slotIndex].ButtonIcon = StickerCache.GetBtkUiIconName(imageRelativePath);
if (_isOurTabOpened) QuickMenuAPI.ShowAlertToast(error, 3); };
};
StickerSystem.OnStickerLoadFailed += (slotIndex, error) =>
Setup_StickersModCategory(); {
Setup_StickerSelectionCategory(); if (_isOurTabOpened) QuickMenuAPI.ShowAlertToast(error, 3);
Setup_OtherOptionsCategory(); };
}
Setup_StickersModCategory();
#endregion Setup Setup_StickerSelectionCategory();
Setup_OtherOptionsCategory();
#region Double-Click Place Sticker }
private static DateTime lastTime = DateTime.Now; #endregion Setup
private static void OnTabChange(string newTab, string previousTab) #region Double-Click Place Sticker
{
_isOurTabOpened = newTab == _rootPageElementID; private static DateTime lastTime = DateTime.Now;
if (!_isOurTabOpened) return;
private static void OnTabChange(string newTab, string previousTab)
TimeSpan timeDifference = DateTime.Now - lastTime; {
if (timeDifference.TotalSeconds <= 0.5) _isOurTabOpened = newTab == _rootPageElementID;
{ if (!_isOurTabOpened) return;
switch (ModSettings.Entry_TabDoubleClick.Value)
{ TimeSpan timeDifference = DateTime.Now - lastTime;
default: if (timeDifference.TotalSeconds <= 0.5)
case TabDoubleClick.ToggleStickerMode: {
OnPlaceStickersButtonClick(); switch (ModSettings.Entry_TabDoubleClick.Value)
break; {
case TabDoubleClick.ClearAllStickers: default:
OnClearAllStickersButtonClick(); case TabDoubleClick.ToggleStickerMode:
break; if (StickerSystem.RestrictedInstance == false)
case TabDoubleClick.ClearSelfStickers: {
OnClearSelfStickersButtonClick(); OnPlaceStickersButtonClick();
break; }
case TabDoubleClick.None: break;
break; case TabDoubleClick.ClearAllStickers:
} OnClearAllStickersButtonClick();
return; break;
} case TabDoubleClick.ClearSelfStickers:
lastTime = DateTime.Now; OnClearSelfStickersButtonClick();
} break;
case TabDoubleClick.None:
#endregion Double-Click Place Sticker break;
}
return;
}
lastTime = DateTime.Now;
}
#endregion Double-Click Place Sticker
} }