public override void Full(StackPanel spRanking)
        {
            spRanking.Children.Clear();

            //If focusing on a team, only show five teams around the current team
            if (_focusOnTeam)
            {
                List <Club> ranking = null;
                for (int group = 0; group < _round.groupsCount; group++)
                {
                    if (_round.groups[group].Contains(_team))
                    {
                        ranking = _round.Ranking(group);
                    }
                }
                //Never know if not null
                if (ranking != null)
                {
                    int beginningIndex = ranking.IndexOf(_team) - 2;
                    if (beginningIndex < 0)
                    {
                        beginningIndex = 0;
                    }
                    else if (beginningIndex > ranking.Count - 5)
                    {
                        beginningIndex = ranking.Count - 5;
                    }
                    for (int i = beginningIndex; i < beginningIndex + 5; i++)
                    {
                        spRanking.Children.Add(CreateRanking(i, ranking[i]));
                    }
                }
            }
            else
            {
                for (int poule = 0; poule < _round.groupsCount; poule++)
                {
                    Label labelPoule = new Label();
                    labelPoule.Content   = _round.GroupName(poule);
                    labelPoule.Style     = Application.Current.FindResource("StyleLabel1") as Style;
                    labelPoule.FontSize *= _sizeMultiplier;
                    spRanking.Children.Add(labelPoule);
                    int i = 0;
                    foreach (Club c in _round.Ranking(poule))
                    {
                        i++;
                        spRanking.Children.Add(CreateRanking(i, c));
                    }


                    int roundLevel = _round.Tournament.level;
                    foreach (Qualification q in _round.qualifications)
                    {
                        string color = "backgroundColor";
                        if (q.tournament.level == roundLevel && q.tournament != _round.Tournament)
                        {
                            color = "cl1Color";
                        }
                        if (q.tournament.level == roundLevel && q.tournament != _round.Tournament && q.qualifies > 0)
                        {
                            color = "cl2Color";
                        }
                        else if (q.tournament.level == roundLevel && q.tournament == _round.Tournament)
                        {
                            color = "cl2Color";
                        }
                        else if (q.tournament.level > roundLevel)
                        {
                            color = "el1Color";
                        }
                        int index = q.ranking;
                        if (color != "backgroundColor")
                        {
                            SolidColorBrush lineColor = Application.Current.TryFindResource(color) as SolidColorBrush;
                            if (_round.matches.Count > 0)
                            {
                                (spRanking.Children[spRanking.Children.Count - _round.Ranking(poule).Count + index - 1] as StackPanel).Background = lineColor;
                            }
                        }
                    }
                }

                foreach (Qualification q in _round.qualifications)
                {
                    if (q.qualifies > 0 && _round.matches.Count > 0)
                    {
                        spRanking.Children.Add(ViewUtils.CreateLabel("Classement des " + q.ranking + "èmes", "StyleLabel2Center", (int)(14 * _sizeMultiplier), -1));
                        List <Club> concernedClubs = new List <Club>();
                        for (int i = 0; i < _round.groupsCount; i++)
                        {
                            concernedClubs.Add(_round.Ranking(i)[q.ranking - 1]);
                        }
                        concernedClubs.Sort(new ClubRankingComparator(_round.matches));
                        int j = 0;
                        foreach (Club c in concernedClubs)
                        {
                            j++;
                            StackPanel spLine = CreateRanking(j, c);
                            if (j <= q.qualifies)
                            {
                                spLine.Background = Application.Current.TryFindResource("cl2Color") as SolidColorBrush;
                            }
                            spRanking.Children.Add(spLine);
                        }
                    }
                }
            }

            //Only show qualification if teams were dispatched in groups (if not useless to show qualifications color) and if we are not focusing on a team
            if (_round.groups[0].Count > 0 && !_focusOnTeam)
            {
                //Split qualifications in several list because according to group qualifications can be differents (if reserves are not promoted for instance)
                List <Qualification>[] qualifications = new List <Qualification> [_round.groupsCount];

                List <Club>[] groups = new List <Club> [_round.groupsCount];
                for (int i = 0; i < _round.groupsCount; i++)
                {
                    groups[i] = new List <Club>(_round.Ranking(i));
                }

                for (int i = 0; i < _round.groupsCount; i++)
                {
                    qualifications[i] = _round.GetGroupQualifications(i);// new List<Qualification>(_round.qualifications);
                    qualifications[i].Sort(new QualificationComparator());

                    //If reserves can't be promoted
                    if (_round.rules.Contains(Rule.ReservesAreNotPromoted))
                    {
                        qualifications[i] = Utils.AdjustQualificationsToNotPromoteReserves(qualifications[i], groups[i], _round.Tournament);
                    }
                }

                int cumulatedChildrenCount = 0;
                for (int j = 0; j < _round.groupsCount; j++)
                {
                    foreach (Qualification q in qualifications[j])
                    {
                        if (q.tournament.isChampionship)
                        {
                            int    niveau  = _round.Tournament.level;
                            string couleur = "backgroundColor";
                            if (q.tournament.level < niveau)
                            {
                                couleur = "promotionColor";
                            }
                            else if (q.tournament.level > niveau)
                            {
                                couleur = "relegationColor";
                            }
                            else if (q.tournament.level == niveau && q.roundId > _round.Tournament.rounds.IndexOf(_round))
                            {
                                couleur = "barrageColor";
                            }

                            int index = q.ranking - 1;

                            SolidColorBrush color = Application.Current.TryFindResource(couleur) as SolidColorBrush;
                            int             nbChildrenParPoule = (_round.clubs.Count / _round.groupsCount) + 1;
                            index++;

                            StackPanel sp = (spRanking.Children[cumulatedChildrenCount /*j * nbChildrenParPoule*/ + index] as StackPanel);
                            sp.Background = color;
                        }
                    }
                    cumulatedChildrenCount += _round.groups[j].Count + 1;
                }
            }
        }
