Updated the code to show on the documentation

This commit is contained in:
2023-06-08 14:30:18 +02:00
parent ac5641125a
commit a7c6ad610c
18 changed files with 321 additions and 619 deletions
+90 -8
View File
@@ -1,4 +1,10 @@
using System;
/// Author : Maxime Rohmer
/// Date : 09/06/2023
/// File : Form1.cs
/// Brief : Class that controls the main view of the app
/// Version : Beta 1.0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -15,7 +21,6 @@ namespace TrackTrends
{
public partial class Main : Form
{
//private Reader Reader = null;
private F1TVEmulator Emulator = null;
private DataWrapper Wrapper = null;
private bool cancelRequested = false;
@@ -47,7 +52,10 @@ namespace TrackTrends
{
InitializeComponent();
}
public async void RefreshUI()
/// <summary>
/// Will update everything that is not data related
/// </summary>
public void RefreshUI()
{
if (Directory.Exists(ConfigurationTool.CONFIGS_FOLDER_NAME))
{
@@ -55,7 +63,12 @@ namespace TrackTrends
lsbPresets.DataSource = Directory.GetFiles(ConfigurationTool.CONFIGS_FOLDER_NAME);
}
}
private async void btnSettings_Click(object sender, EventArgs e)
/// <summary>
/// Opens the settings page. Also disposes of the browser if there is one opened and all thos things
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSettings_Click(object sender, EventArgs e)
{
if (Emulator != null)
Emulator.ResetDriver();
@@ -88,6 +101,7 @@ namespace TrackTrends
}
else
{
//Should technically never show up but we never know
MessageBox.Show("The config file has not been found please return to the config and change it");
}
}
@@ -97,7 +111,11 @@ namespace TrackTrends
//MessageBox.Show("There is no URL for the Grand Prix you want to decode. Please return to the config and add a valid one");
}
}
/// <summary>
/// Will do everything that needs to be done at the first start of the app
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void Form1_Load(object sender, EventArgs e)
{
//Those are the default values but they will need to be changed later when the configuration has been done
@@ -106,6 +124,8 @@ namespace TrackTrends
tbxGpUrl.Text = GpUrl;
this.DoubleBuffered = true;
oldSize = this.Size;
oldRankingSize = gpbxRanking.Size;
oldLapTimesSize = gpbxLapTimes.Size;
@@ -134,7 +154,11 @@ namespace TrackTrends
RefreshUI();
}
/// <summary>
/// Will start or stop the process of decoding
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void btnUpdate_Click(object sender, EventArgs e)
{
cancelRequested = false;
@@ -192,18 +216,32 @@ namespace TrackTrends
btnSettings.Enabled = true;
}
}
/// <summary>
/// Will display the overtakes in the overtakes list box
/// </summary>
private void DisplayOvertakes()
{
Wrapper.DisplayOvertakes(lsbOvertakes);
}
/// <summary>
/// Will display the battles in the battles pannel
/// </summary>
private void DisplayBattles()
{
Wrapper.DisplayBattles(pnlBattles, this);
}
/// <summary>
/// Will display the time differences in the faster and slowest pannels
/// </summary>
private void DisplayDeltas()
{
Wrapper.DisplayTimesDeltas(pnlFastest, pnlSlowest, this);
}
/// <summary>
/// Will try to stop the emulator (usually does not work please do not count on it)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (Emulator != null)
@@ -211,6 +249,12 @@ namespace TrackTrends
Emulator.Stop();
}
}
/// <summary>
/// Will display the live ranking on the live ranking pannel. Its called like this because historically it was the method that just recovered the bare results from the OCR
/// </summary>
/// <param name="errorCode"></param>
/// <param name="sw"></param>
/// <param name="screen"></param>
private void DisplayResults(int errorCode, Stopwatch sw, Bitmap screen)
{
if (errorCode != 0)
@@ -224,6 +268,11 @@ namespace TrackTrends
}
}
/// <summary>
/// Will stop the data recovering operation and resets some buttons and text
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStopUpdating_Click(object sender, EventArgs e)
{
// Set the cancellation flag
@@ -232,6 +281,11 @@ namespace TrackTrends
btnResetEmulator.Enabled = false;
btnStopUpdating.Text = "Stopping";
}
/// <summary>
/// Will start the F1TVEmulator, again this name is historical because back at the start of this project this button did not have a name
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void button1_Click(object sender, EventArgs e)
{
lsbOvertakes.Items.Clear();
@@ -301,6 +355,11 @@ namespace TrackTrends
btnStartDecoding.Enabled = true;
}
}
/// <summary>
/// Silly way to remove borders from groupbox and make them look like pannels with titles
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void removeBorders(object sender, PaintEventArgs e)
{
GroupBox gpbx = (GroupBox)sender;
@@ -317,17 +376,31 @@ namespace TrackTrends
e.Graphics.DrawString(gpbx.Text, gpbx.Font, brush, textPosition);
}
}
/// <summary>
/// Will change the preset to use when starting the emulator
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lsbPresets_SelectedIndexChanged(object sender, EventArgs e)
{
if (lsbPresets.SelectedIndex >= 0)
ConfigFile = lsbPresets.Items[lsbPresets.SelectedIndex].ToString();
}
/// <summary>
/// Will change the URL the emulator will use, historical name again
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (tbxGpUrl.Text != "")
GpUrl = tbxGpUrl.Text;
}
/// <summary>
/// This is called by the automatically generated buttons. Its here to fill in the driver info tab whenever the user clicks on a button that contains the name of a driver
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void btnDriver_Click(object sender, EventArgs e)
{
//Removes the cover
@@ -381,6 +454,11 @@ namespace TrackTrends
break;
}
}
/// <summary>
/// This is supposed to be called by an automatically generated button. It should be any button with a laptime info on it
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void btnLapTime_Click(object sender, EventArgs e)
{
//Happens when a lapTime has been clicked
@@ -388,7 +466,11 @@ namespace TrackTrends
string[] parts = btn.Name.Split('_');
Wrapper.DisplayLapTimeInfos(parts[0], Convert.ToInt32(parts[1]), btn.Text);
}
/// <summary>
/// Will trigger responsive calculation everytime the form changes size
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Main_Resize(object sender, EventArgs e)
{
int xDiff = this.Width - oldSize.Width;