Skip to content

Commit d8c7864

Browse files
committed
More overlay fonts, other overlay changes. Bump 3.2.6
1 parent 4a3a643 commit d8c7864

8 files changed

Lines changed: 64 additions & 78 deletions

File tree

ETS2LA.Overlay/Overlay.cs

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121

2222
namespace ETS2LA.Overlay;
2323

24+
public enum FontStyle
25+
{
26+
Regular,
27+
Medium,
28+
SemiBold,
29+
Bold
30+
}
31+
2432
public class OverlayHandler
2533
{
2634
private static readonly Lazy<OverlayHandler> _instance = new(() => new OverlayHandler());
@@ -44,6 +52,7 @@ public class OverlayHandler
4452
private List<float> frameTimes = new List<float>();
4553

4654
private List<InternalWindow> windows = new();
55+
public Dictionary<FontStyle, ImFontPtr> Fonts = new Dictionary<FontStyle, ImFontPtr>();
4756

4857
public bool IsOverlayFocused => isInteracting;
4958
public float AverageFrameTime => frameTimes.Count > 0 ? frameTimes.Average() : 0f;
@@ -278,18 +287,24 @@ private void OnUIRender()
278287
continue;
279288
}
280289

281-
ImGui.SetNextWindowSize(new Vector2(
282-
window.Definition.Width.GetValueOrDefault(480),
283-
window.Definition.Height.GetValueOrDefault(320)
284-
), ImGuiCond.Once);
285-
286-
ImGui.SetNextWindowBgAlpha(window.Definition.Alpha.GetValueOrDefault(1f));
290+
if (window.Definition.Width.HasValue || window.Definition.Height.HasValue)
291+
{
292+
ImGui.SetNextWindowSize(new Vector2(
293+
window.Definition.Width.GetValueOrDefault(480),
294+
window.Definition.Height.GetValueOrDefault(320)
295+
), ImGuiCond.Once);
296+
}
297+
298+
ImGui.SetNextWindowBgAlpha(window.Definition.Alpha.GetValueOrDefault(0.9f));
287299
ImGui.Begin(window.Definition.Title, window.Definition.Flags.GetValueOrDefault(ImGuiWindowFlags.None));
288300

289-
ImGui.SetWindowPos(new Vector2(
290-
(int)window.Definition.X.GetValueOrDefault(OverlayWidth / 2),
291-
(int)window.Definition.Y.GetValueOrDefault(OverlayHeight / 2)
292-
), ImGuiCond.Once);
301+
if (window.Definition.X.HasValue || window.Definition.Y.HasValue)
302+
{
303+
ImGui.SetWindowPos(new Vector2(
304+
(int)window.Definition.X.GetValueOrDefault(OverlayWidth / 2),
305+
(int)window.Definition.Y.GetValueOrDefault(OverlayHeight / 2)
306+
), ImGuiCond.Once);
307+
}
293308

