Add shareware HUD module and integrate with asset registry for improved HUD handling
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -151,36 +151,49 @@ abstract class RendererBackend<T>
|
||||
/// backend can scale/map them consistently via [blitHudVgaImage].
|
||||
void drawStandardVgaHud(WolfEngine engine) {
|
||||
final List<VgaImage> vgaImages = engine.data.vgaImages;
|
||||
final int statusBarIndex = vgaImages.indexWhere(
|
||||
(img) => img.width == 320 && img.height == 40,
|
||||
);
|
||||
if (statusBarIndex == -1) return;
|
||||
final statusBarRef = engine.data.registry.hud.resolve(HudKey.statusBar);
|
||||
final int statusBarIndex = statusBarRef?.vgaIndex ?? -1;
|
||||
if (statusBarIndex >= 0 && statusBarIndex < vgaImages.length) {
|
||||
blitHudVgaImage(vgaImages[statusBarIndex], 0, 160);
|
||||
}
|
||||
|
||||
blitHudVgaImage(vgaImages[statusBarIndex], 0, 160);
|
||||
_drawHudNumber(vgaImages, 1, 32, 176);
|
||||
_drawHudNumber(vgaImages, engine.player.score, 96, 176);
|
||||
_drawHudNumber(vgaImages, 3, 120, 176);
|
||||
_drawHudNumber(vgaImages, engine.player.health, 192, 176);
|
||||
_drawHudNumber(vgaImages, engine.player.ammo, 232, 176);
|
||||
_drawHudNumber(engine, vgaImages, 1, 32, 176);
|
||||
_drawHudNumber(engine, vgaImages, engine.player.score, 96, 176);
|
||||
_drawHudNumber(engine, vgaImages, 3, 120, 176);
|
||||
_drawHudNumber(engine, vgaImages, engine.player.health, 192, 176);
|
||||
_drawHudNumber(engine, vgaImages, engine.player.ammo, 232, 176);
|
||||
_drawHudFace(engine, vgaImages);
|
||||
_drawHudWeaponIcon(engine, vgaImages);
|
||||
}
|
||||
|
||||
void _drawHudNumber(
|
||||
WolfEngine engine,
|
||||
List<VgaImage> vgaImages,
|
||||
int value,
|
||||
int rightAlignX,
|
||||
int startY,
|
||||
) {
|
||||
// HUD numbers are rendered with fixed-width VGA glyphs (8 px advance).
|
||||
const int zeroIndex = 96;
|
||||
const digitKeys = [
|
||||
HudKey.digit0,
|
||||
HudKey.digit1,
|
||||
HudKey.digit2,
|
||||
HudKey.digit3,
|
||||
HudKey.digit4,
|
||||
HudKey.digit5,
|
||||
HudKey.digit6,
|
||||
HudKey.digit7,
|
||||
HudKey.digit8,
|
||||
HudKey.digit9,
|
||||
];
|
||||
|
||||
final String numStr = value.toString();
|
||||
int currentX = rightAlignX - (numStr.length * 8);
|
||||
|
||||
for (int i = 0; i < numStr.length; i++) {
|
||||
final int digit = int.parse(numStr[i]);
|
||||
final int imageIndex = zeroIndex + digit;
|
||||
if (imageIndex < vgaImages.length) {
|
||||
final ref = engine.data.registry.hud.resolve(digitKeys[digit]);
|
||||
final imageIndex = ref?.vgaIndex ?? -1;
|
||||
if (imageIndex >= 0 && imageIndex < vgaImages.length) {
|
||||
blitHudVgaImage(vgaImages[imageIndex], currentX, startY);
|
||||
}
|
||||
currentX += 8;
|
||||
@@ -188,15 +201,24 @@ abstract class RendererBackend<T>
|
||||
}
|
||||
|
||||
void _drawHudFace(WolfEngine engine, List<VgaImage> vgaImages) {
|
||||
final int faceIndex = hudFaceVgaIndex(engine.player.health);
|
||||
if (faceIndex < vgaImages.length) {
|
||||
final faceRef = engine.data.registry.hud.faceForHealth(
|
||||
engine.player.health,
|
||||
);
|
||||
final int faceIndex = faceRef?.vgaIndex ?? -1;
|
||||
if (faceIndex >= 0 && faceIndex < vgaImages.length) {
|
||||
blitHudVgaImage(vgaImages[faceIndex], 136, 164);
|
||||
}
|
||||
}
|
||||
|
||||
void _drawHudWeaponIcon(WolfEngine engine, List<VgaImage> vgaImages) {
|
||||
final int weaponIndex = hudWeaponVgaIndex(engine);
|
||||
if (weaponIndex < vgaImages.length) {
|
||||
final HudKey weaponKey = engine.player.hasChainGun
|
||||
? HudKey.chainGunIcon
|
||||
: engine.player.hasMachineGun
|
||||
? HudKey.machineGunIcon
|
||||
: HudKey.pistolIcon;
|
||||
final weaponRef = engine.data.registry.hud.resolve(weaponKey);
|
||||
final int weaponIndex = weaponRef?.vgaIndex ?? -1;
|
||||
if (weaponIndex >= 0 && weaponIndex < vgaImages.length) {
|
||||
blitHudVgaImage(vgaImages[weaponIndex], 256, 164);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user