You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdLike2048/assets/script/ui/mingjiangIntroduction/UImingjiangIntroduction.ts

179 lines
6.5 KiB

3 weeks ago
//*********************
// create by 流云
// time: Fri Aug 14 2026
// desc:
//*********************
import { _decorator, Color, Node, sp, Sprite } from 'cc';
import { Auto_mingjiangIntroduction } from './Auto_mingjiangIntroduction';
import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad';
import { ensureSpineSkeletonDataRuntime } from 'db://assets/mx/module/lang/spineRuntimePatch';
import { applyWeaponSpineSkin } from '../../battle/view/GlyphSpineSkin';
import { SpineBatch } from 'db://assets/resources/multSpines/MultSpine';
import type { MingjiangkuBagKind } from '../../manager/EquipDataManager';
import { GBundle } from '../../game/ConfigRes';
const { ccclass } = _decorator;
const LOG = '[mingjiangIntroduction]';
const SPINE_DIM = new Color(0x99, 0x99, 0x99, 255);
const SPINE_NORMAL = new Color(255, 255, 255, 255);
const WEAPON_SPINE_ANIM = '待机';
const SPINE_GRAY_SHADER = 1.999;
type SkelShader = sp.Skeleton & { shaderVar?: number };
/** 武器介绍弹窗入参 */
interface IMingjiangIntroParam {
/** 武器 id */
equipId: number;
/** 来源:成品 / 碎片(碎片 Spine 置灰) */
kind?: MingjiangkuBagKind;
}
/**
* 武器介绍弹窗(Weapon 表)
* ui_quality:icons/weapon/武器信息图标底框0~4
* ui_name:icons/weapon/{icon}
* ui_type1~4:按 type 显隐,skin 换肤
* lb_weaponattack:攻击力 atk
* lb_desc:描述 desc
*/
@ccclass('UImingjiangIntroduction')
export class UImingjiangIntroduction extends Auto_mingjiangIntroduction {
onInit(): void {
const param = this._resolveParam();
this._fillEquip(param.equipId, param.kind);
}
click_btn_close(): void {
this.close(2);
}
/** 点击遮罩关闭 */
click_bgMask(): void {
this.close(2);
}
/** 解析打开参数(兼容仅传 equipId 数字) */
private _resolveParam(): { equipId: number; kind: MingjiangkuBagKind } {
const raw = this.prema;
if (raw !== null && typeof raw === 'object') {
const p = raw as IMingjiangIntroParam;
return {
equipId: Number(p.equipId) || 0,
kind: p.kind === 'fragment' ? 'fragment' : 'equip',
};
}
return { equipId: Number(raw) || 0, kind: 'equip' };
}
/** 按武器 id 刷新展示 */
private _fillEquip(equipId: number, kind: MingjiangkuBagKind): void {
const eq = gg.equip.getEquip(equipId);
if (!eq) {
console.warn(LOG, '武器表缺失', equipId);
this._refreshExclusiveName(0);
return;
}
const bgIndex = this._qualityBgIndex(Number(eq.quality), equipId);
this._setWeaponSprite(this.ui_quality, `weapon/武器信息图标底框${bgIndex}`);
const icon = String(eq.icon ?? '').trim();
const skin = String(eq.skin ?? '').trim();
const weaponType = Number(eq.type) | 0;
if (!icon) console.log(LOG, 'icon 缺失', equipId);
if (!skin) console.log(LOG, 'skin 缺失', equipId);
if (weaponType < 1 || weaponType > 4) console.log(LOG, 'type 无效', equipId, weaponType);
this._setWeaponSprite(this.ui_name, icon ? `weapon/${icon}` : '');
this._applyWeaponSpineGroup(weaponType, skin, kind === 'fragment');
if (this.lb_weaponattack) this.lb_weaponattack.string = String(eq.atk ?? 0);
if (this.lb_desc) this.lb_desc.string = gg.lang.get(eq.desc);
this._refreshExclusiveName(equipId);
}
/** 专属名(Hero.personalweapon 已删:恒隐藏) */
3 weeks ago
private _refreshExclusiveName(equipId: number): void {
const lb = this.lb_exclusiveName;
if (!lb?.node?.isValid) {
if (equipId > 0) console.warn(LOG, 'lb_exclusiveName 缺失');
return;
}
lb.node.active = false;
if (this.ui_exclusive) this.ui_exclusive.active = false;
3 weeks ago
}
/** 按武器类型显隐 ui_type1~4,并设置 Spine 皮肤 */
private _applyWeaponSpineGroup(weaponType: number, skin: string, dimmed: boolean): void {
const typeNodes = [this.ui_type1, this.ui_type2, this.ui_type3, this.ui_type4];
let matched = false;
for (let t = 1; t <= 4; t++) {
const typeNode = typeNodes[t - 1];
if (!typeNode) continue;
const show = t === weaponType;
typeNode.active = show;
if (!show) continue;
matched = true;
this._applyWeaponSpine(typeNode, skin, dimmed);
}
if (!matched && weaponType >= 1 && weaponType <= 4) {
console.log(LOG, 'ui_type 节点缺失', weaponType);
}
}
/** 设置单个武器 Spine 皮肤与待机 */
private _applyWeaponSpine(typeNode: Node, skin: string, dimmed: boolean): void {
const skel = typeNode.getComponent(sp.Skeleton) ?? typeNode.getComponentInChildren(sp.Skeleton);
if (!skel) {
console.log(LOG, 'Spine 缺失', typeNode.name);
return;
}
if (skel.skeletonData) ensureSpineSkeletonDataRuntime(skel.skeletonData);
if (skin) {
applyWeaponSpineSkin(skel, skin, LOG);
}
try {
skel.setAnimation(0, WEAPON_SPINE_ANIM, true);
} catch (e) {
console.log(LOG, 'setAnimation 失败', WEAPON_SPINE_ANIM, String(e));
}
this._setSpineDimmed(skel, dimmed);
}
/** Spine 置灰:MultSpine 合批走 shaderVar,否则 skel.color */
private _setSpineDimmed(skel: sp.Skeleton, dimmed: boolean): void {
const s = skel as SkelShader;
if (SpineBatch.active() && typeof s.shaderVar === 'number') {
s.shaderVar = dimmed ? SPINE_GRAY_SHADER : 0;
skel.color = SPINE_NORMAL;
return;
}
s.shaderVar = 0;
skel.color = dimmed ? SPINE_DIM : SPINE_NORMAL;
}
/** 品质 → 武器信息图标底框 0~4(白/绿/蓝/紫/橙) */
private _qualityBgIndex(quality: number, equipId: number): number {
const q = Number(quality) | 0;
if (q < 0 || q > 4) {
console.log(LOG, '品质无效', equipId, q);
}
return q;
}
/** icons/weapon 下图 */
private _setWeaponSprite(node: Node | null, path: string): void {
if (!node?.isValid) return;
if (!path) {
node.active = false;
return;
}
node.active = true;
if (!node.getComponent(Sprite)) node.addComponent(Sprite);
node.getOrAddComponent(SpriteLoad).setSprite(path, GBundle.Items);
}
}