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
+136 -26
View File
@@ -1,4 +1,10 @@
using System;
/// Author : Maxime Rohmer
/// Date : 09/06/2023
/// File : Settings.cs
/// Brief : Class that controls the settings view
/// Version : Beta 1.0
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -48,6 +54,9 @@ namespace TrackTrends
InitializeComponent();
Load();
}
/// <summary>
/// This methods regroups all the actions that the forms need to be doing at the first launch
/// </summary>
private void Load()
{
RefreshUI();
@@ -57,6 +66,11 @@ namespace TrackTrends
oldPbxPreviewSize = pbxPreview.Size;
oldPbxWindowPreviewSize = pbxWindowPreview.Size;
btnLoadPreset.Enabled = false;
btnDeletePreset.Enabled = false;
btnSavePreset.Enabled = false;
// I prefered regrouping all the tooltips here to make it easier to edit (there is 100% of thoses sentences containing typos so if you see one dont hesitate to edit those messages)
tip1.SetToolTip(btnCreatZone, "After clicking you can select two points in the image to set the bounds of the important data");
tip1.SetToolTip(btnCreateWindow, "After clicking this you will have to select all the windows that are important on the lower image. Refer to the documentation for more infos");
tip1.SetToolTip(btnRefresh, "Starts the emulator or refreshes the images if its already running");
@@ -66,6 +80,10 @@ namespace TrackTrends
tip1.SetToolTip(pbxPreview, "What the emulator returns");
tip1.SetToolTip(pbxWindowPreview, "One of the driver zones that the program managed to slice from the main zone");
}
/// <summary>
/// This is the main method that will be called anytime something changes on the view
/// It can be called at any time and will adapt the UI taking into account the state of the app
/// </summary>
private void RefreshUI()
{
lsbDrivers.DataSource = null;
@@ -116,12 +134,21 @@ namespace TrackTrends
pbxWindowPreview.Image = Config.MainZone.Zones[0].Draw();
}
}
/// <summary>
/// This will create a new zone but will require two points (one at each opposing sides and corners)
/// </summary>
/// <param name="p1">The first corner (usually top left)</param>
/// <param name="p2">The second corner (usually bottom right)</param>
private void CreateNewZone(Point p1, Point p2)
{
Rectangle dimensions = CreateAbsoluteRectangle(p1, p2);
Config = new ConfigurationTool((Bitmap)pbxPreview.Image, dimensions);
RefreshUI();
}
/// <summary>
/// Creates all the windows with an array of rectangles
/// </summary>
/// <param name="dimensions">An array that contains all the windows bounds and position (expects 9)</param>
private void CreateWindows(List<Rectangle> dimensions)
{
if (Config != null)
@@ -129,11 +156,20 @@ namespace TrackTrends
Config.AddWindows(dimensions);
}
}
/// <summary>
/// Will just change the main URL
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tbxGpUrl_TextChanged(object sender, EventArgs e)
{
GrandPrixUrl = tbxGpUrl.Text;
}
/// <summary>
/// Adds a driver into the driver list
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAddDriver_Click(object sender, EventArgs e)
{
string newDriver = tbxDriverName.Text;
@@ -141,7 +177,11 @@ namespace TrackTrends
tbxDriverName.Text = "";
RefreshUI();
}
/// <summary>
/// Removes a driver from the drivers list
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnRemoveDriver_Click(object sender, EventArgs e)
{
if (lsbDrivers.SelectedIndex >= 0)
@@ -150,6 +190,9 @@ namespace TrackTrends
}
RefreshUI();
}
/// <summary>
/// Will change everything that needs to be changed for when the users starts or stops creating a zone
/// </summary>
private void SwitchZoneCreation()
{
if (CreatingZone)
@@ -180,6 +223,9 @@ namespace TrackTrends
}
RefreshUI();
}
/// <summary>
/// Will change everything that needs to be changed for when the users starts or stops creating a window
/// </summary>
private void SwitchWindowCreation()
{
if (CreatingWindow)
@@ -211,6 +257,11 @@ namespace TrackTrends
{
SwitchWindowCreation();
}
/// <summary>
/// If the user is supposed to create a zone, will record the position of the clicks
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pbxMain_MouseClick(object sender, MouseEventArgs e)
{
if (CreatingZone && pbxPreview.Image != null)
@@ -236,10 +287,11 @@ namespace TrackTrends
RefreshUI();
}
}
private void pbxMain_Click(object sender, EventArgs e)
{
//Not the right one to use visibly
}
/// <summary>
/// If the user is supposed to create a window, will record the position of the clicks
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pbxDriverZone_MouseClick(object sender, MouseEventArgs e)
{
if (CreatingWindow && pbxWindowPreview.Image != null)
@@ -276,15 +328,18 @@ namespace TrackTrends
RefreshUI();
}
}
private void pbxDriverZone_Click(object sender, EventArgs e)
{
//Not the right one to use visibly
}
/// <summary>
/// Creates a rectangle without caring about the order of the points.
/// </summary>
/// <param name="p1">First point. Can be top left or bottom right</param>
/// <param name="p2">Second point. Can be top left or bottom right</param>
/// <returns></returns>
private Rectangle CreateAbsoluteRectangle(Point p1, Point p2)
{
Point newP1 = new Point();
Point newP2 = new Point();
//Kind of a pain to have to do this but this lets the user do stupid things without the app crashing
if (p1.X < p2.X)
{
newP1.X = p1.X;
@@ -308,7 +363,11 @@ namespace TrackTrends
}
return new Rectangle(newP1.X, newP1.Y, newP2.X - newP1.X, newP2.Y - newP1.Y);
}
/// <summary>
/// Will refresh the emulator and will controll some of the controls
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void btnRefresh_Click(object sender, EventArgs e)
{
btnRefresh.Enabled = false;
@@ -355,23 +414,45 @@ namespace TrackTrends
break;
}
MessageBox.Show(message);
btnRefresh.Text = "Retry";
btnLoadPreset.Enabled = false;
btnDeletePreset.Enabled = false;
btnSavePreset.Enabled = false;
btnCreatZone.Enabled = false;
btnCreateWindow.Enabled = false;
btnResetDriver.Enabled = false;
}
else
{
btnRefresh.Text = "Get a newer image";
pbxPreview.Image = Emulator.Screenshot();
btnLoadPreset.Enabled = true;
btnDeletePreset.Enabled = true;
btnSavePreset.Enabled = true;
btnCreatZone.Enabled = true;
btnCreateWindow.Enabled = true;
btnResetDriver.Enabled = true;
}
}
else
{
pbxPreview.Image = Emulator.Screenshot();
//I know im repeating myself. This part could use a bool variable that allows those buttons to be displayed but it was the fastest way to fix a bad behaviour in the app
btnLoadPreset.Enabled = true;
btnDeletePreset.Enabled = true;
btnSavePreset.Enabled = true;
btnCreatZone.Enabled = true;
btnCreateWindow.Enabled = true;
btnResetDriver.Enabled = true;
}
btnRefresh.Enabled = true;
btnCreatZone.Enabled = true;
btnCreateWindow.Enabled = true;
btnResetDriver.Enabled = true;
btnRefresh.Text = "Get a newer image";
}
/// <summary>
/// Will try to close the headless browser so the main form can launch a new one safely
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Settings_FormClosing(object sender, FormClosingEventArgs e)
{
if (Emulator != null)
@@ -381,7 +462,11 @@ namespace TrackTrends
Emulator = null;
GC.Collect();
}
/// <summary>
/// Will reset the drivers
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnResetDriver_Click(object sender, EventArgs e)
{
if (Emulator != null)
@@ -389,7 +474,11 @@ namespace TrackTrends
Emulator.ResetDriver();
}
}
/// <summary>
/// Saves the current presets as a new JSON file
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSavePreset_Click(object sender, EventArgs e)
{
string presetName = tbxPresetName.Text;
@@ -399,12 +488,21 @@ namespace TrackTrends
}
RefreshUI();
}
/// <summary>
/// Will change the selected preset. Usefull if you close this page because then the main form will keep in memory your last choice
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lsbPresets_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedConfigFile = (string)lsbPresets.Items[lsbPresets.SelectedIndex];
if (lsbPresets.SelectedIndex >= 0)
SelectedConfigFile = (string)lsbPresets.Items[lsbPresets.SelectedIndex];
}
/// <summary>
/// Will load an existing presets
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLoadPreset_Click(object sender, EventArgs e)
{
//MessageBox.Show(lsbPresets.SelectedIndex.ToString());
@@ -427,7 +525,11 @@ namespace TrackTrends
RefreshUI();
}
}
/// <summary>
/// This will be called everytime the form resizes. Here we are making the form responsive
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Settings_Resize(object sender, EventArgs e)
{
int xDiff = this.Width - oldSize.Width;
@@ -438,7 +540,11 @@ namespace TrackTrends
pbxPreview.Size = new Size(oldPbxPreviewSize.Width + xDiff, oldPbxPreviewSize.Height + yDiff);
pbxWindowPreview.Size = new Size(oldPbxWindowPreviewSize.Width + xDiff, oldPbxWindowPreviewSize.Height);
}
/// <summary>
/// Will delete an existing preset
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDeletePreset_Click(object sender, EventArgs e)
{
int selectedIndex = lsbPresets.SelectedIndex;
@@ -456,7 +562,11 @@ namespace TrackTrends
}
}
}
/// <summary>
/// Sketchy method that is used to remove the borders from groupboxes... Yes its dumb but I dont think there is any other way
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void removeBorders(object sender, PaintEventArgs e)
{
GroupBox gpbx = (GroupBox)sender;