diff --git a/RaceOverlay/API/Overlays/Electronics/Electronics.html b/RaceOverlay/API/Overlays/Electronics/Electronics.html index 16ceb5a..be28281 100644 --- a/RaceOverlay/API/Overlays/Electronics/Electronics.html +++ b/RaceOverlay/API/Overlays/Electronics/Electronics.html @@ -1,13 +1,12 @@ - - - - - Electronics - - - - -
-
-
ABS
-
5
- -
TC1
-
3
- -
TC2
-
1
- -
BB
-
54.2
- -
ARB F
-
4
- -
ARB R
-
2
-
- + gap: 10px; /* Spacing between columns (and rows, if more than 2 fixed rows) */ + } + + .grid-item { + padding: 10px; /* Padding within each item (header or value cell) */ + /* border: 1px solid #555; /* Uncomment for debugging item boundaries */ + } + + + + +
+
+
ABS
+
5
+ +
TC1
+
3
+ +
TC2
+
1
+ +
BB
+
54.2
+ +
ARB F
+
4
+ +
ARB R
+
2
+
+ + - // Update every 16ms (approximately 60fps) - setInterval(updateInputs, 16); - - - - + + \ No newline at end of file diff --git a/RaceOverlay/API/Overlays/Electronics/ElectronicsModel.cs b/RaceOverlay/API/Overlays/Electronics/ElectronicsModel.cs index 4555ba0..ee08568 100644 --- a/RaceOverlay/API/Overlays/Electronics/ElectronicsModel.cs +++ b/RaceOverlay/API/Overlays/Electronics/ElectronicsModel.cs @@ -10,6 +10,12 @@ public class ElectronicsModel public float bb { get; set; } public int abrf { get; set; } public int abrr { get; set; } + public bool show_abs { get; set; } + public bool show_tc1 { get; set; } + public bool show_tc2 { get; set; } + public bool show_brake_bias { get; set; } + public bool show_arb_front { get; set; } + public bool show_arb_rear { get; set; } public ElectronicsModel() { @@ -20,6 +26,12 @@ public ElectronicsModel() bb = iRacingData.LocalCarTelemetry.BrakeBias; abrf = (int) iRacingData.LocalCarTelemetry.ARBFront; abrr = (int) iRacingData.LocalCarTelemetry.ARBRear; + show_abs = StreamOverlay.Electronics.Electronics.ShowABS; + show_tc1 = StreamOverlay.Electronics.Electronics.ShowTC1; + show_tc2 = StreamOverlay.Electronics.Electronics.ShowTC2; + show_brake_bias = StreamOverlay.Electronics.Electronics.ShowBrakeBias; + show_arb_front = StreamOverlay.Electronics.Electronics.ShowARBFront; + show_arb_rear = StreamOverlay.Electronics.Electronics.ShowARBRear; } } \ No newline at end of file diff --git a/RaceOverlay/API/StartAPI.cs b/RaceOverlay/API/StartAPI.cs index 4a8c8e3..c7bd56a 100644 --- a/RaceOverlay/API/StartAPI.cs +++ b/RaceOverlay/API/StartAPI.cs @@ -81,7 +81,7 @@ public static IHost StartApiServer() // - // Setuphider + // Setup hider // endpoints.MapGet("/overlay/setup_hider", () => @@ -105,6 +105,7 @@ public static IHost StartApiServer() { Debug.WriteLine("GetSetupHiderOverlayData"); SetupHiderModel data = new SetupHiderModel(); + data.InGarage = true; return Results.Ok(data); }) .WithName("GetSetupHiderOverlayData"); diff --git a/RaceOverlay/Internals/StreamOverlay.cs b/RaceOverlay/Internals/StreamOverlay.cs index 0301654..8635189 100644 --- a/RaceOverlay/Internals/StreamOverlay.cs +++ b/RaceOverlay/Internals/StreamOverlay.cs @@ -1,3 +1,7 @@ +using System.IO; +using System.Windows.Controls; +using Newtonsoft.Json.Linq; + namespace RaceOverlay.Internals; /// @@ -21,5 +25,285 @@ public StreamOverlay(string title, string description, string link) Description = description; Link = link; } + + /// + /// Method to get the configuration values of the overlay. + /// + /// All values need to be set as public static properties in the derived class to get those in the Objects. + protected virtual void _getConfig() + { + + } + + /// + /// Method to get the configuration of the overlay for showing in the MainWindow. + /// + /// Please override this method the virtual method returns an empty Grid. + /// Grid which will show when selected in the Main Window. + public virtual Grid GetConfig() + { + return new Grid(); + } + + + /// + /// Mehtod to get a string configuration value from the settings.json file.
+ ///
+ /// Json key which will be used to save and load the config value + /// String which is saved by the user or an empty string + protected string _getStringConfig(string key) + { + string settingsFilePath = Path.Combine(App.AppDataPath, "settings.json"); + string jsonContent = File.ReadAllText(settingsFilePath); + JObject settingsObject = JObject.Parse(jsonContent); + + // Ensure the required structure exists + if (settingsObject["Overlays"] == null) + { + settingsObject["Overlays"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"] == null) + { + settingsObject["Overlays"][Title + "StreamOverlay"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"] == null) + { + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] != null) + { + return settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key].ToString(); + } + + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] = ""; + File.WriteAllText(settingsFilePath, settingsObject.ToString()); + return ""; + } + + /// + /// Method to set a string configuration value in the settings.json file.
+ ///
+ /// Json key which will be used to safe and load the config value + /// Value which will set into the config + protected void _setStringConfig(string key, string value) + { + string settingsFilePath = Path.Combine(App.AppDataPath, "settings.json"); + string jsonContent = File.ReadAllText(settingsFilePath); + JObject settingsObject = JObject.Parse(jsonContent); + + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] = value; + File.WriteAllText(settingsFilePath, settingsObject.ToString()); + } + + /// + /// Method to get an integer configuration value from the settings.json file.
+ ///
+ /// Json key which will be used to save and load the config value + /// Int which is saved by the user or 0 + protected int _getIntConfig(string key) + { + string settingsFilePath = Path.Combine(App.AppDataPath, "settings.json"); + string jsonContent = File.ReadAllText(settingsFilePath); + JObject settingsObject = JObject.Parse(jsonContent); + + // Ensure the required structure exists + if (settingsObject["Overlays"] == null) + { + settingsObject["Overlays"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"] == null) + { + settingsObject["Overlays"][Title + "StreamOverlay"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"] == null) + { + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] != null) + { + return (int)settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key]; + } + + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] = 0; + File.WriteAllText(settingsFilePath, settingsObject.ToString()); + return 0; + } + + /// + /// Method to set an integer configuration value in the settings.json file.
+ ///
+ /// Json key which will be used to safe and load the config value + /// Value which will set into the config + protected void _setIntConfig(string key, int value) + { + string settingsFilePath = Path.Combine(App.AppDataPath, "settings.json"); + string jsonContent = File.ReadAllText(settingsFilePath); + JObject settingsObject = JObject.Parse(jsonContent); + + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] = value; + File.WriteAllText(settingsFilePath, settingsObject.ToString()); + } + + /// + /// Method to get a float configuration value from the settings.json file.
+ ///
+ /// Json key which will be used to save and load the config value + /// float which is saved by the user or 0 + protected float _getFloatConfig(string key) + { + string settingsFilePath = Path.Combine(App.AppDataPath, "settings.json"); + string jsonContent = File.ReadAllText(settingsFilePath); + JObject settingsObject = JObject.Parse(jsonContent); + + // Ensure the required structure exists + if (settingsObject["Overlays"] == null) + { + settingsObject["Overlays"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"] == null) + { + settingsObject["Overlays"][Title + "StreamOverlay"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"] == null) + { + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] != null) + { + return (float)settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key]; + } + + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] = 0; + File.WriteAllText(settingsFilePath, settingsObject.ToString()); + return 0; + } + + /// + /// Method to set a float configuration value in the settings.json file.
+ ///
+ /// Json key which will be used to safe and load the config value + /// Value which will set into the config + protected void _setFloatConfig(string key, float value) + { + string settingsFilePath = Path.Combine(App.AppDataPath, "settings.json"); + string jsonContent = File.ReadAllText(settingsFilePath); + JObject settingsObject = JObject.Parse(jsonContent); + + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] = value; + File.WriteAllText(settingsFilePath, settingsObject.ToString()); + } + + /// + /// Method to get a double configuration value from the settings.json file.
+ ///
+ /// Json key which will be used to save and load the config value + /// Double which is saved by the user or 0 + protected double _getDoubleConfig(string key) + { + string settingsFilePath = Path.Combine(App.AppDataPath, "settings.json"); + string jsonContent = File.ReadAllText(settingsFilePath); + JObject settingsObject = JObject.Parse(jsonContent); + + // Ensure the required structure exists + if (settingsObject["Overlays"] == null) + { + settingsObject["Overlays"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"] == null) + { + settingsObject["Overlays"][Title + "StreamOverlay"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"] == null) + { + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] != null) + { + return (double)settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key]; + } + + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] = 0; + File.WriteAllText(settingsFilePath, settingsObject.ToString()); + return 0; + } + + /// + /// Method to set a double configuration value in the settings.json file.
+ ///
+ /// Json key which will be used to safe and load the config value + /// Value which will set into the config + protected void _setDoubleConfig(string key, double value) + { + string settingsFilePath = Path.Combine(App.AppDataPath, "settings.json"); + string jsonContent = File.ReadAllText(settingsFilePath); + JObject settingsObject = JObject.Parse(jsonContent); + + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] = value; + File.WriteAllText(settingsFilePath, settingsObject.ToString()); + } + + /// + /// Method to get a boolean configuration value from the settings.json file.
+ ///
+ /// Json key which will be used to save and load the config value + /// Bool which is saved by the user or false + protected bool _getBoolConfig(string key) + { + string settingsFilePath = Path.Combine(App.AppDataPath, "settings.json"); + string jsonContent = File.ReadAllText(settingsFilePath); + JObject settingsObject = JObject.Parse(jsonContent); + + // Ensure the required structure exists + if (settingsObject["Overlays"] == null) + { + settingsObject["Overlays"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"] == null) + { + settingsObject["Overlays"][Title + "StreamOverlay"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"] == null) + { + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"] = new JObject(); + } + + if (settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] != null) + { + return (bool)settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key]; + } + + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] = false; + File.WriteAllText(settingsFilePath, settingsObject.ToString()); + return false; + } + + /// + /// Method to set a boolean configuration value in the settings.json file.
+ ///
+ /// Json key which will be used to safe and load the config value + /// Value which will set into the config + protected void _setBoolConfig(string key, bool value) + { + string settingsFilePath = Path.Combine(App.AppDataPath, "settings.json"); + string jsonContent = File.ReadAllText(settingsFilePath); + JObject settingsObject = JObject.Parse(jsonContent); + + settingsObject["Overlays"][Title + "StreamOverlay"]["Configs"][key] = value; + File.WriteAllText(settingsFilePath, settingsObject.ToString()); + } } \ No newline at end of file diff --git a/RaceOverlay/MainWindow.xaml b/RaceOverlay/MainWindow.xaml index 0bbacbe..4816327 100644 --- a/RaceOverlay/MainWindow.xaml +++ b/RaceOverlay/MainWindow.xaml @@ -159,14 +159,14 @@ - + - + + { + ShowABS = true; + _setBoolConfig("show_abs", ShowABS); + + }; + absElement.CheckBox.Unchecked += (sender, args) => + { + ShowABS = false; + _setBoolConfig("show_abs", ShowABS); + + }; + Grid.SetRow(absElement, 1); + Grid.SetColumn(absElement, 0); + grid.Children.Add(absElement); + + CheckBoxElement tc1Element = new CheckBoxElement("Show TC1: ", ShowTC1); + + tc1Element.CheckBox.Checked += (sender, args) => + { + ShowTC1 = true; + _setBoolConfig("show_tc1", ShowTC1); + + }; + tc1Element.CheckBox.Unchecked += (sender, args) => + { + ShowTC1 = false; + _setBoolConfig("show_tc1", ShowTC1); + + }; + Grid.SetRow(tc1Element, 0); + Grid.SetColumn(tc1Element, 0); + grid.Children.Add(tc1Element); + + CheckBoxElement tc2Element = new CheckBoxElement("Show TC2: ", ShowTC2); + + tc2Element.CheckBox.Checked += (sender, args) => + { + ShowTC2 = true; + _setBoolConfig("show_tc2", ShowTC2); + + }; + tc2Element.CheckBox.Unchecked += (sender, args) => + { + ShowTC2 = false; + _setBoolConfig("show_tc2", ShowTC2); + + }; + Grid.SetRow(tc2Element, 0); + Grid.SetColumn(tc2Element, 1); + grid.Children.Add(tc2Element); + + CheckBoxElement bbElement = new CheckBoxElement("Show Brake Bias: ", ShowBrakeBias); + bbElement.CheckBox.Checked += (sender, args) => + { + ShowBrakeBias = true; + _setBoolConfig("show_brake_bias", ShowBrakeBias); + + }; + bbElement.CheckBox.Unchecked += (sender, args) => + { + ShowBrakeBias = false; + _setBoolConfig("show_brake_bias", ShowBrakeBias); + + }; + Grid.SetRow(bbElement, 1); + Grid.SetColumn(bbElement, 1); + grid.Children.Add(bbElement); + + CheckBoxElement ARBFrontElement = new CheckBoxElement("Show ARB Front: ", ShowARBFront); + ARBFrontElement.CheckBox.Checked += (sender, args) => + { + ShowARBFront = true; + _setBoolConfig("show_arb_front", ShowARBFront); + + }; + + ARBFrontElement.CheckBox.Unchecked += (sender, args) => + { + ShowARBFront = false; + _setBoolConfig("show_arb_front", ShowARBFront); + + }; + Grid.SetRow(ARBFrontElement, 2); + Grid.SetColumn(ARBFrontElement, 0); + grid.Children.Add(ARBFrontElement); + + CheckBoxElement ARBRearElement = new CheckBoxElement("Show ARB Rear: ", ShowARBRear); + ARBRearElement.CheckBox.Checked += (sender, args) => + { + ShowARBRear = true; + _setBoolConfig("show_arb_rear", ShowARBRear); + + }; + + ARBRearElement.CheckBox.Unchecked += (sender, args) => + { + ShowARBRear = false; + _setBoolConfig("show_arb_rear", ShowARBRear); + + }; + + Grid.SetRow(ARBRearElement, 2); + Grid.SetColumn(ARBRearElement, 1); + grid.Children.Add(ARBRearElement); + + return grid; } } \ No newline at end of file diff --git a/RaceOverlay/StreamOverlay/SetupHider/SetupHider.cs b/RaceOverlay/StreamOverlay/SetupHider/SetupHider.cs index 1579b35..2357b38 100644 --- a/RaceOverlay/StreamOverlay/SetupHider/SetupHider.cs +++ b/RaceOverlay/StreamOverlay/SetupHider/SetupHider.cs @@ -1,10 +1,168 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Shapes; +using Microsoft.Win32; +using System.IO; +using Path = System.IO.Path; +using ShapesPath = System.Windows.Shapes.Path; + namespace RaceOverlay.StreamOverlay.SetupHider; public class SetupHider: Internals.StreamOverlay { - public SetupHider() : base("Setup Hider", - "This Overlay provides an hider for setups while car is in Garage.", + public SetupHider() : base("Setup Hider", + "This Overlay provides an hider for setups while car is in Garage.", "http://localhost:5480/overlay/setup_hider") { } + + public override Grid GetConfig() + { + Grid grid = new Grid(); + + // Create the main button + Button uploadButton = new Button + { + Width = 240, + Height = 40, + Background = new SolidColorBrush(Color.FromRgb(51, 51, 51)), // Dark gray + BorderBrush = Brushes.Transparent, + BorderThickness = new Thickness(0), + Cursor = System.Windows.Input.Cursors.Hand, + Margin = new Thickness(20) + }; + + // Create rounded corners + uploadButton.Style = CreateButtonStyle(); + + // Create the content panel + StackPanel contentPanel = new StackPanel + { + Orientation = Orientation.Horizontal, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center + }; + + // Create upload icon (using a simple path geometry) + ShapesPath uploadIcon = new ShapesPath + { + Data = Geometry.Parse("M12 4L12 14 M8 8L12 4 16 8 M4 18L20 18"), + Stroke = Brushes.White, + StrokeThickness = 1.5, + StrokeLineJoin = PenLineJoin.Round, + Width = 16, + Height = 16, + Margin = new Thickness(0, 0, 8, 0), + Stretch = Stretch.Uniform + }; + + // Create text label + TextBlock uploadText = new TextBlock + { + Text = "Upload new Setup Hider Image", + Foreground = Brushes.White, + FontFamily = new FontFamily("Segoe UI"), + FontSize = 13, + FontWeight = FontWeights.Medium, + VerticalAlignment = VerticalAlignment.Center + }; + + // Add icon and text to content panel + contentPanel.Children.Add(uploadIcon); + contentPanel.Children.Add(uploadText); + + // Set button content + uploadButton.Content = contentPanel; + + // Add click event handler + uploadButton.Click += UploadButton_Click; + grid.Children.Add(uploadButton); + return grid; + } + + private Style CreateButtonStyle() + { + Style buttonStyle = new Style(typeof(Button)); + + // Set the template to create rounded corners and hover effects + ControlTemplate template = new ControlTemplate(typeof(Button)); + + FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border)); + border.Name = "border"; + border.SetValue(Border.BackgroundProperty, new TemplateBindingExtension(Button.BackgroundProperty)); + border.SetValue(Border.BorderBrushProperty, new TemplateBindingExtension(Button.BorderBrushProperty)); + border.SetValue(Border.BorderThicknessProperty, new TemplateBindingExtension(Button.BorderThicknessProperty)); + border.SetValue(Border.CornerRadiusProperty, new CornerRadius(20)); + + FrameworkElementFactory contentPresenter = new FrameworkElementFactory(typeof(ContentPresenter)); + contentPresenter.SetValue(ContentPresenter.HorizontalAlignmentProperty, HorizontalAlignment.Center); + contentPresenter.SetValue(ContentPresenter.VerticalAlignmentProperty, VerticalAlignment.Center); + + border.AppendChild(contentPresenter); + template.VisualTree = border; + + // Add triggers for hover effect + Trigger mouseOverTrigger = new Trigger + { + Property = Button.IsMouseOverProperty, + Value = true + }; + mouseOverTrigger.Setters.Add(new Setter(Button.BackgroundProperty, new SolidColorBrush(Color.FromRgb(71, 71, 71)))); + + template.Triggers.Add(mouseOverTrigger); + + buttonStyle.Setters.Add(new Setter(Button.TemplateProperty, template)); + + return buttonStyle; + } + + + private void UploadButton_Click(object sender, RoutedEventArgs e) + { + try + { + // Create file dialog for JPG files only + OpenFileDialog dialog = new OpenFileDialog + { + Title = "Select JPG Image", + Filter = "JPG Images (*.jpg)|*.jpg", + FilterIndex = 1, + Multiselect = false + }; + + if (dialog.ShowDialog() == true) + { + string selectedFile = dialog.FileName; + + // Verify the file is actually a JPG (double-check extension) + if (!Path.GetExtension(selectedFile).Equals(".jpg", StringComparison.OrdinalIgnoreCase)) + { + MessageBox.Show("Only JPG files are allowed.", "Invalid File Type", + MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + + // Verwende immer den festen Namen "SetupHider.jpg" + string destinationPath = Path.Combine(App.AppDataPath, "SetupHider.jpg"); + + // Überschreibe die Datei, wenn sie existiert + if (File.Exists(destinationPath)) + { + File.Delete(destinationPath); + } + + // Kopiere die Datei + File.Copy(selectedFile, destinationPath); + + MessageBox.Show($"JPG image uploaded successfully!\nSaved to: {destinationPath}", + "Upload Complete", MessageBoxButton.OK, MessageBoxImage.Information); + } + } + catch (Exception ex) + { + MessageBox.Show($"Error uploading file: {ex.Message}", "Upload Error", + MessageBoxButton.OK, MessageBoxImage.Error); + } + } } \ No newline at end of file