small polish tweaks, update to melon 5.5

This commit is contained in:
NotAKidoS 2022-10-14 14:00:04 -05:00
parent 329b3bcbdf
commit 35bcc74e3b
5 changed files with 60 additions and 58 deletions

View file

@ -2,6 +2,7 @@
using ABI_RC.Core.Savior;
using ABI_RC.Core.UI;
using MelonLoader;
using System.Text;
using UnityEngine;
namespace Blackout;
@ -78,17 +79,17 @@ public class BlackoutController : MonoBehaviour
case BlackoutState.Awake:
blackoutAnimator.SetBool("BlackoutState.Drowsy", false);
blackoutAnimator.SetBool("BlackoutState.Sleeping", false);
blackoutAnimator.SetFloat("BlackoutSetting.DrowsyPartial", DrowsyDimStrength);
blackoutAnimator.SetFloat("BlackoutSetting.DrowsyStrength", DrowsyDimStrength);
break;
case BlackoutState.Drowsy:
blackoutAnimator.SetBool("BlackoutState.Drowsy", true);
blackoutAnimator.SetBool("BlackoutState.Sleeping", false);
blackoutAnimator.SetFloat("BlackoutSetting.DrowsyPartial", DrowsyDimStrength);
blackoutAnimator.SetFloat("BlackoutSetting.DrowsyStrength", DrowsyDimStrength);
break;
case BlackoutState.Sleeping:
blackoutAnimator.SetBool("BlackoutState.Drowsy", false);
blackoutAnimator.SetBool("BlackoutState.Sleeping", true);
blackoutAnimator.SetFloat("BlackoutSetting.DrowsyPartial", DrowsyDimStrength);
blackoutAnimator.SetFloat("BlackoutSetting.DrowsyStrength", DrowsyDimStrength);
break;
default:
break;
@ -99,6 +100,22 @@ public class BlackoutController : MonoBehaviour
ChangeTargetFPS();
}
//initialize BlackoutInstance object
void Start()
{
Instance = this;
GameObject blackoutAsset = AssetsHandler.GetAsset("Assets/BundledAssets/Blackout/Blackout.prefab");
GameObject blackoutGO = Instantiate(blackoutAsset, new Vector3(0, 0, 0), Quaternion.identity);
if (blackoutGO == null) return;
blackoutGO.name = "BlackoutInstance";
blackoutAnimator = blackoutGO.GetComponent<Animator>();
SetupBlackoutInstance();
}
//Automatic State Change
void Update()
{
//only run once a second, angularMovement is "smoothed out" at high FPS otherwise
@ -127,28 +144,6 @@ public class BlackoutController : MonoBehaviour
default:
break;
}
//debug
//MelonLogger.Msg("curTime " + curTime);
//MelonLogger.Msg("lastAwakeTime " + lastAwakeTime);
//MelonLogger.Msg("timeleft " + GetNextStateTimer());
//MelonLogger.Msg("current state " + CurrentState);
}
//initialize BlackoutInstance object
void Start()
{
Instance = this;
GameObject blackoutAsset = AssetsHandler.GetAsset("Assets/BundledAssets/Blackout/Blackout.prefab");
GameObject blackoutGO = Instantiate(blackoutAsset, new Vector3(0, 0, 0), Quaternion.identity);
if (blackoutGO != null)
{
blackoutGO.name = "BlackoutInstance";
blackoutAnimator = blackoutGO.GetComponent<Animator>();
SetupBlackoutInstance();
}
}
void OnEnable()
@ -190,7 +185,12 @@ public class BlackoutController : MonoBehaviour
{
MelonLogger.Msg(message);
if (!CohtmlHud.Instance || !HudMessages) return;
CohtmlHud.Instance.ViewDropTextImmediate("Blackout", message, GetNextStateTimer().ToString() + " seconds till next state change.");
StringBuilder secondmessage = new StringBuilder();
if (enabled)
secondmessage = new StringBuilder(GetNextStateTimer().ToString() + " seconds till next state change.");
CohtmlHud.Instance.ViewDropTextImmediate("Blackout", message, secondmessage.ToString());
}
private void ChangeTargetFPS()

View file

@ -14,6 +14,7 @@ internal class HarmonyPatches
if (Blackout.inVR != PlayerSetup.Instance._inVr)
{
BlackoutController.Instance.SetupBlackoutInstance();
BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Awake);
}
}
}

View file

