Game Development Reference
In-Depth Information
);
}
}
GetNodePosition()
traverses siblings until it finds the matching
XmlElement
.If
it isn
t found, then it throws an exception, probably just a result of some late-night
programming.
GetXPathToNode()
uses a recursive implementation, calling itself to
create the XPath for parent nodes.
'
Showing Actor Components
When an actor is selected, the actor components are read to create all the controls
needed to edit their values.
public unsafe void ShowActorComponents(int selectedActorId, XmlNode actorXml)
{
m_SelectedActorId = selectedActorId;
m_ActorXml = actorXml;
m_SelectedActorComponents = new XmlDocument();
XmlNode editorComponents = m_SelectedActorComponents.CreateElement(
“
Actor
”
);
m_SelectedActorComponents.AppendChild(editorComponents);
m_Panel.Controls.Clear();
XmlNodeList actorValueComponents = m_ActorXml.SelectNodes(
“
child::*
”
);
int lineNum = 0;
foreach (XmlNode actorValueComponent in actorValueComponents)
{
XmlNode sourceEditorComponent =
m_ComponentsByName[actorValueComponent.Name];
XmlDocument ownerDoc = editorComponents.OwnerDocument;
XmlNode editorComponent = ownerDoc.ImportNode(sourceEditorComponent,true);
editorComponents.AppendChild(editorComponent);
lineNum = AddComponentUI(actorValueComponent, editorComponent, lineNum);
}
}
The
m_ActorXml
member holds the actor XML values that are read in from the
game and stored in the level XML file. The
m_SelectedActorComponents
mem-
ber is initialized to hold a parallel XML structure that mirrors the actor XML, but
instead of storing actor values, it stores the component names, element names, and
element types of each component. For each component, the
AddComponentUI()
method is called to create all the controls.