Skip to content

Commit

Permalink
Display deltas between cars
Browse files Browse the repository at this point in the history
  • Loading branch information
ColonelChocomel committed Mar 15, 2022
1 parent 2d608f9 commit 89bf6c2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 18 deletions.
45 changes: 35 additions & 10 deletions ACCBroadcaster/Classes/Car.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal class Car : INotifyPropertyChanged
{
public int Index { get; set; }
private int _Position;

public int Position
{
get { return _Position; }
Expand All @@ -22,7 +23,9 @@ public int Position
OnPropertyChanged(nameof(Position));
}
}

public int RaceNumber { get; set; }

private string _DriverName;
public string DriverName
{
Expand All @@ -33,6 +36,7 @@ public string DriverName
OnPropertyChanged(nameof(DriverName));
}
}

private CarLocationEnum _Location;
public CarLocationEnum Location
{
Expand All @@ -43,6 +47,7 @@ public CarLocationEnum Location
OnPropertyChanged(nameof(Location));
}
}

private string _LapDelta;
public string LapDelta
{
Expand All @@ -53,6 +58,18 @@ public string LapDelta
OnPropertyChanged(nameof(LapDelta));
}
}

private string _PositionDelta;
public string PositionDelta
{
get { return _PositionDelta; }
set
{
_PositionDelta = value;
OnPropertyChanged(nameof(PositionDelta));
}
}

private string _CurrentLap;
public string CurrentLap
{
Expand All @@ -63,6 +80,7 @@ public string CurrentLap
OnPropertyChanged(nameof(CurrentLap));
}
}

private string _LastLap;
public string LastLap
{
Expand All @@ -73,6 +91,9 @@ public string LastLap
OnPropertyChanged(nameof(LastLap));
}
}

public int BestLapMS = 0;

private string _BestLap;
public string BestLap
{
Expand All @@ -84,16 +105,9 @@ public string BestLap
}
}

private SolidColorBrush _ForegroundBrush = new SolidColorBrush(Microsoft.UI.Colors.White);
public SolidColorBrush ForegroundBrush
{
get { return _ForegroundBrush; }
set
{
_ForegroundBrush = value;
OnPropertyChanged(nameof(ForegroundBrush));
}
}
public int Kmh;

public int Lap;

private SolidColorBrush _BackgroundBrush;
public SolidColorBrush BackgroundBrush
Expand All @@ -117,6 +131,17 @@ public bool IsFocused
}
}

private float _SplinePosition;
public float SplinePosition
{
get { return _SplinePosition; }
set
{
_SplinePosition = value;
OnPropertyChanged(nameof(SplinePosition));
}
}

public event PropertyChangedEventHandler PropertyChanged;

