//********************* // create by 流云 // time: Thu Oct 08 2026 // desc: 宝石信息弹窗 //********************* import { _decorator, find, Node, Sprite } from 'cc'; import { SpriteLoad } from 'db://assets/mx/components/SpriteLoad'; import { GBundle } from '../../game/ConfigRes'; import { Auto_PopGemInfo } from './Auto_PopGemInfo'; const { ccclass } = _decorator; const LOG = '[PopGemInfo]'; /** * 宝石信息:iconbg=武器信息图标底框{quality};icon=Weapon.icon; * lb_name / lb_desc 多语言;lb_lv=Lv.{quality}。 */ @ccclass('UIPopGemInfo') export class UIPopGemInfo extends Auto_PopGemInfo { /** 品质底框 */ private _iconbg: Node | null = null; /** 宝石图标 */ private _icon: Node | null = null; onLoad(): void { super.onLoad(); this._iconbg = find('center/iconbg', this.node); this._icon = find('center/icon', this.node); if (!this._iconbg) console.warn(LOG, 'iconbg 缺失'); if (!this._icon) console.warn(LOG, 'icon 缺失'); } onInit(): void { this._fill(this._resolveGemId()); } click_bgMask(): void { void this.close(2); } click_btnClose(): void { void this.close(2); } /** 解析打开参数:数字 gemId 或 { gemId } */ private _resolveGemId(): number { const raw = this.prema; if (raw !== null && typeof raw === 'object') { return Math.floor(Number((raw as { gemId?: number }).gemId) || 0); } return Math.floor(Number(raw) || 0); } /** 按宝石 id 刷新 */ private _fill(gemId: number): void { const conf = gemId > 0 ? gg.gem.getGem(gemId) : null; if (!conf) { console.warn(LOG, '宝石配表缺失', gemId); return; } const quality = Math.floor(Number(conf.quality) || 0); if (quality < 1 || quality > 5) console.warn(LOG, '品质无对应底框', gemId, quality); this._setWeaponSprite(this._iconbg, `weapon/武器信息图标底框${quality}`); const iconName = String(conf.icon || '').trim(); if (!iconName) console.warn(LOG, 'icon 缺失', gemId); this._setWeaponSprite(this._icon, iconName ? `weapon/${iconName}` : ''); if (this.lb_name) this.lb_name.string = gg.lang.get(conf.name); if (this.lb_lv) this.lb_lv.string = `Lv.${quality}`; if (this.lb_desc) this.lb_desc.string = gg.lang.get(conf.desc); } /** icons/weapon 下图 */ private _setWeaponSprite(node: Node | null, path: string): void { if (!node?.isValid) return; if (!path) { node.active = false; node.getComponent(SpriteLoad)?.clear(); const sp = node.getComponent(Sprite); if (sp) sp.spriteFrame = null; return; } node.active = true; if (!node.getComponent(Sprite)) node.addComponent(Sprite); node.getOrAddComponent(SpriteLoad).setSprite(path, GBundle.Items); } }