Added a lot to the doc and modified the pdf generation
This commit is contained in:
+106
-44
@@ -8,14 +8,14 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using TrackTrends;
|
||||
|
||||
namespace Test_Merge
|
||||
namespace TrackTrends
|
||||
{
|
||||
public partial class Settings : Form
|
||||
{
|
||||
private string _grandPrixUrl = "";
|
||||
private string _grandPrixName = "";
|
||||
private int _grandPrixYear = 2000;
|
||||
private string _selectedConfigFile;
|
||||
private List<string> _driverList = new List<string>();
|
||||
|
||||
private F1TVEmulator Emulator = null;
|
||||
@@ -32,9 +32,16 @@ namespace Test_Merge
|
||||
List<Rectangle> WindowsToAdd = new List<Rectangle>();
|
||||
|
||||
public string GrandPrixUrl { get => _grandPrixUrl; private set => _grandPrixUrl = value; }
|
||||
public string GrandPrixName { get => _grandPrixName; private set => _grandPrixName = value; }
|
||||
public int GrandPrixYear { get => _grandPrixYear; private set => _grandPrixYear = value; }
|
||||
public List<string> DriverList { get => _driverList; private set => _driverList = value; }
|
||||
public string SelectedConfigFile { get => _selectedConfigFile; private set => _selectedConfigFile = value; }
|
||||
|
||||
//For the responsive content
|
||||
Size oldSize = new Size();
|
||||
Size oldGpbxPreviewSize = new Size();
|
||||
Size oldGpbxWindowPreviewSize = new Size();
|
||||
|
||||
Size oldPbxPreviewSize = new Size();
|
||||
Size oldPbxWindowPreviewSize = new Size();
|
||||
|
||||
public Settings()
|
||||
{
|
||||
@@ -44,10 +51,23 @@ namespace Test_Merge
|
||||
private void Load()
|
||||
{
|
||||
RefreshUI();
|
||||
oldSize = this.Size;
|
||||
oldGpbxPreviewSize = gpbxPreview.Size;
|
||||
oldGpbxWindowPreviewSize = gpbxWindowPreview.Size;
|
||||
oldPbxPreviewSize = pbxPreview.Size;
|
||||
oldPbxWindowPreviewSize = pbxWindowPreview.Size;
|
||||
|
||||
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");
|
||||
tip1.SetToolTip(btnResetDriver, "Resets the driver if something went wrong or if you want to test an other URL");
|
||||
tip1.SetToolTip(lsbDrivers, "The drivers that are on the image. Non-Case sensitive");
|
||||
tip1.SetToolTip(tbxPresetName, "The name of the preset you want to save");
|
||||
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");
|
||||
}
|
||||
private void RefreshUI()
|
||||
{
|
||||
|
||||
lsbDrivers.DataSource = null;
|
||||
lsbDrivers.DataSource = DriverList;
|
||||
|
||||
@@ -91,15 +111,15 @@ namespace Test_Merge
|
||||
}
|
||||
if (Config != null)
|
||||
{
|
||||
pbxMain.Image = Config.MainZone.Draw();
|
||||
if(Config.MainZone.Zones.Count > 0)
|
||||
pbxDriverZone.Image = Config.MainZone.Zones[0].Draw();
|
||||
pbxPreview.Image = Config.MainZone.Draw();
|
||||
if (Config.MainZone.Zones.Count > 0)
|
||||
pbxWindowPreview.Image = Config.MainZone.Zones[0].Draw();
|
||||
}
|
||||
}
|
||||
private void CreateNewZone(Point p1, Point p2)
|
||||
{
|
||||
Rectangle dimensions = CreateAbsoluteRectangle(p1, p2);
|
||||
Config = new ConfigurationTool((Bitmap)pbxMain.Image, dimensions);
|
||||
Config = new ConfigurationTool((Bitmap)pbxPreview.Image, dimensions);
|
||||
RefreshUI();
|
||||
}
|
||||
private void CreateWindows(List<Rectangle> dimensions)
|
||||
@@ -114,25 +134,6 @@ namespace Test_Merge
|
||||
GrandPrixUrl = tbxGpUrl.Text;
|
||||
}
|
||||
|
||||
private void tbxGpName_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
GrandPrixName = tbxGpName.Text;
|
||||
}
|
||||
|
||||
private void tbxGpYear_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
int year;
|
||||
try
|
||||
{
|
||||
year = Convert.ToInt32(tbxGpYear.Text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
year = 1545;
|
||||
}
|
||||
GrandPrixYear = year;
|
||||
}
|
||||
|
||||
private void btnAddDriver_Click(object sender, EventArgs e)
|
||||
{
|
||||
string newDriver = tbxDriverName.Text;
|
||||
@@ -169,7 +170,7 @@ namespace Test_Merge
|
||||
if (Emulator != null && Emulator.Ready)
|
||||
{
|
||||
Config = null;
|
||||
pbxMain.Image = Emulator.Screenshot();
|
||||
pbxPreview.Image = Emulator.Screenshot();
|
||||
}
|
||||
|
||||
ZoneP1 = new Point(-1, -1);
|
||||
@@ -212,12 +213,12 @@ namespace Test_Merge
|
||||
}
|
||||
private void pbxMain_MouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (CreatingZone && pbxMain.Image != null)
|
||||
if (CreatingZone && pbxPreview.Image != null)
|
||||
{
|
||||
//Point coordinates = pbxMain.PointToClient(new Point(MousePosition.X, MousePosition.Y));
|
||||
Point coordinates = e.Location;
|
||||
float xOffset = (float)pbxMain.Image.Width / (float)pbxMain.Width;
|
||||
float yOffset = (float)pbxMain.Image.Height / (float)pbxMain.Height;
|
||||
float xOffset = (float)pbxPreview.Image.Width / (float)pbxPreview.Width;
|
||||
float yOffset = (float)pbxPreview.Image.Height / (float)pbxPreview.Height;
|
||||
Point newPoint = new Point(Convert.ToInt32((float)coordinates.X * xOffset), Convert.ToInt32((float)coordinates.Y * yOffset));
|
||||
|
||||
//MessageBox.Show("Coordinates" + Environment.NewLine + "Old : " + coordinates.ToString() + Environment.NewLine + "New : " + newPoint.ToString());
|
||||
@@ -241,12 +242,12 @@ namespace Test_Merge
|
||||
}
|
||||
private void pbxDriverZone_MouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (CreatingWindow && pbxDriverZone.Image != null)
|
||||
if (CreatingWindow && pbxWindowPreview.Image != null)
|
||||
{
|
||||
Point coordinates = e.Location;
|
||||
|
||||
float xOffset = (float)pbxDriverZone.Image.Width / (float)pbxDriverZone.Width;
|
||||
float yOffset = (float)pbxDriverZone.Image.Height / (float)pbxDriverZone.Height;
|
||||
float xOffset = (float)pbxWindowPreview.Image.Width / (float)pbxWindowPreview.Width;
|
||||
float yOffset = (float)pbxWindowPreview.Image.Height / (float)pbxWindowPreview.Height;
|
||||
|
||||
Point newPoint = new Point(Convert.ToInt32((float)coordinates.X * xOffset), Convert.ToInt32((float)coordinates.Y * yOffset));
|
||||
|
||||
@@ -267,7 +268,7 @@ namespace Test_Merge
|
||||
else
|
||||
{
|
||||
WindowP1 = new Point(WindowP1.X, 0);
|
||||
WindowP2 = new Point(WindowP2.X, pbxDriverZone.Image.Height);
|
||||
WindowP2 = new Point(WindowP2.X, pbxWindowPreview.Image.Height);
|
||||
CreateWindows(WindowsToAdd);
|
||||
SwitchWindowCreation();
|
||||
}
|
||||
@@ -311,6 +312,9 @@ namespace Test_Merge
|
||||
private async void btnRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
btnRefresh.Enabled = false;
|
||||
btnCreatZone.Enabled = false;
|
||||
btnCreateWindow.Enabled = false;
|
||||
btnResetDriver.Enabled = false;
|
||||
if (Emulator == null || Emulator.GrandPrixUrl != tbxGpUrl.Text)
|
||||
{
|
||||
Emulator = new F1TVEmulator(tbxGpUrl.Text);
|
||||
@@ -325,6 +329,9 @@ namespace Test_Merge
|
||||
string message;
|
||||
switch (errorCode)
|
||||
{
|
||||
case 100:
|
||||
message = "Error " + errorCode + " Could not recover cookies. It could be because of an improper installation of python or bad cookies in the chrome database. Please try to log on to the F1TV using chrome again";
|
||||
break;
|
||||
case 101:
|
||||
message = "Error " + errorCode + " Could not start the driver. It could be because an other instance is runnin make sure you closed them all before trying again";
|
||||
break;
|
||||
@@ -351,14 +358,18 @@ namespace Test_Merge
|
||||
}
|
||||
else
|
||||
{
|
||||
pbxMain.Image = Emulator.Screenshot();
|
||||
pbxPreview.Image = Emulator.Screenshot();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pbxMain.Image = Emulator.Screenshot();
|
||||
pbxPreview.Image = Emulator.Screenshot();
|
||||
}
|
||||
btnRefresh.Enabled = true;
|
||||
btnCreatZone.Enabled = true;
|
||||
btnCreateWindow.Enabled = true;
|
||||
btnResetDriver.Enabled = true;
|
||||
btnRefresh.Text = "Get a newer image";
|
||||
}
|
||||
|
||||
private void Settings_FormClosing(object sender, FormClosingEventArgs e)
|
||||
@@ -367,6 +378,8 @@ namespace Test_Merge
|
||||
{
|
||||
Emulator.Stop();
|
||||
}
|
||||
Emulator = null;
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
private void btnResetDriver_Click(object sender, EventArgs e)
|
||||
@@ -382,27 +395,30 @@ namespace Test_Merge
|
||||
string presetName = tbxPresetName.Text;
|
||||
if (Config != null)
|
||||
{
|
||||
Config.SaveToJson(DriverList,presetName);
|
||||
Config.SaveToJson(DriverList, presetName);
|
||||
}
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
private void lsbPresets_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
//Nothing
|
||||
SelectedConfigFile = (string)lsbPresets.Items[lsbPresets.SelectedIndex];
|
||||
}
|
||||
|
||||
private void btnLoadPreset_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (lsbPresets.SelectedIndex >= 0 && pbxMain.Image != null)
|
||||
//MessageBox.Show(lsbPresets.SelectedIndex.ToString());
|
||||
if (lsbPresets.SelectedIndex >= 0 && pbxPreview.Image != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Reader reader = new Reader(lsbPresets.Items[lsbPresets.SelectedIndex].ToString(), (Bitmap)pbxMain.Image,false);
|
||||
string fileName = lsbPresets.Items[lsbPresets.SelectedIndex].ToString();
|
||||
Reader reader = new Reader(fileName, (Bitmap)pbxPreview.Image, false);
|
||||
//MainZones #0 is the big main zone containing driver zones
|
||||
Config = new ConfigurationTool((Bitmap)pbxMain.Image, reader.MainZones[0].Bounds);
|
||||
Config = new ConfigurationTool((Bitmap)pbxPreview.Image, reader.MainZones[0].Bounds);
|
||||
Config.MainZone = reader.MainZones[0];
|
||||
DriverList = reader.Drivers;
|
||||
SelectedConfigFile = fileName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -411,5 +427,51 @@ namespace Test_Merge
|
||||
RefreshUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void Settings_Resize(object sender, EventArgs e)
|
||||
{
|
||||
int xDiff = this.Width - oldSize.Width;
|
||||
int yDiff = this.Height - oldSize.Height;
|
||||
|
||||
gpbxPreview.Size = new Size(oldGpbxPreviewSize.Width + xDiff, oldGpbxPreviewSize.Height + yDiff);
|
||||
gpbxWindowPreview.Size = new Size(oldGpbxWindowPreviewSize.Width + xDiff, oldGpbxWindowPreviewSize.Height);
|
||||
pbxPreview.Size = new Size(oldPbxPreviewSize.Width + xDiff, oldPbxPreviewSize.Height + yDiff);
|
||||
pbxWindowPreview.Size = new Size(oldPbxWindowPreviewSize.Width + xDiff, oldPbxWindowPreviewSize.Height);
|
||||
}
|
||||
|
||||
private void btnDeletePreset_Click(object sender, EventArgs e)
|
||||
{
|
||||
int selectedIndex = lsbPresets.SelectedIndex;
|
||||
if (selectedIndex >= 0)
|
||||
{
|
||||
string fileName = lsbPresets.Items[selectedIndex].ToString();
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
File.Delete(fileName);
|
||||
RefreshUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Could not delete the preset because it does not exists");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeBorders(object sender, PaintEventArgs e)
|
||||
{
|
||||
GroupBox gpbx = (GroupBox)sender;
|
||||
|
||||
using (Pen pen = new Pen(gpbx.BackColor, 50))
|
||||
{
|
||||
e.Graphics.DrawRectangle(pen, 0, 0, gpbx.Width - 1, gpbx.Height - 1);
|
||||
e.Graphics.DrawRectangle(pen, 0, 0, gpbx.Width - 1, gpbx.Height - 1);
|
||||
}
|
||||
|
||||
using (var brush = new SolidBrush(gpbx.ForeColor))
|
||||
{
|
||||
var textPosition = new Point(5, 0); // Adjust the X and Y values as needed
|
||||
e.Graphics.DrawString(gpbx.Text, gpbx.Font, brush, textPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user