"use strict"; cc._RF.push(module, 'dd39fiKMpdPLadEN606AFdU', 'UIBallSkinPreview'); // scripts/ui/uiView/UIBallSkinPreview.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 BattleConst_1 = require("../../kernel/battle/BattleConst"); var PhysicsControl_1 = require("../../kernel/physics/PhysicsControl"); var TableDefine_1 = require("../../kernel/table/TableDefine"); var SkinPreviewBall_1 = require("../../prefabs/SkinPreviewBall"); var UIBase_1 = require("../UIBase"); var UIManager_1 = require("../UIManager"); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var UIBallSkinPreview = /** @class */ (function (_super) { __extends(UIBallSkinPreview, _super); function UIBallSkinPreview() { var _this = _super.call(this) || this; _this.imgTitle = null; _this.prg = null; _this._curId = 0; //#region lifecycle _this.btn_ad = null; _this.btn_start = null; _this.btn_bonus = null; _this.btn_sign = null; _this.btn_wheel = null; _this.btn_use = null; _this.btn_useing = null; _this.openCount = 0; return _this; // this._useCloseEffect = false; // this._usePopUpEffect = false; } UIBallSkinPreview.prototype.onEnable = function () { BattleConst_1.getGlobalNode().on(Global_1.GlobalEvent.BALL_SKIN_UNLOCK, this.refreshState, this); BattleConst_1.getGlobalNode().on(Global_1.GlobalEvent.BALL_SKIN_USE, this.refreshState, this); this.refresh(this.enableParam); 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(); } }; //按钮位置轮换 UIBallSkinPreview.prototype.BtnPos_Change = function () { var tempPos = this.btn_start.position; this.btn_start.position = this.btn_bonus.position; this.btn_sign.position = this.btn_bonus.position; this.btn_wheel.position = this.btn_bonus.position; this.btn_use.position = this.btn_bonus.position; this.btn_useing.position = this.btn_bonus.position; this.btn_bonus.position = this.btn_ad.position; this.btn_ad.position = tempPos; }; UIBallSkinPreview.prototype.onPopUpEffectFinish = function () { this.node.getChildByName('physics').active = true; PhysicsControl_1.PhysicsControl.ins.setPhysicsEnable(true); }; UIBallSkinPreview.prototype.onBeforeClose = function () { _super.prototype.onBeforeClose.call(this); this.node.getChildByName('physics').active = false; PhysicsControl_1.PhysicsControl.ins.setPhysicsEnable(false); }; UIBallSkinPreview.prototype.update = function (dt) { PhysicsControl_1.PhysicsControl.ins.update(dt); }; UIBallSkinPreview.prototype.onDisable = function () { BattleConst_1.getGlobalNode().targetOff(this); }; //#endregion //#region public method //#endregion //#region event UIBallSkinPreview.prototype.onBtnCloseClick = function () { UIManager_1.UIManager.ins.closeWindow(Global_1.WindowName.BALL_SKIN_PREVIEW); }; UIBallSkinPreview.prototype.onPreClick = function () { if (this._curId > 1) { this.refresh(this._curId - 1); } }; UIBallSkinPreview.prototype.onNextClick = function () { var maxId = Global_1.tMgr.getTableMaxID(TableDefine_1.TableName.BALL_SKIN); if (this._curId < maxId) { this.refresh(this._curId + 1); } }; UIBallSkinPreview.prototype.onBuyClick = function () { var wpos = this.node.getChildByName('btnDiamond').convertToWorldSpaceAR(cc.v3(0, 0, 0)); var config = Global_1.tMgr.getConfig(TableDefine_1.TableName.BALL_SKIN, this._curId); if (SaveDataManager_1.SaveDataManager.ins.adjustDiamond(-config.Price, true, wpos)) { SaveDataManager_1.SaveDataManager.ins.unlockBallSkin(config.ID); } }; UIBallSkinPreview.prototype.onSignClick = function () { UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.SIGN); }; UIBallSkinPreview.prototype.onWheelClick = function () { UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.WHEEL); }; UIBallSkinPreview.prototype.onAdTryClick = function () { //AD 放广告,放完后调setTrySkin // HeyGamePlatform.instance.showVideoAd(ADID.ADID_ADDCOIN, (_result) => { if (true) { this.setTrySkin(); } else { console.log('视频播放失败'); } // }); }; UIBallSkinPreview.prototype.onUseClick = function () { SaveDataManager_1.SaveDataManager.ins.useBallSkin(this._curId); }; //#endregion //#region private method UIBallSkinPreview.prototype.refresh = function (skinId) { var _this = this; if (skinId != this._curId) { this._curId = skinId; var config = Global_1.tMgr.getConfig(TableDefine_1.TableName.BALL_SKIN, skinId); this.prg.getComponent(cc.ProgressBar).progress = 0.33 * config.Size; this.refreshState(); cc.resources.load('ui/ballSkinName/name' + skinId.toString(), cc.SpriteFrame, function (error, asset) { !error && (_this.imgTitle.getComponent(cc.Sprite).spriteFrame = asset); }); var ballNode = cc.find('physics/ball', this.node); ballNode.getComponent(SkinPreviewBall_1.default).setSkin(skinId); } }; UIBallSkinPreview.prototype.refreshState = function () { var config = Global_1.tMgr.getConfig(TableDefine_1.TableName.BALL_SKIN, this._curId); var isUnlocked = SaveDataManager_1.SaveDataManager.ins.runtimeData.ballSkinUnlocked.includes(config.ID); var isUsing = (SaveDataManager_1.SaveDataManager.ins.runtimeData.ballSkinCurrent == config.ID); this.node.getChildByName('btnAd').getComponent(cc.Button).interactable = !isUnlocked; this.node.getChildByName('btnDiamond').active = !isUnlocked && config.Price > 0; if (this.node.getChildByName('btnDiamond').active) { this.node.getChildByName('btnDiamond').getComponentInChildren(cc.Label).string = config.Price.toString(); } this.node.getChildByName('btnSign').active = !isUnlocked && config.Price == -1; this.node.getChildByName('btnWheel').active = !isUnlocked && config.Price == -2; this.node.getChildByName('btnUse').active = isUnlocked && !isUsing; this.node.getChildByName('btnUsing').active = isUnlocked && isUsing; }; UIBallSkinPreview.prototype.setTrySkin = function () { SaveDataManager_1.SaveDataManager.ins.runtimeData.ballSkinTry = this._curId; SaveDataManager_1.SaveDataManager.ins.saveData(); UIManager_1.UIManager.ins.closeWindow(Global_1.WindowName.BALL_SKIN_PREVIEW); }; __decorate([ property(cc.Node) ], UIBallSkinPreview.prototype, "imgTitle", void 0); __decorate([ property(cc.Node) ], UIBallSkinPreview.prototype, "prg", void 0); __decorate([ property(cc.Node) ], UIBallSkinPreview.prototype, "btn_ad", void 0); __decorate([ property(cc.Node) ], UIBallSkinPreview.prototype, "btn_start", void 0); __decorate([ property(cc.Node) ], UIBallSkinPreview.prototype, "btn_bonus", void 0); __decorate([ property(cc.Node) ], UIBallSkinPreview.prototype, "btn_sign", void 0); __decorate([ property(cc.Node) ], UIBallSkinPreview.prototype, "btn_wheel", void 0); __decorate([ property(cc.Node) ], UIBallSkinPreview.prototype, "btn_use", void 0); __decorate([ property(cc.Node) ], UIBallSkinPreview.prototype, "btn_useing", void 0); UIBallSkinPreview = __decorate([ ccclass ], UIBallSkinPreview); return UIBallSkinPreview; }(UIBase_1.UIBase)); exports.default = UIBallSkinPreview; cc._RF.pop();