Still not working well but a lot more does
This commit is contained in:
@@ -10,29 +10,62 @@ namespace Test_Merge
|
|||||||
{
|
{
|
||||||
public class ConfigurationTool
|
public class ConfigurationTool
|
||||||
{
|
{
|
||||||
private Zone mainZone;
|
public Zone MainZone;
|
||||||
const int NUMBER_OF_DRIVERS = 20;
|
public const int NUMBER_OF_DRIVERS = 20;
|
||||||
const int NUMBER_OF_ZONES = 7;
|
public const int NUMBER_OF_ZONES = 9;
|
||||||
|
|
||||||
public ConfigurationTool()
|
public ConfigurationTool(Bitmap fullImage,Rectangle mainZoneDimensions)
|
||||||
{
|
{
|
||||||
//empty for now
|
MainZone = new Zone(fullImage,mainZoneDimensions);
|
||||||
|
AutoCalibrate();
|
||||||
}
|
}
|
||||||
public void AddZones(List<Rectangle> rectangles)
|
public void AddWindows(List<Rectangle> rectangles)
|
||||||
{
|
{
|
||||||
foreach (Zone driverZone in mainZone.Zones)
|
foreach (Zone driverZone in MainZone.Zones)
|
||||||
{
|
{
|
||||||
Bitmap zoneImage = driverZone.ZoneImage;
|
Bitmap zoneImage = driverZone.ZoneImage;
|
||||||
|
|
||||||
for ()
|
for (int i = 1; i <= rectangles.Count; i++)
|
||||||
{
|
{
|
||||||
//We need to add all the zone and the types
|
switch (i)
|
||||||
|
{
|
||||||
//if i== 1 => driverZone.Add(new DriverPositionWindow)
|
case 1:
|
||||||
|
//First zone should be the driver's Position
|
||||||
|
driverZone.AddWindow(new DriverPositionWindow(driverZone.ZoneImage, rectangles[i]));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
//First zone should be the driver's Position
|
||||||
|
driverZone.AddWindow(new DriverGapToLeaderWindow(driverZone.ZoneImage, rectangles[i]));
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
//First zone should be the driver's Position
|
||||||
|
driverZone.AddWindow(new DriverLapTimeWindow(driverZone.ZoneImage, rectangles[i]));
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
//First zone should be the driver's Position
|
||||||
|
driverZone.AddWindow(new DriverDrsWindow(driverZone.ZoneImage, rectangles[i]));
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
//First zone should be the driver's Position
|
||||||
|
driverZone.AddWindow(new DriverTyresWindow(driverZone.ZoneImage, rectangles[i]));
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
//First zone should be the driver's Position
|
||||||
|
driverZone.AddWindow(new DriverNameWindow(driverZone.ZoneImage, rectangles[i]));
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
//First zone should be the driver's Position
|
||||||
|
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i]));
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
//First zone should be the driver's Position
|
||||||
|
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i]));
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
//First zone should be the driver's Position
|
||||||
|
driverZone.AddWindow(new DriverSectorWindow(driverZone.ZoneImage, rectangles[i]));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
foreach (Rectangle rectangle in rectangles) {
|
|
||||||
driverZone.AddWindow(new Window());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +75,7 @@ namespace Test_Merge
|
|||||||
List<Zone> zones = new List<Zone>();
|
List<Zone> zones = new List<Zone>();
|
||||||
|
|
||||||
TesseractEngine engine = new TesseractEngine(Window.TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
TesseractEngine engine = new TesseractEngine(Window.TESS_DATA_FOLDER.FullName, "eng", EngineMode.Default);
|
||||||
Image image = mainZone.ZoneImage;
|
Image image = MainZone.ZoneImage;
|
||||||
var tessImage = Pix.LoadFromMemory(Window.ImageToByte(image));
|
var tessImage = Pix.LoadFromMemory(Window.ImageToByte(image));
|
||||||
|
|
||||||
Page page = engine.Process(tessImage);
|
Page page = engine.Process(tessImage);
|
||||||
@@ -89,7 +122,7 @@ namespace Test_Merge
|
|||||||
Point windowLocation = new Point(0, (Rectangle.Y + Rectangle.Height / 2) - windowSize.Height / 2);
|
Point windowLocation = new Point(0, (Rectangle.Y + Rectangle.Height / 2) - windowSize.Height / 2);
|
||||||
windowRectangle = new Rectangle(windowLocation, windowSize);
|
windowRectangle = new Rectangle(windowLocation, windowSize);
|
||||||
//We add the driver zones
|
//We add the driver zones
|
||||||
mainZone.AddZone(new Zone(mainZone.ZoneImage, windowRectangle));
|
MainZone.AddZone(new Zone(MainZone.ZoneImage, windowRectangle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,8 @@ namespace Test_Merge
|
|||||||
actions.SendKeys(OpenQA.Selenium.Keys.Space).Perform();
|
actions.SendKeys(OpenQA.Selenium.Keys.Space).Perform();
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
//Clicks on the settings Icon
|
//Clicks on the settings Icon
|
||||||
|
try
|
||||||
|
{
|
||||||
IWebElement settingsButton = Driver.FindElement(By.ClassName("bmpui-ui-settingstogglebutton"));
|
IWebElement settingsButton = Driver.FindElement(By.ClassName("bmpui-ui-settingstogglebutton"));
|
||||||
settingsButton.Click();
|
settingsButton.Click();
|
||||||
IWebElement selectElement = Driver.FindElement(By.ClassName("bmpui-ui-videoqualityselectbox"));
|
IWebElement selectElement = Driver.FindElement(By.ClassName("bmpui-ui-videoqualityselectbox"));
|
||||||
@@ -155,6 +157,14 @@ namespace Test_Merge
|
|||||||
IWebElement selectOption = selectElement.FindElement(By.CssSelector("option[value^='1080_']"));
|
IWebElement selectOption = selectElement.FindElement(By.CssSelector("option[value^='1080_']"));
|
||||||
selectOption.Click();
|
selectOption.Click();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
//Sometimes it can crash because it could not get the options to show up in time. When it happens just retry
|
||||||
|
Driver.Dispose();
|
||||||
|
return 105;
|
||||||
|
}
|
||||||
|
|
||||||
//Makes the feed fullscreen
|
//Makes the feed fullscreen
|
||||||
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
|
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
|
||||||
IWebElement fullScreenButton = Driver.FindElement(By.ClassName("bmpui-ui-fullscreentogglebutton"));
|
IWebElement fullScreenButton = Driver.FindElement(By.ClassName("bmpui-ui-fullscreentogglebutton"));
|
||||||
|
|||||||
Generated
+1
@@ -371,6 +371,7 @@
|
|||||||
this.Name = "Settings";
|
this.Name = "Settings";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "Settings";
|
this.Text = "Settings";
|
||||||
|
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Settings_FormClosing);
|
||||||
this.gpbxInfos.ResumeLayout(false);
|
this.gpbxInfos.ResumeLayout(false);
|
||||||
this.gpbxInfos.PerformLayout();
|
this.gpbxInfos.PerformLayout();
|
||||||
this.groupBox1.ResumeLayout(false);
|
this.groupBox1.ResumeLayout(false);
|
||||||
|
|||||||
+62
-13
@@ -12,14 +12,13 @@ namespace Test_Merge
|
|||||||
{
|
{
|
||||||
public partial class Settings : Form
|
public partial class Settings : Form
|
||||||
{
|
{
|
||||||
public const int EXPECTED_WINDOWS_AMOUNT = 7;
|
|
||||||
|
|
||||||
private string _grandPrixUrl = "";
|
private string _grandPrixUrl = "";
|
||||||
private string _grandPrixName = "";
|
private string _grandPrixName = "";
|
||||||
private int _grandPrixYear = 2000;
|
private int _grandPrixYear = 2000;
|
||||||
private List<string> _driverList = new List<string>();
|
private List<string> _driverList = new List<string>();
|
||||||
|
|
||||||
private F1TVEmulator Emulator = null;
|
private F1TVEmulator Emulator = null;
|
||||||
|
private ConfigurationTool Config = null;
|
||||||
|
|
||||||
private bool CreatingZone = false;
|
private bool CreatingZone = false;
|
||||||
private Point ZoneP1;
|
private Point ZoneP1;
|
||||||
@@ -76,15 +75,32 @@ namespace Test_Merge
|
|||||||
{
|
{
|
||||||
lblWindowPointsRemaining.Text = "1 point Remaining";
|
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
|
else
|
||||||
{
|
{
|
||||||
lblWindowPointsRemaining.Text = "";
|
lblWindowPointsRemaining.Text = "";
|
||||||
lblWindowsRemaining.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)
|
private void tbxGpUrl_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
GrandPrixUrl = tbxGpUrl.Text;
|
GrandPrixUrl = tbxGpUrl.Text;
|
||||||
@@ -137,6 +153,12 @@ namespace Test_Merge
|
|||||||
if (CreatingWindow)
|
if (CreatingWindow)
|
||||||
SwitchWindowCreation();
|
SwitchWindowCreation();
|
||||||
|
|
||||||
|
if (Emulator != null && Emulator.Ready)
|
||||||
|
{
|
||||||
|
Config = null;
|
||||||
|
pbxMain.Image = Emulator.Screenshot();
|
||||||
|
}
|
||||||
|
|
||||||
ZoneP1 = new Point(-1, -1);
|
ZoneP1 = new Point(-1, -1);
|
||||||
ZoneP2 = new Point(-1, -1);
|
ZoneP2 = new Point(-1, -1);
|
||||||
|
|
||||||
@@ -177,12 +199,15 @@ namespace Test_Merge
|
|||||||
if (CreatingZone && pbxMain.Image != null)
|
if (CreatingZone && pbxMain.Image != null)
|
||||||
{
|
{
|
||||||
Point coordinates = pbxMain.PointToClient(new Point(MousePosition.X, MousePosition.Y));
|
Point coordinates = pbxMain.PointToClient(new Point(MousePosition.X, MousePosition.Y));
|
||||||
|
|
||||||
float xOffset = (float)pbxMain.Image.Width / (float)pbxMain.Width;
|
float xOffset = (float)pbxMain.Image.Width / (float)pbxMain.Width;
|
||||||
float yOffset = (float)pbxMain.Image.Height / (float)pbxMain.Height;
|
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(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))
|
if (ZoneP1 == new Point(-1, -1))
|
||||||
{
|
{
|
||||||
ZoneP1 = newPoint;
|
ZoneP1 = newPoint;
|
||||||
@@ -190,7 +215,20 @@ namespace Test_Merge
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ZoneP2 = newPoint;
|
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();
|
SwitchZoneCreation();
|
||||||
}
|
}
|
||||||
RefreshUI();
|
RefreshUI();
|
||||||
@@ -215,22 +253,22 @@ namespace Test_Merge
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
WindowP2 = newPoint;
|
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);
|
WindowP1 = new Point(-1, -1);
|
||||||
WindowP2 = new Point(-1, -1);
|
WindowP2 = new Point(-1, -1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//CreateWindows();
|
CreateWindows(WindowsToAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RefreshUI();
|
RefreshUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private Rectangle createAbsoluteRectangle(Point p1, Point p2)
|
private Rectangle CreateAbsoluteRectangle(Point p1, Point p2)
|
||||||
{
|
{
|
||||||
Point newP1 = new Point();
|
Point newP1 = new Point();
|
||||||
Point newP2 = new Point();
|
Point newP2 = new Point();
|
||||||
@@ -256,13 +294,13 @@ namespace Test_Merge
|
|||||||
newP1.Y = p2.Y;
|
newP1.Y = p2.Y;
|
||||||
newP2.Y = p1.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)
|
private async void btnRefresh_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
btnRefresh.Enabled = false;
|
btnRefresh.Enabled = false;
|
||||||
if (Emulator == null)
|
if (Emulator == null || Emulator.GrandPrixUrl != tbxGpUrl.Text)
|
||||||
{
|
{
|
||||||
Emulator = new F1TVEmulator(tbxGpUrl.Text);
|
Emulator = new F1TVEmulator(tbxGpUrl.Text);
|
||||||
}
|
}
|
||||||
@@ -288,6 +326,9 @@ namespace Test_Merge
|
|||||||
case 104:
|
case 104:
|
||||||
message = "Error " + errorCode + " The url is not a valid url";
|
message = "Error " + errorCode + " The url is not a valid url";
|
||||||
break;
|
break;
|
||||||
|
case 105:
|
||||||
|
message = "Error " + errorCode + " There has been an error trying to emulate button presses. Please try again";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
message = "Could not start the emulator Error " + errorCode;
|
message = "Could not start the emulator Error " + errorCode;
|
||||||
break;
|
break;
|
||||||
@@ -305,5 +346,13 @@ namespace Test_Merge
|
|||||||
}
|
}
|
||||||
btnRefresh.Enabled = true;
|
btnRefresh.Enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Settings_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
if (Emulator != null)
|
||||||
|
{
|
||||||
|
Emulator.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -111,8 +111,13 @@ namespace Test_Merge
|
|||||||
}
|
}
|
||||||
public virtual Bitmap Draw()
|
public virtual Bitmap Draw()
|
||||||
{
|
{
|
||||||
Image img = ZoneImage;
|
Image img = Image;
|
||||||
Graphics g = Graphics.FromImage(img);
|
Graphics g = Graphics.FromImage(img);
|
||||||
|
foreach (Zone z in Zones)
|
||||||
|
{
|
||||||
|
Rectangle newBounds = new Rectangle(z.Bounds.X,z.Bounds.Y + Bounds.Y,z.Bounds.Width,z.Bounds.Height);
|
||||||
|
g.DrawRectangle(Pens.Red, newBounds);
|
||||||
|
}
|
||||||
foreach (Window w in Windows)
|
foreach (Window w in Windows)
|
||||||
{
|
{
|
||||||
g.DrawRectangle(Pens.Blue, w.Bounds);
|
g.DrawRectangle(Pens.Blue, w.Bounds);
|
||||||
|
|||||||
Reference in New Issue
Block a user