Skip to content

Commit

Permalink
Add Repeat button
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenquyhy committed Feb 22, 2022
1 parent 369c992 commit ad41c62
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions FlightRecorder.Client.Logics/IReplayLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface IReplayLogic
void Seek(int value);
bool StopReplay();
void ChangeRate(double rate);
void SetRepeat(bool repeat);
void Unfreeze();
void NotifyPosition(AircraftPositionStruct? value);

Expand Down
21 changes: 17 additions & 4 deletions FlightRecorder.Client.Logics/ReplayLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ReplayLogic : IReplayLogic, IDisposable
private int currentFrame;

private double rate = 1;
private bool repeat = false;
private int? pausedFrame;
private double? pausedRate;
private bool isReplayStopping;
Expand Down Expand Up @@ -237,6 +238,11 @@ public void ChangeRate(double rate)
this.rate = rate;
}

public void SetRepeat(bool repeat)
{
this.repeat = repeat;
}

public void Unfreeze()
{
if (replayMilliseconds != null)
Expand Down Expand Up @@ -338,7 +344,7 @@ private async Task RunReplay()

if (isReplayStopping)
{
FinishReplay();
FinishReplay(false);
return;
}

Expand Down Expand Up @@ -396,7 +402,7 @@ private async Task RunReplay()
else
{
// Last frame
FinishReplay();
FinishReplay(true);
return;
}
}
Expand All @@ -414,7 +420,7 @@ private async Task RunReplay()
}
}

private void FinishReplay()
private void FinishReplay(bool reachedLastFrame)
{
logger.LogInformation("Replay finished.");

Expand Down Expand Up @@ -443,7 +449,14 @@ private void FinishReplay()
replayMilliseconds = null;
offsetStartMilliseconds = null;

ReplayFinished?.Invoke(this, new EventArgs());
if (reachedLastFrame && repeat)
{
Replay();
}
else
{
ReplayFinished?.Invoke(this, new EventArgs());
}
}

private void MoveAircraft(long nextElapsed, AircraftPositionStruct position, long? lastElapsed, AircraftPositionStruct? lastPosition, long currentElapsed)
Expand Down
1 change: 1 addition & 0 deletions FlightRecorder.Client/AIWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</Grid.ColumnDefinitions>

<StackPanel Orientation="Horizontal" Grid.Column="0">
<ToggleButton x:Name="ButtonRepeat" Padding="5,0" Click="ButtonRepeat_Click">Repeat</ToggleButton>
<Button x:Name="ButtonSpeed" Content="x1" Padding="5,0" Margin="0,0,5,0" ContextMenuService.Placement="Bottom"
IsEnabled="{Binding State, Converter={StaticResource ValueToTrueConverter}, ConverterParameter=IdleSaved|IdleUnsaved|PausingSaved|PausingUnsaved}"
Click="ButtonContext_Click">
Expand Down
9 changes: 9 additions & 0 deletions FlightRecorder.Client/BaseWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace FlightRecorder.Client
{
Expand Down Expand Up @@ -99,6 +100,14 @@ protected void Slider_MouseWheel(object sender, System.Windows.Input.MouseWheelE
}
}

protected void ButtonRepeat_Click(object sender, RoutedEventArgs e)
{
if (sender is ToggleButton buttonRepeat)
{
replayLogic.SetRepeat(buttonRepeat.IsChecked == true);
}
}

#endregion
}
}
1 change: 1 addition & 0 deletions FlightRecorder.Client/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
</Grid.ColumnDefinitions>

<StackPanel Orientation="Horizontal" Grid.Column="0">
<ToggleButton x:Name="ButtonRepeat" Padding="5,0" Click="ButtonRepeat_Click">Repeat</ToggleButton>
<Button x:Name="ButtonSpeed" Content="x1" Padding="5,0" Margin="0,0,5,0" ContextMenuService.Placement="Bottom"
IsEnabled="{Binding State, Converter={StaticResource ValueToTrueConverter}, ConverterParameter=IdleSaved|IdleUnsaved|PausingSaved|PausingUnsaved}"
Click="ButtonContext_Click">
Expand Down

0 comments on commit ad41c62

Please sign in to comment.