public override void ClickPressed(Point point, ButtonModifier modif) { Selection selection = null; modifier = ButtonModifier.None; if (ButtonClickPressed(point, modif, subPlayers, subInjury, homeButton, awayButton)) { return; } // FIXME: this is very awkward, click events should be forwarded to the child views point = VASDrawing.Utils.ToUserCoords(point, offset, scaleX, scaleY); selection = homeBench.GetSelection(point, 0, false); if (selection == null) { selection = awayBench.GetSelection(point, 0, false); if (selection == null) { selection = field.GetSelection(point, 0, false); if (selection != null) { point = VASDrawing.Utils.ToUserCoords(point, field.Position, 1, 1); } } else { point = VASDrawing.Utils.ToUserCoords(point, awayBench.Position, 1, 1); } } else { point = VASDrawing.Utils.ToUserCoords(point, homeBench.Position, 1, 1); } if (selection != null) { clickedPlayer = selection.Drawable as LMPlayerView; modifier = modif; (selection.Drawable as ICanvasObject).ClickPressed(point, modif); } else { clickedPlayer = null; } }
List <LMPlayerView> GetPlayersViews(IEnumerable <LMPlayerVM> players, TeamType team) { List <LMPlayerView> playerObjects; Color color = null; if (team == TeamType.LOCAL) { color = App.Current.Style.HomeTeamColor; } else { color = App.Current.Style.AwayTeamColor; } playerObjects = new List <LMPlayerView> (); foreach (var player in players) { LMPlayerView po = new LMPlayerView { Team = team }; po.ViewModel = player; po.ClickedEvent += HandlePlayerClickedEvent; po.RedrawEvent += (co, area) => { EmitRedrawEvent(po, area); }; playerObjects.Add(po); if ((team == TeamType.LOCAL) && !homePlayerToPlayerObject.ContainsKey(player)) { homePlayerToPlayerObject.Add(player, po); } else if ((team == TeamType.VISITOR) && !awayPlayerToPlayerObject.ContainsKey(player)) { awayPlayerToPlayerObject.Add(player, po); } } return(playerObjects); }
void HandlePlayerClickedEvent(ICanvasObject co) { LMPlayerView player = co as LMPlayerView; ViewModel.PlayerClick(player.ViewModel, modifier); }
void UpdateTeam(List <LMPlayerView> players, int [] formation, TeamType team) { int index = 0, offsetX; int width, colWidth; Color color; width = Width / NTeams; colWidth = width / formation.Length; if (team == TeamType.LOCAL) { color = App.Current.Style.HomeTeamColor; offsetX = 0; } else { color = App.Current.Style.AwayTeamColor; offsetX = Width; } /* Columns */ for (int col = 0; col < formation.Length; col++) { double colX, rowHeight; if (players.Count == index) { break; } if (team == TeamType.LOCAL) { colX = offsetX + colWidth * col + colWidth / 2; } else { colX = offsetX - colWidth * col - colWidth / 2; } rowHeight = Height / formation [col]; for (int row = 0; row < formation [col]; row++) { double rowY; LMPlayerView po = players [index]; if (team == TeamType.LOCAL) { rowY = rowHeight * row + rowHeight / 2; } else { rowY = Height - (rowHeight * row + rowHeight / 2); } po.Size = playerSize; po.Center = new Point(colX, rowY); index++; if (players.Count == index) { break; } } } }