Game Development Reference
In-Depth Information
distinguish which control goes with which XML element. Even better, the XPath can
be used to find both the actor values and the editor ' s component definition. An event
handler is also attached that will run anytime the value of the text box is changed.
A button is also created next to the text box that will bring up the typical open file
dialog box. Its name is set to the XPath of the actor element as well, but with
But-
ton
attached to the end. This will not only uniquely identify the button in case there
are multiple file elements in the actor, but it will enable us to find the exact text box
control the button is associated with.
Editing Actor Components
The C# Windows Form holds the controls for editing different element types, but
there needs to be a way to actually change these values and have them reflect in
visual display. Some controls can be edited directly, such as those for position.
Others, like a choice of color or a filename, can make good use of helper dialog
boxes. Here is SelectFile() , the code that will run when the Browse button is
pressed:
private void SelectFile(object sender, MouseEventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
Button button = (Button)sender;
string buttonDesc =
Button
;
string textBoxElementName =
button.Name.Substring(0, button.Name.Length - buttonDesc.Length);
XmlNode fileElement = FindEditorElementFromXPath(textBoxElementName);
openFile.Filter = fileElement.Attributes[
extensions
].Value;
openFile.ShowDialog();
if (openFile.FileNames.Length > 0)
{
try
{
string fileName = openFile.FileNames[0];
if (fileName.StartsWith(m_AssetsDirectory))
{
TextBox textBox = (TextBox)m_Panel.Controls[textBoxElementName];
textBox.Text = fileName.Substring(m_AssetsDirectory.Length + 1);
}
else
{
 
Search WWH ::




Custom Search