You can now see up to 4 of the battles that are going on (You can even click on the drivers to see them on the bottom of the screen)

This commit is contained in:
2023-05-24 13:54:42 +02:00
parent e4edd71adc
commit f356d90c35
5 changed files with 189 additions and 53 deletions
+135 -27
View File
@@ -13,9 +13,9 @@ namespace Test_Merge
private Reader Reader;
private SqliteStorage Storage;
List<List<DriverData>> LiveDriverDataLogs = new List<List<DriverData>>();
public DataWrapper(string configFile,Bitmap screenshot)
public DataWrapper(string configFile, Bitmap screenshot)
{
Reader = new Reader(configFile,screenshot, true);
Reader = new Reader(configFile, screenshot, true);
Storage = Reader.Storage;
}
public int Refresh()
@@ -29,38 +29,144 @@ namespace Test_Merge
{
Reader.ChangeImage(image);
}
public DriverData GetFullDriverData(string driverName,Panel lastFiveLapsPanel)
public DriverData GetFullDriverData(string driverName, Panel lastFiveLapsPanel, Form1 form1)
{
DriverData result = new DriverData();
foreach (DriverData data in LiveDriverDataLogs[LiveDriverDataLogs.Count - 1])
if (LiveDriverDataLogs.Count > 0)
{
if (data.Name == driverName)
result = data;
}
if(result.Name != "")
{
lastFiveLapsPanel.Controls.Clear();
Size labelDimensions = new Size(lastFiveLapsPanel.Width,lastFiveLapsPanel.Height / 5);
List<(int LapTime, int Lap)> lapsInfos = Storage.GetDriverLaptimes(driverName,5);
foreach ((int LapTime, int Lap) lapData in lapsInfos)
foreach (DriverData data in LiveDriverDataLogs[LiveDriverDataLogs.Count - 1])
{
Button newButton = new Button();
newButton.Name = driverName + "_" + lapData.Lap;
newButton.Text = Reader.ConvertMsToTime(lapData.LapTime);
if (data.Name == driverName)
result = data;
}
lastFiveLapsPanel.Controls.Add(newButton);
if (result.Name != "")
{
lastFiveLapsPanel.Controls.Clear();
Size labelDimensions = new Size(lastFiveLapsPanel.Width, lastFiveLapsPanel.Height / 5);
List<(int LapTime, int Lap)> lapsInfos = Storage.GetDriverLaptimes(driverName, 5);
foreach ((int LapTime, int Lap) lapData in lapsInfos)
{
Button newButton = new Button();
lastFiveLapsPanel.Controls.Add(newButton);
newButton.Name = driverName + "_" + lapData.Lap;
newButton.Text = Reader.ConvertMsToTime(lapData.LapTime);
newButton.Size = labelDimensions;
newButton.Click += form1.btnLapTime_Click;
}
}
}
return result;
}
public void DisplayBattles(Panel pnlBattles,Form1 form1)
{
DriverData oldDriver = null;
List<(DriverData d1, DriverData d2, int gap)> battles = new List<(DriverData d1, DriverData d2, int gap)>();
foreach (DriverData driver in LiveDriverDataLogs[LiveDriverDataLogs.Count - 1])
{
if (oldDriver != null && driver.Position != -1 && oldDriver.Position != -1)
{
if (driver.GapToLeader < oldDriver.GapToLeader)
{
//There is a problem with the drivers gaps
}
else
{
int gap = driver.GapToLeader - oldDriver.GapToLeader;
//3000ms is 3s. If drivers are that close then they are definitely in battle. If they are farther then maybe not
if (gap <= 3000)
{
battles.Add((oldDriver, driver, gap));
}
}
oldDriver = driver;
}
else
{
oldDriver = driver;
}
}
//We will only display 4 battles max
int maxBattles = 4;
if (battles.Count > 0)
{
pnlBattles.Controls.Clear();
int maxUiHeight = Math.Max(pnlBattles.Height / maxBattles, pnlBattles.Height / battles.Count);
int id = 0;
foreach ((DriverData d1, DriverData d2, int gap) battle in battles)
{
if(id < maxBattles)
{
Button btnFirstDriver = new Button();
Button btnSecondDriver = new Button();
Label lblGap = new Label();
pnlBattles.Controls.Add(btnFirstDriver);
pnlBattles.Controls.Add(lblGap);
pnlBattles.Controls.Add(btnSecondDriver);
btnFirstDriver.Anchor = AnchorStyles.Left | AnchorStyles.Top;
btnSecondDriver.Anchor = AnchorStyles.Right | AnchorStyles.Top;
lblGap.Anchor = AnchorStyles.Left | AnchorStyles.Right;
lblGap.Dock = DockStyle.None;
lblGap.TextAlign = ContentAlignment.MiddleCenter;
btnFirstDriver.Click += form1.btnDriver_Click;
btnSecondDriver.Click += form1.btnDriver_Click;
btnFirstDriver.FlatStyle = FlatStyle.Popup;
btnSecondDriver.FlatStyle = FlatStyle.Popup;
btnFirstDriver.Size = new Size(pnlBattles.Width / 3, maxUiHeight);
btnSecondDriver.Size = new Size(pnlBattles.Width / 3, maxUiHeight);
btnFirstDriver.Location = new Point(0, id * maxUiHeight);
lblGap.Location = new Point(btnFirstDriver.Width, id * maxUiHeight);
btnSecondDriver.Location = new Point(pnlBattles.Width / 3 * 2, id * maxUiHeight);
btnFirstDriver.Text = battle.d1.Name;
lblGap.Text = "+ " + Reader.ConvertMsToTime(battle.gap);
if (battle.gap <= 2000)
lblGap.ForeColor = Color.Yellow;
if (battle.gap <= 1000)
lblGap.ForeColor = Color.Green;
btnSecondDriver.Text = battle.d2.Name;
btnFirstDriver.Name = battle.d1.Name + "_" + id;
lblGap.Name = "lbl_Gap_" + id;
btnSecondDriver.Name = battle.d2.Name + "_" + id;
}
else
{
break;
}
id++;
}
}
}
public void DisplayLapTimeInfos(string driverName, int Lap, string LapTime)
{
List<int> sectors = Storage.GetSectorsFromLapTime(driverName, Lap);
string message = "Lap time infos" + Environment.NewLine;
if (sectors.Count() == 3)
{
message += LapTime + Environment.NewLine;
if (sectors.Count > 0)
message += "Sector 1 : " + Reader.ConvertMsToTime(sectors[0]) + Environment.NewLine;
if (sectors.Count > 1)
message += "Sector 2 : " + Reader.ConvertMsToTime(sectors[1]) + Environment.NewLine;
if (sectors.Count > 2)
message += "Sector 3 : " + Reader.ConvertMsToTime(sectors[2]) + Environment.NewLine;
}
MessageBox.Show(message);
}
public void DisplayLiveRanking(Panel pnl, Form1 form1)
{
if(LiveDriverDataLogs.Count > 0)
if (LiveDriverDataLogs.Count > 0)
{
pnl.Controls.Clear();
//Gets the last item that should be the most recent data
@@ -68,14 +174,14 @@ namespace Test_Merge
Button[] buttons = new Button[liveData.Count];
Size buttonDimensions = new Size(pnl.Width,pnl.Height/liveData.Count);
Size buttonDimensions = new Size(pnl.Width, pnl.Height / liveData.Count);
for (int driverCount = 0; driverCount < liveData.Count; driverCount++)
{
Button newButton = new Button();
newButton.Size = buttonDimensions;
newButton.Location = new Point(0,driverCount * buttonDimensions.Height);
newButton.Location = new Point(0, driverCount * buttonDimensions.Height);
DriverData driver = liveData[driverCount];
@@ -84,7 +190,7 @@ namespace Test_Merge
//Its a DNF
newButton.Enabled = false;
}
if(driver.Position > 1)
if (driver.Position > 1)
{
newButton.Text = driver.Name + " +" + Reader.ConvertMsToTime(driver.GapToLeader);
}
@@ -92,16 +198,18 @@ namespace Test_Merge
{
newButton.Text = driver.Name;
}
newButton.Name = liveData[driverCount].Name;
newButton.TextAlign = ContentAlignment.MiddleLeft;
newButton.FlatStyle = FlatStyle.Popup;
newButton.Click += form1.btnDriver_Click;
buttons[driverCount] = newButton;
}
foreach(Button button in buttons)
foreach (Button button in buttons)
{
pnl.Controls.Add(button);
}