diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fc3fb707..1740f1664 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 3.6.0 +- Adds param `hudComponents` in `BonfireWidget`; +- Adds `queryHud` method in `BonfireGameInterface`; +- Adds `addHud` method in `BonfireGameInterface`; +- Update Flame to `1.16.0`. + # 3.5.0 - Adds Parallax support - Background improvements. diff --git a/example/lib/pages/input/keyboard/barrel_show_keyboard_input.dart b/example/lib/pages/input/keyboard/barrel_show_keyboard_input.dart index 157d03951..e916f7186 100644 --- a/example/lib/pages/input/keyboard/barrel_show_keyboard_input.dart +++ b/example/lib/pages/input/keyboard/barrel_show_keyboard_input.dart @@ -36,7 +36,7 @@ class BarrelShowKeyboardInput extends GameDecoration } @override - bool onKeyboard(RawKeyEvent event, Set keysPressed) { + bool onKeyboard(KeyEvent event, Set keysPressed) { input += event.character ?? ''; return true; } diff --git a/example/lib/pages/parallax/bonfire/bonfire_parallax_background.dart b/example/lib/pages/parallax/bonfire/bonfire_parallax_background.dart index 53d18fa49..d8c075dea 100644 --- a/example/lib/pages/parallax/bonfire/bonfire_parallax_background.dart +++ b/example/lib/pages/parallax/bonfire/bonfire_parallax_background.dart @@ -2,9 +2,9 @@ import 'package:bonfire/bonfire.dart'; class BonfireParallaxBackground extends GameBackground { @override - void onGameMounted() { + void onMount() { _addParallax(); - super.onGameMounted(); + super.onMount(); } void _addParallax() async { diff --git a/example/lib/pages/parallax/flame/parallax_background.dart b/example/lib/pages/parallax/flame/parallax_background.dart index ff989f861..57baf6b9a 100644 --- a/example/lib/pages/parallax/flame/parallax_background.dart +++ b/example/lib/pages/parallax/flame/parallax_background.dart @@ -2,9 +2,9 @@ import 'package:bonfire/bonfire.dart'; class ParallaxBackground extends GameBackground { @override - void onGameMounted() { + void onMount() { _addParallax(); - super.onGameMounted(); + super.onMount(); } void _addParallax() async { diff --git a/example/pubspec.lock b/example/pubspec.lock index f85a58ed1..25170a4bc 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -47,7 +47,7 @@ packages: path: ".." relative: true source: path - version: "3.4.0" + version: "3.5.0" boolean_selector: dependency: transitive description: @@ -124,10 +124,10 @@ packages: dependency: transitive description: name: flame - sha256: "2a2352741500ce47823dcf212f06b23e9bdb622454eab90244ee6da58e23b488" + sha256: bb42a35fa5dabdea535daebe5b020e21a2fce8192b67b7e55cd30fed86d29f69 url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.16.0" flutter: dependency: "direct main" description: flutter @@ -238,18 +238,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" mime: dependency: transitive description: @@ -535,14 +535,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" - web: - dependency: transitive - description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 - url: "https://pub.dev" - source: hosted - version: "0.3.0" web_socket_channel: dependency: transitive description: @@ -569,4 +561,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.2.0 <4.0.0" - flutter: ">=3.13.0" + flutter: ">=3.19.0" diff --git a/lib/base/base_game.dart b/lib/base/base_game.dart index 3cb50c8e6..32fc5fc63 100644 --- a/lib/base/base_game.dart +++ b/lib/base/base_game.dart @@ -107,7 +107,7 @@ abstract class BaseGame extends FlameGame @override KeyEventResult onKeyEvent( - RawKeyEvent event, + KeyEvent event, Set keysPressed, ) { if (!enabledKeyboard) { diff --git a/lib/base/bonfire_game.dart b/lib/base/bonfire_game.dart index dba0f878d..1e2c1b510 100644 --- a/lib/base/bonfire_game.dart +++ b/lib/base/bonfire_game.dart @@ -108,6 +108,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface { this.player, this.interface, List? components, + List? hudComponents, this.background, bool debugMode = false, this.showCollisionArea = false, @@ -138,6 +139,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface { keyboardConfig: keyboardConfig, ), if (interface != null) interface, + ...hudComponents ?? [] ], ), world: World( @@ -312,7 +314,6 @@ class BonfireGame extends BaseGame implements BonfireGameInterface { @override void onDetach() { _notifyGameDetach(); - FollowerWidget.removeAll(); super.onDetach(); } @@ -473,6 +474,7 @@ class BonfireGame extends BaseGame implements BonfireGameInterface { } void _notifyGameDetach() { + FollowerWidget.removeAll(); void gameDetachComp(GameComponent c) => c.onGameDetach(); query().forEach(gameDetachComp); for (var child in camera.children) { @@ -485,4 +487,14 @@ class BonfireGame extends BaseGame implements BonfireGameInterface { @override Vector2 get worldsize => map.size; + + @override + Iterable queryHud() { + return camera.viewport.children.query(); + } + + @override + FutureOr addHud(Component component) { + return camera.viewport.add(component); + } } diff --git a/lib/base/bonfire_game_interface.dart b/lib/base/bonfire_game_interface.dart index 23c02a8db..eea6bc710 100644 --- a/lib/base/bonfire_game_interface.dart +++ b/lib/base/bonfire_game_interface.dart @@ -97,10 +97,10 @@ abstract class BonfireGameInterface { Iterable query({bool onlyVisible = false}); /// This method convert word position to screen position - Vector2 worldToScreen(Vector2 position); + Vector2 worldToScreen(Vector2 worldPosition); /// This method convert screen position to word position - Vector2 screenToWorld(Vector2 position); + Vector2 screenToWorld(Vector2 screenPosition); /// Used to check if a component is visible in the camera. bool isVisibleInCamera(GameComponent c); @@ -112,6 +112,12 @@ abstract class BonfireGameInterface { bool moveCameraToTarget = false, }); + /// Used to get hud components. + Iterable queryHud(); + + /// Used to add hud component in the game. + FutureOr addHud(Component component); + RaycastResult? raycast( Ray2 ray, { double? maxDistance, diff --git a/lib/base/listener_game_widget.dart b/lib/base/listener_game_widget.dart index 9edc0f36e..3104c9ab0 100644 --- a/lib/base/listener_game_widget.dart +++ b/lib/base/listener_game_widget.dart @@ -294,7 +294,7 @@ class ListenerGameWidgetState } } - KeyEventResult _handleKeyEvent(FocusNode focusNode, RawKeyEvent event) { + KeyEventResult _handleKeyEvent(FocusNode focusNode, KeyEvent event) { final game = currentGame; if (!_focusNode.hasPrimaryFocus) { @@ -302,7 +302,10 @@ class ListenerGameWidgetState } if (game is KeyboardEvents) { - return game.onKeyEvent(event, RawKeyboard.instance.keysPressed); + return game.onKeyEvent( + event, + HardwareKeyboard.instance.logicalKeysPressed, + ); } return KeyEventResult.handled; } @@ -364,7 +367,7 @@ class ListenerGameWidgetState focusNode: _focusNode, autofocus: widget.autofocus, descendantsAreFocusable: true, - onKey: _handleKeyEvent, + onKeyEvent: _handleKeyEvent, child: MouseRegion( cursor: currentGame.mouseCursor, child: Directionality( diff --git a/lib/color_filter/color_filter_component.dart b/lib/color_filter/color_filter_component.dart index 61df8c8a5..ffd7038d2 100644 --- a/lib/color_filter/color_filter_component.dart +++ b/lib/color_filter/color_filter_component.dart @@ -36,10 +36,7 @@ class ColorFilterComponent extends GameComponent @override int get priority { - if (hasGameRef) { - return LayerPriority.getColorFilterPriority(gameRef.highestPriority); - } - return super.priority; + return LayerPriority.getHudColorFilterPriority(); } @override diff --git a/lib/game_interface/game_interface.dart b/lib/game_interface/game_interface.dart index f6ebdd5bf..c91ee9e5b 100644 --- a/lib/game_interface/game_interface.dart +++ b/lib/game_interface/game_interface.dart @@ -6,10 +6,7 @@ import 'package:bonfire/bonfire.dart'; class GameInterface extends GameComponent { @override int get priority { - if (hasGameRef) { - return LayerPriority.getInterfacePriority(gameRef.highestPriority); - } - return super.priority; + return LayerPriority.getHudInterfacePriority(); } /// Used to add components in your interface like a Button. diff --git a/lib/input/keyboard/control_by_keyboard.dart b/lib/input/keyboard/control_by_keyboard.dart index 46d607436..5c63616d8 100644 --- a/lib/input/keyboard/control_by_keyboard.dart +++ b/lib/input/keyboard/control_by_keyboard.dart @@ -15,7 +15,7 @@ class ControlByKeyboard extends PlayerController with KeyboardEventListener { } @override - bool onKeyboard(RawKeyEvent event, Set keysPressed) { + bool onKeyboard(KeyEvent event, Set keysPressed) { /// If the keyboard is disabled, we do not process the event if (!keyboardConfig.enable) return false; @@ -28,7 +28,7 @@ class ControlByKeyboard extends PlayerController with KeyboardEventListener { /// No keyboard events, keep idle if (!_containDirectionalPressed(keysPressed) && - !event.repeat && + !event.synthesized && !_directionalIsIdle) { _directionalIsIdle = true; joystickChangeDirectional( @@ -57,14 +57,14 @@ class ControlByKeyboard extends PlayerController with KeyboardEventListener { } } else { /// Process action events - if (event is RawKeyDownEvent) { + if (event is KeyDownEvent) { joystickAction( JoystickActionEvent( id: event.logicalKey, event: ActionEvent.DOWN, ), ); - } else if (event is RawKeyUpEvent) { + } else if (event is KeyUpEvent) { joystickAction( JoystickActionEvent( id: event.logicalKey, diff --git a/lib/input/keyboard/keyboard_listener.dart b/lib/input/keyboard/keyboard_listener.dart index 34861854c..61629734c 100644 --- a/lib/input/keyboard/keyboard_listener.dart +++ b/lib/input/keyboard/keyboard_listener.dart @@ -4,7 +4,7 @@ import 'package:flutter/services.dart'; mixin KeyboardEventListener on GameComponent { // If return 'true' this event is not relay to others components. bool onKeyboard( - RawKeyEvent event, + KeyEvent event, Set keysPressed, ) { return false; diff --git a/lib/input/player_controller.dart b/lib/input/player_controller.dart index 14bae7703..a8174f94f 100644 --- a/lib/input/player_controller.dart +++ b/lib/input/player_controller.dart @@ -51,8 +51,15 @@ mixin PlayerControllerListener { } abstract class PlayerController extends GameComponent { + final dynamic id; final List _observers = []; + PlayerController({this.id, PlayerControllerListener? observer}) { + if (observer != null) { + _observers.add(observer); + } + } + void joystickChangeDirectional(JoystickDirectionalEvent event) { for (var o in _observers) { o.onJoystickChangeDirectional(event); @@ -83,10 +90,7 @@ abstract class PlayerController extends GameComponent { @override int get priority { - if (hasGameRef) { - return LayerPriority.getJoystickPriority(gameRef.highestPriority); - } - return super.priority; + return LayerPriority.getHudJoystickPriority(); } @override diff --git a/lib/lighting/lighting_component.dart b/lib/lighting/lighting_component.dart index 4f705d829..ce6745038 100644 --- a/lib/lighting/lighting_component.dart +++ b/lib/lighting/lighting_component.dart @@ -30,10 +30,7 @@ class LightingComponent extends GameComponent implements LightingInterface { @override int get priority { - if (hasGameRef) { - return LayerPriority.getLightingPriority(gameRef.highestPriority); - } - return super.priority; + return LayerPriority.getHudLightingPriority(); } Path getWheelPath(double wheelSize, double fromRadius, double toRadius) { diff --git a/lib/util/priority_layer.dart b/lib/util/priority_layer.dart index ecd035acf..ed9fec627 100644 --- a/lib/util/priority_layer.dart +++ b/lib/util/priority_layer.dart @@ -10,22 +10,22 @@ class LayerPriority { } static int getAbovePriority(int highestPriority) { - return highestPriority + 5; + return highestPriority + 10; } - static int getLightingPriority(int highestPriority) { - return highestPriority + 10; + static int getHudLightingPriority() { + return 10; } - static int getColorFilterPriority(int highestPriority) { - return highestPriority + 20; + static int getHudColorFilterPriority() { + return 20; } - static int getInterfacePriority(int highestPriority) { - return highestPriority + 30; + static int getHudInterfacePriority() { + return 30; } - static int getJoystickPriority(int highestPriority) { - return highestPriority + 40; + static int getHudJoystickPriority() { + return 40; } } diff --git a/lib/util/talk/talk_dialog.dart b/lib/util/talk/talk_dialog.dart index 30e9b67a3..8713777e8 100644 --- a/lib/util/talk/talk_dialog.dart +++ b/lib/util/talk/talk_dialog.dart @@ -103,17 +103,17 @@ class TalkDialogState extends State { Widget build(BuildContext context) { return Material( type: MaterialType.transparency, - child: RawKeyboardListener( + child: KeyboardListener( focusNode: _focusNode, - onKey: (raw) { - if (widget.keyboardKeysToNext.isEmpty && raw is RawKeyDownEvent) { + onKeyEvent: (raw) { + if (widget.keyboardKeysToNext.isEmpty && raw is KeyDownEvent) { // Prevent volume buttons from triggering the next dialog if (raw.logicalKey != LogicalKeyboardKey.audioVolumeUp && raw.logicalKey != LogicalKeyboardKey.audioVolumeDown) { _nextOrFinish(); } } else if (widget.keyboardKeysToNext.contains(raw.logicalKey) && - raw is RawKeyDownEvent) { + raw is KeyDownEvent) { _nextOrFinish(); } }, diff --git a/lib/widgets/bonfire_widget.dart b/lib/widgets/bonfire_widget.dart index ecf1102d0..2ec6e4c71 100644 --- a/lib/widgets/bonfire_widget.dart +++ b/lib/widgets/bonfire_widget.dart @@ -56,6 +56,7 @@ class BonfireWidget extends StatefulWidget { final Map>? overlayBuilderMap; final List? initialActiveOverlays; final List? components; + final List? hudComponents; final GameBackground? background; final CameraConfig? cameraConfig; final GameColorFilter? colorFilter; @@ -77,6 +78,7 @@ class BonfireWidget extends StatefulWidget { this.lightingColorGame, this.backgroundColor, this.colorFilter, + this.hudComponents, this.components, this.overlayBuilderMap, this.initialActiveOverlays, @@ -127,7 +129,8 @@ class BonfireWidgetState extends State { player: widget.player, interface: widget.interface, map: widget.map, - components: widget.components ?? [], + components: widget.components, + hudComponents: widget.hudComponents, background: widget.background, backgroundColor: widget.backgroundColor, debugMode: widget.debugMode, diff --git a/pubspec.lock b/pubspec.lock index 1819a4b27..8e10888dc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -61,10 +61,10 @@ packages: dependency: "direct main" description: name: flame - sha256: "2a2352741500ce47823dcf212f06b23e9bdb622454eab90244ee6da58e23b488" + sha256: bb42a35fa5dabdea535daebe5b020e21a2fce8192b67b7e55cd30fed86d29f69 url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.16.0" flutter: dependency: "direct main" description: flutter @@ -99,6 +99,30 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + url: "https://pub.dev" + source: hosted + version: "2.0.1" lints: dependency: transitive description: @@ -111,26 +135,26 @@ packages: dependency: transitive description: name: matcher - sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.16" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" ordered_set: dependency: transitive description: @@ -143,10 +167,10 @@ packages: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -224,14 +248,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" - web: + vm_service: dependency: transitive description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "13.0.0" sdks: dart: ">=3.2.0 <4.0.0" - flutter: ">=3.13.0" + flutter: ">=3.19.0" diff --git a/pubspec.yaml b/pubspec.yaml index 2f9ef62fd..815e27438 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bonfire description: (RPG maker) Create RPG-style or similar games more simply with Flame. -version: 3.5.0 +version: 3.6.0 homepage: https://bonfire-engine.github.io repository: https://github.com/RafaelBarbosatec/bonfire issue_tracker: https://github.com/RafaelBarbosatec/bonfire/issues @@ -14,7 +14,7 @@ dependencies: flutter: sdk: flutter - flame: ^1.15.0 + flame: ^1.16.0 tiledjsonreader: ^1.3.4 http: ^1.1.0 a_star_algorithm: ^0.3.1