Skip to content

Commit

Permalink
Start replay from car context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ColonelChocomel committed Apr 7, 2022
1 parent 9ecb47b commit ce32073
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ACCBroadcaster/ACCBroadcaster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22000.194" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.2" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22000.197" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions ACCBroadcaster/Classes/ACCService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ namespace ACCBroadcaster.Classes
public static class ACCService
{
public static ACCUdpRemoteClient Client;
public static int CustomReplayLength = 5;
}
}
12 changes: 7 additions & 5 deletions ACCBroadcaster/Views/Broadcasting/CarListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
<Setter Property="Foreground" Value="Red"/>
</Style>
<MenuFlyout x:Name="CarContextFlyout" x:Key="CarContextFlyout">
<MenuFlyoutSubItem x:Name="OnboardContextFlyout" Text="Onboards">

</MenuFlyoutSubItem>
<MenuFlyoutSubItem x:Name="DrivableContextFlyout" Text="Drivable">

<MenuFlyoutSubItem x:Name="ReplayContextFlyout" Text="Instant Replay">
<MenuFlyoutItem CommandParameter="10" Text="-10s" Click="OnCarContextReplayClicked"/>
<MenuFlyoutItem CommandParameter="20" Text="-20s" Click="OnCarContextReplayClicked"/>
<MenuFlyoutItem CommandParameter="30" Text="-30s" Click="OnCarContextReplayClicked"/>
<MenuFlyoutItem Name="Custom" Text="Custom length" Click="OnCarContextReplayClicked"/>
</MenuFlyoutSubItem>
<MenuFlyoutSubItem x:Name="OnboardContextFlyout" Text="Onboards"/>
<MenuFlyoutSubItem x:Name="DrivableContextFlyout" Text="Drivable"/>
</MenuFlyout>
</Page.Resources>

Expand Down
20 changes: 20 additions & 0 deletions ACCBroadcaster/Views/Broadcasting/CarListView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public sealed partial class CarListView : Page
private ObservableCollection<Camera> OnboardCameras = new ObservableCollection<Camera>();
private ObservableCollection<Camera> DrivableCameras = new ObservableCollection<Camera>();
private RaceSessionType SessionType;
private float CurrentSessionTime = 0;

public CarListView()
{
this.InitializeComponent();
Expand Down Expand Up @@ -166,6 +168,7 @@ private void OnRealtimeUpdate(string sender, RealtimeUpdate update)
}
}
SessionType = update.SessionType;
CurrentSessionTime = Convert.ToInt32(update.SessionTime.TotalMilliseconds);
}

private void OnCarClicked(object sender, TappedRoutedEventArgs e)
Expand Down Expand Up @@ -244,5 +247,22 @@ private void OnCarContextDrivableClicked(object sender, RoutedEventArgs e)
Car car = (Car)item.DataContext;
ACCService.Client.MessageHandler.SetFocus((UInt16)car.Index, "Drivable", item.Name);
}

private void OnCarContextReplayClicked(object sender, RoutedEventArgs e)
{
MenuFlyoutItem item = (MenuFlyoutItem)e.OriginalSource;
Car car = (Car)item.DataContext;
float length;
if (item.Name == "Custom")
{
length = ACCService.CustomReplayLength;
}
else
{
length = (float)Convert.ToDouble(item.CommandParameter);
}
float requestedStartTime = CurrentSessionTime - (length * 1000);
ACCService.Client.MessageHandler.RequestInstantReplay(requestedStartTime, length * 1000.0f, car.Index);
}
}
}
4 changes: 3 additions & 1 deletion ACCBroadcaster/Views/Broadcasting/InstantReplayView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
Value="5"
SpinButtonPlacementMode="Inline"
SmallChange="5"
Margin="10"/>
Margin="10"
Minimum="1"
ValueChanged="CustomLengthNumberBox_ValueChanged"/>
<Button Content="Start Custom" Click="StartInstantReplay" Background="{ThemeResource ButtonBackgroundThemeBrush}"></Button>
</StackPanel>
</StackPanel>
Expand Down
9 changes: 7 additions & 2 deletions ACCBroadcaster/Views/Broadcasting/InstantReplayView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public InstantReplayView()
private void StartInstantReplay(object sender, RoutedEventArgs e)
{
Button button = (Button)sender;
float length = 0;
float length;
if (button.CommandParameter == null)
{
length = (float)CustomLengthNumberBox.Value;
length = ACCService.CustomReplayLength;
} else
{
length = (float)Convert.ToDouble(button.CommandParameter);
Expand All @@ -51,5 +51,10 @@ private void OnRealtimeUpdate(string sender, RealtimeUpdate update)
{
CurrentSessionTime = Convert.ToInt32(update.SessionTime.TotalMilliseconds);
}

private void CustomLengthNumberBox_ValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
{
ACCService.CustomReplayLength = (int)sender.Value;
}
}
}

0 comments on commit ce32073

Please sign in to comment.