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": {
"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": "棋盘和上边缘的间距",
"notAIsTurn": "现在不是轮到电脑行棋",
"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) {
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<bool> takeBack() async {
return _gotoHistory(recorder!.cur - 1);
}
void stepForward() async {
_gotoHistory(recorder!.cur + 1);
Future<bool> stepForward() async {
return _gotoHistory(recorder!.cur + 1);
}
void takeBackAll() async {
_gotoHistory(-1);
Future<bool> takeBackAll() async {
return _gotoHistory(-1);
}
void stepForwardAll() async {
_gotoHistory(recorder!.getHistory().length - 1);
Future<bool> stepForwardAll() async {
return _gotoHistory(recorder!.getHistory().length - 1);
}
String movesSinceLastRemove() {

View File

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