Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RaceOverlay/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using RaceOverlay.Overlays.Relative;
using RaceOverlay.Overlays.WeatherInfo;
using RaceOverlay.Overlays.SessionInfo;
using RaceOverlay.Overlays.TrackCircle;
using Inputs = RaceOverlay.Overlays.Inputs.Inputs;

namespace RaceOverlay;
Expand Down Expand Up @@ -62,6 +63,7 @@ private void _initOverlays()
Overlays.Add(new PitstopInfo());
Overlays.Add(new Relative());
//Overlays.Add(new SessionInfo());
Overlays.Add(new TrackCircle());
Overlays.Add(new WeatherInfo());


Expand Down
28 changes: 28 additions & 0 deletions RaceOverlay/Overlays/TrackCircle/TrackCircle.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<internals:Overlay x:Class="RaceOverlay.Overlays.TrackCircle.TrackCircle"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:RaceOverlay.Overlays.TrackCircle"
xmlns:internals="clr-namespace:RaceOverlay.Internals"
mc:Ignorable="d"
Title="Track Circle"
Height="{Binding _windowHeight}" Width="{Binding _windowWidth}"
Background="Transparent"
WindowStyle="None"
WindowStartupLocation="Manual"
ResizeMode="NoResize"
Topmost="True"
Foreground="White">
<Grid>
<Grid.LayoutTransform>
<ScaleTransform x:Name="ContentScaleTransform" ScaleX="1" ScaleY="1" />
</Grid.LayoutTransform>

<Canvas Width="200" Height="200" Name="CircleCanvas">
<Ellipse Width="200" Height="200" StrokeThickness="10" Stroke="White">

</Ellipse>
</Canvas>
</Grid>
</internals:Overlay>
129 changes: 129 additions & 0 deletions RaceOverlay/Overlays/TrackCircle/TrackCircle.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using RaceOverlay.Data.Models;
using RaceOverlay.Internals;

namespace RaceOverlay.Overlays.TrackCircle;

public partial class TrackCircle : Overlay
{
private iRacingData _data;
public TrackCircle() : base("Track Circle", "This Overlay shows the track as a circle with car markers on the track")

Check warning on line 14 in RaceOverlay/Overlays/TrackCircle/TrackCircle.xaml.cs

View workflow job for this annotation

GitHub Actions / test

Non-nullable field '_data' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
InitializeComponent();

_setWindowSize(200, 200);

Thread updateThread = new Thread(UpdateThreadMethod);

updateThread.IsBackground = true;
updateThread.Start();
}

public override void _updateWindow()
{
CircleCanvas.Children.Clear();

// Add Ellipse for the track
Ellipse trackEllipse = new Ellipse();
trackEllipse.Width = 200;
trackEllipse.Height = 200;
trackEllipse.StrokeThickness = 10;
trackEllipse.Stroke = Brushes.White;
CircleCanvas.Children.Add(trackEllipse);


var drivers = _data.Drivers;
for (int i = 0; i < drivers.Length; i++)
{
// Position based on LapDistance
double angle = drivers[i].LapDistance * 2 * Math.PI;
double radius = 185;
double centerX = trackEllipse.Width / 2;
double centerY = trackEllipse.Height / 2;

double posX = centerX + radius * Math.Sin(angle) - 7.5;
double posY = centerY - radius * Math.Cos(angle) - 7.5;

// Ellipse for every car
Ellipse car = new Ellipse();
car.Width = 15;
car.Height = 15;
car.Fill = GetColor(drivers[i].ClassColorCode);
car.Stroke = Brushes.White;
car.StrokeThickness = 1;

Canvas.SetLeft(car, posX);
Canvas.SetTop(car, posY);
CircleCanvas.Children.Add(car);


TextBlock positionText = new TextBlock();
positionText.Text = drivers[i].ClassPosition.ToString();
positionText.Foreground = Brushes.White;
positionText.FontSize = 10;
positionText.FontWeight = FontWeights.Bold;

// Center Text
positionText.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
double textWidth = positionText.DesiredSize.Width;
double textHeight = positionText.DesiredSize.Height;

Canvas.SetLeft(positionText, posX + (15 - textWidth) / 2);
Canvas.SetTop(positionText, posY + (15 - textHeight) / 2);
CircleCanvas.Children.Add(positionText);

}
}

public override void _getData()
{
_data = MainWindow.IRacingData;
if (_devMode)
{
_inCar = true;
return;
}
else
{
_inCar = _data.InCar;
}

}

protected override void _scaleWindow(double scale)
{
try
{
ContentScaleTransform.ScaleX = scale;
ContentScaleTransform.ScaleY = scale;
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}

private Brush GetColor(string colorCode)
{
if (colorCode == "#ffffff" || colorCode == "#000000" || colorCode == "#undefined")
{
var brush = new SolidColorBrush();
brush.Color = Colors.Navy;
return brush;
}
if (!(new BrushConverter().ConvertFromString(colorCode) is SolidColorBrush))
{
var brush = new SolidColorBrush();
brush.Color = Colors.Navy;
return brush;
}

return new BrushConverter().ConvertFromString(colorCode) as SolidColorBrush;
}


}
Loading