294309
var isCollapsed = ImGui.IsWindowCollapsed();
295310
if (isCollapsed) {
@@ -339,39 +354,45 @@ private bool InitImGui()
339354
io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard; // Enable Keyboard Controls
340355
io.ConfigFlags |= ImGuiConfigFlags.NavEnableGamepad; // Enable Gamepad Controls
341356
io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; // Enable Docking
342-
// TODO: This is disabled for now as it causes submenus to appear below main windows.
343-
//io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable; // Enable Multi-Viewport / Platform Windows
344-
345-
var mon = GLFW.GetPrimaryMonitor();
346-
float mainScale = ImGuiImplGLFW.GetContentScaleForMonitor(Unsafe.BitCast<Hexa.NET.GLFW.GLFWmonitorPtr, Hexa.NET.ImGui.Backends.GLFW.GLFWmonitorPtr>(mon));
357+
io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable; // Enable Multi-Viewport / Platform Windows
347358

359+
// Tweak our styling just a little
348360
ImGui.StyleColorsDark();
349361
var style = ImGui.GetStyle();
350-
// style.ScaleAllSizes(1.5f);
362+
style.WindowRounding = 3.0f;
363+
style.Colors[(int)ImGuiCol.TitleBgActive] = new Vector4(0.1f, 0.1f, 0.1f, 1f);
364+
365+
// And then we scale by the monitor DPI
366+
var mon = GLFW.GetPrimaryMonitor();
367+
float mainScale = ImGuiImplGLFW.GetContentScaleForMonitor(Unsafe.BitCast<Hexa.NET.GLFW.GLFWmonitorPtr, Hexa.NET.ImGui.Backends.GLFW.GLFWmonitorPtr>(mon));
351368

352369
style.ScaleAllSizes(mainScale);
353370
style.FontScaleDpi = mainScale;
354371
io.ConfigDpiScaleFonts = true;
355372
io.ConfigDpiScaleViewports = true;
356373

357-
if ((io.ConfigFlags & ImGuiConfigFlags.ViewportsEnable) != 0)
374+
List<Tuple<FontStyle, string>> fonts = new List<Tuple<FontStyle, string>>()
358375
{
359-
style.WindowRounding = 0.0f;
360-
}
376+
new Tuple<FontStyle, string>(FontStyle.Medium, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "Fonts", "Geist-Medium.ttf")),
377+
new Tuple<FontStyle, string>(FontStyle.Regular, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "Fonts", "Geist-Regular.ttf")),
378+
new Tuple<FontStyle, string>(FontStyle.SemiBold, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "Fonts", "Geist-SemiBold.ttf")),
379+
new Tuple<FontStyle, string>(FontStyle.Bold, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "Fonts", "Geist-Bold.ttf")),
380+
};
361381

362382
// Set fonts
363383
unsafe
364384
{
365-
string fontPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Assets", "Fonts", "Geist-Medium.ttf");
366-
if (!File.Exists(fontPath))
385+
for (int i = 0; i < fonts.Count; i++)
367386
{
368-
Logger.Error($"Font file not found at {fontPath}");
369-
// style.FontSizeBase = 18f;
370-
}
371-
else
372-
{
373-
io.Fonts.AddFontFromFileTTF(fontPath);
374-
style.FontSizeBase = 18f;
387+
string fontPath = fonts[i].Item2;
388+
if (!File.Exists(fontPath))
389+
{
390+
Logger.Error($"Font file not found at {fontPath}");
391+
continue;
392+
}
393+
ImFont* font = io.Fonts.AddFontFromFileTTF(fontPath, 18f);
394+
ImFontPtr fontPtr = new ImFontPtr(font);
395+
Fonts[fonts[i].Item1] = fontPtr;
375396
}
376397
}
377398

ETS2LA.Overlay/Window/OverlayInfo.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public OverlayInfoWindow()
1111
Definition = new WindowDefinition
1212
{
1313
Title = "Overlay Info",
14-
Flags = ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings,
14+
Flags = ImGuiWindowFlags.AlwaysAutoResize,
1515
};
1616

1717
Render = () =>
@@ -25,10 +25,14 @@ public OverlayInfoWindow()
2525
ImGui.SameLine();
2626
var controls = ControlsBackend.Current.GetRegisteredControls();
2727
var interactKey = controls.FirstOrDefault(c => c.Definition.Id == OverlayHandler.Current.Interact.Id);
28+
29+
ImGui.PushFont(OverlayHandler.Current.Fonts[FontStyle.Bold], 18f);
2830
if (interactKey != null)
2931
ImGui.TextColored(new Vector4(1f, 0.5f, 0.5f, 1f), interactKey.ControlId.ToString());
3032
else
3133
ImGui.TextColored(new Vector4(1f, 0.5f, 0.5f, 1f), "UNBOUND");
34+
ImGui.PopFont();
35+
3236
ImGui.SameLine();
3337
ImGui.Text("(can be changed in the settings!)");
3438
ImGui.Text("The overlay is pretty much a full window system, there shouldn't be any crashes... hopefully... but if there are, report them!");

