Files
BlockSeasons/lib/ui/widgets/piece_painter.dart
T
airkjw 8739fc0e26 feat: glossy tile rendering and per-season theme colors
Introduces candy-gloss tile rendering (diagonal gradient + glass highlight
+ optional glow) via a shared paintGlossyTile() in tile_painter.dart,
applied to board filled-cells and tray/drag-overlay pieces. Adds
ThemeColors to palette.dart for UI-layer season color resolution, and
activeThemeProvider for one-call access to the active season's theme.
Regenerates the game_screen golden to reflect the new look.
2026-06-11 21:06:26 +09:00

78 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import '../../game/models/piece.dart';
import '../theme/palette.dart';
import 'tile_painter.dart';
/// Draws a piece as rounded tiles at a given cell size; reused by the tray,
/// the drag overlay, and ghost previews.
void paintPiece(
Canvas canvas,
Piece piece, {
required double cellSize,
Offset origin = Offset.zero,
Color? overrideColor,
}) {
final inset = cellSize * 0.05;
final radius = Radius.circular(cellSize * 0.18);
for (final (dx, dy) in piece.offsets) {
final rect = Rect.fromLTWH(
origin.dx + dx * cellSize + inset,
origin.dy + dy * cellSize + inset,
cellSize - inset * 2,
cellSize - inset * 2,
);
if (overrideColor != null) {
canvas.drawRRect(
RRect.fromRectAndRadius(rect, radius),
Paint()..color = overrideColor,
);
} else {
paintGlossyTile(canvas, rect, GamePalette.tile(piece.colorId));
}
}
}
/// Bounding size of a piece in cells.
(int, int) pieceCellBounds(Piece piece) {
var w = 0;
var h = 0;
for (final (dx, dy) in piece.offsets) {
if (dx + 1 > w) w = dx + 1;
if (dy + 1 > h) h = dy + 1;
}
return (w, h);
}
class PieceWidget extends StatelessWidget {
const PieceWidget({super.key, required this.piece, required this.cellSize});
final Piece piece;
final double cellSize;
@override
Widget build(BuildContext context) {
final (w, h) = pieceCellBounds(piece);
return CustomPaint(
size: Size(w * cellSize, h * cellSize),
painter: _PiecePainter(piece, cellSize),
);
}
}
class _PiecePainter extends CustomPainter {
const _PiecePainter(this.piece, this.cellSize);
final Piece piece;
final double cellSize;
@override
void paint(Canvas canvas, Size size) {
paintPiece(canvas, piece, cellSize: cellSize);
}
@override
bool shouldRepaint(_PiecePainter old) =>
old.piece != piece || old.cellSize != cellSize;
}