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.
95 lines
2.6 KiB
95 lines
2.6 KiB
|
|
//*********************
|
|
// create by 流云
|
|
// time: Wed Oct 07 2026
|
|
// desc: 一键合成获得宝石弹窗
|
|
//*********************
|
|
import { _decorator, instantiate, Node } from 'cc';
|
|
import { GemGrid } from '../../com/GemGrid';
|
|
import { IGemFuseGain } from '../../game/GameDataEnums';
|
|
import { Auto_PopGetGem } from './Auto_PopGetGem';
|
|
const { ccclass } = _decorator;
|
|
|
|
const LOG = '[PopGetGem]';
|
|
|
|
/**
|
|
* 获得新宝石:展示一键合成净增列表。
|
|
*/
|
|
@ccclass('UIPopGetGem')
|
|
export class UIPopGetGem extends Auto_PopGetGem {
|
|
|
|
/** 格子模板 */
|
|
private _tpl: Node | null = null;
|
|
/** 动态格子 */
|
|
private _items: Node[] = [];
|
|
|
|
onLoad(): void {
|
|
super.onLoad();
|
|
this._tpl = this.ui_content?.getChildByName('bagItemTemplate') ?? null;
|
|
if (this._tpl) this._tpl.active = false;
|
|
}
|
|
|
|
onEnable(): void {
|
|
super.onEnable();
|
|
}
|
|
|
|
onDisable(): void {
|
|
this._clearItems();
|
|
super.onDisable();
|
|
}
|
|
|
|
onInit(): void {
|
|
this._render(this._resolveGains());
|
|
}
|
|
|
|
click_bgMask(): void {
|
|
void this.close(2);
|
|
}
|
|
|
|
click_btnClose(): void {
|
|
void this.close(2);
|
|
}
|
|
|
|
/** 解析打开参数 */
|
|
private _resolveGains(): IGemFuseGain[] {
|
|
const raw = this.prema;
|
|
if (!Array.isArray(raw)) return [];
|
|
const out: IGemFuseGain[] = [];
|
|
for (let i = 0; i < raw.length; i++) {
|
|
const row = raw[i];
|
|
const gemId = Math.floor(Number(row?.gemId) || 0);
|
|
const count = Math.floor(Number(row?.count) || 0);
|
|
if (gemId > 0 && count > 0) out.push({ gemId, count });
|
|
}
|
|
return out;
|
|
}
|
|
|
|
/** 填充列表 */
|
|
private _render(gains: IGemFuseGain[]): void {
|
|
if (!this.ui_content?.isValid || !this._tpl?.isValid) {
|
|
console.warn(LOG, 'ui_content/bagItemTemplate 缺失');
|
|
return;
|
|
}
|
|
this._clearItems();
|
|
for (let i = 0; i < gains.length; i++) {
|
|
const g = gains[i];
|
|
const node = instantiate(this._tpl);
|
|
node.parent = this.ui_content;
|
|
node.active = true;
|
|
const grid = node.getComponent(GemGrid) || node.addComponent(GemGrid);
|
|
const conf = gg.gem.getGem(g.gemId);
|
|
if (!conf) console.warn(LOG, '宝石配表缺失', g.gemId);
|
|
grid.setData(conf, g.count);
|
|
this._items.push(node);
|
|
}
|
|
}
|
|
|
|
/** 清理动态格 */
|
|
private _clearItems(): void {
|
|
for (let i = 0; i < this._items.length; i++) {
|
|
const n = this._items[i];
|
|
if (n?.isValid) n.destroy();
|
|
}
|
|
this._items.length = 0;
|
|
}
|
|
}
|
|
|