Skip to content

Commit

Permalink
Merge pull request #175 from RiddleTime/dev
Browse files Browse the repository at this point in the history
1.0.7.2
- Fuel Info HUD: Reworked some internals.
- Boost Gauge HUD: Added customizable bar color.
- Speedometer HUD: Added customizable bar color.
- Added Positions Timestamp HUD: Can be used during a race session whilst calling a safety car, you will have all the positions (according to when drivers crossed a sector).
  • Loading branch information
RiddleTime authored May 6, 2024
2 parents 991ad2d + 5c4e8d6 commit d87db97
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ internal sealed class BoostGaugeOverlay : AbstractOverlay
private sealed class BoostConfiguration : OverlayConfiguration
{
public BoostConfiguration() => GenericConfiguration.AllowRescale = true;

[ConfigGrouping("Colors", "Change the appearance of the HUD.")]
public ColorGrouping Colors { get; init; } = new ColorGrouping();
public sealed class ColorGrouping
{
[ToolTip("Sets the color of the bar")]
public Color BarColor { get; init; } = Color.FromArgb(255, 255, 69, 0);
}
}

private readonly InfoPanel _panel;
private SolidBrush _barBrush;

public BoostGaugeOverlay(Rectangle rectangle) : base(rectangle, "Boost Gauge")
{
Expand All @@ -31,12 +40,13 @@ public BoostGaugeOverlay(Rectangle rectangle) : base(rectangle, "Boost Gauge")
this.RefreshRateHz = 10;
}

public override void BeforeStart() { }
public override void BeforeStop() { }
public sealed override void BeforeStart() => _barBrush = new(_config.Colors.BarColor);

public sealed override void BeforeStop() => _barBrush?.Dispose();

public sealed override void Render(Graphics g)
{
_panel.AddProgressBarWithCenteredText($"{pagePhysics.TurboBoost * 100f:F1}".FillStart(4, ' '), 0, 100, pagePhysics.TurboBoost * 100f);
_panel.AddProgressBarWithCenteredText($"{pagePhysics.TurboBoost * 100f:F1}".FillStart(4, ' '), 0, 100, pagePhysics.TurboBoost * 100f, _barBrush);
_panel.Draw(g);
}
}
25 changes: 12 additions & 13 deletions Race_Element.HUD.ACC/Overlays/Driving/FuelInfo/FuelInfoOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public sealed override bool ShouldRender()

public sealed override void Render(Graphics g)
{
Brush fuelBarBrush = GetFuelBarBrush();
using SolidBrush fuelBarBrush = new(GetFuelBarColor());
_infoPanel.AddProgressBarWithCenteredText($"{pagePhysics.Fuel:F2} L", 0, pageStatic.MaxFuel, pagePhysics.Fuel, fuelBarBrush);
// Some global variants
double lapBufferVar = pageGraphics.FuelXLap * this._config.InfoPanel.FuelBufferLaps;
Expand All @@ -115,7 +115,8 @@ public sealed override void Render(Graphics g)
string header = "No Laptime";
header = header.FillEnd(10, ' ');
_infoPanel.AddLine(header, "Waiting...");
goto drawPanel;
_infoPanel.Draw(g);
return;
}
}
}
Expand All @@ -129,7 +130,7 @@ public sealed override void Render(Graphics g)
string fuelTime = $"{TimeSpan.FromMilliseconds(fuelTimeLeft):hh\\:mm\\:ss}";
string stintTime = $"{TimeSpan.FromMilliseconds(stintDebug):hh\\:mm\\:ss}";
//**********************
Brush fuelTimeBrush = GetFuelTimeBrush(fuelTimeLeft, stintDebug);
using SolidBrush fuelTimeBrush = new(GetFuelTimeColor(fuelTimeLeft, stintDebug));
//Start (Basic)
_infoPanel.AddLine("Laps Left", $"{pageGraphics.FuelEstimatedLaps:F1} @ {pageGraphics.FuelXLap:F2}L");
_infoPanel.AddLine("Fuel-End", $"{fuelToEnd + lapBufferVar:F1} : Add {fuelToAdd:F0}");
Expand All @@ -147,10 +148,8 @@ public sealed override void Render(Graphics g)
else
_infoPanel.AddLine("Stint Fuel", $"{stintFuel + lapBufferVar:F1}");
}
//Magic End (Advanced)
drawPanel:
//Magic End (Advanced)
_infoPanel.Draw(g);
//fuelTimeBrush?.Dispose();
}

