Merge pull request #75 from flixcoo/feature/63-implement-new-game-with-same-settings-button-in-activegameview
Implemented new game same settings features
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import 'package:cabo_counter/data/game_session.dart';
|
import 'package:cabo_counter/data/game_session.dart';
|
||||||
import 'package:cabo_counter/l10n/app_localizations.dart';
|
import 'package:cabo_counter/l10n/app_localizations.dart';
|
||||||
import 'package:cabo_counter/utility/custom_theme.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/graph_view.dart';
|
||||||
import 'package:cabo_counter/views/round_view.dart';
|
import 'package:cabo_counter/views/round_view.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
@@ -141,12 +142,24 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
onTap: () {},
|
onTap: () {},
|
||||||
),
|
),
|
||||||
CupertinoListTile(
|
CupertinoListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
AppLocalizations.of(context)
|
AppLocalizations.of(context)
|
||||||
.new_game_same_settings,
|
.new_game_same_settings,
|
||||||
style: const TextStyle(
|
),
|
||||||
color: Colors.white30,
|
onTap: () {
|
||||||
))),
|
Navigator.pushReplacement(
|
||||||
|
context,
|
||||||
|
CupertinoPageRoute(
|
||||||
|
builder: (_) => CreateGameView(
|
||||||
|
gameTitle:
|
||||||
|
widget.gameSession.gameTitle,
|
||||||
|
isPointsLimitEnabled: widget
|
||||||
|
.gameSession
|
||||||
|
.isPointsLimitEnabled,
|
||||||
|
players: widget.gameSession.players,
|
||||||
|
)));
|
||||||
|
},
|
||||||
|
),
|
||||||
CupertinoListTile(
|
CupertinoListTile(
|
||||||
title:
|
title:
|
||||||
Text(AppLocalizations.of(context).export_game,
|
Text(AppLocalizations.of(context).export_game,
|
||||||
|
|||||||
@@ -7,15 +7,24 @@ import 'package:cabo_counter/views/active_game_view.dart';
|
|||||||
import 'package:cabo_counter/views/mode_selection_view.dart';
|
import 'package:cabo_counter/views/mode_selection_view.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
class CreateGame extends StatefulWidget {
|
class CreateGameView extends StatefulWidget {
|
||||||
const CreateGame({super.key});
|
final String? gameTitle;
|
||||||
|
final bool? isPointsLimitEnabled;
|
||||||
|
final List<String>? players;
|
||||||
|
|
||||||
|
const CreateGameView({
|
||||||
|
super.key,
|
||||||
|
this.gameTitle,
|
||||||
|
this.isPointsLimitEnabled,
|
||||||
|
this.players,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
// ignore: library_private_types_in_public_api
|
// ignore: library_private_types_in_public_api
|
||||||
_CreateGameState createState() => _CreateGameState();
|
_CreateGameViewState createState() => _CreateGameViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CreateGameState extends State<CreateGame> {
|
class _CreateGameViewState extends State<CreateGameView> {
|
||||||
final List<TextEditingController> _playerNameTextControllers = [
|
final List<TextEditingController> _playerNameTextControllers = [
|
||||||
TextEditingController()
|
TextEditingController()
|
||||||
];
|
];
|
||||||
@@ -25,8 +34,23 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
/// Maximum number of players allowed in the game.
|
/// Maximum number of players allowed in the game.
|
||||||
final int maxPlayers = 5;
|
final int maxPlayers = 5;
|
||||||
|
|
||||||
/// Variable to store the selected game mode.
|
/// Variable to store whether the points limit feature is enabled.
|
||||||
bool? selectedMode;
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -69,9 +93,9 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
suffix: Row(
|
suffix: Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
selectedMode == null
|
_isPointsLimitEnabled == null
|
||||||
? AppLocalizations.of(context).select_mode
|
? AppLocalizations.of(context).select_mode
|
||||||
: (selectedMode!
|
: (_isPointsLimitEnabled!
|
||||||
? '${Globals.pointLimit} ${AppLocalizations.of(context).points}'
|
? '${Globals.pointLimit} ${AppLocalizations.of(context).points}'
|
||||||
: AppLocalizations.of(context).unlimited),
|
: AppLocalizations.of(context).unlimited),
|
||||||
),
|
),
|
||||||
@@ -80,7 +104,7 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final selected = await Navigator.push(
|
final selectedMode = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => ModeSelectionMenu(
|
builder: (context) => ModeSelectionMenu(
|
||||||
@@ -89,9 +113,9 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (selected != null) {
|
if (selectedMode != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedMode = selected;
|
_isPointsLimitEnabled = selectedMode;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -230,7 +254,7 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (selectedMode == null) {
|
if (_isPointsLimitEnabled == null) {
|
||||||
showCupertinoDialog(
|
showCupertinoDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => CupertinoAlertDialog(
|
builder: (context) => CupertinoAlertDialog(
|
||||||
@@ -293,7 +317,7 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
players: players,
|
players: players,
|
||||||
pointLimit: Globals.pointLimit,
|
pointLimit: Globals.pointLimit,
|
||||||
caboPenalty: Globals.caboPenalty,
|
caboPenalty: Globals.caboPenalty,
|
||||||
isPointsLimitEnabled: selectedMode!,
|
isPointsLimitEnabled: _isPointsLimitEnabled!,
|
||||||
);
|
);
|
||||||
final index = await gameManager.addGameSession(gameSession);
|
final index = await gameManager.addGameSession(gameSession);
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
@@ -321,9 +345,11 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_gameTitleTextController.dispose();
|
||||||
for (var controller in _playerNameTextControllers) {
|
for (var controller in _playerNameTextControllers) {
|
||||||
controller.dispose();
|
controller.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => const CreateGame(),
|
builder: (context) => const CreateGameView(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -82,7 +82,8 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
onTap: () => Navigator.push(
|
onTap: () => Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => const CreateGame(),
|
builder: (context) =>
|
||||||
|
const CreateGameView(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Icon(
|
child: Icon(
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ name: cabo_counter
|
|||||||
description: "Mobile app for the card game Cabo"
|
description: "Mobile app for the card game Cabo"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 0.3.4+267
|
version: 0.3.5+269
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.4
|
sdk: ^3.5.4
|
||||||
|
|||||||
Reference in New Issue
Block a user