Skip to content

Commit

Permalink
flutter: Add History Navigation Toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
calcitem committed Jun 6, 2021
1 parent 1766e95 commit b0d4f2d
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/ui/flutter_app/lib/common/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Config {
static bool standardNotationEnabled = true;
static bool isPieceCountInHandShown = false;
static bool isNotationsShown = false;
static bool isHistoryNavigationToolbarShown = false;
static double boardBorderLineWidth = 2.0;
static double boardInnerLineWidth = 2.0;
static double pieceWidth = 0.9;
Expand Down Expand Up @@ -109,6 +110,8 @@ class Config {
Config.isPieceCountInHandShown =
settings['IsPieceCountInHandShown'] ?? false;
Config.isNotationsShown = settings['IsNotationsShown'] ?? false;
Config.isHistoryNavigationToolbarShown =
settings['IsHistoryNavigationToolbarShown'] ?? false;
Config.boardBorderLineWidth = settings['BoardBorderLineWidth'] ?? 2;
Config.boardInnerLineWidth = settings['BoardInnerLineWidth'] ?? 2;
Config.pieceWidth = settings['PieceWidth'] ?? 0.9;
Expand Down Expand Up @@ -186,6 +189,8 @@ class Config {
settings['StandardNotationEnabled'] = Config.standardNotationEnabled;
settings['IsPieceCountInHandShown'] = Config.isPieceCountInHandShown;
settings['IsNotationsShown'] = Config.isNotationsShown;
settings['IsHistoryNavigationToolbarShown'] =
Config.isHistoryNavigationToolbarShown;
settings['BoardBorderLineWidth'] = Config.boardBorderLineWidth;
settings['BoardInnerLineWidth'] = Config.boardInnerLineWidth;
settings['PieceWidth'] = Config.pieceWidth;
Expand Down
4 changes: 4 additions & 0 deletions src/ui/flutter_app/lib/l10n/intl_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@
"@isNotationsShown": {
"description": "Show notations on board"
},
"isHistoryNavigationToolbarShown": "Symbolleiste für die Verlaufsnavigation anzeigen",
"@isHistoryNavigationToolbarShown": {
"description": "Show history navigation toolbar"
},
"display": "Darstellung",
"@display": {
"description": "Display"
Expand Down
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 @@ -644,6 +644,10 @@
"@isNotationsShown": {
"description": "Show notations on board"
},
"isHistoryNavigationToolbarShown": "Show history navigation toolbar",
"@isHistoryNavigationToolbarShown": {
"description": "Show history navigation toolbar"
},
"display": "Display",
"@display": {
"description": "Display"
Expand Down
4 changes: 4 additions & 0 deletions src/ui/flutter_app/lib/l10n/intl_fa.arb
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@
"@isNotationsShown": {
"description": "Show notations on board"
},
"isHistoryNavigationToolbarShown": "نمایش نوار ابزار پیمایش تاریخچه",
"@isHistoryNavigationToolbarShown": {
"description": "Show history navigation toolbar"
},
"display": "نمایش دادن",
"@display": {
"description": "Display"
Expand Down
1 change: 1 addition & 0 deletions src/ui/flutter_app/lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"aiIsLazy": "机器领先时懒惰",
"isPieceCountInHandShown": "显示手中剩余棋子数",
"isNotationsShown": "棋盘边缘显示坐标",
"isHistoryNavigationToolbarShown": "显示着法导航工具栏",
"display": "显示",
"boardBorderLineWidth": "棋盘外框线宽",
"boardInnerLineWidth": "棋盘内部线宽",
Expand Down
88 changes: 86 additions & 2 deletions src/ui/flutter_app/lib/widgets/game_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ class _GamePageState extends State<GamePage>
if (position.phase == Phase.moving &&
rule.mayFly &&
(Game.instance.position.pieceOnBoardCount[us] ==
Config.flyPieceCount || Game.instance.position.pieceOnBoardCount[us] == 3)) {
Config.flyPieceCount ||
Game.instance.position.pieceOnBoardCount[us] == 3)) {
print("[tap] May fly.");
if (mounted) {
showTip(S.of(context).tipCanMoveToAnyPoint);
Expand Down Expand Up @@ -1415,6 +1416,80 @@ class _GamePageState extends State<GamePage>
);
}

Widget createHistoryNavigationToolbar() {
var takeBackAllButton = TextButton(
child: Column(
// Replace with a Row for horizontal icon + text
children: <Widget>[
Icon(
Icons.first_page,
color: AppTheme.toolbarIconColor,
),
],
),
onPressed: () => onTakeBackAllButtonPressed(pop: false),
);

var takeBackButton = TextButton(
child: Column(
// Replace with a Row for horizontal icon + text
children: <Widget>[
Icon(
ltr ? Icons.keyboard_arrow_left : Icons.keyboard_arrow_right,
color: AppTheme.toolbarIconColor,
),
],
),
onPressed: () => onTakeBackButtonPressed(pop: false),
);

var stepForwardButton = TextButton(
child: Column(
// Replace with a Row for horizontal icon + text
children: <Widget>[
Icon(
ltr ? Icons.keyboard_arrow_right : Icons.keyboard_arrow_left,
color: AppTheme.toolbarIconColor,
),
],
),
onPressed: () => onStepForwardButtonPressed(pop: false),
);

var stepForwardAllButton = TextButton(
child: Column(
// Replace with a Row for horizontal icon + text
children: <Widget>[
Icon(
Icons.last_page,
color: AppTheme.toolbarIconColor,
),
],
),
onPressed: () => onStepForwardAllButtonPressed(pop: false),
);

return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Color(Config.boardBackgroundColor),
),
margin: EdgeInsets.symmetric(horizontal: GamePage.screenPaddingH),
padding: EdgeInsets.symmetric(vertical: 2),
child: Row(children: <Widget>[
Expanded(child: SizedBox()),
takeBackAllButton,
Expanded(child: SizedBox()),
takeBackButton,
Expanded(child: SizedBox()),
stepForwardButton,
Expanded(child: SizedBox()), //dashboard_outlined
stepForwardAllButton,
Expanded(child: SizedBox()),
]),
);
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
Expand Down Expand Up @@ -1442,10 +1517,19 @@ class _GamePageState extends State<GamePage>
final header = createPageHeader();
final board = createBoard();
final toolbar = createToolbar();
final historyNavToolbar = createHistoryNavigationToolbar();

return Scaffold(
backgroundColor: Color(Config.darkBackgroundColor),
body: Column(children: <Widget>[header, board, toolbar]),
body: Column(children: <Widget>[
header,
board,
Config.isHistoryNavigationToolbarShown
? historyNavToolbar
: SizedBox(height: 0),
SizedBox(height: 1),
toolbar,
]),
/*
body: Column(children: <Widget>[
header,
Expand Down
10 changes: 10 additions & 0 deletions src/ui/flutter_app/lib/widgets/game_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,16 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
Config.save();
}

setIsHistoryNavigationToolbarShown(bool value) async {
setState(() {
Config.isHistoryNavigationToolbarShown = value;
});

print("[config] isHistoryNavigationToolbarShown: $value");

Config.save();
}

setStandardNotationEnabled(bool value) async {
setState(() {
Config.standardNotationEnabled = value;
Expand Down
15 changes: 15 additions & 0 deletions src/ui/flutter_app/lib/widgets/personalization_settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ class _PersonalizationSettingsPageState
titleString: S.of(context).isNotationsShown,
),
ListItemDivider(),
SettingsSwitchListTile(
context: context,
value: Config.isHistoryNavigationToolbarShown,
onChanged: setIsHistoryNavigationToolbarShown,
titleString: S.of(context).isHistoryNavigationToolbarShown,
),
ListItemDivider(),
SettingsListTile(
context: context,
titleString: S.of(context).boardBorderLineWidth,
Expand Down Expand Up @@ -463,6 +470,14 @@ class _PersonalizationSettingsPageState
Config.save();
}

setIsHistoryNavigationToolbarShown(bool value) async {
setState(() {
Config.isHistoryNavigationToolbarShown = value;
});

Config.save();
}

setStandardNotationEnabled(bool value) async {
setState(() {
Config.standardNotationEnabled = value;
Expand Down

0 comments on commit b0d4f2d

Please sign in to comment.