From f1928f39f9d86dad6936640daf5ad169010bd4e6 Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Fri, 6 May 2022 10:32:42 +0200 Subject: [PATCH] feat: info screen ui --- lib/game/components/backbox/backbox.dart | 25 ++++++---------- .../backbox/displays/info_display.dart | 30 ++++++++++--------- lib/l10n/arb/app_en.arb | 28 +++++++++++++++++ 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/lib/game/components/backbox/backbox.dart b/lib/game/components/backbox/backbox.dart index ded61f5b..2102007b 100644 --- a/lib/game/components/backbox/backbox.dart +++ b/lib/game/components/backbox/backbox.dart @@ -53,6 +53,14 @@ class Backbox extends PositionComponent with ZIndex { if (state is LoadingState) { _display.add(LoadingDisplay()); } else if (state is InitialsFormState) { + _display.add( + InfoDisplay( + onShared: () { + //_bloc.add(ScoreShared()); + }, + ), + ); + /* _display.add( InitialsInputDisplay( score: state.score, @@ -68,6 +76,7 @@ class Backbox extends PositionComponent with ZIndex { }, ), ); + */ } else if (state is InitialsSuccessState) { _display.add(InitialsSubmissionSuccessDisplay()); } else if (state is InitialsFailureState) { @@ -87,22 +96,6 @@ class Backbox extends PositionComponent with ZIndex { ), ); } - - /// Puts [InfoDisplay] on the [Backbox]. - Future infoScreen({ - required int score, - required String characterIconPath, - ScoreOnShared? onShared, - }) async { - removeAll(children.where((child) => child is! _BackboxSpriteComponent)); - await add( - InfoDisplay( - score: score, - characterIconPath: characterIconPath, - onShared: onShared, - ), - ); - } } class _BackboxSpriteComponent extends SpriteComponent with HasGameRef { diff --git a/lib/game/components/backbox/displays/info_display.dart b/lib/game/components/backbox/displays/info_display.dart index 4edc404b..34e06658 100644 --- a/lib/game/components/backbox/displays/info_display.dart +++ b/lib/game/components/backbox/displays/info_display.dart @@ -3,12 +3,14 @@ import 'dart:async'; import 'package:flame/components.dart'; import 'package:flutter/material.dart'; import 'package:pinball/game/game.dart'; +import 'package:pinball/l10n/l10n.dart'; import 'package:pinball_components/pinball_components.dart'; +import 'package:pinball_flame/pinball_flame.dart'; import 'package:pinball_ui/pinball_ui.dart'; /// Signature for the callback called when the used has /// shared score on the [InfoDisplay]. -typedef ScoreOnShared = void Function(String); +typedef ScoreOnShared = void Function(); final _titleTextPaint = TextPaint( style: const TextStyle( @@ -52,8 +54,6 @@ final _descriptionTextPaint = TextPaint( class InfoDisplay extends Component with HasGameRef { /// {@macro info_display} InfoDisplay({ - required int score, - required String characterIconPath, ScoreOnShared? onShared, }) : _onShared = onShared, super( @@ -65,9 +65,15 @@ class InfoDisplay extends Component with HasGameRef { final ScoreOnShared? _onShared; bool _share() { - _onShared?.call(''); + _onShared?.call(); return true; } + + @override + Future onLoad() async { + await super.onLoad(); + gameRef.overlays.add(PinballGame.replayButtonOverlay); + } } class _InstructionsComponent extends PositionComponent with HasGameRef { @@ -108,8 +114,7 @@ class _ShareScoreTextComponent extends TextComponent @override Future onLoad() async { await super.onLoad(); - text = 'Share your score'; - //gameRef.l10n.shareYourScore; + text = readProvider().shareYourScore; } } @@ -125,8 +130,7 @@ class _ChallengeFriendsTextComponent extends TextComponent @override Future onLoad() async { await super.onLoad(); - text = 'AND CHALLENGE YOUR FRIENDS'; - //gameRef.l10n.challengeYourFriends; + text = readProvider().andChallengeYourFriends; } } @@ -171,7 +175,7 @@ class _ShareLinkComponent extends TextComponent with HasGameRef { @override Future onLoad() async { await super.onLoad(); - text = 'SHARE'; //gameRef.l10n.share; + text = readProvider().share; } } @@ -186,7 +190,7 @@ class _GotoIOLinkComponent extends TextComponent with HasGameRef { @override Future onLoad() async { await super.onLoad(); - text = 'GO TO I/O'; //gameRef.l10n.gotoIO; + text = readProvider().gotoIO; } } @@ -215,8 +219,7 @@ class _LearnMoreTextComponent extends TextComponent @override Future onLoad() async { await super.onLoad(); - text = 'Learn more about building games in Flutter with'; - //gameRef.l10n.learnMore; + text = readProvider().learnMore; } } @@ -232,7 +235,6 @@ class _LearnMore2TextComponent extends TextComponent @override Future onLoad() async { await super.onLoad(); - text = 'Firebase or dive right into the open source code.'; - //gameRef.l10n.learnMore2; + text = readProvider().firebaseOrOpenSource; } } diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index 03fde0bd..6cae5148 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -124,8 +124,36 @@ "@loading": { "description": "Text shown to indicate loading times" }, + "replay": "Replay", + "@replay": { + "description": "Text displayed on the share page for replay button" + }, "ioPinball": "I/O Pinball", "@ioPinball": { "description": "I/O Pinball - Name of the game" + }, + "shareYourScore": "Share your score", + "@shareYourScore": { + "description": "Text shown on title of info screen" + }, + "andChallengeYourFriends": "AND CHALLENGE YOUR FRIENDS", + "@challengeYourFriends": { + "description": "Text shown on title of info screen" + }, + "share": "SHARE", + "@share": { + "description": "Text for share link at info screen." + }, + "gotoIO": "GO TO I/O", + "@gotoIO": { + "description": "Text for going to I/O site link at info screen." + }, + "learnMore": "Learn more about building games in Flutter with", + "@learnMore": { + "description": "Text shown on description of info screen" + }, + "firebaseOrOpenSource": "Firebase or dive right into the open source code.", + "@firebaseOrOpenSource": { + "description": "Text shown on description of info screen" } }