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.
193 lines
6.2 KiB
193 lines
6.2 KiB
|
3 weeks ago
|
|
||
|
|
//*********************
|
||
|
|
// create by 流云
|
||
|
|
// time: Sat Feb 15 2025
|
||
|
|
// desc:
|
||
|
|
//*********************
|
||
|
|
import { _decorator, Component, Node, find, Layout, instantiate, UITransform } from 'cc';
|
||
|
|
import { RewardGrid } from './RewardGrid';
|
||
|
|
|
||
|
|
import { ItemNumType } from '../../game/GameData';
|
||
|
|
import { ItemData } from '../../game/ConfigProjectData';
|
||
|
|
import { Auto_GetReward } from './Auto_GetReward';
|
||
|
|
import { GEvent } from 'db://assets/mx/module/event/GEvent';
|
||
|
|
import MTools from 'db://assets/mx/tools/MTools';
|
||
|
|
const { ccclass, property } = _decorator;
|
||
|
|
|
||
|
|
@ccclass('UIGetReward')
|
||
|
|
export class UIGetReward extends Auto_GetReward {
|
||
|
|
|
||
|
|
curChooseContent = null
|
||
|
|
isadd = false
|
||
|
|
onLoad(): void {
|
||
|
|
super.onLoad();
|
||
|
|
}
|
||
|
|
|
||
|
|
onEnable(): void {
|
||
|
|
super.onEnable();
|
||
|
|
}
|
||
|
|
|
||
|
|
onDisable(): void {
|
||
|
|
super.onDisable();
|
||
|
|
|
||
|
|
GEvent.Ins.emit(GEvent.UpdateGetItem);
|
||
|
|
}
|
||
|
|
|
||
|
|
onInit() {
|
||
|
|
this.isadd = false
|
||
|
|
this.dataList = this._expandType4RewardList(this.prema ?? []);
|
||
|
|
this.dataList.sort((a, b) => {
|
||
|
|
const qa = a.isEquip
|
||
|
|
? (Number(gg.equip.getEquip(a.id)?.quality) || 0)
|
||
|
|
: (a.staticData?.quality ?? gg.data.table.getItemData(a.id)?.quality ?? 0);
|
||
|
|
const qb = b.isEquip
|
||
|
|
? (Number(gg.equip.getEquip(b.id)?.quality) || 0)
|
||
|
|
: (b.staticData?.quality ?? gg.data.table.getItemData(b.id)?.quality ?? 0);
|
||
|
|
return qb - qa;
|
||
|
|
}
|
||
|
|
);
|
||
|
|
this.updateUI();
|
||
|
|
|
||
|
|
let isHaveNewTool = false
|
||
|
|
for (let i = 0; i < this.dataList.length; i++) {
|
||
|
|
let data = this.dataList[i];
|
||
|
|
if (data.isEquip) continue;
|
||
|
|
if (this.dataList[i].isFragment) {
|
||
|
|
//获取武器属性,如果有该武器就把武器转为对应的武器碎片
|
||
|
|
let isHaveWeapon = gg.data.project.isWeaponUnlocked(data.id);
|
||
|
|
|
||
|
|
if (isHaveWeapon) {
|
||
|
|
|
||
|
|
} else {
|
||
|
|
//没有武器添加武器数据,不用了
|
||
|
|
isHaveNewTool = false
|
||
|
|
break
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
this.getNewToolNode.active = isHaveNewTool
|
||
|
|
this.getIconNode.active = !isHaveNewTool
|
||
|
|
}
|
||
|
|
|
||
|
|
dataList: ItemData[] = [];
|
||
|
|
|
||
|
|
/** type=4 品质碎片箱:展开为已解锁英雄的具体碎片(与 showGetRewardByReardStr 一致) */
|
||
|
|
private _expandType4RewardList(list: ItemData[]): ItemData[] {
|
||
|
|
const result: ItemData[] = [];
|
||
|
|
for (const data of list) {
|
||
|
|
const itemData = data.staticData ?? gg.data.table.getItemData(data.id);
|
||
|
|
if (itemData?.type === 4) {
|
||
|
|
const boxRewardArray = gg.data.getFragmentNumArray(`${data.id},${data.num}`);
|
||
|
|
const statsArray = MTools.mergeToStatsArray(boxRewardArray);
|
||
|
|
for (const entry of statsArray) {
|
||
|
|
const [idStr, numStr] = entry.split('|');
|
||
|
|
const item = new ItemData(Number(idStr), Number(numStr));
|
||
|
|
item.id = Number(idStr);
|
||
|
|
item.num = Number(numStr);
|
||
|
|
result.push(item);
|
||
|
|
}
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
result.push(data);
|
||
|
|
}
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
updateUI() {
|
||
|
|
// this.com_content.destroyAllChildren();
|
||
|
|
|
||
|
|
// this.ui_content.destroyAllChildren();
|
||
|
|
|
||
|
|
if (this.dataList.length <= 8) {
|
||
|
|
this.com_content.active = true
|
||
|
|
this.ui_content.active = false
|
||
|
|
this.curChooseContent = this.com_content
|
||
|
|
if (this.dataList.length >= 4) {
|
||
|
|
this.com_content.getComponent(UITransform).width = 560
|
||
|
|
} else {
|
||
|
|
this.com_content.getComponent(UITransform).width = this.dataList.length * 125 + (this.dataList.length - 1) * 20
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
this.com_content.active = false
|
||
|
|
this.ui_content.active = true
|
||
|
|
//ui_layOut 高度变化
|
||
|
|
let num = Math.ceil(this.dataList.length / 4)
|
||
|
|
//上下高度40*2
|
||
|
|
this.ui_layOut.getComponent(UITransform).height = num * 125 + (num - 1) * 20 + 40 * 2
|
||
|
|
this.curChooseContent = this.ui_content
|
||
|
|
}
|
||
|
|
|
||
|
|
for (let i = 0; i < this.dataList.length; i++) {
|
||
|
|
this.createAGrid(this.dataList[i], i);
|
||
|
|
if (i === this.dataList.length - 1) {
|
||
|
|
this.curChooseContent.getComponent(Layout).updateLayout();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
createAGrid(data, index: number) {
|
||
|
|
let grid = instantiate(this.ui_rewardGrid);
|
||
|
|
grid.setPosition(0, 0);
|
||
|
|
grid.parent = this.curChooseContent;
|
||
|
|
grid.active = true;
|
||
|
|
|
||
|
|
grid.getComponent(RewardGrid).setData(data);
|
||
|
|
this.popRevealEnqueue(grid, 'scale');
|
||
|
|
|
||
|
|
return grid;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
click_btnToBag(): void {
|
||
|
|
if (this.isItemRevealPlaying()) {
|
||
|
|
this.skipPopReveal();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (this.isadd) {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
this.isadd = true
|
||
|
|
this.close(2);
|
||
|
|
for (let i = 0; i < this.dataList.length; i++) {
|
||
|
|
let data = this.dataList[i];
|
||
|
|
if (data.isEquip) {
|
||
|
|
gg.equip.addHaveEquip(data.id, data.num);
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
if (this.dataList[i].isFragment) {
|
||
|
|
//获取武器属性,如果有该武器就把武器转为对应的武器碎片
|
||
|
|
let isHaveWeapon = gg.data.project.isWeaponUnlocked(data.id);
|
||
|
|
|
||
|
|
if (isHaveWeapon) {
|
||
|
|
//有武器转为碎片数量
|
||
|
|
//武器属性
|
||
|
|
let weaponData = gg.data.project.getWeaponData(data.id);
|
||
|
|
const scrapId = gg.data.project.getWeaponScrapId(weaponData.id);
|
||
|
|
let itemData = gg.data.table.getItemData(scrapId);
|
||
|
|
if (!itemData) continue;
|
||
|
|
gg.data.addItemNum(scrapId, data.num * itemData.transition);
|
||
|
|
} else {
|
||
|
|
//没有武器添加武器数据
|
||
|
|
gg.data.project.unlockWeapon(data.id);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
gg.data.addItemNum(data.id, data.num);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
gg.data.saveLocal();
|
||
|
|
gg.data.saveToServer();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|