-
Notifications
You must be signed in to change notification settings - Fork 0
Input Event
Input Events are used to create Lock mode tooltips, as well as separate user input from the actual 'state' of the component. They are extremely useful, and every interaction and switch you use should be using an Input Event.
As with every complex behavior expression, inputevent has a bunch of inbuilt structs and enums:
// A lock tooltip icon
enum Icon {
MoveX,
MoveY,
MoveAxis,
MoveAxisX,
MoveAxisY,
Rotate,
Push,
Pull
}// An inbuilt tooltip for interactions
enum InteractionTip {
XAxis,
XAxisLeft,
XAxisRight,
YAxis,
YAxisDown,
YAxisUp,
PrimaryUp,
PrimaryDown,
SecondaryUp,
SecondaryDown,
TertiaryUp,
TertiaryDown,
Lock,
Unlock,
Increase,
Decrease
}// A binding to an alias or key event
struct Binding {
event: str | none = none, // Only one can be set
alias: str | none = none,
params: code // A parameter handler. The variables `p0`..`pn` contain the values that the event contains if it is an event binding, and the variable `p0` contains the value assigned if it is an alias binding. The output is passed to the `Setter`'s `code`.// A setter of InputEvent values
struct Setter {
set: code, // Code that runs to set the value. The implicit variable `p0` contains the variable that was passed to the setter
bindings: [Binding] // An array of bindings to this setter
}You can create Input Events like:
inputevent <name: expr> {
legacy_icon: <expr>,
lock_icon: <expr>,
description: <expr>,
tooltip_value: <expr>,
legacy_interaction: <expr>,
lock_interaction: <expr>,
value: <expr>,
units: <expr>,
init: <expr>,
watch: <expr>,
inc: <expr>,
dec: <expr>,
set: <expr>
}
// Which would be:
inputevent "MyInputEvent" {
legacy_icon: Icon.Push,
lock_icon: Icon.Push,
description: @{ "This is my Input Event" },
tooltip_value: @{
if @"O:InputEventValue, Bool" { "On" } else { "Off" }
},
legacy_interaction: [InteractionTip.PrimaryDown],
lock_interaction: @{
"This is a custom interaction message"
},
value: @{ @"O:InputEventValue, Bool" },
units: "Bool",
init: @{ @"O:InputEventValue, Bool" = false },
watch: ["A:SomeSimVar", "L:SomeLocalVar"],
inc: Setter {
set: @{ @"B:MyInputEvent_Set" = @"B:MyInputEvent" + p0 },
bindings: [Binding {
alias: "MyInputEvent_IncrementByOne",
param: @{ 1 }
}]
},
dec: Setter {
set: @{ @"B:MyInputEvent_Set" = @"B:MyInputEvent" - p0 },
bindings: [Binding {
alias: "MyInputEvent_DecrementByOne",
param: @{ 1 }
}]
},
set: Setter {
set: @{ @"O:InputEventValue, Bool" = p0 },
bindings: [none]
}
}name: The name of the input event, which you will use to refer to it elsewhere (like reading and setting its value).
legacy_icon: The Icon to display when a mouse is being used.
lock_icon: The Icon to display when a controller is being used.
description: Code that generates the description of the tooltip.
tooltip_value: Code that generates the value to show in the tooltip.
legacy_interaction: Either an array of InteractionTips or custom code to generate the interaction message when a mouse is being used ([InteractionTip] | code).
lock_interaction: Either an array of InteractionTips or custom code to generate the interaction message when a controller is being used ([InteractionTip] | code).
value: Code to generate the value of the Input Event when it is read.
units: The units that the input event stores its value in. Used to convert when the value is read with a different unit.
init: The code that sets the value at spawn, or when a watched variable's value changes.
watch: An array of aircraft variables and local variables to watch. They must be prefixed with "A:" or "L:" only.
inc: A Setter that handles the incrementing of the Input Event. It is called when the variable @"B:{name}_Inc" is assigned to.
dec: A Setter that handles the decrementing of the Input Event: It is called when the variable @"B:{name}_Dec" is assigned to.
set: A Setter that sets the Input Event: It is called when the variable @"B:{name}_Set" is assigned to.