93 lines
2.7 KiB
Dart
93 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:wolf_3d_dart/wolf_3d_data_types.dart';
|
|
import 'package:wolf_3d_dart/wolf_3d_entities.dart';
|
|
import 'package:wolf_3d_flutter/wolf_3d.dart';
|
|
|
|
class SpriteGallery extends StatelessWidget {
|
|
final List<Sprite> sprites;
|
|
|
|
const SpriteGallery({super.key, required this.sprites});
|
|
|
|
bool get isShareware => Wolf3d.I.activeGame.version == GameVersion.shareware;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text("Sprite Gallery"),
|
|
automaticallyImplyLeading: true,
|
|
),
|
|
backgroundColor: Colors.black,
|
|
body: GridView.builder(
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 8,
|
|
),
|
|
itemCount: sprites.length,
|
|
itemBuilder: (context, index) {
|
|
// --- Check which enemy owns this sprite ---
|
|
String label = "Sprite Index: $index";
|
|
for (final enemy in EnemyType.values) {
|
|
if (enemy.claimsSpriteIndex(index, isShareware: isShareware)) {
|
|
final EnemyAnimation? animation = enemy.getAnimationFromSprite(
|
|
index,
|
|
isShareware: isShareware,
|
|
);
|
|
|
|
// Appends the enum name (e.g., "guard", "dog")
|
|
label += "\n${enemy.name}";
|
|
|
|
// Appends the animation name
|
|
if (animation != null) {
|
|
label += "\n${animation.name}";
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
return Column(
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: const TextStyle(color: Colors.white, fontSize: 10),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
Expanded(
|
|
child: CustomPaint(
|
|
painter: SingleSpritePainter(sprite: sprites[index]),
|
|
size: const Size(64, 64),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class SingleSpritePainter extends CustomPainter {
|
|
final Sprite sprite;
|
|
SingleSpritePainter({required this.sprite});
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
double pixelSize = size.width / 64;
|
|
for (int x = 0; x < 64; x++) {
|
|
for (int y = 0; y < 64; y++) {
|
|
int colorByte = sprite.pixels[x * 64 + y];
|
|
if (colorByte != 255) {
|
|
// Skip transparency
|
|
canvas.drawRect(
|
|
Rect.fromLTWH(x * pixelSize, y * pixelSize, pixelSize, pixelSize),
|
|
Paint()..color = Color(ColorPalette.vga32Bit[colorByte]),
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(CustomPainter oldDelegate) => false;
|
|
}
|