require("Base/BasePanel") NewShenZunExpExchangePopup = Inherit(BasePanel) local this=NewShenZunExpExchangePopup local storeConfig=ConfigManager.GetConfigData(ConfigName.StoreConfig,1001) local _isClickedReduce = false local _isClickedAdd = false local maxExchangeNum=0 function this:InitComponent() this.spLoader = SpriteLoader.New() this.backBtn=Util.GetGameObject(self.gameObject, "backBtn") this.exchangeItem=Util.GetGameObject(self.gameObject, "layout/exchangeItem") this.reduceBtn=Util.GetGameObject(self.gameObject, "layout/changeNum/reduceBtn") this.addBtn=Util.GetGameObject(self.gameObject, "layout/changeNum/addBtn") this.changeNumText=Util.GetGameObject(self.gameObject, "layout/changeNum/num/Text"):GetComponent("Text") this.costIcon=Util.GetGameObject(self.gameObject, "layout/cost/icon"):GetComponent("Image") this.costNum=Util.GetGameObject(self.gameObject, "layout/cost/num"):GetComponent("Text") this.exchangeBtn=Util.GetGameObject(self.gameObject, "layout/exchangeBtn") this.exchangeItemView=SubUIManager.Open(SubUIConfig.ItemView, this.exchangeItem.transform) this.reduceTrigger = Util.GetEventTriggerListener(this.reduceBtn) this.addTrigger = Util.GetEventTriggerListener(this.addBtn) this.maxBtn = Util.GetGameObject(self.gameObject, "maxBtn") end function this:BindEvent() Util.AddClick(this.backBtn,function () self:ClosePanel() end) Util.AddClick(this.exchangeBtn,function () local costId, discostnum, costnum = ShopManager.calculateBuyCost(storeConfig.StoreId, storeConfig.Id, this.exchangeNum) local haveNum=BagManager.GetItemCountById(costId) if haveNum>=discostnum then ShopManager.RequestBuyItemByShopId(storeConfig.StoreId, storeConfig.Id, this.exchangeNum, function(msg) Game.GlobalEvent:DispatchEvent(GameEvent.Activity.UpdateShenzunLv) self:ClosePanel() end) else PopupTipPanel.ShowTip("道具不足") end end) Util.AddClick(this.maxBtn,function () local costId, discostnum, onecostnum = ShopManager.calculateBuyCost(storeConfig.StoreId, storeConfig.Id, 1) local haveNum=BagManager.GetItemCountById(costId) local maxCostNum=maxExchangeNum*onecostnum local costNum=maxCostNum>haveNum and haveNum or maxCostNum this.exchangeNum=math.floor(costNum/onecostnum) if this.exchangeNum>999 then this.exchangeNum=999 end this.changeNumText.text=this.exchangeNum this.costNum.text=this.exchangeNum*onecostnum end) Util.AddClick(this.reduceBtn,function () local exNum=this.exchangeNum-1 if exNum>0 then local costId, discostnum, costnum = ShopManager.calculateBuyCost(storeConfig.StoreId, storeConfig.Id, exNum) this.exchangeNum=exNum this.changeNumText.text=this.exchangeNum this.costNum.text=discostnum end end) Util.AddClick(this.addBtn,function () local exNum=this.exchangeNum+1 if exNum>maxExchangeNum or exNum>999 then PopupTipPanel.ShowTip("已达上限") return end local costId, discostnum, costnum = ShopManager.calculateBuyCost(storeConfig.StoreId, storeConfig.Id, exNum) local haveNum=BagManager.GetItemCountById(costId) if haveNum>=discostnum then this.exchangeNum=exNum this.changeNumText.text=this.exchangeNum this.costNum.text=discostnum end end) --减号长按按下状态 this._onPointerDownReduce = function(Pointgo, data) LogRed("减号长按按下状态") _isClickedReduce = true this.timePressStarted = Time.realtimeSinceStartup end --减号长按抬起状态 this._onPointerUpReduce = function(Pointgo, data) LogRed("减号长按抬起状态") _isClickedReduce = false end --加号长按按下状态 this._onPointerDownAdd = function(Pointgo, data) LogRed("加号长按按下状态") _isClickedAdd = true this.timePressStarted = Time.realtimeSinceStartup end --加号长按抬起状态 this._onPointerUpAdd = function(Pointgo, data) LogRed("加号长按抬起状态") _isClickedAdd = false end this.reduceTrigger.onPointerDown = this.reduceTrigger.onPointerDown + this._onPointerDownReduce this.reduceTrigger.onPointerUp = this.reduceTrigger.onPointerUp + this._onPointerUpReduce this.addTrigger.onPointerDown = this.addTrigger.onPointerDown + this._onPointerDownAdd this.addTrigger.onPointerUp = this.addTrigger.onPointerUp + this._onPointerUpAdd end function this:OnOpen(data) FixedUpdateBeat:Add(this.OnUpdate, self)--长按方法注册 this.exchangeItemView:OnOpen(false, {storeConfig.Goods[1][1], storeConfig.Goods[1][2]}, 1.2, false) this.exchangeItemView:SetNumShow(false) this.exchangeItemView.gameObject:SetActive(true) this.exchangeNum=1 local itemDataConFig = ConfigManager.GetConfigData(ConfigName.ItemConfig, storeConfig.Cost[1][1]) this.costIcon.sprite = this.spLoader:LoadSprite(GetResourcePath(itemDataConFig.ResourceID)) local costId, discostnum, costnum = ShopManager.calculateBuyCost(storeConfig.StoreId, storeConfig.Id, this.exchangeNum) this.costNum.text=discostnum this.changeNumText.text=this.exchangeNum local curLv=GetShenzunLv() local expNum=BagManager.GetItemCountById(1352) local prestigeConfig=ConfigManager.GetConfigDataByDoubleKey(ConfigName.PrestigeConfig,"Type",1,"Level",curLv) maxExchangeNum=prestigeConfig.Experience[2]-expNum end --长按升级处理 function this.OnUpdate() if _isClickedReduce then if Time.realtimeSinceStartup - this.timePressStarted > 0.4 then local exNum=this.exchangeNum-1 if exNum>0 then local costId, discostnum, costnum = ShopManager.calculateBuyCost(storeConfig.StoreId, storeConfig.Id, exNum) this.exchangeNum=exNum this.changeNumText.text=this.exchangeNum this.costNum.text=discostnum else _isClickedReduce = false return end end end if _isClickedAdd then if Time.realtimeSinceStartup - this.timePressStarted > 0.4 then local exNum=this.exchangeNum+1 if exNum>maxExchangeNum or exNum>999 then PopupTipPanel.ShowTip("已达上限") _isClickedAdd = false return end local costId, discostnum, costnum = ShopManager.calculateBuyCost(storeConfig.StoreId, storeConfig.Id, exNum) local haveCount=BagManager.GetItemCountById(costId) if haveCount>=discostnum then this.exchangeNum=exNum this.changeNumText.text=this.exchangeNum this.costNum.text=discostnum else PopupTipPanel.ShowTip("材料不足") _isClickedAdd = false return end end end end --界面关闭时调用(用于子类重写) function this:OnClose() FixedUpdateBeat:Remove(this.OnUpdate, self) end function this:OnDestroy() this.spLoader:Destroy() end return this