Support for new separated blinking mod (2025r180 nightly)

This commit is contained in:
SDraw 2025-05-23 20:56:32 +03:00
parent a72af43f69
commit 6d3071f32c
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
6 changed files with 210 additions and 34 deletions

View file

@ -16,15 +16,21 @@ namespace ml_vet
enum ModSetting
{
Enabled = 0
Enabled = 0,
Smoothing,
Debug
}
public static bool Enabled { get; private set; } = false;
public static bool Enabled { get; private set; } = true;
public static float Smoothing { get; private set; } = 0f;
public static bool Debug { get; private set; } = false;
static MelonLoader.MelonPreferences_Category ms_category = null;
static List<MelonLoader.MelonPreferences_Entry> ms_entries = null;
public static readonly SettingEvent<bool> OnEnabledChanged = new SettingEvent<bool>();
public static readonly SettingEvent<float> OnSmoothingChanged = new SettingEvent<float>();
public static readonly SettingEvent<bool> OnDebugChanged = new SettingEvent<bool>();
internal static void Init()
{
@ -33,9 +39,13 @@ namespace ml_vet
ms_entries = new List<MelonLoader.MelonPreferences_Entry>()
{
ms_category.CreateEntry(ModSetting.Enabled.ToString(), Enabled),
ms_category.CreateEntry(ModSetting.Smoothing.ToString(), (int)(Smoothing * 100f)),
ms_category.CreateEntry(ModSetting.Debug.ToString(), Debug),
};
Enabled = (bool)ms_entries[(int)ModSetting.Enabled].BoxedValue;
Smoothing = ((int)ms_entries[(int)ModSetting.Smoothing].BoxedValue) * 0.01f;
Debug = (bool)ms_entries[(int)ModSetting.Debug].BoxedValue;
MelonLoader.MelonCoroutines.Start(WaitMainMenuUi());
}
@ -52,6 +62,7 @@ namespace ml_vet
ViewManager.Instance.gameMenuView.Listener.ReadyForBindings += () =>
{
ViewManager.Instance.gameMenuView.View.BindCall("OnToggleUpdate_" + ms_category.Identifier, new Action<string, string>(OnToggleUpdate));
ViewManager.Instance.gameMenuView.View.BindCall("OnSliderUpdate_" + ms_category.Identifier, new Action<string, string>(OnSliderUpdate));
};
ViewManager.Instance.gameMenuView.Listener.FinishLoad += (_) =>
{
@ -59,9 +70,19 @@ namespace ml_vet
ViewManager.Instance.gameMenuView.View.ExecuteScript(ResourcesHandler.GetEmbeddedResource("mod_menu.js"));
foreach(var l_entry in ms_entries)
ViewManager.Instance.gameMenuView.View.TriggerEvent("updateModSetting", ms_category.Identifier, l_entry.DisplayName, l_entry.GetValueAsString());
MelonLoader.MelonCoroutines.Start(UpdateMenuSettings());
};
}
static System.Collections.IEnumerator UpdateMenuSettings()
{
yield return new UnityEngine.WaitForEndOfFrame();
foreach(var l_entry in ms_entries)
ViewManager.Instance.gameMenuView.View.TriggerEvent("updateModSetting", ms_category.Identifier, l_entry.DisplayName, l_entry.GetValueAsString());
}
static void OnToggleUpdate(string p_name, string p_value)
{
try
@ -76,6 +97,37 @@ namespace ml_vet
OnEnabledChanged.Invoke(Enabled);
}
break;
case ModSetting.Debug:
{
Debug = l_value;
OnDebugChanged.Invoke(Debug);
} break;
}
ms_entries[(int)l_setting].BoxedValue = l_value;
}
}
catch(Exception e)
{
MelonLoader.MelonLogger.Error(e);
}
}
static void OnSliderUpdate(string p_name, string p_value)
{
try
{
if(Enum.TryParse(p_name, out ModSetting l_setting) && int.TryParse(p_value, out int l_value))
{
switch(l_setting)
{
case ModSetting.Smoothing:
{
Smoothing = l_value * 0.01f;
OnSmoothingChanged.Invoke(Smoothing);
}
break;
}
ms_entries[(int)l_setting].BoxedValue = l_value;