diff --git a/OpenLyricsClient/Frontend/Events/EventArgs/PageSelectionChangedEventArgs.cs b/OpenLyricsClient/Frontend/Events/EventArgs/PageSelectionChangedEventArgs.cs new file mode 100644 index 0000000..97f618a --- /dev/null +++ b/OpenLyricsClient/Frontend/Events/EventArgs/PageSelectionChangedEventArgs.cs @@ -0,0 +1,26 @@ +using System; +using Avalonia.Controls; + +namespace OpenLyricsClient.Frontend.Events.EventArgs; + +public class PageSelectionChangedEventArgs : System.EventArgs +{ + private UserControl _fromPage; + private UserControl _toPage; + + public PageSelectionChangedEventArgs(UserControl fromPage, UserControl toPage) + { + this._fromPage = fromPage; + this._toPage = toPage; + } + + public UserControl FromPage + { + get => _fromPage; + } + + public UserControl ToPage + { + get => _toPage; + } +} \ No newline at end of file diff --git a/OpenLyricsClient/Frontend/Events/EventHandler/PageSelectionChangedEventHandler.cs b/OpenLyricsClient/Frontend/Events/EventHandler/PageSelectionChangedEventHandler.cs new file mode 100644 index 0000000..ef7f501 --- /dev/null +++ b/OpenLyricsClient/Frontend/Events/EventHandler/PageSelectionChangedEventHandler.cs @@ -0,0 +1,6 @@ +using System; +using OpenLyricsClient.Frontend.Events.EventArgs; + +namespace OpenLyricsClient.Frontend.Events.EventHandler; + +public delegate void PageSelectionChangedEventHandler(Object sender, PageSelectionChangedEventArgs pageSelectionChanged); diff --git a/OpenLyricsClient/Frontend/Events/EventHandler/PageSelectionChangedFinishedEventHandler.cs b/OpenLyricsClient/Frontend/Events/EventHandler/PageSelectionChangedFinishedEventHandler.cs new file mode 100644 index 0000000..d83b0ad --- /dev/null +++ b/OpenLyricsClient/Frontend/Events/EventHandler/PageSelectionChangedFinishedEventHandler.cs @@ -0,0 +1,6 @@ +using System; +using OpenLyricsClient.Frontend.Events.EventArgs; + +namespace OpenLyricsClient.Frontend.Events.EventHandler; + +public delegate void PageSelectionChangedFinishedEventHandler(Object sender, PageSelectionChangedEventArgs pageSelectionChanged); diff --git a/OpenLyricsClient/Frontend/View/Custom/Tile/Overlays/NoteOverlay.axaml.cs b/OpenLyricsClient/Frontend/View/Custom/Tile/Overlays/NoteOverlay.axaml.cs index 3b8b251..77bfc58 100644 --- a/OpenLyricsClient/Frontend/View/Custom/Tile/Overlays/NoteOverlay.axaml.cs +++ b/OpenLyricsClient/Frontend/View/Custom/Tile/Overlays/NoteOverlay.axaml.cs @@ -21,10 +21,13 @@ using OpenLyricsClient.Backend.Events.EventArgs; using OpenLyricsClient.Backend.Handler.Services.Services; using OpenLyricsClient.Backend.Settings.Sections.Lyrics; +using OpenLyricsClient.Frontend.Events.EventArgs; using OpenLyricsClient.Frontend.Extensions; using OpenLyricsClient.Frontend.Models.Pages.Settings; using OpenLyricsClient.Frontend.Structure.Enum; using OpenLyricsClient.Frontend.Utils; +using OpenLyricsClient.Frontend.View.Pages; +using OpenLyricsClient.Frontend.View.Windows; using OpenLyricsClient.Shared.Structure.Lyrics; using OpenLyricsClient.Shared.Utils; using Squalr.Engine.Utils.Extensions; @@ -88,13 +91,32 @@ public NoteOverlay() AvaloniaXamlLoader.Load(this); ApplyAnimationToClasses(this._idleTimeSpan, this._noteTimeSpan); + + MainWindow.Instance.PageSelectionChanged += InstanceOnPageSelectionChanged; + MainWindow.Instance.PageSelectionChangedFinished += InstanceOnPageSelectionChangedFinished; + } + + private void InstanceOnPageSelectionChanged(object sender, PageSelectionChangedEventArgs pageselectionchanged) + { + if (pageselectionchanged.ToPage.GetType() == typeof(SettingsPage)) + { + this.Headless = true; + } + } + + private void InstanceOnPageSelectionChangedFinished(object sender, PageSelectionChangedEventArgs pageselectionchanged) + { + if (pageselectionchanged.ToPage.GetType() == typeof(LyricsPage)) + { + this.Headless = false; + } } #region Events private void LyricHandlerOnLyricsFound(object sender, LyricsFoundEventArgs lyricsfoundeventargs) { - if (this._headlessMode) + if (this.Headless) return; Dispatcher.UIThread.InvokeAsync(() => @@ -105,7 +127,7 @@ private void LyricHandlerOnLyricsFound(object sender, LyricsFoundEventArgs lyric private void SettingsHandlerOnSettingsChanged(object sender, SettingsChangedEventArgs args) { - if (this._headlessMode) + if (this.Headless) return; if (!args.Section.Equals(typeof(SettingsLyricsViewModel))) @@ -117,7 +139,7 @@ private void SettingsHandlerOnSettingsChanged(object sender, SettingsChangedEven private void LyricHandlerOnLyricsPercentageUpdated(object sender, LyricsPercentageUpdatedEventArgs args) { - if (this._headlessMode) + if (this.Headless) return; if (this._lyricPart.Equals(args.LyricPart)) @@ -134,6 +156,8 @@ private void LyricHandlerOnLyricsPercentageUpdated(object sender, LyricsPercenta private void InputElement_OnPointerPressed(object? sender, PointerPressedEventArgs e) { + MainWindow.Instance.WindowDragable = false; + IService service = Core.INSTANCE.ServiceHandler.GetActiveService(); if (!DataValidator.ValidateData(service)) @@ -145,6 +169,8 @@ private void InputElement_OnPointerPressed(object? sender, PointerPressedEventAr private void InputElement_OnPointerEnter(object? sender, PointerEventArgs e) { + MainWindow.Instance.WindowDragable = true; + IService service = Core.INSTANCE.ServiceHandler.GetActiveService(); if (!DataValidator.ValidateData(service)) @@ -177,7 +203,7 @@ private void InputElement_OnPointerLeave(object? sender, PointerEventArgs e) private void ApplyAnimationToClasses(TimeSpan idleTimeSpan, TimeSpan noteTimeSpan) { - if (this._headlessMode) + if (this.Headless) return; Styles styles = new Styles(); @@ -282,7 +308,7 @@ private Style ActiveAnimationStyle(string className, TimeSpan duration, TimeSpan private void ApplyDelay(string classes, TimeSpan span) { double h = span.TotalMilliseconds / 3; - double factor = (h / (3 * 4)) * 0.01d; + double factor = (h / (3 * 6)) * 0.01d; int position = 0; for (int i = 0; i < this._animatale.Length; i++) @@ -292,7 +318,6 @@ private void ApplyDelay(string classes, TimeSpan span) if (element.Item1.SequenceEqual($"{classes}{position + 1}")) { element.Item2.Delay = TimeSpan.FromMilliseconds(position * factor); - Debug.WriteLine($"{element.Item2.Delay} : {factor} : {i}"); position++; } } diff --git a/OpenLyricsClient/Frontend/View/Custom/Tile/Overlays/TextOverlay.axaml.cs b/OpenLyricsClient/Frontend/View/Custom/Tile/Overlays/TextOverlay.axaml.cs index 6a45684..f68444f 100644 --- a/OpenLyricsClient/Frontend/View/Custom/Tile/Overlays/TextOverlay.axaml.cs +++ b/OpenLyricsClient/Frontend/View/Custom/Tile/Overlays/TextOverlay.axaml.cs @@ -24,9 +24,12 @@ using OpenLyricsClient.Backend.Handler.Services.Services; using OpenLyricsClient.Backend.Romanization; using OpenLyricsClient.Backend.Settings.Sections.Lyrics; +using OpenLyricsClient.Frontend.Events.EventArgs; using OpenLyricsClient.Frontend.Extensions; using OpenLyricsClient.Frontend.Structure; using OpenLyricsClient.Frontend.Utils; +using OpenLyricsClient.Frontend.View.Pages; +using OpenLyricsClient.Frontend.View.Windows; using OpenLyricsClient.Shared.Structure.Lyrics; using OpenLyricsClient.Shared.Structure.Visual; using OpenLyricsClient.Shared.Utils; @@ -66,13 +69,19 @@ public partial class TextOverlay : UserControl, INotifyPropertyChanged private bool _isPointerOver; private bool _headlessMode; + private bool _suppressActivity; + + private readonly int LEFT_SPACE; public TextOverlay() { AvaloniaXamlLoader.Load(this); + LEFT_SPACE = 50; + this._initialized = false; this.Headless = false; + this.SuppressActivity = false; this._isPointerOver = false; @@ -90,11 +99,35 @@ public TextOverlay() Core.INSTANCE.LyricHandler.LyricsPercentageUpdated += LyricHandlerOnLyricsPercentageUpdated; this._lyricPart = new LyricPart(-9999, "Hello there ;)"); + + MainWindow.Instance.PageSelectionChanged += InstanceOnPageSelectionChanged; + MainWindow.Instance.PageSelectionChangedFinished += InstanceOnPageSelectionChangedFinished; + } + + private void InstanceOnPageSelectionChanged(object sender, PageSelectionChangedEventArgs pageselectionchanged) + { + if (pageselectionchanged.ToPage.GetType() == typeof(SettingsPage)) + { + this.Headless = true; + this.SuppressActivity = true; + } + } + + private void InstanceOnPageSelectionChangedFinished(object sender, PageSelectionChangedEventArgs pageselectionchanged) + { + if (pageselectionchanged.ToPage.GetType() == typeof(LyricsPage)) + { + this.Headless = false; + this.SuppressActivity = false; + } } private void UpdateView(double width, double height) { - UpdateTextWrappingLines(this._lyricPart.Part, width, height); + if (this.SuppressActivity) + return; + + UpdateTextWrappingLines(this._lyricPart.Part, NewLyricsScroller.Instance.Bounds.Width - LEFT_SPACE, height); } private void UpdateTextWrappingLines(string text, double width, double height) @@ -176,9 +209,6 @@ private void LyricHandlerOnLyricsPercentageUpdated(object sender, LyricsPercenta private void InstanceOnEffectiveViewportChanged(object? sender, EffectiveViewportChangedEventArgs e) { - if (this._headlessMode) - return; - UpdateView(e.EffectiveViewport.Width, e.EffectiveViewport.Height); } @@ -195,6 +225,8 @@ private void InputElement_OnPointerPressed(object? sender, PointerPressedEventAr private void InputElement_OnPointerEnter(object? sender, PointerEventArgs e) { + MainWindow.Instance.WindowDragable = false; + IService service = Core.INSTANCE.ServiceHandler.GetActiveService(); if (!DataValidator.ValidateData(service)) @@ -209,6 +241,8 @@ private void InputElement_OnPointerEnter(object? sender, PointerEventArgs e) private void InputElement_OnPointerLeave(object? sender, PointerEventArgs e) { + MainWindow.Instance.WindowDragable = true; + IService service = Core.INSTANCE.ServiceHandler.GetActiveService(); if (!DataValidator.ValidateData(service)) @@ -255,7 +289,10 @@ public LyricPart LyricPart SetAndRaise(LyricPartProperty, ref _lyricPart, value); - UpdateTextWrappingLines(this._lyricPart.Part, NewLyricsScroller.Instance.Bounds.Width, + if (this.SuppressActivity) + return; + + UpdateTextWrappingLines(this._lyricPart.Part, NewLyricsScroller.Instance.Bounds.Width - LEFT_SPACE, double.PositiveInfinity); this._initialized = true; @@ -332,7 +369,13 @@ public bool Headless get => this._headlessMode; set => this._headlessMode = value; } - + + public bool SuppressActivity + { + get => _suppressActivity; + set => _suppressActivity = value; + } + public Size Size { get diff --git a/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml.cs b/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml.cs index 7217216..52f6b4a 100644 --- a/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml.cs +++ b/OpenLyricsClient/Frontend/View/Pages/LyricsPage.axaml.cs @@ -14,6 +14,7 @@ using Material.Styles; using OpenLyricsClient.Backend; using OpenLyricsClient.Backend.Settings.Sections.Lyrics; +using OpenLyricsClient.Frontend.Events.EventArgs; using OpenLyricsClient.Shared.Utils; using OpenLyricsClient.Frontend.Models.Pages; using OpenLyricsClient.Frontend.View.Custom; @@ -89,9 +90,24 @@ public LyricsPage() if (!DataValidator.ValidateData(this._lyricsPageViewModel)) return; + MainWindow.Instance.PageSelectionChanged += InstanceOnPageSelectionChanged; + this._lyricsPageViewModel.PropertyChanged += DataContextOnPropertyChanged; } + private void InstanceOnPageSelectionChanged(object sender, PageSelectionChangedEventArgs pageselectionchanged) + { + /*if (pageselectionchanged.FromPage.GetType() == typeof(LyricsPage)) + { + this._cstmLyricsDisplay.IsVisible = false; + } + else + { + this._cstmLyricsDisplay.IsVisible = true; + + }*/ + } + private void DataContextOnPropertyChanged(object? sender, PropertyChangedEventArgs e) { if (!DataValidator.ValidateData(e)) @@ -150,7 +166,7 @@ private void InputElement_OnPointerLeave(object? sender, PointerEventArgs e) private void InputElement_OnPointerPressed(object? sender, PointerPressedEventArgs e) { - MainWindow.Instance.BeginMoveDrag(e); + MainWindow.Instance.DragWindow(e); } private void Button_OnClick(object? sender, RoutedEventArgs e) diff --git a/OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml b/OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml index d2b8ccc..73e4291 100644 --- a/OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml +++ b/OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml @@ -171,11 +171,11 @@ - + - + - + diff --git a/OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml.cs b/OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml.cs index 5c3841a..d4bbc7a 100644 --- a/OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml.cs +++ b/OpenLyricsClient/Frontend/View/Windows/MainWindow.axaml.cs @@ -1,10 +1,15 @@ using System; using System.Runtime.InteropServices; +using System.Threading.Tasks; using Avalonia; +using Avalonia.Animation; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Media; +using DevBase.Generics; +using OpenLyricsClient.Frontend.Events.EventArgs; +using OpenLyricsClient.Frontend.Events.EventHandler; using ScalableWindow = OpenLyricsClient.Frontend.Scaling.ScalableWindow; namespace OpenLyricsClient.Frontend.View.Windows @@ -23,10 +28,23 @@ public partial class MainWindow : ScalableWindow private Button _fulltextButton; private Button _settingsButton; + private ATupleList _pageList; + + private TimeSpan _animationSpan; + + public event PageSelectionChangedEventHandler PageSelectionChanged; + public event PageSelectionChangedFinishedEventHandler PageSelectionChangedFinished; + public MainWindow() { + INSTANCE = this; InitializeComponent(); + this._pageList = new ATupleList(); + this._pageList.Add(0, this.Get(nameof(LyricsPage))); + this._pageList.Add(1, this.Get(nameof(FullLyricsPage))); + this._pageList.Add(2, this.Get(nameof(SettingsPage))); + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { this.WindowStartupLocation = WindowStartupLocation.Manual; // center doesn't work on osx @@ -36,10 +54,10 @@ public MainWindow() this.CRD_WindowDecoration_FullScreen.IsVisible = false; // hide fullscreen button } - INSTANCE = this; this._windowDragable = true; this._pageSelector = this.Get(nameof(PageSelection)); + this._pageSelector.SelectedIndex = 0; this._lyricsButton = this.Get