public NameEntry(HighTimeData playerData, string levelName, int currentZone, int currentLevel) { this.playerData = playerData; this.levelName = levelName; this.currentLevel = currentLevel; this.currentZone = currentZone; if (HighTime.PlayerData.PlayerName != null) { this.playerName = HighTime.PlayerData.PlayerName; } //Append characters to the typedText string when the player types stuff on the keyboard. KeyGrabber.InboundCharEvent += (inboundCharacter) => { //Only append characters that exist in the spritefont. if (inboundCharacter < 32) { return; } if (inboundCharacter > 126) { return; } if (playerName.Length < maxNameLength) { playerName += inboundCharacter; } }; }
public static void LoadData(string filename) { string fullname = string.Empty; if (filename.Contains('.') == true) { fullname = filename; } else { fullname = filename + ".dat"; } string pathString = "Content/Leaderboard"; fullname = System.IO.Path.Combine(pathString, fullname); XmlDocument doc = new XmlDocument(); if (File.Exists(fullname) == false) { return; } if (timeList.Count > 0) { timeList.Clear(); } doc.Load(fullname); foreach (XmlNode node in doc.DocumentElement.ChildNodes) { if (node.Name == "PlayerDetails") { HighTimeData data = new HighTimeData(); data.PlayerPosition = node.Attributes["PlayerPosition"].Value; data.PlayerName = node.Attributes["PlayerName"].Value; data.PlayerTime = node.Attributes["PlayerTime"].Value; timeList.Add(data); } } }
public static void SaveData(string filename, HighTimeData data) { string pathString = "Content/Leaderboard"; if (File.Exists(pathString) == false) { System.IO.Directory.CreateDirectory(pathString); } timeList.Clear(); string fullname = filename + ".dat"; pathString = System.IO.Path.Combine(pathString, fullname); playerData.PlayerName = data.PlayerName; HighTimeOnline.CreateTable(filename); XmlDocument doc = new XmlDocument(); XmlElement rootElement = doc.CreateElement("TimeBoard"); doc.AppendChild(rootElement); LoadData(fullname); timeList.Add(data); timeList.Sort((s1, s2) => s1.PlayerTime.CompareTo(s2.PlayerTime)); List <HighTimeData> list = timeList.Distinct().ToList(); HighTimeOnline.AddUserTime(filename, list[0].PlayerName, list[0].PlayerTime); if (list.Count >= amount) { int max = list.Count; list.RemoveRange(amount, max - amount); } for (int i = 0; i < list.Count; i++) { int position = i + 1; XmlElement pElement = doc.CreateElement("PlayerDetails"); XmlAttribute positionAttr = doc.CreateAttribute("PlayerPosition"); positionAttr.Value = position.ToString(); XmlAttribute nameAttr = doc.CreateAttribute("PlayerName"); nameAttr.Value = list[i].PlayerName; XmlAttribute timeAttr = doc.CreateAttribute("PlayerTime"); timeAttr.Value = list[i].PlayerTime; pElement.Attributes.Append(positionAttr); pElement.Attributes.Append(nameAttr); pElement.Attributes.Append(timeAttr); rootElement.AppendChild(pElement); } doc.Save(pathString); }