major rework
This commit is contained in:
73
Car simulation/UI/Instruments/InstrumentPanel.cs
Normal file
73
Car simulation/UI/Instruments/InstrumentPanel.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Car_simulation.Core.Models;
|
||||
using SFML.Graphics;
|
||||
using SFML.System;
|
||||
|
||||
namespace Car_simulation.UI.Instruments
|
||||
{
|
||||
public class InstrumentPanel
|
||||
{
|
||||
private List<Text> _displayTexts = new List<Text>();
|
||||
private Tachometer _tachometer;
|
||||
private Speedometer _speedometer;
|
||||
private Font _font;
|
||||
|
||||
private Color _textColor = Color.White;
|
||||
|
||||
public InstrumentPanel(Font font, Vector2f tachometerPosition, Vector2f speedometerPosition)
|
||||
{
|
||||
_font = font;
|
||||
_tachometer = new Tachometer(font, tachometerPosition, 200, 7000);
|
||||
_speedometer = new Speedometer(font, speedometerPosition, 200);
|
||||
InitializeDisplayTexts();
|
||||
}
|
||||
|
||||
private void InitializeDisplayTexts()
|
||||
{
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
Text text = new Text("", _font, 16);
|
||||
text.FillColor = Color.White;
|
||||
text.Position = new Vector2f(20, 20 + i * 24);
|
||||
_displayTexts.Add(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(Car_simulation.Core.Models.Car car)
|
||||
{
|
||||
UpdateTextDisplay(car);
|
||||
_tachometer.Update(car.Engine.RPM);
|
||||
_speedometer.Update(car.Speed);
|
||||
}
|
||||
|
||||
private void UpdateTextDisplay(Car car)
|
||||
{
|
||||
var displayData = car.GetDisplayData();
|
||||
|
||||
// Just put each line in a text element
|
||||
for (int i = 0; i < _displayTexts.Count; i++)
|
||||
{
|
||||
if (i < displayData.Count)
|
||||
{
|
||||
_displayTexts[i].DisplayedString = displayData[i];
|
||||
_displayTexts[i].FillColor = _textColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
_displayTexts[i].DisplayedString = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(RenderWindow window)
|
||||
{
|
||||
foreach (var text in _displayTexts)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(text.DisplayedString))
|
||||
window.Draw(text);
|
||||
}
|
||||
|
||||
_tachometer.Draw(window);
|
||||
_speedometer.Draw(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user