123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import { _decorator, Component, Node, Sprite, spriteAssembler, SpriteFrame } from 'cc';
- import BasePanel from '../core/component/BasePanel';
- import { audioMgr } from '../core/manager/AudioManager';
- import Data from '../core/manager/Data';
- import WindowManager from '../core/manager/WindowManager';
- import MsgHints from '../core/utils/MsgHints';
- import { Main } from '../game/Main';
- import { ITEM_TYPE, GameConst } from '../core/common/GameConst';
- import i18n from '../core/i18n/runtime-scripts/LanguageData';
- import platformSystem from '../platform/platformSystem';
- const { ccclass, property } = _decorator;
- @ccclass('BuyItemLayer')
- export class BuyItemLayer extends BasePanel {
- @property({type:Node,tooltip:"金币节点"})
- public gold_n: Node = null!;
- @property({type:Node,tooltip:"视频节点"})
- public video_n: Node = null!;
- private type: ITEM_TYPE;
- setItemType(type: ITEM_TYPE) {
- this.type = type;
- this.GetGameObject("Magnet").active = type == ITEM_TYPE.Magnet;
- this.GetGameObject("Hint").active = type == ITEM_TYPE.Hint;
- this.GetGameObject("Frozen").active = type == ITEM_TYPE.Frozen;
- this.GetGameObject("Time").active = type == ITEM_TYPE.Time;
- this.SetText("lbl_name", GameConst.getItemName(type))
- Main.I._GameUI.pasue = true;
- }
- onLoad(): void {
- if(Data.user.coin <= 0){
- this.gold_n.active = false;
- this.video_n.active = true;
- }else{
- this.gold_n.active = true;
- this.video_n.active = false;
- }
- }
- onDestroy() {
- super.onDestroy();
- Main.I._GameUI.pasue = false;
- }
- onBtnClicked(event: any, customEventData: any) {
- audioMgr.playOneShot(GameConst.audios.btnclick);
- var btnName = event.target.name;
- switch (btnName) {
- case "btn_close":
- this.close();
- break;
- case "btn_buy":
- if(Data.user.coin <= 0){
- platformSystem.platform.showRewardVideo((b) => {
- if(b){
- MsgHints.show(i18n("main.购买成功!"))
- Data.user.coin -= 90;
- Data.user.addItem(this.type, 3);
- Data.save();
- this.close();
- }
- })
- }else{
- if (Data.user.coin < 90) {
- WindowManager.ins.open("BuyCoinLayer");
- }else {
- MsgHints.show(i18n("main.购买成功!"))
- Data.user.coin -= 90;
- Data.user.addItem(this.type, 3);
- Data.save();
- this.close();
- }
- break;
- }
- }
- }
- }
|