0.2.6-dev: port PR #552 by IceCodeNew — an optional 「弹药数量」 setting (default off: the official HUD has no such number, the maintainer's decision of 2026-10-13) shows an ammo skill's rounds left / magazine under its bar, from the exact b.snap ammo counts; sanitised with the other settings, applied by the field view live, all four language packs, the diagnostics line; the simplified board has no ammo bar; DESIGN §31.9; golden: unchanged

This commit is contained in:
sganggs committed 2026-10-13 04:43:39 +08:00
1 parent 231da0efbc
commit 461a7747e1
16 files changed
+244 -17

No files matched your search

+31 -4
View File
@@ -2,7 +2,8 @@
//
// UnitView = shadow sprite (shadow layer) + body container (depth-sorted unit layer: elite aura, Spine actor or
// the avatar-in-rarity-diamond fallback) + HUD container (bar layer: HP bar with delayed "ghost" damage, SP bar
// with ready glow / draining skill bar, tier chip, status icons, blocked marker). The fallback shows at once and
// with ready glow / draining skill bar — an ammo skill's segmented magazine, with its count under it when 设置「弹药数量」
// is on (PR #552) —, tier chip, status icons, blocked marker). The fallback shows at once and
// cross-fades to the Spine model when it has loaded (the game never blocks on Spine); an optional local-client model
// (assets.js spineEntry `fallback`, DESIGN §13: 灼热源石虫 / 炽焰源石虫) falls back to the web model first; that web alias
// (the plain 源石虫) is drawn tinted toward the slug's own colours (ALIAS_TINT). A model that failed or timed out is
@@ -462,7 +463,7 @@ function bar(P, parent, color, alpha = 1) {
* Shared context handed to every view by app.js (`audio`: the audio manager of public/js/audio.js — prep landings, land()).
* @typedef {{ P: any, layers: { shadow: any, units: any, bars: any, groundFx: any },
* assets: any, audio?: any, cam: () => any, heightAt: (r:number,c:number)=>number, fx: any, time: () => number,
* settings: { damageNumbers: boolean, quality: string } }} ViewCtx
* settings: { damageNumbers: boolean, quality: string, ammoCount?: boolean } }} ViewCtx
*/
export class UnitView {
@@ -805,6 +806,7 @@ export class UnitView {
this.blockIcon.visible = false;
this.ctx.layers.groundFx.addChild(this.blockIcon);
this.countText = null;
this.ammoText = null; // 设置「弹药数量」: the magazine's count under the ammo bar (_updateAmmoCount)
this.itemPips = [];
}
@@ -1496,8 +1498,10 @@ export class UnitView {
ic.position.set(x - ((icons.length - 1) * (isz + 2)) / 2 + i * (isz + 2), iy);
}
// 狼影 pips under the bars (b.snap `wolves`), then the element gauge row under them (b.snap `elem`); redeploy ring above a
// knocked-down operator (b.snap `down`)
const rowsTop = cy + bh / 2 + (showSp ? spH + 1.5 : 0);
// knocked-down operator (b.snap `down`). 设置「弹药数量」 (off by default) first puts the magazine's count right under
// the ammo bar, and the rows below move down by its height
let rowsTop = cy + bh / 2 + (showSp ? spH + 1.5 : 0);
rowsTop += this._updateAmmoCount(showSp && !!ammo && this.ctx.settings?.ammoCount === true, x0 + bw / 2, rowsTop, s);
const wolfH = this._updateWolfPips(showBars && !this.isEnemy && !!this.wolves, x0, rowsTop, s);
const coinH = this._updateCoins(showBars && !this.isEnemy && !!this.coins, x0, rowsTop + wolfH, s);
this._updateElementBar(showBars && !!this.el, x0, bw, rowsTop + wolfH + coinH + 1, spH, s, t);
@@ -1525,6 +1529,29 @@ export class UnitView {
}
}
/**
* 设置「弹药数量」 (PR #552 by @IceCodeNew; off by default — the official HUD has no such number, the maintainer's decision
* of 2026-10-13): the rounds left / the rounds in the magazine (b.snap `ammo`: the exact counts, 拉特兰's extra rounds
* and refills included) centred at `x` under the ammo bar, its top at `top`, in the bar's yellow — readable even where the
* cells are too narrow for their cuts. Built on first use, hidden otherwise (the skill over, the prep view, a death, an
* older snapshot without the row). Returns the height it takes (0 while hidden) so the rows under the bars move down.
*/
_updateAmmoCount(show, x, top, s) {
let text = this.ammoText;
if (!show) { if (text) text.visible = false; return 0; }
if (!text) {
text = this.ammoText = new this.P.Text('', { fontFamily: 'Bender, Oxanium, sans-serif', fontSize: 16, fontWeight: '700', fill: COLORS.ammo, stroke: '#0b0f0e', strokeThickness: 3 });
text.anchor.set(0.5, 0);
this.hud.addChild(text);
}
const label = `${this.ammo[0]}/${this.ammo[1]}`;
if (text.text !== label) text.text = label;
text.scale.set(clamp(s * 0.2, 10, 16) / 16);
text.position.set(x, top + 3);
text.visible = true;
return text.height + 6;
}
/**
* The thin dark separators between the ammo bar's cells (see _updateHud): one at every round boundary of the `n`-round
* magazine across the bar `x0` … `x0 + bw` at height `y`, `h` tall; none while a cell would be under AMMO_BAR.minCell px