mirror of https://github.com/flutter/pinball.git
parent
a55fec26e4
commit
72f8b6c5a4
@ -0,0 +1,51 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pinball/game/game.dart';
|
||||||
|
import 'package:pinball_ui/pinball_ui.dart';
|
||||||
|
|
||||||
|
/// {@template mobile_controls}
|
||||||
|
/// Widget with the controls used to enable the user initials input on mobile.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class MobileControls extends StatelessWidget {
|
||||||
|
/// {@macro mobile_controls}
|
||||||
|
const MobileControls({Key? key,
|
||||||
|
required this.onTapUp,
|
||||||
|
required this.onTapDown,
|
||||||
|
required this.onTapLeft,
|
||||||
|
required this.onTapRight,
|
||||||
|
required this.onTapEnter,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
/// Called when dpad up is pressed
|
||||||
|
final VoidCallback onTapUp;
|
||||||
|
|
||||||
|
/// Called when dpad down is pressed
|
||||||
|
final VoidCallback onTapDown;
|
||||||
|
|
||||||
|
/// Called when dpad left is pressed
|
||||||
|
final VoidCallback onTapLeft;
|
||||||
|
|
||||||
|
/// Called when dpad right is pressed
|
||||||
|
final VoidCallback onTapRight;
|
||||||
|
|
||||||
|
/// Called when enter is pressed
|
||||||
|
final VoidCallback onTapEnter;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [
|
||||||
|
MobileDpad(
|
||||||
|
onTapUp: onTapUp,
|
||||||
|
onTapDown: onTapUp,
|
||||||
|
onTapLeft: onTapLeft,
|
||||||
|
onTapRight: onTapRight,
|
||||||
|
),
|
||||||
|
PinballButton(
|
||||||
|
text: 'Enter', // TODO l10n
|
||||||
|
onTap: onTapEnter,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pinball_ui/pinball_ui.dart';
|
||||||
|
|
||||||
|
/// {@template mobile_dpad}
|
||||||
|
/// Widget that renders a 4 direction dpad.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class MobileDpad extends StatelessWidget {
|
||||||
|
/// {@template mobile_dpad}
|
||||||
|
const MobileDpad({
|
||||||
|
Key? key,
|
||||||
|
required this.onTapUp,
|
||||||
|
required this.onTapDown,
|
||||||
|
required this.onTapLeft,
|
||||||
|
required this.onTapRight,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
static const _size = 180.0;
|
||||||
|
|
||||||
|
/// Called when dpad up is pressed
|
||||||
|
final VoidCallback onTapUp;
|
||||||
|
|
||||||
|
/// Called when dpad down is pressed
|
||||||
|
final VoidCallback onTapDown;
|
||||||
|
|
||||||
|
/// Called when dpad left is pressed
|
||||||
|
final VoidCallback onTapLeft;
|
||||||
|
|
||||||
|
/// Called when dpad right is pressed
|
||||||
|
final VoidCallback onTapRight;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
width: _size,
|
||||||
|
height: _size,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Expanded(child: SizedBox()),
|
||||||
|
PinballDpadButton(
|
||||||
|
direction: PinballDpadDirection.up,
|
||||||
|
onTap: onTapUp,
|
||||||
|
),
|
||||||
|
const Expanded(child: SizedBox()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
PinballDpadButton(
|
||||||
|
direction: PinballDpadDirection.left,
|
||||||
|
onTap: onTapLeft,
|
||||||
|
),
|
||||||
|
const Expanded(child: SizedBox()),
|
||||||
|
PinballDpadButton(
|
||||||
|
direction: PinballDpadDirection.right,
|
||||||
|
onTap: onTapRight,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
const Expanded(child: SizedBox()),
|
||||||
|
PinballDpadButton(
|
||||||
|
direction: PinballDpadDirection.down,
|
||||||
|
onTap: onTapDown,
|
||||||
|
),
|
||||||
|
const Expanded(child: SizedBox()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
export 'bonus_animation.dart';
|
export 'bonus_animation.dart';
|
||||||
export 'game_hud.dart';
|
export 'game_hud.dart';
|
||||||
|
export 'mobile_controls.dart';
|
||||||
|
export 'mobile_dpad.dart';
|
||||||
export 'play_button_overlay.dart';
|
export 'play_button_overlay.dart';
|
||||||
export 'round_count_display.dart';
|
export 'round_count_display.dart';
|
||||||
export 'score_view.dart';
|
export 'score_view.dart';
|
||||||
|
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.8 KiB |
@ -0,0 +1,66 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pinball_ui/gen/gen.dart';
|
||||||
|
import 'package:pinball_ui/pinball_ui.dart';
|
||||||
|
|
||||||
|
/// Enum with all possibile directions of a [PinballDpadButton].
|
||||||
|
enum PinballDpadDirection {
|
||||||
|
/// Up
|
||||||
|
up,
|
||||||
|
|
||||||
|
/// Down
|
||||||
|
down,
|
||||||
|
|
||||||
|
/// Left
|
||||||
|
left,
|
||||||
|
|
||||||
|
/// Right
|
||||||
|
right,
|
||||||
|
}
|
||||||
|
|
||||||
|
extension _PinballDpadDirectionX on PinballDpadDirection {
|
||||||
|
String toAsset() {
|
||||||
|
switch (this) {
|
||||||
|
case PinballDpadDirection.up:
|
||||||
|
return Assets.images.button.dpadUp.keyName;
|
||||||
|
case PinballDpadDirection.down:
|
||||||
|
return Assets.images.button.dpadDown.keyName;
|
||||||
|
case PinballDpadDirection.left:
|
||||||
|
return Assets.images.button.dpadLeft.keyName;
|
||||||
|
case PinballDpadDirection.right:
|
||||||
|
return Assets.images.button.dpadRight.keyName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// {@template pinball_dpad_button}
|
||||||
|
/// Widget that renders a Dpad button with a given direction.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class PinballDpadButton extends StatelessWidget {
|
||||||
|
/// {@macro pinball_dpad_button}
|
||||||
|
const PinballDpadButton({
|
||||||
|
Key? key,
|
||||||
|
required this.direction,
|
||||||
|
required this.onTap,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
/// Which [PinballDpadDirection] this button is.
|
||||||
|
final PinballDpadDirection direction;
|
||||||
|
|
||||||
|
/// The function executed when the button is pressed.
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Material(
|
||||||
|
color: PinballColors.transparent,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
child: Image.asset(
|
||||||
|
direction.toAsset(),
|
||||||
|
width: 60,
|
||||||
|
height: 60,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
export 'animated_ellipsis_text.dart';
|
export 'animated_ellipsis_text.dart';
|
||||||
export 'crt_background.dart';
|
export 'crt_background.dart';
|
||||||
export 'pinball_button.dart';
|
export 'pinball_button.dart';
|
||||||
|
export 'pinball_dpad.dart';
|
||||||
export 'pinball_loading_indicator.dart';
|
export 'pinball_loading_indicator.dart';
|
||||||
|
Loading…
Reference in new issue