// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import { SaveDataManager } from "../../component/SaveDataManager"; import { ADID, tMgr, WindowName } from "../../Global"; import { TableName, UserSkillTable } from "../../kernel/table/TableDefine"; import { UIBase } from "../UIBase"; import { UIManager } from "../UIManager"; const { ccclass, property } = cc._decorator; @ccclass export default class UIUserSkillInfo extends UIBase { private _config: UserSkillTable; //#region LIFE-CYCLE CALLBACKS: // onLoad () {} @property(cc.Node) btn_ad: cc.Node = null; @property(cc.Node) btn_start: cc.Node = null; @property(cc.Node) btn_bonus: cc.Node = null; openCount: number = 0; protected onEnable(): void { let skillId = this.enableParam; this._config = tMgr.getConfig(TableName.USER_SKILL, skillId) as UserSkillTable; this.node.getChildByName('txtDesc').getComponent(cc.Label).string = this._config.Desc; cc.resources.load('ui/battle/' + this._config.Icon, cc.SpriteFrame, (error, asset) => { if (!error) { this.node.getChildByName('icon').getComponent(cc.Sprite).spriteFrame = asset as cc.SpriteFrame; } }); this.node.getChildByName('btnDiamond').getComponentInChildren(cc.Label).string = this._config.Cost.toString(); this.node.getChildByName('icon').getComponentInChildren(cc.Label).string = this._config.BuyNum.toString(); this.btn_ad.getChildByName('Background').getChildByName('UI_General_Btn_yellow_ckgg').active = true; this.btn_ad.getChildByName('Background').getChildByName('UI_Finish_kxsx').active = false; this.openCount++; if (this.openCount > 1) { this.BtnPos_Change(); } } //按钮位置轮换 BtnPos_Change() { let tempPos = this.btn_start.position; this.btn_start.position = this.btn_bonus.position; this.btn_bonus.position = this.btn_ad.position; this.btn_ad.position = tempPos; } // update (dt) {} //#endregion //#region event onBtnCloseClick() { UIManager.ins.closeWindow(WindowName.USER_SKILL_INFO); } onBtnAdClick() { //AD 放广告,放完后调用 doAddNum() // HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => { if (true) { this.doAddNum(); } else { console.log('视频播放失败'); } // }); this.onBtnCloseClick(); } onBtnBuyClick() { if (SaveDataManager.ins.adjustDiamond(-this._config.Cost)) { //扣钱成功 this.doAddNum(); this.onBtnCloseClick(); } else { console.log('diamond donot enough') } } //#endregion //#region private method private doAddNum() { SaveDataManager.ins.setUserSkillNumDelta(this._config.ID, this._config.BuyNum); } //#endregion }