private double FuelToAdd(double lapBufferVar, double stintDebug, double stintFuel, double fuelToEnd)
Expand All @@ -164,24 +163,24 @@ private double FuelToAdd(double lapBufferVar, double stintDebug, double stintFue
return fuel;
}

private SolidBrush GetFuelBarBrush()
private Color GetFuelBarColor()
{
float percentage = pagePhysics.Fuel / pageStatic.MaxFuel;

Color color = _config.Colors.FullColor;
if (percentage <= _config.Colors.MediumPercent) color = _config.Colors.MediumColor;
if (percentage <= _config.Colors.LowPercent) color = _config.Colors.LowColor;

return new SolidBrush(color);
return color;
}

private Brush GetFuelTimeBrush(double fuelTimeLeft, double stintDebug)
private Color GetFuelTimeColor(double fuelTimeLeft, double stintDebug)
{
Brush brush;
Color color;
if (stintDebug > -1)
brush = fuelTimeLeft <= stintDebug ? Brushes.Red : Brushes.LimeGreen;
color = fuelTimeLeft <= stintDebug ? Color.Red : Color.LimeGreen;
else
brush = fuelTimeLeft <= pageGraphics.SessionTimeLeft ? Brushes.Red : Brushes.LimeGreen;
return brush;
color = fuelTimeLeft <= pageGraphics.SessionTimeLeft ? Color.Red : Color.LimeGreen;
return color;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ public sealed class InfoPanelGrouping
[ToolTip("Displays the minimum speed reached on each lap.")]
public bool MinSpeed { get; init; } = false;
}

[ConfigGrouping("Colors", "Change the appearance of the HUD.")]
public ColorGrouping Colors { get; init; } = new ColorGrouping();
public sealed class ColorGrouping
{
[ToolTip("Sets the color of the bar")]
public Color BarColor { get; init; } = Color.FromArgb(255, 255, 69, 0);
}
}

private readonly InfoPanel _panel;
private SolidBrush _barBrush;

private float _maxSpeed = 0;
private float _minSpeed = 0;

Expand All @@ -54,12 +64,16 @@ public sealed override void BeforeStart()
this.Height -= _panel.FontHeight;
if (!_config.InfoPanel.MaxSpeed)
this.Height -= _panel.FontHeight;

_barBrush = new(_config.Colors.BarColor);
}

public sealed override void BeforeStop()
{
if (_config.InfoPanel.MinSpeed || _config.InfoPanel.MaxSpeed)
LapTracker.Instance.LapFinished -= OnLapFinished;

_barBrush?.Dispose();
}

private void OnLapFinished(object sender, DbLapData e)
Expand All @@ -70,7 +84,7 @@ private void OnLapFinished(object sender, DbLapData e)

