Example #1
0
        public SoccerLineupDetailsViewModel(Team team, IChangeManager changeManager, CollectionFactory collections)
        {
            _changeManager = changeManager;
            _teamModel     = team;

            Collections = collections;
            Team        = new TeamViewModel(team, _changeManager, Collections);

            SoccerPlayerViewModel.IsSelectedPropertyChanged += SoccerPlayerViewModel_IsSelectedPropertyChanged;

            Substitutions = Team.Squad.Where(p => (RotationTeam)p.RotationTeam.Value == RotationTeam.Substitute).ToSquadList();
            if (Substitutions.Count < 7)
            {
                Substitutions.Add(new SoccerPlayerViewModel()
                {
                    Name = new EditableCellViewModel(string.Empty, _changeManager), Position = new ComboBoxCellViewModel(null, null, _changeManager)
                });
            }
            Substitutions.RemoveFirstNames();
            Substitutions.ArrangePositionRoleAsec();

            Reserves = Team.Squad.Where(p => (RotationTeam)p.RotationTeam.Value == RotationTeam.Reserves).ToSquadList();
            Reserves.RemoveFirstNames();
            Reserves.ArrangePositionRoleAsec();

            DragDropPlayer = new RelayCommand <SoccerPlayerViewModel>(DragOrDropFieldPlayer);
        }
