Menu constructor
- required Game game,
- required Message title,
- List<
MenuItem> ? items, - int? position,
- TaskFunction? onCancel,
- ScanCode upScanCode = ScanCode.up,
- GameControllerButton upButton = GameControllerButton.dpadUp,
- ScanCode downScanCode = ScanCode.down,
- GameControllerButton downButton = GameControllerButton.dpadDown,
- ScanCode activateScanCode = ScanCode.space,
- GameControllerButton activateButton = GameControllerButton.dpadRight,
- ScanCode cancelScanCode = ScanCode.escape,
- GameControllerButton cancelButton = GameControllerButton.dpadLeft,
- GameControllerAxis movementAxis = GameControllerAxis.lefty,
- GameControllerAxis activateAxis = GameControllerAxis.triggerright,
- GameControllerAxis cancelAxis = GameControllerAxis.triggerleft,
- int controllerMovementSpeed = 500,
- double controllerAxisSensitivity = 0.5,
- bool searchEnabled = true,
- int searchInterval = 500,
- SoundChannel? soundChannel,
- AssetReference? music,
- List<
Ambiance> ? ambiances, - List<
RandomSound> ? randomSounds, - Map<
String, Command> ? commands, - RumbleEffect? titleRumbleEffect,
- RumbleEffect? itemRumbleEffect,
Create a menu.
If position
is null
, then the menu title will be selected. Otherwise,
the menu item at the given position (starting at 0) in the menuItems
list will be selected.
You can either specify a list of [MenuItems as the items
argument, or
override the menuItems property.
Please note: Whether or not you provide an items
list, you can still
pass a position
value, as this only affects the currentMenuItem
getter.
The list of ambiances
and randomSounds
are passed to the Level
constructor.
The controllerAxisSensitivity
value defines how sensitive an axis is to
controlling this instance. The higher this value, the further the
controller axis has to be pushed before anything happens. The lower the
value, the easier it is to accidentally do things in the menu.
The controllerMovementSpeed
value controls how often the player can use
a controller in this menu.
The activateAxis
value is the axis which can be used to call the
activate method.
The cancelAxis
value is the axis which can be used to call the cancel
method.
The movementAxis
value is the axis which can be used to move within this
menu.
Implementation
Menu({
required super.game,
required this.title,
final List<MenuItem>? items,
this.position,
this.onCancel,
this.upScanCode = ScanCode.up,
this.upButton = GameControllerButton.dpadUp,
this.downScanCode = ScanCode.down,
this.downButton = GameControllerButton.dpadDown,
this.activateScanCode = ScanCode.space,
this.activateButton = GameControllerButton.dpadRight,
this.cancelScanCode = ScanCode.escape,
this.cancelButton = GameControllerButton.dpadLeft,
final GameControllerAxis movementAxis = GameControllerAxis.lefty,
final GameControllerAxis activateAxis = GameControllerAxis.triggerright,
final GameControllerAxis cancelAxis = GameControllerAxis.triggerleft,
final int controllerMovementSpeed = 500,
final double controllerAxisSensitivity = 0.5,
this.searchEnabled = true,
this.searchInterval = 500,
this.soundChannel,
super.music,
super.ambiances,
super.randomSounds,
super.commands,
this.titleRumbleEffect,
this.itemRumbleEffect,
}) : menuItems = items ?? [],
searchString = '',
searchTime = 0 {
controllerAxisDispatcher = ControllerAxisDispatcher(
{
movementAxis: (final value) {
if (value < 0) {
up();
} else {
down();
}
},
activateAxis: (final value) => activate(),
cancelAxis: (final value) => cancel()
},
axisSensitivity: controllerAxisSensitivity,
functionInterval: controllerMovementSpeed,
);
}