Ejemplo n.º 1
0
        public SoccerPlayer(SoccerPlayerViewModel viewModel = null)
        {
            if (viewModel == null)
            {
                return;
            }

            Id     = viewModel.Id;
            TeamId = viewModel.TeamId;
            Name   = (string)viewModel.Name.Value;

            DateTime birthDate = new DateTime();

            if (viewModel.BirthDate.Value is DateTime)
            {
                birthDate = (DateTime)viewModel.BirthDate.Value;
            }
            else
            {
                birthDate = DateTime.Parse((string)viewModel.BirthDate.Value);
            }
            BirthDate = birthDate;

            Position = CreatePosition((PositionRole)viewModel.Position.Value);

            IsCaptain = (bool)viewModel.IsCaptain.Value;
            Rating    = viewModel.Rating.Value is string?int.Parse((string)viewModel.Rating.Value) : (int)viewModel.Rating.Value;

            Rotation    = (RotationTeam)viewModel.RotationTeam.Value;
            Nationality = (viewModel.Nationality.Value as ComboBoxItemViewModel).Id;
        }
        private void DragOrDropFieldPlayer(SoccerPlayerViewModel draggedPlayer)
        {
            if (_draggedPlayer == null)
            {
                _draggedPlayer = draggedPlayer;
            }
            else
            {
                var formation = _teamModel.Formations.Find(f => f.Id == SelectedFormation.Id);
                UpdateFormationModel(formation, _draggedPlayer.Id, true);
                SquadRepository.UpdateFormation(formation);

                _draggedPlayer = null;
            }
        }
