-
Notifications
You must be signed in to change notification settings - Fork 802
Feature: Redesign Status Window #3359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9b0fea3
46205bb
ea9b8cb
9ab289d
658aa29
ff39fed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using System; | ||
| using System.Globalization; | ||
| using System.Windows.Data; | ||
|
|
||
| namespace NETworkManager.Converters; | ||
|
|
||
| /// <summary> | ||
| /// Converts <c>Time</c> (values[0]) and <c>TimeMax</c> (values[1]) into a <see cref="double" /> | ||
| /// stroke dash offset for a circular countdown ring. <c>ConverterParameter</c> must be the full | ||
| /// circumference of the ring in <c>StrokeDashArray</c> units (circumference / StrokeThickness). | ||
| /// </summary> | ||
| public sealed class TimeToStrokeDashOffsetConverter : IMultiValueConverter | ||
| { | ||
| public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) | ||
| { | ||
| if (parameter is not string circumferenceStr || | ||
| !double.TryParse(circumferenceStr, NumberStyles.Float, CultureInfo.InvariantCulture, | ||
| out var circumference)) | ||
| return 0.0; | ||
|
|
||
| if (values.Length < 2 || | ||
| values[0] is not double time || | ||
| values[1] is not double timeMax || | ||
| timeMax == 0 || | ||
| time <= 0) | ||
| return circumference + 1.0; | ||
|
|
||
| var progress = (double)time / timeMax; | ||
|
|
||
| return (1.0 - progress) * circumference; | ||
| } | ||
|
|
||
| public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ | |
| using NETworkManager.Views; | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Diagnostics; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading.Tasks; | ||
| using System.Windows.Forms; | ||
| using System.Windows.Input; | ||
| using System.Windows.Threading; | ||
|
|
@@ -19,9 +21,11 @@ public StatusWindow(MainWindow mainWindow) | |
| InitializeComponent(); | ||
| DataContext = this; | ||
|
|
||
| Title = $"NETworkManager {AssemblyManager.Current.Version} - {Localization.Resources.Strings.NetworkStatus}"; | ||
|
|
||
| _mainWindow = mainWindow; | ||
|
|
||
| _dispatcherTimerClose.Interval = new TimeSpan(0, 0, 0, 0, 250); | ||
| _dispatcherTimerClose.Interval = TimeSpan.FromMilliseconds(16); | ||
| _dispatcherTimerClose.Tick += DispatcherTimerTime_Tick; | ||
|
|
||
| _networkConnectionView = new NetworkConnectionWidgetView(); | ||
|
|
@@ -43,8 +47,8 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
|
|
||
| #region Variables | ||
|
|
||
| // Set priority to make the ui smoother | ||
| private readonly DispatcherTimer _dispatcherTimerClose = new(DispatcherPriority.Normal); | ||
| private readonly DispatcherTimer _dispatcherTimerClose = new(DispatcherPriority.Render); | ||
| private readonly Stopwatch _stopwatch = new(); | ||
|
|
||
| private readonly MainWindow _mainWindow; | ||
| private readonly NetworkConnectionWidgetView _networkConnectionView; | ||
|
|
@@ -64,9 +68,9 @@ public bool ShowTime | |
| } | ||
| } | ||
|
|
||
| private int _timeMax; | ||
| private double _timeMax; | ||
|
|
||
| public int TimeMax | ||
| public double TimeMax | ||
| { | ||
| get => _timeMax; | ||
| private set | ||
|
|
@@ -79,9 +83,9 @@ private set | |
| } | ||
| } | ||
|
|
||
| private int _time; | ||
| private double _time; | ||
|
|
||
| public int Time | ||
| public double Time | ||
| { | ||
| get => _time; | ||
| set | ||
|
|
@@ -153,6 +157,8 @@ public void ShowWindow(bool enableCloseTimer = false) | |
| // Check the network connection | ||
| Check(); | ||
|
|
||
| enableCloseTimer = true; | ||
|
|
||
| // Close the window after a certain time | ||
| if (enableCloseTimer) | ||
| { | ||
|
|
@@ -166,9 +172,10 @@ public void ShowWindow(bool enableCloseTimer = false) | |
|
|
||
| private void SetupCloseTimer() | ||
| { | ||
| Time = SettingsManager.Current.Status_WindowCloseTime * 4; | ||
| TimeMax = Time; | ||
| TimeMax = SettingsManager.Current.Status_WindowCloseTime; | ||
| Time = TimeMax; | ||
|
|
||
| _stopwatch.Restart(); | ||
| ShowTime = true; | ||
| _dispatcherTimerClose.Start(); | ||
| } | ||
|
|
@@ -189,18 +196,22 @@ private void MetroWindow_Closing(object sender, CancelEventArgs e) | |
| Hide(); | ||
| } | ||
|
|
||
| private void DispatcherTimerTime_Tick(object sender, EventArgs e) | ||
| private async void DispatcherTimerTime_Tick(object sender, EventArgs e) | ||
| { | ||
| Time--; | ||
| Time = Math.Max(0.0, TimeMax - _stopwatch.Elapsed.TotalSeconds); | ||
|
|
||
| if (Time > 0) | ||
| return; | ||
|
|
||
| _dispatcherTimerClose.Stop(); | ||
| _stopwatch.Stop(); | ||
|
|
||
| await Task.Delay(250); | ||
|
|
||
| ShowTime = false; | ||
|
|
||
| Hide(); | ||
| } | ||
|
Comment on lines
+199
to
214
|
||
|
|
||
| #endregion | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.