85 lines
3.0 KiB
TypeScript
85 lines
3.0 KiB
TypeScript
/************************************************************************************
|
|
|
|
* FileName : RewardItem.ts
|
|
* Description :
|
|
* Version : v1.0.0
|
|
* CreateTime : 2024-12-11 21:44:54
|
|
* Author :
|
|
* Copyright (c) since 2024
|
|
* ==============================================================
|
|
* Method Description:
|
|
*
|
|
* ==============================================================
|
|
************************************************************************************/
|
|
import { _decorator, Component, Node, Sprite, Label, SpriteFrame } from 'cc';
|
|
import {resLoader} from "db://assets/core_tgx/base/utils/ResLoader";
|
|
import {ModuleDef} from "db://assets/scripts/ModuleDef";
|
|
import {areanMgr} from "db://assets/module_arean/scripts/AreanManager";
|
|
import {CommonFun} from "db://assets/module_arean/scripts/CommonFun";
|
|
import {EAreanBuyType, IRewardData} from "db://assets/module_basic/shared/protocols/public/arean/AreanTypeDef";
|
|
import {UserMgr} from "db://assets/module_basic/scripts/UserMgr";
|
|
import {BaseUI} from "db://assets/module_arean/scripts/BaseUI";
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('RewardItem')
|
|
export class RewardItem extends BaseUI {
|
|
@property(Sprite)
|
|
bg : Sprite = null;
|
|
@property(Sprite)
|
|
icon : Sprite = null;
|
|
@property(Label)
|
|
iconName : Label = null;
|
|
@property(Label)
|
|
iconCount : Label = null;
|
|
|
|
// 道具属性
|
|
private _itemData : IRewardData = null;
|
|
|
|
public initData(data : IRewardData) : void{
|
|
this._itemData = data;
|
|
this._updateIcon(data);
|
|
this._updateName(data);
|
|
this._updateCount(data);
|
|
this._updateItem(data);
|
|
CommonFun.getInstance().showItemInfo(this.node,this._itemData.itemId);
|
|
}
|
|
|
|
/** 更新客户端数据 */
|
|
private _updateItem(data : IRewardData) : void{
|
|
// let index = UserMgr.inst.userInfo.itemList.findIndex((item)=> item.itemId == data.itemId)
|
|
// if (index !== -1) {
|
|
// UserMgr.inst.userInfo.itemList[index].itemCount += data.count;
|
|
// }else{
|
|
// UserMgr.inst.userInfo.itemList.push({itemId: data.itemId, itemCount: data.count});
|
|
// }
|
|
// if(data.itemId == EAreanBuyType.Coin){
|
|
// UserMgr.inst.userInfo.coin += data.count;
|
|
// }else if(data.itemId == EAreanBuyType.Diamond){
|
|
// UserMgr.inst.userInfo.diamond += data.count;
|
|
// }
|
|
}
|
|
|
|
private async _updateIcon(data: IRewardData) {
|
|
let itemData = areanMgr.cfgMgr.PropData.getData(data.itemId);
|
|
if (itemData) {
|
|
let sp: SpriteFrame = await this.getPropIconSprite(itemData.icon);
|
|
if (sp) this.icon.spriteFrame = sp;
|
|
}
|
|
}
|
|
|
|
private _updateName(data : IRewardData) : void{
|
|
let itemData = areanMgr.cfgMgr.PropData.getData(data.itemId);
|
|
if(itemData){
|
|
this.iconName.string = `${itemData.name}`;
|
|
}
|
|
}
|
|
|
|
private _updateCount(data : IRewardData) : void{
|
|
this.iconCount.string = `${data.count}`;
|
|
}
|
|
|
|
public clickBtn() : void{
|
|
console.log("些道具的信息 ==== ",this._itemData);
|
|
|
|
}
|
|
} |