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.
215 lines
7.3 KiB
215 lines
7.3 KiB
|
1 week ago
|
|
||
|
|
//*********************
|
||
|
|
// create by 流云
|
||
|
|
// time: Sat Feb 15 2025
|
||
|
|
// desc:
|
||
|
|
//*********************
|
||
|
|
import { _decorator, Component, Node, find, Layout, instantiate, tween, v3, Vec3, UITransform } from 'cc';
|
||
|
|
import { RewardGrid } from './RewardGrid';
|
||
|
|
|
||
|
|
import { ItemNumType, StatusType } from '../../game/GameData';
|
||
|
|
import { ItemData } from '../../game/ConfigProjectData';
|
||
|
|
import { Auto_GetReward } from './Auto_GetReward';
|
||
|
|
import { GEvent } from 'db://assets/mx/module/event/GEvent';
|
||
|
|
const { ccclass, property } = _decorator;
|
||
|
|
|
||
|
|
@ccclass('UIGetReward')
|
||
|
|
export class UIGetReward extends Auto_GetReward {
|
||
|
|
|
||
|
|
/** 获得奖励弹窗最多展示条目(合并同 id 后);实际入账用 _grantList 全量 */
|
||
|
|
private static readonly MAX_REWARD_ITEMS = 30;
|
||
|
|
|
||
|
|
curChooseContent = null
|
||
|
|
isadd = false
|
||
|
|
/** 合并后的完整奖励,确认时全部入账 */
|
||
|
|
private _grantList: ItemData[] = []
|
||
|
|
onLoad(): void {
|
||
|
|
super.onLoad();
|
||
|
|
}
|
||
|
|
|
||
|
|
onEnable(): void {
|
||
|
|
super.onEnable();
|
||
|
|
}
|
||
|
|
|
||
|
|
onDisable(): void {
|
||
|
|
super.onDisable();
|
||
|
|
gg.game.afkRewardClaimLock = false;
|
||
|
|
GEvent.Ins.emit(GEvent.UpdateGetItem);
|
||
|
|
}
|
||
|
|
|
||
|
|
onInit() {
|
||
|
|
this.unscheduleAllCallbacks();
|
||
|
|
this._clearRewardGrids();
|
||
|
|
this.showOpenMaskEff(2);
|
||
|
|
this.isadd = false
|
||
|
|
this._grantList = []
|
||
|
|
gg.audio.playEffect({ name: "获得物品弹窗" });
|
||
|
|
this._grantList = this._normalizeRewardList(this.prema ?? []);
|
||
|
|
this._grantList.sort((a, b) => {
|
||
|
|
let itena = a.staticData;
|
||
|
|
let itemb = b.staticData;
|
||
|
|
if (!itena) itena = gg.data.table.getItemData(a.id);
|
||
|
|
if (!itemb) itemb = gg.data.table.getItemData(b.id);
|
||
|
|
if(!itena || !itemb) return 0;
|
||
|
|
return itemb.quality - itena.quality;
|
||
|
|
});
|
||
|
|
this.dataList = this._grantList.length <= UIGetReward.MAX_REWARD_ITEMS
|
||
|
|
? this._grantList
|
||
|
|
: this._grantList.slice(0, UIGetReward.MAX_REWARD_ITEMS);
|
||
|
|
this.updateUI();
|
||
|
|
let ui_center = this.node.getChildByName('ui_center')
|
||
|
|
ui_center.scale = v3(0.1, 0.1, 0.1)
|
||
|
|
tween(ui_center)
|
||
|
|
.to(0.5, { scale: v3(1, 1, 1) }, { easing: 'elasticOut' })
|
||
|
|
.start()
|
||
|
|
|
||
|
|
let isHaveNewTool = false
|
||
|
|
for (let i = 0; i < this._grantList.length; i++) {
|
||
|
|
let data = this._grantList[i];
|
||
|
|
if (this._grantList[i].isFragment) {
|
||
|
|
//获取武器属性,如果有该武器就把武器转为对应的武器碎片
|
||
|
|
let isHaveWeapon = gg.data.project.isWeaponUnlocked(data.id);
|
||
|
|
|
||
|
|
if (isHaveWeapon) {
|
||
|
|
|
||
|
|
} else {
|
||
|
|
//没有武器添加武器数据,不用了
|
||
|
|
isHaveNewTool = false
|
||
|
|
break
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
//如果拥有了该皮肤,就把该皮肤转为1000钻石
|
||
|
|
let itemData = gg.data.table.getItemData(data.id);
|
||
|
|
if (itemData && itemData.type == 5 && gg.skin.checkHasSkin(itemData.id)) {
|
||
|
|
let { pieceId, num } = gg.role.skinToPiece(itemData.id);
|
||
|
|
data.id = pieceId
|
||
|
|
|
||
|
|
data.num = num * data.num;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
this.getNewToolNode.active = isHaveNewTool
|
||
|
|
this.getIconNode.active = !isHaveNewTool
|
||
|
|
}
|
||
|
|
|
||
|
|
dataList: ItemData[] = [];
|
||
|
|
|
||
|
|
/** 合并同 id 数量,防止上游 itemsArray 重复 push 时格子刷屏 */
|
||
|
|
private _normalizeRewardList(list: ItemData[]): ItemData[] {
|
||
|
|
const countMap = new Map<number, ItemData>();
|
||
|
|
for (let i = 0; i < list.length; i++) {
|
||
|
|
const src = list[i];
|
||
|
|
if (!src?.id) continue;
|
||
|
|
const prev = countMap.get(src.id);
|
||
|
|
if (prev) {
|
||
|
|
prev.num = (prev.num ?? 0) + (src.num ?? 0);
|
||
|
|
} else {
|
||
|
|
const copy = new ItemData(src.id, src.num);
|
||
|
|
copy.isFragment = src.isFragment;
|
||
|
|
copy.staticData = src.staticData;
|
||
|
|
countMap.set(src.id, copy);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return Array.from(countMap.values());
|
||
|
|
}
|
||
|
|
|
||
|
|
private _clearRewardGrids() {
|
||
|
|
if (this.com_content?.isValid) this.com_content.destroyAllChildren();
|
||
|
|
if (this.ui_content?.isValid) this.ui_content.destroyAllChildren();
|
||
|
|
}
|
||
|
|
|
||
|
|
updateUI() {
|
||
|
|
this._clearRewardGrids();
|
||
|
|
|
||
|
|
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)
|
||
|
|
//
|
||
|
|
if(this.dataList.length >= UIGetReward.MAX_REWARD_ITEMS){
|
||
|
|
num = Math.ceil(UIGetReward.MAX_REWARD_ITEMS / 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++) {
|
||
|
|
let data = this.dataList[i];
|
||
|
|
this.scheduleOnce(() => {
|
||
|
|
this.createAGrid(data);
|
||
|
|
if (i == this.dataList.length - 1) {
|
||
|
|
this.curChooseContent.getComponent(Layout).updateLayout();
|
||
|
|
}
|
||
|
|
}, 0.15 * i);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
createAGrid(data) {
|
||
|
|
let grid = instantiate(this.ui_rewardGrid);
|
||
|
|
grid.setPosition(0, 0);
|
||
|
|
grid.parent = this.curChooseContent;
|
||
|
|
grid.active = true;
|
||
|
|
|
||
|
|
grid.getComponent(RewardGrid).setData(data);
|
||
|
|
|
||
|
|
grid.scale = Vec3.ZERO
|
||
|
|
tween(grid).set({ opacity: 0 }).to(0.2, { scale: Vec3.ONE, opacity: 255 }, { easing: 'backOut' }).start();
|
||
|
|
|
||
|
|
return grid;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
click_btnToBag(): void {
|
||
|
|
if (this.isadd) return;
|
||
|
|
this.isadd = true;
|
||
|
|
gg.audio.playEffect({ name: "成功获得物品" });
|
||
|
|
this.close(2);
|
||
|
|
for (let i = 0; i < this._grantList.length; i++) {
|
||
|
|
let data = this._grantList[i];
|
||
|
|
if (this._grantList[i].isFragment) {
|
||
|
|
//获取武器属性,如果有该武器就把武器转为对应的武器碎片
|
||
|
|
let isHaveWeapon = gg.data.project.isWeaponUnlocked(data.id);
|
||
|
|
|
||
|
|
if (isHaveWeapon) {
|
||
|
|
//有武器转为碎片数量
|
||
|
|
//武器属性
|
||
|
|
let weaponData = gg.data.project.getWeaponData(data.id);
|
||
|
|
let itemData = gg.data.table.getItemData(weaponData.scrapId)
|
||
|
|
|
||
|
|
gg.data.addItemNum(weaponData.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();
|
||
|
|
gg.newFun.checkNewFunPop();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|