@ -1,23 +1,21 @@
using ABI_RC.Core.Player;
using MelonLoader;
using UnityEngine;
namespace Blackout;
public class Blackout : MelonMod
{
public const string SettingsCategory = "Blackout";
internal static bool inVR;
internal static MelonPreferences_Category m_categoryBlackout;
internal static MelonPreferences_Entry<bool> m_entryEnabled, m_entryHudMessages, m_entryDropFPSOnSleep;
//internal static MelonPreferences_Entry<bool> m_entryVROnly;
internal static MelonPreferences_Entry<float>
internal const string SettingsCategory = "Blackout";
private static MelonPreferences_Category m_categoryBlackout;
private static MelonPreferences_Entry<bool> m_entryEnabled, m_entryHudMessages, m_entryDropFPSOnSleep;
private static MelonPreferences_Entry<float>
m_entryDrowsyThreshold, m_entryAwakeThreshold,
m_entryDrowsyModeTimer, m_entrySleepModeTimer,
m_entryDrowsyDimStrength;
public override void OnApplicationStart()
public override void OnInitializeMelon()
{
m_categoryBlackout = MelonPreferences.CreateCategory(nameof(Blackout));
m_entryEnabled = m_categoryBlackout.CreateEntry<bool>("Automatic State Change", true, description: "Dim screen when there is no movement for a while.");
@ -28,29 +26,25 @@ public class Blackout : MelonMod
m_entryDrowsyModeTimer = m_categoryBlackout.CreateEntry<float>("Enter Drowsy Time", 3f, description: "How many minutes without movement until enter drowsy mode.");
m_entrySleepModeTimer = m_categoryBlackout.CreateEntry<float>("Enter Sleep Time", 10f, description: "How many seconds without movement until enter sleep mode.");
m_entryDrowsyDimStrength = m_categoryBlackout.CreateEntry<float>("Drowsy Dim Strength", 0.5f, description: "How strong of a dimming effect should drowsy mode have.");
//m_entryVROnly = m_categoryBlackout.CreateEntry<bool>("VR Only", false, description: "Only enable mod in VR.");
m_categoryBlackout.SaveToFile(false);
//please tell me a better way to do this
//this is fucking
//gross pleas etell me how to do this but not like this
m_entryEnabled.OnValueChangedUntyped += OnEnabled;
m_entryHudMessages.OnValueChangedUntyped += OnUpdateSettings;
m_entryDropFPSOnSleep.OnValueChangedUntyped += OnUpdateSettings;
m_entryDrowsyThreshold.OnValueChangedUntyped += OnUpdateSettings;
m_entryAwakeThreshold.OnValueChangedUntyped += OnUpdateSettings;
m_entryDrowsyModeTimer.OnValueChangedUntyped += OnUpdateSettings;
m_entrySleepModeTimer.OnValueChangedUntyped += OnUpdateSettings;
m_entryDrowsyDimStrength.OnValueChangedUntyped += OnUpdateSettings;
//m_entryVROnly.OnValueChangedUntyped += OnUpdateSettings;
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
m_entryEnabled.OnEntryValueChangedUntyped.Subscribe(OnUpdateEnabled);
m_entryHudMessages.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
m_entryDropFPSOnSleep.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
m_entryDrowsyThreshold.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
m_entryAwakeThreshold.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
m_entryDrowsyModeTimer.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
m_entrySleepModeTimer.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
m_entryDrowsyDimStrength.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings);
//UIExpansionKit addon
if (MelonHandler.Mods.Any(it => it.Info.Name == "UI Expansion Kit"))
if (MelonMod.RegisteredMelons.Any(it => it.Info.Name == "UI Expansion Kit"))
{
MelonLogger.Msg("Initializing UIExpansionKit support.");
UiExtensionsAddon.Init();
}
MelonLoader.MelonCoroutines.Start(WaitForLocalPlayer());
}
System.Collections.IEnumerator WaitForLocalPlayer()
@ -65,8 +59,10 @@ public class Blackout : MelonMod
PlayerSetup.Instance.gameObject.AddComponent<BlackoutController>();
//update BlackoutController settings after it initializes
yield return new WaitForEndOfFrame();
OnUpdateSettings();
while (BlackoutController.Instance == null)
yield return null;
UpdateAllSettings();
}
private void OnEnabled()
@ -74,20 +70,25 @@ public class Blackout : MelonMod
if (!BlackoutController.Instance) return;
BlackoutController.Instance.enabled = m_entryEnabled.Value;
}
private void OnUpdateSettings()
private void UpdateAllSettings()
{
if (!BlackoutController.Instance) return;
BlackoutController.Instance.enabled = m_entryEnabled.Value;
BlackoutController.Instance.HudMessages = m_entryHudMessages.Value;
BlackoutController.Instance.DropFPSOnSleep = m_entryDropFPSOnSleep.Value;
BlackoutController.Instance.drowsyThreshold = m_entryDrowsyThreshold.Value;
BlackoutController.Instance.wakeThreshold = m_entryAwakeThreshold.Value;
BlackoutController.Instance.DrowsyModeTimer = m_entryDrowsyModeTimer.Value;
BlackoutController.Instance.SleepModeTimer = m_entrySleepModeTimer.Value;
BlackoutController.Instance.DrowsyDimStrength = m_entryDrowsyDimStrength.Value;
BlackoutController.Instance.HudMessages = m_entryHudMessages.Value;
BlackoutController.Instance.DropFPSOnSleep = m_entryDropFPSOnSleep.Value;
}
private void OnUpdateEnabled(object arg1, object arg2) => OnEnabled();
private void OnUpdateSettings(object arg1, object arg2) => UpdateAllSettings();
//UIExpansionKit actions
public static void AwakeState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Awake);
public static void DrowsyState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Drowsy);
public static void SleepingState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Sleeping);
internal static void AwakeState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Awake);
internal static void DrowsyState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Drowsy);
internal static void SleepingState() => BlackoutController.Instance.ChangeBlackoutState(BlackoutController.BlackoutState.Sleeping);
}

View file

@ -25,6 +25,6 @@ using System.Reflection;
namespace Blackout.Properties;
internal static class AssemblyInfoParams
{
public const string Version = "1.0.0";
public const string Version = "1.0.1";
public const string Author = "NotAKidoS";
}