public MapPlayerLocationGroup(XNAPanel parent, Point offset, String mapname) { this.parent = parent; this.offset = offset; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(Game1.MAPS_FOLDER_LOCATION + "/" + mapname + ".xml"); foreach (XmlNode rootChild in xmldoc.ChildNodes[1].ChildNodes) { if (rootChild.Name == "Players") { this.buttons.Clear(); foreach (XmlNode playerNode in rootChild.ChildNodes) { Point mapLocation = new Point( Int32.Parse(playerNode.Attributes["x"].Value), Int32.Parse(playerNode.Attributes["y"].Value)); Point minimapLocation = this.MapToMiniMap(mapLocation); MapPlayerLocationButton button = new MapPlayerLocationButton( this, parent, mapLocation, minimapLocation); this.buttons.AddLast(button); } if (parent is MapSelectionPanel) this.OnMapSelectionChanged(false); else if (parent is MapPreviewPanel) this.OnMapSelectionChanged(true); } else if (rootChild.Name == "Data") { this.mapWidth = Int32.Parse(rootChild.Attributes["width"].Value) * Int32.Parse(rootChild.Attributes["tileWidth"].Value); this.selectedMapHeight = Int32.Parse(rootChild.Attributes["height"].Value) * Int32.Parse(rootChild.Attributes["tileHeight"].Value); } } // Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace); }
/// <summary> /// When a user clicks on an empty MapPlayerLocationButton, a number needs to appear. /// </summary> /// <param name="number">Number to display on the map</param> public void OnPlayerIndexChanged(MapPlayerLocationButton clickedButton, int number) { int result = 0; // If user clicked on a button that already contained this number if (Int32.TryParse(clickedButton.text, out result) && result == number) { clickedButton.text = ""; } else { // Clear all buttons which have the number text foreach (MapPlayerLocationButton button in this.buttons) { if (Int32.TryParse(button.text, out result) && result == number) button.text = ""; } // Reapply on the correct one if (clickedButton.text == "") { clickedButton.text = number + ""; } } }
/// <summary> /// Gets the index of a button. /// </summary> /// <param name="button">The button to search for</param> /// <returns>The integer value</returns> public int GetIndexOfButton(MapPlayerLocationButton button) { for (int i = 0; i < this.buttons.Count; i++) { if (this.buttons.ElementAt(i) == button) return i; } return -1; }