399 lines
16 KiB
Dart
399 lines
16 KiB
Dart
import 'dart:ui' as ui;
|
||
|
||
import 'package:flutter/material.dart';
|
||
|
||
import '../domain/game.dart';
|
||
import '../domain/postcards.dart';
|
||
import '../services/browser_assets.dart';
|
||
import 'translation.dart';
|
||
|
||
/// A saved memory comes into focus and regains its colour.
|
||
class PostcardRevealArt extends StatelessWidget {
|
||
const PostcardRevealArt({super.key, required this.card});
|
||
final IslandPostcard card;
|
||
|
||
@override
|
||
Widget build(BuildContext context) => TweenAnimationBuilder<double>(
|
||
tween: Tween(begin: 0, end: 1),
|
||
duration: MediaQuery.disableAnimationsOf(context)
|
||
? Duration.zero
|
||
: const Duration(milliseconds: 1800),
|
||
curve: Curves.easeInOut,
|
||
child: Image.asset(
|
||
artworkAsset(card.illustrationAsset),
|
||
fit: BoxFit.cover,
|
||
semanticLabel: 'Watercolour illustration for ${card.title}',
|
||
),
|
||
builder: (context, progress, child) {
|
||
final faded = 1 - progress;
|
||
return ClipRect(
|
||
child: ColorFiltered(
|
||
key: const ValueKey('postcard-reveal-color'),
|
||
colorFilter: ColorFilter.matrix([
|
||
.2126 * faded + progress,
|
||
.7152 * faded,
|
||
.0722 * faded,
|
||
0,
|
||
0,
|
||
.2126 * faded,
|
||
.7152 * faded + progress,
|
||
.0722 * faded,
|
||
0,
|
||
0,
|
||
.2126 * faded,
|
||
.7152 * faded,
|
||
.0722 * faded + progress,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
1,
|
||
0,
|
||
]),
|
||
child: ImageFiltered(
|
||
imageFilter: ui.ImageFilter.blur(
|
||
sigmaX: 7 * faded,
|
||
sigmaY: 7 * faded,
|
||
),
|
||
enabled: progress < 1,
|
||
child: child,
|
||
),
|
||
),
|
||
);
|
||
},
|
||
);
|
||
}
|
||
|
||
class ShelfActivities extends StatelessWidget {
|
||
const ShelfActivities({
|
||
super.key,
|
||
required this.game,
|
||
required this.onPostcards,
|
||
});
|
||
final Game game;
|
||
final VoidCallback onPostcards;
|
||
|
||
@override
|
||
Widget build(BuildContext context) => Container(
|
||
key: const ValueKey('shelf-activities'),
|
||
margin: const EdgeInsets.only(bottom: 32),
|
||
padding: const EdgeInsets.all(20),
|
||
decoration: BoxDecoration(
|
||
color: const Color(0xffe5ebe2),
|
||
borderRadius: BorderRadius.circular(12),
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
const CopyText(
|
||
'A little light, every day',
|
||
style: TextStyle(fontFamily: 'serif', fontSize: 27),
|
||
),
|
||
const SizedBox(height: 8),
|
||
CopyText(
|
||
game.todaySolved
|
||
? 'Today’s pattern is complete. Your next daily puzzle arrives tomorrow.'
|
||
: 'One fresh daily pattern, or a short walk around Mara’s island.',
|
||
style: const TextStyle(fontFamily: 'sans-serif', fontSize: 15),
|
||
),
|
||
const SizedBox(height: 12),
|
||
SizedBox(
|
||
width: double.infinity,
|
||
child: FilledButton.icon(
|
||
key: const ValueKey('shelf-daily'),
|
||
onPressed: () => game.startDaily(DateTime.now()),
|
||
style: FilledButton.styleFrom(
|
||
minimumSize: const Size(0, 64),
|
||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||
),
|
||
icon: Icon(
|
||
game.todaySolved ? Icons.check : Icons.wb_sunny_outlined,
|
||
size: 24,
|
||
),
|
||
label: CopyText(
|
||
game.todaySolved ? 'Revisit today’s puzzle' : 'Today’s puzzle',
|
||
style: const TextStyle(
|
||
fontFamily: 'sans-serif',
|
||
fontSize: 20,
|
||
fontWeight: FontWeight.w600,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(height: 12),
|
||
SizedBox(
|
||
width: double.infinity,
|
||
child: OutlinedButton.icon(
|
||
key: const ValueKey('shelf-postcards'),
|
||
onPressed: onPostcards,
|
||
style: OutlinedButton.styleFrom(
|
||
minimumSize: const Size(0, 64),
|
||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||
),
|
||
icon: const Icon(Icons.local_post_office_outlined, size: 24),
|
||
label: const CopyText(
|
||
'Island postcards',
|
||
style: TextStyle(
|
||
fontFamily: 'sans-serif',
|
||
fontSize: 20,
|
||
fontWeight: FontWeight.w600,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(height: 8),
|
||
CopyText(
|
||
'${game.postcardsCollected} / 14 postcards collected',
|
||
style: const TextStyle(fontFamily: 'sans-serif', fontSize: 13),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
class PostcardCollectionView extends StatelessWidget {
|
||
const PostcardCollectionView({
|
||
super.key,
|
||
required this.game,
|
||
required this.onBack,
|
||
required this.onOpen,
|
||
required this.onRead,
|
||
});
|
||
final Game game;
|
||
final VoidCallback onBack;
|
||
final ValueChanged<int> onOpen, onRead;
|
||
|
||
@override
|
||
Widget build(BuildContext context) => ColoredBox(
|
||
color: const Color(0xfff6f1e7),
|
||
child: SafeArea(
|
||
child: SingleChildScrollView(
|
||
key: const ValueKey('postcard-collection'),
|
||
padding: const EdgeInsets.all(24),
|
||
child: Center(
|
||
child: ConstrainedBox(
|
||
constraints: const BoxConstraints(maxWidth: 760),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
children: [
|
||
Align(
|
||
alignment: Alignment.centerLeft,
|
||
child: TextButton.icon(
|
||
onPressed: onBack,
|
||
icon: const Icon(Icons.arrow_back),
|
||
label: const CopyText('Back to the shelf'),
|
||
),
|
||
),
|
||
const SizedBox(height: 16),
|
||
const CopyText(
|
||
'Island postcards',
|
||
style: TextStyle(fontFamily: 'serif', fontSize: 36),
|
||
),
|
||
const SizedBox(height: 12),
|
||
const CopyText(
|
||
'Fourteen small outings after the lighthouse story. Solve three patterns to keep each postcard. Take them at your own pace; nothing expires.',
|
||
style: TextStyle(fontFamily: 'sans-serif', fontSize: 16),
|
||
),
|
||
const SizedBox(height: 8),
|
||
const CopyText(
|
||
'Illustrated postcards · English · Recorded readings',
|
||
style: TextStyle(fontFamily: 'sans-serif', fontSize: 13),
|
||
),
|
||
const SizedBox(height: 16),
|
||
CopyText('${game.postcardsCollected} / 14 postcards collected'),
|
||
if (game.store.contains('postcard_last') &&
|
||
game.postcardSolved(
|
||
game.store.number('postcard_last').clamp(0, 13),
|
||
) <
|
||
3)
|
||
Padding(
|
||
padding: const EdgeInsets.only(top: 12),
|
||
child: FilledButton(
|
||
onPressed: () => onOpen(
|
||
game.store.number('postcard_last').clamp(0, 13),
|
||
),
|
||
child: const CopyText('Continue your outing'),
|
||
),
|
||
),
|
||
const SizedBox(height: 20),
|
||
for (var i = 0; i < islandPostcards.length; i++)
|
||
Semantics(
|
||
key: ValueKey('postcard-$i'),
|
||
button: true,
|
||
label:
|
||
'${islandPostcards[i].title}, ${game.postcardSolved(i)} of 3 patterns found. ${game.postcardSolved(i) == 3
|
||
? 'Read your postcard'
|
||
: game.postcardSolved(i) == 0
|
||
? 'Begin outing'
|
||
: 'Continue outing'}',
|
||
onTap: () =>
|
||
game.postcardSolved(i) == 3 ? onRead(i) : onOpen(i),
|
||
excludeSemantics: true,
|
||
child: Material(
|
||
color: Colors.transparent,
|
||
child: InkWell(
|
||
excludeFromSemantics: true,
|
||
onTap: () =>
|
||
game.postcardSolved(i) == 3 ? onRead(i) : onOpen(i),
|
||
child: Container(
|
||
margin: const EdgeInsets.only(bottom: 24),
|
||
padding: const EdgeInsets.all(9),
|
||
decoration: BoxDecoration(
|
||
color: const Color(0xfffffbef),
|
||
border: Border.all(color: const Color(0xffd2bf9c)),
|
||
boxShadow: const [
|
||
BoxShadow(
|
||
color: Color(0x253c3124),
|
||
blurRadius: 9,
|
||
offset: Offset(2, 4),
|
||
),
|
||
],
|
||
),
|
||
child: Column(
|
||
children: [
|
||
AspectRatio(
|
||
aspectRatio: 1.7,
|
||
child: Stack(
|
||
fit: StackFit.expand,
|
||
children: [
|
||
ColorFiltered(
|
||
key: ValueKey('postcard-art-$i'),
|
||
colorFilter: ColorFilter.matrix(
|
||
game.postcardSolved(i) == 3
|
||
? const <double>[
|
||
1,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
1,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
1,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
1,
|
||
0,
|
||
]
|
||
: const <double>[
|
||
.2126,
|
||
.7152,
|
||
.0722,
|
||
0,
|
||
0,
|
||
.2126,
|
||
.7152,
|
||
.0722,
|
||
0,
|
||
0,
|
||
.2126,
|
||
.7152,
|
||
.0722,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
1,
|
||
0,
|
||
],
|
||
),
|
||
child: ClipRect(
|
||
child: ImageFiltered(
|
||
key: ValueKey('postcard-blur-$i'),
|
||
enabled: game.postcardSolved(i) < 3,
|
||
imageFilter: ui.ImageFilter.blur(
|
||
sigmaX: 7,
|
||
sigmaY: 7,
|
||
tileMode: TileMode.decal,
|
||
),
|
||
child: Image.asset(
|
||
artworkAsset(
|
||
islandPostcards[i]
|
||
.illustrationAsset,
|
||
),
|
||
fit: BoxFit.cover,
|
||
semanticLabel:
|
||
game.postcardSolved(i) == 3
|
||
? 'Watercolour illustration for ${islandPostcards[i].title}'
|
||
: 'Postcard artwork locked until all three patterns are solved',
|
||
),
|
||
),
|
||
),
|
||
),
|
||
if (game.postcardSolved(i) < 3)
|
||
const Center(
|
||
child: DecoratedBox(
|
||
decoration: BoxDecoration(
|
||
color: Color(0xaa243a38),
|
||
shape: BoxShape.circle,
|
||
),
|
||
child: Padding(
|
||
padding: EdgeInsets.all(12),
|
||
child: Icon(
|
||
Icons.lock_outline,
|
||
color: Colors.white,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
Padding(
|
||
padding: const EdgeInsets.fromLTRB(
|
||
12,
|
||
16,
|
||
12,
|
||
12,
|
||
),
|
||
child: Column(
|
||
crossAxisAlignment:
|
||
CrossAxisAlignment.stretch,
|
||
children: [
|
||
Text(
|
||
'${i + 1}. ${islandPostcards[i].title}',
|
||
style: const TextStyle(
|
||
fontFamily: 'MaraHand',
|
||
fontSize: 28,
|
||
),
|
||
),
|
||
const SizedBox(height: 8),
|
||
Text(
|
||
islandPostcards[i].invitation,
|
||
style: const TextStyle(
|
||
fontFamily: 'MaraHand',
|
||
fontSize: 21,
|
||
height: 1.3,
|
||
),
|
||
),
|
||
const SizedBox(height: 12),
|
||
CopyText(
|
||
'${game.postcardSolved(i)} / 3 patterns found',
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|