diff --git a/lib/data_classes/game_session.dart b/lib/data_classes/game_session.dart index 02d0225..a5dbbdc 100644 --- a/lib/data_classes/game_session.dart +++ b/lib/data_classes/game_session.dart @@ -15,7 +15,8 @@ class GameSession { [7, 1, 4, 2], [7, 0, 3, 4], [5, 5, 0, 0], - [10, 3, 3, 2] + [10, 3, 3, 2], + [30, 10, 15, 5] ]; @override diff --git a/lib/views/active_game_view.dart b/lib/views/active_game_view.dart index 61a4b99..9e83bb7 100644 --- a/lib/views/active_game_view.dart +++ b/lib/views/active_game_view.dart @@ -109,7 +109,7 @@ class _ActiveGameViewState extends State { playerIndices.sort((a, b) { int scoreA = widget.gameSession.playerScores[a][0]; int scoreB = widget.gameSession.playerScores[b][0]; - return scoreB.compareTo(scoreA); // Absteigende Sortierung + return scoreA.compareTo(scoreB); // Absteigende Sortierung }); print('playerIndices sortiert: $playerIndices'); return playerIndices; diff --git a/lib/views/create_game_view.dart b/lib/views/create_game_view.dart index f00a680..da075ff 100644 --- a/lib/views/create_game_view.dart +++ b/lib/views/create_game_view.dart @@ -44,6 +44,7 @@ class _CreateGameState extends State { Padding( padding: EdgeInsets.fromLTRB(10, 10, 0, 0), child: CupertinoTextField( + maxLength: 8, prefix: Text('Name'), textAlign: TextAlign.right, placeholder: 'Titel des Spiels', diff --git a/lib/views/main_menu_view.dart b/lib/views/main_menu_view.dart index b1dc22a..95cc78b 100644 --- a/lib/views/main_menu_view.dart +++ b/lib/views/main_menu_view.dart @@ -18,12 +18,12 @@ class _MainMenuViewState extends State { final List gameSessionArray = [ GameSession( gameTitle: 'Spiel am 27.02.2025', - players: ['Alex', 'Ben', 'Clara'], + players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'], winner: 'Clara', gameMode: 0), GameSession( gameTitle: 'Freundschaftsrunde', - players: ['Jonas', 'Felix', 'Nils'], + players: ['Felix', 'Jonas', 'Nils'], winner: 'Jonas', gameMode: 1), GameSession( diff --git a/lib/views/round_view.dart b/lib/views/round_view.dart index 1278eb8..5215f8b 100644 --- a/lib/views/round_view.dart +++ b/lib/views/round_view.dart @@ -1,6 +1,7 @@ import 'package:cabo_counter/data_classes/game_session.dart'; import 'package:cabo_counter/utility/styles.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/services.dart'; class RoundView extends StatefulWidget { final GameSession gameSession; @@ -16,13 +17,21 @@ class RoundView extends StatefulWidget { class _RoundViewState extends State { late final List _isKamikazeChecked = List.filled(widget.gameSession.players.length, false); - late final List _pointControllers = - List.filled(widget.gameSession.players.length, TextEditingController()); - late final List _hasSaidCabo = - List.filled(widget.gameSession.players.length, false); + late final List _pointControllers = List.generate( + widget.gameSession.players.length, + (index) => TextEditingController(), + ); + int _caboPlayerIndex = 0; + late GameSession gameSession = widget.gameSession; + late final List _focusNodes = List.generate( + widget.gameSession.players.length, + (index) => FocusNode(), + ); // Neue FocusNodes-Liste + @override void initState() { super.initState(); + print('Runde ${widget.roundNumber} geöffnet'); } @@ -40,20 +49,50 @@ class _RoundViewState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ Padding( - padding: const EdgeInsets.fromLTRB(0, 50, 0, 50), + padding: const EdgeInsets.fromLTRB(0, 40, 0, 50), child: Text( 'Runde ${widget.roundNumber}', style: Styles.roundTitle, ), ), Padding( - padding: const EdgeInsets.fromLTRB(0, 0, 0, 5), - child: CupertinoListTile( - title: Row( - children: [ - Text('Name'), - ], + padding: const EdgeInsets.fromLTRB(0, 0, 0, 10), + child: Text('Wer hat CABO gesagt?', + style: TextStyle(fontWeight: FontWeight.bold)), + ), + Padding( + padding: EdgeInsets.symmetric( + horizontal: gameSession.players.length > 3 ? 5 : 20, + vertical: 10), + child: SizedBox( + height: 40, + child: CupertinoSegmentedControl( + groupValue: _caboPlayerIndex, + children: Map.fromIterable( + widget.gameSession.players.asMap().keys, + value: (index) => Padding( + padding: EdgeInsets.symmetric( + horizontal: gameSession.players.length > 3 ? 7 : 15, + ), + child: Text( + widget.gameSession.players[index], + style: TextStyle( + fontSize: gameSession.players.length > 3 ? 14 : 16), + ), + ), + ), + onValueChanged: (int value) { + setState(() { + _caboPlayerIndex = value; + }); + }, ), + ), + ), + Padding( + padding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 20.0), + child: CupertinoListTile( + title: Text('Spieler:in'), trailing: Row( children: [ SizedBox( @@ -69,7 +108,8 @@ class _RoundViewState extends State { ), ), ), - ListView.builder( + Expanded( + child: ListView.builder( shrinkWrap: true, itemCount: widget.gameSession.players.length, itemBuilder: (BuildContext context, int index) { @@ -89,29 +129,37 @@ class _RoundViewState extends State { subtitle: Text( '${widget.gameSession.playerScores[index][widget.roundNumber - 1]} Punkte', ), - leading: CupertinoRadio( - value: _hasSaidCabo[index], - groupValue: _hasSaidCabo, - onChanged: (value) { - setState(() { - _hasSaidCabo[index] = true; - }); - }), trailing: Row( children: [ SizedBox( - width: 100, - child: CupertinoTextField( - keyboardType: TextInputType.number, - controller: _pointControllers[index], - placeholder: 'Punkte', - textAlign: TextAlign.center, - onChanged: (value) { - widget.gameSession.playerScores[index] - [widget.roundNumber - 1] = - int.parse(value); - }, - )), + width: 100, + child: CupertinoTextField( + maxLength: 3, + focusNode: _focusNodes[index], + //keyboardType: + // TextInputType.numberWithOptions( + // signed: false, decimal: false), + keyboardType: + TextInputType.numberWithOptions( + signed: true, + decimal: false, + ), + inputFormatters: [ + FilteringTextInputFormatter.digitsOnly, + ], + textInputAction: index == + widget.gameSession.players.length - + 1 + ? TextInputAction.done + : TextInputAction.next, + controller: _pointControllers[index], + placeholder: 'Punkte', + textAlign: TextAlign.center, + // 👇 Action-Typ explizit setzen + + onSubmitted: (_) => _nextField(index), + ), + ), SizedBox(width: 20), SizedBox( width: 50, @@ -132,8 +180,16 @@ class _RoundViewState extends State { ], )))); }, - ), + )), ], ))); } + + void _nextField(int index) { + if (index < widget.gameSession.players.length - 1) { + FocusScope.of(context).requestFocus(_focusNodes[index + 1]); + } else { + _focusNodes[index].unfocus(); + } + } }