Skip to content

Commit

Permalink
flutter: Prompt at the end of move list
Browse files Browse the repository at this point in the history
  • Loading branch information
calcitem committed May 22, 2021
1 parent 0d86b50 commit d9c8c69
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/ui/flutter_app/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
3 changes: 2 additions & 1 deletion src/ui/flutter_app/lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,6 @@
"boardTop": "棋盘和上边缘的间距",
"notAIsTurn": "现在不是轮到电脑行棋",
"aiIsNotThinking": "电脑并非正在思考中",
"autoReplay": "自动回放"
"autoReplay": "自动回放",
"atEnd": "已经到底了"
}
36 changes: 25 additions & 11 deletions src/ui/flutter_app/lib/mill/position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(() {});
}
Expand All @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/ui/flutter_app/lib/widgets/game_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d9c8c69

Please sign in to comment.