Skip to content

Commit

Permalink
add radar + more bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuvix25 committed Jun 19, 2023
1 parent bbec276 commit fd7ec48
Show file tree
Hide file tree
Showing 15 changed files with 370 additions and 76 deletions.
5 changes: 3 additions & 2 deletions Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
<title>ReHUD</title>


@* <script src="https://cdn.jsdelivr.net/npm/@@shopify/draggable@latest/lib/draggable.bundle.js"></script> *@
<script src="https://www.unpkg.com/agnostic-draggable@1.4.5/dist/agnostic-draggable.min.js"></script>

<script src="~/js/index.js" asp-append-version="true"></script>
<script src="~/js/utils.js" asp-append-version="true"></script>
<script src="~/js/index.js" asp-append-version="true"></script>
</head>

<div id="main-container" class="col sb">
Expand Down Expand Up @@ -256,3 +255,5 @@
</div>
</div>

<div id="radar"></div>

2 changes: 1 addition & 1 deletion Pages/Settings.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="setting">
<label>HUD Layout</label>
<button id="edit-layout" onclick="lockOverlay(true)">Edit</button>
<button id="cancel-layout" onclick="lockOverlay(false)" style="display: none;">Cancel</button>
<button id="cancel-reset-layout" onclick="lockOverlay(false)">Reset</button>
</div>

<div class="setting">
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ I started this project following the recent increase in the number of bugs in Ra
- Input meter
- Damage viewer
- Live on-track relative display*
- Radar* (waiting for some features to be implemented into the shared memory API)
- Session status*
- Settings window:
- Element scale and rearrangement*
Expand All @@ -32,7 +33,6 @@ _\* work in progress_

## Planned Features
- Position bar
- Radar
- Live delta
- Manual rolling start

