Rearrange landscape puzzle layout
Landscape leaves now lay the puzzle out in two columns: the whole grid keeps one column (square, sized to the page) with the heading, area totals, hint/undo and notes beside it, and the leaf navigation folds into a single row. The game leaf also keeps its actions in a compact bottom bar, so the board and controls are visible without scrolling. - Leaf gains an optional wideBody used on landscape pages. - Board gains maxWidth, defaulting to the previous 350. - Split the puzzle body into area, board and note builders so both layouts share the same controls. - Add a landscape widget regression test and document the layout. This snapshot also carries the pending 2.0.2 notebook work already in the tree: read-ahead restore, bundled PCM WAV narration assets, the audio consistency comment, version 2.0.2+11, and the related unit, integration and script updates.
This commit is contained in:
+11
-4
@@ -60,8 +60,9 @@ class Game extends ChangeNotifier {
|
||||
contents();
|
||||
} else if (saved == 'briefing') {
|
||||
briefing(campaignIndex);
|
||||
} else if (saved == 'reveal' && recovered(campaignIndex)) {
|
||||
reveal(campaignIndex);
|
||||
} else if (saved == 'reveal' &&
|
||||
(recovered(campaignIndex) || progress.flag('flutter_read_ahead'))) {
|
||||
reveal(campaignIndex, readAhead: progress.flag('flutter_read_ahead'));
|
||||
} else if (saved == 'game') {
|
||||
final mode = progress.text('flutter_mode');
|
||||
if (mode == 'campaign') {
|
||||
@@ -79,6 +80,12 @@ class Game extends ChangeNotifier {
|
||||
void _route(Screen value) {
|
||||
screen = value;
|
||||
unawaited(progress.set('flutter_screen', value.name));
|
||||
unawaited(
|
||||
progress.set(
|
||||
'flutter_read_ahead',
|
||||
value == Screen.reveal && !recovered(campaignIndex),
|
||||
),
|
||||
);
|
||||
unawaited(progress.set('flutter_campaign', campaignIndex));
|
||||
unawaited(progress.set('flutter_mode', mode.name));
|
||||
unawaited(progress.set('flutter_date', date.toIso8601String()));
|
||||
@@ -125,8 +132,8 @@ class Game extends ChangeNotifier {
|
||||
_route(Screen.briefing);
|
||||
}
|
||||
|
||||
void reveal(int i) {
|
||||
if (!recovered(i)) {
|
||||
void reveal(int i, {bool readAhead = false}) {
|
||||
if (!recovered(i) && (!readAhead || i > accessible)) {
|
||||
briefing(i);
|
||||
return;
|
||||
}
|
||||
|
||||
+317
-134
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
@@ -183,6 +184,67 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
g.showStory(next);
|
||||
}
|
||||
|
||||
Future<void> turnCampaign(int direction) async {
|
||||
final index = g.campaignIndex;
|
||||
switch (g.screen) {
|
||||
case Screen.briefing:
|
||||
if (direction > 0) {
|
||||
g.startCampaign(index);
|
||||
} else if (index > 0) {
|
||||
g.reveal(index - 1, readAhead: true);
|
||||
} else {
|
||||
g.contents();
|
||||
}
|
||||
case Screen.game:
|
||||
if (direction < 0) {
|
||||
g.briefing(index);
|
||||
return;
|
||||
}
|
||||
if (!g.won &&
|
||||
!await confirm(
|
||||
'Leave a ribbon here?',
|
||||
'Your puzzle marks are saved. You can read the memory now and return to this pattern whenever you like.',
|
||||
'Read ahead',
|
||||
no: 'Keep solving',
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
if (mounted) g.reveal(index, readAhead: true);
|
||||
case Screen.reveal:
|
||||
if (direction < 0) {
|
||||
g.briefing(index);
|
||||
} else {
|
||||
nextCampaign();
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void nextCampaign() {
|
||||
final index = g.campaignIndex;
|
||||
if (index == 11) {
|
||||
g.contents();
|
||||
return;
|
||||
}
|
||||
// Reading access is distinct from completed puzzles and their awards.
|
||||
unawaited(
|
||||
prefs.set('story_access_level', math.max(g.accessible, index + 1)),
|
||||
);
|
||||
void next() {
|
||||
if (mounted) g.briefing(index + 1);
|
||||
}
|
||||
|
||||
if (g.recovered(index) &&
|
||||
(index + 1) % 4 == 0 &&
|
||||
!prefs.flag('storyAd_$index')) {
|
||||
unawaited(prefs.set('storyAd_$index', true));
|
||||
ads.between(next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
void back() {
|
||||
if (g.busy) {
|
||||
g.home();
|
||||
@@ -358,46 +420,62 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
),
|
||||
),
|
||||
);
|
||||
Widget navigation() => column([
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: InkButton('Contents', g.contents, size: 20)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: InkButton('Bookmark', () {
|
||||
unawaited(
|
||||
prefs.set(
|
||||
'notebook_manual_bookmark',
|
||||
g.book.pages[g.storyIndex].id,
|
||||
),
|
||||
);
|
||||
toast('A ribbon marks this page.');
|
||||
}, size: 20),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: InkButton('Close book', g.home, size: 20)),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: InkButton(
|
||||
'← Previous leaf',
|
||||
g.storyIndex > 0 ? () => turn(-1) : null,
|
||||
size: 21,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: InkButton(
|
||||
g.storyIndex == 5 ? 'End of this trail' : 'Next leaf →',
|
||||
g.storyIndex < 5 ? () => turn(1) : null,
|
||||
size: 21,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]);
|
||||
void bookmark() {
|
||||
unawaited(
|
||||
prefs.set('notebook_manual_bookmark', g.book.pages[g.storyIndex].id),
|
||||
);
|
||||
toast('A ribbon marks this page.');
|
||||
}
|
||||
|
||||
Widget navigation() {
|
||||
final wide = MediaQuery.orientationOf(context) == Orientation.landscape;
|
||||
final previous = InkButton(
|
||||
'← Previous leaf',
|
||||
g.storyIndex > 0 ? () => turn(-1) : null,
|
||||
size: wide ? 19 : 21,
|
||||
);
|
||||
final next = InkButton(
|
||||
g.storyIndex == 5 ? 'End of this trail' : 'Next leaf →',
|
||||
g.storyIndex < 5 ? () => turn(1) : null,
|
||||
size: wide ? 19 : 21,
|
||||
);
|
||||
if (wide) {
|
||||
// One row keeps the shorter landscape page free for the illustration
|
||||
// and the puzzle beside it.
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(child: InkButton('Contents', g.contents, size: 19)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: InkButton('Bookmark', bookmark, size: 19)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: InkButton('Close book', g.home, size: 19)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: previous),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: next),
|
||||
],
|
||||
);
|
||||
}
|
||||
return column([
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: InkButton('Contents', g.contents, size: 20)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: InkButton('Bookmark', bookmark, size: 20)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: InkButton('Close book', g.home, size: 20)),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: previous),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: next),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
Widget reading(String text) => ListenableBuilder(
|
||||
listenable: narrator,
|
||||
builder: (context, _) {
|
||||
@@ -472,10 +550,12 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
);
|
||||
Widget story() {
|
||||
final p = g.book.pages[g.storyIndex];
|
||||
final body = <Widget>[
|
||||
final heading = <Widget>[
|
||||
folio('MARA’S NOTEBOOK / ${g.storyIndex + 1} OF 6'),
|
||||
writing(p.title, size: 31),
|
||||
];
|
||||
final body = <Widget>[...heading];
|
||||
Widget? wideBody;
|
||||
switch (g.storyIndex) {
|
||||
case 0:
|
||||
body.addAll([
|
||||
@@ -495,14 +575,15 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
audio(),
|
||||
]);
|
||||
case 2:
|
||||
body.addAll([
|
||||
writing(
|
||||
'Restore a small light, or leave a bookmark and read on.',
|
||||
size: 21,
|
||||
color: muted,
|
||||
),
|
||||
puzzleBody(),
|
||||
]);
|
||||
final intro = writing(
|
||||
'Restore a small light, or leave a bookmark and read on.',
|
||||
size: 21,
|
||||
color: muted,
|
||||
);
|
||||
body.addAll([intro, puzzleBody()]);
|
||||
wideBody = splitPuzzle(
|
||||
side: [...heading, intro, areaPicker(), ...puzzleNotes()],
|
||||
);
|
||||
case 3:
|
||||
body.addAll([
|
||||
const Sketch('match'),
|
||||
@@ -578,6 +659,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
key: ValueKey('story-${g.storyIndex}'),
|
||||
onTurn: (d) => turn(d),
|
||||
body: column(body),
|
||||
wideBody: wideBody,
|
||||
footer: navigation(),
|
||||
);
|
||||
}
|
||||
@@ -677,6 +759,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
final l = g.book.levels[g.campaignIndex];
|
||||
return Leaf(
|
||||
key: ValueKey('briefing-${g.campaignIndex}'),
|
||||
onTurn: (d) => turnCampaign(d),
|
||||
body: column([
|
||||
folio('MARA’S NOTEBOOK / LEAF ${g.campaignIndex + 1}'),
|
||||
writing(l.chapter, size: 20, color: blue),
|
||||
@@ -703,67 +786,116 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
);
|
||||
}
|
||||
|
||||
Widget puzzleBody() {
|
||||
Widget puzzleBody() => column([areaPicker(), board(), ...puzzleNotes()]);
|
||||
|
||||
Widget areaPicker() {
|
||||
final p = g.puzzle;
|
||||
if (p == null) return const SizedBox.shrink();
|
||||
if (p == null || p.regions.isEmpty) return const SizedBox.shrink();
|
||||
return column([
|
||||
if (p.regions.isNotEmpty) ...[
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
children: [
|
||||
for (var i = 0; i < p.regions.length; i++)
|
||||
InkButton(
|
||||
'${p.regions[i].label} · ${List.generate(g.cells.length, (j) => j).where((j) => p.regions[i].contains(j, p.size) && g.cells[j] == 1).length} / ${p.regionTotal(p.regions[i])}',
|
||||
() => g.area(i),
|
||||
size: 21,
|
||||
primary: i == g.selectedArea,
|
||||
),
|
||||
],
|
||||
),
|
||||
writing('Tap A, B or C to highlight its area', size: 17, color: muted),
|
||||
],
|
||||
Board(
|
||||
puzzle: p,
|
||||
cells: g.cells,
|
||||
onMark: g.mark,
|
||||
selectedArea: g.selectedArea,
|
||||
won: g.won,
|
||||
),
|
||||
writing(
|
||||
g.won
|
||||
? 'Already restored. Turn the leaf to revisit the memory.'
|
||||
: 'Tap: light → cross → clear. Mark every cell.',
|
||||
size: 18,
|
||||
color: muted,
|
||||
),
|
||||
if (!g.won)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: InkButton(
|
||||
'Undo a mark',
|
||||
g.canUndo ? g.undo : null,
|
||||
size: 22,
|
||||
),
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
children: [
|
||||
for (var i = 0; i < p.regions.length; i++)
|
||||
InkButton(
|
||||
'${p.regions[i].label} · ${List.generate(g.cells.length, (j) => j).where((j) => p.regions[i].contains(j, p.size) && g.cells[j] == 1).length} / ${p.regionTotal(p.regions[i])}',
|
||||
() => g.area(i),
|
||||
size: 21,
|
||||
primary: i == g.selectedArea,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: InkButton(
|
||||
prefs.flag('hint_${g.key}')
|
||||
? 'Hint · rewarded ad'
|
||||
: 'Hint · free',
|
||||
hint,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
writing('Tap A, B or C to highlight its area', size: 17, color: muted),
|
||||
]);
|
||||
}
|
||||
|
||||
Widget game() => Leaf(
|
||||
key: ValueKey('game-${g.key}'),
|
||||
body: column([
|
||||
Widget board({double maxWidth = 350}) {
|
||||
final p = g.puzzle;
|
||||
if (p == null) return const SizedBox.shrink();
|
||||
return Board(
|
||||
puzzle: p,
|
||||
cells: g.cells,
|
||||
onMark: g.mark,
|
||||
selectedArea: g.selectedArea,
|
||||
won: g.won,
|
||||
maxWidth: maxWidth,
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> puzzleNotes() => [
|
||||
writing(
|
||||
g.won
|
||||
? 'Already restored. Turn the leaf to revisit the memory.'
|
||||
: 'Tap: light → cross → clear. Mark every cell.',
|
||||
size: 18,
|
||||
color: muted,
|
||||
),
|
||||
if (!g.won)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: InkButton(
|
||||
'Undo a mark',
|
||||
g.canUndo ? g.undo : null,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: InkButton(
|
||||
prefs.flag('hint_${g.key}')
|
||||
? 'Hint · rewarded ad'
|
||||
: 'Hint · free',
|
||||
hint,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
];
|
||||
|
||||
/// Landscape puzzle leaf: the grid keeps the left column at its full height
|
||||
/// while the heading, area clues and notes sit beside it, so nothing has to
|
||||
/// be scrolled into view before the board can be played.
|
||||
Widget splitPuzzle({required List<Widget> side}) => LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final width = math.min(c.maxWidth, 980.0),
|
||||
height = c.maxHeight.isFinite ? c.maxHeight : c.maxWidth,
|
||||
// Keep a readable column for the notes, then give the rest to the
|
||||
// grid, which stays a square no taller than the page.
|
||||
panel = math.min(
|
||||
math.min(280.0, math.max(200.0, width * .40)),
|
||||
width * .55,
|
||||
),
|
||||
grid = math.min(math.min(height, width - panel - 18), 520.0);
|
||||
return Align(
|
||||
alignment: Alignment.center,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
height: height,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: grid,
|
||||
child: Center(child: board(maxWidth: grid)),
|
||||
),
|
||||
const SizedBox(width: 18),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
key: const PageStorageKey('leaf-side-scroll'),
|
||||
padding: const EdgeInsets.fromLTRB(2, 0, 2, 8),
|
||||
child: column(side),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
Widget game() {
|
||||
List<Widget> heading({bool compact = false}) => [
|
||||
folio(
|
||||
g.mode == Mode.daily
|
||||
? 'DAILY / ${DateFormat('d MMMM').format(g.date)}'
|
||||
@@ -775,28 +907,79 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
g.mode == Mode.campaign
|
||||
? g.book.levels[g.campaignIndex].title
|
||||
: 'Find the light.',
|
||||
size: 32,
|
||||
size: compact ? 27 : 32,
|
||||
),
|
||||
writing(
|
||||
g.puzzle!.regions.isEmpty
|
||||
g.puzzle?.regions.isEmpty ?? true
|
||||
? 'Match the totals. Let the pattern emerge.'
|
||||
: 'Compare rows, columns and overlapping areas.',
|
||||
size: 21,
|
||||
size: compact ? 18 : 21,
|
||||
color: muted,
|
||||
),
|
||||
puzzleBody(),
|
||||
if (g.won) ...[
|
||||
writing('A moment of clarity.', size: 29),
|
||||
action(
|
||||
g.mode == Mode.daily ? 'Return to the notebook' : 'Next puzzle →',
|
||||
g.mode == Mode.daily ? g.home : nextPractice,
|
||||
];
|
||||
final actions = <({String label, VoidCallback run, bool primary})>[
|
||||
if (g.won)
|
||||
(
|
||||
label: g.mode == Mode.daily
|
||||
? 'Return to the notebook'
|
||||
: 'Next puzzle →',
|
||||
run: g.mode == Mode.daily ? g.home : nextPractice,
|
||||
primary: true,
|
||||
),
|
||||
],
|
||||
action('How to play', rules),
|
||||
action('Back to notebook', g.mode == Mode.campaign ? g.contents : g.home),
|
||||
]),
|
||||
);
|
||||
(label: 'How to play', run: rules, primary: false),
|
||||
(
|
||||
label: 'Back to notebook',
|
||||
run: g.mode == Mode.campaign ? g.contents : g.home,
|
||||
primary: false,
|
||||
),
|
||||
];
|
||||
final clarity = writing('A moment of clarity.', size: 29);
|
||||
return Leaf(
|
||||
key: ValueKey('game-${g.key}'),
|
||||
onTurn: g.mode == Mode.campaign ? (d) => turnCampaign(d) : null,
|
||||
body: column([
|
||||
...heading(),
|
||||
puzzleBody(),
|
||||
if (g.won) clarity,
|
||||
for (final a in actions) action(a.label, a.run, primary: a.primary),
|
||||
]),
|
||||
// Landscape: the heading and notes sit beside the grid while the leaf's
|
||||
// actions stay in a compact bar that does not take room from the board.
|
||||
wideBody: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: splitPuzzle(
|
||||
side: [
|
||||
...heading(compact: true),
|
||||
areaPicker(),
|
||||
...puzzleNotes(),
|
||||
if (g.won) writing('A moment of clarity.', size: 23),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6, bottom: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
for (var i = 0; i < actions.length; i++) ...[
|
||||
if (i > 0) const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: InkButton(
|
||||
actions[i].label,
|
||||
actions[i].run,
|
||||
size: 20,
|
||||
primary: actions[i].primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> hint() async {
|
||||
final requested = g.key;
|
||||
void give() async {
|
||||
@@ -847,10 +1030,13 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
final i = g.campaignIndex, l = g.book.levels[i];
|
||||
return Leaf(
|
||||
key: ValueKey('reveal-$i'),
|
||||
onTurn: (d) => turnCampaign(d),
|
||||
body: column([
|
||||
folio('MARA’S NOTEBOOK / LEAF ${i + 1}'),
|
||||
writing(
|
||||
'Something found. Something remembered.',
|
||||
g.recovered(i)
|
||||
? 'Something found. Something remembered.'
|
||||
: 'A memory to read · your pattern can wait',
|
||||
size: 23,
|
||||
color: muted,
|
||||
),
|
||||
@@ -859,31 +1045,28 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
writing(l.after, size: 25),
|
||||
gap(),
|
||||
writing(
|
||||
'Kept safe, between these pages. — M.',
|
||||
g.recovered(i)
|
||||
? 'Kept safe, between these pages. — M.'
|
||||
: 'Your pattern is saved for another day.',
|
||||
size: 23,
|
||||
color: const Color(0xff70503b),
|
||||
),
|
||||
divider(),
|
||||
if (i == 11) ...[
|
||||
folio('THE END · YOUR WATCH HAS BEGUN'),
|
||||
folio(
|
||||
g.recoveredCount == 12
|
||||
? 'THE END · YOUR WATCH HAS BEGUN'
|
||||
: 'THE LAST PAGE · COME BACK WHENEVER YOU LIKE',
|
||||
),
|
||||
writing(
|
||||
'Twelve patterns. One light brought home. The daily puzzle will be here whenever you return.',
|
||||
g.recoveredCount == 12
|
||||
? 'Twelve patterns. One light brought home. The daily puzzle will be here whenever you return.'
|
||||
: 'A light kept in these pages. Your unfinished patterns will be here whenever you return.',
|
||||
),
|
||||
action('Return to the notebook', g.contents, primary: true),
|
||||
action('Today’s puzzle', () => g.startDaily(DateTime.now())),
|
||||
] else
|
||||
action('Turn the page →', () {
|
||||
void next() {
|
||||
if (mounted) g.briefing(i + 1);
|
||||
}
|
||||
|
||||
if ((i + 1) % 4 == 0 && !prefs.flag('storyAd_$i')) {
|
||||
unawaited(prefs.set('storyAd_$i', true));
|
||||
ads.between(next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}, primary: true),
|
||||
action('Turn the page →', nextCampaign, primary: true),
|
||||
action('Back to notebook', g.contents),
|
||||
]),
|
||||
);
|
||||
|
||||
@@ -67,6 +67,7 @@ class Narrator extends ChangeNotifier {
|
||||
await session.configure(const AudioSessionConfiguration.speech());
|
||||
if (generation != _generation) return;
|
||||
page = id;
|
||||
// PCM WAV avoids silent FLAC playback on the API 26 Huawei tablet.
|
||||
await _player.setAsset('assets/audio/${tracks[id]['file']}');
|
||||
if (generation != _generation) return;
|
||||
} else if (finished) {
|
||||
|
||||
+211
-127
@@ -1,3 +1,5 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../domain/puzzle.dart';
|
||||
@@ -11,163 +13,245 @@ class Board extends StatelessWidget {
|
||||
required this.onMark,
|
||||
this.selectedArea = 0,
|
||||
this.won = false,
|
||||
this.maxWidth = 350,
|
||||
});
|
||||
final Puzzle puzzle;
|
||||
final List<int> cells;
|
||||
final ValueChanged<int> onMark;
|
||||
final int selectedArea;
|
||||
final bool won;
|
||||
|
||||
/// Wide leaves give the grid more room; it still stays a square.
|
||||
final double maxWidth;
|
||||
@override
|
||||
Widget build(BuildContext context) => Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 350),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final n = puzzle.size,
|
||||
u = c.maxWidth / (n + 1.3),
|
||||
r = puzzle.regions.isEmpty
|
||||
? null
|
||||
: puzzle.regions[selectedArea];
|
||||
Widget clue(String text, bool complete) => SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Center(
|
||||
child: Text(
|
||||
text,
|
||||
style: hand(
|
||||
(u * .42).clamp(16, 23),
|
||||
color: complete ? blue : muted,
|
||||
Widget build(BuildContext context) => PageSwipeBlocker(
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: maxWidth),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final n = puzzle.size,
|
||||
u = c.maxWidth / (n + 1.3),
|
||||
r = puzzle.regions.isEmpty
|
||||
? null
|
||||
: puzzle.regions[selectedArea];
|
||||
Widget clue(String text, bool complete) => SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Center(
|
||||
child: Text(
|
||||
text,
|
||||
style: hand(
|
||||
(u * .42).clamp(16, 23),
|
||||
color: complete ? blue : muted,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
bool complete(Iterable<int> indices, int total) =>
|
||||
indices.where((i) => cells[i] == 1).length == total;
|
||||
return Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(width: u, height: u),
|
||||
for (var col = 0; col < n; col++)
|
||||
clue(
|
||||
'${puzzle.cols[col]}',
|
||||
complete(
|
||||
List.generate(n, (i) => i * n + col),
|
||||
puzzle.cols[col],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var row = 0; row < n; row++)
|
||||
);
|
||||
bool complete(Iterable<int> indices, int total) =>
|
||||
indices.where((i) => cells[i] == 1).length == total;
|
||||
return Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
clue(
|
||||
'${puzzle.rows[row]}',
|
||||
complete(
|
||||
List.generate(n, (i) => row * n + i),
|
||||
puzzle.rows[row],
|
||||
),
|
||||
),
|
||||
SizedBox(width: u, height: u),
|
||||
for (var col = 0; col < n; col++)
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final i = row * n + col,
|
||||
value = cells[i],
|
||||
fixed = puzzle.given[i],
|
||||
inside = r?.contains(i, n) ?? false;
|
||||
final state = value == 0
|
||||
? 'empty'
|
||||
: value == 1
|
||||
? 'lit'
|
||||
: 'crossed out';
|
||||
return Semantics(
|
||||
label:
|
||||
'Row ${row + 1}, column ${col + 1}, $state${fixed ? ', fixed clue' : ''}',
|
||||
button: !fixed && !won,
|
||||
enabled: !fixed && !won,
|
||||
onTap: fixed || won ? null : () => onMark(i),
|
||||
excludeSemantics: true,
|
||||
child: GestureDetector(
|
||||
key: ValueKey('cell-$i'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
clue(
|
||||
'${puzzle.cols[col]}',
|
||||
complete(
|
||||
List.generate(n, (i) => i * n + col),
|
||||
puzzle.cols[col],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var row = 0; row < n; row++)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
clue(
|
||||
'${puzzle.rows[row]}',
|
||||
complete(
|
||||
List.generate(n, (i) => row * n + i),
|
||||
puzzle.rows[row],
|
||||
),
|
||||
),
|
||||
for (var col = 0; col < n; col++)
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final i = row * n + col,
|
||||
value = cells[i],
|
||||
fixed = puzzle.given[i],
|
||||
inside = r?.contains(i, n) ?? false;
|
||||
final state = value == 0
|
||||
? 'empty'
|
||||
: value == 1
|
||||
? 'lit'
|
||||
: 'crossed out';
|
||||
return Semantics(
|
||||
label:
|
||||
'Row ${row + 1}, column ${col + 1}, $state${fixed ? ', fixed clue' : ''}',
|
||||
button: !fixed && !won,
|
||||
enabled: !fixed && !won,
|
||||
onTap: fixed || won ? null : () => onMark(i),
|
||||
child: SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: value == 1
|
||||
? blue
|
||||
: inside
|
||||
? amber.withValues(alpha: .22)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(
|
||||
2,
|
||||
),
|
||||
border: Border.all(
|
||||
excludeSemantics: true,
|
||||
child: GestureDetector(
|
||||
key: ValueKey('cell-$i'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: fixed || won
|
||||
? null
|
||||
: () => onMark(i),
|
||||
child: SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: inside
|
||||
? const Color(0xffaa5b2a)
|
||||
: muted.withValues(alpha: .48),
|
||||
width: inside ? 1.4 : .65,
|
||||
? amber.withValues(alpha: .22)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(
|
||||
2,
|
||||
),
|
||||
border: Border.all(
|
||||
color: inside
|
||||
? const Color(0xffaa5b2a)
|
||||
: muted.withValues(
|
||||
alpha: .48,
|
||||
),
|
||||
width: inside ? 1.4 : .65,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
if (value == 2)
|
||||
Center(
|
||||
child: Text(
|
||||
'×',
|
||||
style: hand(
|
||||
u * .62,
|
||||
color: muted,
|
||||
child: Stack(
|
||||
children: [
|
||||
if (value != 0)
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: PencilMark(
|
||||
value: value,
|
||||
variation: i,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (fixed)
|
||||
Positioned(
|
||||
right: 3,
|
||||
bottom: 3,
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: value == 1
|
||||
? cream
|
||||
: muted,
|
||||
shape: BoxShape.circle,
|
||||
if (fixed)
|
||||
Positioned(
|
||||
right: 3,
|
||||
bottom: 3,
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: muted,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Deterministic pencil strokes stay put when the player revisits a cell.
|
||||
/// Both marks use paths, so their appearance never depends on a fallback font.
|
||||
class PencilMark extends CustomPainter {
|
||||
const PencilMark({required this.value, required this.variation});
|
||||
final int value, variation;
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final unit = math.min(size.width, size.height);
|
||||
final wobble = ((variation % 5) - 2) * .006;
|
||||
final paint = Paint()
|
||||
..isAntiAlias = true
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeCap = StrokeCap.round
|
||||
..strokeJoin = StrokeJoin.round;
|
||||
canvas.save();
|
||||
canvas.scale(size.width, size.height);
|
||||
if (value == 1) {
|
||||
paint
|
||||
..color = blue.withValues(alpha: .78)
|
||||
..strokeWidth = 1.65 / unit;
|
||||
// Closely spaced, slightly wandering strokes shade the cell by hand.
|
||||
canvas.clipRect(const Rect.fromLTWH(.13, .13, .74, .74));
|
||||
for (var line = -12; line <= 20; line++) {
|
||||
final x = line * .065;
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(x, .90)
|
||||
..quadraticBezierTo(x + .34 + wobble, .52, x + .68, .09),
|
||||
paint,
|
||||
);
|
||||
}
|
||||
paint
|
||||
..color = blue.withValues(alpha: .34)
|
||||
..strokeWidth = .8 / unit;
|
||||
for (var line = -6; line <= 12; line++) {
|
||||
final x = line * .13;
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(x, .12)
|
||||
..quadraticBezierTo(x + .3, .50 + wobble, x + .59, .89),
|
||||
paint,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
paint
|
||||
..color = muted
|
||||
..strokeWidth = 1.8 / unit;
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(.26, .24 + wobble)
|
||||
..cubicTo(.43, .38, .58, .64, .76, .77),
|
||||
paint,
|
||||
);
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(.75, .22)
|
||||
..cubicTo(.61, .42 + wobble, .40, .59, .24, .78),
|
||||
paint,
|
||||
);
|
||||
paint
|
||||
..color = muted.withValues(alpha: .30)
|
||||
..strokeWidth = .65 / unit;
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(.28, .25)
|
||||
..quadraticBezierTo(.54, .56, .74, .79),
|
||||
paint,
|
||||
);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(PencilMark old) =>
|
||||
value != old.value || variation != old.variation;
|
||||
}
|
||||
|
||||
class PixelPicture extends StatelessWidget {
|
||||
const PixelPicture(
|
||||
this.picture, {
|
||||
|
||||
+114
-61
@@ -1,6 +1,7 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
|
||||
const ink = Color(0xff36413c),
|
||||
blue = Color(0xff274956),
|
||||
@@ -31,23 +32,25 @@ class InkButton extends StatelessWidget {
|
||||
final double size;
|
||||
final bool primary;
|
||||
@override
|
||||
Widget build(BuildContext context) => DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(color: blue.withValues(alpha: primary ? .5 : .18)),
|
||||
Widget build(BuildContext context) => PageSwipeBlocker(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(color: blue.withValues(alpha: primary ? .5 : .18)),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: TextButton(
|
||||
onPressed: onPressed,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: blue,
|
||||
disabledForegroundColor: muted.withValues(alpha: .4),
|
||||
textStyle: hand(size),
|
||||
minimumSize: const Size(48, 48),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 8),
|
||||
shape: const RoundedRectangleBorder(),
|
||||
child: TextButton(
|
||||
onPressed: onPressed,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: blue,
|
||||
disabledForegroundColor: muted.withValues(alpha: .4),
|
||||
textStyle: hand(size),
|
||||
minimumSize: const Size(48, 48),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 8),
|
||||
shape: const RoundedRectangleBorder(),
|
||||
),
|
||||
child: Text(label, textAlign: TextAlign.center),
|
||||
),
|
||||
child: Text(label, textAlign: TextAlign.center),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -61,7 +64,8 @@ class Paper extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PaperState extends State<Paper> {
|
||||
Offset? start;
|
||||
Offset _drag = Offset.zero;
|
||||
Offset _origin = Offset.zero;
|
||||
@override
|
||||
Widget build(BuildContext context) => ColoredBox(
|
||||
color: const Color(0xff314345),
|
||||
@@ -91,38 +95,55 @@ class _PaperState extends State<Paper> {
|
||||
top + h * .91,
|
||||
);
|
||||
return Listener(
|
||||
onPointerDown: (e) {
|
||||
start =
|
||||
(e.localPosition.dx < content.left ||
|
||||
e.localPosition.dx > content.right)
|
||||
? e.localPosition
|
||||
: null;
|
||||
onPointerCancel: (_) {
|
||||
_drag = Offset.zero;
|
||||
},
|
||||
onPointerUp: (e) {
|
||||
final origin = start;
|
||||
start = null;
|
||||
if (origin == null) return;
|
||||
final d = e.localPosition - origin;
|
||||
if (d.dx.abs() > 55 && d.dx.abs() > d.dy.abs() * 1.5) {
|
||||
widget.onTurn?.call(d.dx < 0 ? 1 : -1);
|
||||
}
|
||||
},
|
||||
child: Stack(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
children: [
|
||||
Positioned(
|
||||
left: left,
|
||||
top: top,
|
||||
width: w,
|
||||
height: h,
|
||||
child: Image.asset(
|
||||
'assets/artwork/mara-single-page-v2.png',
|
||||
fit: BoxFit.fill,
|
||||
excludeFromSemantics: true,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
dragStartBehavior: DragStartBehavior.down,
|
||||
onHorizontalDragStart: widget.onTurn == null
|
||||
? null
|
||||
: (details) {
|
||||
_origin = details.globalPosition;
|
||||
_drag = Offset.zero;
|
||||
},
|
||||
onHorizontalDragUpdate: widget.onTurn == null
|
||||
? null
|
||||
: (details) {
|
||||
_drag = details.globalPosition - _origin;
|
||||
},
|
||||
onHorizontalDragCancel: widget.onTurn == null
|
||||
? null
|
||||
: () {
|
||||
_drag = Offset.zero;
|
||||
},
|
||||
onHorizontalDragEnd: widget.onTurn == null
|
||||
? null
|
||||
: (_) {
|
||||
final drag = _drag;
|
||||
_drag = Offset.zero;
|
||||
if (drag.dx.abs() >= 48 &&
|
||||
drag.dx.abs() > drag.dy.abs() * 1.3) {
|
||||
widget.onTurn?.call(drag.dx < 0 ? 1 : -1);
|
||||
}
|
||||
},
|
||||
child: Stack(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
children: [
|
||||
Positioned(
|
||||
left: left,
|
||||
top: top,
|
||||
width: w,
|
||||
height: h,
|
||||
child: Image.asset(
|
||||
'assets/artwork/mara-single-page-v2.png',
|
||||
fit: BoxFit.fill,
|
||||
excludeFromSemantics: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned.fromRect(rect: content, child: widget.child),
|
||||
],
|
||||
Positioned.fromRect(rect: content, child: widget.child),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -131,27 +152,59 @@ class _PaperState extends State<Paper> {
|
||||
);
|
||||
}
|
||||
|
||||
/// A descendant horizontal recognizer wins over the page recognizer on drags.
|
||||
/// Taps still reach the controls, and vertical drags can reach a ScrollView.
|
||||
class PageSwipeBlocker extends StatelessWidget {
|
||||
const PageSwipeBlocker({super.key, required this.child});
|
||||
final Widget child;
|
||||
@override
|
||||
Widget build(BuildContext context) => GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onHorizontalDragStart: (_) {},
|
||||
onHorizontalDragUpdate: (_) {},
|
||||
onHorizontalDragEnd: (_) {},
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
class Leaf extends StatelessWidget {
|
||||
const Leaf({super.key, required this.body, this.footer, this.onTurn});
|
||||
const Leaf({
|
||||
super.key,
|
||||
required this.body,
|
||||
this.wideBody,
|
||||
this.footer,
|
||||
this.onTurn,
|
||||
});
|
||||
final Widget body;
|
||||
|
||||
/// Replaces [body] on a landscape page. The shorter page suits side-by-side
|
||||
/// columns better than one long scroll, so it should arrange its own panes.
|
||||
final Widget? wideBody;
|
||||
final Widget? footer;
|
||||
final ValueChanged<int>? onTurn;
|
||||
@override
|
||||
Widget build(BuildContext context) => Paper(
|
||||
onTurn: onTurn,
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
key: const PageStorageKey('leaf-scroll'),
|
||||
padding: const EdgeInsets.fromLTRB(4, 0, 4, 8),
|
||||
child: body,
|
||||
Widget build(BuildContext context) {
|
||||
final wide =
|
||||
wideBody != null &&
|
||||
MediaQuery.orientationOf(context) == Orientation.landscape;
|
||||
return Paper(
|
||||
onTurn: onTurn,
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: wide
|
||||
? wideBody!
|
||||
: SingleChildScrollView(
|
||||
key: const PageStorageKey('leaf-scroll'),
|
||||
padding: const EdgeInsets.fromLTRB(4, 0, 4, 8),
|
||||
child: body,
|
||||
),
|
||||
),
|
||||
),
|
||||
?footer,
|
||||
],
|
||||
),
|
||||
);
|
||||
?footer,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Cover extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user