public void SetChamps(ChampionStatInfoList champs) { if (champs == null || champs.Count < 1) { return; } if (InvokeRequired) { Invoke(new Action <ChampionStatInfoList>(SetChamps), champs); return; } RemoveAll(p => (p.Tag as string) == "Champs"); var layout = new TableLayoutPanel(); layout.Dock = DockStyle.Fill; foreach (var champ in champs) { if (champ.ChampionId == 0) { continue; } var lbl = new Label { Font = new Font("Bitstream Vera Sans Mono", 8.25F, FontStyle.Bold), AutoSize = true, Text = string.Format("{0} ({1})", ChampNames.Get(champ.ChampionId), champ.TotalGamesPlayed) }; layout.Controls.Add(lbl); } var tab = new TabPage("Champs") { BackColor = this.BackColor, Tag = "Champs" }; tab.Controls.Add(layout); AddTab(tab); }
public void SetRankedStats(PublicSummoner summoner, AggregatedStats stats) { if (summoner == null || stats == null) { return; } if (InvokeRequired) { Invoke(new Action <PublicSummoner, AggregatedStats>(SetRankedStats), summoner, stats); return; } PlayerStats = stats; int kills = 0; int assists = 0; int deaths = 0; Dictionary <int, int> favChamps = new Dictionary <int, int>(); foreach (var stat in stats.LifetimeStatistics) { if (stat.ChampionID == 0) { if (stat.StatType.Contains("TOTAL_CHAMPION_KILLS")) { kills = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_ASSISTS")) { assists = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_DEATHS_PER_SESSION")) { deaths = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_SESSIONS_PLAYED")) { totalGames.Text = Convert.ToInt32(stat.Value).ToString(); } if (stat.StatType.Contains("TOTAL_SESSIONS_WON")) { totalPercentWon.Text = Convert.ToInt32(stat.Value).ToString(); } } else { if (stat.StatType.Contains("TOTAL_SESSIONS_PLAYED")) { if (favChamps.Count() <= 5) { favChamps.Add(stat.ChampionID, Convert.ToInt32(stat.Value)); } else { var min = favChamps.OrderBy(kvp => kvp.Value).First(); var minKey = min.Key; var minValue = min.Value; if (Convert.ToInt32(stat.Value) > minValue) { favChamps.Remove(minKey); favChamps.Add(stat.ChampionID, Convert.ToInt32(stat.Value)); } } } } } totalPercentWon.Text = ((100.0f * (Convert.ToInt32(totalPercentWon.Text)) / Convert.ToDouble(totalGames.Text)) + 0.0001).ToString().Substring(0, 4) + "%"; if (Convert.ToDouble(totalPercentWon.Text.Substring(0, 4)) > 50.0f) { totalPercentWon.ForeColor = Color.DarkGreen; } else { totalPercentWon.ForeColor = Color.DarkRed; } float totalKdaCalc = (kills + assists) / (float)deaths; totalKda.Text = totalKdaCalc.ToString().Substring(0, 4); if (totalKdaCalc < 2.25) { totalKda.ForeColor = Color.DarkRed; } else if (totalKdaCalc < 3) { totalKda.ForeColor = Color.DarkOrange; } else { totalKda.ForeColor = Color.DarkGreen; } for (int i = 0; i < 5; i++) { var favChamp = favChamps.OrderBy(kvp => kvp.Value).Last(); var name = ChampNames.GetOrDefault(favChamp.Key); favChampIcons[i].Image = ChampIcons.Get(favChamp.Key); favChamps.Remove(favChamp.Key); foreach (var stat in stats.LifetimeStatistics) { if (favChamp.Key == stat.ChampionID) { if (stat.StatType.Contains("TOTAL_CHAMPION_KILLS")) { kills = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_ASSISTS")) { assists = Convert.ToInt32(stat.Value); } if (stat.StatType.Contains("TOTAL_DEATHS_PER_SESSION")) { deaths = Convert.ToInt32(stat.Value); } } } float tempChampKda = (kills + assists) / (float)deaths; favChampKdas[i].SetToolTip(favChampIcons[i], tempChampKda.ToString()); } }