Expand Down Expand Up @@ -61,3 +61,4 @@ Any contribution to the project will be highly appreciated! Feel free to open a
## Special Thanks
- [Tobias Naumann](https://twitch.tv/DasBreitschwert) - for being an early tester and providing me with a lot of great feedback.
- [Rich Weatherill](https://www.youtube.com/@trippsix_motorsport) - for designing the ReHUD icon.
- [OtterNas3](https://www.twitch.tv/otternas3n) - for creating [OtterHUD](https://forum.kw-studios.com/index.php?threads/otterhud-a-custom-webhud-with-additional-features.13152/) - the inspiration for this project, and an amazing HUD for RaceRoom.
4 changes: 0 additions & 4 deletions SharedMemory.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
using System.Threading;
using R3E.Data;

namespace R3E
Expand Down
52 changes: 34 additions & 18 deletions Startup.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ElectronNET.API;
using ElectronNET.API.Entities;
using Newtonsoft.Json;
using System.Diagnostics;

namespace ReHUD;

Expand Down Expand Up @@ -66,7 +65,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

private async Task CreateMainWindow(IWebHostEnvironment env)
{
// double factor = (await Electron.Screen.GetPrimaryDisplayAsync()).WorkAreaSize.Width / 1920.0;
var window = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions()
{
Resizable = false,
Expand All @@ -91,29 +89,41 @@ private async Task CreateMainWindow(IWebHostEnvironment env)
return;
}


window.SetAlwaysOnTop(true, OnTopLevel.screenSaver);

if (!env.IsDevelopment())
window.SetIgnoreMouseEvents(true);


await Electron.IpcMain.On("get-hud-layout", (args) => {
sendHudLayout(window);
SendHudLayout(window);
});

await Electron.IpcMain.On("set-hud-layout", (args) => {
SetHudLayout(JsonConvert.DeserializeObject<Object>(args.ToString() ?? "{}") ?? new Dictionary<String, Object>());
});

await Electron.IpcMain.On("reset-hud-layout", (args) => {
try {
SendHudLayout(window, new Dictionary<String, Object>());
} catch (Exception e) {
Console.WriteLine(e);
}
});

RunLoop(window, env);

window.OnClosed += () => Electron.App.Quit();
}

private void sendHudLayout(ElectronNET.API.BrowserWindow window)
private void SendHudLayout(ElectronNET.API.BrowserWindow window)
{
SendHudLayout(window, GetHudLayout());
}

private void SendHudLayout(ElectronNET.API.BrowserWindow window, object layout)
{
Electron.IpcMain.Send(window, "hud-layout", JsonConvert.SerializeObject(GetHudLayout()));
Electron.IpcMain.Send(window, "hud-layout", JsonConvert.SerializeObject(layout));
}


Expand Down Expand Up @@ -151,45 +161,44 @@ await Electron.IpcMain.On("lock-overlay", (data) =>
if (locked && save) {
Electron.IpcMain.Send(mainWindow, "save-hud-layout");
} else if (locked) {
sendHudLayout(mainWindow);
SendHudLayout(mainWindow);
}
});

await Electron.IpcMain.On("set-setting", (arg) =>
{
Electron.IpcMain.Send(mainWindow, "set-setting", arg.ToString());
SaveSetting((Newtonsoft.Json.Linq.JArray)arg);
Newtonsoft.Json.Linq.JArray array = (Newtonsoft.Json.Linq.JArray)arg;
if (array.Count == 2 && array[0] != null && array[0].Type == Newtonsoft.Json.Linq.JTokenType.String)
SaveSetting(array[0].ToString(), array[1]);
else
Console.WriteLine("Invalid setting: " + arg);
});

window.OnClosed += () => Electron.App.Quit();
}

Dictionary<String, Object> settings = GetSettings();

private void SaveSetting(Newtonsoft.Json.Linq.JArray setting)
{

settings[setting[0].ToString()] = setting[1];
WriteDataFile(settingsFile, JsonConvert.SerializeObject(settings));
}
private void SaveSetting(String key, Object value)
{
SaveSetting(new Newtonsoft.Json.Linq.JArray(key, value));
if (key == null)
return;
settings[key] = value;
WriteDataFile(settingsFile, JsonConvert.SerializeObject(settings));
}

private static Dictionary<String, Object> GetSettings()
{
return JsonConvert.DeserializeObject<Dictionary<String, Object>>(ReadDataFile(settingsFile)) ?? new Dictionary<String, Object>();
}

private Object GetHudLayout() {
private object GetHudLayout() {
return settings.ContainsKey("hudLayout") ? settings["hudLayout"] : new Dictionary<String, Object>();
}

private void SetHudLayout(Object layout)
{
// settings["hudLayout"] = layout;
// WriteDataFile(settingsFile, JsonConvert.SerializeObject(settings));
SaveSetting("hudLayout", layout);
}

Expand Down Expand Up @@ -254,6 +263,13 @@ private void RunLoop(BrowserWindow window, IWebHostEnvironment env)

R3E.Combination combination = userData.GetCombination(data.LayoutId, data.VehicleInfo.ModelId);
extraData.RawData = data;
int driverDataSize = 0;
foreach (var d in extraData.RawData.DriverData) {
if (d.DriverInfo.CarNumber == -1)
break;
driverDataSize++;
}
extraData.RawData.DriverData = extraData.RawData.DriverData.Take(driverDataSize).ToArray();
if (iter % (1000 / R3E.SharedMemory.timeInterval.Milliseconds) * 10 == 0)
{
extraData.FuelPerLap = combination.GetAverageFuelUsage();
Expand Down
2 changes: 1 addition & 1 deletion electron.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"appId": "com.yuvix.rehud",
"productName": "ReHUD",
"copyright": "Copyright © 2023",
"buildVersion": "0.2.2",
"buildVersion": "0.3.0",
"win": {
"icon": "../../../wwwroot/ReHUD.png"
},
Expand Down
39 changes: 38 additions & 1 deletion wwwroot/css/app.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
:root {
--hud-element-background: rgba(0, 0, 0, 0.6);

--revs-color-normal: white;
--revs-color-upshift: rgb(0, 255, 0);
--revs-color-redline: rgb(255, 0, 0);
Expand Down Expand Up @@ -105,7 +107,7 @@ table {
}

he {
background-color: rgba(0, 0, 0, 0.6);
background-color: var(--hud-element-background);
border-radius: 5px;
align-items: center;
margin: 2px;
Expand Down Expand Up @@ -634,11 +636,23 @@ progress#revs::-webkit-progress-value {
gap: 70px;
}

#laps-left {
width: 120px !important;
text-align: center;
direction: rtl;
}

#time-left-container {
align-items: center;
margin: 10px;
}

#time-left {
width: 180px;
text-align: center;
direction: rtl;
}

#time-left span {
margin: 0 !important;
margin-right: 1px !important;
Expand All @@ -662,3 +676,26 @@ progress#revs::-webkit-progress-value {
margin: 10px;
}


#radar {
border-radius: 50%;
width: 300px;
height: 300px;
position: absolute;
top: calc(100vh - 300px - 15px);
left: 50%;
transform: translateX(-50%);
overflow: hidden;
background-size: contain;
opacity: 0.8;
}

#radar .radar-car {
position: absolute;
border-radius: 6px;
background-color: red;
}

#radar .radar-car-self {
background-color: white;
}
2 changes: 1 addition & 1 deletion wwwroot/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ button:hover {
}

button.selected {
background-color: #212121;
background-color: #46290c;
}

.setting {
Expand Down
Binary file added wwwroot/icons/radar-grid-warning-left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wwwroot/icons/radar-grid-warning-right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wwwroot/icons/radar-grid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit fd7ec48

Please sign in to comment.