mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 11:43:19 +08:00
Fix gestures when isHud = true and camera is transformed (#843)
* Fix gestures when isHud = true and camera is transformed * Use Info instead of Event everywhere
This commit is contained in:
@ -60,7 +60,7 @@ class BasicAnimations extends BaseGame with TapDetector {
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapDown(TapDownInfo event) {
|
||||
addAnimation(event.eventPosition.game);
|
||||
void onTapDown(TapDownInfo info) {
|
||||
addAnimation(info.eventPosition.game);
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,8 +31,8 @@ class ZoomGame extends BaseGame with ScrollDetector, ScaleDetector {
|
||||
|
||||
static const zoomPerScrollUnit = 0.001;
|
||||
@override
|
||||
void onScroll(PointerScrollInfo event) {
|
||||
camera.zoom += event.scrollDelta.game.y * zoomPerScrollUnit;
|
||||
void onScroll(PointerScrollInfo info) {
|
||||
camera.zoom += info.scrollDelta.game.y * zoomPerScrollUnit;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -65,7 +65,7 @@ class Circles extends BaseGame with HasCollidables, TapDetector {
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapDown(TapDownInfo event) {
|
||||
add(MyCollidable(event.eventPosition.game));
|
||||
void onTapDown(TapDownInfo info) {
|
||||
add(MyCollidable(info.eventPosition.game));
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,8 +110,8 @@ abstract class MyCollidable extends PositionComponent
|
||||
}
|
||||
|
||||
@override
|
||||
bool onDragEnd(int pointerId, DragEndInfo event) {
|
||||
velocity.setFrom(event.velocity / 10);
|
||||
bool onDragEnd(int pointerId, DragEndInfo info) {
|
||||
velocity.setFrom(info.velocity / 10);
|
||||
_isDragged = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -44,9 +44,9 @@ class OnlyShapes extends BaseGame with HasTapableComponents {
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapDown(int pointerId, TapDownInfo event) {
|
||||
super.onTapDown(pointerId, event);
|
||||
final tapDownPoint = event.eventPosition.game;
|
||||
void onTapDown(int pointerId, TapDownInfo info) {
|
||||
super.onTapDown(pointerId, info);
|
||||
final tapDownPoint = info.eventPosition.game;
|
||||
final component = MyShapeComponent(randomShape(tapDownPoint), shapePaint);
|
||||
add(component);
|
||||
}
|
||||
@ -56,7 +56,7 @@ class MyShapeComponent extends ShapeComponent with Tapable {
|
||||
MyShapeComponent(Shape shape, Paint shapePaint) : super(shape, shapePaint);
|
||||
|
||||
@override
|
||||
bool onTapDown(TapDownInfo event) {
|
||||
bool onTapDown(TapDownInfo info) {
|
||||
remove();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ class Square extends PositionComponent with HasGameRef<Priority>, Tapable {
|
||||
}
|
||||
|
||||
@override
|
||||
bool onTapDown(TapDownInfo event) {
|
||||
bool onTapDown(TapDownInfo info) {
|
||||
final topComponent = gameRef.components.last;
|
||||
if (topComponent != this) {
|
||||
gameRef.changePriority(this, topComponent.priority + 1);
|
||||
|
||||
@ -33,13 +33,13 @@ class DraggableSquare extends PositionComponent
|
||||
}
|
||||
|
||||
@override
|
||||
bool onDragUpdate(int pointerId, DragUpdateInfo event) {
|
||||
bool onDragUpdate(int pointerId, DragUpdateInfo info) {
|
||||
final dragDeltaPosition = this.dragDeltaPosition;
|
||||
if (dragDeltaPosition == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
position.setFrom(event.eventPosition.game - dragDeltaPosition);
|
||||
position.setFrom(info.eventPosition.game - dragDeltaPosition);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ class HoverablesGame extends BaseGame with HasHoverableComponents, TapDetector {
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapDown(TapDownInfo event) {
|
||||
add(HoverableSquare(event.eventPosition.game));
|
||||
void onTapDown(TapDownInfo info) {
|
||||
add(HoverableSquare(info.eventPosition.game));
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,8 +16,8 @@ class MouseMovementGame extends BaseGame with MouseMovementDetector {
|
||||
bool onTarget = false;
|
||||
|
||||
@override
|
||||
void onMouseMove(PointerHoverInfo event) {
|
||||
target = event.eventPosition.game;
|
||||
void onMouseMove(PointerHoverInfo info) {
|
||||
target = info.eventPosition.game;
|
||||
}
|
||||
|
||||
Rect _toRect() => position.toPositionedRect(objSize);
|
||||
|
||||
@ -12,8 +12,8 @@ class MultitapGame extends BaseGame with MultiTouchTapDetector {
|
||||
final Map<int, Rect> taps = {};
|
||||
|
||||
@override
|
||||
void onTapDown(int pointerId, TapDownInfo event) {
|
||||
taps[pointerId] = event.eventPosition.game.toPositionedRect(tapSize);
|
||||
void onTapDown(int pointerId, TapDownInfo info) {
|
||||
taps[pointerId] = info.eventPosition.game.toPositionedRect(tapSize);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -17,8 +17,8 @@ class MultitapAdvancedGame extends BaseGame
|
||||
Rect? panRect;
|
||||
|
||||
@override
|
||||
void onTapDown(int pointerId, TapDownInfo event) {
|
||||
taps[pointerId] = event.eventPosition.game.toPositionedRect(tapSize);
|
||||
void onTapDown(int pointerId, TapDownInfo info) {
|
||||
taps[pointerId] = info.eventPosition.game.toPositionedRect(tapSize);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -45,8 +45,8 @@ class MultitapAdvancedGame extends BaseGame
|
||||
}
|
||||
|
||||
@override
|
||||
void onDragUpdate(int pointerId, DragUpdateInfo event) {
|
||||
end = event.eventPosition.game;
|
||||
void onDragUpdate(int pointerId, DragUpdateInfo info) {
|
||||
end = info.eventPosition.game;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -13,8 +13,8 @@ class ScrollGame extends BaseGame with ScrollDetector {
|
||||
Vector2? target;
|
||||
|
||||
@override
|
||||
void onScroll(PointerScrollInfo event) {
|
||||
target = position + event.scrollDelta.game * 5;
|
||||
void onScroll(PointerScrollInfo info) {
|
||||
target = position + info.scrollDelta.game * 5;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -27,9 +27,9 @@ class CombinedEffectGame extends BaseGame with TapDetector {
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapUp(TapUpInfo event) {
|
||||
void onTapUp(TapUpInfo info) {
|
||||
greenSquare.clearEffects();
|
||||
final currentTap = event.eventPosition.game;
|
||||
final currentTap = info.eventPosition.game;
|
||||
|
||||
final move = MoveEffect(
|
||||
path: [
|
||||
|
||||
@ -31,8 +31,8 @@ class InfiniteEffectGame extends BaseGame with TapDetector {
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapUp(TapUpInfo event) {
|
||||
final p = event.eventPosition.game;
|
||||
void onTapUp(TapUpInfo info) {
|
||||
final p = info.eventPosition.game;
|
||||
|
||||
greenSquare.clearEffects();
|
||||
redSquare.clearEffects();
|
||||
|
||||
@ -16,11 +16,11 @@ class MoveEffectGame extends BaseGame with TapDetector {
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapUp(TapUpInfo event) {
|
||||
void onTapUp(TapUpInfo info) {
|
||||
square.addEffect(
|
||||
MoveEffect(
|
||||
path: [
|
||||
event.eventPosition.game,
|
||||
info.eventPosition.game,
|
||||
Vector2(100, 100),
|
||||
Vector2(50, 120),
|
||||
Vector2(200, 400),
|
||||
|
||||
@ -20,8 +20,8 @@ class SequenceEffectGame extends BaseGame with TapDetector {
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapUp(TapUpInfo event) {
|
||||
final currentTap = event.eventPosition.game;
|
||||
void onTapUp(TapUpInfo info) {
|
||||
final currentTap = info.eventPosition.game;
|
||||
greenSquare.clearEffects();
|
||||
|
||||
final move1 = MoveEffect(
|
||||
|
||||
@ -89,8 +89,8 @@ class IsometricTileMapGame extends BaseGame with MouseMovementDetector {
|
||||
}
|
||||
|
||||
@override
|
||||
void onMouseMove(PointerHoverInfo event) {
|
||||
final screenPosition = event.eventPosition.game;
|
||||
void onMouseMove(PointerHoverInfo info) {
|
||||
final screenPosition = info.eventPosition.game;
|
||||
final block = base.getBlock(screenPosition);
|
||||
selector.show = base.containsBlock(block);
|
||||
selector.position.setFrom(topLeft + base.getBlockPosition(block));
|
||||
|
||||
@ -28,6 +28,7 @@
|
||||
- Add `Matrix4` extensions
|
||||
- `Camera.apply` is done with matrix transformations
|
||||
- `Camera` zooming is taking current `relativeOffset` into account
|
||||
- Fix gestures for when `isHud = true` and `Camera` is modified
|
||||
|
||||
## [1.0.0-releasecandidate.11]
|
||||
- Replace deprecated analysis option lines-of-executable-code with source-lines-of-code
|
||||
|
||||
@ -61,9 +61,9 @@ class MyGame extends BaseGame with DoubleTapDetector, TapDetector {
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapUp(TapUpInfo event) {
|
||||
void onTapUp(TapUpInfo info) {
|
||||
final touchArea = RectExtension.fromVector2Center(
|
||||
center: event.eventPosition.game,
|
||||
center: info.eventPosition.game,
|
||||
width: 20,
|
||||
height: 20,
|
||||
);
|
||||
|
||||
@ -6,6 +6,7 @@ import 'package:ordered_set/comparing.dart';
|
||||
import 'package:ordered_set/ordered_set.dart';
|
||||
|
||||
import '../../game.dart';
|
||||
import '../../gestures.dart';
|
||||
import '../effects/effects.dart';
|
||||
import '../effects/effects_handler.dart';
|
||||
import '../extensions/vector2.dart';
|
||||
@ -230,4 +231,9 @@ abstract class BaseComponent extends Component {
|
||||
}
|
||||
return shouldContinue;
|
||||
}
|
||||
|
||||
@protected
|
||||
Vector2 eventPosition(PositionInfo info) {
|
||||
return isHud ? info.eventPosition.widget : info.eventPosition.game;
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,9 +186,9 @@ class JoystickAction extends BaseComponent with Draggable, HasGameRef {
|
||||
}
|
||||
|
||||
@override
|
||||
bool onDragUpdate(int pointerId, DragUpdateInfo event) {
|
||||
bool onDragUpdate(int pointerId, DragUpdateInfo info) {
|
||||
if (_dragging) {
|
||||
_dragPosition = event.eventPosition.game;
|
||||
_dragPosition = info.eventPosition.game;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@ -161,9 +161,9 @@ class JoystickDirectional extends BaseComponent with Draggable, HasGameRef {
|
||||
}
|
||||
|
||||
@override
|
||||
bool onDragUpdate(_, DragUpdateInfo event) {
|
||||
bool onDragUpdate(_, DragUpdateInfo info) {
|
||||
if (_dragging) {
|
||||
_dragPosition = event.eventPosition.game;
|
||||
_dragPosition = info.eventPosition.game;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -28,7 +28,7 @@ mixin Draggable on BaseComponent {
|
||||
bool _checkPointerId(int pointerId) => _currentPointerIds.contains(pointerId);
|
||||
|
||||
bool handleDragStart(int pointerId, DragStartInfo info) {
|
||||
if (containsPoint(info.eventPosition.game)) {
|
||||
if (containsPoint(eventPosition(info))) {
|
||||
_isDragged = true;
|
||||
_currentPointerIds.add(pointerId);
|
||||
return onDragStart(pointerId, info);
|
||||
|
||||
@ -8,20 +8,20 @@ import '../base_component.dart';
|
||||
mixin Hoverable on BaseComponent {
|
||||
bool _isHovered = false;
|
||||
bool get isHovered => _isHovered;
|
||||
void onHoverEnter(PointerHoverInfo event) {}
|
||||
void onHoverLeave(PointerHoverInfo event) {}
|
||||
void onHoverEnter(PointerHoverInfo info) {}
|
||||
void onHoverLeave(PointerHoverInfo info) {}
|
||||
|
||||
@nonVirtual
|
||||
void doHandleMouseMovement(PointerHoverInfo event, Vector2 p) {
|
||||
if (containsPoint(p)) {
|
||||
void handleMouseMovement(PointerHoverInfo info) {
|
||||
if (containsPoint(eventPosition(info))) {
|
||||
if (!_isHovered) {
|
||||
_isHovered = true;
|
||||
onHoverEnter(event);
|
||||
onHoverEnter(info);
|
||||
}
|
||||
} else {
|
||||
if (_isHovered) {
|
||||
_isHovered = false;
|
||||
onHoverLeave(event);
|
||||
onHoverLeave(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -29,10 +29,9 @@ mixin Hoverable on BaseComponent {
|
||||
|
||||
mixin HasHoverableComponents on BaseGame {
|
||||
@mustCallSuper
|
||||
void onMouseMove(PointerHoverInfo event) {
|
||||
final p = event.eventPosition.game;
|
||||
void onMouseMove(PointerHoverInfo info) {
|
||||
bool _mouseMoveHandler(Hoverable c) {
|
||||
c.doHandleMouseMovement(event, p);
|
||||
c.handleMouseMovement(info);
|
||||
return true; // always continue
|
||||
}
|
||||
|
||||
|
||||
@ -10,11 +10,11 @@ mixin Tapable on BaseComponent {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool onTapDown(TapDownInfo event) {
|
||||
bool onTapDown(TapDownInfo info) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool onTapUp(TapUpInfo event) {
|
||||
bool onTapUp(TapUpInfo info) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -22,18 +22,18 @@ mixin Tapable on BaseComponent {
|
||||
|
||||
bool _checkPointerId(int pointerId) => _currentPointerId == pointerId;
|
||||
|
||||
bool handleTapDown(int pointerId, TapDownInfo event) {
|
||||
if (containsPoint(event.eventPosition.game)) {
|
||||
bool handleTapDown(int pointerId, TapDownInfo info) {
|
||||
if (containsPoint(eventPosition(info))) {
|
||||
_currentPointerId = pointerId;
|
||||
return onTapDown(event);
|
||||
return onTapDown(info);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool handleTapUp(int pointerId, TapUpInfo event) {
|
||||
if (_checkPointerId(pointerId) && containsPoint(event.eventPosition.game)) {
|
||||
bool handleTapUp(int pointerId, TapUpInfo info) {
|
||||
if (_checkPointerId(pointerId) && containsPoint(eventPosition(info))) {
|
||||
_currentPointerId = null;
|
||||
return onTapUp(event);
|
||||
return onTapUp(info);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -69,12 +69,12 @@ mixin HasTapableComponents on BaseGame {
|
||||
}
|
||||
|
||||
@mustCallSuper
|
||||
void onTapDown(int pointerId, TapDownInfo event) {
|
||||
_handleTapEvent((Tapable child) => child.handleTapDown(pointerId, event));
|
||||
void onTapDown(int pointerId, TapDownInfo info) {
|
||||
_handleTapEvent((Tapable child) => child.handleTapDown(pointerId, info));
|
||||
}
|
||||
|
||||
@mustCallSuper
|
||||
void onTapUp(int pointerId, TapUpInfo event) {
|
||||
_handleTapEvent((Tapable child) => child.handleTapUp(pointerId, event));
|
||||
void onTapUp(int pointerId, TapUpInfo info) {
|
||||
_handleTapEvent((Tapable child) => child.handleTapUp(pointerId, info));
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,9 +4,9 @@ import 'events.dart';
|
||||
mixin MultiTouchTapDetector on Game {
|
||||
void onTap(int pointerId) {}
|
||||
void onTapCancel(int pointerId) {}
|
||||
void onTapDown(int pointerId, TapDownInfo event) {}
|
||||
void onTapUp(int pointerId, TapUpInfo event) {}
|
||||
void onLongTapDown(int pointerId, TapDownInfo event) {}
|
||||
void onTapDown(int pointerId, TapDownInfo info) {}
|
||||
void onTapUp(int pointerId, TapUpInfo info) {}
|
||||
void onLongTapDown(int pointerId, TapDownInfo info) {}
|
||||
}
|
||||
|
||||
mixin MultiTouchDragDetector on Game {
|
||||
@ -20,13 +20,13 @@ mixin MultiTouchDragDetector on Game {
|
||||
mixin TapDetector on Game {
|
||||
void onTap() {}
|
||||
void onTapCancel() {}
|
||||
void onTapDown(TapDownInfo event) {}
|
||||
void onTapUp(TapUpInfo event) {}
|
||||
void onTapDown(TapDownInfo info) {}
|
||||
void onTapUp(TapUpInfo info) {}
|
||||
}
|
||||
|
||||
mixin SecondaryTapDetector on Game {
|
||||
void onSecondaryTapDown(TapDownInfo event) {}
|
||||
void onSecondaryTapUp(TapUpInfo event) {}
|
||||
void onSecondaryTapDown(TapDownInfo info) {}
|
||||
void onSecondaryTapUp(TapUpInfo info) {}
|
||||
void onSecondaryTapCancel() {}
|
||||
}
|
||||
|
||||
@ -36,10 +36,10 @@ mixin DoubleTapDetector on Game {
|
||||
|
||||
mixin LongPressDetector on Game {
|
||||
void onLongPress() {}
|
||||
void onLongPressStart(LongPressStartInfo event) {}
|
||||
void onLongPressMoveUpdate(LongPressMoveUpdateInfo event) {}
|
||||
void onLongPressStart(LongPressStartInfo info) {}
|
||||
void onLongPressMoveUpdate(LongPressMoveUpdateInfo info) {}
|
||||
void onLongPressUp() {}
|
||||
void onLongPressEnd(LongPressEndInfo event) {}
|
||||
void onLongPressEnd(LongPressEndInfo info) {}
|
||||
}
|
||||
|
||||
mixin VerticalDragDetector on Game {
|
||||
@ -80,9 +80,9 @@ mixin ScaleDetector on Game {
|
||||
}
|
||||
|
||||
mixin MouseMovementDetector on Game {
|
||||
void onMouseMove(PointerHoverInfo event) {}
|
||||
void onMouseMove(PointerHoverInfo info) {}
|
||||
}
|
||||
|
||||
mixin ScrollDetector on Game {
|
||||
void onScroll(PointerScrollInfo event) {}
|
||||
void onScroll(PointerScrollInfo info) {}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ class DraggableComponent extends PositionComponent with Draggable {
|
||||
bool hasStartedDragging = false;
|
||||
|
||||
@override
|
||||
bool onDragStart(int pointerId, DragStartInfo event) {
|
||||
bool onDragStart(int pointerId, DragStartInfo info) {
|
||||
hasStartedDragging = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -16,12 +16,12 @@ class HoverableComponent extends PositionComponent with Hoverable {
|
||||
int leaveCount = 0;
|
||||
|
||||
@override
|
||||
void onHoverEnter(PointerHoverInfo event) {
|
||||
void onHoverEnter(PointerHoverInfo info) {
|
||||
enterCount++;
|
||||
}
|
||||
|
||||
@override
|
||||
void onHoverLeave(PointerHoverInfo event) {
|
||||
void onHoverLeave(PointerHoverInfo info) {
|
||||
leaveCount++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,14 +46,14 @@ class MyGame extends Game with TapDetector {
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapDown(TapDownInfo event) {
|
||||
void onTapDown(TapDownInfo info) {
|
||||
final buttonArea = buttonPosition & buttonSize;
|
||||
|
||||
isPressed = buttonArea.contains(event.eventPosition.game.toOffset());
|
||||
isPressed = buttonArea.contains(info.eventPosition.game.toOffset());
|
||||
}
|
||||
|
||||
@override
|
||||
void onTapUp(TapUpInfo event) {
|
||||
void onTapUp(TapUpInfo info) {
|
||||
isPressed = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user