diff --git a/firka/assets/images/epic_grades/star_large.svg b/firka/assets/images/epic_grades/star_large.svg new file mode 100644 index 00000000..c0a5e6ab --- /dev/null +++ b/firka/assets/images/epic_grades/star_large.svg @@ -0,0 +1,3 @@ + + + diff --git a/firka/assets/images/epic_grades/star_medium.svg b/firka/assets/images/epic_grades/star_medium.svg new file mode 100644 index 00000000..0316ff15 --- /dev/null +++ b/firka/assets/images/epic_grades/star_medium.svg @@ -0,0 +1,3 @@ + + + diff --git a/firka/assets/images/epic_grades/star_small.svg b/firka/assets/images/epic_grades/star_small.svg new file mode 100644 index 00000000..a76e0220 --- /dev/null +++ b/firka/assets/images/epic_grades/star_small.svg @@ -0,0 +1,3 @@ + + + diff --git a/firka/codegen-lock.yaml b/firka/codegen-lock.yaml index e7d1ca36..5fe5a146 100644 --- a/firka/codegen-lock.yaml +++ b/firka/codegen-lock.yaml @@ -1,15 +1,15 @@ icons: "flutter_launcher_icons.yaml": "c600507ca0df7cebd0f708124842512a14ed3d597b779176200d6ba25b1335b1" - "pubspec.yaml": "d0f795bcffd597e260202b29476fc99caa3bb4aac5abd48a210cadb9f45c19e7" + "pubspec.yaml": "dbb15aa3301f9f021134e6705847dfbc5149df751d698ba79e3b01da03e12353" "assets/images/logos/colored_logo.webp": "4b4fa99d144fe6694aa4487ba1b26aeecafae41e3c877836cd7da28d61a77983" "assets/images/logos/monochrome_logo.png": "188d2b0a64c70323b09bcee721663d6698fb557066f20ddaec97bba6869c1c6c" "assets/images/logos/colored_logo_without_mustache.png": "d11cff9f38985885873bfdd2d84e61f8fab03803eada94d4caac1545ef3685f3" "assets/images/logos/colored_logo_only_mustache.png": "bad6220c11bdfb1dfe04e5173bd2ebedd3999689d4b3a68fc63dc520c96dd33b" l10n: "l10n.yml": "a57bc304cac4a2b0235593586f17f400a5165d67fc9aadeaa11893cfa36ee082" - "lib/l10n/app_de.arb": "125070dd8de963b7e3b91196c4e94c4d18404a4013fd3bd41a43b92ec9109fc9" - "lib/l10n/app_hu.arb": "90bffe2a339abbc9ece90a19d2fac0c56f07f2f54c713e45fb710c9a09dc01a6" - "lib/l10n/app_en.arb": "f1898853cf2503aaf28f79640a4ed81dd8ce9b156d8a618d2492550ecc7c3f24" + "lib/l10n/app_de.arb": "acaa77af7b19d9ea479bd876245d76b3079d05ce05f51db7a8300ea17dd68907" + "lib/l10n/app_hu.arb": "63bfe9901b9fc233940de5bd1e9a714e4cbe91638861d0f2591df22e3bd8e91f" + "lib/l10n/app_en.arb": "828c1536f650fb5240d511d32b2f89f8dca84576dfadc3626edb79fcd39887c9" "lib/l10n/app_pl.arb": "a8426455757e587c7635c3a62c650a4aae2a0cac1de1175e8ab7fb0d3b387537" isar: "lib/data/models/app_settings_model.dart": "5eb5af345f1347f104257f0999763650fe2673f9da1754bd12d3f756fe5c9723" diff --git a/firka/lib/ui/phone/screens/debug/debug_screen.dart b/firka/lib/ui/phone/screens/debug/debug_screen.dart index fefd70dd..39e1e90e 100644 --- a/firka/lib/ui/phone/screens/debug/debug_screen.dart +++ b/firka/lib/ui/phone/screens/debug/debug_screen.dart @@ -23,10 +23,12 @@ import 'package:firka/core/debug_helper.dart'; import 'package:firka/core/settings/settings_repository.dart'; import 'package:firka/core/settings/settings_schema.dart'; import 'package:firka/core/state/firka_state.dart'; +import 'package:firka/ui/phone/screens/epic_grades/epic_grades_screen.dart'; import 'package:firka/ui/shared/firka_icon.dart'; import 'package:firka/ui/theme/style.dart'; import 'package:flutter/services.dart'; import 'package:home_widget/home_widget.dart'; +import 'package:isar_community/isar.dart'; import 'package:path/path.dart' as p; import 'package:path_provider/path_provider.dart'; @@ -253,6 +255,60 @@ class _DebugScreen extends FirkaState { }, child: const Text('getGrades()'), ), + ElevatedButton( + onPressed: () { + final grades = widget.data.isar.gradeCacheModels + .where() + .findAllSync(); + + if (grades.isEmpty) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('no new grades uwu')), + ); + return; + } + + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => + EpicGradesScreen(grades, widget.data.l10n), + ), + ); + }, + child: const Text('Epikus jegyszerzés'), + ), + ElevatedButton( + onPressed: () { + final grades = widget.data.isar.gradeCacheModels + .where() + .findAllSync(); + + if (grades.isEmpty) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('no new grades uwu')), + ); + return; + } + + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => + EpicCardFaceDebugScreen(grades.first, widget.data.l10n), + ), + ); + }, + child: const Text('Epikus jegyszerzés (card face debug)'), + ), + ElevatedButton( + onPressed: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => const EpicParticleDebugScreen(), + ), + ); + }, + child: const Text('Epikus jegyszerzés (particle debug)'), + ), ElevatedButton( onPressed: () async { var now = timeNow(); diff --git a/firka/lib/ui/phone/screens/epic_grades/epic_grades_screen.dart b/firka/lib/ui/phone/screens/epic_grades/epic_grades_screen.dart new file mode 100644 index 00000000..447d34b0 --- /dev/null +++ b/firka/lib/ui/phone/screens/epic_grades/epic_grades_screen.dart @@ -0,0 +1,1172 @@ +import "dart:async"; +import "dart:math"; + +import "package:firka/core/extensions.dart"; +import "package:firka/l10n/app_localizations.dart"; +import "package:firka/ui/theme/style.dart"; +import "package:firka_common/data/models/grade_cache_model.dart"; +import "package:firka_common/data/models/subject_cache_model.dart"; +import "package:firka_common/data/util.dart"; +import "package:firka_common/ui/components/grade.dart"; +import "package:firka_common/ui/shared/class_icon.dart"; +import "package:flutter/material.dart"; +import "package:flutter_svg/flutter_svg.dart"; +import "package:majesticons_flutter/majesticons_flutter.dart"; +import "package:vibration/vibration.dart"; + +const _starLarge = "assets/images/epic_grades/star_large.svg"; +const _starMedium = "assets/images/epic_grades/star_medium.svg"; +const _starSmall = "assets/images/epic_grades/star_small.svg"; +const _gradeEmojis = {5: "🏆", 4: "😃", 3: "😐", 2: "😬", 1: "💩"}; +const _flipDuration = Duration(milliseconds: 1000); + +String _gradeEmoji(int? value) => _gradeEmojis[value] ?? "✨"; + +String _rankLabel( + AppLocalizations l10n, + List allGrades, + int value, +) { + final numeric = allGrades.map((g) => g.numericValue).whereType(); + final total = numeric.length; + final matching = numeric.where((v) => v == value).length; + final fraction = total == 0 ? 0.0 : matching / total; + + if (fraction < 0.10) return l10n.epic_grade_rank_5; + if (fraction < 0.25) return l10n.epic_grade_rank_4; + if (fraction < 0.45) return l10n.epic_grade_rank_3; + if (fraction < 0.70) return l10n.epic_grade_rank_2; + return l10n.epic_grade_rank_1; +} + +(Alignment, double) _pickCardEdge(Random rand) { + final edge = rand.nextInt(4); + final jitter = rand.nextDouble() * 2 - 1; + switch (edge) { + case 0: + return (Alignment(jitter, -1), -pi / 2); + case 1: + return (Alignment(1, jitter), 0); + case 2: + return (Alignment(jitter, 1), pi / 2); + default: + return (Alignment(-1, jitter), pi); + } +} + +String _describeGradeWeight(AppLocalizations l10n, GradeCacheModel grade) { + final weight = grade.weightPercentage; + if (weight == null) return grade.type; + + final weightText = switch (weight) { + 100 => l10n.grade_weight_x1, + 200 => l10n.grade_weight_x2, + 300 => l10n.grade_weight_x3, + 400 => l10n.grade_weight_x4, + 500 => l10n.grade_weight_x5, + _ => l10n.grade_weight_percent(weight), + }; + + return grade.type.isEmpty ? weightText : "${grade.type}, $weightText"; +} + +class EpicGradesScreen extends StatefulWidget { + final List grades; + final AppLocalizations l10n; + + const EpicGradesScreen(this.grades, this.l10n, {super.key}); + + @override + State createState() => _EpicGradesScreenState(); +} + +class _EpicGradesScreenState extends State { + int _page = 0; + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: appStyle.colors.background, + body: SafeArea( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(20, 12, 20, 0), + child: GestureDetector( + onTap: () => Navigator.of(context).pop(), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Majesticon( + Majesticon.chevronLeftLine, + color: appStyle.colors.textPrimary, + size: 20, + ), + const SizedBox(width: 6), + Text( + "Főoldal", + style: appStyle.fonts.B_16R.apply( + color: appStyle.colors.textPrimary, + ), + ), + ], + ), + ), + ), + const SizedBox(height: 12), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Text( + "Új jegyek!", + style: appStyle.fonts.H_H2.apply( + color: appStyle.colors.textPrimary, + ), + ), + ), + const SizedBox(height: 16), + Expanded( + child: Container( + margin: const EdgeInsets.symmetric(horizontal: 20), + decoration: BoxDecoration( + color: appStyle.colors.a15p, + borderRadius: BorderRadius.circular(20), + ), + child: _CardDeck( + grades: widget.grades, + l10n: widget.l10n, + onIndexChanged: (i) => setState(() => _page = i), + ), + ), + ), + const SizedBox(height: 16), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: List.generate(widget.grades.length, (i) { + final active = i == _page; + return AnimatedContainer( + duration: const Duration(milliseconds: 200), + margin: const EdgeInsets.symmetric(horizontal: 4), + width: active ? 10 : 8, + height: active ? 10 : 8, + decoration: BoxDecoration( + color: active + ? appStyle.colors.accent + : appStyle.colors.accent.withAlpha(90), + shape: BoxShape.circle, + ), + ); + }), + ), + const SizedBox(height: 16), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Text( + "Tartsd lenyomva a kártyát, hogy megfordítsd.", + textAlign: TextAlign.center, + style: appStyle.fonts.B_16R.apply( + color: appStyle.colors.textPrimary, + ), + ), + ), + const SizedBox(height: 20), + ], + ), + ), + ); + } +} + +class _CardDeck extends StatefulWidget { + final List grades; + final AppLocalizations l10n; + final ValueChanged onIndexChanged; + + const _CardDeck({ + required this.grades, + required this.l10n, + required this.onIndexChanged, + }); + + @override + State<_CardDeck> createState() => _CardDeckState(); +} + +class _CardDeckState extends State<_CardDeck> with TickerProviderStateMixin { + static const _cardWidth = 240.0; + static const _cardHeight = 300.0; + static const _swipeThreshold = 90.0; + static const _peekVisibleSliver = 40.0; + static const _peekCornerAngle = 8 * pi / 180; + static const _dragSlop = 20.0; + static const _holdDuration = Duration(milliseconds: 2000); + static const _chargeVibrateMs = 20; + static const _chargeWaitStartMs = 100.0; + static const _chargeWaitEndMs = 2.0; + static const _chargePatternMarginMs = 400; + static const _sprayCount = 30; + static const _sprayLifespanFraction = 0.12; + static const _shakeMaxAmplitude = 8.0; + + double get _restOffset => + (MediaQuery.sizeOf(context).width + _cardWidth) / 2 - + _peekVisibleSliver; + static const _shakeTuningSpanMs = 2400.0; + static const _shakeRateDx = 113 / _shakeTuningSpanMs; + static const _shakeRateDy = 97 / _shakeTuningSpanMs; + static const _shakeRateAngle = 131 / _shakeTuningSpanMs; + + static final (List, List) _chargePattern = _buildChargePattern(); + + static (List, List) _buildChargePattern() { + final pattern = [0]; + final intensities = [0]; + final totalMs = _holdDuration.inMilliseconds + _chargePatternMarginMs; + var elapsedMs = 0; + while (elapsedMs < totalMs) { + final t = (elapsedMs / _holdDuration.inMilliseconds).clamp(0.0, 1.0); + final eased = 1 - pow(1 - t, 6).toDouble(); + final wait = + (_chargeWaitStartMs + (_chargeWaitEndMs - _chargeWaitStartMs) * eased) + .round(); + final strength = (70 + 185 * eased).round().clamp(1, 255); + pattern.add(_chargeVibrateMs); + intensities.add(strength); + pattern.add(wait); + intensities.add(0); + elapsedMs += _chargeVibrateMs + wait; + } + return (pattern, intensities); + } + + late final _settleController = AnimationController( + vsync: this, + duration: const Duration(milliseconds: 320), + ); + late final _shakeController = AnimationController( + vsync: this, + duration: _holdDuration, + ); + final _flipKey = GlobalKey<_EpicFlipCardState>(); + final _rand = Random(); + + int _index = 0; + double _dragDx = 0; + double _settleFrom = 0; + double _settleTo = 0; + + Timer? _holdTimer; + double _pressStartX = 0; + bool _holdCancelled = false; + int _burstTrigger = 0; + int _revealBurstTrigger = 0; + String _revealEmoji = ""; + List<_SprayParticle> _sprayParticles = []; + final Set _revealedIndices = {}; + + @override + void initState() { + super.initState(); + _settleController.addListener(() { + final t = Curves.easeOut.transform(_settleController.value); + setState(() { + _dragDx = _settleFrom + (_settleTo - _settleFrom) * t; + }); + }); + } + + @override + void dispose() { + _holdTimer?.cancel(); + _settleController.dispose(); + _shakeController.dispose(); + super.dispose(); + } + + List<_SprayParticle> _generateSprayParticles() { + return List.generate(_sprayCount, (i) { + final (origin, normalAngle) = _pickCardEdge(_rand); + final spread = (_rand.nextDouble() - 0.5) * (pi / 2.5); + final distance = 40.0 + _rand.nextDouble() * 60; + final value = 1 + _rand.nextInt(5); + final spawnFraction = + (i / _sprayCount + (_rand.nextDouble() - 0.5) * 0.02).clamp( + 0.0, + 1 - _sprayLifespanFraction, + ); + return _SprayParticle( + origin: origin, + angle: normalAngle + spread, + distance: distance, + value: value, + spawnFraction: spawnFraction, + lifespanFraction: _sprayLifespanFraction, + ); + }); + } + + void _onPointerDown(PointerDownEvent event) { + _pressStartX = event.position.dx; + _holdCancelled = false; + if (_flipKey.currentState?.isRevealed ?? false) { + return; + } + setState(() { + _burstTrigger++; + _sprayParticles = _generateSprayParticles(); + }); + final (pattern, intensities) = _chargePattern; + Vibration.vibrate(pattern: pattern, intensities: intensities); + _shakeController.forward(from: 0); + _holdTimer = Timer(_holdDuration, () { + _holdTimer = null; + Vibration.cancel(); + Vibration.vibrate(duration: 28, amplitude: 200); + _shakeController.value = 0; + _flipKey.currentState?.flip(); + }); + } + + void _cancelHold() { + _holdTimer?.cancel(); + _holdTimer = null; + Vibration.cancel(); + _shakeController.stop(); + _shakeController.value = 0; + } + + void _onPointerMove(PointerMoveEvent event) { + if (!_holdCancelled && + (event.position.dx - _pressStartX).abs() > _dragSlop) { + _holdCancelled = true; + _cancelHold(); + } + if (_holdCancelled) { + final revealed = _flipKey.currentState?.isRevealed ?? false; + setState(() { + final updated = _dragDx + event.delta.dx; + _dragDx = revealed + ? updated.clamp(-_restOffset, _restOffset) + : updated.clamp(0.0, _restOffset); + }); + } + } + + void _onPointerUp(PointerUpEvent event) { + if (!_holdCancelled) { + _cancelHold(); + return; + } + _holdTimer?.cancel(); + _holdTimer = null; + _finishDrag(); + } + + void _onPointerCancel(PointerCancelEvent event) { + final wasDragging = _holdCancelled; + _cancelHold(); + if (wasDragging) _finishDrag(); + } + + void _finishDrag() { + final canAdvance = + _dragDx < -_swipeThreshold && _index < widget.grades.length - 1; + final canRecede = _dragDx > _swipeThreshold && _index > 0; + + if (canAdvance) { + _animateSettle(target: -_restOffset, onDone: () => _advance(1)); + } else if (canRecede) { + _animateSettle(target: _restOffset, onDone: () => _advance(-1)); + } else { + _animateSettle(target: 0, onDone: () {}); + } + } + + void _advance(int direction) { + setState(() { + _index += direction; + _dragDx = 0; + }); + widget.onIndexChanged(_index); + Vibration.vibrate(duration: 25, amplitude: 110); + } + + void _animateSettle({required double target, required VoidCallback onDone}) { + _settleFrom = _dragDx; + _settleTo = target; + _settleController.forward(from: 0).whenComplete(onDone); + } + + @override + Widget build(BuildContext context) { + final progress = (-_dragDx / _cardWidth).clamp(-1.0, 1.0); + final next = _index + 1 < widget.grades.length + ? widget.grades[_index + 1] + : null; + final prev = _index > 0 ? widget.grades[_index - 1] : null; + + final restOffset = _restOffset; + + return SizedBox.expand( + child: Listener( + onPointerDown: _onPointerDown, + onPointerMove: _onPointerMove, + onPointerUp: _onPointerUp, + onPointerCancel: _onPointerCancel, + child: Stack( + alignment: Alignment.center, + clipBehavior: Clip.none, + children: [ + AnimatedBuilder( + animation: _shakeController, + builder: (context, child) { + final shakeT = _shakeController.value; + final elapsedMs = shakeT * _holdDuration.inMilliseconds; + final amplitude = + _shakeMaxAmplitude * (1 / 3 + 2 / 3 * shakeT * shakeT); + final shakeDx = sin(elapsedMs * _shakeRateDx) * amplitude; + final shakeDy = cos(elapsedMs * _shakeRateDy) * amplitude * 0.5; + final shakeAngle = + sin(elapsedMs * _shakeRateAngle) * 0.03 * shakeT * shakeT; + return Transform.translate( + offset: Offset(_dragDx + shakeDx, shakeDy), + child: Transform.rotate( + angle: (_dragDx / _restOffset) * _peekCornerAngle + shakeAngle, + child: child, + ), + ); + }, + child: SizedBox( + width: _cardWidth, + height: _cardHeight, + child: _EpicFlipCard( + key: _flipKey, + grade: widget.grades[_index], + allGrades: widget.grades, + l10n: widget.l10n, + initiallyRevealed: _revealedIndices.contains(_index), + onRevealed: () { + final revealedGrade = widget.grades[_index]; + setState(() => _revealedIndices.add(_index)); + Future.delayed(_flipDuration, () { + if (!mounted) return; + setState(() { + _revealEmoji = _gradeEmoji(revealedGrade.numericValue); + _revealBurstTrigger++; + }); + }); + }, + ), + ), + ), + if (next != null) + _buildPeek( + next, + progress: progress, + fromRight: true, + restOffset: restOffset, + isRevealed: _revealedIndices.contains(_index + 1), + ), + if (prev != null) + _buildPeek( + prev, + progress: progress, + fromRight: false, + restOffset: restOffset, + isRevealed: _revealedIndices.contains(_index - 1), + ), + if (_burstTrigger > 0) + AnimatedBuilder( + animation: _shakeController, + builder: (context, child) => _HoldSpray( + progress: _shakeController.value, + particles: _sprayParticles, + ), + ), + if (_revealBurstTrigger > 0) + IgnorePointer( + child: SizedBox( + width: _cardWidth, + height: _cardHeight, + child: _RevealEmojiBurst( + key: ValueKey(_revealBurstTrigger), + emoji: _revealEmoji, + ), + ), + ), + ], + ), + ), + ); + } + + Widget _buildPeek( + GradeCacheModel grade, { + required double progress, + required bool fromRight, + required double restOffset, + required bool isRevealed, + }) { + final side = fromRight ? 1.0 : -1.0; + final tt = (fromRight ? progress : -progress).clamp(0.0, 1.0); + final dx = restOffset * (side - progress); + final angle = _peekCornerAngle * (1 - tt) * side; + + return Transform.translate( + offset: Offset(dx, 0), + child: Transform.rotate( + angle: angle, + child: SizedBox( + width: _cardWidth, + height: _cardHeight, + child: IgnorePointer( + child: isRevealed + ? _EpicCardFace.back(grade, widget.grades, widget.l10n) + : _EpicCardFace.front(grade, widget.grades, widget.l10n), + ), + ), + ), + ); + } +} + +class _EpicFlipCard extends StatefulWidget { + final GradeCacheModel grade; + final List allGrades; + final AppLocalizations l10n; + final bool initiallyRevealed; + final VoidCallback onRevealed; + + const _EpicFlipCard({ + required this.grade, + required this.allGrades, + required this.l10n, + required this.initiallyRevealed, + required this.onRevealed, + super.key, + }); + + @override + State<_EpicFlipCard> createState() => _EpicFlipCardState(); +} + +class _EpicFlipCardState extends State<_EpicFlipCard> + with SingleTickerProviderStateMixin { + late final AnimationController _controller; + bool _showFront = true; + + bool get isRevealed => !_showFront; + + @override + void initState() { + super.initState(); + _controller = AnimationController(vsync: this, duration: _flipDuration); + if (widget.initiallyRevealed) { + _showFront = false; + _controller.value = 1; + } + } + + @override + void didUpdateWidget(covariant _EpicFlipCard oldWidget) { + super.didUpdateWidget(oldWidget); + if (widget.grade != oldWidget.grade) { + _showFront = !widget.initiallyRevealed; + _controller.value = widget.initiallyRevealed ? 1 : 0; + } + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + void flip() { + if (!_showFront) return; + setState(() => _showFront = false); + _controller.forward(); + widget.onRevealed(); + } + + @override + Widget build(BuildContext context) { + return AnimatedBuilder( + animation: _controller, + builder: (context, child) { + final angle = _controller.value * pi; + final isBack = angle > pi / 2; + final displayAngle = isBack ? angle - pi : angle; + return Transform( + alignment: Alignment.center, + transform: Matrix4.identity() + ..setEntry(3, 2, 0.001) + ..rotateY(displayAngle), + child: isBack + ? _EpicCardFace.back(widget.grade, widget.allGrades, widget.l10n) + : _EpicCardFace.front( + widget.grade, + widget.allGrades, + widget.l10n, + ), + ); + }, + ); + } +} + +class _TexturedGridBox extends StatelessWidget { + final Widget? child; + + const _TexturedGridBox({this.child}); + + @override + Widget build(BuildContext context) { + return Container( + decoration: BoxDecoration( + border: Border.all(color: appStyle.colors.accent), + borderRadius: BorderRadius.circular(24), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(23), + child: CustomPaint( + painter: _GridPainter(appStyle.colors.accent.withAlpha(46)), + child: SizedBox.expand(child: child), + ), + ), + ); + } +} + +class _GridPainter extends CustomPainter { + final Color color; + + const _GridPainter(this.color); + + static const _cellSize = 24.0; + + @override + void paint(Canvas canvas, Size size) { + final paint = Paint() + ..color = color + ..strokeWidth = 1; + + for (double x = 0; x <= size.width; x += _cellSize) { + canvas.drawLine(Offset(x, 0), Offset(x, size.height), paint); + } + for (double y = 0; y <= size.height; y += _cellSize) { + canvas.drawLine(Offset(0, y), Offset(size.width, y), paint); + } + } + + @override + bool shouldRepaint(covariant _GridPainter oldDelegate) => + oldDelegate.color != color; +} + +class _EpicCardFace extends StatelessWidget { + final GradeCacheModel grade; + final List allGrades; + final AppLocalizations l10n; + final bool isBack; + + const _EpicCardFace.front(this.grade, this.allGrades, this.l10n) + : isBack = false; + const _EpicCardFace.back(this.grade, this.allGrades, this.l10n) + : isBack = true; + + @override + Widget build(BuildContext context) { + final subject = grade.subject.loadAndGet(); + final headline = (grade.topic ?? grade.type).firstUpper(); + + return Container( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration( + color: appStyle.colors.card, + borderRadius: BorderRadius.circular(16), + boxShadow: [ + BoxShadow( + color: appStyle.colors.textPrimary.withAlpha(20), + blurRadius: 15, + offset: const Offset(0, 11), + ), + ], + ), + child: isBack + ? _buildBack(subject, headline) + : _buildFront(subject, headline), + ); + } + + Widget _buildFront(SubjectCacheModel? subject, String headline) { + return Padding( + padding: const EdgeInsets.all(12), + child: Stack( + alignment: Alignment.center, + children: [ + const Positioned.fill(child: _TexturedGridBox()), + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + width: 40, + height: 40, + decoration: BoxDecoration( + color: appStyle.colors.a15p, + borderRadius: BorderRadius.circular(20), + ), + alignment: Alignment.center, + child: subject == null + ? null + : ClassIconWidget( + subject: subject, + color: appStyle.colors.accent, + size: 24, + ), + ), + const SizedBox(height: 20), + Text( + headline, + textAlign: TextAlign.center, + style: appStyle.fonts.H_H2.apply( + color: appStyle.colors.textPrimary, + ), + ), + if (subject != null) ...[ + const SizedBox(height: 4), + Text( + subject.name, + textAlign: TextAlign.center, + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.textSecondary, + ), + ), + ], + const SizedBox(height: 20), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 12), + child: Text( + _describeGradeWeight(l10n, grade), + textAlign: TextAlign.center, + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.textSecondary, + ), + ), + ), + ], + ), + ], + ), + ); + } + + Widget _buildBack(SubjectCacheModel? subject, String headline) { + return Stack( + children: [ + Positioned( + left: 12, + top: 73, + width: 216, + height: 159, + child: _TexturedGridBox( + child: Center(child: _EpicBadge(grade, allGrades, l10n)), + ), + ), + Positioned( + left: 16, + top: 16, + right: 16, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + headline, + style: appStyle.fonts.B_16SB.apply( + color: appStyle.colors.textPrimary, + ), + ), + if (subject != null) + Text( + subject.name, + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.textSecondary, + ), + ), + ], + ), + ), + Positioned( + left: 16, + right: 16, + bottom: 16, + child: Text( + _describeGradeWeight(l10n, grade), + style: appStyle.fonts.B_14R.apply( + color: appStyle.colors.textTertiary, + ), + ), + ), + ], + ); + } +} + +class _EpicBadge extends StatelessWidget { + final GradeCacheModel grade; + final List allGrades; + final AppLocalizations l10n; + + const _EpicBadge(this.grade, this.allGrades, this.l10n); + + @override + Widget build(BuildContext context) { + final rank = grade.numericValue != null + ? _rankLabel(l10n, allGrades, grade.numericValue!) + : null; + + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Stack( + clipBehavior: Clip.none, + alignment: Alignment.center, + children: [ + GradeWidget(grade, size: 90), + Positioned( + right: -6, + top: -4, + child: SvgPicture.asset(_starMedium, width: 25, height: 25), + ), + Positioned( + left: 2, + bottom: -2, + child: SvgPicture.asset(_starLarge, width: 21, height: 21), + ), + Positioned( + left: -6, + bottom: 6, + child: SvgPicture.asset(_starSmall, width: 10, height: 10), + ), + ], + ), + if (rank != null) ...[ + const SizedBox(height: 12), + Text( + rank, + style: appStyle.fonts.H_H2.apply( + color: appStyle.colors.textPrimary, + ), + ), + ], + ], + ); + } +} + +class _HoldSpray extends StatelessWidget { + static const _width = 240.0; + static const _height = 300.0; + + final double progress; + final List<_SprayParticle> particles; + + const _HoldSpray({required this.progress, required this.particles}); + + @override + Widget build(BuildContext context) { + return IgnorePointer( + child: SizedBox( + width: _width, + height: _height, + child: Stack( + clipBehavior: Clip.none, + children: particles.map((p) { + final localT = ((progress - p.spawnFraction) / p.lifespanFraction) + .clamp(0.0, 1.0); + final alive = + progress > 0 && progress >= p.spawnFraction && localT < 1.0; + if (!alive) return const SizedBox.shrink(); + + final fade = (1 - localT).clamp(0.0, 1.0); + final dx = cos(p.angle) * p.distance * localT; + final dy = sin(p.angle) * p.distance * localT; + final scale = 0.6 + 0.4 * (1 - localT); + return Align( + alignment: p.origin, + child: Transform.translate( + offset: Offset(dx, dy), + child: Transform.scale( + scale: scale, + child: Opacity( + opacity: fade, + child: GradeWidget.gradeValue(p.value, size: 28), + ), + ), + ), + ); + }).toList(), + ), + ), + ); + } +} + +class _SprayParticle { + final Alignment origin; + final double angle; + final double distance; + final int value; + final double spawnFraction; + final double lifespanFraction; + + const _SprayParticle({ + required this.origin, + required this.angle, + required this.distance, + required this.value, + required this.spawnFraction, + required this.lifespanFraction, + }); +} + +class _RevealEmojiBurst extends StatefulWidget { + final String emoji; + + const _RevealEmojiBurst({required this.emoji, super.key}); + + @override + State<_RevealEmojiBurst> createState() => _RevealEmojiBurstState(); +} + +class _RevealEmojiBurstState extends State<_RevealEmojiBurst> + with SingleTickerProviderStateMixin { + static const _width = 240.0; + static const _height = 300.0; + + late final _controller = AnimationController( + vsync: this, + duration: const Duration(milliseconds: 1400), + ); + final _rand = Random(); + late final List<_EdgeParticle> _particles = _spawn(); + + List<_EdgeParticle> _spawn() { + return List.generate(14, (i) { + final (origin, normalAngle) = _pickCardEdge(_rand); + final spread = (_rand.nextDouble() - 0.5) * (pi / 2.5); + final distance = 40.0 + _rand.nextDouble() * 60; + return _EdgeParticle( + origin: origin, + angle: normalAngle + spread, + distance: distance, + ); + }); + } + + @override + void initState() { + super.initState(); + _controller.forward(); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return IgnorePointer( + child: AnimatedBuilder( + animation: _controller, + builder: (context, child) { + final t = _controller.value; + final fadeOut = (1 - t).clamp(0.0, 1.0); + final fadeIn = (t / 0.12).clamp(0.0, 1.0); + final fade = fadeIn * fadeOut; + final active = t > 0 && !_controller.isDismissed; + + return SizedBox( + width: _width, + height: _height, + child: !active + ? null + : Stack( + clipBehavior: Clip.none, + children: _particles.map((p) { + final dx = cos(p.angle) * p.distance * t; + final dy = sin(p.angle) * p.distance * t; + final scale = (0.6 + 0.4 * (1 - t)) * fadeIn; + return Align( + alignment: p.origin, + child: Transform.translate( + offset: Offset(dx, dy), + child: Transform.scale( + scale: scale, + child: Opacity( + opacity: fade, + child: Text( + widget.emoji, + style: const TextStyle(fontSize: 30), + ), + ), + ), + ), + ); + }).toList(), + ), + ); + }, + ), + ); + } +} + +class _EdgeParticle { + final Alignment origin; + final double angle; + final double distance; + + const _EdgeParticle({ + required this.origin, + required this.angle, + required this.distance, + }); +} + +class EpicCardFaceDebugScreen extends StatefulWidget { + final GradeCacheModel grade; + final AppLocalizations l10n; + + const EpicCardFaceDebugScreen(this.grade, this.l10n, {super.key}); + + @override + State createState() => + _EpicCardFaceDebugScreenState(); +} + +class _EpicCardFaceDebugScreenState extends State { + bool _isBack = false; + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: appStyle.colors.background, + body: SafeArea( + child: Column( + children: [ + Padding( + padding: const EdgeInsets.all(16), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + GestureDetector( + onTap: () => Navigator.of(context).pop(), + child: Majesticon( + Majesticon.chevronLeftLine, + color: appStyle.colors.textPrimary, + size: 24, + ), + ), + ElevatedButton( + onPressed: () => setState(() => _isBack = !_isBack), + child: Text(_isBack ? "Show front" : "Show back"), + ), + ], + ), + ), + Expanded( + child: Center( + child: SizedBox( + width: 240, + height: 300, + child: _isBack + ? _EpicCardFace.back( + widget.grade, + [widget.grade], + widget.l10n, + ) + : _EpicCardFace.front( + widget.grade, + [widget.grade], + widget.l10n, + ), + ), + ), + ), + ], + ), + ), + ); + } +} + +class EpicParticleDebugScreen extends StatefulWidget { + const EpicParticleDebugScreen({super.key}); + + @override + State createState() => + _EpicParticleDebugScreenState(); +} + +class _EpicParticleDebugScreenState extends State { + int _burstId = 0; + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: appStyle.colors.background, + body: SafeArea( + child: Column( + children: [ + Padding( + padding: const EdgeInsets.all(16), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + GestureDetector( + onTap: () => Navigator.of(context).pop(), + child: Majesticon( + Majesticon.chevronLeftLine, + color: appStyle.colors.textPrimary, + size: 24, + ), + ), + ElevatedButton( + onPressed: () => setState(() => _burstId++), + child: const Text("Burst"), + ), + ], + ), + ), + Expanded( + child: Center( + child: Stack( + alignment: Alignment.center, + clipBehavior: Clip.none, + children: [ + Container( + width: 240, + height: 300, + decoration: BoxDecoration( + border: Border.all(color: appStyle.colors.accent), + borderRadius: BorderRadius.circular(16), + ), + ), + _RevealEmojiBurst( + key: ValueKey(_burstId), + emoji: _gradeEmoji(1 + _burstId % 5), + ), + ], + ), + ), + ), + ], + ), + ), + ); + } +} diff --git a/firka/pubspec.yaml b/firka/pubspec.yaml index 88bef0ea..5ab3e2ec 100644 --- a/firka/pubspec.yaml +++ b/firka/pubspec.yaml @@ -96,6 +96,7 @@ flutter: - assets/images/cactus_error_screen.png - assets/images/logos/dave_error.png - assets/icons/button/colorwheel.png + - assets/images/epic_grades/ fonts: - family: Montserrat