Still not working well but a lot more does

This commit is contained in:
2023-04-27 11:18:53 +02:00
parent d1eb1720a2
commit 23de653bde
5 changed files with 137 additions and 39 deletions

View File

@@ -12,14 +12,13 @@ namespace Test_Merge
{
public partial class Settings : Form
{
public const int EXPECTED_WINDOWS_AMOUNT = 7;
private string _grandPrixUrl = "";
private string _grandPrixName = "";
private int _grandPrixYear = 2000;
private List<string> _driverList = new List<string>();
private F1TVEmulator Emulator = null;
private ConfigurationTool Config = null;
private bool CreatingZone = false;
private Point ZoneP1;
@@ -76,15 +75,32 @@ namespace Test_Merge
{
lblWindowPointsRemaining.Text = "1 point Remaining";
}
lblWindowPointsRemaining.Text = EXPECTED_WINDOWS_AMOUNT - WindowsToAdd.Count() + " Windows remaining";
lblWindowPointsRemaining.Text = ConfigurationTool.NUMBER_OF_ZONES - WindowsToAdd.Count() + " Windows remaining";
}
else
{
lblWindowPointsRemaining.Text = "";
lblWindowsRemaining.Text = "";
}
if (Config != null)
{
pbxMain.Image = Config.MainZone.Draw();
pbxDriverZone.Image = Config.MainZone.Zones[0].ZoneImage;
}
}
private void CreateNewZone(Point p1, Point p2)
{
Rectangle dimensions = CreateAbsoluteRectangle(p1, p2);
Config = new ConfigurationTool((Bitmap)pbxMain.Image, dimensions);
RefreshUI();
}
private void CreateWindows(List<Rectangle> dimensions)
{
if (Config != null)
{
Config.AddWindows(dimensions);
}
}
private void tbxGpUrl_TextChanged(object sender, EventArgs e)
{
GrandPrixUrl = tbxGpUrl.Text;
@@ -137,6 +153,12 @@ namespace Test_Merge
if (CreatingWindow)
SwitchWindowCreation();
if (Emulator != null && Emulator.Ready)
{
Config = null;
pbxMain.Image = Emulator.Screenshot();
}
ZoneP1 = new Point(-1, -1);
ZoneP2 = new Point(-1, -1);
@@ -177,12 +199,15 @@ namespace Test_Merge
if (CreatingZone && pbxMain.Image != null)
{
Point coordinates = pbxMain.PointToClient(new Point(MousePosition.X, MousePosition.Y));
float xOffset = (float)pbxMain.Image.Width / (float)pbxMain.Width;
float yOffset = (float)pbxMain.Image.Height / (float)pbxMain.Height;
Point newPoint = new Point(Convert.ToInt32((float)coordinates.X * xOffset), Convert.ToInt32((float)coordinates.Y * yOffset));
//Point newPoint = new Point(coordinates.X - pbxMain.Left, coordinates.Y - pbxMain.Top);
//newPoint = new Point(Convert.ToInt32((float)newPoint.X * xOffset),Convert.ToInt32((float)newPoint.Y * yOffset));
MessageBox.Show("Coordinates" + Environment.NewLine + "Old : " + coordinates.ToString() + Environment.NewLine + "New : " + newPoint.ToString());
if (ZoneP1 == new Point(-1, -1))
{
ZoneP1 = newPoint;
@@ -190,7 +215,20 @@ namespace Test_Merge
else
{
ZoneP2 = newPoint;
//CreateNewZone();
/*
//Correction
if(ZoneP1.Y > ZoneP2.Y)
{
ZoneP1 = new Point(ZoneP1.X,ZoneP1.Y + pbxMain.Top);
}
else
{
ZoneP2 = new Point(ZoneP2.X, ZoneP2.Y - pbxMain.Top);
}
*/
CreateNewZone(ZoneP1, ZoneP2);
SwitchZoneCreation();
}
RefreshUI();
@@ -215,22 +253,22 @@ namespace Test_Merge
else
{
WindowP2 = newPoint;
WindowsToAdd.Add(createAbsoluteRectangle(WindowP1,WindowP2));
WindowsToAdd.Add(CreateAbsoluteRectangle(WindowP1, WindowP2));
if (WindowsToAdd.Count < EXPECTED_WINDOWS_AMOUNT)
if (WindowsToAdd.Count < ConfigurationTool.NUMBER_OF_ZONES)
{
WindowP1 = new Point(-1, -1);
WindowP2 = new Point(-1, -1);
}
else
{
//CreateWindows();
CreateWindows(WindowsToAdd);
}
}
RefreshUI();
}
}
private Rectangle createAbsoluteRectangle(Point p1, Point p2)
private Rectangle CreateAbsoluteRectangle(Point p1, Point p2)
{
Point newP1 = new Point();
Point newP2 = new Point();
@@ -256,13 +294,13 @@ namespace Test_Merge
newP1.Y = p2.Y;
newP2.Y = p1.Y;
}
return new Rectangle(newP1.X, newP1.Y,newP2.X-newP1.X,newP2.Y -newP2.Y);
return new Rectangle(newP1.X, newP1.Y, newP2.X - newP1.X, newP2.Y - newP1.Y);
}
private async void btnRefresh_Click(object sender, EventArgs e)
{
btnRefresh.Enabled = false;
if (Emulator == null)
if (Emulator == null || Emulator.GrandPrixUrl != tbxGpUrl.Text)
{
Emulator = new F1TVEmulator(tbxGpUrl.Text);
}
@@ -283,10 +321,13 @@ namespace Test_Merge
message = "Error " + errorCode + " Could not navigate on the F1TV site. Make sure the correct URL has been given and that you logged from chrome. It can take a few minutes to update";
break;
case 103:
message = "Error "+errorCode+" The url is not a valid url";
message = "Error " + errorCode + " The url is not a valid url";
break;
case 104:
message = "Error "+errorCode+" The url is not a valid url";
message = "Error " + errorCode + " The url is not a valid url";
break;
case 105:
message = "Error " + errorCode + " There has been an error trying to emulate button presses. Please try again";
break;
default:
message = "Could not start the emulator Error " + errorCode;
@@ -305,5 +346,13 @@ namespace Test_Merge
}
btnRefresh.Enabled = true;
}
private void Settings_FormClosing(object sender, FormClosingEventArgs e)
{
if (Emulator != null)
{
Emulator.Stop();
}
}
}
}