var touch,__extends=this&&this.__extends||function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(t,n)};return function(t,n){function a(){this.constructor=t}if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");e(t,n),t.prototype=null===n?Object.create(n):(a.prototype=n.prototype,new a)}}();!function(e){var t=function(t){function n(n,a){var i=t.call(this)||this;return i._main=null,i._scene=null,i._camera=null,i._ball=null,i._ballSkinTexture=null,i._light=null,i._skinIndex=0,i._selectedSkinCell=null,i._currentSkinPageIndex=0,i._skinPageCategory=[],i._pageIndicatorSkins=[],i._main=n,i._ballSkinTexture=a,i.btnClose.clickHandler=Laya.Handler.create(i,i.onClickClose,null,!1),i.btnUse.clickHandler=Laya.Handler.create(i,i.onClickUse,null,!1),i.listSkin.visible=!1,i.imgRandom.visible=!1,i.boxPageIndicator.visible=!0,i._skinPageCategory=[e.TASK_VALUE_TYPE.TOTAL_DISTANCE,e.TASK_VALUE_TYPE.TOTAL_SURPASS,e.TASK_VALUE_TYPE.NONE],i.listSkinPages.array=i._skinPageCategory,i.listSkinPages.hScrollBarSkin="",i.listSkinPages.renderHandler=Laya.Handler.create(i,i.skinListRender,null,!1),i.listSkinPages.onPageChangeHandler=i.onPageChange.bind(i),i._pageIndicatorSkins.push(i.boxPageIndicator.getChildByName("imgSelected").skin),i._pageIndicatorSkins.push(i.boxPageIndicator.getChildByName("imgUnselected").skin),i._skinIndex=e.GameData.instance.skinIndex,i._updateSelectSkinInfo(),i.tfDiamond.text=e.GameData.instance.diamond.toString(),i.btnBuy.clickHandler=Laya.Handler.create(i,i.onClickBuy,null,!1),Laya.timer.callLater(i,i.showSkin),Laya.timer.callLater(i,function(){i.scrollToSkin(i._skinIndex)}),i.adapterScreen(),Laya.stage.on(Laya.Event.RESIZE,i,i.onResize),i.skinLab.text=e.Lang.getLangText(e.Lang.skin),i}return __extends(n,t),n.prototype.onResize=function(){this.adapterScreen(),this.adjustBallPosition()},n.prototype.adjustBallPosition=function(){var e=new Laya.Vector3,t=(this.imgRandom.height,this.scaleY,this.imgRandom.localToGlobal(new Laya.Point(0,0)));this._camera.convertScreenCoordToOrthographicCoord(new Laya.Vector3(GameBaseData.screenWidth/2,t.y,0),e),this._ball.transform.position=e,this._ball.transform.scale=new Laya.Vector3(this.scaleX,this.scaleX,this.scaleX)},n.prototype.adapterScreen=function(){var e=GameBaseData.getAdapterRatio();this.scale(e,e)},n.prototype.scrollToSkin=function(t){var n=e.SkinManager.getSkinInfoById(t),a=this._skinPageCategory.indexOf(n.taskType);this.listSkinPages.scrollTo(a),this.onPageChange(a)},n.prototype._updateSelectSkinInfo=function(t){t||(t=e.SkinManager.getSkinInfoById(this._skinIndex));var n=e.TaskManager.instance.getTaskProgress(t.taskType);n&&(this.ballDes.text=e.TaskManager.getTaskDesc({type:t.taskType,value:t.taskValue}),this.ballPro.text=e.TaskManager.getTaskProgress({type:t.taskType,value:t.taskValue},n.value));var a=t.unlocked,i=e.GameData.instance.skinIndex==this._skinIndex;this.btnUse.visible=a&&!i,this.btnBuy.visible=!a,a||(this.tfCostDiamond.text=t.price.toString()),this.ballDes.visible=!a,this.imgDes.visible=!a,this.ballPro.visible=!a&&t.taskType!=e.TASK_VALUE_TYPE.NONE,this.boxSkinTask.visible=!a&&t.taskType!=e.TASK_VALUE_TYPE.NONE},n.prototype.destroy=function(){null!=this.btnClose.clickHandler&&(this.btnClose.clickHandler.recover(),this.btnClose.clickHandler=null),null!=this.btnBuy.clickHandler&&(this.btnBuy.clickHandler.recover(),this.btnBuy.clickHandler=null),null!=this.btnUse.clickHandler&&(this.btnUse.clickHandler.recover(),this.btnUse.clickHandler=null),t.prototype.destroy.call(this),Laya.stage.off(Laya.Event.RESIZE,this,this.onResize)},n.prototype.onClickClose=function(){this._main.event(e.GameEvent.CLOSE_SKIN),SdkHelper.SdkUtils.setAdflyState(1)},n.prototype.onClickUse=function(){e.GameData.instance.skinIndex=this._skinIndex,this._updateSelectSkinInfo(),this._refreshList(),this.updateSkin(),this._main.event(e.GameEvent.CHANGE_SKIN)},n.prototype._refreshList=function(){this.listSkinPages.array=this._skinPageCategory,this.listSkinPages.cells.forEach(function(e){e.getChildAt(0).refresh()})},n.prototype.onPageChange=function(e){this._currentSkinPageIndex=e,this._updatePageIndicator(e)},n.prototype._updatePageIndicator=function(e){for(var t=0;t0,t.tfVideo.visible=!1,e.GameData.instance.skinIndex==i&&(this._selectedSkinCell=t)},n.prototype.onSkinSelect=function(t){console.log("Select Ball cellIndex: ",t);var n=this._skinPageCategory[this._currentSkinPageIndex],a=e.SkinManager.getSkinsByUnlockCondition(n);console.log("Select Ball currentPage: ",a),console.assert(a&&a.length>0);var i=a[t],s=i.skin;console.log("Select Ball: ",s),this.tfDiamond.text=e.GameData.instance.diamond.toString(),this._skinIndex=s,e.GameConfig.SKIN_TYPE[s]=0,this._updateSelectSkinInfo(i),this._refreshList(),this.updateSkin()},n.prototype.showSkin=function(){this._scene=new Laya.Scene,this.addChild(this._scene);var t=new Laya.SphereMesh(.15,64,64);this._ball=new Laya.MeshSprite3D(t),this._ball.transform.position=new Laya.Vector3(.1,2.1,0);var n=new Laya.StandardMaterial;this._ball.meshRender.material=n;var a=this;this._ball.timer.loop(10,this._ball,function(){a.tfDiamond.text=e.GameData.instance.diamond.toString(),a._ball.transform.rotate(new Laya.Vector3(4,4,0),!0,!1)}),this._scene.addChild(this._ball),this._ball.transform.translate(new Laya.Vector3(0,0,0),!1),this._camera=new Laya.Camera(0,.1,1e3),this._scene.addChild(this._camera),this._camera.transform.rotate(new Laya.Vector3(-45,0,0),!1,!1),this._camera.transform.translate(new Laya.Vector3(0,.5,500)),this._camera.orthographic=!0,this._camera.orthographicVerticalSize=4,this.adjustBallPosition(),this.updateSkin()},n.prototype.updateSkin=function(){this._ball.meshRender.material.diffuseTexture=this._ballSkinTexture[this._skinIndex],this._ball.active=!0,this.imgRandom.visible=!1},n.prototype.hideSkin=function(){null!=this._ball&&(this._ball.destroy(),this._ball=null),null!=this._camera&&(this._camera.destroy(),this._camera=null),null!=this._scene&&(this._scene.destroy(),this._scene=null)},n.prototype.onClickBuy=function(){var t=e.SkinManager.getSkinInfoById(this._skinIndex).price;if(e.GameData.instance.diamond>=t){e.GameData.instance.setAddDiamond(-t),this.tfDiamond.text=e.GameData.instance.diamond.toString();var a=this._skinIndex;e.SkinManager.unlockSkin(a),e.SkinManager.save(),this._updateSelectSkinInfo(),this._main.event(e.GameEvent.SHOW_REWARD,[a]),this.onClickUse()}else SdkHelper.EventLogger.logDailyGiftPage(n.PAGE),e.Notice.show(e.Lang.getLangText(e.Lang.not_enough)),this._main.event(e.GameEvent.OPEN_GIFT)},n.PAGE="SkinShop",n}(ui.SkinDialogUI);e.SkinDialog=t}(touch||(touch={}));