flutter: Add rule settings page

This commit is contained in:
Calcitem 2021-02-21 13:02:05 +08:00
parent d25baa2d9a
commit 46007d76fb
8 changed files with 333 additions and 252 deletions

View File

@ -391,5 +391,9 @@
"exit": "Exit", "exit": "Exit",
"@exit": { "@exit": {
"description": "Exit" "description": "Exit"
},
"ruleSettings": "Rule Settings",
"@ruleSettings": {
"description": "Rule Settings"
} }
} }

View File

@ -97,5 +97,6 @@
"feedback": "反馈", "feedback": "反馈",
"inviteFriend": "邀请", "inviteFriend": "邀请",
"rateTheApp": "投票", "rateTheApp": "投票",
"exit": "退出" "exit": "退出",
"ruleSettings": "规则设置"
} }

View File

@ -23,7 +23,6 @@ import 'package:flutter/material.dart';
import 'package:package_info/package_info.dart'; import 'package:package_info/package_info.dart';
import 'package:sanmill/common/config.dart'; import 'package:sanmill/common/config.dart';
import 'package:sanmill/generated/l10n.dart'; import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/mill/rule.dart';
import 'package:sanmill/services/audios.dart'; import 'package:sanmill/services/audios.dart';
import 'package:sanmill/services/player.dart'; import 'package:sanmill/services/player.dart';
import 'package:sanmill/style/colors.dart'; import 'package:sanmill/style/colors.dart';
@ -31,12 +30,12 @@ import 'package:url_launcher/url_launcher.dart';
import 'edit_page.dart'; import 'edit_page.dart';
class SettingsPage extends StatefulWidget { class GameSettingsPage extends StatefulWidget {
@override @override
_SettingsPageState createState() => _SettingsPageState(); _GameSettingsPageState createState() => _GameSettingsPageState();
} }
class _SettingsPageState extends State<SettingsPage> { class _GameSettingsPageState extends State<GameSettingsPage> {
String _version = ""; String _version = "";
@override @override
@ -203,149 +202,6 @@ class _SettingsPageState extends State<SettingsPage> {
Config.save(); Config.save();
} }
// Rules
setNTotalPiecesEachSide() {
//
callback(int piecesCount) async {
//
Navigator.of(context).pop();
setState(() {
rule.piecesCount = Config.piecesCount = piecesCount;
});
Config.save();
}
showModalBottomSheet(
context: context,
builder: (BuildContext context) => Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(height: 10),
RadioListTile(
activeColor: UIColors.primaryColor,
title: Text('6'),
groupValue: Config.piecesCount,
value: 6,
onChanged: callback,
),
Divider(),
RadioListTile(
activeColor: UIColors.primaryColor,
title: Text('9'),
groupValue: Config.piecesCount,
value: 9,
onChanged: callback,
),
Divider(),
RadioListTile(
activeColor: UIColors.primaryColor,
title: Text('12'),
groupValue: Config.piecesCount,
value: 12,
onChanged: callback,
),
Divider(),
SizedBox(height: 56),
],
),
);
}
setNPiecesAtLeast(int value) async {
//
setState(() {
rule.piecesAtLeastCount = Config.piecesAtLeastCount = value;
});
Config.save();
}
setHasObliqueLines(bool value) async {
//
setState(() {
rule.hasObliqueLines = Config.hasObliqueLines = value;
});
Config.save();
}
setHasBannedLocations(bool value) async {
//
setState(() {
rule.hasBannedLocations = Config.hasBannedLocations = value;
});
Config.save();
}
setIsDefenderMoveFirst(bool value) async {
//
setState(() {
rule.isDefenderMoveFirst = Config.isDefenderMoveFirst = value;
});
Config.save();
}
setAllowRemoveMultiPiecesWhenCloseMultiMill(bool value) async {
//
setState(() {
rule.mayRemoveMultiple = Config.mayRemoveMultiple = value;
});
Config.save();
}
setAllowRemovePieceInMill(bool value) async {
//
setState(() {
rule.mayRemoveFromMillsAlways = Config.mayRemoveFromMillsAlways = value;
});
Config.save();
}
setIsBlackLoseButNotDrawWhenBoardFull(bool value) async {
//
setState(() {
rule.isBlackLoseButNotDrawWhenBoardFull =
Config.isBlackLoseButNotDrawWhenBoardFull = value;
});
Config.save();
}
setIsLoseButNotChangeSideWhenNoWay(bool value) async {
//
setState(() {
rule.isLoseButNotChangeSideWhenNoWay =
Config.isLoseButNotChangeSideWhenNoWay = value;
});
Config.save();
}
setAllowFlyingAllowed(bool value) async {
//
setState(() {
rule.mayFly = Config.mayFly = value;
});
Config.save();
}
setMaxStepsLedToDraw(int value) async {
//
setState(() {
rule.maxStepsLedToDraw = Config.maxStepsLedToDraw = value;
});
Config.save();
}
changeName() async { changeName() async {
// //
final newName = await Navigator.of(context).push( final newName = await Navigator.of(context).push(
@ -564,105 +420,6 @@ class _SettingsPageState extends State<SettingsPage> {
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Text(S.of(context).rules, style: headerStyle),
Card(
color: UIColors.boardBackgroundColor,
margin: const EdgeInsets.symmetric(vertical: 10),
child: Column(
children: <Widget>[
ListTile(
title: Text(S.of(context).piecesCount, style: itemStyle),
trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(Config.piecesCount == 6
? '6'
: Config.piecesCount == 9
? '9'
: '12'),
Icon(Icons.keyboard_arrow_right,
color: UIColors.secondaryColor),
]),
onTap: setNTotalPiecesEachSide,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.hasObliqueLines,
title:
Text(S.of(context).hasObliqueLines, style: itemStyle),
onChanged: setHasObliqueLines,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.hasBannedLocations,
title: Text(S.of(context).hasBannedLocations,
style: itemStyle),
onChanged: setHasBannedLocations,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.isDefenderMoveFirst,
title: Text(S.of(context).isDefenderMoveFirst,
style: itemStyle),
onChanged: setIsDefenderMoveFirst,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.mayRemoveMultiple,
title:
Text(S.of(context).mayRemoveMultiple, style: itemStyle),
onChanged: setAllowRemoveMultiPiecesWhenCloseMultiMill,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.mayRemoveFromMillsAlways,
title: Text(S.of(context).mayRemoveFromMillsAlways,
style: itemStyle),
onChanged: setAllowRemovePieceInMill,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.isBlackLoseButNotDrawWhenBoardFull,
title: Text(
S.of(context).isBlackLoseButNotDrawWhenBoardFull,
style: itemStyle),
onChanged: setIsBlackLoseButNotDrawWhenBoardFull,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.isLoseButNotChangeSideWhenNoWay,
title: Text(S.of(context).isLoseButNotChangeSideWhenNoWay,
style: itemStyle),
onChanged: setIsLoseButNotChangeSideWhenNoWay,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.mayFly,
title: Text(S.of(context).mayFly, style: itemStyle),
onChanged: setAllowFlyingAllowed,
),
_buildDivider(),
/*
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.maxStepsLedToDraw,
title:
Text(S.of(context).maxStepsLedToDraw, style: itemStyle),
onChanged: setMaxStepsLedToDraw,
),
_buildDivider(),
*/
],
),
),
const SizedBox(height: 16),
Text(S.of(context).misc, style: headerStyle), Text(S.of(context).misc, style: headerStyle),
Card( Card(
color: UIColors.boardBackgroundColor, color: UIColors.boardBackgroundColor,

View File

@ -48,6 +48,11 @@ class _HomeDrawerState extends State<HomeDrawer> {
labelName: S.of(context).settings, labelName: S.of(context).settings,
icon: Icon(Icons.settings), icon: Icon(Icons.settings),
), ),
DrawerList(
index: DrawerIndex.ruleSettings,
labelName: S.of(context).ruleSettings,
icon: Icon(Icons.rule),
),
DrawerList( DrawerList(
index: DrawerIndex.Help, index: DrawerIndex.Help,
labelName: S.of(context).help, labelName: S.of(context).help,
@ -297,6 +302,7 @@ enum DrawerIndex {
humanVsHuman, humanVsHuman,
aiVsAi, aiVsAi,
settings, settings,
ruleSettings,
FeedBack, FeedBack,
Help, Help,
Share, Share,

View File

@ -22,7 +22,7 @@ import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/style/colors.dart'; import 'package:sanmill/style/colors.dart';
import 'game_page.dart'; import 'game_page.dart';
import 'settings_page.dart'; import 'game_settings_page.dart';
class MainMenu extends StatefulWidget { class MainMenu extends StatefulWidget {
@override @override
@ -133,7 +133,7 @@ class _MainMenuState extends State<MainMenu> with TickerProviderStateMixin {
FlatButton( FlatButton(
child: Text(S.of(context).settings, style: menuItemStyle), child: Text(S.of(context).settings, style: menuItemStyle),
onPressed: () => Navigator.of(context).push( onPressed: () => Navigator.of(context).push(
MaterialPageRoute(builder: (context) => SettingsPage()), MaterialPageRoute(builder: (context) => GameSettingsPage()),
), ),
), ),
Expanded(child: SizedBox()), Expanded(child: SizedBox()),

View File

@ -8,7 +8,8 @@ import 'package:sanmill/widgets/help_screen.dart';
import 'package:sanmill/widgets/home_drawer.dart'; import 'package:sanmill/widgets/home_drawer.dart';
import 'game_page.dart'; import 'game_page.dart';
import 'settings_page.dart'; import 'game_settings_page.dart';
import 'rule_settings_page.dart';
class NavigationHomeScreen extends StatefulWidget { class NavigationHomeScreen extends StatefulWidget {
@override @override
@ -70,7 +71,11 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
}); });
} else if (drawerIndex == DrawerIndex.settings) { } else if (drawerIndex == DrawerIndex.settings) {
setState(() { setState(() {
screenView = SettingsPage(); screenView = GameSettingsPage();
});
} else if (drawerIndex == DrawerIndex.ruleSettings) {
setState(() {
screenView = RuleSettingsPage();
}); });
} else if (drawerIndex == DrawerIndex.Help) { } else if (drawerIndex == DrawerIndex.Help) {
setState(() { setState(() {

View File

@ -0,0 +1,308 @@
/*
This file is part of Sanmill.
Copyright (C) 2019-2021 The Sanmill developers (see AUTHORS file)
Sanmill is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Sanmill is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:sanmill/common/config.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/mill/rule.dart';
import 'package:sanmill/style/colors.dart';
class RuleSettingsPage extends StatefulWidget {
@override
_RuleSettingsPageState createState() => _RuleSettingsPageState();
}
class _RuleSettingsPageState extends State<RuleSettingsPage> {
String _version = "";
@override
void initState() {
super.initState();
}
setNTotalPiecesEachSide() {
//
callback(int piecesCount) async {
//
Navigator.of(context).pop();
setState(() {
rule.piecesCount = Config.piecesCount = piecesCount;
});
Config.save();
}
showModalBottomSheet(
context: context,
builder: (BuildContext context) => Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(height: 10),
RadioListTile(
activeColor: UIColors.primaryColor,
title: Text('6'),
groupValue: Config.piecesCount,
value: 6,
onChanged: callback,
),
Divider(),
RadioListTile(
activeColor: UIColors.primaryColor,
title: Text('9'),
groupValue: Config.piecesCount,
value: 9,
onChanged: callback,
),
Divider(),
RadioListTile(
activeColor: UIColors.primaryColor,
title: Text('12'),
groupValue: Config.piecesCount,
value: 12,
onChanged: callback,
),
Divider(),
SizedBox(height: 56),
],
),
);
}
setNPiecesAtLeast(int value) async {
//
setState(() {
rule.piecesAtLeastCount = Config.piecesAtLeastCount = value;
});
Config.save();
}
setHasObliqueLines(bool value) async {
//
setState(() {
rule.hasObliqueLines = Config.hasObliqueLines = value;
});
Config.save();
}
setHasBannedLocations(bool value) async {
//
setState(() {
rule.hasBannedLocations = Config.hasBannedLocations = value;
});
Config.save();
}
setIsDefenderMoveFirst(bool value) async {
//
setState(() {
rule.isDefenderMoveFirst = Config.isDefenderMoveFirst = value;
});
Config.save();
}
setAllowRemoveMultiPiecesWhenCloseMultiMill(bool value) async {
//
setState(() {
rule.mayRemoveMultiple = Config.mayRemoveMultiple = value;
});
Config.save();
}
setAllowRemovePieceInMill(bool value) async {
//
setState(() {
rule.mayRemoveFromMillsAlways = Config.mayRemoveFromMillsAlways = value;
});
Config.save();
}
setIsBlackLoseButNotDrawWhenBoardFull(bool value) async {
//
setState(() {
rule.isBlackLoseButNotDrawWhenBoardFull =
Config.isBlackLoseButNotDrawWhenBoardFull = value;
});
Config.save();
}
setIsLoseButNotChangeSideWhenNoWay(bool value) async {
//
setState(() {
rule.isLoseButNotChangeSideWhenNoWay =
Config.isLoseButNotChangeSideWhenNoWay = value;
});
Config.save();
}
setAllowFlyingAllowed(bool value) async {
//
setState(() {
rule.mayFly = Config.mayFly = value;
});
Config.save();
}
setMaxStepsLedToDraw(int value) async {
//
setState(() {
rule.maxStepsLedToDraw = Config.maxStepsLedToDraw = value;
});
Config.save();
}
@override
Widget build(BuildContext context) {
//
final TextStyle headerStyle =
TextStyle(color: UIColors.secondaryColor, fontSize: 20.0);
final TextStyle itemStyle = TextStyle(color: UIColors.primaryColor);
return Scaffold(
backgroundColor: UIColors.lightBackgroundColor,
appBar: AppBar(centerTitle: true, title: Text(S.of(context).settings)),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 16),
Text(S.of(context).rules, style: headerStyle),
Card(
color: UIColors.boardBackgroundColor,
margin: const EdgeInsets.symmetric(vertical: 10),
child: Column(
children: <Widget>[
ListTile(
title: Text(S.of(context).piecesCount, style: itemStyle),
trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(Config.piecesCount == 6
? '6'
: Config.piecesCount == 9
? '9'
: '12'),
Icon(Icons.keyboard_arrow_right,
color: UIColors.secondaryColor),
]),
onTap: setNTotalPiecesEachSide,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.hasObliqueLines,
title:
Text(S.of(context).hasObliqueLines, style: itemStyle),
onChanged: setHasObliqueLines,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.hasBannedLocations,
title: Text(S.of(context).hasBannedLocations,
style: itemStyle),
onChanged: setHasBannedLocations,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.isDefenderMoveFirst,
title: Text(S.of(context).isDefenderMoveFirst,
style: itemStyle),
onChanged: setIsDefenderMoveFirst,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.mayRemoveMultiple,
title:
Text(S.of(context).mayRemoveMultiple, style: itemStyle),
onChanged: setAllowRemoveMultiPiecesWhenCloseMultiMill,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.mayRemoveFromMillsAlways,
title: Text(S.of(context).mayRemoveFromMillsAlways,
style: itemStyle),
onChanged: setAllowRemovePieceInMill,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.isBlackLoseButNotDrawWhenBoardFull,
title: Text(
S.of(context).isBlackLoseButNotDrawWhenBoardFull,
style: itemStyle),
onChanged: setIsBlackLoseButNotDrawWhenBoardFull,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.isLoseButNotChangeSideWhenNoWay,
title: Text(S.of(context).isLoseButNotChangeSideWhenNoWay,
style: itemStyle),
onChanged: setIsLoseButNotChangeSideWhenNoWay,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.mayFly,
title: Text(S.of(context).mayFly, style: itemStyle),
onChanged: setAllowFlyingAllowed,
),
_buildDivider(),
/*
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.maxStepsLedToDraw,
title:
Text(S.of(context).maxStepsLedToDraw, style: itemStyle),
onChanged: setMaxStepsLedToDraw,
),
_buildDivider(),
*/
],
),
),
const SizedBox(height: 16),
],
),
),
);
}
Container _buildDivider() {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16),
width: double.infinity,
height: 1.0,
color: UIColors.lightLineColor,
);
}
}

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
cd ~/AppData/Local/Android/Sdk/platform-tools cd ~/AppData/Local/Android/Sdk/platform-tools
./adb shell monkey -v -p com.calcitem.sanmill --pct-touch 100 --pct-trackball 0 --pct-nav 0 --pct-majornav 0 --pct-syskeys 0 --pct-anyevent 0 1000 ./adb shell monkey -v -p com.calcitem.sanmill --pct-touch 100 --pct-trackball 0 --pct-nav 0 --pct-majornav 0 --pct-syskeys 0 --pct-anyevent 0 --throttle 100 1000000