Ejemplo n.º 3
0
        private void DragOrDropFieldPlayer(SoccerPlayerViewModel draggedPlayer)
        {
            //if (_draggedPlayer == null)
            //{
            //    _draggedPlayer = draggedPlayer;
            //}
            //else
            //{
            //    var formation = _teamModel.Formations.Find(f => f.Id == SelectedFormation.Id);
            //    UpdateFormationModel(formation, _draggedPlayer.Id, true);
            //    SquadRepository.UpdateFormation(formation);

            //    _draggedPlayer = null;
            //}
        }
        public void Changed(ChangeArgs args)
        {
            if (args is SubstitutionArgs)
            {
                var subArgs   = (SubstitutionArgs)args;
                var firstSub  = subArgs.FirstSub;
                var secondSub = subArgs.SecondSub;
                if (args.Type == ChangeType.SubSelected)
                {
                    if (_firstSubstitute == null)
                    {
                        _firstSubstitute = SelectedFormation.Lineup.FirstOrDefault(p => p.Id == firstSub.Id) ?? Team.Squad.Find(p => p.Id == firstSub.Id);
                    }
                    else if (firstSub.Id == _firstSubstitute.Id && secondSub == null)
                    {
                        return;
                    }

                    if (secondSub != null)
                    {
                        if (_secondSubstitute == null)
                        {
                            _secondSubstitute = SelectedFormation.Lineup.FirstOrDefault(p => p.Id == secondSub.Id) ?? Team.Squad.Find(p => p.Id == secondSub.Id);
                        }
                        else if (secondSub.Id == _secondSubstitute.Id)
                        {
                            return;
                        }
                    }
                }
                else if (args.Type == ChangeType.SubDeselect)
                {
                    if (firstSub != null)
                    {
                        _firstSubstitute = null;
                    }
                    else if (secondSub != null)
                    {
                        _secondSubstitute = null;
                    }
                }
            }
        }
        private void AddNewPlayerToSquad()
        {
            var player = new SoccerPlayerViewModel(NewPlayer, Collections, _changesManager);

            Players.Remove(NewPlayer);
            Players.Add(player);

            ResetNewPlayerValues();
            Players.Add(NewPlayer);

            Team.Squad.Add(player);
            var playerModel = new SoccerPlayer(player);

            _teamModel.Squad.Add(playerModel);


            playerModel.Id = player.Id = SquadRepository.AddPlayer(_teamModel.Id, _teamModel.Squad.Last());

            _changesManager.Change(new SoccerPlayerArgs(playerModel, ChangeType.PlayerAdded));
        }
        private void SetPlayers()
        {
            Team = new TeamViewModel(_teamModel, _changesManager, Collections);

            Players = new ObservableCollection <SoccerPlayerViewModel>();
            Team.Squad.ForEach(p => Players.Add(p));

            NewPlayer = new SoccerPlayerViewModel()
            {
                Name         = new EditableCellViewModel(null, _changesManager),
                BirthDate    = new EditableCellViewModel(new DateTime(1950, 1, 1).ToShortDateString(), _changesManager),
                Age          = new CellViewModel(null),
                Position     = new ComboBoxCellViewModel(null, Collections.PositionRoles, _changesManager),
                Nationality  = new ComboBoxCellViewModel(null, Collections.NationViewModels, _changesManager),
                Rating       = new EditableCellViewModel(null, _changesManager),
                RotationTeam = new CellViewModel(RotationTeam.Reserves),
                IsCaptain    = new EditableCellViewModel(false, _changesManager),
                IsNewPlayer  = new CellViewModel(true),
            };
            Players.Add(NewPlayer);
        }
        private void SubstitutePlayers()
        {
            var firstSubX  = _firstSubstitute.X;
            var firstSubY  = _firstSubstitute.Y;
            var secondSubX = _secondSubstitute.X;
            var secondSubY = _secondSubstitute.Y;

            SubFrom?isInsideLineupSection = null;

            // VIEW MODEL
            // sub inside 'field details'
            if (SelectedFormation.Lineup.Contains(_firstSubstitute) && SelectedFormation.Lineup.Contains(_secondSubstitute))
            {
                _firstSubstitute.X  = _secondSubstitute.X;
                _firstSubstitute.Y  = _secondSubstitute.Y;
                _secondSubstitute.X = firstSubX;
                _secondSubstitute.Y = firstSubY;
            }
            // sub first sub from 'field details' to second sub in 'lineup details'
            else if (SelectedFormation.Lineup.Contains(_firstSubstitute) && !SelectedFormation.Lineup.Contains(_secondSubstitute))
            {
                SubstituteBetweenChangeables(SubFrom.FieldDetailsSection, firstSubX, firstSubY);
                SelectedFormation.Lineup.RemoveFirstNames();
            }
            // sub first sub from 'lineup details' to second sub in 'field details'
            else if (!SelectedFormation.Lineup.Contains(_firstSubstitute) && SelectedFormation.Lineup.Contains(_secondSubstitute))
            {
                SubstituteBetweenChangeables(SubFrom.LineupDetailsSection, secondSubX, secondSubY);
                SelectedFormation.Lineup.RemoveFirstNames();
            }
            // sub inside 'lineup details'
            else if (!SelectedFormation.Lineup.Contains(_firstSubstitute) && !SelectedFormation.Lineup.Contains(_secondSubstitute))
            {
                isInsideLineupSection = SubFrom.InsideLineupDetailsSection;
            }

            // MODEL
            SoccerPlayer firstSubModel     = _teamModel.Squad.FirstOrDefault(p => p.Id == _firstSubstitute.Id);
            SoccerPlayer secondSubModel    = _teamModel.Squad.FirstOrDefault(p => p.Id == _secondSubstitute.Id);
            var          originalFirstSub  = firstSubModel.RefferenceCopy();
            var          originalSecondSub = secondSubModel.RefferenceCopy();

            if (isInsideLineupSection.HasValue && isInsideLineupSection.Value == SubFrom.InsideLineupDetailsSection)
            {
                firstSubModel.Rotation  = (RotationTeam)_secondSubstitute.RotationTeam.Value;
                secondSubModel.Rotation = (RotationTeam)_firstSubstitute.RotationTeam.Value;
            }
            else
            {
                firstSubModel.Rotation  = (RotationTeam)_firstSubstitute.RotationTeam.Value;
                secondSubModel.Rotation = (RotationTeam)_secondSubstitute.RotationTeam.Value;
            }

            var formation         = _teamModel.Formations.Find(f => f.Id == SelectedFormation.Id);
            var originalFormation = formation.RefferenceCopy();

            if (originalFormation.LineupIds.Contains(_firstSubstitute.Id))
            {
                UpdateFormationModel(formation, _firstSubstitute.Id);
            }
            if (originalFormation.LineupIds.Contains(_secondSubstitute.Id))
            {
                UpdateFormationModel(formation, _secondSubstitute.Id);
            }

            // DB
            SquadRepository.UpdatePlayer(firstSubModel);
            SquadRepository.UpdatePlayer(secondSubModel);
            if (!isInsideLineupSection.HasValue)
            {
                SquadRepository.UpdateFormation(formation);
            }

            // CHANGE
            if (firstSubModel == null || secondSubModel == null)
            {
                throw new InvalidOperationException("Models were not found from the view model id's");
            }
            var subArgs = new SubstitutionArgs(ChangeType.SubConfirmed, originalFirstSub, originalSecondSub)
            {
                firstSubX  = _firstSubstitute.X,
                firstSubY  = _firstSubstitute.Y,
                secondSubX = _secondSubstitute.X,
                secondSubY = _secondSubstitute.Y,
            };

            _changeManager.Change(subArgs);

            // RESET SUB VM => should be in VIEW MODEL update??
            _firstSubstitute.SetIsSelectedBinding(false);
            _secondSubstitute.SetIsSelectedBinding(false);
            _firstSubstitute  = null;
            _secondSubstitute = null;
        }
