flutter: settings: Add IsPieceCountInHandShown option

This commit is contained in:
Calcitem 2021-03-06 01:15:00 +08:00
parent 7b3ed6c4b8
commit 84a6e4dbb9
5 changed files with 73 additions and 22 deletions

View File

@ -36,6 +36,9 @@ class Config {
static bool depthExtension = true;
static bool openingBook = false;
// Display
static bool isPieceCountInHandShown = false;
// Color
static int boardLineColor = UIColors.boardLineColor.value;
static int darkBackgroundColor = UIColors.darkBackgroundColor.value;
@ -71,6 +74,10 @@ class Config {
Config.depthExtension = profile['DepthExtension'] ?? false;
Config.openingBook = profile['OpeningBook'] ?? false;
// Display
Config.isPieceCountInHandShown =
profile['IsPieceCountInHandShown'] ?? false;
// Color
Config.boardLineColor =
profile['BoardLineColor'] ?? UIColors.boardLineColor.value;
@ -121,6 +128,9 @@ class Config {
profile['DepthExtension'] = Config.depthExtension;
profile['OpeningBook'] = Config.openingBook;
// Display
profile['IsPieceCountInHandShown'] = Config.isPieceCountInHandShown;
// Color
profile['BoardLineColor'] = Config.boardLineColor;
profile['DarkBackgroundColor'] = Config.darkBackgroundColor;

View File

@ -435,5 +435,13 @@
"aiIsLazy": "AI is Lazy",
"@aiIsLazy": {
"description": "AI is Lazy"
},
"isPieceCountInHandShown": "Show Piece in Hand Count",
"@isPieceCountInHandShown": {
"description": "Show Piece in Hand Count"
},
"display": "Display",
"@display": {
"description": "Display"
}
}

View File

@ -108,5 +108,7 @@
"pieceColor": "棋子颜色",
"backgroudColor": "背景颜色",
"lineColor": "线条颜色",
"aiIsLazy": "机器领先时懒惰"
"aiIsLazy": "机器领先时懒惰",
"isPieceCountInHandShown": "显示手中剩余棋子数",
"display": "显示"
}

View File

@ -65,31 +65,34 @@ class BoardPainter extends PiecesBasePainter {
paint.strokeWidth = borderLineWidth;
var pieceInHandCount =
Game.shared.position.pieceInHandCount[PieceColor.white];
if (Config.isPieceCountInHandShown) {
var pieceInHandCount =
Game.shared.position.pieceInHandCount[PieceColor.white];
var pieceInHandCountStr = "";
var pieceInHandCountStr = "";
if (Game.shared.position.phase == Phase.placing) {
pieceInHandCountStr = pieceInHandCount.toString();
if (Game.shared.position.phase == Phase.placing) {
pieceInHandCountStr = pieceInHandCount.toString();
}
TextSpan textSpan = TextSpan(
style:
TextStyle(fontSize: 48, color: UIColors.boardLineColor), // TODO
text: pieceInHandCountStr);
TextPainter textPainter = TextPainter(
text: textSpan,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr);
textPainter.layout();
textPainter.paint(
canvas,
Offset(left + squareWidth * 3 - textPainter.width / 2,
top + squareWidth * 3 - textPainter.height / 2));
}
TextSpan textSpan = TextSpan(
style: TextStyle(fontSize: 48, color: UIColors.boardLineColor), // TODO
text: pieceInHandCountStr);
TextPainter textPainter = TextPainter(
text: textSpan,
textAlign: TextAlign.center,
textDirection: TextDirection.ltr);
textPainter.layout();
textPainter.paint(
canvas,
Offset(left + squareWidth * 3 - textPainter.width / 2,
top + squareWidth * 3 - textPainter.height / 2));
canvas.drawRect(
Rect.fromLTWH(left, top, squareWidth * 6, squareWidth * 6),
paint,

View File

@ -280,6 +280,16 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
Config.save();
}
// Display
setIsPieceCountInHandShown(bool value) async {
setState(() {
Config.isPieceCountInHandShown = value;
});
Config.save();
}
@override
Widget build(BuildContext context) {
final TextStyle headerStyle =
@ -387,6 +397,24 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
),
),
const SizedBox(height: 16),
Text(S.of(context).display, style: headerStyle),
Card(
color: cardColor,
margin: const EdgeInsets.symmetric(vertical: 10),
child: Column(
children: <Widget>[
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.isPieceCountInHandShown,
title: Text(S.of(context).isPieceCountInHandShown,
style: itemStyle),
onChanged: setIsPieceCountInHandShown,
),
_buildDivider(),
],
),
),
const SizedBox(height: 16),
Text(S.of(context).color, style: headerStyle),
Card(
color: cardColor,