/// <summary> /// Clears and repopulats the list of replays /// </summary> private void Refresh() { //clear the list replays.Clear(); foreach (Transform t in replayList.transform) { Destroy(t.gameObject); } //find the replays in the save directory System.IO.Directory.CreateDirectory(Level.SAVE_PATH); List <FileInfo> files = new DirectoryInfo(Level.SAVE_PATH).GetFiles().OrderByDescending(f => f.LastWriteTime).ToList(); //create a ReplayItem for each replay and add it to the replay list foreach (FileInfo item in files) { GameObject replay = ReplayItem.GetFromFile(item); if (replay != null) { replay.GetComponent <Toggle>().group = group; replay.GetComponent <Toggle>().isOn = false; replays.Add(replay.GetComponent <ReplayItem>()); } } SortByDate(); }
private void InitReplayItemInfo() { // 初始化 _infoList = new List <ReplayInfo>(); ReplayInfo info; for (int i = 0; i < MaxInfoCount; i++) { info = new ReplayInfo { replayIndex = -1, }; _infoList.Add(info); } // 读取replay的信息 List <ReplayInfo> infos = ReplayManager.GetInstance().GetReplayInfoList(); _infoCount = infos.Count; for (int i = 0; i < _infoCount; i++) { info = infos[i]; _infoList[info.replayIndex] = info; } // 更新ReplayItem的显示 for (int i = 0; i < MaxInfoCount; i++) { ReplayItem item = _itemList[i]; item.SetInfo(_infoList[i]); } }
/// <summary> /// Static method that creates a ReplayItem from a file containing a replay. /// Returns the ReplayItem if it was created succesfully, null if not. /// </summary> /// <param name="file">File containing the replay.</param> /// <returns>The created ReplayItem or null.</returns> public static GameObject GetFromFile(FileInfo file) { StreamReader reader = null; try { string extention = file.Extension; string tempSaveName, tempDate, tempLevel, tempPlayers, tempDifficulty, tempPvp; //make sure the file is the correct type if (extention.Equals(Level.REPLAY_EXTENTION)) { tempSaveName = Path.GetFileNameWithoutExtension(file.Name); } else { return(null); } tempDate = file.LastWriteTime.ToString(); reader = new System.IO.StreamReader(file.FullName); //read in the Levels settings tempLevel = reader.ReadLine(); tempPlayers = reader.ReadLine(); tempDifficulty = reader.ReadLine(); tempPvp = reader.ReadLine(); //create the ReplayItem GameObject obj = Instantiate(Resources.Load("ReplayItemPF"), Vector3.zero, Quaternion.Euler(0, 0, 0)) as GameObject; ReplayItem save = obj.GetComponent <ReplayItem>(); //set the values in the ReplayItem with the read in Level settings, //filename and file modified time save.date.text = tempDate; save.saveName.text = tempSaveName; save.level.text = tempLevel; save.players.text = tempPlayers; save.difficulty.text = tempDifficulty; save.pvp.text = tempPvp; save.replayFile = file; return(obj); } catch { return(null); } finally { if (reader != null) { reader.Close(); } } }
void item_MouseDown(object sender, MouseButtonEventArgs e) { ReplayItem item = (ReplayItem)sender; EndOfGameStats stats = (EndOfGameStats)item.Tag; selectedStats = stats; ReplayOverviewGrid.Visibility = Visibility.Visible; var fadeGridInAnimation = new DoubleAnimation(1, TimeSpan.FromSeconds(0.1)); ReplayOverviewGrid.BeginAnimation(Grid.OpacityProperty, fadeGridInAnimation); GameId.Content = stats.Difficulty; GameType.Content = stats.GameMode.ToLower(); double seconds = stats.GameLength % 60; double minutes = stats.GameLength / 60; GameTime.Content = string.Format("{0:0}:{1:00}", minutes, seconds); TeamOnePanel.Children.Clear(); TeamTwoPanel.Children.Clear(); foreach (PlayerParticipantStatsSummary summary in stats.TeamPlayerParticipantStats) { PlayerItemReplay player = new PlayerItemReplay(); player.PlayerNameLabel.Content = summary.SummonerName; Uri UriSource = new Uri("/LegendaryReplays;component/champion/" + summary.SkinName + ".png", UriKind.RelativeOrAbsolute); player.ChampionIcon.ChampionImage.Source = new BitmapImage(UriSource); TeamOnePanel.Children.Add(player); } foreach (PlayerParticipantStatsSummary summary in stats.OtherTeamPlayerParticipantStats) { PlayerItemReplay player = new PlayerItemReplay(); player.PlayerNameLabel.Content = summary.SummonerName; Uri UriSource = new Uri("/LegendaryReplays;component/champion/" + summary.SkinName + ".png", UriKind.RelativeOrAbsolute); player.ChampionIcon.ChampionImage.Source = new BitmapImage(UriSource); TeamTwoPanel.Children.Add(player); } }
public override void Init(GameObject viewObj) { base.Init(viewObj); // 背景 _bgTf = _viewTf.Find("Bg").GetComponent <RectTransform>(); RectTransform containerTf = _viewTf.Find("Container").GetComponent <RectTransform>(); _selectedImgTf = containerTf.Find("SelectedImg").GetComponent <RectTransform>(); // 创建ReplayItem ReplayItem repItem; GameObject itemGo; _itemList = new List <ReplayItem>(); for (int i = 0; i < MaxInfoCount; i++) { repItem = new ReplayItem(); itemGo = ResourceManager.GetInstance().GetCommonPrefab("Prefab/Views", "ReplayItem"); itemGo.transform.SetParent(containerTf, false); repItem.Init(itemGo); _itemList.Add(repItem); } }
private void UpdateReplays() { GamePanel.Children.Clear(); var dir = new DirectoryInfo(Path.Combine(Client.ExecutingDirectory, "cabinet")); IOrderedEnumerable <DirectoryInfo> directories = dir.EnumerateDirectories() .OrderBy(d => d.CreationTime); string[] Replays = Directory.GetDirectories(Path.Combine(Client.ExecutingDirectory, "cabinet")); foreach (DirectoryInfo di in directories) { string d = di.Name; if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "cabinet", d, "token")) || !File.Exists(Path.Combine(Client.ExecutingDirectory, "cabinet", d, "key")) || !File.Exists(Path.Combine(Client.ExecutingDirectory, "cabinet", d, "endOfGameStats"))) { continue; } byte[] base64Stats = Convert.FromBase64String( File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "cabinet", d, "endOfGameStats"))); var statsReader = new AmfReader(new MemoryStream(base64Stats), context); var stats = (EndOfGameStats)statsReader.ReadAmf3Item(); var item = new ReplayItem(); //Use unoccupied variable stats.Difficulty = d; item.Tag = stats; item.GameId.Text = File.Exists(Path.Combine(Client.ExecutingDirectory, "cabinet", d, "name")) ? File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "cabinet", d, "name")) : d; item.GameId.Tag = d; item.GameType.Content = stats.GameMode.ToLower(); item.GameDate.Content = di.CreationTime.ToShortTimeString() + " " + di.CreationTime.ToShortDateString(); double seconds = stats.GameLength % 60; double minutes = stats.GameLength / 60; item.GameTime.Content = string.Format("{0:0}:{1:00}", minutes, seconds); item.Margin = new Thickness(0, 5, 0, 0); foreach ( SmallChampionItem image in stats.TeamPlayerParticipantStats.Select(summary => new SmallChampionItem { Width = 38, Height = 38, ChampionImage = { Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "champion", summary.SkinName + ".png")) } })) { item.TeamOnePanel.Children.Add(image); } foreach ( SmallChampionItem image in stats.OtherTeamPlayerParticipantStats.Select(summary => new SmallChampionItem { Width = 38, Height = 38, ChampionImage = { Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "champion", summary.SkinName + ".png")) } })) { item.TeamTwoPanel.Children.Add(image); } item.MouseDown += item_MouseDown; item.GameId.MouseDoubleClick += GameId_MouseDoubleClick; item.GameId.MouseLeave += GameId_MouseLeave; item.KeyDown += item_KeyDown; //Insert on top GamePanel.Children.Insert(0, item); } }
void item_MouseDown(object sender, MouseButtonEventArgs e) { ReplayItem item = (ReplayItem)sender; EndOfGameStats stats = (EndOfGameStats)item.Tag; selectedStats = stats; ReplayOverviewGrid.Visibility = Visibility.Visible; var fadeGridInAnimation = new DoubleAnimation(1, TimeSpan.FromSeconds(0.1)); ReplayOverviewGrid.BeginAnimation(Grid.OpacityProperty, fadeGridInAnimation); GameId.Content = stats.Difficulty; GameType.Content = stats.GameMode.ToLower(); double seconds = stats.GameLength % 60; double minutes = stats.GameLength / 60; GameTime.Content = string.Format("{0:0}:{1:00}", minutes, seconds); TeamOnePanel.Children.Clear(); TeamTwoPanel.Children.Clear(); foreach (PlayerParticipantStatsSummary summary in stats.TeamPlayerParticipantStats) { double k = -1, d = -1, a = -1; PlayerItemReplay player = new PlayerItemReplay(); player.PlayerNameLabel.Content = summary.SummonerName; foreach (RawStatDTO stat in summary.Statistics) { if (stat.StatTypeName.StartsWith("ITEM") && stat.Value != 0) { switch (stat.StatTypeName) { case "ITEM1": player.gameItem1.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; case "ITEM2": player.gameItem2.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; case "ITEM3": player.gameItem3.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; case "ITEM4": player.gameItem4.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; case "ITEM5": player.gameItem5.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; case "ITEM6": player.gameTrinket.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; default: break; } } switch (stat.StatTypeName) { case "CHAMPIONS_KILLED": k = stat.Value; break; case "NUM_DEATHS": d = stat.Value; break; case "ASSISTS": a = stat.Value; break; default: break; } } foreach (object element in player.getChildElements()) { if (element is SmallChampionItem && ((SmallChampionItem)element).Name.StartsWith("game")) { ((SmallChampionItem)element).MouseMove += img_MouseMove; ((SmallChampionItem)element).MouseLeave += img_MouseLeave; } } player.ChampionIcon.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "champion", summary.SkinName + ".png")); player.File.Content = summary.SkinName; player.KDA.Content = k + "/" + d + "/" + a; TeamOnePanel.Children.Add(player); } foreach (PlayerParticipantStatsSummary summary in stats.OtherTeamPlayerParticipantStats) { double k = -1, d = -1, a = -1; PlayerItemReplay player = new PlayerItemReplay(); player.PlayerNameLabel.Content = summary.SummonerName; foreach (RawStatDTO stat in summary.Statistics) { if (stat.StatTypeName.StartsWith("ITEM") && stat.Value != 0) { switch (stat.StatTypeName) { case "ITEM1": player.gameItem1.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; case "ITEM2": player.gameItem2.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; case "ITEM3": player.gameItem3.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; case "ITEM4": player.gameItem4.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; case "ITEM5": player.gameItem5.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; case "ITEM6": player.gameTrinket.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "item", stat.Value + ".png")); break; default: break; } } switch (stat.StatTypeName) { case "CHAMPIONS_KILLED": k = stat.Value; break; case "NUM_DEATHS": d = stat.Value; break; case "ASSISTS": a = stat.Value; break; default: break; } } foreach (object element in player.getChildElements()) { if (element is SmallChampionItem && ((SmallChampionItem)element).Name.StartsWith("game")) { ((SmallChampionItem)element).MouseMove += img_MouseMove; ((SmallChampionItem)element).MouseLeave += img_MouseLeave; } } player.File.Content = summary.SkinName; player.ChampionIcon.ChampionImage.Source = Client.GetImage(Path.Combine(Client.ExecutingDirectory, "Assets", "champion", summary.SkinName + ".png")); player.KDA.Content = k + "/" + d + "/" + a; TeamTwoPanel.Children.Add(player); } }
private void LoadMatches() { FileInfo summaryFile = new FileInfo(App.SummaryPath); var dir = new DirectoryInfo(App.Rootpath); if (!dir.Exists) dir.Create(); Logger.WriteLine("Loading replays from {0}", App.Rootpath); FileStream loadSummary; if (!summaryFile.Exists) loadSummary = summaryFile.Create(); else loadSummary = summaryFile.Open(FileMode.Open); var mems = new MemoryStream(); loadSummary.CopyTo(mems); loadSummary.Close(); dynamic summary; try { summary = MFroehlich.Parsing.MFro.MFroFormat.Deserialize(mems.ToArray()); Logger.WriteLine("Loaded {0} summaries from {1}", summary.Count, summaryFile.FullName); } catch (Exception x) { summary = new JSONObject(); Logger.WriteLine(Priority.Error, "Error loading summaries {0}, starting new summary list", x.Message); } dynamic newSummary = new JSONObject(); List<FileInfo> files = new DirectoryInfo(App.Rootpath).EnumerateFiles("*.lol").ToList(); files.Sort((a, b) => b.Name.CompareTo(a.Name)); int summaries = 0; var timer = new System.Diagnostics.Stopwatch(); timer.Start(); for (int i = 0; i < files.Count; i++) { string filename = files[i].Name.Substring(0, files[i].Name.Length - 4); ReplayItem item; if (summary.ContainsKey(filename)) { item = new ReplayItem((SummaryData) summary[filename], files[i]); newSummary.Add(filename, summary[filename]); } else { SummaryData data = new SummaryData(new MFroReplay(files[i])); newSummary.Add(filename, JSONObject.From(data)); item = new ReplayItem(data, files[i]); summaries++; } item.MouseUp += OpenDetails; replays.Add(item); } Logger.WriteLine("All replays loaded, took {0}ms", timer.ElapsedMilliseconds); using (FileStream saveSummary = summaryFile.Open(FileMode.Open)) { byte[] summBytes = MFroehlich.Parsing.MFro.MFroFormat.Serialize(newSummary); saveSummary.Write(summBytes, 0, summBytes.Length); Logger.WriteLine("Saved summaries, {0} total summaries, {1} newly generated", newSummary.Count, summaries); } Search(); ReplayArea.Visibility = System.Windows.Visibility.Visible; LoadArea.Visibility = System.Windows.Visibility.Hidden; Console.WriteLine("DONE"); }
void UpdateReplays() { GamePanel.Children.Clear(); var dir = new DirectoryInfo("cabinet"); var directories = dir.EnumerateDirectories() .OrderBy(d => d.CreationTime); string[] Replays = Directory.GetDirectories("cabinet"); foreach (DirectoryInfo di in directories) { string d = di.Name; if (!File.Exists(Path.Combine("cabinet", d, "token")) || !File.Exists(Path.Combine("cabinet", d, "key")) || !File.Exists(Path.Combine("cabinet", d, "endOfGameStats"))) { continue; } byte[] Base64Stats = Convert.FromBase64String(File.ReadAllText(Path.Combine("cabinet", d, "endOfGameStats"))); AmfReader statsReader = new AmfReader(new MemoryStream(Base64Stats), context); EndOfGameStats stats = (EndOfGameStats)statsReader.ReadAmf3Item(); ReplayItem item = new ReplayItem(); //Use unoccupied variable stats.Difficulty = d; item.Tag = stats; item.GameId.Content = d; item.GameType.Content = stats.GameMode.ToLower(); item.GameDate.Content = di.CreationTime.ToShortTimeString() + " " + di.CreationTime.ToShortDateString(); double seconds = stats.GameLength % 60; double minutes = stats.GameLength / 60; item.GameTime.Content = string.Format("{0:0}:{1:00}", minutes, seconds); item.Margin = new Thickness(0, 5, 0, 0); foreach (PlayerParticipantStatsSummary summary in stats.TeamPlayerParticipantStats) { SmallChampionItem image = new SmallChampionItem(); image.Width = 38; image.Height = 38; Uri UriSource = new Uri("/LegendaryClient;component/Assets/champion/" + summary.SkinName + ".png", UriKind.RelativeOrAbsolute); image.ChampionImage.Source = new BitmapImage(UriSource); item.TeamOnePanel.Children.Add(image); } foreach (PlayerParticipantStatsSummary summary in stats.OtherTeamPlayerParticipantStats) { SmallChampionItem image = new SmallChampionItem(); image.Width = 38; image.Height = 38; Uri UriSource = new Uri("/LegendaryClient;component/Assets/champion/" + summary.SkinName + ".png", UriKind.RelativeOrAbsolute); image.ChampionImage.Source = new BitmapImage(UriSource); item.TeamTwoPanel.Children.Add(image); } item.MouseDown += item_MouseDown; //Insert on top GamePanel.Children.Insert(0, item); } }