Ejemplo n.º 8
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
        }
Ejemplo n.º 9
0
        private void SoccerPlayerViewModel_IsSelectedPropertyChanged(object sender, IsSelectedEventArgs args)
        {
            var player = (SoccerPlayerViewModel)sender;

            if (args.IsSelected)
            {
                if (_firstSubstitute == null)
                {
                    _firstSubstitute = player;
                    var subArgs = new SubstitutionArgs(ChangeType.SubSelected, _teamModel.Squad.Find(p => p.Id == _firstSubstitute.Id).RefferenceCopy())
                    {
                        firstSubX  = _firstSubstitute.X,
                        firstSubY  = _firstSubstitute.Y,
                        secondSubX = 0,
                        secondSubY = 0,
                    };
                    _changeManager.Change(subArgs);
                }
                else if (_firstSubstitute != null && _secondSubstitute == null)
                {
                    _secondSubstitute = player;
                    var subArgs = new SubstitutionArgs(ChangeType.SubSelected, _teamModel.Squad.Find(p => p.Id == _firstSubstitute.Id).RefferenceCopy(), _teamModel.Squad.Find(p => p.Id == _secondSubstitute.Id).RefferenceCopy())
                    {
                        firstSubX  = _firstSubstitute.X,
                        firstSubY  = _firstSubstitute.Y,
                        secondSubX = _secondSubstitute.X,
                        secondSubY = _secondSubstitute.Y,
                    };
                    _changeManager.Change(subArgs);
                }
                else if (_firstSubstitute != null && _secondSubstitute != null)
                {
                    player.SetIsSelectedBinding(false);
                }
            }
            else
            {
                if (_firstSubstitute != null && _firstSubstitute.Id == player.Id)
                {
                    _firstSubstitute = null;
                    var subArgs = new SubstitutionArgs(ChangeType.SubDeselect, null, _secondSubstitute != null ? _teamModel.Squad.Find(p => p.Id == _secondSubstitute.Id).RefferenceCopy() : null)
                    {
                        firstSubX  = 0,
                        firstSubY  = 0,
                        secondSubX = _secondSubstitute != null ? _secondSubstitute.X : 0,
                        secondSubY = _secondSubstitute != null ? _secondSubstitute.Y : 0,
                    };
                    _changeManager.Change(subArgs);
                }
                else if (_secondSubstitute != null && _secondSubstitute.Id == player.Id)
                {
                    _secondSubstitute = null;
                    var subArgs = new SubstitutionArgs(ChangeType.SubDeselect, _firstSubstitute != null ? _teamModel.Squad.Find(p => p.Id == _firstSubstitute.Id).RefferenceCopy() : null, null)
                    {
                        firstSubX  = _firstSubstitute != null ? _firstSubstitute.X : 0,
                        firstSubY  = _firstSubstitute != null ? _firstSubstitute.Y : 0,
                        secondSubX = 0,
                        secondSubY = 0,
                    };
                    _changeManager.Change(subArgs);
                }
            }
        }
 private void ExecuteRemovePlayerConfirmation(SoccerPlayerViewModel player)
 {
     PlayerToRemove             = player;
     PanelEnabled               = false;
     ConfirmationOverlayVisible = true;
 }