diff --git a/assets/backgrounds/bg00_dark.webp b/assets/backgrounds/bg00_dark.webp new file mode 100644 index 0000000..99eaa2d Binary files /dev/null and b/assets/backgrounds/bg00_dark.webp differ diff --git a/assets/backgrounds/bg00_light.webp b/assets/backgrounds/bg00_light.webp new file mode 100644 index 0000000..8d390b0 Binary files /dev/null and b/assets/backgrounds/bg00_light.webp differ diff --git a/assets/backgrounds/bg01_dark.webp b/assets/backgrounds/bg01_dark.webp index 4ba61a6..2693ed8 100644 Binary files a/assets/backgrounds/bg01_dark.webp and b/assets/backgrounds/bg01_dark.webp differ diff --git a/assets/backgrounds/bg01_light.webp b/assets/backgrounds/bg01_light.webp index 63a7d00..cf08393 100644 Binary files a/assets/backgrounds/bg01_light.webp and b/assets/backgrounds/bg01_light.webp differ diff --git a/assets/backgrounds/bg02_dark.webp b/assets/backgrounds/bg02_dark.webp index 1e1ed73..9e7ec87 100644 Binary files a/assets/backgrounds/bg02_dark.webp and b/assets/backgrounds/bg02_dark.webp differ diff --git a/assets/backgrounds/bg02_light.webp b/assets/backgrounds/bg02_light.webp index dcb061a..521e864 100644 Binary files a/assets/backgrounds/bg02_light.webp and b/assets/backgrounds/bg02_light.webp differ diff --git a/assets/backgrounds/bg03_dark.webp b/assets/backgrounds/bg03_dark.webp index 570db7f..08ea5da 100644 Binary files a/assets/backgrounds/bg03_dark.webp and b/assets/backgrounds/bg03_dark.webp differ diff --git a/assets/backgrounds/bg03_light.webp b/assets/backgrounds/bg03_light.webp index bd2f1fa..4ff78fa 100644 Binary files a/assets/backgrounds/bg03_light.webp and b/assets/backgrounds/bg03_light.webp differ diff --git a/assets/backgrounds/bg04_dark.webp b/assets/backgrounds/bg04_dark.webp index 4c7f3de..b6df326 100644 Binary files a/assets/backgrounds/bg04_dark.webp and b/assets/backgrounds/bg04_dark.webp differ diff --git a/assets/backgrounds/bg04_light.webp b/assets/backgrounds/bg04_light.webp index d5f1c6d..79cbf8d 100644 Binary files a/assets/backgrounds/bg04_light.webp and b/assets/backgrounds/bg04_light.webp differ diff --git a/assets/backgrounds/bg05_dark.webp b/assets/backgrounds/bg05_dark.webp index c37f7f2..77204f1 100644 Binary files a/assets/backgrounds/bg05_dark.webp and b/assets/backgrounds/bg05_dark.webp differ diff --git a/assets/backgrounds/bg05_light.webp b/assets/backgrounds/bg05_light.webp index 8edb8d3..f59031e 100644 Binary files a/assets/backgrounds/bg05_light.webp and b/assets/backgrounds/bg05_light.webp differ diff --git a/assets/backgrounds/bg06_dark.webp b/assets/backgrounds/bg06_dark.webp index d8f1b19..34c2b06 100644 Binary files a/assets/backgrounds/bg06_dark.webp and b/assets/backgrounds/bg06_dark.webp differ diff --git a/assets/backgrounds/bg06_light.webp b/assets/backgrounds/bg06_light.webp index eddec40..f5d83e8 100644 Binary files a/assets/backgrounds/bg06_light.webp and b/assets/backgrounds/bg06_light.webp differ diff --git a/assets/backgrounds/bg07_dark.webp b/assets/backgrounds/bg07_dark.webp index 1b1b362..4a79a53 100644 Binary files a/assets/backgrounds/bg07_dark.webp and b/assets/backgrounds/bg07_dark.webp differ diff --git a/assets/backgrounds/bg07_light.webp b/assets/backgrounds/bg07_light.webp index fdb7711..eab65a5 100644 Binary files a/assets/backgrounds/bg07_light.webp and b/assets/backgrounds/bg07_light.webp differ diff --git a/assets/backgrounds/bg08_dark.webp b/assets/backgrounds/bg08_dark.webp index d756848..ed7e93a 100644 Binary files a/assets/backgrounds/bg08_dark.webp and b/assets/backgrounds/bg08_dark.webp differ diff --git a/assets/backgrounds/bg08_light.webp b/assets/backgrounds/bg08_light.webp index 12f1c1a..35d9527 100644 Binary files a/assets/backgrounds/bg08_light.webp and b/assets/backgrounds/bg08_light.webp differ diff --git a/assets/backgrounds/bg09_dark.webp b/assets/backgrounds/bg09_dark.webp index 34f1242..fd274b2 100644 Binary files a/assets/backgrounds/bg09_dark.webp and b/assets/backgrounds/bg09_dark.webp differ diff --git a/assets/backgrounds/bg09_light.webp b/assets/backgrounds/bg09_light.webp index 8fb2ae1..e93b8d1 100644 Binary files a/assets/backgrounds/bg09_light.webp and b/assets/backgrounds/bg09_light.webp differ diff --git a/assets/backgrounds/bg10_dark.webp b/assets/backgrounds/bg10_dark.webp index 656872b..3f89609 100644 Binary files a/assets/backgrounds/bg10_dark.webp and b/assets/backgrounds/bg10_dark.webp differ diff --git a/assets/backgrounds/bg10_light.webp b/assets/backgrounds/bg10_light.webp index defac22..706e134 100644 Binary files a/assets/backgrounds/bg10_light.webp and b/assets/backgrounds/bg10_light.webp differ diff --git a/assets/backgrounds/t00_dark.webp b/assets/backgrounds/t00_dark.webp new file mode 100644 index 0000000..0fe0737 Binary files /dev/null and b/assets/backgrounds/t00_dark.webp differ diff --git a/assets/backgrounds/t00_light.webp b/assets/backgrounds/t00_light.webp new file mode 100644 index 0000000..1fe8036 Binary files /dev/null and b/assets/backgrounds/t00_light.webp differ diff --git a/assets/backgrounds/t01_dark.webp b/assets/backgrounds/t01_dark.webp new file mode 100644 index 0000000..14ad2ce Binary files /dev/null and b/assets/backgrounds/t01_dark.webp differ diff --git a/assets/backgrounds/t01_light.webp b/assets/backgrounds/t01_light.webp new file mode 100644 index 0000000..d42bc15 Binary files /dev/null and b/assets/backgrounds/t01_light.webp differ diff --git a/assets/backgrounds/t05_dark.webp b/assets/backgrounds/t05_dark.webp new file mode 100644 index 0000000..4b8ff8a Binary files /dev/null and b/assets/backgrounds/t05_dark.webp differ diff --git a/assets/backgrounds/t05_light.webp b/assets/backgrounds/t05_light.webp new file mode 100644 index 0000000..d3db2e1 Binary files /dev/null and b/assets/backgrounds/t05_light.webp differ diff --git a/assets/backgrounds/t07_dark.webp b/assets/backgrounds/t07_dark.webp new file mode 100644 index 0000000..ebbd341 Binary files /dev/null and b/assets/backgrounds/t07_dark.webp differ diff --git a/assets/backgrounds/t07_light.webp b/assets/backgrounds/t07_light.webp new file mode 100644 index 0000000..bb444da Binary files /dev/null and b/assets/backgrounds/t07_light.webp differ diff --git a/assets/backgrounds/t18_dark.webp b/assets/backgrounds/t18_dark.webp new file mode 100644 index 0000000..cc71164 Binary files /dev/null and b/assets/backgrounds/t18_dark.webp differ diff --git a/assets/backgrounds/t18_light.webp b/assets/backgrounds/t18_light.webp new file mode 100644 index 0000000..1014425 Binary files /dev/null and b/assets/backgrounds/t18_light.webp differ diff --git a/assets/backgrounds/t19_dark.webp b/assets/backgrounds/t19_dark.webp new file mode 100644 index 0000000..e8dcb84 Binary files /dev/null and b/assets/backgrounds/t19_dark.webp differ diff --git a/assets/backgrounds/t19_light.webp b/assets/backgrounds/t19_light.webp new file mode 100644 index 0000000..c00d4fa Binary files /dev/null and b/assets/backgrounds/t19_light.webp differ diff --git a/assets/backgrounds/t42_dark.webp b/assets/backgrounds/t42_dark.webp new file mode 100644 index 0000000..aae8ac0 Binary files /dev/null and b/assets/backgrounds/t42_dark.webp differ diff --git a/assets/backgrounds/t42_light.webp b/assets/backgrounds/t42_light.webp new file mode 100644 index 0000000..bcb1b61 Binary files /dev/null and b/assets/backgrounds/t42_light.webp differ diff --git a/assets/backgrounds/t53_dark.webp b/assets/backgrounds/t53_dark.webp new file mode 100644 index 0000000..f1850ef Binary files /dev/null and b/assets/backgrounds/t53_dark.webp differ diff --git a/assets/backgrounds/t53_light.webp b/assets/backgrounds/t53_light.webp new file mode 100644 index 0000000..2860941 Binary files /dev/null and b/assets/backgrounds/t53_light.webp differ diff --git a/assets/backgrounds/t61_dark.webp b/assets/backgrounds/t61_dark.webp new file mode 100644 index 0000000..96df671 Binary files /dev/null and b/assets/backgrounds/t61_dark.webp differ diff --git a/assets/backgrounds/t61_light.webp b/assets/backgrounds/t61_light.webp new file mode 100644 index 0000000..8239fb7 Binary files /dev/null and b/assets/backgrounds/t61_light.webp differ diff --git a/assets/backgrounds/t70_dark.webp b/assets/backgrounds/t70_dark.webp new file mode 100644 index 0000000..9402084 Binary files /dev/null and b/assets/backgrounds/t70_dark.webp differ diff --git a/assets/backgrounds/t70_light.webp b/assets/backgrounds/t70_light.webp new file mode 100644 index 0000000..ce32aa8 Binary files /dev/null and b/assets/backgrounds/t70_light.webp differ diff --git a/assets/backgrounds/t71_dark.webp b/assets/backgrounds/t71_dark.webp new file mode 100644 index 0000000..33b282e Binary files /dev/null and b/assets/backgrounds/t71_dark.webp differ diff --git a/assets/backgrounds/t71_light.webp b/assets/backgrounds/t71_light.webp new file mode 100644 index 0000000..b9dd777 Binary files /dev/null and b/assets/backgrounds/t71_light.webp differ diff --git a/assets/backgrounds/t72_dark.webp b/assets/backgrounds/t72_dark.webp new file mode 100644 index 0000000..58bb036 Binary files /dev/null and b/assets/backgrounds/t72_dark.webp differ diff --git a/assets/backgrounds/t72_light.webp b/assets/backgrounds/t72_light.webp new file mode 100644 index 0000000..7eb4535 Binary files /dev/null and b/assets/backgrounds/t72_light.webp differ diff --git a/assets/backgrounds/t73_dark.webp b/assets/backgrounds/t73_dark.webp new file mode 100644 index 0000000..02b012c Binary files /dev/null and b/assets/backgrounds/t73_dark.webp differ diff --git a/assets/backgrounds/t73_light.webp b/assets/backgrounds/t73_light.webp new file mode 100644 index 0000000..c080c55 Binary files /dev/null and b/assets/backgrounds/t73_light.webp differ diff --git a/assets/backgrounds/t74_dark.webp b/assets/backgrounds/t74_dark.webp new file mode 100644 index 0000000..cc6c6ff Binary files /dev/null and b/assets/backgrounds/t74_dark.webp differ diff --git a/assets/backgrounds/t74_light.webp b/assets/backgrounds/t74_light.webp new file mode 100644 index 0000000..a79aafc Binary files /dev/null and b/assets/backgrounds/t74_light.webp differ diff --git a/assets/backgrounds/t75_dark.webp b/assets/backgrounds/t75_dark.webp new file mode 100644 index 0000000..ac1df6b Binary files /dev/null and b/assets/backgrounds/t75_dark.webp differ diff --git a/assets/backgrounds/t75_light.webp b/assets/backgrounds/t75_light.webp new file mode 100644 index 0000000..4c58175 Binary files /dev/null and b/assets/backgrounds/t75_light.webp differ diff --git a/assets/backgrounds/t76_dark.webp b/assets/backgrounds/t76_dark.webp new file mode 100644 index 0000000..9da6610 Binary files /dev/null and b/assets/backgrounds/t76_dark.webp differ diff --git a/assets/backgrounds/t76_light.webp b/assets/backgrounds/t76_light.webp new file mode 100644 index 0000000..decaac4 Binary files /dev/null and b/assets/backgrounds/t76_light.webp differ diff --git a/assets/backgrounds/t77_dark.webp b/assets/backgrounds/t77_dark.webp new file mode 100644 index 0000000..2c17f2c Binary files /dev/null and b/assets/backgrounds/t77_dark.webp differ diff --git a/assets/backgrounds/t77_light.webp b/assets/backgrounds/t77_light.webp new file mode 100644 index 0000000..f6c07b0 Binary files /dev/null and b/assets/backgrounds/t77_light.webp differ diff --git a/assets/backgrounds/t78_dark.webp b/assets/backgrounds/t78_dark.webp new file mode 100644 index 0000000..3007676 Binary files /dev/null and b/assets/backgrounds/t78_dark.webp differ diff --git a/assets/backgrounds/t78_light.webp b/assets/backgrounds/t78_light.webp new file mode 100644 index 0000000..4f476c1 Binary files /dev/null and b/assets/backgrounds/t78_light.webp differ diff --git a/assets/backgrounds/t79_dark.webp b/assets/backgrounds/t79_dark.webp new file mode 100644 index 0000000..aa640e5 Binary files /dev/null and b/assets/backgrounds/t79_dark.webp differ diff --git a/assets/backgrounds/t79_light.webp b/assets/backgrounds/t79_light.webp new file mode 100644 index 0000000..40eb6d3 Binary files /dev/null and b/assets/backgrounds/t79_light.webp differ diff --git a/assets/targets/v3/t01.webp b/assets/targets/v3/t01.webp deleted file mode 100644 index f81edad..0000000 Binary files a/assets/targets/v3/t01.webp and /dev/null differ diff --git a/assets/targets/v3/t05.webp b/assets/targets/v3/t05.webp deleted file mode 100644 index 741d0c9..0000000 Binary files a/assets/targets/v3/t05.webp and /dev/null differ diff --git a/assets/targets/v3/t07.webp b/assets/targets/v3/t07.webp deleted file mode 100644 index 93c8a04..0000000 Binary files a/assets/targets/v3/t07.webp and /dev/null differ diff --git a/assets/targets/v3/t08.webp b/assets/targets/v3/t08.webp deleted file mode 100644 index 57eeb67..0000000 Binary files a/assets/targets/v3/t08.webp and /dev/null differ diff --git a/assets/targets/v3/t42.webp b/assets/targets/v3/t42.webp deleted file mode 100644 index 7959125..0000000 Binary files a/assets/targets/v3/t42.webp and /dev/null differ diff --git a/assets/targets/v3/t70.webp b/assets/targets/v3/t70.webp deleted file mode 100644 index 5272596..0000000 Binary files a/assets/targets/v3/t70.webp and /dev/null differ diff --git a/assets/targets/v3/t71.webp b/assets/targets/v3/t71.webp deleted file mode 100644 index d9be69d..0000000 Binary files a/assets/targets/v3/t71.webp and /dev/null differ diff --git a/assets/targets/v3/t72.webp b/assets/targets/v3/t72.webp deleted file mode 100644 index 75b02a9..0000000 Binary files a/assets/targets/v3/t72.webp and /dev/null differ diff --git a/assets/targets/v3/t73.webp b/assets/targets/v3/t73.webp deleted file mode 100644 index ec63ca7..0000000 Binary files a/assets/targets/v3/t73.webp and /dev/null differ diff --git a/assets/targets/v3/t74.webp b/assets/targets/v3/t74.webp deleted file mode 100644 index 3edfd86..0000000 Binary files a/assets/targets/v3/t74.webp and /dev/null differ diff --git a/assets/targets/v3/t75.webp b/assets/targets/v3/t75.webp deleted file mode 100644 index 878dd3a..0000000 Binary files a/assets/targets/v3/t75.webp and /dev/null differ diff --git a/assets/targets/v3/t76.webp b/assets/targets/v3/t76.webp deleted file mode 100644 index ca023b8..0000000 Binary files a/assets/targets/v3/t76.webp and /dev/null differ diff --git a/assets/targets/v3/t77.webp b/assets/targets/v3/t77.webp deleted file mode 100644 index 9e6f106..0000000 Binary files a/assets/targets/v3/t77.webp and /dev/null differ diff --git a/assets/targets/v3/t78.webp b/assets/targets/v3/t78.webp deleted file mode 100644 index e047255..0000000 Binary files a/assets/targets/v3/t78.webp and /dev/null differ diff --git a/assets/targets/v3/t79.webp b/assets/targets/v3/t79.webp deleted file mode 100644 index b92e517..0000000 Binary files a/assets/targets/v3/t79.webp and /dev/null differ diff --git a/assets/targets/v5/t01.webp b/assets/targets/v5/t01.webp new file mode 100644 index 0000000..5749ae9 Binary files /dev/null and b/assets/targets/v5/t01.webp differ diff --git a/assets/targets/v5/t05.webp b/assets/targets/v5/t05.webp new file mode 100644 index 0000000..7de8229 Binary files /dev/null and b/assets/targets/v5/t05.webp differ diff --git a/assets/targets/v5/t07.webp b/assets/targets/v5/t07.webp new file mode 100644 index 0000000..8028fdf Binary files /dev/null and b/assets/targets/v5/t07.webp differ diff --git a/assets/targets/v5/t18.webp b/assets/targets/v5/t18.webp new file mode 100644 index 0000000..1612265 Binary files /dev/null and b/assets/targets/v5/t18.webp differ diff --git a/assets/targets/v5/t19.webp b/assets/targets/v5/t19.webp new file mode 100644 index 0000000..f540856 Binary files /dev/null and b/assets/targets/v5/t19.webp differ diff --git a/assets/targets/v5/t42.webp b/assets/targets/v5/t42.webp new file mode 100644 index 0000000..df7c769 Binary files /dev/null and b/assets/targets/v5/t42.webp differ diff --git a/assets/targets/v5/t53.webp b/assets/targets/v5/t53.webp new file mode 100644 index 0000000..c82bec7 Binary files /dev/null and b/assets/targets/v5/t53.webp differ diff --git a/assets/targets/v5/t61.webp b/assets/targets/v5/t61.webp new file mode 100644 index 0000000..8ebc356 Binary files /dev/null and b/assets/targets/v5/t61.webp differ diff --git a/assets/targets/v5/t70.webp b/assets/targets/v5/t70.webp new file mode 100644 index 0000000..a41f426 Binary files /dev/null and b/assets/targets/v5/t70.webp differ diff --git a/assets/targets/v5/t71.webp b/assets/targets/v5/t71.webp new file mode 100644 index 0000000..87987e0 Binary files /dev/null and b/assets/targets/v5/t71.webp differ diff --git a/assets/targets/v5/t72.webp b/assets/targets/v5/t72.webp new file mode 100644 index 0000000..a2fb64b Binary files /dev/null and b/assets/targets/v5/t72.webp differ diff --git a/assets/targets/v5/t73.webp b/assets/targets/v5/t73.webp new file mode 100644 index 0000000..c551fbc Binary files /dev/null and b/assets/targets/v5/t73.webp differ diff --git a/assets/targets/v5/t74.webp b/assets/targets/v5/t74.webp new file mode 100644 index 0000000..ee23dd7 Binary files /dev/null and b/assets/targets/v5/t74.webp differ diff --git a/assets/targets/v5/t75.webp b/assets/targets/v5/t75.webp new file mode 100644 index 0000000..99032dd Binary files /dev/null and b/assets/targets/v5/t75.webp differ diff --git a/assets/targets/v5/t76.webp b/assets/targets/v5/t76.webp new file mode 100644 index 0000000..d2958c0 Binary files /dev/null and b/assets/targets/v5/t76.webp differ diff --git a/assets/targets/v5/t77.webp b/assets/targets/v5/t77.webp new file mode 100644 index 0000000..4c426ec Binary files /dev/null and b/assets/targets/v5/t77.webp differ diff --git a/assets/targets/v5/t78.webp b/assets/targets/v5/t78.webp new file mode 100644 index 0000000..0687ad9 Binary files /dev/null and b/assets/targets/v5/t78.webp differ diff --git a/assets/targets/v5/t79.webp b/assets/targets/v5/t79.webp new file mode 100644 index 0000000..d19dd01 Binary files /dev/null and b/assets/targets/v5/t79.webp differ diff --git a/lib/models/holiday_theme.dart b/lib/models/holiday_theme.dart index c0c72b5..3b09e6b 100644 --- a/lib/models/holiday_theme.dart +++ b/lib/models/holiday_theme.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -/// A holiday look (FigCraft Designs/holiday-themes/v2, themes.json): while a +/// A holiday look (FigCraft Designs/holiday-themes/v3, themes.json): while a /// holiday's window is on, the app shows its background, its target (locked) /// and its hit colour (until the user picks another one). Afterwards everything /// is back to the user's own settings. Saved targets are never changed. @@ -17,7 +17,12 @@ class HolidayTheme { const HolidayTheme(this.id, this.name, this.targetId, this.color, {this.from, this.to, this.easter}); - String background(bool dark) => 'assets/backgrounds/bg${id}_${dark ? 'dark' : 'light'}.webp'; + String background(bool dark) => _background(id, dark); + + /// The background when no holiday is on ("00 Privzeto"). + static String everydayBackground(bool dark) => _background('00', dark); + + static String _background(String id, bool dark) => 'assets/backgrounds/bg${id}_${dark ? 'dark' : 'light'}.webp'; /// In the order of themes.json: when windows overlap, the first one wins. static const List all = [ diff --git a/lib/models/target_style.dart b/lib/models/target_style.dart index e675e7f..db04045 100644 --- a/lib/models/target_style.dart +++ b/lib/models/target_style.dart @@ -3,13 +3,15 @@ import 'package:flutter/material.dart'; /// Where a target design comes from (only used to order and group the picker). enum TargetGroup { classic, design, holiday } -/// One target design of the v3 set (FigCraft Designs/target-designs/v3). +/// One target design of the v5 set (FigCraft Designs/target-designs/v5). /// /// Every design has the same geometry in a 1200 × 1200 space: centre /// (600, 600), ring 1 at r 510, the black at r 180; decoration and glow only -/// outside ring 1. Hits are stored in that space, so a hit lands on the same -/// ring whatever design is picked. The default ([id] 0) is drawn as vectors -/// (sharp at any zoom); the others are 1600 px WebP images with transparency. +/// outside ring 1, transparent beyond. Each design comes with its own screen +/// background (target-backgrounds/v3), shown on the target screens. Hits are stored in that space, so a hit lands on the same +/// ring whatever design is picked. The default ([id] 0, "00 Privzeta") is +/// drawn as vectors (sharp at any zoom); the others are 1600 px WebP images +/// with transparency. class TargetStyle { final int id; // 1–35 are the old Target.jpg, so saved choices carry over final String sl; @@ -21,10 +23,16 @@ class TargetStyle { const TargetStyle(this.id, this.sl, this.en, this.de, this.group, this.glow); bool get isDefault => id == 0; + + bool get isHoliday => group == TargetGroup.holiday; /// Image asset; null for the vector default. - String? get asset => isDefault ? null : 'assets/targets/v3/t${id.toString().padLeft(2, '0')}.webp'; + String? get asset => isDefault ? null : 'assets/targets/v5/t${id.toString().padLeft(2, '0')}.webp'; + + /// Its background on the target screens (target-backgrounds/v3, laid out + /// round the result screen's target), in dark or light. + String background(bool dark) => 'assets/backgrounds/t${id.toString().padLeft(2, '0')}_${dark ? 'dark' : 'light'}.webp'; String name(String language) => switch (language) { 'Slovenian' => sl, @@ -52,15 +60,25 @@ class TargetStyle { TargetStyle(79, 'Dan državnosti', 'Statehood Day', 'Staatsfeiertag', TargetGroup.holiday, Color(0xFF1C4FA0)), ]; - /// The designs the app ships, in picker order. The rest of the v3 set - /// (FigCraft Designs/target-designs/v3) is not used for now; to bring one - /// back, add its line here and its webp to assets/targets/v3. + /// The designs the app ships, in picker order (light to dark, then by + /// colour round the wheel: a 3 × 3 grid). The rest of the v5 set + /// (FigCraft Designs/target-designs/v5) is not used for now; to bring one + /// back, add its line here and its webp to assets/targets/v5. static const List all = [ fallback, - TargetStyle(1, 'Lovorov venec', 'Laurel wreath', 'Lorbeerkranz', TargetGroup.classic, Color(0xFF3E8A1E)), TargetStyle(42, 'ISSF ecru', 'ISSF ecru', 'ISSF Ecru', TargetGroup.design, Color(0xFFE8D9B0)), - TargetStyle(5, 'Plameni', 'Flames', 'Flammen', TargetGroup.classic, Color(0xFFFF3D00)), - TargetStyle(8, 'Val', 'Wave', 'Welle', TargetGroup.classic, Color(0xFF0B8BD9)), TargetStyle(7, 'Sončno rumena', 'Sunny yellow', 'Sonnengelb', TargetGroup.classic, Color(0xFFFFA000)), + TargetStyle(19, 'Oranžna', 'Orange', 'Orange', TargetGroup.classic, Color(0xFFFF5A00)), + TargetStyle(5, 'Plameni', 'Flames', 'Flammen', TargetGroup.classic, Color(0xFFFF3D00)), + TargetStyle(61, 'Cvetlice', 'Flowers', 'Blumen', TargetGroup.design, Color(0xFFFF6FB0)), + TargetStyle(18, 'Ledeni kristal', 'Ice crystal', 'Eiskristall', TargetGroup.classic, Color(0xFF00B8FF)), + TargetStyle(53, 'Kamuflaža', 'Camouflage', 'Tarnmuster', TargetGroup.design, Color(0xFF3E4A26)), + TargetStyle(1, 'Lovorov venec', 'Laurel wreath', 'Lorbeerkranz', TargetGroup.classic, Color(0xFF3E8A1E)), ]; + + @override + bool operator ==(Object other) => other is TargetStyle && other.id == id; + + @override + int get hashCode => id.hashCode; } diff --git a/lib/screens/book_screen.dart b/lib/screens/book_screen.dart index cbde1fe..85da05e 100644 --- a/lib/screens/book_screen.dart +++ b/lib/screens/book_screen.dart @@ -6,7 +6,6 @@ import '../services/app_settings.dart'; import '../services/target_repository.dart'; import '../theme/app_theme.dart'; import '../utils/format.dart'; -import '../widgets/bar_tabs.dart'; import '../widgets/ui.dart'; import '../widgets/help_sheet.dart'; import '../widgets/progress_chart.dart'; @@ -289,8 +288,7 @@ class _BookScreenState extends State with WidgetsBindingObserver { if (_view == _View.history) { return Column(children: [ - _buildTabs(), - _buildHistoryBar(), + _buildTabs(filters: _buildHistoryBar()), Expanded(child: _buildHistoryScreen()), ]); } @@ -313,8 +311,7 @@ class _BookScreenState extends State with WidgetsBindingObserver { return Column( children: [ - _buildTabs(), - _buildStatsBar(_formatCounts(typed.where(_inPeriod).toList()), shots), + _buildTabs(filters: _buildStatsBar(_formatCounts(typed.where(_inPeriod).toList()), shots)), Expanded( child: _years.isEmpty ? _centered(_buildEmpty()) @@ -432,8 +429,8 @@ class _BookScreenState extends State with WidgetsBindingObserver { ); } - // Title, then the two screens - Widget _buildTabs() { + // Title, then one card: the two screens over that screen's filters + Widget _buildTabs({Widget? filters}) { final s = AppSettings.instance; return Column( children: [ @@ -441,13 +438,21 @@ class _BookScreenState extends State with WidgetsBindingObserver { title: s.t('Book'), action: CircleButton(icon: Icons.info_outline_rounded, tooltip: s.t('Help'), onTap: () => showBookHelp(context)), ), - BarTabs( - tabs: [ - BarTab(s.t('Statistics'), Icons.bar_chart_rounded), - BarTab(s.t('History'), Icons.history_rounded), - ], - selected: _view.index, - onSelect: (i) => _change(() => _view = _View.values[i]), + Padding( + padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 12), + child: SegmentedCard(rows: [ + SegmentedTabs( + bare: true, + height: 40, + items: [ + SegmentItem(s.t('Statistics'), Icons.bar_chart_rounded), + SegmentItem(s.t('History'), Icons.history_rounded), + ], + selected: _view.index, + onSelect: (i) => _change(() => _view = _View.values[i]), + ), + if (filters != null) filters, + ]), ), ], ); @@ -456,33 +461,19 @@ class _BookScreenState extends State with WidgetsBindingObserver { // Zgodovina: which sessions to list Widget _buildHistoryBar() { final s = AppSettings.instance; - final labels = { - _HistoryFilter.all: s.t('All'), - _HistoryFilter.training: s.t('Trainings'), - _HistoryFilter.tournament: s.t('Tournaments'), - }; - return Padding( - padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 12), - child: Row( - children: [ - for (final f in _HistoryFilter.values) ...[ - if (f.index > 0) const SizedBox(width: 8), - Expanded( - child: ChoicePill( - label: labels[f]!, - selected: f == _historyFilter, - onTap: () => _change(() => _historyFilter = f), - ), - ), - ], - ], - ), + return SegmentedTabs( + bare: true, + height: 36, + items: [SegmentItem(s.t('All')), SegmentItem(s.t('Trainings')), SegmentItem(s.t('Tournaments'))], + selected: _historyFilter.index, + onSelect: (i) => _change(() => _historyFilter = _HistoryFilter.values[i]), ); } - // Statistika: trainings or tournaments, then the shots-per-target format as - // one chip with a menu. Shots are 1–5 (the capture limit); older saves above - // 5 keep their own entry. Formats with no targets yet can't be picked. + // Statistika: trainings or tournaments, and at the end of the same bar the + // shots-per-target format as a menu. Shots are 1–5 (the capture limit); + // older saves above 5 keep their own entry. Formats with no targets yet + // can't be picked. Widget _buildStatsBar(Map counts, int? selected) { final s = AppSettings.instance; final c = Palette.current; @@ -491,78 +482,68 @@ class _BookScreenState extends State with WidgetsBindingObserver { ...counts.keys, }.toList() ..sort((a, b) => b.compareTo(a)); - Widget kind(_Filter f, String label) => ChoicePill( - label: s.t(label), - selected: f == _filter, - onTap: () => _change(() { - _filter = f; - _shots = null; - _chartAt = null; - }), - ); - return Padding( - padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 12), - child: Row( - children: [ - Expanded(child: kind(_Filter.training, 'Trainings')), - const SizedBox(width: 6), - Expanded(child: kind(_Filter.tournament, 'Tournaments')), - const SizedBox(width: 6), - PopupMenuButton( - tooltip: s.t('Shots per target'), - initialValue: selected, - position: PopupMenuPosition.under, - offset: const Offset(0, 6), - color: c.isDark ? c.card2 : c.card, - surfaceTintColor: Colors.transparent, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(14), - side: BorderSide(color: c.line), - ), - onSelected: (n) => _change(() => _shots = n), - itemBuilder: (_) => [ - for (final n in sorted) - PopupMenuItem( - value: n, - enabled: (counts[n] ?? 0) > 0, - height: 44, - child: Row( - children: [ - SizedBox( - width: 22, - child: n == selected ? Icon(Icons.check_rounded, size: 18, color: c.accent) : null, - ), - const SizedBox(width: 6), - Text(shotCount(n), - style: TextStyle( - fontSize: 14, - fontWeight: n == selected ? FontWeight.w700 : FontWeight.w500, - color: (counts[n] ?? 0) > 0 ? c.ink : c.faint)), - const SizedBox(width: 16), - const Spacer(), - Text(targetCount(counts[n] ?? 0), - style: TextStyle(fontSize: 12, color: c.muted, fontFeatures: AppTheme.tnum)), - ], - ), + final shotsMenu = PopupMenuButton( + tooltip: s.t('Shots per target'), + initialValue: selected, + position: PopupMenuPosition.under, + offset: const Offset(0, 6), + color: c.isDark ? c.card2 : c.card, + surfaceTintColor: Colors.transparent, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(14), + side: BorderSide(color: c.line), + ), + onSelected: (n) => _change(() => _shots = n), + itemBuilder: (_) => [ + for (final n in sorted) + PopupMenuItem( + value: n, + enabled: (counts[n] ?? 0) > 0, + height: 44, + child: Row( + children: [ + SizedBox( + width: 22, + child: n == selected ? Icon(Icons.check_rounded, size: 18, color: c.accent) : null, ), - ], - child: Container( - height: 32, - padding: const EdgeInsets.only(left: 12, right: 6), - decoration: BoxDecoration(color: c.tile, borderRadius: BorderRadius.circular(16)), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text(selected == null ? '–' : shotCount(selected), - style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: c.ink2)), - Icon(Icons.expand_more_rounded, size: 18, color: c.muted), - ], - ), + const SizedBox(width: 6), + Text(shotCount(n), + style: TextStyle( + fontSize: 14, + fontWeight: n == selected ? FontWeight.w700 : FontWeight.w500, + color: (counts[n] ?? 0) > 0 ? c.ink : c.faint)), + const SizedBox(width: 16), + const Spacer(), + Text(targetCount(counts[n] ?? 0), + style: TextStyle(fontSize: 12, color: c.muted, fontFeatures: AppTheme.tnum)), + ], ), ), - ], + ], + child: Padding( + padding: const EdgeInsets.only(left: 8, right: 2), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text(selected == null ? '–' : shotCount(selected), + style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: c.ink)), + Icon(Icons.expand_more_rounded, size: 18, color: c.muted), + ], + ), ), ); + return SegmentedTabs( + bare: true, + height: 36, + items: [SegmentItem(s.t('Trainings')), SegmentItem(s.t('Tournaments'))], + selected: _filter.index, + onSelect: (i) => _change(() { + _filter = _Filter.values[i]; + _shots = null; + _chartAt = null; + }), + trailing: shotsMenu, + ); } // Monday–Sunday week of [date], cut to its month: "6.–12. 10.", "27.–31. 10." diff --git a/lib/screens/calendar_screen.dart b/lib/screens/calendar_screen.dart index c120e88..845e096 100644 --- a/lib/screens/calendar_screen.dart +++ b/lib/screens/calendar_screen.dart @@ -10,6 +10,7 @@ import '../services/google_calendar_service.dart'; import '../services/notification_service.dart'; import '../widgets/section.dart'; import '../widgets/ui.dart'; +import 'league_view.dart'; import 'settings_screen.dart'; enum EventType { @@ -32,7 +33,7 @@ class _CalendarScreenState extends State { bool _isLoading = false; List _events = []; String? _errorMessage; - bool _showContacts = false; + int _tab = 0; // 0 calendar, 1 contacts, 2 league String _query = ''; List get _contacts => AppSettings.instance.clubContacts; @@ -534,8 +535,10 @@ class _CalendarScreenState extends State { listenable: AppSettings.instance, builder: (context, _) { Widget body; - if (_showContacts) { + if (_tab == 1) { body = _buildContactsList(); + } else if (_tab == 2) { + body = const LeagueView(); // loads each time the tab is opened } else if (_isLoading && _events.isEmpty) { body = const Center(child: CircularProgressIndicator()); } else if (_errorMessage != null && _events.isEmpty) { @@ -567,9 +570,10 @@ class _CalendarScreenState extends State { tabs: [ BarTab(_t('Calendar'), Icons.calendar_today_outlined), BarTab(_t('Contacts'), Icons.person_add_alt_outlined), + BarTab(_t('League'), Icons.emoji_events_outlined), ], - selected: _showContacts ? 1 : 0, - onSelect: (i) => setState(() => _showContacts = i == 1), + selected: _tab, + onSelect: (i) => setState(() => _tab = i), ), Expanded(child: body), ], diff --git a/lib/screens/league_view.dart b/lib/screens/league_view.dart new file mode 100644 index 0000000..d0309a7 --- /dev/null +++ b/lib/screens/league_view.dart @@ -0,0 +1,305 @@ +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; +import 'package:url_launcher/url_launcher.dart'; +import '../services/app_settings.dart'; +import '../services/league_service.dart'; +import '../theme/app_theme.dart'; +import '../widgets/ui.dart'; +import 'session_screen.dart' show targetCount, shotCount; + +/// Koledar → Liga: the club league from liga.bl3kunja.top – which tournament +/// is open, the plan of all of them, and the live standings. Read when the +/// tab is opened (and on pull to refresh), never in the background. +class LeagueView extends StatefulWidget { + final LeagueService? service; // tests pass one with a fake client + const LeagueView({super.key, this.service}); + + @override + State createState() => _LeagueViewState(); +} + +class _LeagueViewState extends State { + static const String _ourClub = 'Kovinar'; // our shooters are highlighted + + late final LeagueService _service = widget.service ?? LeagueService(); + LeagueStandings? _data; + Object? _error; + bool _loading = true; + + String _t(String key) => AppSettings.instance.t(key); + + @override + void initState() { + super.initState(); + _load(); + } + + @override + void dispose() { + _service.dispose(); + super.dispose(); + } + + Future _load() async { + setState(() => _loading = true); + try { + final data = await _service.standings(); + if (!mounted) return; + setState(() { + _data = data; + _error = null; + _loading = false; + }); + } catch (e) { + if (!mounted) return; + setState(() { + _error = e; + _loading = false; + }); + } + } + + Future _openSite() => + launchUrl(Uri.parse('${LeagueService.site}/lestvica'), mode: LaunchMode.externalApplication); + + @override + Widget build(BuildContext context) { + final data = _data; + if (data == null) { + if (_loading) return const Center(child: CircularProgressIndicator()); + return Center( + child: Padding( + padding: const EdgeInsets.all(32), + child: EmptyState( + icon: Icons.cloud_off_rounded, + title: _t('Could not load the league'), + hint: '$_error', + action: SizedBox( + width: 180, + child: PrimaryButton(label: _t('Retry'), icon: Icons.refresh_rounded, height: 46, onTap: _load), + ), + ), + ), + ); + } + return RefreshIndicator( + onRefresh: _load, + child: ListView( + padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 24), + children: [ + _statusCard(data), + const SizedBox(height: 12), + _standingsCard(data), + const SizedBox(height: 12), + SoftButton(label: _t('Open the league website'), icon: Icons.open_in_new_rounded, onTap: _openSite), + ], + ), + ); + } + + // Which tournament is open (or next), the plan of all of them, the rules + Widget _statusCard(LeagueStandings data) { + final c = Palette.current; + final open = data.openRound; + final next = data.nextRound; + final day = DateFormat('d. M.'); + final (String title, String? sub, Color dot) = open != null + ? ( + _t('{n}. tournament is open').replaceAll('{n}', '${open.number}'), + [ + if (open.endsAt != null) _t('until {d}').replaceAll('{d}', day.format(open.endsAt!)), + _t('Entries: {n}').replaceAll('{n}', '${open.submissions}'), + ].join(' · '), + c.pos, + ) + : next != null + ? ( + _t('{n}. tournament').replaceAll('{n}', '${next.number}'), + next.startsAt == null ? null : _t('from {d}').replaceAll('{d}', day.format(next.startsAt!)), + c.muted, + ) + : (_t('The league has finished'), null, c.faint); + return AppCard( + padding: const EdgeInsets.fromLTRB(16, 14, 16, 14), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Kicker(data.league.name), + const SizedBox(height: 8), + Row( + children: [ + Container(width: 9, height: 9, decoration: BoxDecoration(color: dot, shape: BoxShape.circle)), + const SizedBox(width: 8), + Expanded(child: Text(title, style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700, color: c.ink))), + ], + ), + if (sub != null) ...[ + const SizedBox(height: 2), + Padding( + padding: const EdgeInsets.only(left: 17), + child: Text(sub, style: TextStyle(fontSize: 13, color: c.muted)), + ), + ], + const SizedBox(height: 14), + Row( + children: [ + for (int i = 0; i < data.rounds.length; i++) ...[ + if (i > 0) const SizedBox(width: 6), + Expanded(child: _roundChip(data.rounds[i])), + ], + ], + ), + const SizedBox(height: 12), + Text( + [ + _t('Best {n} count').replaceAll('{n}', '${data.league.counted}'), + targetCount(data.league.targets), + shotCount(data.league.shots), + ].join(' · '), + style: TextStyle(fontSize: 12, color: c.muted), + ), + ], + ), + ); + } + + // One tournament of the plan: open in the accent, done ticked, to come faint + Widget _roundChip(LeagueRound r) { + final c = Palette.current; + final month = r.startsAt == null + ? '' + : DateFormat('LLL', AppSettings.instance.dateLocale).format(r.startsAt!).replaceAll('.', ''); + final fg = r.isOpen ? c.onAccent : (r.isDone ? c.ink2 : c.faint); + return Container( + height: 50, + decoration: BoxDecoration( + color: r.isOpen ? c.accent : (r.isDone ? c.tile : Colors.transparent), + borderRadius: BorderRadius.circular(12), + border: r.isUpcoming ? Border.all(color: c.line) : null, + ), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (r.isDone) ...[Icon(Icons.check_rounded, size: 13, color: fg), const SizedBox(width: 2)], + Text('${r.number}.', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w800, color: fg)), + ], + ), + Text(month, style: TextStyle(fontSize: 10.5, fontWeight: FontWeight.w600, color: fg.withValues(alpha: 0.8))), + ], + ), + ); + } + + Widget _standingsCard(LeagueStandings data) { + final c = Palette.current; + // Only tournaments that have started get a column, so early in the season + // names have room; the plan of all of them is in the status card + final rounds = data.rounds.where((r) => !r.isUpcoming).length.clamp(1, data.rounds.length); + return AppCard( + padding: const EdgeInsets.fromLTRB(12, 14, 12, 6), + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Padding( + padding: const EdgeInsets.only(left: 4, bottom: 6), + child: Row( + children: [ + Expanded(child: Kicker(_t('Standings'))), + for (int i = 1; i <= rounds; i++) + SizedBox(width: 30, child: Text('$i.', textAlign: TextAlign.center, style: AppTheme.kicker(c))), + SizedBox(width: 48, child: Text('Σ', textAlign: TextAlign.right, style: AppTheme.kicker(c))), + ], + ), + ), + if (data.players.isEmpty) + Padding( + padding: const EdgeInsets.symmetric(vertical: 20), + child: Text(_t('No results yet'), textAlign: TextAlign.center, style: TextStyle(color: c.muted)), + ), + for (final p in data.players) _playerRow(p, rounds), + ], + ), + ); + } + + Widget _playerRow(LeaguePlayer p, int rounds) { + final c = Palette.current; + final ours = p.club.contains(_ourClub); + // 1–3 in gold, silver and bronze + final medal = switch (p.rank) { + 1 => c.gold, + 2 => const Color(0xFFB8BEC6), + 3 => const Color(0xFFCD8B4E), + _ => null, + }; + return Container( + margin: const EdgeInsets.only(bottom: 4), + padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 7), + decoration: BoxDecoration( + color: ours ? c.accentSoft : Colors.transparent, + borderRadius: BorderRadius.circular(10), + ), + child: Row( + children: [ + Container( + width: 26, + height: 26, + alignment: Alignment.center, + decoration: BoxDecoration( + color: medal?.withValues(alpha: 0.22) ?? c.tile, + shape: BoxShape.circle, + ), + child: Text('${p.rank}', + style: TextStyle(fontSize: 12, fontWeight: FontWeight.w800, color: medal ?? c.ink2, fontFeatures: AppTheme.tnum)), + ), + const SizedBox(width: 10), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(p.name, + maxLines: 2, + overflow: TextOverflow.ellipsis, + style: TextStyle(fontSize: 14, fontWeight: FontWeight.w700, color: c.ink)), + Text(p.club, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle(fontSize: 11.5, color: ours ? c.accent : c.muted, fontWeight: ours ? FontWeight.w600 : null)), + ], + ), + ), + // Each tournament: counted ones plain, dropped ones struck through + for (int i = 0; i < rounds; i++) + SizedBox( + width: 30, + child: Text( + i < p.cells.length && p.cells[i] != null ? '${p.cells[i]!.score}' : '–', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 11.5, + fontWeight: FontWeight.w600, + fontFeatures: AppTheme.tnum, + color: i < p.cells.length && p.cells[i] != null ? (p.cells[i]!.counted ? c.ink2 : c.faint) : c.faint, + decoration: i < p.cells.length && p.cells[i] != null && !p.cells[i]!.counted ? TextDecoration.lineThrough : null, + ), + ), + ), + SizedBox( + width: 48, + child: Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text('${p.finalScore}', + style: TextStyle(fontSize: 16, fontWeight: FontWeight.w800, color: c.ink, fontFeatures: AppTheme.tnum)), + Text('${p.tens}×10', style: TextStyle(fontSize: 10.5, color: c.muted, fontFeatures: AppTheme.tnum)), + ], + ), + ), + ], + ), + ); + } +} diff --git a/lib/screens/preview_screen.dart b/lib/screens/preview_screen.dart index 6b7afc7..37d7d04 100644 --- a/lib/screens/preview_screen.dart +++ b/lib/screens/preview_screen.dart @@ -20,12 +20,27 @@ import 'yolo_detector.dart'; /// "Preveri zadetke": the detected hits on the chosen target design. Tap a /// tile to pick a hit, then hold and drag on the target to move it; add or /// remove hits; choose where to save; save. +/// +/// [PreviewScreen.edit] opens a saved target the same way: its hits, no photo +/// and no folder choice; saving overwrites that target's file. class PreviewScreen extends StatefulWidget { - final String imagePath; + final String? imagePath; final List detections; final int bulletCount; + final File? editFile; // the saved target being edited + final List initialHits; - const PreviewScreen({super.key, required this.imagePath, required this.detections, required this.bulletCount}); + const PreviewScreen({super.key, required String this.imagePath, required this.detections, required this.bulletCount}) + : editFile = null, + initialHits = const []; + + const PreviewScreen.edit({super.key, required File file, required List hits, required this.bulletCount}) + : imagePath = null, + detections = const [], + editFile = file, + initialHits = hits; + + bool get isEdit => editFile != null; @override State createState() => _PreviewScreenState(); @@ -68,7 +83,11 @@ class _PreviewScreenState extends State { } Future _load() async { - await Future.wait([_loadFolders(), _runDetectionAndMapping()]); + if (widget.isEdit) { + _hits = [...widget.initialHits]; + } else { + await Future.wait([_loadFolders(), _runDetectionAndMapping()]); + } if (mounted) setState(() => _isLoading = false); } @@ -106,7 +125,7 @@ class _PreviewScreenState extends State { Future _runDetectionAndMapping() async { try { - final bytes = await File(widget.imagePath).readAsBytes(); + final bytes = await File(widget.imagePath!).readAsBytes(); _photo = bytes; _photoSize = await _imageSize(bytes); @@ -232,9 +251,8 @@ class _PreviewScreenState extends State { final i = _selected; if (i == null) return; setState(() { - final p = _hits[i] + delta; - // Keep it on the canvas - _hits[i] = Offset(p.dx.clamp(0, TargetScoring.size), p.dy.clamp(0, TargetScoring.size)); + // Keep it within the target's square + _hits[i] = TargetScoring.shown(_hits[i] + delta); }); } @@ -285,7 +303,30 @@ class _PreviewScreenState extends State { }); } + // Edit: the same file with the new hits; everything else in it is kept + Future _saveEdit() async { + final file = widget.editFile!; + if (_saving) return; + setState(() => _saving = true); + try { + final data = jsonDecode(await file.readAsString()) as Map; + final scores = [for (int i = 0; i < _hits.length; i++) _scoreAt(i)]; + data['totalScore'] = scores.fold(0, (a, b) => a + b); + data['bulletCount'] = widget.bulletCount; + data['bullets'] = [for (final b in _hits) {'x': b.dx, 'y': b.dy}]; + data['scores'] = scores; + await file.writeAsString(jsonEncode(data)); + TargetRepository.notifyChanged(); + if (!mounted) return; + Navigator.pop(context, true); + } catch (e) { + debugPrint('Error saving edited target: $e'); + if (mounted) setState(() => _saving = false); + } + } + Future _save() async { + if (widget.isEdit) return _saveEdit(); final to = _saveTo; if (to == null || _saving) return; setState(() => _saving = true); @@ -327,8 +368,8 @@ class _PreviewScreenState extends State { showHelpSheet(context, t: _t, items: const [ (Icons.touch_app_outlined, 'Tap a value below to pick that hit; it gets a red border.'), (Icons.open_with_rounded, 'Hold and drag on the target to move the picked hit; a magnifier shows where it is.'), - (Icons.add_rounded, 'Add hit: for a shot that was not found. Remove hit: deletes the picked one.'), - (Icons.folder_outlined, 'Save to: training or tournament, and which folder. The last one is chosen for you.'), + (Icons.add_box_outlined, '+ tile: for a shot that was not found. Bin: deletes the picked hit.'), + (Icons.emoji_events_outlined, 'Button bottom left: training or tournament. The folder on top: where it is saved; the last one is chosen for you.'), (Icons.photo_outlined, 'Photo icon: see the photo with what was detected.'), ]); } @@ -338,77 +379,118 @@ class _PreviewScreenState extends State { final s = AppSettings.instance; final c = Palette.current; final found = widget.detections.where((r) => r.classId == 0).length; - return Scaffold( - body: Column( + // The picked target's own background (a holiday's wins) + return AppBackground( + target: true, + child: Scaffold( + // Laid out on the target background's zones: header and "save to" above + // its first line, the target in the window between the lines, the hits + // and buttons below the second one + body: Stack( children: [ - BackHeader( - title: _t('Check hits'), - subtitle: _t('{n} hits detected · correct them if needed').replaceAll('{n}', '${min(found, widget.bulletCount)}'), - actions: [CircleButton(icon: Icons.info_outline_rounded, onTap: _showHelp)], - ), - if (_isLoading) - const Expanded(child: Center(child: CircularProgressIndicator())) - else ...[ - Padding( - padding: const EdgeInsets.fromLTRB(AppTheme.edge, 4, AppTheme.edge, 0), - child: _saveCard(c), - ), - Expanded( + if (!_isLoading) + TargetWindow( child: Stack( children: [ Positioned.fill(child: _showPhoto ? _photoView(c) : _targetView(s, c)), - // The photo with what the model saw, for checking - Positioned( - top: 8, - right: AppTheme.edge, - child: CircleButton( - icon: _showPhoto ? Icons.track_changes_rounded : Icons.photo_outlined, - size: 36, - iconSize: 18, - tooltip: _t(_showPhoto ? 'Show Mapped Target' : 'Show Camera Detections'), - onTap: () => setState(() => _showPhoto = !_showPhoto), + // The photo with what the model saw, for checking (a saved + // target has no photo): the window's top right corner + if (!widget.isEdit) + Positioned( + top: 10, + right: AppTheme.edge, + child: CircleButton( + icon: _showPhoto ? Icons.track_changes_rounded : Icons.photo_outlined, + size: 40, + iconSize: 19, + tooltip: _t(_showPhoto ? 'Show Mapped Target' : 'Show Camera Detections'), + onTap: () => setState(() => _showPhoto = !_showPhoto), + ), ), - ), ], ), ), - Padding( - padding: const EdgeInsets.fromLTRB(AppTheme.edge, 0, AppTheme.edge, 0), - child: _tiles(c), + // The folder it is saved to sits on the target window's upper line + if (!_isLoading && !widget.isEdit) + Positioned.fill( + child: LayoutBuilder(builder: (context, box) { + // From under the header (60 + the status bar) down to just + // above the line: it grows with the room the screen has + final (line, _) = TargetWindow.lines(box.biggest); + final bottom = line - 12; + final top = min(MediaQuery.paddingOf(context).top + 60 + 6, bottom - 56); + return Stack(children: [ + Positioned(left: AppTheme.edge, right: AppTheme.edge, top: top, height: bottom - top, child: _saveCard(c)), + ]); + }), ), - Padding( - padding: const EdgeInsets.fromLTRB(AppTheme.edge, 12, AppTheme.edge, 0), - child: Row( - children: [ - Expanded( - child: SoftButton( - label: _t('Add hit'), - icon: Icons.add_rounded, - onTap: _hits.length < widget.bulletCount ? _addHit : null, - ), - ), - const SizedBox(width: 10), - Expanded( - child: SoftButton( - label: _t('Remove hit'), - icon: Icons.delete_outline_rounded, - destructive: _selected != null, - onTap: _selected == null ? null : _removeHit, - ), - ), + Column( + children: [ + BackHeader( + title: _t(widget.isEdit ? 'Edit target' : 'Check hits'), + subtitle: widget.isEdit + ? widget.editFile!.parent.path.split('/').last + : _t('{n} hits detected').replaceAll('{n}', '${min(found, widget.bulletCount)}'), + actions: [ + CircleButton(icon: Icons.info_outline_rounded, onTap: _showHelp), ], ), + if (_isLoading) + const Expanded(child: Center(child: CircularProgressIndicator())) + else ...[ + const Spacer(), + Padding( + padding: const EdgeInsets.fromLTRB(AppTheme.edge, 8, AppTheme.edge, 0), + child: _tiles(c), + ), + _actions(c), + ], + ], + ), + ], + ), + ), + ); + } + + // Like the result page: a square button either side of the main one + Widget _actions(Palette c) { + return Padding( + padding: EdgeInsets.fromLTRB(AppTheme.edge, 16, AppTheme.edge, 12 + MediaQuery.paddingOf(context).bottom), + child: Row( + children: [ + // Training or tournament: one tap switches (and the folder with it) + if (!widget.isEdit) ...[ + SquareButton( + size: 52, + icon: _tournament ? Icons.emoji_events_outlined : Icons.track_changes_rounded, + color: _tournament ? c.gold : c.accent, + background: _tournament ? c.goldSoft : c.accentSoft, + tooltip: _t(_tournament ? 'Tournament' : 'Training'), + onTap: () { + HapticFeedback.selectionClick(); + _setKind(!_tournament); + }, ), - Padding( - padding: EdgeInsets.fromLTRB(AppTheme.edge, 16, AppTheme.edge, 12 + MediaQuery.paddingOf(context).bottom), - child: PrimaryButton( - label: '${_t('Save target')} · $_total', - icon: Icons.check_rounded, - busy: _saving, - onTap: _save, - ), - ), + const SizedBox(width: 10), ], + Expanded( + child: PrimaryButton( + label: '${_t(widget.isEdit ? 'Save changes' : 'Save target')} · $_total', + icon: Icons.check_rounded, + busy: _saving, + onTap: _save, + ), + ), + const SizedBox(width: 10), + SquareButton( + size: 52, + icon: Icons.delete_outline_rounded, + tooltip: _t('Remove hit'), + color: _selected == null ? c.faint : c.red, + background: _selected == null ? null : c.redSoft, + onTap: _selected == null ? null : _removeHit, + ), ], ), ); @@ -423,48 +505,63 @@ class _PreviewScreenState extends State { : DateUtils.isSameDay(to.date, DateTime.now()) ? '${_t('today')} ${DateFormat('HH:mm').format(to.date!)}' : DateFormat('d. M.').format(to.date ?? DateTime.now()); - return AppCard( - padding: const EdgeInsets.fromLTRB(12, 12, 12, 12), - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Kicker(_t('Save to'), padding: const EdgeInsets.only(left: 2, bottom: 8)), - SegmentedTabs( - height: 40, - items: [SegmentItem(_t('Training')), SegmentItem(_t('Tournament'))], - selected: _tournament ? 1 : 0, - onSelect: (i) => _setKind(i == 1), - ), - const SizedBox(height: 8), - Material( - color: c.isDark ? c.card : c.card, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12), side: BorderSide(color: c.line)), - clipBehavior: Clip.antiAlias, - child: InkWell( - onTap: _pickFolder, - child: SizedBox( - height: 42, - child: Row( - children: [ - const SizedBox(width: 12), - Icon(Icons.folder_outlined, size: 18, color: c.accent), - const SizedBox(width: 10), - Flexible( - child: Text(to?.name ?? '', + // The folder, with the kind above its name (switched by the button + // bottom left); fills the room between the header and the line + final tint = _tournament ? c.gold : c.accent; + return Material( + color: c.card, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16), side: BorderSide(color: c.line)), + clipBehavior: Clip.antiAlias, + child: InkWell( + onTap: _pickFolder, + child: LayoutBuilder(builder: (context, box) { + final roomy = box.maxHeight >= 76; + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 14), + child: Row( + children: [ + Container( + width: roomy ? 48 : 34, + height: roomy ? 48 : 34, + decoration: BoxDecoration( + color: _tournament ? c.goldSoft : c.accentSoft, + borderRadius: BorderRadius.circular(roomy ? 14 : 10), + ), + child: Icon(Icons.folder_outlined, size: roomy ? 24 : 18, color: tint), + ), + const SizedBox(width: 12), + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('${_t('Save to')} · ${_t(_tournament ? 'Tournament' : 'Training')}'.toUpperCase(), maxLines: 1, overflow: TextOverflow.ellipsis, - style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: c.ink)), - ), - Text(' · $when', style: TextStyle(fontSize: 12.5, color: c.muted)), - const Spacer(), - Icon(Icons.expand_more_rounded, size: 20, color: c.muted), - const SizedBox(width: 8), - ], + style: AppTheme.kicker(c).copyWith(fontSize: roomy ? 10.5 : 9.5)), + SizedBox(height: roomy ? 4 : 2), + Text(to?.name ?? '', + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle(fontSize: roomy ? 19 : 15, height: 1.15, fontWeight: FontWeight.w700, color: c.ink)), + if (roomy && when.isNotEmpty) ...[ + const SizedBox(height: 3), + Text(when, maxLines: 1, style: TextStyle(fontSize: 12.5, color: c.muted)), + ], + ], + ), ), - ), + if (!roomy && when.isNotEmpty) ...[Text(when, style: TextStyle(fontSize: 12, color: c.muted)), const SizedBox(width: 4)], + Container( + width: 32, + height: 32, + decoration: BoxDecoration(color: c.tile, shape: BoxShape.circle), + child: Icon(Icons.unfold_more_rounded, size: 18, color: c.ink2), + ), + ], ), - ), - ], + ); + }), ), ); } @@ -475,17 +572,18 @@ class _PreviewScreenState extends State { final side = min(box.maxWidth, box.maxHeight) - 8; if (side <= 0) return const SizedBox(); final scale = side / TargetScoring.size; + Offset toTarget(Offset screen) => screen / scale; final i = _selected; - final picked = i == null || i >= _hits.length ? null : _hits[i] * scale; + final picked = i == null || i >= _hits.length ? null : TargetScoring.shown(_hits[i]) * scale; return Center( child: SizedBox.square( dimension: side, child: GestureDetector( behavior: HitTestBehavior.opaque, - onTapUp: (d) => _pickAt(d.localPosition / scale), + onTapUp: (d) => _pickAt(toTarget(d.localPosition)), onPanStart: (d) { // Starting on another hit picks that one - final near = _nearest(d.localPosition / scale); + final near = _nearest(toTarget(d.localPosition)); if (near != null) _selected = near; if (_selected == null) return; HapticFeedback.selectionClick(); @@ -544,7 +642,7 @@ class _PreviewScreenState extends State { int? best; var bestD = 60.0; // target units: a little more than a hit's radius for (int i = 0; i < _hits.length; i++) { - final d = (_hits[i] - p).distance; + final d = (TargetScoring.shown(_hits[i]) - p).distance; // where it is drawn if (d < bestD) { bestD = d; best = i; diff --git a/lib/screens/session_screen.dart b/lib/screens/session_screen.dart index 6cf8663..ba9d923 100644 --- a/lib/screens/session_screen.dart +++ b/lib/screens/session_screen.dart @@ -168,6 +168,7 @@ class _SessionScreenState extends State { style: s.target, hits: _hits[target.file.path]?.bullets ?? const [], hitColor: s.bulletColor, + zoomToHits: true, ), ), const SizedBox(width: 12), diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart index 613ca41..df2a5b6 100644 --- a/lib/screens/settings_screen.dart +++ b/lib/screens/settings_screen.dart @@ -151,11 +151,14 @@ class SettingsScreen extends StatelessWidget { ), FutureBuilder( future: _packageInfo, - // Debug builds: long press previews a holiday - builder: (context, snap) => SettingsTile( - icon: Icons.info_outline_rounded, - title: t('Version'), - value: snap.data?.version ?? '', + // Hidden (any build): long press previews a holiday + builder: (context, snap) => GestureDetector( + onLongPress: () => _previewHoliday(context), + child: SettingsTile( + icon: Icons.info_outline_rounded, + title: t('Version'), + value: snap.data?.version ?? '', + ), ), ), ]), @@ -168,7 +171,7 @@ class SettingsScreen extends StatelessWidget { icon: Icons.celebration_outlined, title: 'Holiday preview', subtitle: 'Shows the app as on a day of the holiday', - value: s.debugToday == null ? 'Today' : (s.holiday?.name ?? 'Today'), + value: s.debugNoHoliday ? 'Default' : (s.debugToday == null ? 'Today' : (s.holiday?.name ?? 'Today')), onTap: () => _previewHoliday(context), ), ]), @@ -195,13 +198,24 @@ class SettingsScreen extends StatelessWidget { children: [ SheetOption( label: 'Today', - selected: s.debugToday == null, + subtitle: s.debugToday == null && !s.debugNoHoliday ? null : 'The real date', + selected: s.debugToday == null && !s.debugNoHoliday, showDivider: false, onTap: () { s.previewDay(null); Navigator.pop(sheet); }, ), + SheetOption( + label: 'Default (no holiday)', + subtitle: 'Everyday look, your own target and colour', + leading: TargetThumb(s.ownTarget, size: 32), + selected: s.debugNoHoliday, + onTap: () { + s.previewDay(null, noHoliday: true); + Navigator.pop(sheet); + }, + ), for (final h in HolidayTheme.all) Builder(builder: (_) { // First day of the holiday this year @@ -213,7 +227,7 @@ class SettingsScreen extends StatelessWidget { label: h.name, subtitle: '${DateFormat('d. M.').format(start)} – ${DateFormat('d. M.').format(end)}', leading: TargetThumb(TargetStyle.byId(h.targetId), size: 32), - selected: s.holiday == h && s.debugToday != null, + selected: s.holiday == h && s.debugToday != null && !s.debugNoHoliday, onTap: () { s.previewDay(day); Navigator.pop(sheet); @@ -371,22 +385,32 @@ void showAppearanceSheet(BuildContext context) { children: [ SheetTitle(s.t('Appearance'), trailing: TargetThumb(s.target, size: 52)), Kicker(s.t('Bullet color'), padding: const EdgeInsets.only(bottom: 12)), + // During a holiday its colour gets its own line first (and is the + // one in use until another is picked) + if (s.holiday != null) + Padding( + padding: const EdgeInsets.only(bottom: 12), + child: GestureDetector( + onTap: s.useHolidayColor, + behavior: HitTestBehavior.opaque, + child: Row( + children: [ + _ColorDot(s.holiday!.color, size: 32, selected: s.holidayColorActive), + const SizedBox(width: 10), + Text(s.holiday!.name, style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Palette.current.ink2)), + ], + ), + ), + ), + // Two rows of 8, round the colour wheel LayoutBuilder(builder: (context, box) { const perRow = 8; final size = ((box.maxWidth - (perRow - 1) * 10) / perRow).clamp(28.0, 40.0); + final gap = (box.maxWidth - perRow * size) / (perRow - 1); return Wrap( - spacing: 10, + spacing: gap - 0.01, // exactly 8 per row at any width runSpacing: 12, children: [ - // During a holiday its colour comes first (and is the one in use) - if (s.holiday != null) - GestureDetector( - onTap: s.useHolidayColor, - child: Tooltip( - message: s.holiday!.name, - child: _ColorDot(s.holiday!.color, size: size, selected: s.holidayColorActive), - ), - ), for (final name in AppSettings.bulletColors.keys) GestureDetector( onTap: () => s.setBulletColor(name), @@ -408,13 +432,20 @@ void showAppearanceSheet(BuildContext context) { ); } -/// Three target designs per row; the chosen one has an accent border and a check. +/// Three target designs per row; the chosen one has an accent border. class _TargetGrid extends StatelessWidget { final List styles; const _TargetGrid({required this.styles}); + // Listens itself: the sheet builds it as a const, so the sheet's own + // rebuild never reaches it and the check would stay on the old target @override - Widget build(BuildContext context) { + Widget build(BuildContext context) => ListenableBuilder( + listenable: AppSettings.instance, + builder: (context, _) => _grid(), + ); + + Widget _grid() { final s = AppSettings.instance; final c = Palette.current; return LayoutBuilder(builder: (context, box) { @@ -430,31 +461,16 @@ class _TargetGrid extends StatelessWidget { onTap: () => s.setTarget(style), child: Column( children: [ - Stack( - children: [ - Container( - height: w * 0.92, - width: w, - padding: const EdgeInsets.all(8), - decoration: BoxDecoration( - color: c.isDark ? c.card2 : c.tile, - borderRadius: BorderRadius.circular(14), - border: Border.all(color: style == s.target ? c.accent : Colors.transparent, width: 2), - ), - child: Center(child: TargetThumb(style, size: w * 0.92 - 16)), - ), - if (style == s.target) - Positioned( - top: 6, - right: 6, - child: Container( - width: 20, - height: 20, - decoration: BoxDecoration(color: c.accent, shape: BoxShape.circle), - child: Icon(Icons.check_rounded, size: 14, color: c.onAccent), - ), - ), - ], + Container( + height: w * 0.92, + width: w, + padding: const EdgeInsets.all(8), + decoration: BoxDecoration( + color: c.isDark ? c.card2 : c.tile, + borderRadius: BorderRadius.circular(14), + border: Border.all(color: style == s.target ? c.accent : Colors.transparent, width: 2), + ), + child: Center(child: TargetThumb(style, size: w * 0.92 - 16)), ), const SizedBox(height: 6), Text( diff --git a/lib/screens/target_screen.dart b/lib/screens/target_screen.dart index 7697edb..807ffcc 100644 --- a/lib/screens/target_screen.dart +++ b/lib/screens/target_screen.dart @@ -193,26 +193,27 @@ class _TargetScreenState extends State { ); } - // A ready camera: the hit colour over the whole tile, a solid icon and the - // name in one colour. One not set up is dashed. + // A ready camera: a normal card outlined in the hit colour, its icon on a + // soft badge of that colour, the name in the text colour. One not set up is + // dashed, with a plus. Widget _cameraTile(AppSettings s, Palette c, int position, bool ready) { final name = '${s.t('Camera')} $position'; - final fill = c.accent; - final fg = ready ? Palette.onColor(fill) : c.ink2; final content = Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ - ready - ? Icon(Icons.videocam_rounded, size: 36, color: fg) - : Container( - width: 48, - height: 48, - decoration: BoxDecoration(color: c.tile, borderRadius: BorderRadius.circular(14)), - child: Icon(Icons.add_rounded, size: 26, color: c.muted), - ), - const SizedBox(height: 8), - Text(name, textAlign: TextAlign.center, style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: fg)), + Container( + width: 48, + height: 48, + decoration: BoxDecoration(color: ready ? c.accentSoft : c.tile, borderRadius: BorderRadius.circular(14)), + child: ready + ? Icon(Icons.videocam_rounded, size: 26, color: c.accent) + : Icon(Icons.add_rounded, size: 26, color: c.muted), + ), + const SizedBox(height: 10), + Text(name, + textAlign: TextAlign.center, + style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: ready ? c.ink : c.ink2)), if (!ready) Text(s.t('Not set up'), textAlign: TextAlign.center, style: TextStyle(fontSize: 11.5, color: c.faint)), ], @@ -220,8 +221,8 @@ class _TargetScreenState extends State { ); return AppCard( dashed: !ready, - color: ready ? fill : null, - borderColor: ready ? fill : null, + borderColor: ready ? c.accent : null, + borderWidth: ready ? 1.5 : 1, padding: const EdgeInsets.all(10), onTap: () => _openPosition(position), child: content, @@ -244,6 +245,7 @@ class _TargetScreenState extends State { style: s.target, hits: _lastHits?.bullets ?? const [], hitColor: s.bulletColor, + zoomToHits: true, ), ), const SizedBox(width: 12), diff --git a/lib/screens/target_view.dart b/lib/screens/target_view.dart index d9036a5..944b45b 100644 --- a/lib/screens/target_view.dart +++ b/lib/screens/target_view.dart @@ -10,7 +10,8 @@ import '../widgets/bar_list.dart'; import '../widgets/result_share.dart'; import '../widgets/target_face.dart'; import '../widgets/ui.dart'; -import 'session_screen.dart' show targetCount, shotCount, confirmDelete; +import 'preview_screen.dart'; +import 'session_screen.dart' show SessionScreen, targetCount, shotCount, confirmDelete; /// The result of one target, or of a whole session on one target /// ([isCombinedView]): the score, the target with every hit, the hits grouped @@ -32,6 +33,8 @@ class TargetViewScreen extends StatefulWidget { } class _TargetViewScreenState extends State { + // The targets shown; deleting some from the session list shortens it + late List _files = widget.jsonFiles; List? _targets; // one per file, in the order given TargetHits _all = TargetHits.empty; int? _number; // 1-based number of a single target in its session @@ -41,7 +44,7 @@ class _TargetViewScreenState extends State { bool _showScoring = false; // debug builds: long press the target final _zoom = TransformationController(); - String get _folder => widget.jsonFiles.first.parent.path.split('/').last; + String get _folder => _files.first.parent.path.split('/').last; @override void initState() { @@ -56,7 +59,7 @@ class _TargetViewScreenState extends State { } Future _load() async { - final targets = await TargetRepository.readAllHits(widget.jsonFiles); + final targets = await TargetRepository.readAllHits(_files); int? number; DateTime? date; final sessions = await TargetRepository.loadSessions(); @@ -65,7 +68,7 @@ class _TargetViewScreenState extends State { date = session.date; if (!widget.isCombinedView) { final i = session.targets - .indexWhere((t) => t.file.path == widget.jsonFiles.first.path); + .indexWhere((t) => t.file.path == _files.first.path); if (i >= 0) { number = i + 1; date = session.targets[i].shotAt; @@ -90,12 +93,50 @@ class _TargetViewScreenState extends State { '${p[2]}-${p[1].padLeft(2, '0')}-${p[0].padLeft(2, '0')}'); } + // The editor of "Check hits" on this target's hits; saving overwrites the + // file, then the result is read again + Future _editTarget() async { + final target = _targets?.firstOrNull; + if (target == null) return; + final saved = await Navigator.push( + context, + MaterialPageRoute( + builder: (_) => PreviewScreen.edit( + file: _files.first, + hits: target.bullets, + bulletCount: target.shots < target.bullets.length ? target.bullets.length : target.shots, + ), + ), + ); + if (saved != true || !mounted) return; + await _load(); + widget.refreshFolders(); + } + + // Session view: its training or tournament, to see, edit and delete each + // target; back here, what is left of it is shown again + Future _openSession() async { + final sessions = await TargetRepository.loadSessions(); + final session = sessions.where((x) => x.name == _folder).firstOrNull; + if (session == null || !mounted) return; + await Navigator.push(context, MaterialPageRoute(builder: (_) => SessionScreen(session: session))); + if (!mounted) return; + widget.refreshFolders(); + final left = [for (final f in _files) if (f.existsSync()) f]; + if (left.isEmpty) { + Navigator.pop(context); // every target was deleted + return; + } + _files = left; + await _load(); + } + Future _deleteTarget() async { final s = AppSettings.instance; final ok = await confirmDelete(context, s.t('Are you sure you want to delete this target?')); if (!ok) return; try { - await File(widget.jsonFiles.first.path).delete(); + await File(_files.first.path).delete(); TargetRepository.notifyChanged(); widget.refreshFolders(); if (mounted) Navigator.pop(context); @@ -107,16 +148,16 @@ class _TargetViewScreenState extends State { } } - // Values shown as tiles: 10 down to 7 always (so a missing 10 shows as 0×), - // plus any lower value that was hit; at most 6 tiles. + // Every value from 10 down to 0 + static const List _values = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]; + + // Only the values that were hit, best first: a tile each List<(int value, int count)> _groups() { final counts = {}; for (final v in _all.scores) { counts[v] = (counts[v] ?? 0) + 1; } - final values = {10, 9, 8, 7, ...counts.keys}.toList() - ..sort((a, b) => b.compareTo(a)); - return [for (final v in values.take(6)) (v, counts[v] ?? 0)]; + return [for (final v in _values) if (counts[v] != null) (v, counts[v]!)]; } String get _title => widget.isCombinedView @@ -128,7 +169,7 @@ class _TargetViewScreenState extends State { if (widget.isCombinedView) { return [ if (date != null) dayDate(date, year: true), - targetCount(widget.jsonFiles.length), + targetCount(_files.length), shotCount(_all.shots), ].join(' · '); } @@ -170,7 +211,7 @@ class _TargetViewScreenState extends State { highlight: targets[i].total == best), ] : [ - for (final v in [10, 9, 8, 7, 6]) + for (final (v, _) in _groups()) BarEntry( '$v', _all.scores.where((x) => x == v).length.toDouble(), @@ -202,8 +243,16 @@ class _TargetViewScreenState extends State { final s = AppSettings.instance; final c = Palette.current; final loaded = _targets != null; - return Scaffold( - body: Column( + // The picked target's own background (a holiday's wins) + return AppBackground( + target: true, + child: Scaffold( + body: Stack( + children: [ + // The target, zoomed or not, lives in the window the background + // draws for it: between its score line and its dock line + if (loaded && !_showChart) TargetWindow(child: _target(s)), + Column( children: [ BackHeader( title: loaded ? _title : '', @@ -214,12 +263,15 @@ class _TargetViewScreenState extends State { child: Center(child: CircularProgressIndicator())) else ...[ _scoreRow(s, c), - Expanded(child: _showChart ? _chart(s, c) : _target(s)), + Expanded(child: _showChart ? _chart(s, c) : const SizedBox()), if (!_showChart) _tiles(c), _actions(s, c), ], ], ), + ], + ), + ), ); }, ); @@ -273,7 +325,7 @@ class _TargetViewScreenState extends State { ); } - // The target fills the free space; pinch to zoom in (the default target is + // The target fills its window; pinch to zoom in (the default target is // vectors, so its lines stay sharp), double tap to zoom back out. Widget _target(AppSettings s) { final pressed = _pressedValue; @@ -303,6 +355,13 @@ class _TargetViewScreenState extends State { for (int i = 0; i < scores.length; i++) if (scores[i] == pressed) i }, + // The rest fade while a value is held, so its hits stand out + dimmed: pressed == null + ? const {} + : { + for (int i = 0; i < scores.length; i++) + if (scores[i] != pressed) i + }, ), ), ), @@ -313,25 +372,21 @@ class _TargetViewScreenState extends State { Widget _tiles(Palette c) { final groups = _groups(); + final many = groups.length > 6; return Padding( padding: const EdgeInsets.fromLTRB(AppTheme.edge, 8, AppTheme.edge, 0), - child: Row( + child: TileRow( + gap: many ? 4 : 10, children: [ - for (int i = 0; i < groups.length; i++) ...[ - if (i > 0) const SizedBox(width: 10), - Expanded( - child: ScoreTile( - top: '${groups[i].$2}×', - value: '${groups[i].$1}', - filled: groups[i].$2 > 0, - height: 64, - onTapDown: groups[i].$2 == 0 - ? null - : (_) => setState(() => _pressedValue = groups[i].$1), - onTapEnd: () => setState(() => _pressedValue = null), - ), + for (final (value, count) in groups) + ScoreTile( + top: '$count×', + value: '$value', + height: many ? 56 : 64, + radius: many ? 10 : 14, + onTapDown: (_) => setState(() => _pressedValue = value), + onTapEnd: () => setState(() => _pressedValue = null), ), - ], ], ), ); @@ -379,6 +434,15 @@ class _TargetViewScreenState extends State { 12 + MediaQuery.paddingOf(context).bottom), child: Row( children: [ + // A session: its target list, to see, edit and delete each one. + // A single target: correct its hits. + SquareButton( + size: 52, + icon: Icons.edit_outlined, + tooltip: s.t(widget.isCombinedView ? 'Edit' : 'Edit target'), + onTap: widget.isCombinedView ? _openSession : _editTarget, + ), + const SizedBox(width: 10), Expanded( child: PrimaryButton( label: s.t('Share result'), diff --git a/lib/services/app_settings.dart b/lib/services/app_settings.dart index 6b883cf..eeddc47 100644 --- a/lib/services/app_settings.dart +++ b/lib/services/app_settings.dart @@ -34,20 +34,23 @@ class AppSettings extends ChangeNotifier with WidgetsBindingObserver { /// Hit colours, each tuned for the dark and the light theme. The chosen /// one is the accent of the whole interface. + // Round the colour wheel, then the neutrals: two rows of 8 in the picker. + // No red: a red hit would vanish in the red edge of a selected one. static const Map bulletColors = { - 'Blue': (Color(0xFF4B8EF5), Color(0xFF2D6BD8)), - 'Green': (Color(0xFF3CC764), Color(0xFF1E9A4C)), - 'Yellow': (Color(0xFFF2C12E), Color(0xFFC08E00)), - 'Purple': (Color(0xFFB45EE3), Color(0xFF8E3FBF)), - 'Cyan': (Color(0xFF22C7E0), Color(0xFF12B4CE)), - 'Teal': (Color(0xFF17B3A3), Color(0xFF0E9384)), - 'Indigo': (Color(0xFF6E6CF2), Color(0xFF4F46E5)), - 'Pink': (Color(0xFFF0457A), Color(0xFFD63366)), - 'Lime': (Color(0xFFC9DC3C), Color(0xFF85A00E)), - 'Mint': (Color(0xFF5EE6B0), Color(0xFF1FAE7A)), 'Orange': (Color(0xFFFF8A1F), Color(0xFFE06F00)), - 'Violet': (Color(0xFF8E62F7), Color(0xFF7C3AED)), 'Amber': (Color(0xFFFFB020), Color(0xFFD18A00)), + 'Yellow': (Color(0xFFF2C12E), Color(0xFFC08E00)), + 'Lime': (Color(0xFFC9DC3C), Color(0xFF85A00E)), + 'Green': (Color(0xFF3CC764), Color(0xFF1E9A4C)), + 'Mint': (Color(0xFF5EE6B0), Color(0xFF1FAE7A)), + 'Teal': (Color(0xFF17B3A3), Color(0xFF0E9384)), + 'Cyan': (Color(0xFF22C7E0), Color(0xFF12B4CE)), + 'Blue': (Color(0xFF4B8EF5), Color(0xFF2D6BD8)), + 'Indigo': (Color(0xFF6E6CF2), Color(0xFF4F46E5)), + 'Violet': (Color(0xFF8E62F7), Color(0xFF7C3AED)), + 'Purple': (Color(0xFFB45EE3), Color(0xFF8E3FBF)), + 'Magenta': (Color(0xFFE04BD8), Color(0xFFB8269F)), + 'Pink': (Color(0xFFF0457A), Color(0xFFD63366)), 'Brown': (Color(0xFFB07A55), Color(0xFF8A5536)), 'Grey': (Color(0xFFA3AAB2), Color(0xFF6F757C)), }; @@ -93,7 +96,10 @@ class AppSettings extends ChangeNotifier with WidgetsBindingObserver { DateTime get today => debugToday ?? DateTime.now(); - HolidayTheme? get holiday => HolidayTheme.on(today); + /// Preview only: show the everyday look even on a holiday. + bool debugNoHoliday = false; + + HolidayTheme? get holiday => debugNoHoliday ? null : HolidayTheme.on(today); /// True while a holiday decides the target. bool get targetLocked => holiday != null; @@ -120,7 +126,16 @@ class AppSettings extends ChangeNotifier with WidgetsBindingObserver { } /// The holiday's screen background (the everyday one is painted, see AppBackground). - String get background => holiday?.background(isDark) ?? ''; + /// Screen background of the whole app: the holiday's, else the everyday one. + String get background => holiday?.background(isDark) ?? HolidayTheme.everydayBackground(isDark); + + /// Background of the target screens (result, check hits, edit): the shown + /// target's own – the holiday target's during a holiday – with the window + /// lines the target sits between (target-backgrounds/v3). + String get targetBackground { + final h = holiday; + return (h == null ? _target : TargetStyle.byId(h.targetId)).background(isDark); + } // A new day may start or end a holiday @override @@ -165,6 +180,9 @@ class AppSettings extends ChangeNotifier with WidgetsBindingObserver { } /// The target shown: the holiday's while one is on, otherwise the user's. + /// The user's own pick, whatever the holiday. + TargetStyle get ownTarget => _target; + TargetStyle get target { final h = holiday; return h == null ? _target : TargetStyle.byId(h.targetId); @@ -257,9 +275,11 @@ class AppSettings extends ChangeNotifier with WidgetsBindingObserver { await _prefs.setInt('targetStyle', style.id); } - /// Debug: show the look of [day] (null = today). - void previewDay(DateTime? day) { + /// Preview: show the look of [day] (null = today); [noHoliday] shows the + /// everyday look whatever the day. Not saved: a restart is back to today. + void previewDay(DateTime? day, {bool noHoliday = false}) { debugToday = day; + debugNoHoliday = noHoliday; notifyListeners(); } diff --git a/lib/services/league_service.dart b/lib/services/league_service.dart new file mode 100644 index 0000000..52540dc --- /dev/null +++ b/lib/services/league_service.dart @@ -0,0 +1,147 @@ +import 'dart:async'; +import 'dart:convert'; +import 'package:http/http.dart' as http; + +/// The club's shooting league (liga.bl3kunja.top): the current league, its +/// tournaments and the live standings, from the site's public JSON API. +/// +/// `GET /api/lestvica` is the current league (what the site's Lestvica page +/// shows). The app reads it only when the Liga tab is opened (or pulled to +/// refresh), never in the background. +class LeagueService { + static const String site = 'https://liga.bl3kunja.top'; + static const Duration _timeout = Duration(seconds: 10); + + final http.Client _client; + LeagueService([http.Client? client]) : _client = client ?? http.Client(); + + Future standings() async { + final res = await _client.get(Uri.parse('$site/api/lestvica')).timeout(_timeout); + if (res.statusCode != 200) throw LeagueException('HTTP ${res.statusCode}'); + return LeagueStandings.fromJson(jsonDecode(utf8.decode(res.bodyBytes)) as Map); + } + + void dispose() => _client.close(); +} + +class LeagueException implements Exception { + final String message; + const LeagueException(this.message); + @override + String toString() => message; +} + +class LeagueStandings { + final League league; + final List rounds; + final List players; // by rank + + const LeagueStandings({required this.league, required this.rounds, required this.players}); + + factory LeagueStandings.fromJson(Map j) => LeagueStandings( + league: League.fromJson(j['league'] as Map), + rounds: [for (final r in (j['rounds'] as List? ?? const [])) LeagueRound.fromJson(r as Map)] + ..sort((a, b) => a.number.compareTo(b.number)), + players: [for (final p in (j['players'] as List? ?? const [])) LeaguePlayer.fromJson(p as Map)] + ..sort((a, b) => a.rank.compareTo(b.rank)), + ); + + /// The tournament that is open now, if any. + LeagueRound? get openRound => rounds.where((r) => r.isOpen).firstOrNull; + + /// The next one to open, if none is open. + LeagueRound? get nextRound => rounds.where((r) => r.isUpcoming).firstOrNull; +} + +class League { + final int id; + final String name; // "Liga 2026-2027" + final String status; // "active", … + final int counted; // best N tournaments count + final int shots; // shots per target + final int targets; // targets per tournament + + const League({required this.id, required this.name, required this.status, required this.counted, required this.shots, required this.targets}); + + factory League.fromJson(Map j) => League( + id: (j['id'] as num?)?.toInt() ?? 0, + name: j['name'] as String? ?? '', + status: j['status'] as String? ?? '', + counted: (j['counted'] as num?)?.toInt() ?? 0, + shots: (j['shots'] as num?)?.toInt() ?? 0, + targets: (j['targets'] as num?)?.toInt() ?? 0, + ); + + bool get isActive => status == 'active'; +} + +class LeagueRound { + final int number; + final DateTime? startsAt; + final DateTime? endsAt; + final String state; // "open", "upcoming", or done + final int submissions; // clubs that have entered their results + + const LeagueRound({required this.number, this.startsAt, this.endsAt, required this.state, required this.submissions}); + + factory LeagueRound.fromJson(Map j) => LeagueRound( + number: (j['number'] as num?)?.toInt() ?? 0, + startsAt: DateTime.tryParse(j['starts_at'] as String? ?? ''), + endsAt: DateTime.tryParse(j['ends_at'] as String? ?? ''), + state: j['state'] as String? ?? '', + submissions: (j['submissions'] as num?)?.toInt() ?? 0, + ); + + bool get isOpen => state == 'open'; + bool get isUpcoming => state == 'upcoming'; + bool get isDone => !isOpen && !isUpcoming; +} + +class LeaguePlayer { + final int rank; + final String name; + final String club; + final List cells; // one per tournament; null = not shot + final int total; // all tournaments + final int finalScore; // the counted ones: what the ranking uses + final int tens; // tie-break + final int played; + + const LeaguePlayer({ + required this.rank, + required this.name, + required this.club, + required this.cells, + required this.total, + required this.finalScore, + required this.tens, + required this.played, + }); + + factory LeaguePlayer.fromJson(Map j) => LeaguePlayer( + rank: (j['rank'] as num?)?.toInt() ?? 0, + name: j['name'] as String? ?? '', + club: j['club'] as String? ?? '', + cells: [for (final c in (j['cells'] as List? ?? const [])) c == null ? null : LeagueCell.fromJson(c as Map)], + total: (j['total'] as num?)?.toInt() ?? 0, + finalScore: (j['final'] as num?)?.toInt() ?? 0, + tens: (j['tens'] as num?)?.toInt() ?? 0, + played: (j['played'] as num?)?.toInt() ?? 0, + ); +} + +class LeagueCell { + final int score; + final int tens; + final bool counted; // among the best N + final bool joker; + + const LeagueCell({required this.score, required this.tens, required this.counted, required this.joker}); + + factory LeagueCell.fromJson(Map j) => LeagueCell( + score: (j['score'] as num?)?.toInt() ?? 0, + tens: (j['tens'] as num?)?.toInt() ?? 0, + counted: j['counted'] as bool? ?? true, + joker: j['joker'] as bool? ?? false, + ); +} diff --git a/lib/theme/app_theme.dart b/lib/theme/app_theme.dart index 3a4b840..d773fc4 100644 --- a/lib/theme/app_theme.dart +++ b/lib/theme/app_theme.dart @@ -321,11 +321,47 @@ class AppTheme { ); } -/// The screen background of the design (holiday-themes/v2, "ozadje"): the -/// everyday one in dark or light, or the current holiday's. +/// The screen background, in dark or light: the current holiday's +/// (holiday-themes/v3) for the whole app, otherwise the everyday "00 Privzeto". +/// [target]: the target screens' background instead, the picked target's own +/// (target-backgrounds/v2) unless a holiday is on; those screens wrap +/// themselves in it, over the page's everyday one. +/// The target's window on a target screen: the band the target backgrounds +/// (target-backgrounds/v3, drawn for a 390 × 844 screen and shown with +/// BoxFit.cover, see [AppBackground]) leave for it, between the line under +/// the header and the line over the tiles and buttons. Put it in a [Stack] +/// that fills the screen; the page's other parts go above and below it. +class TargetWindow extends StatelessWidget { + final Widget child; + const TargetWindow({super.key, required this.child}); + + static const double _bgWidth = 390, _bgHeight = 844; + static const double _top = 186.5, _bottom = 659; + + /// Where the two lines are on a screen of [size]: (y of the upper, y of the lower). + static (double, double) lines(Size size) { + final k = size.width / _bgWidth > size.height / _bgHeight ? size.width / _bgWidth : size.height / _bgHeight; + final dy = (size.height - _bgHeight * k) / 2; + return (dy + _top * k, dy + _bottom * k); + } + + @override + Widget build(BuildContext context) { + return Positioned.fill( + child: LayoutBuilder(builder: (context, box) { + final (top, bottom) = lines(box.biggest); + return Stack(children: [ + Positioned(left: 0, right: 0, top: top, height: bottom - top, child: child), + ]); + }), + ); + } +} + class AppBackground extends StatelessWidget { final Widget child; - const AppBackground({super.key, required this.child}); + final bool target; + const AppBackground({super.key, required this.child, this.target = false}); @override Widget build(BuildContext context) { @@ -337,12 +373,8 @@ class AppBackground extends StatelessWidget { fit: StackFit.expand, children: [ ColoredBox(color: s.palette.bg), - // Holidays have their drawn backgrounds; the everyday one is - // painted here, cleaner than the design's busier image - if (s.holiday != null) - Image.asset(s.background, fit: BoxFit.cover, gaplessPlayback: true, filterQuality: FilterQuality.medium) - else - CustomPaint(painter: _EverydayBackground(dark: s.isDark)), + Image.asset(target ? s.targetBackground : s.background, + fit: BoxFit.cover, gaplessPlayback: true, filterQuality: FilterQuality.medium), child!, ], ); @@ -373,55 +405,3 @@ class _BackgroundTransitions extends PageTransitionsBuilder { inner.buildTransitions(route, context, animation, secondaryAnimation, AppBackground(child: child)); } -/// The everyday background ("00 Privzeto", holiday-themes/v2) in a calmer -/// version: the same gradient and two corners of target rings, but three -/// widely spaced, faint rings per corner and a few fine dots. -class _EverydayBackground extends CustomPainter { - final bool dark; - const _EverydayBackground({required this.dark}); - - @override - void paint(Canvas canvas, Size size) { - final rect = Offset.zero & size; - canvas.drawRect( - rect, - Paint() - ..shader = LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: dark ? const [Color(0xFF15191C), Color(0xFF0B0D0F)] : const [Color(0xFFFAFAF7), Color(0xFFECEDE7)], - ).createShader(rect), - ); - // Design units: a 390 × 844 screen - final k = size.width / 390; - final ink = dark ? Colors.white : const Color(0xFF16181B); - final ring = Paint() - ..style = PaintingStyle.stroke - ..isAntiAlias = true; - void rings(Offset c, List radii) { - for (int i = 0; i < radii.length; i++) { - ring - ..strokeWidth = (i == radii.length - 1 ? 1.6 : 1.1) * k - ..color = ink.withValues(alpha: dark ? (i == radii.length - 1 ? 0.09 : 0.06) : (i == radii.length - 1 ? 0.08 : 0.05)); - canvas.drawCircle(c, radii[i] * k, ring); - } - } - - rings(Offset(size.width + 40 * k, -30 * k), const [150, 260, 380]); - rings(Offset(-60 * k, size.height + 40 * k), const [140, 250]); - - // A few fine dots, always in the same places - final dot = Paint()..color = ink.withValues(alpha: dark ? 0.16 : 0.12); - const spots = [ - (0.12, 0.08), (0.78, 0.18), (0.34, 0.31), (0.88, 0.44), (0.07, 0.52), - (0.62, 0.61), (0.25, 0.74), (0.91, 0.83), (0.48, 0.92), (0.70, 0.36), - ]; - for (int i = 0; i < spots.length; i++) { - final (x, y) = spots[i]; - canvas.drawCircle(Offset(x * size.width, y * size.height), (i.isEven ? 1.4 : 1.0) * k, dot); - } - } - - @override - bool shouldRepaint(_EverydayBackground old) => old.dark != dark; -} diff --git a/lib/utils/target_scoring.dart b/lib/utils/target_scoring.dart index 46a3901..e003c18 100644 --- a/lib/utils/target_scoring.dart +++ b/lib/utils/target_scoring.dart @@ -2,7 +2,7 @@ import 'dart:math'; import 'dart:ui'; /// The one scoring rule for a shot, in the 1200 × 1200 space every target -/// design shares (target-designs/v3: centre 600/600, ring 1 at r 510, the +/// design shares (target-designs/v5: centre 600/600, ring 1 at r 510, the /// black at r 180). Saving, the preview and the target view all use it, so a /// shot scores the same everywhere and on every design. /// @@ -17,6 +17,16 @@ class TargetScoring { static const double bulletRadius = 25; static const double bulletDiameter = 53; // drawn size of a hit + // Where a hit's centre may be drawn: the 1200 square, less the dot's + // radius and a little air. Outside ring 1 a miss simply lies on the screen + // background, where it landed + static const double _hitInset = bulletDiameter / 2 + 2; // 28.5 + + /// [p] if its whole dot is inside the target's square, otherwise the + /// nearest place that is (only for shots that landed far off; still 0). + static Offset shown(Offset p) => + Offset(p.dx.clamp(_hitInset, size - _hitInset), p.dy.clamp(_hitInset, size - _hitInset)); + /// Outer edge of ring 10, 9, ... 1, measured from [center]. /// /// A shot touching a ring line counts the higher value, so each edge is the @@ -50,15 +60,20 @@ class TargetScoring { /// Where to draw a shot that was scored by hand, in direction [angle] /// (radians): the middle of the band of positions [scoreAt] gives [score] - /// for, so the dot always scores what was entered. + /// for, so the dot always scores what was entered. A 0 goes towards the + /// corner nearest to [angle], clear of ring 1's decoration. static Offset positionFor(int score, double angle) { final s = score.clamp(0, 10); + if (s == 0) { + // Nearest diagonal, keeping a little of the angle so 0s don't stack + final diagonal = ((angle - pi / 4) / (pi / 2)).round() * (pi / 2) + pi / 4; + final a = diagonal + (angle - diagonal) * 0.3; + return shown(center + Offset(cos(a), sin(a)) * 700); + } // Distance of the bullet's edge from the centre, middle of the band final double edge; if (s == 10) { edge = (-bulletRadius + rings[0]) / 2; // bullet over the centre - } else if (s == 0) { - edge = rings.last + 30; // just outside the target } else { edge = (rings[9 - s] + rings[10 - s]) / 2; } diff --git a/lib/utils/translations_v2.dart b/lib/utils/translations_v2.dart index f44cae4..25e6837 100644 --- a/lib/utils/translations_v2.dart +++ b/lib/utils/translations_v2.dart @@ -4,6 +4,21 @@ const Map> translationsV2 = { // Changed wording 'Contacts': {'English': 'Contacts', 'Slovenian': 'Kontakti', 'German': 'Kontakte'}, + + // Koledar → Liga (liga.bl3kunja.top) + 'Magenta': {'English': 'Magenta', 'Slovenian': 'Magenta', 'German': 'Magenta'}, + 'League': {'English': 'League', 'Slovenian': 'Liga', 'German': 'Liga'}, + 'Standings': {'English': 'Standings', 'Slovenian': 'Lestvica', 'German': 'Rangliste'}, + '{n}. tournament is open': {'English': 'Tournament {n} is open', 'Slovenian': '{n}. turnir je odprt', 'German': '{n}. Turnier ist offen'}, + '{n}. tournament': {'English': 'Tournament {n}', 'Slovenian': '{n}. turnir', 'German': '{n}. Turnier'}, + 'until {d}': {'English': 'until {d}', 'Slovenian': 'do {d}', 'German': 'bis {d}'}, + 'from {d}': {'English': 'from {d}', 'Slovenian': 'od {d}', 'German': 'ab {d}'}, + 'Entries: {n}': {'English': 'Entries: {n}', 'Slovenian': 'Oddano: {n}', 'German': 'Abgaben: {n}'}, + 'The league has finished': {'English': 'The league has finished', 'Slovenian': 'Liga je zaključena', 'German': 'Die Liga ist beendet'}, + 'Best {n} count': {'English': 'Best {n} count', 'Slovenian': 'Šteje najboljših {n}', 'German': 'Die besten {n} zählen'}, + 'Could not load the league': {'English': 'Could not load the league', 'Slovenian': 'Lige ni bilo mogoče naložiti', 'German': 'Liga konnte nicht geladen werden'}, + 'Open the league website': {'English': 'Open the league website', 'Slovenian': 'Odpri stran lige', 'German': 'Liga-Website öffnen'}, + 'No results yet': {'English': 'No results yet', 'Slovenian': 'Še ni rezultatov', 'German': 'Noch keine Ergebnisse'}, 'COMPETITION': {'English': 'COMPETITION', 'Slovenian': 'TEKMA', 'German': 'WETTKAMPF'}, // Streljanje @@ -53,13 +68,15 @@ const Map> translationsV2 = { // Preveri zadetke 'Check hits': {'English': 'Check hits', 'Slovenian': 'Preveri zadetke', 'German': 'Treffer prüfen'}, - '{n} hits detected · correct them if needed': {'English': '{n} hits detected · correct them if needed', 'Slovenian': '{n} zadetkov zaznanih · popravi, če je treba', 'German': '{n} Treffer erkannt · bei Bedarf korrigieren'}, + '{n} hits detected': {'English': '{n} hits detected', 'Slovenian': '{n} zadetkov zaznanih', 'German': '{n} Treffer erkannt'}, 'Save to': {'English': 'Save to', 'Slovenian': 'Shrani v', 'German': 'Speichern in'}, 'new': {'English': 'new', 'Slovenian': 'nova', 'German': 'neu'}, 'today': {'English': 'today', 'Slovenian': 'danes', 'German': 'heute'}, 'Add hit': {'English': 'Add hit', 'Slovenian': 'Dodaj zadetek', 'German': 'Treffer hinzufügen'}, 'Remove hit': {'English': 'Remove hit', 'Slovenian': 'Odstrani zadetek', 'German': 'Treffer entfernen'}, 'Save target': {'English': 'Save target', 'Slovenian': 'Shrani tarčo', 'German': 'Scheibe speichern'}, + 'Edit target': {'English': 'Edit target', 'Slovenian': 'Uredi tarčo', 'German': 'Scheibe bearbeiten'}, + 'Save changes': {'English': 'Save changes', 'Slovenian': 'Shrani spremembe', 'German': 'Änderungen speichern'}, 'Hold and drag': {'English': 'Hold and drag', 'Slovenian': 'Drži in povleci', 'German': 'Halten und ziehen'}, 'Its value; then drag it to where it hit.': {'English': 'Its value; then drag it to where it hit.', 'Slovenian': 'Njegova vrednost; nato ga povleci na mesto zadetka.', 'German': 'Sein Wert; dann an die Trefferstelle ziehen.'}, 'Image not available': {'English': 'Image not available', 'Slovenian': 'Slika ni na voljo', 'German': 'Bild nicht verfügbar'}, @@ -73,15 +90,15 @@ const Map> translationsV2 = { 'Slovenian': 'Drži in povleci po tarči, da premakneš izbrani zadetek; povečevalo pokaže, kje je.', 'German': 'Halten und auf der Scheibe ziehen, um den gewählten Treffer zu verschieben; eine Lupe zeigt, wo er liegt.', }, - 'Add hit: for a shot that was not found. Remove hit: deletes the picked one.': { - 'English': 'Add hit: for a shot that was not found. Remove hit: deletes the picked one.', - 'Slovenian': 'Dodaj zadetek: za strel, ki ni bil najden. Odstrani zadetek: izbriše izbranega.', - 'German': 'Treffer hinzufügen: für einen nicht gefundenen Schuss. Treffer entfernen: löscht den gewählten.', + '+ tile: for a shot that was not found. Bin: deletes the picked hit.': { + 'English': '+ tile: for a shot that was not found. Bin: deletes the picked hit.', + 'Slovenian': 'Ploščica +: za strel, ki ni bil najden. Koš: izbriše izbrani zadetek.', + 'German': 'Kachel +: für einen nicht gefundenen Schuss. Papierkorb: löscht den gewählten Treffer.', }, - 'Save to: training or tournament, and which folder. The last one is chosen for you.': { - 'English': 'Save to: training or tournament, and which folder. The last one is chosen for you.', - 'Slovenian': 'Shrani v: trening ali tekmovanje in katera mapa. Zadnja je že izbrana.', - 'German': 'Speichern in: Training oder Wettkampf und welcher Ordner. Der letzte ist vorausgewählt.', + 'Button bottom left: training or tournament. The folder on top: where it is saved; the last one is chosen for you.': { + 'English': 'Button bottom left: training or tournament. The folder on top: where it is saved; the last one is chosen for you.', + 'Slovenian': 'Gumb levo spodaj: trening ali tekmovanje. Mapa zgoraj: kam se shrani; zadnja je že izbrana.', + 'German': 'Knopf unten links: Training oder Wettkampf. Der Ordner oben: wohin gespeichert wird; der letzte ist vorausgewählt.', }, 'Photo icon: see the photo with what was detected.': { 'English': 'Photo icon: see the photo with what was detected.', diff --git a/lib/widgets/bar_list.dart b/lib/widgets/bar_list.dart index ea58c27..97d583f 100644 --- a/lib/widgets/bar_list.dart +++ b/lib/widgets/bar_list.dart @@ -39,6 +39,16 @@ class BarList extends StatelessWidget { String tick(double v) => v == v.roundToDouble() ? '${v.round()}' : v.toStringAsFixed(1); return LayoutBuilder(builder: (context, box) { final barWidth = box.maxWidth - labelWidth - valueWidth; + // 26 high, thinner when many rows share little height (e.g. 10 … 0) + final ticksHeight = ticks.isEmpty ? 0.0 : 20 * scale; + final rowHeight = entries.isEmpty || !box.hasBoundedHeight + ? double.infinity + : (box.maxHeight - ticksHeight) / entries.length; + final barHeight = (rowHeight * 0.75).clamp(4.0, 26 * scale); + // Text shrinks with thin rows too, so many bars (a session of 20 + // targets) don't run their labels and values into each other + final labelSize = (rowHeight * 0.78).clamp(6.0, 12 * scale); + final valueSize = (rowHeight * 0.85).clamp(6.0, 15 * scale); return Column( children: [ Expanded( @@ -51,8 +61,10 @@ class BarList extends StatelessWidget { SizedBox( width: labelWidth, child: Text(e.label, + maxLines: 1, style: TextStyle( - fontSize: 12 * scale, + fontSize: labelSize, + height: 1, fontWeight: FontWeight.w600, color: e.goldLabel ? c.gold : c.muted)), ), @@ -62,16 +74,16 @@ class BarList extends StatelessWidget { alignment: Alignment.centerLeft, children: [ Container( - height: 26 * scale, - decoration: BoxDecoration(color: c.tile, borderRadius: BorderRadius.circular(7 * scale)), + height: barHeight, + decoration: BoxDecoration(color: c.tile, borderRadius: BorderRadius.circular(barHeight * 0.27)), ), FractionallySizedBox( widthFactor: max <= 0 ? 0 : (e.value / max).clamp(0.0, 1.0), child: Container( - height: 26 * scale, + height: barHeight, decoration: BoxDecoration( color: e.highlight ? c.gold : c.accent, - borderRadius: BorderRadius.circular(7 * scale), + borderRadius: BorderRadius.circular(barHeight * 0.27), ), ), ), @@ -85,7 +97,8 @@ class BarList extends StatelessWidget { child: Text(e.valueText, maxLines: 1, style: TextStyle( - fontSize: 15 * scale, + fontSize: valueSize, + height: 1, fontWeight: FontWeight.w700, color: e.highlight ? c.gold : (e.value == 0 ? c.faint : c.ink), fontFeatures: AppTheme.tnum)), diff --git a/lib/widgets/progress_chart.dart b/lib/widgets/progress_chart.dart index 366f7d6..3e4a33b 100644 --- a/lib/widgets/progress_chart.dart +++ b/lib/widgets/progress_chart.dart @@ -200,7 +200,7 @@ class _ChartPainter extends CustomPainter { // Gridlines + y labels in each axis series' colour final grid = Paint() ..color = gridColor - ..strokeWidth = 1; + ..strokeWidth = 0.6; for (final f in [0.0, 0.5, 1.0]) { final y = plot.bottom - plot.height * f; canvas.drawLine(Offset(axis, y), Offset(size.width - axis, y), grid); @@ -232,7 +232,7 @@ class _ChartPainter extends CustomPainter { path, Paint() ..color = s.color - ..strokeWidth = 2 + ..strokeWidth = 1.2 ..style = PaintingStyle.stroke ..strokeJoin = StrokeJoin.round, ); @@ -240,8 +240,8 @@ class _ChartPainter extends CustomPainter { for (int i = 0; i < n; i++) { final isSel = i == selected; final p = Offset(xAt(i), yAt(s.values[i], r)); - canvas.drawCircle(p, isSel ? 6 : 4.5, Paint()..color = surfaceColor); - canvas.drawCircle(p, isSel ? 4.5 : 3.5, Paint()..color = s.color); + canvas.drawCircle(p, isSel ? 5 : 2.8, Paint()..color = surfaceColor); + canvas.drawCircle(p, isSel ? 3.8 : 2, Paint()..color = s.color); } } diff --git a/lib/widgets/result_share.dart b/lib/widgets/result_share.dart index 73e4048..f0eff6b 100644 --- a/lib/widgets/result_share.dart +++ b/lib/widgets/result_share.dart @@ -163,19 +163,17 @@ class ResultShareCard extends StatelessWidget { ), ), const SizedBox(height: 10), - Row( + TileRow( + gap: data.tiles.length > 6 ? 3 : 6, children: [ - for (int i = 0; i < data.tiles.length; i++) ...[ - if (i > 0) const SizedBox(width: 6), - Expanded( - child: ScoreTile( - top: data.tiles[i].$1, - value: data.tiles[i].$2, - filled: data.tiles[i].$3, - height: 60, - ), + for (final (top, value, filled) in data.tiles) + ScoreTile( + top: top, + value: value, + filled: filled, + height: 60, + radius: data.tiles.length > 6 ? 9 : 14, ), - ], ], ), ], diff --git a/lib/widgets/target_face.dart b/lib/widgets/target_face.dart index f038364..ab972a9 100644 --- a/lib/widgets/target_face.dart +++ b/lib/widgets/target_face.dart @@ -3,10 +3,13 @@ import '../models/target_style.dart'; import '../utils/target_scoring.dart'; /// A target design with hits on it, drawn in the shared 1200 × 1200 space and -/// scaled to the space it gets (always square). +/// scaled to the space it gets (always square). The designs are transparent +/// outside the target; a miss is drawn where it landed, on the screen +/// background. The small previews ([zoomToHits]) show the target only, +/// without the misses. /// /// The default target is painted as vectors, so its rings and numbers stay -/// sharp at any size or zoom; the other designs are their v3 images. +/// sharp at any size or zoom; the other designs are their v5 images. class TargetFace extends StatelessWidget { final TargetStyle style; final List hits; // in target space (0–1200) @@ -14,6 +17,7 @@ class TargetFace extends StatelessWidget { final Set highlighted; // indexes of [hits] drawn with a ring final Set dimmed; // indexes drawn faded (e.g. other values while one is pressed) final bool showScoring; // debug: the radii the scoring uses, over the design + final bool zoomToHits; // small previews: the target only, zoomed in on the shots const TargetFace({ super.key, @@ -23,18 +27,38 @@ class TargetFace extends StatelessWidget { this.highlighted = const {}, this.dimmed = const {}, this.showScoring = false, + this.zoomToHits = false, }); + + + /// How far [zoomToHits] zooms: just enough, round the centre, to keep every + /// shot (and a little air) in view; never past 3× and never so far that the + /// black and ring 6 are cut, so there is always something to read them by. + static double zoomFor(List hits) { + if (hits.isEmpty) return 1; + var r = 0.0; + for (final h in hits) { + final d = (TargetScoring.shown(h) - TargetScoring.center).distance; + if (d > r) r = d; + } + final view = (r + TargetScoring.bulletDiameter / 2 + 30).clamp(260.0, TargetScoring.size / 2); + return (TargetScoring.size / 2 / view).clamp(1.0, 3.0); + } + @override Widget build(BuildContext context) { final asset = style.asset; - return AspectRatio( + // Small previews: the target only, so misses are left out + final hits = zoomToHits ? [for (final h in this.hits) if (TargetScoring.scoreAt(h) > 0) h] : this.hits; + final zoom = zoomToHits ? zoomFor(hits) : 1.0; + final face = AspectRatio( aspectRatio: 1, child: Stack( fit: StackFit.expand, children: [ if (asset == null) - const RepaintBoundary(child: CustomPaint(painter: DefaultTargetPainter(glow: true))) + const RepaintBoundary(child: CustomPaint(painter: DefaultTargetPainter())) else Image.asset(asset, fit: BoxFit.contain, filterQuality: FilterQuality.medium, gaplessPlayback: true), if (showScoring) const CustomPaint(painter: ScoringRingsPainter()), @@ -45,9 +69,28 @@ class TargetFace extends StatelessWidget { ], ), ); + if (zoom == 1) return face; + return AspectRatio( + aspectRatio: 1, + child: LayoutBuilder( + builder: (context, box) => ClipRRect( + borderRadius: BorderRadius.circular(box.biggest.shortestSide * 0.1), + child: Transform.scale(scale: zoom, child: face), + ), + ), + ); } } +/// Maps the shared target space into a square of [size], centred; returns +/// the scale (screen px per target unit). +double toFaceSpace(Canvas canvas, Size size) { + final s = size.shortestSide / TargetScoring.size; + canvas.translate((size.width - size.shortestSide) / 2, (size.height - size.shortestSide) / 2); + canvas.scale(s); + return s; +} + /// Small preview of a design, for the pickers and the settings row. class TargetThumb extends StatelessWidget { final TargetStyle style; @@ -61,7 +104,7 @@ class TargetThumb extends StatelessWidget { return SizedBox.square( dimension: size, child: asset == null - ? CustomPaint(painter: DefaultTargetPainter(glow: true, numbers: size >= 60)) + ? CustomPaint(painter: DefaultTargetPainter(numbers: size >= 60)) : Image.asset( asset, fit: BoxFit.contain, @@ -72,52 +115,44 @@ class TargetThumb extends StatelessWidget { } } -/// The default target ("00 Privzeta · brez sijaja") in vectors: white paper -/// ending on ring 1, black 7–10, numbers 1–8 on the four axes. [glow] adds a -/// small glow (white rim, short light-blue halo). +/// The default target ("00 Privzeta", target-designs/v5) in vectors: white +/// paper ending on ring 1, black 7–10, numbers 1–8 on the four axes, no glow. class DefaultTargetPainter extends CustomPainter { - final bool glow; final bool numbers; - const DefaultTargetPainter({this.glow = false, this.numbers = true}); + const DefaultTargetPainter({this.numbers = true}); - static const double _paper = 510; - static const Color _glowOuter = Color(0xFF9FD8FF); // Outer radius of score zone k (1–9); zone 10 is the centre dot static double ring(int k) => k == 10 ? 15 : 15 + 55 * (10 - k).toDouble(); @override void paint(Canvas canvas, Size size) { - final s = size.shortestSide / TargetScoring.size; canvas.save(); - canvas.translate((size.width - size.shortestSide) / 2, (size.height - size.shortestSide) / 2); - canvas.scale(s); + toFaceSpace(canvas, size); const c = TargetScoring.center; - if (glow) { - // figcraft drop-shadow "radius" is the blur; Flutter wants sigma ≈ blur / 2 - void blurDisc(double r, Color color, double blur) => canvas.drawCircle( - c, r, Paint()..color = color..maskFilter = MaskFilter.blur(BlurStyle.normal, blur / 2)); - // A small glow: a short light-blue halo and a white rim - blurDisc(_paper + 2, _glowOuter.withValues(alpha: 0.55), 40); - blurDisc(_paper + 1, Colors.white.withValues(alpha: 0.7), 10); - } - // Paper, then the black (zones 7–10) - canvas.drawCircle(c, _paper, Paint()..color = Colors.white); - canvas.drawCircle(c, ring(7), Paint()..color = Colors.black); - - final line = Paint() - ..style = PaintingStyle.stroke - ..isAntiAlias = true; + // Ring lines are filled discs painted from the outside in (line colour out + // to r + w/2, then the zone colour from r − w/2), not stroked circles: + // Impeller draws thin stroked circles unevenly, some rings thinner than + // the rest + final black = Paint()..color = Colors.black; + final white = Paint()..color = Colors.white; + const paperLine = 2.0; + const blackLine = 3.0; + // Paper with lines 1–6 (ring 1 is its edge) for (int k = 1; k <= 6; k++) { - canvas.drawCircle(c, ring(k), line..color = Colors.black..strokeWidth = 3); + canvas.drawCircle(c, ring(k) + paperLine / 2, black); + canvas.drawCircle(c, ring(k) - paperLine / 2, white); } + // The black (zones 7–10) with white lines 8 and 9 + canvas.drawCircle(c, ring(7), black); for (final k in [8, 9]) { - canvas.drawCircle(c, ring(k), line..color = Colors.white..strokeWidth = 5); + canvas.drawCircle(c, ring(k) + blackLine / 2, white); + canvas.drawCircle(c, ring(k) - blackLine / 2, black); } - canvas.drawCircle(c, ring(10), Paint()..color = Colors.white); + canvas.drawCircle(c, ring(10), white); if (numbers) { for (int k = 1; k <= 8; k++) { @@ -146,7 +181,7 @@ class DefaultTargetPainter extends CustomPainter { } @override - bool shouldRepaint(DefaultTargetPainter old) => old.glow != glow || old.numbers != numbers; + bool shouldRepaint(DefaultTargetPainter old) => old.numbers != numbers; } /// Hits in target space: a filled dot of [TargetScoring.bulletDiameter] with a @@ -164,10 +199,8 @@ class HitsPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { - final s = size.shortestSide / TargetScoring.size; canvas.save(); - canvas.translate((size.width - size.shortestSide) / 2, (size.height - size.shortestSide) / 2); - canvas.scale(s); + toFaceSpace(canvas, size); const r = TargetScoring.bulletDiameter / 2; final rim = Color.lerp(color, Colors.black, 0.6)!; @@ -179,21 +212,22 @@ class HitsPainter extends CustomPainter { if (highlighted.contains(i)) i, ]; for (final i in order) { - final p = hits[i]; + final p = TargetScoring.shown(hits[i]); // a shot far off is kept in the square final selected = highlighted.contains(i); final faded = dimmed.contains(i); // Semi-transparent, so overlapping hits and the rings under them show through canvas.drawCircle(p + const Offset(0, 2), r, - Paint()..color = Colors.black.withValues(alpha: faded ? 0.05 : 0.18)..maskFilter = const MaskFilter.blur(BlurStyle.normal, 3)); - canvas.drawCircle(p, r, Paint()..color = color.withValues(alpha: faded ? 0.25 : (selected ? 0.9 : 0.78))); + Paint()..color = Colors.black.withValues(alpha: faded ? 0.03 : (selected ? 0.35 : 0.18))..maskFilter = const MaskFilter.blur(BlurStyle.normal, 3)); + // Faded ones barely show; highlighted ones are solid + canvas.drawCircle(p, r, Paint()..color = color.withValues(alpha: faded ? 0.18 : (selected ? 1.0 : 0.78))); canvas.drawCircle( p, - r - 1.5, + r - 0.75, Paint() ..style = PaintingStyle.stroke - ..strokeWidth = 3 - ..color = rim.withValues(alpha: faded ? 0.2 : 0.8)); - // Selected: a red border on the hit's own edge, nothing around it + ..strokeWidth = 1.5 + ..color = rim.withValues(alpha: faded ? 0.12 : 0.8)); + // Selected: a thick red border on the hit's own edge, nothing around it if (selected) { canvas.drawCircle( p, @@ -220,10 +254,8 @@ class ScoringRingsPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { - final s = size.shortestSide / TargetScoring.size; canvas.save(); - canvas.translate((size.width - size.shortestSide) / 2, (size.height - size.shortestSide) / 2); - canvas.scale(s); + final s = toFaceSpace(canvas, size); const c = TargetScoring.center; final line = Paint() ..style = PaintingStyle.stroke diff --git a/lib/widgets/ui.dart b/lib/widgets/ui.dart index 861a1ae..b2e3dc4 100644 --- a/lib/widgets/ui.dart +++ b/lib/widgets/ui.dart @@ -176,13 +176,19 @@ class SegmentItem { const SegmentItem(this.label, [this.icon]); } -/// Two or three equal segments in a card ("Statistika | Zgodovina"). +/// Two or three equal segments in a card ("Statistika | Zgodovina"). The +/// selected pill hops over to a newly picked segment (a slide with a slight +/// overshoot). [trailing] sits at the end of the same bar, after a thin line +/// (e.g. a menu); [bare] leaves out the bar's own card, for several rows in +/// one card (see [SegmentedCard]). class SegmentedTabs extends StatelessWidget { final List items; final int selected; final ValueChanged onSelect; final double height; final bool accentSelected; // selected segment filled with the accent + final Widget? trailing; + final bool bare; const SegmentedTabs({ super.key, @@ -191,62 +197,125 @@ class SegmentedTabs extends StatelessWidget { required this.onSelect, this.height = 44, this.accentSelected = false, + this.trailing, + this.bare = false, }); + static const Duration _hop = Duration(milliseconds: 380); + // Slides past its target a little and settles back: a hop, not a fade + static const Curve _hopCurve = Cubic(0.3, 1.3, 0.5, 1); + + static BoxDecoration track(Palette c) => BoxDecoration( + color: c.isDark ? c.card : c.tile, + borderRadius: BorderRadius.circular(14), + border: c.isDark ? Border.all(color: c.line) : null, + ); + + @override + Widget build(BuildContext context) { + final c = Palette.current; + final segments = LayoutBuilder(builder: (context, box) { + final w = box.maxWidth / items.length; + return Stack( + children: [ + // The pill, under the labels + if (selected >= 0 && selected < items.length) + AnimatedPositioned( + duration: _hop, + curve: _hopCurve, + left: w * selected, + top: 0, + bottom: 0, + width: w, + child: AnimatedContainer( + duration: const Duration(milliseconds: 180), + decoration: BoxDecoration( + color: accentSelected ? c.accent : (c.isDark ? c.tile : c.card), + borderRadius: BorderRadius.circular(10), + boxShadow: !c.isDark ? c.shadow : null, + ), + ), + ), + Row( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + for (int i = 0; i < items.length; i++) + Expanded( + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () => onSelect(i), + child: TweenAnimationBuilder( + tween: ColorTween(end: _fg(c, i)), + duration: const Duration(milliseconds: 220), + builder: (context, fg, _) => Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (items[i].icon != null) ...[ + Icon(items[i].icon, size: 16, color: fg), + const SizedBox(width: 8), + ], + Flexible( + child: Text( + items[i].label, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: fg), + ), + ), + ], + ), + ), + ), + ), + ], + ), + ], + ); + }); + final bar = trailing == null + ? segments + : Row( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Expanded(child: segments), + Container(width: 1, margin: const EdgeInsets.symmetric(horizontal: 4, vertical: 6), color: c.isDark ? c.line : c.line2), + trailing!, + ], + ); + return Container( + height: height, + padding: bare ? EdgeInsets.zero : const EdgeInsets.all(4), + decoration: bare ? null : track(c), + child: bar, + ); + } + + Color _fg(Palette c, int i) => i != selected ? c.muted : (accentSelected ? c.onAccent : c.ink); +} + +/// Several [SegmentedTabs] rows (built [bare]) in one card, a thin line +/// between them: "Statistika | Zgodovina" over its filters. +class SegmentedCard extends StatelessWidget { + final List rows; + const SegmentedCard({super.key, required this.rows}); + @override Widget build(BuildContext context) { final c = Palette.current; return Container( - height: height, padding: const EdgeInsets.all(4), - decoration: BoxDecoration( - color: c.isDark ? c.card : c.tile, - borderRadius: BorderRadius.circular(14), - border: c.isDark ? Border.all(color: c.line) : null, - ), - child: Row( - // The selected pill fills the bar's height - crossAxisAlignment: CrossAxisAlignment.stretch, + decoration: SegmentedTabs.track(c), + child: Column( + mainAxisSize: MainAxisSize.min, children: [ - for (int i = 0; i < items.length; i++) - Expanded( - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () => onSelect(i), - child: AnimatedContainer( - duration: const Duration(milliseconds: 180), - curve: Curves.easeOut, - decoration: BoxDecoration( - color: i == selected ? (accentSelected ? c.accent : (c.isDark ? c.tile : c.card)) : Colors.transparent, - borderRadius: BorderRadius.circular(10), - boxShadow: i == selected && !c.isDark ? c.shadow : null, - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - if (items[i].icon != null) ...[ - Icon(items[i].icon, size: 16, color: _fg(c, i)), - const SizedBox(width: 8), - ], - Flexible( - child: Text( - items[i].label, - maxLines: 1, - overflow: TextOverflow.ellipsis, - style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: _fg(c, i)), - ), - ), - ], - ), - ), - ), - ), + for (int i = 0; i < rows.length; i++) ...[ + if (i > 0) Container(height: 1, margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), color: c.isDark ? c.line : c.line2), + rows[i], + ], ], ), ); } - - Color _fg(Palette c, int i) => i != selected ? c.muted : (accentSelected ? c.onAccent : c.ink); } /// Stadium chip: accent when selected ("Treningi", "Vse"). @@ -304,6 +373,7 @@ class AppCard extends StatelessWidget { final double radius; final Color? color; final Color? borderColor; + final double borderWidth; final bool dashed; const AppCard({ @@ -315,6 +385,7 @@ class AppCard extends StatelessWidget { this.radius = AppTheme.radius, this.color, this.borderColor, + this.borderWidth = 1, this.dashed = false, }); @@ -323,7 +394,7 @@ class AppCard extends StatelessWidget { final c = Palette.current; final shape = RoundedRectangleBorder( borderRadius: BorderRadius.circular(radius), - side: dashed ? BorderSide.none : BorderSide(color: borderColor ?? (c.isDark ? c.line2 : c.line2)), + side: dashed ? BorderSide.none : BorderSide(color: borderColor ?? (c.isDark ? c.line2 : c.line2), width: borderWidth), ); Widget content = Padding(padding: padding, child: child); if (onTap != null || onLongPress != null) { @@ -447,7 +518,8 @@ class SoftButton extends StatelessWidget { @override Widget build(BuildContext context) { final c = Palette.current; - final fg = destructive ? c.red : c.ink; + // Without an action it is visibly off, so it never looks like it does nothing + final fg = (destructive ? c.red : c.ink).withValues(alpha: onTap == null ? 0.35 : 1); return Material( color: destructive ? c.redSoft : c.tile, borderRadius: BorderRadius.circular(12), @@ -486,6 +558,7 @@ class ScoreTile extends StatelessWidget { final GestureTapDownCallback? onTapDown; final VoidCallback? onTapEnd; final bool outlined; + final double radius; const ScoreTile({ super.key, @@ -498,6 +571,7 @@ class ScoreTile extends StatelessWidget { this.onTapDown, this.onTapEnd, this.outlined = false, + this.radius = 14, }); @override @@ -515,16 +589,19 @@ class ScoreTile extends StatelessWidget { height: height, decoration: BoxDecoration( color: fill, - borderRadius: BorderRadius.circular(14), + borderRadius: BorderRadius.circular(radius), border: outlined ? Border.all(color: c.ink, width: 2) : null, ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ if (top != null) - Text(top!, - style: TextStyle( - fontSize: 10, fontWeight: FontWeight.w600, color: fg.withValues(alpha: 0.7), fontFeatures: AppTheme.tnum)), + FittedBox( + fit: BoxFit.scaleDown, + child: Text(top!, + style: TextStyle( + fontSize: 10, fontWeight: FontWeight.w600, color: fg.withValues(alpha: 0.7), fontFeatures: AppTheme.tnum)), + ), FittedBox( fit: BoxFit.scaleDown, child: Text(value, @@ -538,6 +615,33 @@ class ScoreTile extends StatelessWidget { } } +/// A centred row of equal tiles. Each is as wide as if there were at least +/// [minSlots], so one or two tiles don't stretch across the whole width. +class TileRow extends StatelessWidget { + final List children; + final double gap; + final int minSlots; + + const TileRow({super.key, required this.children, this.gap = 10, this.minSlots = 6}); + + @override + Widget build(BuildContext context) { + return LayoutBuilder(builder: (context, box) { + final slots = children.length < minSlots ? minSlots : children.length; + final w = (box.maxWidth - gap * (slots - 1)) / slots; + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + for (int i = 0; i < children.length; i++) ...[ + if (i > 0) SizedBox(width: gap), + SizedBox(width: w, child: children[i]), + ], + ], + ); + }); + } +} + /// Small coloured label: "TRENING", "TEKMOVANJE", "V ŽIVO". class StatusChip extends StatelessWidget { final String label; diff --git a/pubspec.yaml b/pubspec.yaml index d8ef6cd..0cdf5e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -45,7 +45,7 @@ flutter: assets: - assets/club.enc - assets/best_float32_nms.tflite - - assets/targets/v3/ + - assets/targets/v5/ - assets/backgrounds/ # Inter for the interface, JetBrains Mono for camera addresses (both SIL OFL 1.1) diff --git a/test/league_service_test.dart b/test/league_service_test.dart new file mode 100644 index 0000000..4ab7d56 --- /dev/null +++ b/test/league_service_test.dart @@ -0,0 +1,31 @@ +import 'dart:convert'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:sd_kovinar/services/league_service.dart'; + +// Shape of liga.bl3kunja.top/api/lestvica (trimmed, names made up) +const _json = ''' +{"league":{"counted":4,"id":1,"name":"Liga 2026-2027","shots":2,"status":"active","targets":20}, + "players":[ + {"cells":[{"counted":true,"joker":false,"score":340,"tens":5},null,null,null,null],"club":"SD Kovinar Muta","final":340,"name":"B","played":1,"rank":2,"tens":5,"total":340}, + {"cells":[{"counted":true,"joker":false,"score":364,"tens":13},null,null,null,null],"club":"SD Kamnik","final":364,"name":"A","played":1,"rank":1,"tens":13,"total":364}], + "rounds":[ + {"ends_at":"2026-12-31T23:59","number":2,"starts_at":"2026-12-01T00:00","state":"upcoming","submissions":0}, + {"ends_at":"2026-11-30T23:59","number":1,"starts_at":"2026-11-01T00:00","state":"open","submissions":4}]} +'''; + +void main() { + test('the league API is read: league, rounds in order, players by rank', () { + final d = LeagueStandings.fromJson(jsonDecode(_json) as Map); + expect(d.league.name, 'Liga 2026-2027'); + expect(d.league.counted, 4); + expect([for (final r in d.rounds) r.number], [1, 2]); + expect(d.openRound?.number, 1); + expect(d.openRound?.endsAt, DateTime(2026, 11, 30, 23, 59)); + expect(d.nextRound?.number, 2); + expect([for (final p in d.players) p.name], ['A', 'B']); + expect(d.players.first.cells.first?.score, 364); + expect(d.players.first.cells[1], isNull); // not shot yet + expect(d.players.first.finalScore, 364); + }); +} diff --git a/test/target_face_zoom_test.dart b/test/target_face_zoom_test.dart new file mode 100644 index 0000000..b171f00 --- /dev/null +++ b/test/target_face_zoom_test.dart @@ -0,0 +1,28 @@ +import 'dart:math'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:sd_kovinar/utils/target_scoring.dart'; +import 'package:sd_kovinar/widgets/target_face.dart'; + +void main() { + test('previews zoom in on the shots, keeping every one and ring 6 in view', () { + expect(TargetFace.zoomFor(const []), 1); // nothing to zoom on + + // All in the black: as far in as ring 6 allows + final tight = [for (final a in [0.0, 2.0, 4.0]) TargetScoring.positionFor(9, a)]; + final z = TargetFace.zoomFor(tight); + expect(z, greaterThan(2)); + expect(TargetScoring.size / 2 / z, greaterThanOrEqualTo(236.5)); // ring 6's outer edge still shows + + // Every shot stays inside the zoomed view + final spread = [for (int s = 4; s <= 10; s++) TargetScoring.positionFor(s, s.toDouble())]; + final zs = TargetFace.zoomFor(spread); + for (final h in spread) { + final d = (h - TargetScoring.center).distance + TargetScoring.bulletDiameter / 2; + expect(d, lessThanOrEqualTo(TargetScoring.size / 2 / zs)); + } + + // A miss in a corner: no zoom + expect(TargetFace.zoomFor([TargetScoring.positionFor(0, pi / 4)]), 1); + }); +} diff --git a/test/target_scoring_test.dart b/test/target_scoring_test.dart index 28cbfc6..100221e 100644 --- a/test/target_scoring_test.dart +++ b/test/target_scoring_test.dart @@ -41,12 +41,29 @@ void main() { expect(TargetScoring.scoreAt(c + const Offset(510 + 1.5 + 25 + 0.5, 0)), 0); }); - test('hand-entered shots stay on the 1200x1200 target', () { - for (int deg = 0; deg < 360; deg += 15) { + // The dot is wholly inside the target's 1200 square + bool onSquare(Offset p) { + const r = TargetScoring.bulletDiameter / 2; + return p.dx >= r && p.dy >= r && p.dx <= TargetScoring.size - r && p.dy <= TargetScoring.size - r; + } + + test('a hand-entered 0 lands towards a corner, clear of ring 1', () { + for (int deg = 0; deg < 360; deg += 5) { final p = TargetScoring.positionFor(0, deg * pi / 180); - expect(p.dx, inInclusiveRange(0, 1200)); - expect(p.dy, inInclusiveRange(0, 1200)); + expect(onSquare(p), isTrue, reason: '$deg°: $p'); + // Past ring 1's decoration (r 510–590), not just past the ring + expect((p - TargetScoring.center).distance - TargetScoring.bulletDiameter / 2, greaterThan(590), reason: '$deg°: $p'); } }); + + test('a shot far off is kept in the square and still scores 0', () { + for (final far in [const Offset(0, 0), const Offset(1200, 1200), const Offset(-500, 600), const Offset(600, 2000), const Offset(1190, 20)]) { + final p = TargetScoring.shown(far); + expect(onSquare(p), isTrue, reason: '$far -> $p'); + expect(TargetScoring.scoreAt(p), 0); + } + const inside = Offset(700, 650); + expect(TargetScoring.shown(inside), inside); // inside: unchanged + }); }); } diff --git a/test/target_style_test.dart b/test/target_style_test.dart index f82d31f..139bd23 100644 --- a/test/target_style_test.dart +++ b/test/target_style_test.dart @@ -15,8 +15,14 @@ void main() { expect(File(asset!).existsSync(), isTrue, reason: '$asset missing'); } } + // Every design (picker and holidays) has its screen background, dark and light + for (final style in [...TargetStyle.all, ...TargetStyle.holidays]) { + for (final dark in [true, false]) { + expect(File(style.background(dark)).existsSync(), isTrue, reason: '${style.background(dark)} missing'); + } + } expect(TargetStyle.byId(13), TargetStyle.fallback); // removed skin falls back to the default - expect(TargetStyle.all.length, 6); // the default and five designs + expect(TargetStyle.all.length, 9); // the default and eight designs (a 3 × 3 picker) expect(TargetStyle.byId(24), TargetStyle.fallback); // a design no longer shipped falls back too }); }