// 08-19-2011 Scott public static void ReadDrawingUp(Drawing drawing, XElement element) { var figuresNode = element.Element("Figures"); var figures = ReadFigures(figuresNode, drawing); drawing.Add(figures, false); // 08-19-2011 Scott System.Windows.Point ptBall = new System.Windows.Point(0, 0); foreach (IFigure figure in figures) { if (figure is Game.PBBall) { ptBall = (figure as Game.PBBall).Coordinates; break; } } System.Windows.Point ptPlayer = figures.OfType<Game.PBPlayer>().First().Coordinates; if (figures.OfType<Game.PBPlayer>().All(p => p.ScoutType == 1)) // 01-04-2010 Scott { if (ptBall.Y > ptPlayer.Y) { figures.OfType<PointBase>().ForEach(p => { p.X = -p.Coordinates.X; p.Y = -p.Coordinates.Y; }); } } // end drawing.Recalculate(); }
public void EndEdit() { if (Edit.Text.Trim().IsEmpty()) { return; } double left = Canvas.GetLeft(Edit); double top = Canvas.GetTop(Edit); if (Label == null) { PBLabel label = new PBLabel() { Coordinates = ToLogical(new Point(left, top)), Text = Edit.Text, }; Drawing.Add(label, true); } else { Label.Text = Edit.Text; } CancelEdit(); }
public static void ReadDrawingReverse(Drawing drawing, XElement element) { var figuresNode = element.Element("Figures"); var figures = ReadFigures(figuresNode, drawing); drawing.Add(figures, false); if (drawing.Figures.OfType<Game.PBPlayer>().All(p => p.Coordinates.Y < 0)) // 01-04-2010 Scott { drawing.Figures.OfType<PointBase>().ForEach(p => { p.X = -p.Coordinates.X; p.Y = -p.Coordinates.Y; }); } drawing.Recalculate(); }
protected override void MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (Drawing != null) { Point ptPhy = Coordinates(e); Microsoft.Win32.OpenFileDialog ofDialog = new Microsoft.Win32.OpenFileDialog() { Title = "Insert Background", Filter = Webb.Playbook.Data.Extensions.ImageFileFilter, }; if (ofDialog.ShowDialog().Value) { ImageBrush imgBrush = new ImageBrush() { Stretch = Stretch.None, AlignmentX = AlignmentX.Center, AlignmentY = AlignmentY.Center, ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri(ofDialog.FileName, UriKind.RelativeOrAbsolute)), }; System.Drawing.Image image = System.Drawing.Image.FromFile(ofDialog.FileName); PBImage pbImg = new PBImage() { Coordinates = ptPhy, File = ofDialog.FileName, Width = ToLogical(image.Width), Height = ToLogical(image.Height), }; Drawing.Add(pbImg); pbImg.MoveTo(pbImg.Coordinates); } Drawing.SetDefaultBehavior(); } }
//public static void ReadPlayer(Drawing drawing, Game.PBPlayer player, string strFile) // 11-04-2010 Scott //{ // string text = System.IO.File.ReadAllText(strFile); // XElement element = XElement.Parse(text); // DrawingDeserializer.ReadPlayer(drawing, player, element); //} //public static void ReadPlayer(Drawing drawing, Game.PBPlayer player, XElement element) // 11-04-2010 Scott //{ // var figuresNode = element.Element("Figures"); // var figures = ReadFigures(figuresNode, drawing); // drawing.Add(figures, false); // drawing.Recalculate(); //} public static void ReadDrawing(Drawing drawing, XElement element) { if(element.Attribute("Title") != null) { drawing.Title = bool.Parse(element.ReadString("Title")); } if(element.Attribute("BackgroundPath") != null) { drawing.BackgroundPath = element.ReadString("BackgroundPath"); } if (element.Attribute("YardLine") != null) // 01-20-2012 Scott { drawing.YardLine = element.ReadDouble("YardLine"); } var figuresNode = element.Element("Figures"); var figures = ReadFigures(figuresNode, drawing); drawing.Add(figures, false); drawing.Recalculate(); //drawing.CoordinateSystem.MoveTo(drawing.Figures.OfType<IPoint>().Midpoint().Minus()); }
protected override void MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { offsetFromFigureLeftTopCorner = Coordinates(e); oldCoordinates = offsetFromFigureLeftTopCorner; IEnumerable <IFigure> figures = Drawing.GetSelectedFigures(); if (figures != null && figures.Count() > 0) { IFigure source = figures.ElementAt(0); if (source is Game.PBPlayer) { Game.PBPlayer sourcePlayer = source as Game.PBPlayer; IFigure endFigure = sourcePlayer.GetEndFigure(); if (endFigure == null) { endFigure = source; } if (!(endFigure is Game.PBPlayer) && !(endFigure is Game.Zone) && (endFigure is FreePoint)) { if (endFigure.Dependents.Count > 0) { PBLine endline = endFigure.Dependents.ElementAt(0) as PBLine; if (endline != null && endline.CapType == CapType.Arrow) { IFigure underMouse = CreatePointAtCurrentPosition(offsetFromFigureLeftTopCorner, false); PBLine line = new PBLine(); List <IFigure> dependencies = new List <IFigure>(); dependencies.Add(endFigure); dependencies.Add(underMouse); line.Dependencies = dependencies; Drawing.Add(line); if (!Drawing.DrawingMode) { line.CapType = CapType.BlockArea; line.StrokeColor = Webb.Playbook.Data.ColorSetting.Instance.BlockColor; } Drawing.Figures.UpdateVisual(); } } } else if (endFigure == source) { IFigure underMouse = CreatePointAtCurrentPosition(offsetFromFigureLeftTopCorner, false); PBLine line = new PBLine(); List <IFigure> dependencies = new List <IFigure>(); dependencies.Add(endFigure); dependencies.Add(underMouse); line.Dependencies = dependencies; Drawing.Add(line); if (!Drawing.DrawingMode) { line.CapType = CapType.BlockArea; line.StrokeColor = Webb.Playbook.Data.ColorSetting.Instance.BlockColor; } Drawing.Figures.UpdateVisual(); } } } }
/// <summary> /// Assumes coordinates are logical already /// </summary> /// <param name="coordinates">Logical coordinates of the click point</param> protected override void MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { // 11-18-2010 Scott if (e.ClickCount == 2) { Drawing.SetDefaultBehavior(); return; } IEnumerable <IFigure> selectedFigures = Drawing.GetSelectedFigures(); PBPlayer player = null; if (selectedFigures != null && selectedFigures.Count() > 0) { player = selectedFigures.ElementAt(0) as PBPlayer; if (player == null) { return; } } else { return; } //Type expectedType = ExpectedDependency; System.Windows.Point coordinates = Coordinates(e); IFigure underMouse = null; underMouse = Drawing.Figures.HitTest(coordinates); if (underMouse == player) { Drawing.SetDefaultBehavior(); return; } IFigure endFigure = player.GetEndFigure(); if (endFigure is Game.Zone) { return; } player.ChangeLineType(CapType.Arrow); FreePoint pp = CreatePointAtCurrentPosition(coordinates, false); FigureList fl = new FigureList(); if (endFigure != null) { if (endFigure is Game.PBPlayer) { player.ClearEndPath(); endFigure = player.GetEndFigure(); if (endFigure != null) { fl.Add(endFigure); } else { fl.Add(player); } } else { fl.Add(endFigure); } } else { fl.Add(player); } fl.Add(pp); PBLine line = Factory.CreateArrowLine(Drawing, fl); if (!Drawing.DrawingMode) { line.StrokeColor = Webb.Playbook.Data.ColorSetting.Instance.RouteColor; } FigureList figureList = new FigureList(); figureList.Add(line); figureList.Add(pp); Drawing.Add(figureList as IEnumerable <IFigure>); Drawing.Figures.CheckConsistency(); Drawing.Figures.UpdateVisual(); //if (TempPoint != null) //{ // underMouse = Drawing.Figures.HitTest( // coordinates, // typeof(IPoint)); //} //else if (expectedType != null) //{ // underMouse = Drawing.Figures.HitTest(coordinates, expectedType); //} //else //{ // underMouse = Drawing.Figures.HitTest(coordinates); //} //if (underMouse != null // && underMouse != TempPoint // && ((FoundDependencies.Contains(underMouse) && !CanReuseDependency()) // || underMouse == TempResult)) //{ // return; //} //IFigure endPointFigure = player.GetEndFigure(); //if (TempPoint == null && underMouse != player && underMouse != endPointFigure) //{ // return; //} //if (ExpectingAPoint()) //{ // if (underMouse == null) // { // underMouse = CreatePointAtCurrentPosition(coordinates, true); // FigureList fl = new FigureList(); // fl.Add(player); // if (underMouse != null) // { // fl.Add(underMouse); // } // PBLine line = Factory.CreateArrowLine(Drawing, fl); // FigureList figureList = new FigureList(); // figureList.Add(line); // figureList.Add(underMouse); // Drawing.Add(figureList as IEnumerable<IFigure>); // return; // } // else // { // // one branch only // if (underMouse is Webb.Playbook.Geometry.Game.PBPlayer && underMouse.Dependents.Count > 0) // { // foreach (IFigure dep in underMouse.Dependents) // { // if (dep.Dependencies != null && dep.Dependencies.Count() > 1 && dep.Dependencies.ElementAt(0) == underMouse) // { // return; // } // } // if (underMouse != player) // { // return; // } // } // // at most two branch // else if (underMouse is IPoint && underMouse.Dependents.Count > 1) // { // return; // } // else if (underMouse is Zone) // { // return; // } // } //} //RemoveIntermediateFigureIfNecessary(); //if (TempPoint != null) //{ // //if (underMouse == TempPoint || underMouse == TempResult || underMouse == null) // //{ // underMouse = CreatePointAtCurrentPosition(coordinates, true); // //} // TempPoint.SubstituteWith(underMouse); // FoundDependencies.Remove(TempPoint); // Drawing.Figures.Remove(TempPoint); // TempPoint = null; //} //if (ExpectedDependency != null) //{ // AddFoundDependency(underMouse); //} //if (ExpectedDependency != null) //{ // if (ExpectingAPoint()) // { // player.ChangeLineType(CapType.Arrow); // 01-07-2010 Scott // TempPoint = CreateTempPoint(coordinates); // AddFoundDependency(TempPoint); // if (ExpectedDependency == null) // { // CreateAndAddFigure(); // Drawing.Figures.UpdateVisual(); // } // } // AddIntermediateFigureIfNecessary(); // AdvertiseNextDependency(); //} //else //{ // Finish(); // //07-22-2009 scott // if (IsMouseButtonDown) // {// click mode // IFigure endFigure = Drawing.Figures.HitTest(coordinates, typeof(Webb.Playbook.Geometry.Game.PBPlayer)); // if (endFigure is Webb.Playbook.Geometry.Game.PBPlayer) // { // Drawing.ActionManager.Undo(); // } // else // { // MouseLeftButtonDown(sender, e as System.Windows.Input.MouseButtonEventArgs); // } // } // else // {// drag mode // } //} //Drawing.Figures.CheckConsistency(); //Drawing.Figures.UpdateVisual(); }
public void CreatePlayers(Webb.Playbook.Geometry.Drawing drawing, Data.Personnel personnel, bool bCreateBall, double dLogicScrimmage) { // 03-16-2011 Scott double radius = Webb.Playbook.Data.GameSetting.Instance.PlayerSize; double angle = Webb.Playbook.Data.GameSetting.Instance.PlayerAngle; PlayerAppearance playerAppearance = (PlayerAppearance)Enum.Parse(typeof(PlayerAppearance), Webb.Playbook.Data.GameSetting.Instance.PlayerAppearance); double thickness = Webb.Playbook.Data.GameSetting.Instance.PlayerThickness; bool dash = Webb.Playbook.Data.GameSetting.Instance.PlayerDash; bool textVisibility = Webb.Playbook.Data.GameSetting.Instance.PlayerTextVisibility; IEnumerable <Webb.Playbook.Geometry.Game.PBPlayer> players = drawing.Figures.OfType <Webb.Playbook.Geometry.Game.PBPlayer>(); if (players != null && players.Count() > 0) { radius = players.First().Radius; } double scrimmage = dLogicScrimmage; int i = 0; double x = 0; double y = 0; double size = Webb.Playbook.Data.GameSetting.Instance.PlayerSize * 1.1; //Color colorOffense = Colors.OrangeRed; //Color colorDefense = Colors.SteelBlue; if (personnel.ScoutType == ScoutTypes.Offensive) { foreach (Position pos in personnel.Positions.FindAll(p => p.Name.StartsWith("QB"))) { PBPlayer player = new PBPlayer(playerAppearance, pos.Name) { Text = pos.Value, Coordinates = new Point(0, scrimmage - 2 * size), Stance = "TwoPointCenter", FillColor = ColorSetting.Instance.OffensivePlayerColor, Radius = radius, Angle = angle, StrokeThickness = thickness, TextVisible = textVisibility, Dash = dash, }; drawing.Add(player); } y = -0.5 * size; foreach (Position pos in personnel.Positions.FindAll(p => p.Name.StartsWith("OL"))) { i = pos.ID - 1; PBPlayer player = new PBPlayer(playerAppearance, pos.Name) { Text = pos.Value, Coordinates = new Point((i + 1) / 2 * System.Math.Pow(-1, i) * size, scrimmage + y), Stance = "ThreePointRight", FillColor = ColorSetting.Instance.OffensivePlayerColor, Radius = radius, Angle = angle, StrokeThickness = thickness, TextVisible = textVisibility, Dash = dash, }; drawing.Add(player); } x = -6 * size; y = -1 * size; foreach (Position pos in personnel.Positions.FindAll(p => p.Name.StartsWith("TE"))) { i = pos.ID - 1; PBPlayer player = new PBPlayer(playerAppearance, pos.Name) { Text = pos.Value, Coordinates = new Point(x, scrimmage + y - i * size), Stance = "ThreePointRight", FillColor = ColorSetting.Instance.OffensivePlayerColor, Radius = radius, Angle = angle, StrokeThickness = thickness, TextVisible = textVisibility, Dash = dash, }; drawing.Add(player); } x = 8 * size; y = -1 * size; foreach (Position pos in personnel.Positions.FindAll(p => p.Name.StartsWith("WR"))) { i = pos.ID - 1; PBPlayer player = new PBPlayer(playerAppearance, pos.Name) { Text = pos.Value, Coordinates = new Point(x, scrimmage + y - i * size), Stance = "TwoPointRight", FillColor = ColorSetting.Instance.OffensivePlayerColor, Radius = radius, Angle = angle, StrokeThickness = thickness, TextVisible = textVisibility, Dash = dash, }; drawing.Add(player); } x = 0 * size; y = -4 * size; foreach (Position pos in personnel.Positions.FindAll(p => p.Name.StartsWith("RB"))) { i = pos.ID - 1; PBPlayer player = new PBPlayer(playerAppearance, pos.Name) { Text = pos.Value, Coordinates = new Point(x, scrimmage + y - i * size), Stance = "TwoPointCenter", FillColor = ColorSetting.Instance.OffensivePlayerColor, Radius = radius, Angle = angle, StrokeThickness = thickness, TextVisible = textVisibility, Dash = dash, }; drawing.Add(player); } } else if (personnel.ScoutType == ScoutTypes.Defensive) { y = 0.5 * size; foreach (Position pos in personnel.Positions.FindAll(p => p.Name.StartsWith("DL"))) { i = pos.ID - 1; PBPlayer player = new PBPlayer(playerAppearance, pos.Name) { Text = pos.Value, Coordinates = new Point((i + 1) / 2 * System.Math.Pow(-1, i) * size, scrimmage + y), Stance = "ThreePointLeft", FillColor = ColorSetting.Instance.DefensivePlayerColor, Radius = radius, Angle = angle, StrokeThickness = thickness, TextVisible = textVisibility, Dash = dash, }; drawing.Add(player); } x = 8 * size; y = 1 * size; foreach (Position pos in personnel.Positions.FindAll(p => p.Name.StartsWith("CB"))) { i = pos.ID - 1; PBPlayer player = new PBPlayer(playerAppearance, pos.Name) { Text = pos.Value, Coordinates = new Point(x * System.Math.Pow(-1, i) * size, scrimmage + (i / 2) * size + y), Stance = "TwoPointCenter", FillColor = ColorSetting.Instance.DefensivePlayerColor, Radius = radius, Angle = angle, StrokeThickness = thickness, TextVisible = textVisibility, Dash = dash, }; drawing.Add(player); } y = 3 * size; foreach (Position pos in personnel.Positions.FindAll(p => p.Name.StartsWith("LB"))) { i = pos.ID - 1; PBPlayer player = new PBPlayer(playerAppearance, pos.Name) { Text = pos.Value, Coordinates = new Point((i + 1) / 2 * System.Math.Pow(-1, i) * size, scrimmage + y), Stance = "TwoPointCenter", FillColor = ColorSetting.Instance.DefensivePlayerColor, Radius = radius, Angle = angle, StrokeThickness = thickness, TextVisible = textVisibility, Dash = dash, }; drawing.Add(player); } y = 5.5 * size; foreach (Position pos in personnel.Positions.FindAll(p => p.Name.StartsWith("S"))) { i = pos.ID - 1; PBPlayer player = new PBPlayer(playerAppearance, pos.Name) { Text = pos.Value, Coordinates = new Point((i + 1) / 2 * System.Math.Pow(-1, i) * size, scrimmage + y), Stance = "TwoPointCenter", FillColor = ColorSetting.Instance.DefensivePlayerColor, Radius = radius, Angle = angle, StrokeThickness = thickness, TextVisible = textVisibility, Dash = dash, }; drawing.Add(player); } } if (bCreateBall) { Point ptBall = new Point(0, 0); bool bHasBall = false; foreach (PBPlayer player in drawing.Figures.OfType <PBPlayer>()) { if (personnel.ScoutType == ScoutTypes.Offensive) { if (player.Name == PersonnelEditor.OffHasBallPlayer) { ptBall = player.Coordinates; bHasBall = true; } } else if (personnel.ScoutType == ScoutTypes.Defensive) { if (player.Name == PersonnelEditor.DefHasBallPlayer) { ptBall = player.Coordinates; bHasBall = true; } } } if (bHasBall) { PBBall ball = new PBBall() { Center = new Point(ptBall.X, personnel.ScoutType == ScoutTypes.Defensive ? ptBall.Y - 0.5f : ptBall.Y + 0.5f), }; if (drawing.Figures.OfType <PBBall>().Count() == 0) { ball.Visible = Webb.Playbook.Data.GameSetting.Instance.ShowBall; drawing.Add(ball); } } } }
protected override void MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { bool bSuccess = false; offsetFromFigureLeftTopCorner = Coordinates(e); oldCoordinates = offsetFromFigureLeftTopCorner; IFigure found = Drawing.Figures.HitTest(offsetFromFigureLeftTopCorner, typeof(Game.PBPlayer)); if (found != null && found is Game.PBPlayer) { Game.PBPlayer targetPlayer = found as Game.PBPlayer; IEnumerable <IFigure> figures = Drawing.GetSelectedFigures(); if (figures != null && figures.Count() > 0) { IFigure source = figures.ElementAt(0); if (source is Game.PBPlayer) { Game.PBPlayer sourcePlayer = source as Game.PBPlayer; if (sourcePlayer.ScoutType != targetPlayer.ScoutType) { IFigure endfigure = sourcePlayer.GetEndFigure(); if (endfigure == null) { endfigure = source; } if (!(endfigure is Game.PBPlayer) && !(endfigure is Game.Zone) && (endfigure is FreePoint)) { if (endfigure.Dependents.Count > 0) { PBLine endline = endfigure.Dependents.ElementAt(0) as PBLine; if (endline != null /*&& endline.CapType == CapType.Arrow*/) { PBLine line = new PBLine(); List <IFigure> dependencies = new List <IFigure>(); dependencies.Add(endfigure); dependencies.Add(found); line.Dependencies = dependencies; sourcePlayer.ChangeLineType(CapType.Arrow); Drawing.Add(line); if (!Drawing.DrawingMode) { line.CapType = CapType.Block; line.StrokeColor = Webb.Playbook.Data.ColorSetting.Instance.BlockColor; } Drawing.Figures.UpdateVisual(); Drawing.SetDefaultBehavior(); bSuccess = true; } } } else if (endfigure == source) { PBLine line = new PBLine(); List <IFigure> dependencies = new List <IFigure>(); dependencies.Add(endfigure); dependencies.Add(found); line.Dependencies = dependencies; sourcePlayer.ChangeLineType(CapType.Arrow); Drawing.Add(line); if (!Drawing.DrawingMode) { line.CapType = CapType.Block; line.StrokeColor = Webb.Playbook.Data.ColorSetting.Instance.BlockColor; } Drawing.Figures.UpdateVisual(); Drawing.SetDefaultBehavior(); bSuccess = true; } } } } } if (!bSuccess) { MessageBox.Show("You must select a player of opposing team !"); } }
/// <summary> /// Assumes coordinates are logical already /// </summary> /// <param name="coordinates">Logical coordinates of the click point</param> protected override void MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { if (e.ClickCount > 1) { Drawing.SetDefaultBehavior(); return; } IEnumerable <IFigure> selectedFigures = Drawing.GetSelectedFigures(); PBPlayer player = null; IFigure endFigure = null; if (selectedFigures != null && selectedFigures.Count() > 0) { player = selectedFigures.ElementAt(0) as PBPlayer; } //Type expectedType = ExpectedDependency; System.Windows.Point coordinates = Coordinates(e); IFigure underMouse = null; underMouse = Drawing.Figures.HitTest(coordinates); if (underMouse is Game.PBPlayer) { if (underMouse == player) { Drawing.SetDefaultBehavior(); return; } player = underMouse as Game.PBPlayer; Drawing.ClearSelectedFigures(); player.Selected = true; Drawing.Figures.UpdateVisual(); return; } else if (underMouse is IPoint && (underMouse as IPoint).Dependents.Count == 1) { Drawing.ClearSelectedFigures(); underMouse.Selected = true; Drawing.Figures.UpdateVisual(); return; } if (player == null) { if (selectedFigures != null && selectedFigures.Count() > 0) { IFigure figure = selectedFigures.ElementAt(0); if (figure is IPoint && (figure as IPoint).Dependents.Count == 1) { endFigure = figure; } else { return; } } else { return; } } else {// 09-26-2011 Scott endFigure = null; //endFigure = player.GetEndFigure(); //player.ChangeLineType(CapType.Arrow); //if (endFigure is Game.Zone) //{ // return; //} } FreePoint pp = CreatePointAtCurrentPosition(coordinates, false); FigureList fl = new FigureList(); if (endFigure != null) { if (endFigure is Game.PBPlayer) { player.ClearEndPath(); endFigure = player.GetEndFigure(); if (endFigure != null) { fl.Add(endFigure); } else { fl.Add(player); } } else { fl.Add(endFigure); } } else { fl.Add(player); } fl.Add(pp); PBLine line = Factory.CreateArrowLine(Drawing, fl); if (!Drawing.DrawingMode) { line.StrokeColor = Webb.Playbook.Data.ColorSetting.Instance.RouteColor; } FigureList figureList = new FigureList(); figureList.Add(line); figureList.Add(pp); Drawing.Add(figureList as IEnumerable <IFigure>); Drawing.ClearSelectedFigures(); pp.Selected = true; Drawing.Figures.CheckConsistency(); Drawing.Figures.UpdateVisual(); }