mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
further cleanup of repo
This commit is contained in:
parent
4f8dcb0cd0
commit
323eb92f2e
140 changed files with 1 additions and 2430 deletions
|
@ -0,0 +1,144 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
using NAK.OriginShift;
|
||||
|
||||
namespace NAK.OriginShiftMod.Integrations;
|
||||
|
||||
public static partial class BtkUiAddon
|
||||
{
|
||||
private static Category _ourCategory;
|
||||
|
||||
private static Button _ourMainButton;
|
||||
private static bool _isForcedMode;
|
||||
|
||||
private static ToggleButton _ourToggle;
|
||||
|
||||
private static void Setup_OriginShiftModCategory(Page page)
|
||||
{
|
||||
// dear category
|
||||
_ourCategory = page.AddCategory(ModSettings.OSM_SettingsCategory, ModSettings.ModName, true, true, false);
|
||||
|
||||
// the button
|
||||
_ourMainButton = _ourCategory.AddButton(string.Empty, string.Empty, string.Empty, ButtonStyle.TextWithIcon);
|
||||
_ourMainButton.OnPress += OnMainButtonClick;
|
||||
SetButtonState(OriginShiftManager.OriginShiftState.Inactive); // default state
|
||||
|
||||
// compatibility mode
|
||||
_ourToggle = _ourCategory.AddToggle(ModSettings.EntryCompatibilityMode.DisplayName,
|
||||
ModSettings.EntryCompatibilityMode.Description, ModSettings.EntryCompatibilityMode.Value);
|
||||
_ourToggle.OnValueUpdated += OnCompatibilityModeToggle;
|
||||
|
||||
// listen for state changes
|
||||
OriginShiftManager.OnStateChanged += OnOriginShiftStateChanged;
|
||||
|
||||
// debug toggle
|
||||
ToggleButton debugToggle = _ourCategory.AddToggle("Debug Overlay", "Displays coordinate & chunk debug information on the Desktop view.", false);
|
||||
debugToggle.OnValueUpdated += OnDebugToggle;
|
||||
}
|
||||
|
||||
#region Category Actions
|
||||
|
||||
private static void UpdateCategoryModUserCount()
|
||||
{
|
||||
int modUsers = 1; // we are always here :3
|
||||
int playerCount = CVRPlayerManager.Instance.NetworkPlayers.Count + 1; // +1 for us :3
|
||||
_ourCategory.CategoryName = $"{ModSettings.OSM_SettingsCategory} ({modUsers}/{playerCount})";
|
||||
}
|
||||
|
||||
#endregion Category Actions
|
||||
|
||||
#region Button Actions
|
||||
|
||||
private static void SetButtonState(OriginShiftManager.OriginShiftState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
default:
|
||||
case OriginShiftManager.OriginShiftState.Inactive:
|
||||
_ourMainButton.ButtonText = "Inactive";
|
||||
_ourMainButton.ButtonTooltip = "This world is not using Origin Shift.";
|
||||
_ourMainButton.ButtonIcon = "OriginShift-Icon-Inactive";
|
||||
break;
|
||||
case OriginShiftManager.OriginShiftState.Active:
|
||||
_ourMainButton.ButtonText = "Active";
|
||||
_ourMainButton.ButtonTooltip = "This world is currently using Origin Shift.";
|
||||
_ourMainButton.ButtonIcon = "OriginShift-Icon-Active";
|
||||
break;
|
||||
case OriginShiftManager.OriginShiftState.Forced:
|
||||
_ourMainButton.ButtonText = "Forced";
|
||||
_ourMainButton.ButtonTooltip = "You have forced Origin Shift for this world.";
|
||||
_ourMainButton.ButtonIcon = "OriginShift-Icon-Forced";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnMainButtonClick()
|
||||
{
|
||||
// if active, return as world is using Origin Shift
|
||||
if (OriginShiftManager.Instance.CurrentState
|
||||
is OriginShiftManager.OriginShiftState.Active)
|
||||
return;
|
||||
|
||||
if (_isForcedMode)
|
||||
{
|
||||
OriginShiftManager.Instance.ResetManager();
|
||||
}
|
||||
else
|
||||
{
|
||||
QuickMenuAPI.ShowConfirm("Force Origin Shift",
|
||||
"Are you sure you want to force Origin Shift for this world? " +
|
||||
"This is a highly experimental feature that may break the world in unexpected ways!",
|
||||
() =>
|
||||
{
|
||||
OriginShiftManager.Instance.ForceManager();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnOriginShiftStateChanged(OriginShiftManager.OriginShiftState state)
|
||||
{
|
||||
_isForcedMode = state == OriginShiftManager.OriginShiftState.Forced;
|
||||
SetButtonState(state);
|
||||
SetToggleLocked(_isForcedMode);
|
||||
}
|
||||
|
||||
#endregion Button Actions
|
||||
|
||||
#region Toggle Actions
|
||||
|
||||
private static void SetToggleLocked(bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
// lock the toggle
|
||||
_ourToggle.ToggleTooltip = "This setting is locked while Origin Shift is forced.";
|
||||
_ourToggle.ToggleValue = true;
|
||||
_ourToggle.Disabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// unlock the toggle
|
||||
_ourToggle.ToggleValue = ModSettings.EntryCompatibilityMode.Value;
|
||||
_ourToggle.ToggleTooltip = ModSettings.EntryCompatibilityMode.Description;
|
||||
_ourToggle.Disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnCompatibilityModeToggle(bool value)
|
||||
{
|
||||
ModSettings.EntryCompatibilityMode.Value = value;
|
||||
}
|
||||
|
||||
#endregion Toggle Actions
|
||||
|
||||
#region Debug Toggle Actions
|
||||
|
||||
private static void OnDebugToggle(bool value)
|
||||
{
|
||||
OriginShiftManager.Instance.ToggleDebugOverlay(value);
|
||||
}
|
||||
|
||||
#endregion Debug Toggle Actions
|
||||
}
|
65
.Experimental/OriginShift/Integrations/BTKUI/BtkuiAddon.cs
Normal file
65
.Experimental/OriginShift/Integrations/BTKUI/BtkuiAddon.cs
Normal file
|
@ -0,0 +1,65 @@
|
|||
using ABI_RC.Core.Player;
|
||||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using NAK.OriginShift;
|
||||
|
||||
namespace NAK.OriginShiftMod.Integrations;
|
||||
|
||||
public static partial class BtkUiAddon
|
||||
{
|
||||
private static Page _miscTabPage;
|
||||
private static string _miscTabElementID;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
Prepare_Icons();
|
||||
Setup_OriginShiftTab();
|
||||
}
|
||||
|
||||
#region Initialization
|
||||
|
||||
private static void Prepare_Icons()
|
||||
{
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "OriginShift-Icon-Active",
|
||||
GetIconStream("OriginShift-Icon-Active.png"));
|
||||
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "OriginShift-Icon-Inactive",
|
||||
GetIconStream("OriginShift-Icon-Inactive.png"));
|
||||
|
||||
QuickMenuAPI.PrepareIcon(ModSettings.ModName, "OriginShift-Icon-Forced",
|
||||
GetIconStream("OriginShift-Icon-Forced.png"));
|
||||
}
|
||||
|
||||
private static void Setup_OriginShiftTab()
|
||||
{
|
||||
_miscTabPage = QuickMenuAPI.MiscTabPage;
|
||||
_miscTabElementID = _miscTabPage.ElementID;
|
||||
QuickMenuAPI.UserJoin += OnUserJoinLeave;
|
||||
QuickMenuAPI.UserLeave += OnUserJoinLeave;
|
||||
QuickMenuAPI.OnWorldLeave += OnWorldLeave;
|
||||
|
||||
// // Origin Shift Mod
|
||||
Setup_OriginShiftModCategory(_miscTabPage);
|
||||
//
|
||||
// // Origin Shift Tool
|
||||
// Setup_OriginShiftToolCategory(_miscTabPage);
|
||||
//
|
||||
// // Universal Shifting Settings
|
||||
// Setup_UniversalShiftingSettings(_miscTabPage);
|
||||
//
|
||||
// // Debug Options
|
||||
// Setup_DebugOptionsCategory(_miscTabPage);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Player Count Display
|
||||
|
||||
private static void OnWorldLeave()
|
||||
=> UpdateCategoryModUserCount();
|
||||
|
||||
private static void OnUserJoinLeave(CVRPlayerEntity _)
|
||||
=> UpdateCategoryModUserCount();
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
using System.Reflection;
|
||||
using BTKUILib;
|
||||
using BTKUILib.UIObjects;
|
||||
using BTKUILib.UIObjects.Components;
|
||||
using MelonLoader;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NAK.OriginShiftMod.Integrations;
|
||||
|
||||
public static partial class BtkUiAddon
|
||||
{
|
||||
#region Melon Preference Helpers
|
||||
|
||||
private static ToggleButton AddMelonToggle(ref Category category, MelonPreferences_Entry<bool> entry)
|
||||
{
|
||||
ToggleButton toggle = category.AddToggle(entry.DisplayName, entry.Description, entry.Value);
|
||||
toggle.OnValueUpdated += b => entry.Value = b;
|
||||
return toggle;
|
||||
}
|
||||
|
||||
private static SliderFloat AddMelonSlider(ref 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;
|
||||
}
|
||||
|
||||
private static Button AddMelonStringInput(ref 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;
|
||||
}
|
||||
|
||||
private static Button AddMelonNumberInput(ref 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;
|
||||
}
|
||||
|
||||
private static Category AddMelonCategory(ref 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;
|
||||
return category;
|
||||
}
|
||||
|
||||
#endregion Melon Preference Helpers
|
||||
|
||||
#region Icon Utils
|
||||
|
||||
private static Stream GetIconStream(string iconName)
|
||||
{
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
string assemblyName = assembly.GetName().Name;
|
||||
return assembly.GetManifestResourceStream($"{assemblyName}.Resources.{iconName}");
|
||||
}
|
||||
|
||||
#endregion Icon Utils
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue