/// <summary> /// Get player rod first player position by rod type /// </summary> /// <param name="mark">First Player Mark</param> /// <param name="position">Point - position of first player of rod in Frame dimensions</param> public void Set(eMarks mark, Point position) { if (IsFirstPlayerMark(mark)) { eRod rodType = MarkTypeToRodType(mark); Set(rodType, position); } }
//public static void DrawRodPlayers(eRod rod, int linearMoveDestination, eRotationalMove rotationalMove, bool isLocation = true) //{ // try // { // eMarks playersBase = 0; // eMarks mark; // Enum.TryParse<eMarks>(rod.ToString(), out mark); // int eMarkType = ((int)mark); // int rodPlayersCount = _rodPlayerCount[mark]; // int yDistance = _rodsPlayersDistance[mark]; // int firstPlayerOffsetY = _rodsOffsetY[mark]; // int rodStartX = XTableToDeviceCoordinates(_rods[mark]); // switch (eMarkType) // { // case (int)eMarks.GoalKeeper: playersBase = eMarks.GoalKeeperPlayer; break; // case (int)eMarks.Defence: playersBase = eMarks.DefencePlayer1; break; // case (int)eMarks.Midfield: playersBase = eMarks.MidfieldPlayer1; break; // case (int)eMarks.Attack: playersBase = eMarks.AttackPlayer1; break; // default: break; // } // for (int rodPlayer = 0; rodPlayer < rodPlayersCount; rodPlayer++) // { // int movmentOffset = 0; // int x = rodStartX; // int y = 0; // int y1 = 0; // if (isLocation) // { // ConvertToLocation(ref x, ref y1); // } // y = y1 + linearMoveDestination + firstPlayerOffsetY + yDistance * rodPlayer; // DrawPlayer(playersBase + rodPlayer, // new Point(x * _actualWidthRate, y * _actualHeightRate), 12, rotationalMove); // } // } // catch (Exception e) // { // Log.Common.Error(String.Format("[{0}] Failed to draw rods players mark. Reason: {1}", // MethodBase.GetCurrentMethod().Name, e.Message)); // } //} /// <summary> /// Drawing a single player at a time , used by the DrawRodPlayers method to draw all rods players /// </summary> /// <param name="eNumKey">eMark of the wanted rod : GOALKEEPER , Defence , Midfield, Attack</param> /// <param name="center">Center of the players radius</param> /// <param name="radius">Radius size</param> /// <param name="circleColor">Color for the roational current pos</param> private static void DrawPlayer(eMarks eNumKey, Point center, int radius, eRotationalMove rotationalMove, SolidColorBrush playerColor = null) { try { object token = null; if (_positionToken.ContainsKey(eNumKey)) { token = _positionToken[eNumKey]; } if (token != null) { lock (token) { _playerPositions[eNumKey] = center; } } int key = (int)eNumKey; int rotationalMoveFactor = 0; SolidColorBrush rotationalColor = Brushes.DarkBlue; if (rotationalMove == eRotationalMove.DEFENCE) { rotationalMoveFactor = radius; rotationalColor = Brushes.Blue; } else if (rotationalMove == eRotationalMove.RISE) { rotationalMoveFactor = (int)(radius * 2.5); rotationalColor = Brushes.Cyan; } _dispatcher.Invoke(new ThreadStart(delegate { (_markups[key] as Shape).Fill = (rotationalColor == null) ? Brushes.White : rotationalColor; _markups[key].Width = radius * 2; _markups[key].Height = radius * 2; Canvas.SetLeft(_markups[key], center.X - radius); Canvas.SetTop(_markups[key], center.Y - radius); (_markups[key + 5] as Shape).Height = 24; (_markups[key + 5] as Shape).Width = 30; (_markups[key + 5] as Shape).StrokeThickness = 2; (_markups[key + 5] as Shape).Fill = rotationalColor; Canvas.SetLeft(_markups[key + 5], center.X - rotationalMoveFactor); Canvas.SetTop(_markups[key + 5], center.Y - radius); })); } catch (Exception e) { Log.Print(String.Format("Failed to draw player mark. Reason: {0}", e.Message), eCategory.Error, LogTag.COMMON); } }
/// <summary> /// Draw a rod by a given eMark sign , moving the rod on the linear and rotational axes /// </summary> /// <param name="rod">eMark of the wanted rod : GoalKeeper, Defence , Midfield, Attack</param> /// <param name="deltaYMovment">The change on the linear movement</param> /// <param name="rotationalMove">eRotationalMove of the rod : DEFENCE, RISE, ATTACK</param> public static void DrawRodPlayers(eRod rod, int linearMoveDestination, eRotationalMove rotationalMove, bool isLocation = true) { try { eMarks playersBase = 0; eMarks mark; Enum.TryParse <eMarks>(rod.ToString(), out mark); int eMarkType = ((int)mark); int rodPlayersCount = _rodPlayerCount[mark]; int yDistance = _rodsPlayersDistance[mark]; int firstPlayerOffsetY = _rodsOffsetY[mark]; int x = XTableToDeviceCoordinates(_rods[mark]); switch (eMarkType) { case (int)eMarks.GoalKeeper: playersBase = eMarks.GoalKeeperPlayer; break; case (int)eMarks.Defence: playersBase = eMarks.DefencePlayer1; break; case (int)eMarks.Midfield: playersBase = eMarks.MidfieldPlayer1; break; case (int)eMarks.Attack: playersBase = eMarks.AttackPlayer1; break; default: break; } for (int rodPlayer = 0; rodPlayer < rodPlayersCount; rodPlayer++) { int y = linearMoveDestination + firstPlayerOffsetY + yDistance * rodPlayer; int y1 = y; int x1 = x; if (isLocation) { ConvertToLocation(ref x1, ref y); } DrawPlayer(playersBase + rodPlayer, new Point(x1 * _actualWidthRate, y1 * _actualHeightRate), 12, rotationalMove); } } catch (Exception e) { Log.Print(String.Format("Failed to draw rods players mark. Reason: {0}", e.Message), eCategory.Error, LogTag.COMMON); } }
/// <summary> /// Convert rod type to first player on rod mark /// </summary> /// <param name="rodType">Rod Type</param> /// <returns>First player on rod mark</returns> public eRod MarkTypeToRodType(eMarks markType) { switch (markType) { case eMarks.GoalKeeperPlayer: return eRod.GoalKeeper; case eMarks.DefencePlayer1: return eRod.Defence; case eMarks.MidfieldPlayer1: return eRod.Midfield; case eMarks.AttackPlayer1: return eRod.Attack; default: throw new NotSupportedException(String.Format( "Provided mark {0} is not of a first player, and cannot be converted to eRod type.", markType)); } }
public static Point PlayerPosition(eRod type) { eMarks mark = eMarks.NA; switch (type) { case eRod.GoalKeeper: mark = eMarks.GoalKeeper; break; case eRod.Defence: mark = eMarks.DefencePlayer1; break; case eRod.Midfield: mark = eMarks.MidfieldPlayer1; break; case eRod.Attack: mark = eMarks.AttackPlayer1; break; default: break; } if (_playerPositions.ContainsKey(mark)) { object token = _positionToken[mark]; Point? point = null; lock (token) { point = new Point(_playerPositions[mark].X, _playerPositions[mark].Y); } if (point != null) { return((Point)point); } } throw new NotSupportedException("Not supported player type"); }
/// <summary> /// Parsing sector line marks by selected rod type /// </summary> /// <param name="type"></param> /// <param name="lineA"></param> /// <param name="lineB"></param> protected void TryParseToSectorLineMarks(eRod type, out eMarks lineA, out eMarks lineB) { lineA = eMarks.NA; lineB = eMarks.NA; switch (type) { case eRod.GoalKeeper: lineA = eMarks.GoalKeeperSector1; lineB = eMarks.GoalKeeperSector2; break; case eRod.Defence: lineA = eMarks.DefenceSector1; lineB = eMarks.DefenceSector2; break; case eRod.Midfield: lineA = eMarks.MidfieldSector1; lineB = eMarks.MidfieldSector2; break; case eRod.Attack: lineA = eMarks.AttackSector1; lineB = eMarks.AttackSector2; break; } }
/// <summary> /// Convert provided calibration mark to out parameters: mark of circle and text /// </summary> /// <param name="mark">Calibration mark</param> /// <param name="circle">[OUT] circle mark</param> /// <param name="text">[OUT] text mark</param> protected void TryParseToCalibrationCircleAndTextMark(eCallibrationMark mark, out eMarks circle, out eMarks text) { circle = eMarks.NA; text = eMarks.NA; switch (mark) { case eCallibrationMark.BL: circle = eMarks.ButtomLeftMark; text = eMarks.ButtomLeftText; break; case eCallibrationMark.BR: circle = eMarks.ButtomRightMark; text = eMarks.ButtomRightText; break; case eCallibrationMark.TL: circle = eMarks.TopLeftMark; text = eMarks.TopLeftText; break; case eCallibrationMark.TR: circle = eMarks.TopRightMark; text = eMarks.TopRightText; break; } }
/// <summary> /// Verify if selected mark is first player of rod mark /// </summary> /// <param name="markType">Mark</param> /// <returns>[True] if selected mark is first player of rod mark, [False] otherwise</returns> public bool IsFirstPlayerMark(eMarks markType) { switch (markType) { case eMarks.GoalKeeperPlayer: case eMarks.DefencePlayer1: case eMarks.MidfieldPlayer1: case eMarks.AttackPlayer1: return true; default: return false; } }
/// <summary> /// Drawing a single player at a time , used by the DrawRodPlayers method to draw all rods players /// </summary> /// <param name="playerMark">eMark of the wanted rod : GoalKeeper, Defense , Midfield, Attack</param> /// <param name="center">Center of the players radius in Foosbot WORLD</param> /// <param name="radius">Radius size</param> /// <param name="circleColor">Color for the rotational current position</param> private void DrawPlayer(eMarks playerMark, Point center, eRotationalMove rotationalMove) { try { if (rotationalMove != eRotationalMove.NA) { //update position of player (only if first on rod) _state.Set(playerMark, center); //get coordinates in Frame dimesions center = TransformAgent.Data.InvertTransform(center); //get coordinates in Screen dimesions center = _screen.FrameToScreenCoordinates(center); //Select color based on Rotational Move SolidColorBrush color = Brushes.Blue; //default for defense int bodyOffset = 0; switch(rotationalMove) { case eRotationalMove.KICK: color = Brushes.DarkBlue; bodyOffset = -PLAYER_RADIUS; break; case eRotationalMove.RISE: color = Brushes.Cyan; bodyOffset = Convert.ToInt32(PLAYER_RADIUS * 1.5); break; } _dispatcher.Invoke(() => { //Draw Player Body _screen.Element<Shape>(playerMark+5).Fill = color; _screen.Element<Shape>(playerMark + 5).Width = PLAYER_RADIUS * 2.5; _screen.Element<Shape>(playerMark + 5).Height = PLAYER_RADIUS * 2; _screen.Draw(playerMark + 5, center.X - PLAYER_RADIUS - bodyOffset, center.Y - PLAYER_RADIUS, eCoordinatesType.Screen, 10); //Draw Player Head _screen.Element<Shape>(playerMark).Fill = Brushes.DarkBlue; _screen.Element<Shape>(playerMark).Stroke = Brushes.White; _screen.Element<Shape>(playerMark).Width = PLAYER_RADIUS * 2; _screen.Element<Shape>(playerMark).Height = PLAYER_RADIUS * 2; _screen.Draw(playerMark, center.X - PLAYER_RADIUS, center.Y - PLAYER_RADIUS, eCoordinatesType.Screen, 20); }); } } catch (Exception e) { Log.Print(String.Format("Unable to draw player mark. Reason: {0}", e.Message), eCategory.Warn, LogTag.COMMON); } }