From 629aa3018fe90f9ad0746eaaa619507ffe13edc0 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Tue, 31 Aug 2021 01:32:06 +0800 Subject: [PATCH] accessibility: Show toast when selecting piece and doing error move --- src/ui/flutter_app/lib/l10n/intl_de.arb | 6 +- src/ui/flutter_app/lib/l10n/intl_en.arb | 6 +- src/ui/flutter_app/lib/l10n/intl_zh.arb | 6 +- src/ui/flutter_app/lib/widgets/game_page.dart | 79 ++++++++++++++++--- src/ui/flutter_app/lib/widgets/snack_bar.dart | 5 +- 5 files changed, 83 insertions(+), 19 deletions(-) diff --git a/src/ui/flutter_app/lib/l10n/intl_de.arb b/src/ui/flutter_app/lib/l10n/intl_de.arb index f31640cd..6e89f00f 100644 --- a/src/ui/flutter_app/lib/l10n/intl_de.arb +++ b/src/ui/flutter_app/lib/l10n/intl_de.arb @@ -1189,8 +1189,8 @@ "@lastMove": { "description": "Last move" }, - "select": "Auswählen", - "@select": { - "description": "Select" + "selected": "Ausgewählt", + "@selected": { + "description": "Selected" } } \ No newline at end of file diff --git a/src/ui/flutter_app/lib/l10n/intl_en.arb b/src/ui/flutter_app/lib/l10n/intl_en.arb index 2a50d3b5..20fdd650 100644 --- a/src/ui/flutter_app/lib/l10n/intl_en.arb +++ b/src/ui/flutter_app/lib/l10n/intl_en.arb @@ -1189,8 +1189,8 @@ "@lastMove": { "description": "Last move" }, - "select": "Select", - "@select": { - "description": "Select" + "selected": "Selected", + "@selected": { + "description": "Selected" } } \ No newline at end of file diff --git a/src/ui/flutter_app/lib/l10n/intl_zh.arb b/src/ui/flutter_app/lib/l10n/intl_zh.arb index 33b85d64..bc2fc825 100644 --- a/src/ui/flutter_app/lib/l10n/intl_zh.arb +++ b/src/ui/flutter_app/lib/l10n/intl_zh.arb @@ -1189,8 +1189,8 @@ "@lastMove": { "description": "Last move" }, - "select": "选中", - "@select": { - "description": "Select" + "selected": "已选中", + "@selected": { + "description": "Selected" } } \ No newline at end of file diff --git a/src/ui/flutter_app/lib/widgets/game_page.dart b/src/ui/flutter_app/lib/widgets/game_page.dart index f204b7c8..65ef6d77 100644 --- a/src/ui/flutter_app/lib/widgets/game_page.dart +++ b/src/ui/flutter_app/lib/widgets/game_page.dart @@ -254,6 +254,9 @@ class _GamePageState extends State //Audios.playTone(Audios.millSoundId); if (mounted) { showTip(S.of(context).tipMill); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipMill); + } } } else { //Audios.playTone(Audios.placeSoundId); @@ -273,6 +276,9 @@ class _GamePageState extends State print("[tap] putPiece: skip [$sq]"); if (mounted) { showTip(S.of(context).tipBanPlace); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipBanPlace); + } } } @@ -284,6 +290,9 @@ class _GamePageState extends State if (position.phase == Phase.placing) { if (mounted) { showTip(S.of(context).tipCannotPlace); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipCannotPlace); + } } break; } @@ -304,9 +313,15 @@ class _GamePageState extends State print("[tap] May fly."); if (mounted) { showTip(S.of(context).tipCanMoveToAnyPoint); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipCanMoveToAnyPoint); + } } } else if (mounted) { showTip(S.of(context).tipPlace); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).selected); + } } break; @@ -315,6 +330,9 @@ class _GamePageState extends State print("[tap] selectPiece: skip [$sq]"); if (mounted && position.phase != Phase.gameOver) { showTip(S.of(context).tipCannotMove); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipCannotMove); + } } break; case -3: @@ -322,6 +340,9 @@ class _GamePageState extends State print("[tap] selectPiece: skip [$sq]"); if (mounted) { showTip(S.of(context).tipCanMoveOnePoint); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipCanMoveOnePoint); + } } break; case -4: @@ -329,6 +350,9 @@ class _GamePageState extends State print("[tap] selectPiece: skip [$sq]"); if (mounted) { showTip(S.of(context).tipSelectPieceToMove); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipSelectPieceToMove); + } } break; default: @@ -336,6 +360,9 @@ class _GamePageState extends State print("[tap] selectPiece: skip [$sq]"); if (mounted) { showTip(S.of(context).tipSelectWrong); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipSelectWrong); + } } break; } @@ -353,6 +380,9 @@ class _GamePageState extends State if (Game.instance.position.pieceToRemoveCount >= 1) { if (mounted) { showTip(S.of(context).tipContinueMill); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipContinueMill); + } } } else { if (Game.instance.engineType == EngineType.humanVsAi) { @@ -376,6 +406,9 @@ class _GamePageState extends State print("[tap] removePiece: Cannot Remove our pieces, skip [$sq]"); if (mounted) { showTip(S.of(context).tipSelectOpponentsPiece); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipSelectOpponentsPiece); + } } break; case -3: @@ -384,6 +417,10 @@ class _GamePageState extends State "[tap] removePiece: Cannot remove piece from Mill, skip [$sq]"); if (mounted) { showTip(S.of(context).tipCannotRemovePieceFromMill); + if (Config.screenReaderSupport) { + showSnackBar( + context, S.of(context).tipCannotRemovePieceFromMill); + } } break; default: @@ -391,6 +428,9 @@ class _GamePageState extends State print("[tap] removePiece: skip [$sq]"); if (mounted && position.phase != Phase.gameOver) { showTip(S.of(context).tipBanRemove); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).tipBanRemove); + } } break; } @@ -433,18 +473,11 @@ class _GamePageState extends State position.recorder.prune(); position.recorder.moveIn(m, position); + /* if (Config.screenReaderSupport && m.notation != null) { - /* - var playerName = ""; - if (position.sideToMove() == PieceColor.white) { - playerName = S.of(context).player + " 1"; - } else if (position.sideToMove() == PieceColor.black) { - playerName = S.of(context).player + " 2"; - } - */ - showSnackBar(context, S.of(context).human + ": " + m.notation!); } + */ setState(() {}); @@ -502,6 +535,15 @@ class _GamePageState extends State } else { if (mounted) { showTip(S.of(context).thinking); + + Move? m = Game.instance.position.recorder.lastMove; + + if (Config.screenReaderSupport && + Game.instance.position.action != Act.remove && + m != null && + m.notation != null) { + showSnackBar(context, S.of(context).human + ": " + m.notation!); + } } } @@ -542,6 +584,9 @@ class _GamePageState extends State case 'timeout': if (mounted) { showTip(S.of(context).timeout); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).timeout); + } } //if (Config.developerMode) { @@ -573,6 +618,9 @@ class _GamePageState extends State if (mounted) { showTip(S.of(context).gameStarted); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).gameStarted); + } } if (Game.instance.isAiToMove()) { @@ -601,12 +649,19 @@ class _GamePageState extends State if (importFailedStr != "") { showTip(S.of(context).cannotImport + " " + importFailedStr); + if (Config.screenReaderSupport) { + showSnackBar( + context, S.of(context).cannotImport + " " + importFailedStr); + } return; } await onStepForwardAllButtonPressed(pop: false); showTip(S.of(context).gameImported); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).gameImported); + } } onExportGameButtonPressed() async { @@ -956,6 +1011,9 @@ class _GamePageState extends State if (mounted) { showTip(S.of(context).done); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).done); // TODO: Last move + } } } @@ -1271,6 +1329,9 @@ class _GamePageState extends State Game.instance.newGame(); if (mounted) { showTip(S.of(context).gameStarted); + if (Config.screenReaderSupport) { + showSnackBar(context, S.of(context).gameStarted); + } } if (Game.instance.isAiToMove()) { diff --git a/src/ui/flutter_app/lib/widgets/snack_bar.dart b/src/ui/flutter_app/lib/widgets/snack_bar.dart index f6640127..30cffd43 100644 --- a/src/ui/flutter_app/lib/widgets/snack_bar.dart +++ b/src/ui/flutter_app/lib/widgets/snack_bar.dart @@ -21,7 +21,10 @@ import 'package:sanmill/common/config.dart'; void showSnackBar(BuildContext context, String message, {Duration duration = const Duration(milliseconds: 4000)}) { - ScaffoldMessenger.of(context).hideCurrentSnackBar(); + if (!Config.screenReaderSupport) { + ScaffoldMessenger.of(context).hideCurrentSnackBar(); + } + ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text( message,