From e1561223575e81301274258edf57eda5f7ced342 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 26 Mar 2026 00:43:35 +0100 Subject: [PATCH] Fixed ui --- Car simulation/Core/Components/Drivetrain.cs | 11 +++--- Car simulation/UI/DisplayManager.cs | 11 ------ Car simulation/UI/Instruments/Gauge.cs | 3 +- Car simulation/UI/Instruments/Speedometer.cs | 38 ++++---------------- Car simulation/UI/Instruments/Tachometer.cs | 2 +- 5 files changed, 13 insertions(+), 52 deletions(-) diff --git a/Car simulation/Core/Components/Drivetrain.cs b/Car simulation/Core/Components/Drivetrain.cs index 2ca0d6e..15e7ac6 100644 --- a/Car simulation/Core/Components/Drivetrain.cs +++ b/Car simulation/Core/Components/Drivetrain.cs @@ -110,12 +110,11 @@ namespace Car_simulation.Core.Components public string GetCurrentGearName() { - return _currentGear switch - { - -1 => "R", - 0 => "N", - _ => _currentGear.ToString() - }; + if (_currentGear == -1) return "R"; + if (_currentGear == 0) return "N"; + if (_currentGear > 0 && _currentGear <= GearRatios.Length) return _currentGear.ToString(); + + return "??"; // Debugging: if you see this, _currentGear is out of bounds } public float GetClutchSlipPercent() => ClutchSlipRatio * 100f; diff --git a/Car simulation/UI/DisplayManager.cs b/Car simulation/UI/DisplayManager.cs index fa82da5..7765ea0 100644 --- a/Car simulation/UI/DisplayManager.cs +++ b/Car simulation/UI/DisplayManager.cs @@ -176,17 +176,6 @@ namespace Car_simulation.UI _window.Draw(text); } } - - // Draw version info - DrawVersionInfo(); - } - - private void DrawVersionInfo() - { - Text versionText = new Text("Car Simulation v1.0", _font, 10); - versionText.FillColor = new Color(100, 100, 100); - versionText.Position = new Vector2f(_window.Size.X - 120, _window.Size.Y - 15); - _window.Draw(versionText); } public void ToggleDebugInfo() diff --git a/Car simulation/UI/Instruments/Gauge.cs b/Car simulation/UI/Instruments/Gauge.cs index 7f9cb2b..56ba8cd 100644 --- a/Car simulation/UI/Instruments/Gauge.cs +++ b/Car simulation/UI/Instruments/Gauge.cs @@ -27,7 +27,7 @@ namespace Car_simulation.UI.Instruments { _minValue = minValue; _maxValue = maxValue; - _linesPerMark = linesPerMark + _linesPerMark = linesPerMark; _valuePerMark = valuePerMark; _font = font; Position = position; @@ -71,7 +71,6 @@ namespace Car_simulation.UI.Instruments { _value = value; - _minValue float ratio = Math.Clamp(_value / _maxValue, 0f, 1f); float needleAngle = -45 + (270 * ratio); diff --git a/Car simulation/UI/Instruments/Speedometer.cs b/Car simulation/UI/Instruments/Speedometer.cs index b069d6f..ad14bcf 100644 --- a/Car simulation/UI/Instruments/Speedometer.cs +++ b/Car simulation/UI/Instruments/Speedometer.cs @@ -10,7 +10,6 @@ namespace Car_simulation.UI.Instruments private Font _font; private Text _label; private Text _speedText; - private Text _gearText; private Color _normalColor = Color.White; private Color _highlightColor = new Color(0, 150, 255); @@ -18,7 +17,6 @@ namespace Car_simulation.UI.Instruments public float Size { get; set; } = 200f; private float _currentSpeed = 0f; - private string _currentGear = "N"; private const float MAX_SPEED = 200f; // km/h public Speedometer(Font font) @@ -59,7 +57,7 @@ namespace Car_simulation.UI.Instruments _label.FillColor = Color.White; _label.Position = new Vector2f( Position.X + Size / 2 - _label.GetLocalBounds().Width / 2, - Position.Y + Size * 0.05f + Position.Y + Size * 0.80f ); _speedText = new Text("0 km/h", _font, (uint)(Size * 0.1f)); @@ -68,13 +66,6 @@ namespace Car_simulation.UI.Instruments Position.X + Size / 2 - 40, Position.Y + Size * 0.25f ); - - _gearText = new Text($"GEAR {_currentGear}", _font, (uint)(Size * 0.14f)); - _gearText.FillColor = _highlightColor; - _gearText.Position = new Vector2f( - Position.X + Size * 0.5f, - Position.Y + Size * 1.1f - ); } public void Update(float speed) @@ -84,7 +75,7 @@ namespace Car_simulation.UI.Instruments // Update needle angle (-90° to +180° rotation) float speedRatio = Math.Clamp(speedKmh / MAX_SPEED, 0f, 1f); - float needleAngle = -90 + (270 * speedRatio); + float needleAngle = -45 + (270 * speedRatio); _needle.Rotation = needleAngle; // Update speed text @@ -99,20 +90,6 @@ namespace Car_simulation.UI.Instruments ); } - public void UpdateGear(string gear) - { - _currentGear = gear; - _gearText.DisplayedString = $"GEAR {gear}"; - - // Center gear text - FloatRect bounds = _gearText.GetLocalBounds(); - _gearText.Origin = new Vector2f(bounds.Width / 2, bounds.Height / 2); - _gearText.Position = new Vector2f( - Position.X + Size / 2, - Position.Y + Size * 1.1f - ); - } - public void Draw(RenderWindow window) { window.Draw(_background); @@ -123,14 +100,16 @@ namespace Car_simulation.UI.Instruments window.Draw(_needle); window.Draw(_label); window.Draw(_speedText); - window.Draw(_gearText); } private void DrawTickMarks(RenderWindow window) { + float targetAngle = 270; + int marks = 10; + for (int i = 0; i <= 10; i++) { - float angle = -90 + (i * 27); // 270° divided into 10 segments + float angle = 135 + (i * (targetAngle / marks)); // 270° divided into 10 segments float startRadius = Size * 0.45f; float endRadius = Size * 0.42f; @@ -188,11 +167,6 @@ namespace Car_simulation.UI.Instruments Initialize(); // Re-initialize with new size } - public void SetGearColor(Color color) - { - _gearText.FillColor = color; - } - public void SetNeedleColor(Color color) { _needle.FillColor = color; diff --git a/Car simulation/UI/Instruments/Tachometer.cs b/Car simulation/UI/Instruments/Tachometer.cs index 4653de8..5a136c1 100644 --- a/Car simulation/UI/Instruments/Tachometer.cs +++ b/Car simulation/UI/Instruments/Tachometer.cs @@ -59,7 +59,7 @@ namespace Car_simulation.UI.Instruments _rpmText.FillColor = _normalColor; _rpmText.Position = new Vector2f( Position.X + Size / 2 - 20, - Position.Y + Size + Position.Y + Size * 0.25f ); }