This commit is contained in:
max
2026-03-26 00:43:35 +01:00
parent 932734e5b4
commit e156122357
5 changed files with 13 additions and 52 deletions

View File

@@ -110,12 +110,11 @@ namespace Car_simulation.Core.Components
public string GetCurrentGearName() public string GetCurrentGearName()
{ {
return _currentGear switch if (_currentGear == -1) return "R";
{ if (_currentGear == 0) return "N";
-1 => "R", if (_currentGear > 0 && _currentGear <= GearRatios.Length) return _currentGear.ToString();
0 => "N",
_ => _currentGear.ToString() return "??"; // Debugging: if you see this, _currentGear is out of bounds
};
} }
public float GetClutchSlipPercent() => ClutchSlipRatio * 100f; public float GetClutchSlipPercent() => ClutchSlipRatio * 100f;

View File

@@ -176,17 +176,6 @@ namespace Car_simulation.UI
_window.Draw(text); _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() public void ToggleDebugInfo()

View File

@@ -27,7 +27,7 @@ namespace Car_simulation.UI.Instruments
{ {
_minValue = minValue; _minValue = minValue;
_maxValue = maxValue; _maxValue = maxValue;
_linesPerMark = linesPerMark _linesPerMark = linesPerMark;
_valuePerMark = valuePerMark; _valuePerMark = valuePerMark;
_font = font; _font = font;
Position = position; Position = position;
@@ -71,7 +71,6 @@ namespace Car_simulation.UI.Instruments
{ {
_value = value; _value = value;
_minValue
float ratio = Math.Clamp(_value / _maxValue, 0f, 1f); float ratio = Math.Clamp(_value / _maxValue, 0f, 1f);
float needleAngle = -45 + (270 * ratio); float needleAngle = -45 + (270 * ratio);

View File

@@ -10,7 +10,6 @@ namespace Car_simulation.UI.Instruments
private Font _font; private Font _font;
private Text _label; private Text _label;
private Text _speedText; private Text _speedText;
private Text _gearText;
private Color _normalColor = Color.White; private Color _normalColor = Color.White;
private Color _highlightColor = new Color(0, 150, 255); private Color _highlightColor = new Color(0, 150, 255);
@@ -18,7 +17,6 @@ namespace Car_simulation.UI.Instruments
public float Size { get; set; } = 200f; public float Size { get; set; } = 200f;
private float _currentSpeed = 0f; private float _currentSpeed = 0f;
private string _currentGear = "N";
private const float MAX_SPEED = 200f; // km/h private const float MAX_SPEED = 200f; // km/h
public Speedometer(Font font) public Speedometer(Font font)
@@ -59,7 +57,7 @@ namespace Car_simulation.UI.Instruments
_label.FillColor = Color.White; _label.FillColor = Color.White;
_label.Position = new Vector2f( _label.Position = new Vector2f(
Position.X + Size / 2 - _label.GetLocalBounds().Width / 2, 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)); _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.X + Size / 2 - 40,
Position.Y + Size * 0.25f 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) public void Update(float speed)
@@ -84,7 +75,7 @@ namespace Car_simulation.UI.Instruments
// Update needle angle (-90° to +180° rotation) // Update needle angle (-90° to +180° rotation)
float speedRatio = Math.Clamp(speedKmh / MAX_SPEED, 0f, 1f); float speedRatio = Math.Clamp(speedKmh / MAX_SPEED, 0f, 1f);
float needleAngle = -90 + (270 * speedRatio); float needleAngle = -45 + (270 * speedRatio);
_needle.Rotation = needleAngle; _needle.Rotation = needleAngle;
// Update speed text // 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) public void Draw(RenderWindow window)
{ {
window.Draw(_background); window.Draw(_background);
@@ -123,14 +100,16 @@ namespace Car_simulation.UI.Instruments
window.Draw(_needle); window.Draw(_needle);
window.Draw(_label); window.Draw(_label);
window.Draw(_speedText); window.Draw(_speedText);
window.Draw(_gearText);
} }
private void DrawTickMarks(RenderWindow window) private void DrawTickMarks(RenderWindow window)
{ {
float targetAngle = 270;
int marks = 10;
for (int i = 0; i <= 10; i++) 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 startRadius = Size * 0.45f;
float endRadius = Size * 0.42f; float endRadius = Size * 0.42f;
@@ -188,11 +167,6 @@ namespace Car_simulation.UI.Instruments
Initialize(); // Re-initialize with new size Initialize(); // Re-initialize with new size
} }
public void SetGearColor(Color color)
{
_gearText.FillColor = color;
}
public void SetNeedleColor(Color color) public void SetNeedleColor(Color color)
{ {
_needle.FillColor = color; _needle.FillColor = color;

View File

@@ -59,7 +59,7 @@ namespace Car_simulation.UI.Instruments
_rpmText.FillColor = _normalColor; _rpmText.FillColor = _normalColor;
_rpmText.Position = new Vector2f( _rpmText.Position = new Vector2f(
Position.X + Size / 2 - 20, Position.X + Size / 2 - 20,
Position.Y + Size Position.Y + Size * 0.25f
); );
} }