Implemented delete game button

This commit is contained in:
2025-07-06 00:32:25 +02:00
parent ab1e51f0b8
commit 181a135c07
8 changed files with 123 additions and 4 deletions

View File

@@ -129,21 +129,40 @@ class _ActiveGameViewState extends State<ActiveGameView> {
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<ActiveGameView> {
AppLocalizations.of(context)
.new_game_same_settings,
),
backgroundColorActivated:
CustomTheme.backgroundColor,
onTap: () {
Navigator.pushReplacement(
context,
@@ -176,6 +197,8 @@ class _ActiveGameViewState extends State<ActiveGameView> {
style: const TextStyle(
color: Colors.white30,
)),
backgroundColorActivated:
CustomTheme.backgroundColor,
),
],
)
@@ -186,6 +209,41 @@ class _ActiveGameViewState extends State<ActiveGameView> {
});
}
/// 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<int> _getSortedPlayerIndices() {