-
-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1043 add castling method option v2 #1347
base: main
Are you sure you want to change the base?
Changes from all commits
92ec7b8
a3a4dd0
af02c69
ab1df72
cd26a45
c8348c0
5e4a995
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,10 @@ class BoardPreferences extends _$BoardPreferences with PreferencesStorage<BoardP | |
await save(state.copyWith(pieceShiftMethod: pieceShiftMethod)); | ||
} | ||
|
||
Future<void> setCastlingMethod(CastlingMethod castlingMethod) { | ||
return save(state.copyWith(castlingMethod: castlingMethod)); | ||
} | ||
|
||
Future<void> toggleHapticFeedback() { | ||
return save(state.copyWith(hapticFeedback: !state.hapticFeedback)); | ||
} | ||
|
@@ -125,6 +129,7 @@ class BoardPrefs with _$BoardPrefs implements Serializable { | |
required ClockPosition clockPosition, | ||
@JsonKey(defaultValue: PieceShiftMethod.either, unknownEnumValue: PieceShiftMethod.either) | ||
required PieceShiftMethod pieceShiftMethod, | ||
required CastlingMethod castlingMethod, | ||
|
||
/// Whether to enable shape drawings on the board for games and puzzles. | ||
@JsonKey(defaultValue: true) required bool enableShapeDrawings, | ||
|
@@ -150,6 +155,7 @@ class BoardPrefs with _$BoardPrefs implements Serializable { | |
materialDifferenceFormat: MaterialDifferenceFormat.materialDifference, | ||
clockPosition: ClockPosition.right, | ||
pieceShiftMethod: PieceShiftMethod.either, | ||
castlingMethod: CastlingMethod.either, | ||
enableShapeDrawings: true, | ||
magnifyDraggedPiece: true, | ||
dragTargetKind: DragTargetKind.circle, | ||
|
@@ -347,6 +353,19 @@ enum ClockPosition { | |
}; | ||
} | ||
|
||
enum CastlingMethod { | ||
kingOverRook, | ||
kingTwoSquares, | ||
either; | ||
|
||
// TODO: l10n | ||
String get label => switch (this) { | ||
CastlingMethod.kingOverRook => 'Move king over rook', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. translation keys already exist: look at app_en.arb: |
||
CastlingMethod.kingTwoSquares => 'Move king two squares', | ||
CastlingMethod.either => 'Either', | ||
}; | ||
} | ||
|
||
String dragTargetKindLabel(DragTargetKind kind) => switch (kind) { | ||
DragTargetKind.circle => 'Circle', | ||
DragTargetKind.square => 'Square', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,6 +75,34 @@ class _Body extends ConsumerWidget { | |
} | ||
}, | ||
), | ||
SettingsListTile( | ||
settingsLabel: Text( | ||
context.l10n.preferencesCastleByMovingTheKingTwoSquaresOrOntoTheRook, | ||
), | ||
settingsValue: boardPrefs.castlingMethod.name, | ||
showCupertinoTrailingValue: false, | ||
onTap: () { | ||
if (Theme.of(context).platform == TargetPlatform.android) { | ||
showChoicePicker( | ||
context, | ||
choices: CastlingMethod.values, | ||
selectedItem: boardPrefs.castlingMethod, | ||
labelBuilder: (t) => Text(t.label), | ||
onSelectedItemChanged: (CastlingMethod? value) { | ||
ref | ||
.read(boardPreferencesProvider.notifier) | ||
.setCastlingMethod(value ?? CastlingMethod.either); | ||
}, | ||
); | ||
} else { | ||
pushPlatformRoute( | ||
context, | ||
title: context.l10n.preferencesCastleByMovingTheKingTwoSquaresOrOntoTheRook, | ||
builder: (context) => const CastlingMethodSettingsScreen(), | ||
); | ||
} | ||
}, | ||
), | ||
SwitchSettingTile( | ||
title: Text(context.l10n.mobilePrefMagnifyDraggedPiece), | ||
value: boardPrefs.magnifyDraggedPiece, | ||
|
@@ -271,6 +299,38 @@ class PieceShiftMethodSettingsScreen extends ConsumerWidget { | |
} | ||
} | ||
|
||
class CastlingMethodSettingsScreen extends ConsumerWidget { | ||
const CastlingMethodSettingsScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final castlingMethod = ref.watch( | ||
boardPreferencesProvider.select((state) => state.castlingMethod), | ||
); | ||
|
||
void onChanged(CastlingMethod? value) { | ||
ref.read(boardPreferencesProvider.notifier).setCastlingMethod(value ?? CastlingMethod.either); | ||
} | ||
|
||
return CupertinoPageScaffold( | ||
navigationBar: const CupertinoNavigationBar(), | ||
child: SafeArea( | ||
child: ListView( | ||
children: [ | ||
ChoicePicker( | ||
notchedTile: true, | ||
choices: CastlingMethod.values, | ||
selectedItem: castlingMethod, | ||
titleBuilder: (t) => Text(t.label), | ||
onSelectedItemChanged: onChanged, | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} | ||
|
||
class BoardClockPositionScreen extends ConsumerWidget { | ||
const BoardClockPositionScreen({super.key}); | ||
|
||
|
@@ -369,3 +429,11 @@ String pieceShiftMethodl10n(BuildContext context, PieceShiftMethod pieceShiftMet | |
PieceShiftMethod.drag => context.l10n.preferencesDragPiece, | ||
PieceShiftMethod.tapTwoSquares => 'Tap two squares', | ||
}; | ||
|
||
String castlingMethodl10n(BuildContext context, CastlingMethod castlingMethod) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated l10n logic; must be defined directly in the enum to be consistent with rest of code. |
||
switch (castlingMethod) { | ||
// TODO add this to mobile translations | ||
CastlingMethod.kingOverRook => context.l10n.preferencesCastleByMovingOntoTheRook, | ||
CastlingMethod.kingTwoSquares => context.l10n.preferencesCastleByMovingTwoSquares, | ||
CastlingMethod.either => 'Either', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not support
either
because it is not supported on website.The default is
kingOverRook