ETS2LA.Overlay/Window/StateWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public StateWindow()
3030
Definition = new WindowDefinition
3131
{
3232
Title = "State Info",
33-
Flags = ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings,
33+
Flags = ImGuiWindowFlags.AlwaysAutoResize,
3434
};
3535

3636
Render = () =>

ETS2LA.UI/MainWindow.axaml.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ private enum PageKind
3737
private readonly ManagerView managerView;
3838
private readonly SettingsView settingsView;
3939
public static event EventHandler? WindowOpened;
40-
41-
# if WINDOWS
42-
private readonly VisualizationView? visualizationView;
43-
# else
44-
private readonly UserControl? visualizationView = null;
45-
# endif
4640

4741

4842
public MainWindow()
@@ -55,10 +49,6 @@ public MainWindow()
5549

5650
UINotificationHandler.Current.SetWindow(this);
5751

58-
# if WINDOWS
59-
visualizationView = new VisualizationView();
60-
# endif
61-
6252
pluginService = new PluginManagerService();
6353
managerView = new ManagerView(pluginService);
6454
settingsView = new SettingsView();
@@ -198,7 +188,7 @@ private void ShowPage(PageKind page)
198188
{
199189
PageKind.Dashboard => dashboardView,
200190
PageKind.Manager => managerView,
201-
PageKind.Visualization => visualizationView ?? CreatePlaceholder("Sorry", "This page is only available on Windows. You can still use the visualization and map by going to https://visualization.ets2la.com (or https://map.ets2la.com)."),
191+
PageKind.Visualization => CreatePlaceholder("Sorry", "This page is being remade and isn't available in this version. It will return in a future update post open beta release."),
202192
PageKind.Catalogue => CreatePlaceholder("Catalogue", "This page will contain 3rd party plugins. Those aren't supported yet, you can copy them manually to the plugins folder and restart."),
203193
PageKind.Performance => CreatePlaceholder("Performance", "This page hasn't been implemented yet, you can monitor performance using external tools."),
204194
PageKind.Wiki => CreatePlaceholder("Wiki", "Please take a look at https://docs.ets2la.com for documentation. This page will link there once we have more content."),

ETS2LA.UI/Views/VisualizationView.axaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

ETS2LA.UI/Views/VisualizationView.axaml.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

ETS2LA/ETS2LA.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<Title>ETS2LA</Title>
1010
<Description>Self driving for ETS2 and ATS.</Description>
11-
<Version>3.2.5</Version>
11+
<Version>3.2.6</Version>
1212
</PropertyGroup>
1313

1414
<ItemGroup>

ETS2LA/ReleaseNotes.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
### ETS2LA C# 3.2.5
2-
* Created a new toggle element for use in UI.
3-
* Implemented `Display` settings page in the UI.
4-
* Implemented overlay framerate limiting. By default the overlay will now limit itself to 30fps. This cuts ETS2LA's CPU usage by around 60-70% on an R7 5800x3d.
5-
* Added a setting for changing the maximum AR rendering distance, default is now 150m.
6-
* Added a setting to disable AR rendering entirely.
7-
* Implemented new `UnitConversion` class, as well as a setting to change default units. Once ETS2LA starts adding UI, all displayed values will follow this setting.
1+
### ETS2LA C# 3.2.6
2+
* Added ability for developers to use several different fonts in the overlay, as well as the ability to specify their font size.
3+
* Overlay windows are now slightly translucent, and they have are slightly rounded.
4+
* Removed blue highlight from currently focused window title, it is now slightly more grey instead.
5+
* Removed visualization page entirely, as it's going to be remade in the future.
6+
* Removed `ImGui.NoSavedSettings` flag from default windows.
7+
* Only applying position and size to windows if defined, else they will use previously saved position and sizing.
88

99
**WARNING:** ETS2LA C# on Linux requires Linux specific SDKs. These can be found on the closed beta Discord, as they aren't yet included in ETS2LA C#.
1010

0 commit comments

Comments
 (0)