public void OnPropertyChanged(string propertyName)
Expand Down
18 changes: 10 additions & 8 deletions ACCBroadcaster/Views/Broadcasting/CarListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Style="{StaticResource TextStyle}" Width="90">Delta</TextBlock>
<TextBlock Style="{StaticResource TextStyle}" Width="40">Pos</TextBlock>
<TextBlock Style="{StaticResource TextStyle}" Width="40">#</TextBlock>
<TextBlock Style="{StaticResource TextStyle}" Width="250">Driver</TextBlock>
Expand All @@ -32,14 +33,15 @@
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="classes:Car">
<StackPanel Orientation="Horizontal" Background="{Binding BackgroundBrush, Mode=OneWay}">
<TextBlock Text="{Binding Position, Mode=OneWay}" Style="{StaticResource TextStyle}" Foreground="{Binding ForegroundBrush, Mode=OneWay}" Width="40"/>
<TextBlock Text="{Binding RaceNumber}" Style="{StaticResource TextStyle}" Foreground="{Binding ForegroundBrush, Mode=OneWay}" Width="40"/>
<TextBlock Text="{Binding DriverName, Mode=OneWay}" Style="{StaticResource TextStyle}" Foreground="{Binding ForegroundBrush, Mode=OneWay}" Width="250"/>
<TextBlock Text="{Binding Location, Mode=OneWay}" Style="{StaticResource TextStyle}" Foreground="{Binding ForegroundBrush, Mode=OneWay}" Width="85"/>
<TextBlock Text="{Binding LapDelta, Mode=OneWay}" Style="{StaticResource TextStyle}" Foreground="{Binding ForegroundBrush, Mode=OneWay}" Width="93"/>
<TextBlock Text="{Binding CurrentLap, Mode=OneWay}" Style="{StaticResource TextStyle}" Foreground="{Binding ForegroundBrush, Mode=OneWay}" Width="100"/>
<TextBlock Text="{Binding LastLap, Mode=OneWay}" Style="{StaticResource TextStyle}" Foreground="{Binding ForegroundBrush, Mode=OneWay}" Width="100"/>
<TextBlock Text="{Binding BestLap, Mode=OneWay}" Style="{StaticResource TextStyle}" Foreground="{Binding ForegroundBrush, Mode=OneWay}" Width="100"/>
<TextBlock Text="{Binding PositionDelta, Mode=OneWay}" Style="{StaticResource TextStyle}" Width="90"/>
<TextBlock Text="{Binding Position, Mode=OneWay}" Style="{StaticResource TextStyle}" Width="40"/>
<TextBlock Text="{Binding RaceNumber}" Style="{StaticResource TextStyle}" Width="40"/>
<TextBlock Text="{Binding DriverName, Mode=OneWay}" Style="{StaticResource TextStyle}" Width="250"/>
<TextBlock Text="{Binding Location, Mode=OneWay}" Style="{StaticResource TextStyle}" Width="85"/>
<TextBlock Text="{Binding LapDelta, Mode=OneWay}" Style="{StaticResource TextStyle}" Width="93"/>
<TextBlock Text="{Binding CurrentLap, Mode=OneWay}" Style="{StaticResource TextStyle}" Width="100"/>
<TextBlock Text="{Binding LastLap, Mode=OneWay}" Style="{StaticResource TextStyle}" Width="100"/>
<TextBlock Text="{Binding BestLap, Mode=OneWay}" Style="{StaticResource TextStyle}" Width="100"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
Expand Down
36 changes: 36 additions & 0 deletions ACCBroadcaster/Views/Broadcasting/CarListView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace ACCBroadcaster.Views.Broadcasting
public sealed partial class CarListView : Page
{
private ObservableCollection<Car> Cars = new ObservableCollection<Car>();
private RaceSessionType SessionType;
public CarListView()
{
this.InitializeComponent();
Expand Down Expand Up @@ -91,6 +92,13 @@ private void OnRealtimeCarUpdate(string sender, RealtimeCarUpdate carUpdate)
car.CurrentLap = car.LapTimeMsToReadable(carUpdate.CurrentLap.LaptimeMS);
car.LastLap = car.LapTimeMsToReadable(carUpdate.LastLap.LaptimeMS);
car.BestLap = car.LapTimeMsToReadable(carUpdate.BestSessionLap.LaptimeMS);
if (carUpdate.BestSessionLap.LaptimeMS != null)
{
car.BestLapMS = (int)carUpdate.BestSessionLap.LaptimeMS;
}
car.SplinePosition = carUpdate.SplinePosition;
car.Kmh = carUpdate.Kmh;
car.Lap = carUpdate.Laps;
if (positionChanged)
{
Cars = new ObservableCollection<Car>(Cars.OrderBy(x => x.Position));
Expand All @@ -101,6 +109,33 @@ private void OnRealtimeCarUpdate(string sender, RealtimeCarUpdate carUpdate)
}
CarLV.ItemsSource = Cars;
}
if (car.Position != 1)
{
Car carAhead = Cars.FirstOrDefault(x => x.Position == (car.Position - 1));
if (carAhead != null)
{
if (SessionType != RaceSessionType.Race)
{
if (car.BestLapMS > 0)
{
int lapDelta = carAhead.BestLapMS - car.BestLapMS;
car.PositionDelta = car.DeltaMsToReadable(lapDelta);
}
}
else if (carAhead.SplinePosition > car.SplinePosition && carAhead.Lap == car.Lap)
{
float splineDistance = Math.Abs(carAhead.SplinePosition - car.SplinePosition);
float gapFrontMeters = splineDistance * ACCService.Client.MessageHandler.TrackMeters;
car.PositionDelta = $"+{gapFrontMeters / car.Kmh * 3.6:F3}";
} else
{
car.PositionDelta = null;
}
}
} else
{
car.PositionDelta = null;
}
}
}

Expand All @@ -122,6 +157,7 @@ private void OnRealtimeUpdate(string sender, RealtimeUpdate update)
focusedCar.SetAsFocusedCar(true);
}
}
SessionType = update.SessionType;
}

private void OnCarClicked(object sender, TappedRoutedEventArgs e)
Expand Down

0 comments on commit 89bf6c2

Please sign in to comment.