|
using System.Collections.Generic;
using System.Xml;
namespace GG.GameAttackCombos.Logic {
/// <summary>
/// Represents a button set for a platform. A button set is a named list of buttons that
/// form a graphical related set.
/// </summary>
public class ButtonSet {
#region Properties
/// <summary>
/// The platform this button set belongs to.
/// </summary>
public string Platform { get; private set; }
/// <summary>
/// The name of this button set.
/// </summary>
public string Name { get; private set; }
/// <summary>
/// The dictionary of buttons that make up this button set, keyed by ID.
/// </summary>
public Dictionary<string, Button> Buttons { get; private set; }
#endregion
/// <summary>
/// Initializes a new instance of ButtonSet.
/// </summary>
/// <param name="platform">The platform for this button set.</param>
/// <param name="name">The name of this button set.</param>
public ButtonSet(string platform, string name) {
Platform = platform;
Name = name;
Buttons = new Dictionary<string, Button>();
}
/// <summary>
/// Loads button sets from an XML document.
/// </summary>
/// <param name="document">The XML document that defines the button set.s</param>
/// <returns></returns>
public static List<ButtonSet> LoadButtonSets(XmlDocument document) {
List<ButtonSet> ButtonSets = new List<ButtonSet>();
// Read the button sets.
XmlNodeList ButtonSetNodes = document.SelectNodes("ButtonSets/ButtonSet");
foreach (XmlNode ButtonSetNode in ButtonSetNodes) {
// Create a new button set and add it to the list.
ButtonSet DefinedButtonSet = new ButtonSet(
ButtonSetNode.Attributes["platform"].Value,
ButtonSetNode.Attributes["name"].Value
);
ButtonSets.Add(DefinedButtonSet);
// Read the buttons for this button set.
XmlNodeList ButtonNodes = ButtonSetNode.SelectNodes("Button");
foreach (XmlNode ButtonNode in ButtonNodes) {
// Create a new button and add it to the button set.
Button DefinedButton = new Button(
ButtonNode.Attributes["id"].Value,
DefinedButtonSet.Platform,
ButtonNode.Attributes["iconKey"].Value
);
DefinedButtonSet.Buttons.Add(DefinedButton.Id, DefinedButton);
}
}
return ButtonSets;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I began programming on my Commodore 64 at around the age of 12. After migrating to DOS and then Windows, I decided to take on the Web. Several languages and platforms later, I have settled in with .NET nicely. I am currently the owner of a software consulting company and lead application developer for a learning-based technology consultation company.
The love of a finished application is usually at war with the desire to improve it as soon as it's released (they're never really finished).