Example #2
0
        public void Changed(ChangeArgs args)
        {
            #region Substitution
            if (args is SubstitutionArgs)
            {
                var subArgs   = (SubstitutionArgs)args;
                var firstSub  = subArgs.FirstSub;
                var secondSub = subArgs.SecondSub;

                switch (args.Type)
                {
                case ChangeType.SubSelected:
                    if (_firstSubstitute == null)
                    {
                        _firstSubstitute = Team.Squad.Find(p => p.Id == firstSub.Id);
                    }
                    else if (firstSub.Id == _firstSubstitute.Id && secondSub == null)
                    {
                        return;
                    }

                    if (secondSub != null)
                    {
                        if (_secondSubstitute == null)
                        {
                            _secondSubstitute = Team.Squad.Find(p => p.Id == secondSub.Id);
                        }
                        else if (secondSub.Id == _secondSubstitute.Id)
                        {
                            return;
                        }
                    }
                    break;

                case ChangeType.SubDeselect:
                    if (firstSub != null)
                    {
                        _firstSubstitute = null;
                    }
                    else if (secondSub != null)
                    {
                        _secondSubstitute = null;
                    }
                    break;

                case ChangeType.SubConfirmed:
                    _firstSubstitute.RotationTeam.Value  = firstSub.Rotation;
                    _secondSubstitute.RotationTeam.Value = secondSub.Rotation;

                    var firstSubIndex  = Substitutions.Contains(_firstSubstitute) ? Substitutions.IndexOf(_firstSubstitute) : Reserves.IndexOf(_firstSubstitute);
                    var secondSubIndex = Substitutions.Contains(_secondSubstitute) ? Substitutions.IndexOf(_secondSubstitute) : Reserves.IndexOf(_secondSubstitute);

                    var firstSubX  = subArgs.secondSubX;
                    var firstSubY  = subArgs.secondSubY;
                    var secondSubX = subArgs.firstSubX;
                    var secondSubY = subArgs.firstSubY;

                    // sub inside 'lineup details'
                    if ((RotationTeam)_firstSubstitute.RotationTeam.Value != RotationTeam.Lineup && (RotationTeam)_secondSubstitute.RotationTeam.Value != RotationTeam.Lineup)
                    {
                        // sub inside same rotation team
                        if ((RotationTeam)_firstSubstitute.RotationTeam.Value == (RotationTeam)_secondSubstitute.RotationTeam.Value)
                        {
                            if (Substitutions.Contains(_firstSubstitute))
                            {
                                Substitutions.RemoveAt(firstSubIndex);
                                Substitutions.Insert(firstSubIndex, _secondSubstitute);
                                Substitutions.RemoveAt(secondSubIndex);
                                Substitutions.Insert(secondSubIndex, _firstSubstitute);
                            }
                            else if (Reserves.Contains(_firstSubstitute))
                            {
                                Reserves.RemoveAt(firstSubIndex);
                                Reserves.Insert(firstSubIndex, _secondSubstitute);
                                Reserves.RemoveAt(secondSubIndex);
                                Reserves.Insert(secondSubIndex, _firstSubstitute);
                            }
                        }
                        // sub between differant rotaion team
                        else if ((RotationTeam)_firstSubstitute.RotationTeam.Value != (RotationTeam)_secondSubstitute.RotationTeam.Value)
                        {
                            if (Substitutions.Contains(_firstSubstitute))
                            {
                                Substitutions.RemoveAt(firstSubIndex);
                                Substitutions.Insert(firstSubIndex, _secondSubstitute);

                                Reserves.RemoveAt(secondSubIndex);
                                Reserves.Insert(secondSubIndex, _firstSubstitute);
                            }
                            else if (Reserves.Contains(_firstSubstitute))
                            {
                                Reserves.RemoveAt(firstSubIndex);
                                Reserves.Insert(firstSubIndex, _secondSubstitute);

                                Substitutions.RemoveAt(secondSubIndex);
                                Substitutions.Insert(secondSubIndex, _firstSubstitute);
                            }
                        }
                    }
                    // sub first sub from 'field details' to second sub in 'lineup details'
                    else if ((RotationTeam)_firstSubstitute.RotationTeam.Value == RotationTeam.Lineup && (RotationTeam)_secondSubstitute.RotationTeam.Value != RotationTeam.Lineup)
                    {
                        if (Substitutions.Contains(_secondSubstitute))
                        {
                            Substitutions.Remove(_secondSubstitute);
                            _firstSubstitute.RotationTeam.Value = RotationTeam.Substitute;
                            Substitutions.Insert(secondSubIndex, _firstSubstitute);
                        }
                        else if (Reserves.Contains(_secondSubstitute))
                        {
                            Reserves.Remove(_secondSubstitute);
                            _firstSubstitute.RotationTeam.Value = RotationTeam.Reserves;
                            Reserves.Insert(secondSubIndex, _firstSubstitute);
                        }

                        _secondSubstitute.X = firstSubX;
                        _secondSubstitute.Y = firstSubY;
                        _firstSubstitute.X  = secondSubX;
                        _firstSubstitute.Y  = secondSubY;
                    }
                    // sub first sub from 'lineup details' to second sub in 'field details'
                    else if ((RotationTeam)_firstSubstitute.RotationTeam.Value != RotationTeam.Lineup && (RotationTeam)_secondSubstitute.RotationTeam.Value == RotationTeam.Lineup)
                    {
                        if (Substitutions.Contains(_firstSubstitute))
                        {
                            Substitutions.Remove(_firstSubstitute);
                            _secondSubstitute.RotationTeam.Value = RotationTeam.Substitute;
                            Substitutions.Insert(firstSubIndex, _secondSubstitute);
                        }
                        else if (Reserves.Contains(_firstSubstitute))
                        {
                            Reserves.Remove(_firstSubstitute);
                            _secondSubstitute.RotationTeam.Value = RotationTeam.Reserves;
                            Reserves.Insert(firstSubIndex, _secondSubstitute);
                        }

                        _firstSubstitute.X  = secondSubX;
                        _firstSubstitute.Y  = secondSubY;
                        _secondSubstitute.X = firstSubX;
                        _secondSubstitute.Y = firstSubY;
                    }

                    Substitutions.RemoveFirstNames();
                    Substitutions.ArrangePositionRoleAsec();
                    Substitutions = new SquadList <SoccerPlayerViewModel>(Substitutions);

                    Reserves.RemoveFirstNames();
                    Reserves.ArrangePositionRoleAsec();
                    Reserves = new SquadList <SoccerPlayerViewModel>(Reserves);

                    // reset subs VM
                    _firstSubstitute.SetIsSelectedBinding(false);
                    _secondSubstitute.SetIsSelectedBinding(false);
                    _firstSubstitute  = null;
                    _secondSubstitute = null;

                    // Also:
                    // recreate TeamDetails & PlayerDetails
                    break;
                }
            }
            #endregion

            #region EditFormation
            if (args is EditFormationArgs)
            {
                var editArgs = (EditFormationArgs)args;
                Substitutions.ForEach(p => p.IsEnabled = !editArgs.IsEditMode);
                Reserves.ForEach(p => p.IsEnabled      = !editArgs.IsEditMode);

                switch (editArgs.Type)
                {
                //case ChangeType.EditFormationModeEnabled:
                //    break;

                case ChangeType.EditFormationModeDisabled:
                    break;
                }
            }
            #endregion
        }