diff --git a/lib/l10n/arb/app_de.arb b/lib/l10n/arb/app_de.arb index 399aefd..dceb8fc 100644 --- a/lib/l10n/arb/app_de.arb +++ b/lib/l10n/arb/app_de.arb @@ -71,6 +71,7 @@ "results": "Ergebnisse", "who_said_cabo": "Wer hat CABO gesagt?", "kamikaze": "Kamikaze", + "who_has_kamikaze": "Wer hat Kamikaze?", "done": "Fertig", "next_round": "Nächste Runde", "bonus_points_title": "Bonus-Punkte!", diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index 3b6150a..3009d6e 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -71,6 +71,7 @@ "results": "Results", "who_said_cabo": "Who called Cabo?", "kamikaze": "Kamikaze", + "who_has_kamikaze": "Who has Kamikaze?", "done": "Done", "next_round": "Next Round", "bonus_points_title": "Bonus-Points!", diff --git a/lib/l10n/generated/app_localizations.dart b/lib/l10n/generated/app_localizations.dart index 7ce3c52..695fb57 100644 --- a/lib/l10n/generated/app_localizations.dart +++ b/lib/l10n/generated/app_localizations.dart @@ -404,6 +404,12 @@ abstract class AppLocalizations { /// **'Kamikaze'** String get kamikaze; + /// No description provided for @who_has_kamikaze. + /// + /// In de, this message translates to: + /// **'Wer hat Kamikaze?'** + String get who_has_kamikaze; + /// No description provided for @done. /// /// In de, this message translates to: diff --git a/lib/l10n/generated/app_localizations_de.dart b/lib/l10n/generated/app_localizations_de.dart index 6539c20..3ef54b8 100644 --- a/lib/l10n/generated/app_localizations_de.dart +++ b/lib/l10n/generated/app_localizations_de.dart @@ -172,6 +172,9 @@ class AppLocalizationsDe extends AppLocalizations { @override String get kamikaze => 'Kamikaze'; + @override + String get who_has_kamikaze => 'Wer hat Kamikaze?'; + @override String get done => 'Fertig'; diff --git a/lib/l10n/generated/app_localizations_en.dart b/lib/l10n/generated/app_localizations_en.dart index 7e026f6..8a86b95 100644 --- a/lib/l10n/generated/app_localizations_en.dart +++ b/lib/l10n/generated/app_localizations_en.dart @@ -170,6 +170,9 @@ class AppLocalizationsEn extends AppLocalizations { @override String get kamikaze => 'Kamikaze'; + @override + String get who_has_kamikaze => 'Who has Kamikaze?'; + @override String get done => 'Done'; diff --git a/lib/presentation/views/round_view.dart b/lib/presentation/views/round_view.dart index 9e2b40f..45834e4 100644 --- a/lib/presentation/views/round_view.dart +++ b/lib/presentation/views/round_view.dart @@ -154,6 +154,17 @@ class _RoundViewState extends State { ), ), ), + Center( + child: CupertinoButton( + onPressed: () async { + if (await _showKamikazeSheet(context)) { + if (!context.mounted) return; + _endOfRoundNavigation(context, true); + } + }, + child: Text(AppLocalizations.of(context).kamikaze), + ), + ), Padding( padding: const EdgeInsets.symmetric(horizontal: 20.0), child: CupertinoListTile( @@ -308,15 +319,8 @@ class _RoundViewState extends State { children: [ CupertinoButton( onPressed: _areRoundInputsValid() - ? () async { - List bonusPlayersIndices = _finishRound(); - if (bonusPlayersIndices.isNotEmpty) { - await _showBonusPopup( - context, bonusPlayersIndices); - } - LocalStorageService.saveGameSessions(); - if (!context.mounted) return; - Navigator.pop(context); + ? () { + _endOfRoundNavigation(context, false); } : null, child: Text(AppLocalizations.of(context).done), @@ -324,21 +328,8 @@ class _RoundViewState extends State { if (!widget.gameSession.isGameFinished) CupertinoButton( onPressed: _areRoundInputsValid() - ? () async { - List bonusPlayersIndices = - _finishRound(); - if (bonusPlayersIndices.isNotEmpty) { - await _showBonusPopup( - context, bonusPlayersIndices); - } - LocalStorageService.saveGameSessions(); - if (widget.gameSession.isGameFinished && - context.mounted) { - Navigator.pop(context); - } else if (context.mounted) { - Navigator.pop( - context, widget.roundNumber + 1); - } + ? () { + _endOfRoundNavigation(context, true); } : null, child: Text(AppLocalizations.of(context).next_round), @@ -401,6 +392,36 @@ class _RoundViewState extends State { ]; } + Future _showKamikazeSheet(BuildContext context) async { + return await showCupertinoModalPopup( + context: context, + builder: (BuildContext context) { + return CupertinoActionSheet( + title: Text(AppLocalizations.of(context).kamikaze), + message: Text(AppLocalizations.of(context).who_has_kamikaze), + actions: widget.gameSession.players.asMap().entries.map((entry) { + final index = entry.key; + final name = entry.value; + return CupertinoActionSheetAction( + onPressed: () { + _kamikazePlayerIndex = + _kamikazePlayerIndex == index ? null : index; + Navigator.pop(context, true); + }, + child: Text(name), + ); + }).toList(), + cancelButton: CupertinoActionSheetAction( + onPressed: () => Navigator.pop(context, false), + isDestructiveAction: true, + child: Text(AppLocalizations.of(context).cancel), + ), + ); + }, + ) ?? + false; + } + /// Focuses the next text field in the list of text fields. /// [index] is the index of the current text field. void _focusNextTextfield(int index) { @@ -521,6 +542,30 @@ class _RoundViewState extends State { return resultText; } + /// Handles the navigation for the end of the round. + /// It checks for bonus players and shows a popup, saves the game session, + /// and navigates to the next round or back to the previous screen. + /// It takes the BuildContext [context] and a boolean [navigateToNextRound] to determine + /// if it should navigate to the next round or not. + Future _endOfRoundNavigation( + BuildContext context, bool navigateToNextRound) async { + List bonusPlayersIndices = _finishRound(); + if (bonusPlayersIndices.isNotEmpty) { + await _showBonusPopup(context, bonusPlayersIndices); + } + + LocalStorageService.saveGameSessions(); + + if (context.mounted) { + if (!navigateToNextRound || widget.gameSession.isGameFinished) { + Navigator.pop(context); + return; + } else { + Navigator.pop(context, widget.roundNumber + 1); + } + } + } + @override void dispose() { for (final controller in _scoreControllerList) { diff --git a/pubspec.yaml b/pubspec.yaml index 7f8483c..4a2e99d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: cabo_counter description: "Mobile app for the card game Cabo" publish_to: 'none' -version: 0.4.8+525 +version: 0.4.8+526 environment: sdk: ^3.5.4