flutter: Prompt at the end of move list

This commit is contained in:
Calcitem 2021-05-23 01:01:36 +08:00
parent 0d86b504b4
commit d9c8c69d7d
4 changed files with 36 additions and 13 deletions

View File

@ -903,5 +903,9 @@
"autoReplay": "Auto replay moves", "autoReplay": "Auto replay moves",
"@autoReplay": { "@autoReplay": {
"description": "Auto replay moves" "description": "Auto replay moves"
},
"atEnd": "At the end of move list.",
"@atEnd": {
"description": "At the end of move list."
} }
} }

View File

@ -225,5 +225,6 @@
"boardTop": "棋盘和上边缘的间距", "boardTop": "棋盘和上边缘的间距",
"notAIsTurn": "现在不是轮到电脑行棋", "notAIsTurn": "现在不是轮到电脑行棋",
"aiIsNotThinking": "电脑并非正在思考中", "aiIsNotThinking": "电脑并非正在思考中",
"autoReplay": "自动回放" "autoReplay": "自动回放",
"atEnd": "已经到底了"
} }

View File

@ -1035,16 +1035,23 @@ class Position {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void _gotoHistory(int moveIndex) async { Future<bool> _gotoHistory(int moveIndex) async {
bool ret = false;
if (recorder == null) { if (recorder == null) {
print("[goto] recorder is null."); print("[goto] recorder is null.");
return; return false;
} }
var history = recorder!.getHistory(); var history = recorder!.getHistory();
if (moveIndex < -1 || history.length <= moveIndex) { if (moveIndex < -1 || history.length <= moveIndex) {
print("[goto] moveIndex is out of range."); 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 // Backup context
@ -1057,8 +1064,13 @@ class Position {
await Game.instance.newGame(); await Game.instance.newGame();
if (moveIndex == -1) {
ret = true;
}
for (var i = 0; i <= moveIndex; i++) { for (var i = 0; i <= moveIndex; i++) {
Game.instance.doMove(history[i].move); Game.instance.doMove(history[i].move);
ret = true;
//await Future.delayed(Duration(seconds: 1)); //await Future.delayed(Duration(seconds: 1));
//setState(() {}); //setState(() {});
} }
@ -1068,22 +1080,24 @@ class Position {
Game.instance.setWhoIsAi(engineTypeBackup); Game.instance.setWhoIsAi(engineTypeBackup);
recorder!.setHistory(historyBack); recorder!.setHistory(historyBack);
recorder!.cur = moveIndex; recorder!.cur = moveIndex;
return ret;
} }
void takeBack() async { Future<bool> takeBack() async {
_gotoHistory(recorder!.cur - 1); return _gotoHistory(recorder!.cur - 1);
} }
void stepForward() async { Future<bool> stepForward() async {
_gotoHistory(recorder!.cur + 1); return _gotoHistory(recorder!.cur + 1);
} }
void takeBackAll() async { Future<bool> takeBackAll() async {
_gotoHistory(-1); return _gotoHistory(-1);
} }
void stepForwardAll() async { Future<bool> stepForwardAll() async {
_gotoHistory(recorder!.getHistory().length - 1); return _gotoHistory(recorder!.getHistory().length - 1);
} }
String movesSinceLastRemove() { String movesSinceLastRemove() {

View File

@ -601,7 +601,11 @@ class _GamePageState extends State<GamePage> with RouteAware {
} }
isGoingToHistory = true; isGoingToHistory = true;
await func;
if (await func == false) {
showSnackBar(S.of(context).atEnd);
}
isGoingToHistory = false; isGoingToHistory = false;
if (mounted) { if (mounted) {