Skip to content

Commit

Permalink
Removed touchpad control mode because it doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
FragileDeviations committed May 22, 2024
1 parent 2eceb90 commit e972d05
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 138 deletions.
50 changes: 27 additions & 23 deletions BoneMenu/BoneMenu.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OBSWebsocketDotNet.Types.Events;
using System.Linq;
using OBSWebsocketDotNet.Types.Events;
using UnityEngine.Diagnostics;
using WeatherElectric.OBSControl.Handlers;

Expand All @@ -13,7 +14,7 @@ internal static class BoneMenu
private static FunctionElement _replayButton;

private static SubPanelElement _scenesPanel;
private static readonly Dictionary<string, FunctionElement> SceneButtons = [];
private static readonly List<FunctionElement> SceneButtons = [];


public static void SetupBaseMenu()
Expand Down Expand Up @@ -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;
}
});
Expand All @@ -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;
}
});
Expand All @@ -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;
}
});
Expand All @@ -99,28 +106,37 @@ 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

#region Scenes

_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
Expand All @@ -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);

Expand All @@ -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)
Expand All @@ -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)
Expand Down
111 changes: 5 additions & 106 deletions Handlers/ControlHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using WeatherElectric.OBSControl.Handlers;

namespace WeatherElectric.OBSControl;

internal static class ControlHandler
Expand All @@ -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)
{
Expand Down Expand Up @@ -154,6 +50,7 @@ void HandleBoth()
if (_doubleTapTimer < Preferences.DoubleTapTime.Value)
{
ObsBridge.SaveReplayBuffer();
NotificationHandler.SendNotif(NotificationHandler.ReplaySaved);
_isFirstTap = false;
}
}
Expand All @@ -174,6 +71,7 @@ void HandleLeft()
if (_doubleTapTimer < Preferences.DoubleTapTime.Value)
{
ObsBridge.SaveReplayBuffer();
NotificationHandler.SendNotif(NotificationHandler.ReplaySaved);
_isFirstTap = false;
}
}
Expand All @@ -194,6 +92,7 @@ void HandleRight()
if (_doubleTapTimer < Preferences.DoubleTapTime.Value)
{
ObsBridge.SaveReplayBuffer();
NotificationHandler.SendNotif(NotificationHandler.ReplaySaved);
_isFirstTap = false;
}
}
Expand Down
9 changes: 9 additions & 0 deletions Handlers/NotificationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 0 additions & 8 deletions Melon/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ internal static class Preferences
public static MelonPreferences_Entry<bool> ShowNotifications { get; set; }
public static MelonPreferences_Entry<string> WebsocketURL { get; set; }
public static MelonPreferences_Entry<string> WebsocketPassword { get; set; }
public static MelonPreferences_Entry<ControlMode> ReplayControlMode { get; set; }
public static MelonPreferences_Entry<ControlHand> ReplayControlHand { get; set; }
public static MelonPreferences_Entry<float> DoubleTapTime { get; set; }

Expand All @@ -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");
Expand All @@ -34,12 +32,6 @@ public static void Setup()
}
}

internal enum ControlMode
{
Touchpad,
MenuButton
}

internal enum ControlHand
{
Left,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit e972d05

Please sign in to comment.