Menu constructor

Menu({
  1. required Game game,
  2. required Message title,
  3. List<MenuItem>? items,
  4. int? position,
  5. TaskFunction? onCancel,
  6. ScanCode upScanCode = ScanCode.up,
  7. GameControllerButton upButton = GameControllerButton.dpadUp,
  8. ScanCode downScanCode = ScanCode.down,
  9. GameControllerButton downButton = GameControllerButton.dpadDown,
  10. ScanCode activateScanCode = ScanCode.space,
  11. GameControllerButton activateButton = GameControllerButton.dpadRight,
  12. ScanCode cancelScanCode = ScanCode.escape,
  13. GameControllerButton cancelButton = GameControllerButton.dpadLeft,
  14. GameControllerAxis movementAxis = GameControllerAxis.lefty,
  15. GameControllerAxis activateAxis = GameControllerAxis.triggerright,
  16. GameControllerAxis cancelAxis = GameControllerAxis.triggerleft,
  17. int controllerMovementSpeed = 500,
  18. double controllerAxisSensitivity = 0.5,
  19. bool searchEnabled = true,
  20. int searchInterval = 500,
  21. SoundChannel? soundChannel,
  22. AssetReference? music,
  23. List<Ambiance>? ambiances,
  24. List<RandomSound>? randomSounds,
  25. Map<String, Command>? commands,
  26. RumbleEffect? titleRumbleEffect,
  27. 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,
  );
}