Fixed ui
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user