"use strict"; cc._RF.push(module, '9db7eM9faJCuoiR7FkqUhYW', 'UIShop'); // scripts/ui/uiView/UIShop.ts "use strict"; // 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 var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var SaveDataManager_1 = require("../../component/SaveDataManager"); var Global_1 = require("../../Global"); var TableDefine_1 = require("../../kernel/table/TableDefine"); var UIBase_1 = require("../UIBase"); var UIManager_1 = require("../UIManager"); var UITitle_1 = require("./UITitle"); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var UIShop = /** @class */ (function (_super) { __extends(UIShop, _super); function UIShop() { var _this = _super.call(this) || this; _this.txtPackDiamond = null; _this.txtAdDiamond = null; _this.adNode = null; _this.btn_ad = null; _this._useCloseEffect = false; _this._usePopUpEffect = false; return _this; } //#region lifecycle UIShop.prototype.onLoad = function () { this.txtPackDiamond.getComponent(cc.Label).string = Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 20).Value.toString(); this.txtAdDiamond.getComponent(cc.Label).string = Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 14).Value.toString(); var content = cc.find('scrollView/view/content', this.node); for (var i = 1; i <= 4; ++i) { var item = content.getChildByName('itemSkill' + i.toString()); item.getChildByName('btnGet').getComponentInChildren(cc.Label).string = Global_1.tMgr.getConfig(TableDefine_1.TableName.USER_SKILL, i).Cost.toString(); item.getChildByName('icon').getComponentInChildren(cc.Label).string = Global_1.tMgr.getConfig(TableDefine_1.TableName.USER_SKILL, i).BuyNum.toString(); } }; UIShop.prototype.onEnable = function () { this.refresh(); this.setAD(); }; UIShop.prototype.setAD = function () { // this.adNode.getComponent(CustomNativeAdView).showNativeAd((result) => { // if (result) { // this.btn_ad.active = true; // } else { // this.btn_ad.active = false; // } // }); this.btn_ad.getChildByName('Background').getChildByName('UI_General_Btn_yellow_ckgg').active = true; this.btn_ad.getChildByName('Background').getChildByName('UI_Finish_kxsx').active = false; }; UIShop.prototype.onDestroy = function () { UIManager_1.UIManager.ins.cache.delete(Global_1.WindowName.SHOP); // 此界面添加在场景中,会随场景一起销毁,将UIManager中的缓存也删除,避免后续取到被销毁的缓存 }; UIShop.prototype.hide_btn_ad = function () { this.btn_ad.active = false; }; //#endregion //#region public method //#endregion //#region event UIShop.prototype.onGetClick = function (e, customData) { if (customData == 'pack') { //AD 放广告,放完后调 getPack() // HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => { if (true) { this.getPack(); } else { console.log('视频播放失败'); } // }); } else if (customData == 'diamond') { //AD 放广告,放完后调 getDiamond() // HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => { if (true) { this.getDiamond(); } else { console.log('视频播放失败'); } // }); } else if (customData == 'ad') { //AD 纯看广告 } else if (customData.includes('skill')) { var skillId = Number(customData.slice(5)); var config = Global_1.tMgr.getConfig(TableDefine_1.TableName.USER_SKILL, skillId); var wpos = e.target.convertToWorldSpaceAR(cc.Vec3.ZERO); if (SaveDataManager_1.SaveDataManager.ins.adjustDiamond(-config.Cost, true, wpos)) { //扣钱成功 SaveDataManager_1.SaveDataManager.ins.setUserSkillNumDelta(skillId, config.BuyNum); } } }; UIShop.prototype.onCloseClick = function () { var titleNode = cc.find('Canvas/UITitle', cc.director.getScene()); titleNode.getComponent(UITitle_1.default).onShopCloseClick(); }; //#endregion //#region private method UIShop.prototype.refresh = function () { var btnPackGet = cc.find('bg/pack/btnBuy', this.node); var btnPackBg = btnPackGet.getChildByName('Background'); var valid = (Date.now() > SaveDataManager_1.SaveDataManager.ins.runtimeData.shopDailyPackRefreshTime); btnPackGet.getComponent(cc.Button).interactable = valid; btnPackBg.getChildByName('txtFree').active = valid; btnPackBg.getChildByName('iconAd').active = valid; btnPackBg.getChildByName('txtGeted').active = !valid; }; UIShop.prototype.getPack = function () { var valid = (Date.now() > SaveDataManager_1.SaveDataManager.ins.runtimeData.shopDailyPackRefreshTime); if (valid) { var config = Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 20); //礼包钻石数量 SaveDataManager_1.SaveDataManager.ins.adjustDiamond(config.Value, true); SaveDataManager_1.SaveDataManager.ins.setUserSkillNumDelta(1, 1); SaveDataManager_1.SaveDataManager.ins.setUserSkillNumDelta(2, 1); SaveDataManager_1.SaveDataManager.ins.setUserSkillNumDelta(3, 1); SaveDataManager_1.SaveDataManager.ins.setUserSkillNumDelta(4, 1); var endTime = new Date(); endTime.setHours(23, 59, 59); SaveDataManager_1.SaveDataManager.ins.runtimeData.shopDailyPackRefreshTime = endTime.getTime(); SaveDataManager_1.SaveDataManager.ins.saveData(); this.refresh(); } }; UIShop.prototype.getDiamond = function () { var config = Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 14); SaveDataManager_1.SaveDataManager.ins.adjustDiamond(config.Value, true); }; __decorate([ property(cc.Node) ], UIShop.prototype, "txtPackDiamond", void 0); __decorate([ property(cc.Node) ], UIShop.prototype, "txtAdDiamond", void 0); __decorate([ property(cc.Node) ], UIShop.prototype, "adNode", void 0); __decorate([ property(cc.Node) ], UIShop.prototype, "btn_ad", void 0); UIShop = __decorate([ ccclass ], UIShop); return UIShop; }(UIBase_1.UIBase)); exports.default = UIShop; cc._RF.pop();