From 181a135c07bbd7b44970981b0eef6e4f83fe96b4 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 6 Jul 2025 00:32:25 +0200 Subject: [PATCH 1/6] Implemented delete game button --- lib/data/game_manager.dart | 18 +++++++++ lib/l10n/app_de.arb | 4 +- lib/l10n/app_en.arb | 3 ++ lib/l10n/app_localizations.dart | 18 +++++++++ lib/l10n/app_localizations_de.dart | 10 +++++ lib/l10n/app_localizations_en.dart | 10 +++++ lib/views/active_game_view.dart | 62 +++++++++++++++++++++++++++++- pubspec.yaml | 2 +- 8 files changed, 123 insertions(+), 4 deletions(-) diff --git a/lib/data/game_manager.dart b/lib/data/game_manager.dart index 24c55da..ea18be7 100644 --- a/lib/data/game_manager.dart +++ b/lib/data/game_manager.dart @@ -42,9 +42,27 @@ class GameManager extends ChangeNotifier { removeGameSessionByIndex(index); } + /// Retrieves a game session by its ID. + /// Takes a String [id] as input. It finds the game session with the matching id bool gameExistsInGameList(String id) { return gameList.any((session) => session.id.toString() == id); } + + /// Ends a game session if its in unlimited mode. + /// Takes a String [id] as input. It finds the index of the game + /// session with the matching ID marks it as finished, + void endGame(String id) { + final int index = + gameList.indexWhere((session) => session.id.toString() == id); + + // Game session not found or not in unlimited mode + if (index == -1 || gameList[index].isPointsLimitEnabled == false) return; + + gameList[index].roundNumber--; + gameList[index].isGameFinished = true; + notifyListeners(); + LocalStorageService.saveGameSessions(); + } } final gameManager = GameManager(); diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 7fa3710..d300ab0 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -65,12 +65,14 @@ "next_round": "Nächste Runde", "statistics": "Statistiken", + "end_game": "Spiel beenden", "delete_game": "Spiel löschen", "new_game_same_settings": "Neues Spiel mit gleichen Einstellungen", "export_game": "Spiel exportieren", "id_error_title": "ID Fehler", "id_error_message": "Das Spiel hat bisher noch keine ID zugewiesen bekommen. Falls du das Spiel löschen möchtest, mache das bitte über das Hauptmenü. Alle neu erstellten Spiele haben eine ID.", - + "end_game_title": "Spiel beenden?", + "end_game_message": "Möchtest du das Spiel beenden? Das Spiel wird als beendet markiert und kann nicht forgeführt werden.", "game_process": "Spielverlauf", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index f8dbb2f..8b328ba 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -65,6 +65,7 @@ "next_round": "Next Round", "statistics": "Statistics", + "end_game": "End Game", "delete_game": "Delete Game", "new_game_same_settings": "New Game with same Settings", "export_game": "Export Game", @@ -82,6 +83,8 @@ "export_data": "Export Data", "id_error_title": "ID Error", "id_error_message": "The game has not yet been assigned an ID. If you want to delete the game, please do so via the main menu. All newly created games have an ID.", + "end_game_title": "End the game?", + "end_game_message": "Do you want to end the game? The game gets marked as finished and cannot be continued.", "import_success_title": "Import successful", "import_success_message":"The game data has been successfully imported.", diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index eb858f5..02e1d3c 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -368,6 +368,12 @@ abstract class AppLocalizations { /// **'Statistiken'** String get statistics; + /// No description provided for @end_game. + /// + /// In de, this message translates to: + /// **'Spiel beenden'** + String get end_game; + /// No description provided for @delete_game. /// /// In de, this message translates to: @@ -398,6 +404,18 @@ abstract class AppLocalizations { /// **'Das Spiel hat bisher noch keine ID zugewiesen bekommen. Falls du das Spiel löschen möchtest, mache das bitte über das Hauptmenü. Alle neu erstellten Spiele haben eine ID.'** String get id_error_message; + /// No description provided for @end_game_title. + /// + /// In de, this message translates to: + /// **'Spiel beenden?'** + String get end_game_title; + + /// No description provided for @end_game_message. + /// + /// In de, this message translates to: + /// **'Möchtest du das Spiel beenden? Das Spiel wird als beendet markiert und kann nicht forgeführt werden.'** + String get end_game_message; + /// No description provided for @game_process. /// /// In de, this message translates to: diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index f72adbb..1b91ed4 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -152,6 +152,9 @@ class AppLocalizationsDe extends AppLocalizations { @override String get statistics => 'Statistiken'; + @override + String get end_game => 'Spiel beenden'; + @override String get delete_game => 'Spiel löschen'; @@ -168,6 +171,13 @@ class AppLocalizationsDe extends AppLocalizations { String get id_error_message => 'Das Spiel hat bisher noch keine ID zugewiesen bekommen. Falls du das Spiel löschen möchtest, mache das bitte über das Hauptmenü. Alle neu erstellten Spiele haben eine ID.'; + @override + String get end_game_title => 'Spiel beenden?'; + + @override + String get end_game_message => + 'Möchtest du das Spiel beenden? Das Spiel wird als beendet markiert und kann nicht forgeführt werden.'; + @override String get game_process => 'Spielverlauf'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 657f2ce..c98dddd 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -149,6 +149,9 @@ class AppLocalizationsEn extends AppLocalizations { @override String get statistics => 'Statistics'; + @override + String get end_game => 'End Game'; + @override String get delete_game => 'Delete Game'; @@ -165,6 +168,13 @@ class AppLocalizationsEn extends AppLocalizations { String get id_error_message => 'The game has not yet been assigned an ID. If you want to delete the game, please do so via the main menu. All newly created games have an ID.'; + @override + String get end_game_title => 'End the game?'; + + @override + String get end_game_message => + 'Do you want to end the game? The game gets marked as finished and cannot be continued.'; + @override String get game_process => 'Spielverlauf'; diff --git a/lib/views/active_game_view.dart b/lib/views/active_game_view.dart index 1b5e546..dc0e078 100644 --- a/lib/views/active_game_view.dart +++ b/lib/views/active_game_view.dart @@ -129,21 +129,40 @@ class _ActiveGameViewState extends State { Column( children: [ CupertinoListTile( - backgroundColorActivated: - CustomTheme.backgroundColor, title: Text( AppLocalizations.of(context).statistics, ), + backgroundColorActivated: + CustomTheme.backgroundColor, onTap: () => Navigator.push( context, CupertinoPageRoute( builder: (_) => GraphView( gameSession: gameSession, )))), + if (!gameSession.isPointsLimitEnabled) + CupertinoListTile( + title: Text( + AppLocalizations.of(context).end_game, + style: gameSession.roundNumber > 1 && + !gameSession.isGameFinished + ? const TextStyle(color: Colors.white) + : const TextStyle(color: Colors.white30), + ), + backgroundColorActivated: + CustomTheme.backgroundColor, + onTap: () => { + gameSession.roundNumber > 1 && + !gameSession.isGameFinished + ? _showEndGameDialog() + : null + }), CupertinoListTile( title: Text( AppLocalizations.of(context).delete_game, ), + backgroundColorActivated: + CustomTheme.backgroundColor, onTap: () { _showDeleteGameDialog().then((value) { if (value) { @@ -157,6 +176,8 @@ class _ActiveGameViewState extends State { AppLocalizations.of(context) .new_game_same_settings, ), + backgroundColorActivated: + CustomTheme.backgroundColor, onTap: () { Navigator.pushReplacement( context, @@ -176,6 +197,8 @@ class _ActiveGameViewState extends State { style: const TextStyle( color: Colors.white30, )), + backgroundColorActivated: + CustomTheme.backgroundColor, ), ], ) @@ -186,6 +209,41 @@ class _ActiveGameViewState extends State { }); } + /// Shows a dialog to confirm ending the game. + /// If the user confirms, it calls the `endGame` method on the game manager + void _showEndGameDialog() { + showCupertinoDialog( + context: context, + builder: (BuildContext context) { + return CupertinoAlertDialog( + title: Text(AppLocalizations.of(context).end_game_title), + content: Text(AppLocalizations.of(context).end_game_message), + actions: [ + CupertinoDialogAction( + child: Text( + AppLocalizations.of(context).end_game, + style: const TextStyle( + fontWeight: FontWeight.bold, color: Colors.red), + ), + onPressed: () { + setState(() { + gameSession.isGameFinished = true; + gameSession.roundNumber--; + gameManager.endGame(gameSession.id); + }); + Navigator.pop(context); + }, + ), + CupertinoDialogAction( + child: Text(AppLocalizations.of(context).cancel), + onPressed: () => Navigator.pop(context), + ), + ], + ); + }, + ); + } + /// Returns a list of player indices sorted by their scores in /// ascending order. List _getSortedPlayerIndices() { diff --git a/pubspec.yaml b/pubspec.yaml index 56b89bc..e3b4a67 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.3.6+318 +version: 0.3.6+322 environment: sdk: ^3.5.4 From aa338451130f25ce99dce315f9e3b921b16bae4a Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 6 Jul 2025 00:35:17 +0200 Subject: [PATCH 2/6] Updated version number --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index e3b4a67..e9ef18c 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.3.6+322 +version: 0.3.7+322 environment: sdk: ^3.5.4 From 003e80c6ff2af03070311764109b96989b66ab25 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 6 Jul 2025 00:39:55 +0200 Subject: [PATCH 3/6] Updated onTap Handler --- lib/views/active_game_view.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/views/active_game_view.dart b/lib/views/active_game_view.dart index dc0e078..aaea85d 100644 --- a/lib/views/active_game_view.dart +++ b/lib/views/active_game_view.dart @@ -151,12 +151,12 @@ class _ActiveGameViewState extends State { ), backgroundColorActivated: CustomTheme.backgroundColor, - onTap: () => { - gameSession.roundNumber > 1 && - !gameSession.isGameFinished - ? _showEndGameDialog() - : null - }), + onTap: () { + if (gameSession.roundNumber > 1 && + !gameSession.isGameFinished) { + _showEndGameDialog(); + } + }), CupertinoListTile( title: Text( AppLocalizations.of(context).delete_game, From 554f6e243c2cd70b8f8e6328ea339bc61f2420c4 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 6 Jul 2025 00:41:26 +0200 Subject: [PATCH 4/6] Updated typo --- lib/l10n/app_de.arb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index d300ab0..9281ac1 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -72,7 +72,7 @@ "id_error_title": "ID Fehler", "id_error_message": "Das Spiel hat bisher noch keine ID zugewiesen bekommen. Falls du das Spiel löschen möchtest, mache das bitte über das Hauptmenü. Alle neu erstellten Spiele haben eine ID.", "end_game_title": "Spiel beenden?", - "end_game_message": "Möchtest du das Spiel beenden? Das Spiel wird als beendet markiert und kann nicht forgeführt werden.", + "end_game_message": "Möchtest du das Spiel beenden? Das Spiel wird als beendet markiert und kann nicht fortgeführt werden.", "game_process": "Spielverlauf", From 32aa2e607062f52007c8cbcd86faa3021a29be68 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 6 Jul 2025 00:43:32 +0200 Subject: [PATCH 5/6] Updated endGame method --- lib/data/game_manager.dart | 2 +- lib/views/active_game_view.dart | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/data/game_manager.dart b/lib/data/game_manager.dart index ea18be7..b3a1933 100644 --- a/lib/data/game_manager.dart +++ b/lib/data/game_manager.dart @@ -56,7 +56,7 @@ class GameManager extends ChangeNotifier { gameList.indexWhere((session) => session.id.toString() == id); // Game session not found or not in unlimited mode - if (index == -1 || gameList[index].isPointsLimitEnabled == false) return; + if (index == -1 || gameList[index].isPointsLimitEnabled == true) return; gameList[index].roundNumber--; gameList[index].isGameFinished = true; diff --git a/lib/views/active_game_view.dart b/lib/views/active_game_view.dart index aaea85d..586eab3 100644 --- a/lib/views/active_game_view.dart +++ b/lib/views/active_game_view.dart @@ -227,8 +227,6 @@ class _ActiveGameViewState extends State { ), onPressed: () { setState(() { - gameSession.isGameFinished = true; - gameSession.roundNumber--; gameManager.endGame(gameSession.id); }); Navigator.pop(context); From 6f340a0d3917dd94ff5fa5f1b43e48ebf072a7e0 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 6 Jul 2025 00:43:42 +0200 Subject: [PATCH 6/6] Updated localization --- lib/l10n/app_localizations.dart | 2 +- lib/l10n/app_localizations_de.dart | 2 +- pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index 02e1d3c..c836194 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -413,7 +413,7 @@ abstract class AppLocalizations { /// No description provided for @end_game_message. /// /// In de, this message translates to: - /// **'Möchtest du das Spiel beenden? Das Spiel wird als beendet markiert und kann nicht forgeführt werden.'** + /// **'Möchtest du das Spiel beenden? Das Spiel wird als beendet markiert und kann nicht fortgeführt werden.'** String get end_game_message; /// No description provided for @game_process. diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 1b91ed4..5b9d841 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -176,7 +176,7 @@ class AppLocalizationsDe extends AppLocalizations { @override String get end_game_message => - 'Möchtest du das Spiel beenden? Das Spiel wird als beendet markiert und kann nicht forgeführt werden.'; + 'Möchtest du das Spiel beenden? Das Spiel wird als beendet markiert und kann nicht fortgeführt werden.'; @override String get game_process => 'Spielverlauf'; diff --git a/pubspec.yaml b/pubspec.yaml index e9ef18c..160097c 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.3.7+322 +version: 0.3.7+323 environment: sdk: ^3.5.4