Esempio n. 2
0
        public Windows_Club(CityClub c)
        {
            InitializeComponent();

            imgBudget.Source        = new BitmapImage(new Uri(System.IO.Directory.GetCurrentDirectory() + "\\" + Utils.imagesFolderName + "\\budget.png"));
            imgCurrentBudget.Source = new BitmapImage(new Uri(System.IO.Directory.GetCurrentDirectory() + "\\" + Utils.imagesFolderName + "\\budget.png"));
            imgBtnQuitter.Source    = new BitmapImage(new Uri(System.IO.Directory.GetCurrentDirectory() + "\\" + Utils.imagesFolderName + "\\return.png"));
            imgManager.Source       = new BitmapImage(new Uri(System.IO.Directory.GetCurrentDirectory() + "\\" + Utils.imagesFolderName + "\\manager.png"));

            _club          = c;
            lbClub.Content = c.name;

            if (c.manager != null)
            {
                lbEntraineur.Content = c.manager.ToString();
            }
            else
            {
                lbEntraineur.Content = FindResource("str_noManager").ToString();
            }

            lbBudget.Content        = Utils.FormatMoney(c.budget);
            lbCurrentBudget.Content = Utils.FormatMoney(c.budget);

            try
            {
                imgLogo.Source = new BitmapImage(new Uri(Utils.Logo(c)));
            }
            catch (Exception e)
            {
                Utils.Debug(e.ToString());
            }
            Palmares(c);
            FillGames();
            FillBudget();



            List <Player> newContracts = new List <Player>();

            foreach (Contract ct in c.allContracts)
            {
                if ((ct.beginning.Year == Session.Instance.Game.date.Year - 1 && ct.beginning.Month < 7) ||
                    (ct.beginning.Year == Session.Instance.Game.date.Year && ct.beginning.Month >= 7))
                {
                    newContracts.Add(ct.player);
                }
            }

            /*TODO
             * ViewPlayers viewNewPlayers = new ViewPlayers(newContracts, 11, false, false, false, true, false, false, false, false, false, true, false, false, false, false, false, false, false);
             * viewNewPlayers.Full(spArrivees);
             */
            ViewPlayers viewPlayers = new ViewPlayers(c.Players(), 12, true, true, true, true, true, false, false, true, false, true, false, false, false, false, false, true, true, true);

            viewPlayers.Full(spPlayers);

            List <HistoriqueClubElement> lhce = new List <HistoriqueClubElement>();

            foreach (Tournament competition in Session.Instance.Game.kernel.Competitions)
            {
                foreach (KeyValuePair <int, Tournament> ancienne in competition.previousEditions)
                {
                    if (ancienne.Value.isChampionship && ancienne.Value.rounds[0].clubs.Contains(c))
                    {
                        int classement = 0;
                        //Si la compétition était active (tour 0 un tour de type championnat, pas inactif)
                        if ((ancienne.Value.rounds[0] as ChampionshipRound) != null)
                        {
                            classement = (ancienne.Value.rounds[0] as ChampionshipRound).Ranking().IndexOf(c) + 1;
                        }
                        else if ((ancienne.Value.rounds[0] as GroupsRound) != null)
                        {
                            GroupsRound rnd = (ancienne.Value.rounds[0] as GroupsRound);
                            for (int j = 0; j < rnd.groupsCount; j++)
                            {
                                if (rnd.groups[j].Contains(c))
                                {
                                    classement = rnd.Ranking(j).IndexOf(c);
                                }
                            }
                        }
                        lhce.Add(new HistoriqueClubElement {
                            Competition = ancienne.Value, Classement = classement, Annee = ancienne.Key
                        });
                    }
                }
            }
            lhce.Sort(new HistoriqueClubComparator());
            foreach (HistoriqueClubElement hce in lhce)
            {
                StackPanel spHistoryEntry = new StackPanel();
                spHistoryEntry.Orientation = Orientation.Horizontal;
                spHistoryEntry.Children.Add(ViewUtils.CreateLabelOpenWindow <Tournament>(hce.Competition, OpenTournament, hce.Annee.ToString(), "StyleLabel2", 11, 75));
                spHistoryEntry.Children.Add(ViewUtils.CreateLabelOpenWindow <Tournament>(hce.Competition, OpenTournament, hce.Competition.name, "StyleLabel2", 11, 125));
                spHistoryEntry.Children.Add(ViewUtils.CreateLabel(hce.Classement.ToString(), "StyleLabel2", 11, 50));
                spHistory.Children.Add(spHistoryEntry);
            }


            ChartValues <int> budgets         = new ChartValues <int>();
            ChartValues <int> centreFormation = new ChartValues <int>();
            ChartValues <int> attendance      = new ChartValues <int>();

            foreach (HistoricEntry eh in c.history.elements)
            {
                budgets.Add(eh.budget);
                centreFormation.Add(eh.formationFacilities);
                attendance.Add(eh.averageAttendance);
            }

            BudgetsCollection = new SeriesCollection
            {
                new LineSeries
                {
                    Title  = FindResource("str_budget").ToString(),
                    Values = budgets,
                }
            };

            //Formation facilities

            CFCollection = new SeriesCollection
            {
                new LineSeries
                {
                    Title  = FindResource("str_level").ToString(),
                    Values = centreFormation,
                }
            };

            //Average attendance

            AttendanceCollection = new SeriesCollection
            {
                new LineSeries
                {
                    Title  = FindResource("str_averageAttendance").ToString(),
                    Values = attendance,
                }
            };

            LabelsAnnees = new string[c.history.elements.Count];
            int i = 0;

            foreach (HistoricEntry eh in c.history.elements)
            {
                LabelsAnnees[i] = c.history.elements[i].date.Year.ToString();
                i++;
            }
            YFormatter = value => value.ToString("C");

            DataContext = this;

            if (c.records.BiggestWin != null)
            {
                lbBiggestWin.Content = c.records.BiggestWin.home.name + " " + c.records.BiggestWin.score1 + " - " + c.records.BiggestWin.score2 + " " + c.records.BiggestWin.away.name;
            }
            if (c.records.BiggestLose != null)
            {
                lbBiggestLose.Content = c.records.BiggestLose.home.name + " " + c.records.BiggestLose.score1 + " - " + c.records.BiggestLose.score2 + " " + c.records.BiggestLose.away.name;
            }
        }