示例#1
0
        public void SetGames(RecentGames games)
        {
            if (games == null || games.GameStatistics.Count < 1)
            {
                return;
            }

            if (InvokeRequired)
            {
                Invoke(new Action <RecentGames>(SetGames), games);
                return;
            }

            RemoveAll(p => (p.Tag as string) == "Recent");

            var layout = new TableLayoutPanel
            {
                Dock   = DockStyle.Fill,
                Margin = Padding.Empty,
            };

            const int rows = 5;
            const int cols = 2;

            var list = games.GameStatistics.OrderByDescending(p => p.GameId).ToList();

            for (int x = 0; x < cols; x++)
            {
                for (int y = 0; y < rows; y++)
                {
                    int idx = y + (x * rows);
                    if (idx >= list.Count)
                    {
                        break;
                    }

                    var game = list[idx];
                    if (game.ChampionId == 0)
                    {
                        continue;
                    }

                    var won     = game.Statistics.GetInt(RawStat.WIN) != 0;
                    var kills   = game.Statistics.GetInt(RawStat.CHAMPION_KILLS);
                    var deaths  = game.Statistics.GetInt(RawStat.DEATHS);
                    var assists = game.Statistics.GetInt(RawStat.ASSISTS);
                    var left    = game.Leaver;
                    var botgame = game.QueueType == "BOT";

                    var wonlabel = CreateLabel(string.Format("{0}{1}", left ? "[L] " : "", won ? "Won" : "Lost"));
                    wonlabel.ForeColor = won ? Color.Green : Color.Red;

                    var kdrlbl = CreateLabel(string.Format("({0}/{1}/{2})", kills, deaths, assists));
                    kdrlbl.ForeColor = GetKdrColor(kills, deaths);

                    var champicon = new PictureBox
                    {
                        Image    = ChampIcons.Get(game.ChampionId),
                        Margin   = Padding.Empty,
                        SizeMode = PictureBoxSizeMode.StretchImage,
                        Size     = new Size(20, 20)
                    };

                    if (botgame)
                    {
                        wonlabel.ForeColor = kdrlbl.ForeColor = Color.Black;
                    }


                    var controls = new List <Control>
                    {
                        champicon,
                        wonlabel,
                        kdrlbl,
                        CreateSpellPicture(game.Spell1),
                        CreateSpellPicture(game.Spell2)
                    };
                    //Add a space between the last column in each set.
                    controls[controls.Count - 1].Margin = new Padding(0, 0, 5, 0);

                    for (int i = 0; i < controls.Count; i++)
                    {
                        layout.AddControl(controls[i], i + x * controls.Count, y);
                    }
                }
            }

            var tab = new TabPage("Recent")
            {
                BackColor = this.BackColor,
                Tag       = "Recent"
            };

            tab.Controls.Add(layout);
            AddTab(tab);
        }