diff --git a/BoneMenu/BoneMenu.cs b/BoneMenu/BoneMenu.cs index 50e41d7..9eb9197 100644 --- a/BoneMenu/BoneMenu.cs +++ b/BoneMenu/BoneMenu.cs @@ -1,4 +1,5 @@ -using OBSWebsocketDotNet.Types.Events; +using System.Linq; +using OBSWebsocketDotNet.Types.Events; using UnityEngine.Diagnostics; using WeatherElectric.OBSControl.Handlers; @@ -13,7 +14,7 @@ internal static class BoneMenu private static FunctionElement _replayButton; private static SubPanelElement _scenesPanel; - private static readonly Dictionary SceneButtons = []; + private static readonly List SceneButtons = []; public static void SetupBaseMenu() @@ -48,9 +49,11 @@ private static void SetupObsControls() { case true: ObsBridge.StopRecording(); + NotificationHandler.SendNotif(NotificationHandler.RecordingStopped); break; case false: ObsBridge.StartRecording(); + NotificationHandler.SendNotif(NotificationHandler.RecordingStarted); break; } }); @@ -61,9 +64,11 @@ private static void SetupObsControls() { case true: ObsBridge.ResumeRecording(); + NotificationHandler.SendNotif(NotificationHandler.RecordingResumed); break; case false: ObsBridge.PauseRecording(); + NotificationHandler.SendNotif(NotificationHandler.RecordingPaused); break; } }); @@ -80,9 +85,11 @@ private static void SetupObsControls() { case true: ObsBridge.StopStreaming(); + NotificationHandler.SendNotif(NotificationHandler.StreamStopped); break; case false: ObsBridge.StartStreaming(); + NotificationHandler.SendNotif(NotificationHandler.StreamStarted); break; } }); @@ -99,14 +106,20 @@ private static void SetupObsControls() { case true: ObsBridge.StopReplayBuffer(); + NotificationHandler.SendNotif(NotificationHandler.ReplayBufferStopped); break; case false: ObsBridge.StartReplayBuffer(); + NotificationHandler.SendNotif(NotificationHandler.ReplayBufferStarted); break; } }); SetReplayButton(ObsBridge.IsReplayBufferActive()); - replayPanel.CreateFunctionElement("Save Replay", Color.blue, ObsBridge.SaveReplayBuffer); + replayPanel.CreateFunctionElement("Save Replay", Color.blue, () => + { + ObsBridge.SaveReplayBuffer(); + NotificationHandler.SendNotif(NotificationHandler.ReplaySaved); + }); #endregion @@ -114,13 +127,16 @@ private static void SetupObsControls() _scenesPanel = _subCat.CreateSubPanel("Scenes", Color.red); var scenes = ObsBridge.GetScenes(); + // ReSharper disable once ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator foreach (var scene in scenes) { var func= _scenesPanel.CreateFunctionElement(scene.Name, Color.white, () => { ObsBridge.SetScene(scene.Name); + NotificationHandler.SceneChanged.Message = $"Scene changed to {scene.Name}"; + NotificationHandler.SendNotif(NotificationHandler.SceneChanged); }); - SceneButtons.Add(scene.Name, func); + SceneButtons.Add(func); } #endregion @@ -129,7 +145,6 @@ private static void SetupObsControls() SubPanelElement settingsPanel = _subCat.CreateSubPanel("Settings", Color.gray); settingsPanel.CreateBoolPreference("Show Notifications", Color.white, Preferences.ShowNotifications, Preferences.OwnCategory); - settingsPanel.CreateEnumPreference("Replay Control Mode", Color.white, Preferences.ReplayControlMode, Preferences.OwnCategory); settingsPanel.CreateEnumPreference("Replay Control Hand", Color.white, Preferences.ReplayControlHand, Preferences.OwnCategory); settingsPanel.CreateFloatPreference("Double Tap Time", Color.white, 0.1f, 0.1f, 1f, Preferences.DoubleTapTime, Preferences.OwnCategory); @@ -145,31 +160,21 @@ private static void ConnectHooks() ObsBridge.OnReplayBufferStateChanged += ReplayStatusChanged; ObsBridge.OnSceneCreated += SceneCreated; ObsBridge.OnSceneRemoved += SceneDeleted; - ObsBridge.OnReplayBufferSaved += ReplaySaved; } private static void RecordStatusChanged(object sender, RecordStateChangedEventArgs e) { SetRecordButton(e.OutputState.IsActive); - NotificationHandler.SendNotif(e.OutputState.IsActive - ? NotificationHandler.RecordingStarted - : NotificationHandler.RecordingStopped); } private static void StreamStatusChanged(object sender, StreamStateChangedEventArgs e) { SetStreamButton(e.OutputState.IsActive); - NotificationHandler.SendNotif(e.OutputState.IsActive - ? NotificationHandler.StreamStarted - : NotificationHandler.StreamStopped); } private static void ReplayStatusChanged(object sender, ReplayBufferStateChangedEventArgs e) { SetReplayButton(e.OutputState.IsActive); - NotificationHandler.SendNotif(e.OutputState.IsActive - ? NotificationHandler.ReplayBufferStarted - : NotificationHandler.ReplayBufferStopped); } private static void SceneCreated(object sender, SceneCreatedEventArgs e) @@ -178,18 +183,17 @@ private static void SceneCreated(object sender, SceneCreatedEventArgs e) { ObsBridge.SetScene(e.SceneName); }); - SceneButtons.Add(e.SceneName, func); + SceneButtons.Add(func); } private static void SceneDeleted(object sender, SceneRemovedEventArgs e) { - _scenesPanel.RemoveElement(SceneButtons[e.SceneName]); - SceneButtons.Remove(e.SceneName); - } - - private static void ReplaySaved(object sender, ReplayBufferSavedEventArgs e) - { - NotificationHandler.SendNotif(NotificationHandler.ReplaySaved); + foreach (var button in SceneButtons.Where(button => button.Name == e.SceneName)) + { + _scenesPanel.RemoveElement(button); + SceneButtons.Remove(button); + break; + } } private static void SetRecordButton(bool isRecording) diff --git a/Handlers/ControlHandler.cs b/Handlers/ControlHandler.cs index bb322f8..01f4f5f 100644 --- a/Handlers/ControlHandler.cs +++ b/Handlers/ControlHandler.cs @@ -1,3 +1,5 @@ +using WeatherElectric.OBSControl.Handlers; + namespace WeatherElectric.OBSControl; internal static class ControlHandler @@ -6,112 +8,6 @@ internal static class ControlHandler private static float _doubleTapTimer; public static void Update() - { - switch (Preferences.ReplayControlMode.Value) - { - case ControlMode.Touchpad: - Touchpad(); - break; - case ControlMode.MenuButton: - MenuButton(); - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - private static void Touchpad() - { - switch (Preferences.ReplayControlHand.Value) - { - case ControlHand.Left: - HandleLeft(); - break; - case ControlHand.Right: - HandleRight(); - break; - case ControlHand.Both: - HandleBoth(); - break; - default: - throw new ArgumentOutOfRangeException(); - } - - - if (_isFirstTap) - { - _doubleTapTimer += Time.deltaTime; - - if (_doubleTapTimer > Preferences.DoubleTapTime.Value) - { - _isFirstTap = false; - } - } - - return; - - void HandleBoth() - { - if (Player.rightController._touchPad || Player.leftController._touchPad) - { - if (!_isFirstTap) - { - _isFirstTap = true; - _doubleTapTimer = 0; - } - else - { - if (_doubleTapTimer < Preferences.DoubleTapTime.Value) - { - ObsBridge.SaveReplayBuffer(); - _isFirstTap = false; - } - } - } - } - - void HandleLeft() - { - if (Player.leftController._touchPad) - { - if (!_isFirstTap) - { - _isFirstTap = true; - _doubleTapTimer = 0; - } - else - { - if (_doubleTapTimer < Preferences.DoubleTapTime.Value) - { - ObsBridge.SaveReplayBuffer(); - _isFirstTap = false; - } - } - } - } - - void HandleRight() - { - if (Player.rightController._touchPad) - { - if (!_isFirstTap) - { - _isFirstTap = true; - _doubleTapTimer = 0; - } - else - { - if (_doubleTapTimer < Preferences.DoubleTapTime.Value) - { - ObsBridge.SaveReplayBuffer(); - _isFirstTap = false; - } - } - } - } - } - - private static void MenuButton() { switch (Preferences.ReplayControlHand.Value) { @@ -154,6 +50,7 @@ void HandleBoth() if (_doubleTapTimer < Preferences.DoubleTapTime.Value) { ObsBridge.SaveReplayBuffer(); + NotificationHandler.SendNotif(NotificationHandler.ReplaySaved); _isFirstTap = false; } } @@ -174,6 +71,7 @@ void HandleLeft() if (_doubleTapTimer < Preferences.DoubleTapTime.Value) { ObsBridge.SaveReplayBuffer(); + NotificationHandler.SendNotif(NotificationHandler.ReplaySaved); _isFirstTap = false; } } @@ -194,6 +92,7 @@ void HandleRight() if (_doubleTapTimer < Preferences.DoubleTapTime.Value) { ObsBridge.SaveReplayBuffer(); + NotificationHandler.SendNotif(NotificationHandler.ReplaySaved); _isFirstTap = false; } } diff --git a/Handlers/NotificationHandler.cs b/Handlers/NotificationHandler.cs index bd5f657..48cfcb7 100644 --- a/Handlers/NotificationHandler.cs +++ b/Handlers/NotificationHandler.cs @@ -14,6 +14,15 @@ public static void SendNotif(Notification notification) #region Notifications + public static Notification SceneChanged { get; } = new() + { + Title = "Scene Changed", + Message = "Scene has been changed.", + Type = NotificationType.Information, + PopupLength = 1f, + ShowTitleOnPopup = true + }; + public static Notification RecordingStarted { get; } = new() { Title = "Recording Started", diff --git a/Melon/Preferences.cs b/Melon/Preferences.cs index 8ebaaeb..3c669bf 100644 --- a/Melon/Preferences.cs +++ b/Melon/Preferences.cs @@ -11,7 +11,6 @@ internal static class Preferences public static MelonPreferences_Entry ShowNotifications { get; set; } public static MelonPreferences_Entry WebsocketURL { get; set; } public static MelonPreferences_Entry WebsocketPassword { get; set; } - public static MelonPreferences_Entry ReplayControlMode { get; set; } public static MelonPreferences_Entry ReplayControlHand { get; set; } public static MelonPreferences_Entry DoubleTapTime { get; set; } @@ -25,7 +24,6 @@ public static void Setup() ShowNotifications = OwnCategory.CreateEntry("ShowNotifications", true, "Show Notifications", "Whether to show notifications when OBS events occur."); WebsocketURL = OwnCategory.CreateEntry("WebsocketURL", "ws://127.0.0.1:4455", "Websocket URL", "The URL to use for the websocket connection. Usually don't have to change this."); WebsocketPassword = OwnCategory.CreateEntry("WebsocketPassword", "REPLACEME", "Websocket Password", "The password to use for the websocket connection. Change this to the password you set in OBS."); - ReplayControlMode = OwnCategory.CreateEntry("ReplayControlMode", ControlMode.Touchpad, "Replay Control Mode", "The mode to use for saving replays. Touchpad = Use the touchpad, MenuButton = Use the menu button."); ReplayControlHand = OwnCategory.CreateEntry("ReplayControlHand", ControlHand.Right, "Replay Control Hand", "The hand to use for saving replays. Left = Left hand, Right = Right hand, Both = Both hands."); DoubleTapTime = OwnCategory.CreateEntry("DoubleTapTime", 0.3f, "Double Tap Time", "The time to wait between taps to trigger saving a replay."); OwnCategory.SetFilePath(MelonUtils.UserDataDirectory + "/WeatherElectric.cfg"); @@ -34,12 +32,6 @@ public static void Setup() } } -internal enum ControlMode -{ - Touchpad, - MenuButton -} - internal enum ControlHand { Left, diff --git a/README.md b/README.md index 3831d52..a4ae304 100644 --- a/README.md +++ b/README.md @@ -29,5 +29,5 @@ Allows you to control OBS from within BONELAB. 4. Make sure that the URL ends with the port number that OBS shows 5. Save the file ### In-Game Usage -* Double tap the touchpad or the menu button to save a replay. The button used to save replays can be configured. +* Double tap the menu button to save a replay. The hand it listens for can be configured. * BoneMenu has most of the controls. \ No newline at end of file