public sealed override void Render(Graphics g)
{
_panel.AddProgressBarWithCenteredText($"{pagePhysics.SpeedKmh:F0}".FillStart(3, ' '), 0, 320, pagePhysics.SpeedKmh);
_panel.AddProgressBarWithCenteredText($"{pagePhysics.SpeedKmh:F0}".FillStart(3, ' '), 0, 320, pagePhysics.SpeedKmh, _barBrush);

if (_config.InfoPanel.MaxSpeed)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using Gma.System.MouseKeyHook;
using RaceElement.HUD.Overlay.Configuration;
using RaceElement.HUD.Overlay.Internal;
using RaceElement.HUD.Overlay.OverlayUtil;
using RaceElement.HUD.Overlay.Util;
using RaceElement.Util.SystemExtensions;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using static RaceElement.Data.ACC.EntryList.EntryListTracker;

namespace RaceElement.HUD.ACC.Overlays.Pitwall.OverlayPositionsTimestamp;

[Overlay(Name = "Positions Timestamp",
Description = "Shows the car numbers, positions laps driven at a timestamp when the hotkey(control + s) was pressed during a race session.\nPress hotkey to reset and hide hud again.",
Authors = ["Reinier Klarenberg", "Kenneth Portis(idea)"],
OverlayType = OverlayType.Pitwall)]
internal sealed class PositionsTimestamp : AbstractOverlay
{
private readonly PositionsTimestampConfiguration _config = new();
private sealed class PositionsTimestampConfiguration : OverlayConfiguration
{
public PositionsTimestampConfiguration() => GenericConfiguration.AllowRescale = false;

[ConfigGrouping("Text Settings", "Adjust the look and feel of the text")]
public TextGrouping Text { get; init; } = new TextGrouping();
public sealed class TextGrouping
{
[ToolTip("Sets the size of the font.")]
[IntRange(10, 20, 1)]
public int FontSize { get; init; } = 12;
}
}

private IKeyboardMouseEvents m_GlobalHook;
private DateTime TimeStamped;
private List<KeyValuePair<int, CarData>> TimeStampedCars = new();

private Font _font;

public PositionsTimestamp(Rectangle rectangle) : base(rectangle, "Positions Timestamp")
{
RefreshRateHz = 2;
TimeStamped = DateTime.MinValue;
}

public sealed override void BeforeStart()
{
if (IsPreviewing) return;

_font = FontUtil.FontSegoeMono(_config.Text.FontSize);

m_GlobalHook = Hook.GlobalEvents();
m_GlobalHook.OnCombination(new Dictionary<Combination, Action> {
{
Combination.FromString("Control+S"), () => {
if (broadCastRealTime.SessionType == Broadcast.RaceSessionType.Race)
if (TimeStamped == DateTime.MinValue){
TimeStampedCars = Instance.Cars.OrderBy(x => x.Value.RealtimeCarUpdate.Position).ToList();
TimeStamped = DateTime.UtcNow;
} else {
TimeStamped = DateTime.MinValue;
TimeStampedCars.Clear();
}
}
}});
}

public sealed override void BeforeStop()
{
if (IsPreviewing) return;
m_GlobalHook?.Dispose();
}

public sealed override void Render(Graphics g)
{
if (IsPreviewing) return;

if (TimeStampedCars.Count == 0)
return;

float maxWidth = 0;
List<string> strings = [];
for (int i = 0; i < TimeStampedCars.Count; i++)
{
string row = $"{TimeStampedCars[i].Value.RealtimeCarUpdate.Position} - #{TimeStampedCars[i].Value.CarInfo.RaceNumber} | L{TimeStampedCars[i].Value.RealtimeCarUpdate.Laps}";
maxWidth.ClipMin(g.MeasureString(row, _font).Width);
strings.Add(row);
}
int totalHeight = (int)Math.Ceiling(strings.Count * _font.GetHeight());
Width = (int)maxWidth;
Height = totalHeight;

g.FillRectangle(Brushes.Black, new Rectangle(0, 0, Width, Height));
g.TextRenderingHint = TextRenderingHint.AntiAlias;
for (int i = 0; i < strings.Count; i++)
{
g.DrawStringWithShadow(strings[i], _font, Brushes.White, new PointF(0, i * _font.GetHeight()));
}
}
}
2 changes: 1 addition & 1 deletion Race_Element/Controls/HUD/HudOptions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public HudOptions()
listBoxItemToggleDemoMode.Selected += (s, e) =>
{
_hudSettingsJson.DemoMode = true;
_hudSettings.Save(_hudSettingsJson);
_hudSettings.Save(_hudSettingsJson);
listBoxItemToggleDemoMode.Foreground = Brushes.Cyan;
};
listBoxItemToggleDemoMode.Unselected += (s, e) =>
Expand Down
4 changes: 4 additions & 0 deletions Race_Element/Controls/Info/ReleaseNotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ public static class ReleaseNotes
{
internal readonly static Dictionary<string, string> Notes = new()
{
{"1.0.7.2", "- Fuel Info HUD: Reworked some internals."+
"\n- Boost Gauge HUD: Added customizable bar color."+
"\n- Speedometer HUD: Added customizable bar color."+
"\n- Added Positions Timestamp HUD: Can be used during a race session whilst calling a safety car, you will have all the positions (according to when drivers crossed a sector)."},
{"1.0.7.0", "- hotfix for fuel info hud, drawing things were disposed when they shouldn't have been." },
{"1.0.6.8", "- Fuel Info HUD:" +
"\n - Now calculates laptimes above 3 minutes. It will also use your last lap as laptime if you don't haven't set a valid best lap yet." +
Expand Down
2 changes: 1 addition & 1 deletion Race_Element/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
WindowStyle="None"
Title="Race Element" MinWidth="1210" Width="1210" MinHeight="790" Height="790" ResizeMode="CanResizeWithGrip" AllowsTransparency="True"
Title="Race Element" MinWidth="1210" Width="1210" MinHeight="790" ResizeMode="CanResizeWithGrip" AllowsTransparency="True"
WindowStartupLocation="Manual"
WindowState="Minimized"
AllowDrop="True">
Expand Down
28 changes: 14 additions & 14 deletions Race_Element/Race Element.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<SuiteName>Race Element</SuiteName>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<DisallowUrlActivation>true</DisallowUrlActivation>
<ApplicationVersion>1.0.7.0</ApplicationVersion>
<AssemblyVersion>1.0.7.0</AssemblyVersion>
<Version>1.0.7.0</Version>
<ApplicationVersion>1.0.7.2</ApplicationVersion>
<AssemblyVersion>1.0.7.2</AssemblyVersion>
<Version>1.0.7.2</Version>
<UseApplicationTrust>true</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down Expand Up @@ -73,21 +73,21 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="DdsFileTypePlusHack" Version="1.2.1" />
<PackageReference Include="LiteDB" Version="5.0.17" />
<PackageReference Include="LiteDB" Version="5.0.19" />
<PackageReference Include="MaterialDesignColors" Version="2.1.4" />
<PackageReference Include="MaterialDesignThemes" Version="4.9.0" />
<PackageReference Include="obs-websocket-dotnet" Version="5.0.0.3" />
<PackageReference Include="Octokit" Version="9.1.0" />
<PackageReference Include="Octokit" Version="11.0.1" />
<PackageReference Include="ScottPlot" Version="4.1.69" />
<PackageReference Include="ScottPlot.WPF" Version="4.1.69" />
<PackageReference Include="SharpCompress" Version="0.36.0" />
<PackageReference Include="SharpCompress" Version="0.37.2" />
<PackageReference Include="SLOBSharp" Version="1.1.4" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="System.Runtime.Handles" Version="4.3.0" />
<PackageReference Include="Websocket.Client" Version="5.0.0" />
<PackageReference Include="Websocket.Client" Version="5.1.1" />
<PackageReference Include="WebSocketSharp-netstandard" Version="1.0.1" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
Expand All @@ -99,31 +99,31 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.EventSource" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="8.0.0" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="8.0.0-preview.7.23375.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
<PackageReference Include="System.Drawing.Common" Version="8.0.1" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
<PackageReference Include="System.Drawing.Common" Version="8.0.4" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageReference Include="System.Text.Encodings.Web" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
</ItemGroup>
Expand Down

0 comments on commit d87db97

Please sign in to comment.