UI fixes and league

This commit is contained in:
Jan Pleterski
2026-11-28 12:22:02 +01:00
parent 2fc741a9f6
commit 258303deb8
118 changed files with 1439 additions and 537 deletions
+79 -47
View File
@@ -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<Offset> hits; // in target space (0–1200)
@@ -14,6 +17,7 @@ class TargetFace extends StatelessWidget {
final Set<int> highlighted; // indexes of [hits] drawn with a ring
final Set<int> 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<Offset> 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