From d9c8c69d7d68fada0fd161e54abfa818a11d457e Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sun, 23 May 2021 01:01:36 +0800 Subject: [PATCH] flutter: Prompt at the end of move list --- src/ui/flutter_app/lib/l10n/intl_en.arb | 4 +++ src/ui/flutter_app/lib/l10n/intl_zh.arb | 3 +- src/ui/flutter_app/lib/mill/position.dart | 36 +++++++++++++------ src/ui/flutter_app/lib/widgets/game_page.dart | 6 +++- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/ui/flutter_app/lib/l10n/intl_en.arb b/src/ui/flutter_app/lib/l10n/intl_en.arb index 1e093ac3..1f81c9ba 100644 --- a/src/ui/flutter_app/lib/l10n/intl_en.arb +++ b/src/ui/flutter_app/lib/l10n/intl_en.arb @@ -903,5 +903,9 @@ "autoReplay": "Auto replay moves", "@autoReplay": { "description": "Auto replay moves" + }, + "atEnd": "At the end of move list.", + "@atEnd": { + "description": "At the end of move list." } } diff --git a/src/ui/flutter_app/lib/l10n/intl_zh.arb b/src/ui/flutter_app/lib/l10n/intl_zh.arb index 49e62631..5d1a7ba3 100644 --- a/src/ui/flutter_app/lib/l10n/intl_zh.arb +++ b/src/ui/flutter_app/lib/l10n/intl_zh.arb @@ -225,5 +225,6 @@ "boardTop": "棋盘和上边缘的间距", "notAIsTurn": "现在不是轮到电脑行棋", "aiIsNotThinking": "电脑并非正在思考中", - "autoReplay": "自动回放" + "autoReplay": "自动回放", + "atEnd": "已经到底了" } \ No newline at end of file diff --git a/src/ui/flutter_app/lib/mill/position.dart b/src/ui/flutter_app/lib/mill/position.dart index 382ff63e..ef5de6b9 100644 --- a/src/ui/flutter_app/lib/mill/position.dart +++ b/src/ui/flutter_app/lib/mill/position.dart @@ -1035,16 +1035,23 @@ class Position { /////////////////////////////////////////////////////////////////////////////// - void _gotoHistory(int moveIndex) async { + Future _gotoHistory(int moveIndex) async { + bool ret = false; + if (recorder == null) { print("[goto] recorder is null."); - return; + return false; } var history = recorder!.getHistory(); if (moveIndex < -1 || history.length <= moveIndex) { print("[goto] moveIndex is out of range."); - return; + return false; + } + + if (recorder!.cur == moveIndex) { + print("[goto] cur is equal to moveIndex."); + return false; } // Backup context @@ -1057,8 +1064,13 @@ class Position { await Game.instance.newGame(); + if (moveIndex == -1) { + ret = true; + } + for (var i = 0; i <= moveIndex; i++) { Game.instance.doMove(history[i].move); + ret = true; //await Future.delayed(Duration(seconds: 1)); //setState(() {}); } @@ -1068,22 +1080,24 @@ class Position { Game.instance.setWhoIsAi(engineTypeBackup); recorder!.setHistory(historyBack); recorder!.cur = moveIndex; + + return ret; } - void takeBack() async { - _gotoHistory(recorder!.cur - 1); + Future takeBack() async { + return _gotoHistory(recorder!.cur - 1); } - void stepForward() async { - _gotoHistory(recorder!.cur + 1); + Future stepForward() async { + return _gotoHistory(recorder!.cur + 1); } - void takeBackAll() async { - _gotoHistory(-1); + Future takeBackAll() async { + return _gotoHistory(-1); } - void stepForwardAll() async { - _gotoHistory(recorder!.getHistory().length - 1); + Future stepForwardAll() async { + return _gotoHistory(recorder!.getHistory().length - 1); } String movesSinceLastRemove() { diff --git a/src/ui/flutter_app/lib/widgets/game_page.dart b/src/ui/flutter_app/lib/widgets/game_page.dart index 9b1a2f6c..d8de37d5 100644 --- a/src/ui/flutter_app/lib/widgets/game_page.dart +++ b/src/ui/flutter_app/lib/widgets/game_page.dart @@ -601,7 +601,11 @@ class _GamePageState extends State with RouteAware { } isGoingToHistory = true; - await func; + + if (await func == false) { + showSnackBar(S.of(context).atEnd); + } + isGoingToHistory = false; if (mounted) {