MODEL BEHAVIORS TEMPLATES
A template can be defined directly under any <Behaviors>
or <CompileBehaviours>
node, and it consists of an identifier specified with the attribute name and a "body" where we specify what the template does. For example:
<Template Name="Create_Animation">
<Parameters Type="Default">
<GUID/>
<LENGTH>100</LENGTH>
<TYPE>Sim</TYPE>
<TYPE_PARAMS>Autoplay</TYPE_PARAMS>
<LAG>0</LAG>
<WRAP>False</WRAP>
<DELTA>False</DELTA>
<BLENDWEIGHT>1.0</BLENDWEIGHT>
</Parameters>
<Animation Name="#NAME#" Guid="#GUID#" Length="#LENGTH#" Type="#TYPE#" TypeParam="#TYPE_PARAMS#">
<Parameter>
<Code>#CODE#</Code>
<Lag>#LAG#</Lag>
<Wrap>#WRAP#</Wrap>
<Delta>#DELTA#</Delta>
<BlendWeight>#BLENDWEIGHT#</BlendWeight>
</Parameter>
</Animation>
</Template>
The goal of creating and using a template is to define base components (like <MouseRect>
, <Animation>
, etc..). A component definition consist of a lot of parameters, many of which can simply have a few default parameters. Therefor a template is the interface that allows you to use these default values while hiding most of the component parameters behind behavior <Parameters>
.
Using A Template
To make use of a defined template we use the node <UseTemplate>
which takes the name of the template to be included as an argument. Any content defined within the <UseTemplate>
node will be parsed as parameters with an override rule. We discuss this in more detail on the following page (Default Templates), but let's just take a quick look at an example, using the XML posted above, to create an animation:
<!-- Use the template with 2 parameters NAME & CODE -->
<UseTemplate Name="Create_Animation">
<NAME>An_Animation_ID</NAME>
<CODE>(L:XMLVAR_My_Lever_Position, percent)</CODE>
</UseTemplate>
<!-- Use the template with 3 parameters NAME, CODE a LAG -->
<UseTemplate Name="Create_Animation">
<NAME>An_Other_Animation_ID</NAME>
<CODE>(A:ELEVATOR DEFLECTION PCT, percent) 100 + 2 /</CODE>
<LAG>100</LAG><!-- Override default value of 0 -->
</UseTemplate>
What makes using the template system so special, is the use of conditional statements (using Program Template Definitions). With this system you can easily use a template or an other based on a parameter specification, changing radically the created component properties
<Switch>
<Case NotEmpty="ANIM_CODE">
<UseTemplate Name="Create_Animation_Code"/>
</Case>
<Case NotEmpty="ANIM_SIMVAR">
<UseTemplate Name="Create_Animation_Simvar"/>
</Case>
</Switch>
One of the XML programming elements in particular is very useful: <Loop>
. This element allows the simplification of repetitive <UseTemplate>
statements, for example:
<Loop>
<Setup>
<Value>MAP_MODE</Value>
<Parameters>
<1>WXR</1>
<2>STA</2>
<3>WPT</3>
<4>ARPT</4>
<5>DATA</5>
<6>POS</6>
<7>TERR</7>
</Parameters>
</Setup>
<Do>
<UseTemplate Name="My_Button_Template">
<BASE_NAME>A_GLTF_NODE_PUSH_#MAP_MODE#</BASE_NAME>
<ON_EVENT>(>H:Plane_MFD_MAP_#MAP_MODE#)</ON_EVENT>
</UseTemplate>
</Do>
</Loop>
<!-- Create 7 buttons with an animation, a mouserect and an inputevent -->