Howto:Make a clickable panel
There are two methodes to make a clickable planel in FlightGear at the moment:
- Hotspot: adds a clickable (invisible) face at a certain position.
- Pick: makes a whole object clickable.
The easiest to use is pick, since you do not have to look up all the coordinates. Also the pick animation is more realistic and therefore more often used.
The hotspot animation is somewhat complicated. You have to define the x and y coordinates of every clickable "face" (hotspot) aswell the width and heigth of the hotspot to click on. See the following example of the 777-200.
Make a new panel file (.xml) in your aircraft's directory. The following lines are only placed on top of the file:
<PropertyList> <name>777-200 Overhead Panel</name> <background>Aircraft/777-200/Panels/transparent-bg.rgb</background> <w>256</w> <h>512</h> <instruments> <instrument> <name>panel hotspots</name> <x>128</x> <y>256</y> <w>256</w> <h>512</h> <w-base>256</w-base> <h-base>512</h-base> <actions>
Now all hotspots need to be listed as seperate actions:
<action> <name>Master Battery Switch</name> <button>0</button> <x>-278</x> <y>-188</y> <w>10</w> <h>10</h> <binding> <command>property-toggle</command> <property>/controls/electric/battery-switch</property> <step>1</step> <min>0</min> <max>1</max> <wrap>true</wrap> </binding> </action>
We close the file with:
</actions> </instrument> </instruments> </PropertyList>
Now we need to link to this file from our model's file. Add something similar to the following in your model file:
<panel> <path>Aircraft/777-200/Panels/oh-panel.xml</path> <bottom-left> <x-m>-23.396</x-m> <y-m>-0.522</y-m> <z-m>0.992</z-m> </bottom-left> <bottom-right> <x-m>-23.396</x-m> <y-m>0.522</y-m> <z-m>0.992</z-m> </bottom-right> <top-left> <x-m>-22.686</x-m> <y-m>-0.522</y-m> <z-m>1.323</z-m> </top-left> </panel>
As of FlightGear 2.11 (Git version), there's a new Knob / slider animation, to be used instead of the pick animation.
For 3D clickable object we can use the pick-animation. It makes a whole (3D) object clickable. This is especially easy to use with switches.
Each single clickable object requires a seperate animation; however you can have multiple objects (that result in the same action) in one animation. A pick animation exists of atleast the following lines of code, to be added in the .xml file of your panel:
<animation> <type>pick</type> <object-name>ButtonName</object-name> <action> <button>0</button> <repeatable>false</repeatable> <interval-sec>0.2</interval-sec> <binding> ... </binding> <mod-up> <binding> ... </binding> </mod-up> </action> </animation>
- object-name: remember to change into your buttons/knobs/switches name (!) and set the property to the property, corresponding with your button.
- button: what mouse button result in this action:
- 0 = left mouse button
- 1 = middle mouse button (usually clicking the scrollwheel)
- 2 = right mouse button
- 3 = mouse wheel forward
- 4 = mouse wheel back
- repeatable: setting to true will make users able to hold their mouse on a knob or switch, repeating the action. This should be disabled for most (if not all) toggle switches. Only dials usually benefit from such repeatability.
- interval-sec: is optional. Can be used on repeatable dials, to limit the frequency of actions.
- binding: is optional. Can be used to trigger an action on pressing the specified button.
- mod-up/binding: is optional. Can be used to trigger an action on releasing the button pressed over the object before.
Although binding and mod-up/binding are both optional, at least one should be included in order to make the object clickable. A list of all available bindings can be retrieved at the bindings article.
Note that you can add multiple actions in a single animation.
To check if the pick and/or hotspot animation work (on the correct buttons) we launch FlightGear and press Ctrl+C. Now all clickable objects or areas will get a yellow lining.