diff --git a/lib/views/active_game_view.dart b/lib/views/active_game_view.dart index 6266348..d4ff7bd 100644 --- a/lib/views/active_game_view.dart +++ b/lib/views/active_game_view.dart @@ -1,6 +1,7 @@ import 'package:cabo_counter/data/game_session.dart'; import 'package:cabo_counter/l10n/app_localizations.dart'; import 'package:cabo_counter/utility/custom_theme.dart'; +import 'package:cabo_counter/views/create_game_view.dart'; import 'package:cabo_counter/views/graph_view.dart'; import 'package:cabo_counter/views/round_view.dart'; import 'package:flutter/cupertino.dart'; @@ -141,12 +142,24 @@ class _ActiveGameViewState extends State { onTap: () {}, ), CupertinoListTile( - title: Text( - AppLocalizations.of(context) - .new_game_same_settings, - style: const TextStyle( - color: Colors.white30, - ))), + title: Text( + AppLocalizations.of(context) + .new_game_same_settings, + ), + onTap: () { + Navigator.pushReplacement( + context, + CupertinoPageRoute( + builder: (_) => CreateGameView( + gameTitle: + widget.gameSession.gameTitle, + isPointsLimitEnabled: widget + .gameSession + .isPointsLimitEnabled, + players: widget.gameSession.players, + ))); + }, + ), CupertinoListTile( title: Text(AppLocalizations.of(context).export_game, diff --git a/lib/views/create_game_view.dart b/lib/views/create_game_view.dart index adcbf86..6c52890 100644 --- a/lib/views/create_game_view.dart +++ b/lib/views/create_game_view.dart @@ -7,15 +7,24 @@ import 'package:cabo_counter/views/active_game_view.dart'; import 'package:cabo_counter/views/mode_selection_view.dart'; import 'package:flutter/cupertino.dart'; -class CreateGame extends StatefulWidget { - const CreateGame({super.key}); +class CreateGameView extends StatefulWidget { + final String? gameTitle; + final bool? isPointsLimitEnabled; + final List? players; + + const CreateGameView({ + super.key, + this.gameTitle, + this.isPointsLimitEnabled, + this.players, + }); @override // ignore: library_private_types_in_public_api - _CreateGameState createState() => _CreateGameState(); + _CreateGameViewState createState() => _CreateGameViewState(); } -class _CreateGameState extends State { +class _CreateGameViewState extends State { final List _playerNameTextControllers = [ TextEditingController() ]; @@ -25,8 +34,23 @@ class _CreateGameState extends State { /// Maximum number of players allowed in the game. final int maxPlayers = 5; - /// Variable to store the selected game mode. - bool? selectedMode; + /// Variable to store whether the points limit feature is enabled. + bool? _isPointsLimitEnabled; + + @override + void initState() { + super.initState(); + + _isPointsLimitEnabled = widget.isPointsLimitEnabled; + _gameTitleTextController.text = widget.gameTitle ?? ''; + + if (widget.players != null) { + _playerNameTextControllers.clear(); + for (var player in widget.players!) { + _playerNameTextControllers.add(TextEditingController(text: player)); + } + } + } @override Widget build(BuildContext context) { @@ -69,9 +93,9 @@ class _CreateGameState extends State { suffix: Row( children: [ Text( - selectedMode == null + _isPointsLimitEnabled == null ? AppLocalizations.of(context).select_mode - : (selectedMode! + : (_isPointsLimitEnabled! ? '${Globals.pointLimit} ${AppLocalizations.of(context).points}' : AppLocalizations.of(context).unlimited), ), @@ -80,7 +104,7 @@ class _CreateGameState extends State { ], ), onTap: () async { - final selected = await Navigator.push( + final selectedMode = await Navigator.push( context, CupertinoPageRoute( builder: (context) => ModeSelectionMenu( @@ -89,9 +113,9 @@ class _CreateGameState extends State { ), ); - if (selected != null) { + if (selectedMode != null) { setState(() { - selectedMode = selected; + _isPointsLimitEnabled = selectedMode; }); } }, @@ -230,7 +254,7 @@ class _CreateGameState extends State { ); return; } - if (selectedMode == null) { + if (_isPointsLimitEnabled == null) { showCupertinoDialog( context: context, builder: (context) => CupertinoAlertDialog( @@ -293,7 +317,7 @@ class _CreateGameState extends State { players: players, pointLimit: Globals.pointLimit, caboPenalty: Globals.caboPenalty, - isPointsLimitEnabled: selectedMode!, + isPointsLimitEnabled: _isPointsLimitEnabled!, ); final index = await gameManager.addGameSession(gameSession); if (context.mounted) { @@ -321,9 +345,11 @@ class _CreateGameState extends State { @override void dispose() { + _gameTitleTextController.dispose(); for (var controller in _playerNameTextControllers) { controller.dispose(); } + super.dispose(); } } diff --git a/lib/views/main_menu_view.dart b/lib/views/main_menu_view.dart index ab52d4e..f41a0ef 100644 --- a/lib/views/main_menu_view.dart +++ b/lib/views/main_menu_view.dart @@ -61,7 +61,7 @@ class _MainMenuViewState extends State { Navigator.push( context, CupertinoPageRoute( - builder: (context) => const CreateGame(), + builder: (context) => const CreateGameView(), ), ) }, @@ -82,7 +82,8 @@ class _MainMenuViewState extends State { onTap: () => Navigator.push( context, CupertinoPageRoute( - builder: (context) => const CreateGame(), + builder: (context) => + const CreateGameView(), ), ), child: Icon( diff --git a/pubspec.yaml b/pubspec.yaml index af1107f..a7c91ae 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.4+267 +version: 0.3.5+269 environment: sdk: ^3.5.4