84 lines
3.1 KiB
TypeScript
84 lines
3.1 KiB
TypeScript
import { _decorator, Button, Component, director, Label, Node, Sprite, SpriteFrame, Prefab, instantiate, v3,sp } from 'cc';
|
|
import {areanMgr} from "db://assets/module_arean/scripts/AreanManager";
|
|
import {EAreanItemType, ItemAttributes} from "db://assets/module_basic/shared/protocols/public/arean/AreanTypeDef";
|
|
import {resLoader} from "db://assets/core_tgx/base/utils/ResLoader";
|
|
import {ModuleDef} from "db://assets/scripts/ModuleDef";
|
|
import {CommonFun} from "db://assets/module_arean/scripts/CommonFun";
|
|
import {tgxAudioMgr} from "db://assets/core_tgx/tgx";
|
|
import {EMusicDefine} from "db://assets/module_basic/Define/MusicDefine";
|
|
import {UserMgr} from "db://assets/module_basic/scripts/UserMgr";
|
|
import { IPropCfg } from '../../module_basic/shared/configs/interface/IPropCfg';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('BagItemDetail')
|
|
export class BagItemDetail extends Component {
|
|
|
|
@property(Sprite)
|
|
icon: Sprite;
|
|
|
|
|
|
@property(Label)
|
|
itemName: Label;
|
|
|
|
@property(Label)
|
|
itemDesc: Label;
|
|
|
|
@property(Node)
|
|
btnOpen: Node;
|
|
|
|
private _curItem:ItemAttributes = null;
|
|
private _callBack : Function = null;
|
|
|
|
start(){
|
|
}
|
|
|
|
async openBox() {
|
|
tgxAudioMgr.inst.playCommonBtn(EMusicDefine.EFFECT_CLICK);
|
|
let result = await UserMgr.inst.rpc_use_item(this._curItem.itemId);
|
|
console.log("使用道具结果=========================",result)
|
|
this._callBack && this._callBack(result);
|
|
}
|
|
|
|
setCallBack(fun : Function) : void{
|
|
this._callBack = fun;
|
|
}
|
|
|
|
public setData(item: ItemAttributes) : void {
|
|
this._curItem = item;
|
|
let data : IPropCfg = areanMgr.cfgMgr.PropData.getData(this._curItem.itemId);
|
|
if(data){
|
|
if(data.type === EAreanItemType.Hero){
|
|
let skinId = data.icon
|
|
resLoader.load<Prefab>(ModuleDef.Arean,`res/Prefebs/heroSpine/${skinId}`,(err: Error, prefab: Prefab) => {
|
|
if(err){
|
|
console.error(err);
|
|
return;
|
|
}else {
|
|
let spineNode = instantiate(prefab);
|
|
this.icon.node.destroyAllChildren();
|
|
this.icon.node.addChild(spineNode);
|
|
spineNode.scale = v3(0.8,0.8,1);
|
|
spineNode.position = v3(0,-60,0);
|
|
spineNode.getComponent(sp.Skeleton).animation = null;
|
|
}
|
|
})
|
|
}else{
|
|
this.icon.node.destroyAllChildren();
|
|
let res : string = CommonFun.getInstance().getIcon(item.itemId);
|
|
let sp : SpriteFrame = resLoader.getSpriteFrame(res,ModuleDef.Arean);
|
|
if(sp) this.icon.getComponent(Sprite).spriteFrame = sp;
|
|
}
|
|
this.itemDesc.string = data.desc;
|
|
this.itemName.string = data.name;
|
|
}
|
|
this.updateBtnState();
|
|
}
|
|
|
|
public updateBtnState() : void{
|
|
let data : IPropCfg = areanMgr.cfgMgr.PropData.getData(this._curItem.itemId);
|
|
this.btnOpen.active = data && data.type !== EAreanItemType.Hero;
|
|
}
|
|
}
|
|
|
|
|