From a13fcfae2d7c693c0cc21c96725cf16363f45128 Mon Sep 17 00:00:00 2001 From: BoiHanny Date: Thu, 2 May 2024 16:38:45 +0200 Subject: [PATCH 01/39] Added MediaLinkTimeSeekbar enum and updated UI This commit introduces the `MediaLinkTimeSeekbar` enum in `MediaLinkModule.cs` to allow different styles for the media link time seek bar. The `MediaLinkShowTime` property in `ViewModel.cs` was replaced with `MediaLinkTimeSeekStyle` to reflect this change. A new property `AvailableTimeSeekbarStyles` was also added to `ViewModel.cs` to get all possible values of the new enum. The dictionary key in `DataController.cs` and the condition in `OSCController.cs` were updated accordingly. Two new methods `CreateTimeStamp()` and `CreateProgressBar()` were added to `OSCController.cs` to create a timestamp and a progress bar based on the `MediaLinkTimeSeekStyle` property. The UI in `MainWindow.xaml` was updated to replace the checkbox with a combo box for `MediaLinkTimeSeekStyle`, and minor adjustments were made to the width and margin of various UI elements. --- .../Classes/DataAndSecurity/DataController.cs | 5 +- .../Classes/DataAndSecurity/OSCController.cs | 46 +++++++++++++++++- .../Classes/Modules/MediaLinkModule.cs | 12 +++++ vrcosc-magicchatbox/MainWindow.xaml | 48 +++++++++++-------- vrcosc-magicchatbox/ViewModels/ViewModel.cs | 20 ++++++-- 5 files changed, 103 insertions(+), 28 deletions(-) diff --git a/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs b/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs index 6b5d69a0..7cb10c4d 100644 --- a/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs +++ b/vrcosc-magicchatbox/Classes/DataAndSecurity/DataController.cs @@ -16,6 +16,7 @@ using vrcosc_magicchatbox.Classes.Modules; using vrcosc_magicchatbox.ViewModels; using vrcosc_magicchatbox.ViewModels.Models; +using static vrcosc_magicchatbox.Classes.Modules.MediaLinkModule; using Version = vrcosc_magicchatbox.ViewModels.Models.Version; namespace vrcosc_magicchatbox.DataAndSecurity @@ -168,6 +169,8 @@ private static object ConvertToType(Type targetType, string value) return double.Parse(value); case Type t when t == typeof(Timezone): return Enum.Parse(typeof(Timezone), value); + case Type t when t == typeof(MediaLinkTimeSeekbar): + return Enum.Parse(typeof(MediaLinkTimeSeekbar), value); case Type t when t == typeof(DateTime): return DateTime.Parse(value); default: @@ -288,7 +291,7 @@ public static void LoadComponentStats() { "MediaSession_AutoSwitchSpawn", (typeof(bool), "MediaLink") }, { "MediaSession_AutoSwitch", (typeof(bool), "MediaLink") }, { "DisableMediaLink", (typeof(bool), "MediaLink") }, - { "MediaLinkShowTime", (typeof(bool), "MediaLink") }, + { "MediaLinkTimeSeekStyle", (typeof(MediaLinkTimeSeekbar), "MediaLink") }, { "ScanningInterval", (typeof(double), "Scanning") }, { "ScanPauseTimeout", (typeof(int), "Scanning") }, diff --git a/vrcosc-magicchatbox/Classes/DataAndSecurity/OSCController.cs b/vrcosc-magicchatbox/Classes/DataAndSecurity/OSCController.cs index 2b24b248..8fad7a96 100644 --- a/vrcosc-magicchatbox/Classes/DataAndSecurity/OSCController.cs +++ b/vrcosc-magicchatbox/Classes/DataAndSecurity/OSCController.cs @@ -4,9 +4,12 @@ using System.Globalization; using System.Linq; using System.Text; +using vrcosc_magicchatbox.Classes.Modules; using vrcosc_magicchatbox.DataAndSecurity; using vrcosc_magicchatbox.ViewModels; using vrcosc_magicchatbox.ViewModels.Models; +using static vrcosc_magicchatbox.Classes.Modules.MediaLinkModule; +using static WindowsMediaController.MediaManager; namespace vrcosc_magicchatbox.Classes.DataAndSecurity { @@ -156,9 +159,9 @@ public static void AddMediaLink(List Uncomplete) : $"{mediaAction} '{mediaLinkTitle}'"; } - if (ViewModel.Instance.MediaLinkShowTime && !mediaSession.IsLiveTime && mediaSession.TimePeekEnabled) + if (!mediaSession.IsLiveTime && mediaSession.TimePeekEnabled) { - x = x + DataController.TransformToSuperscript($" {FormatTimeSpan(mediaSession.CurrentTime)} l {FormatTimeSpan(mediaSession.FullTime)}"); + x = CreateTimeStamp(x, mediaSession, ViewModel.Instance.MediaLinkTimeSeekStyle); } } @@ -173,6 +176,45 @@ public static void AddMediaLink(List Uncomplete) } } + private static string CreateTimeStamp(string x, MediaSessionInfo mediaSession, MediaLinkTimeSeekbar style) + { + TimeSpan currentTime = mediaSession.CurrentTime; + TimeSpan fullTime = mediaSession.FullTime; + + if (currentTime.TotalSeconds < 0 || fullTime.TotalSeconds < 0 || currentTime > fullTime) + { + return x; + } + + double percentage = fullTime.TotalSeconds == 0 ? 0 : (currentTime.TotalSeconds / fullTime.TotalSeconds) * 100; + + switch (style) + { + case MediaLinkTimeSeekbar.NumbersAndSeekBar: + return $"{x}\n{DataController.TransformToSuperscript(FormatTimeSpan(currentTime))} {CreateProgressBar(percentage, 10)} {DataController.TransformToSuperscript(FormatTimeSpan(fullTime))}"; + + case MediaLinkTimeSeekbar.SeekBarOnly: + return $"{x}\n{CreateProgressBar(percentage, 13)}"; + + case MediaLinkTimeSeekbar.SmallNumbers: + return $"{x} {DataController.TransformToSuperscript(FormatTimeSpan(currentTime) + " l " + FormatTimeSpan(fullTime))}"; + + case MediaLinkTimeSeekbar.None: + return x; + default: + return x; + } + } + + private static string CreateProgressBar(double percentage, int totalBlocks) + { + int filledBlocks = (int)(percentage / (100.0 / totalBlocks)); + string filledBar = new string('▒', filledBlocks); + string emptyBar = new string('░', totalBlocks - filledBlocks); + return filledBar + "▓" + emptyBar; + } + + // this function will build the spotify status message to be sent to VRChat and add it to the list of strings if the total length of the list is less than 144 characters public static void AddSpotifyStatus(List Uncomplete) diff --git a/vrcosc-magicchatbox/Classes/Modules/MediaLinkModule.cs b/vrcosc-magicchatbox/Classes/Modules/MediaLinkModule.cs index 5d58bb6c..53d2ca6e 100644 --- a/vrcosc-magicchatbox/Classes/Modules/MediaLinkModule.cs +++ b/vrcosc-magicchatbox/Classes/Modules/MediaLinkModule.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using System.Windows; @@ -291,6 +292,17 @@ public static async Task MediaManager_PreviousAsync(MediaSessionInfo sessionInfo } + public enum MediaLinkTimeSeekbar + { + [Description ("Small numbers")] + SmallNumbers, + [Description("Current time bar with time")] + NumbersAndSeekBar, + [Description("Current time bar only")] + SeekBarOnly, + [Description("None")] + None + } diff --git a/vrcosc-magicchatbox/MainWindow.xaml b/vrcosc-magicchatbox/MainWindow.xaml index bb400cc7..a2882947 100644 --- a/vrcosc-magicchatbox/MainWindow.xaml +++ b/vrcosc-magicchatbox/MainWindow.xaml @@ -396,7 +396,7 @@ - + @@ -3934,21 +3934,29 @@ Visibility="{Binding DisableMediaLink, Converter={StaticResource InverseBoolToVisibilityConverter}, UpdateSourceTrigger=PropertyChanged}"> Turn autoswitch on when new session detected - + - Show song time of media session - + + + + + + - +