local UIGoldenHeroStoreExchange = UIViewClass() local ChangeItemCountSpeed = 0.3 local MaxItemBuyCount = 99 ---被UIGoldenHeroEnergyBuy和UISuperGoldEnergyBuy继承,修改时请注意!!! function UIGoldenHeroStoreExchange:OnOpened(context) self.activityType = MDL.OperationActivity.ActivityType.GoldenHero self:InitView(context) self:RegistTriggerEvent(self.btn_Plus, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.btn_Plus, UIEventTriggerType.PointerUp) self:RegistTriggerEvent(self.btn_Minus, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.btn_Minus, UIEventTriggerType.PointerUp) self:RegistSystemEvent(EventID.UI_OperationActivity_DataChanged, self.OnDataChanged) self:RegistSystemEvent(EventID.UI_OperationActivity_CloseView, self.OnCloseActivitySelf) self.pressPlus=false self.pressMinus=false self:RefreshBuyCount() end function UIGoldenHeroStoreExchange:OnDataChanged() self:OnButtonClicked(self.btn_Cancel) end function UIGoldenHeroStoreExchange:InitView(context) self.activityId = context.activityId UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS[context.title]) local data = context.itemStoreData local goodData = data.OriData self.itemStoreId = goodData.ID self.currencyCount = goodData.BuyPrice local limitedCount = MDL.PayMall.GetLimitedCount(goodData) local leftCount = 0 if limitedCount == 0 then leftCount = DataSheetManager.ConstData:GetDataByID("SigleBuyMax").IntValue else leftCount = limitedCount - MDL.PayMall.GetPurchaseItemCount(goodData) end self.maxCount = math.min(math.min(leftCount, math.floor(MDL.Currency.GetMoneyCount(goodData.MoneyID) / self.currencyCount)), MaxItemBuyCount) self.buyCount = 1 self:InitBuyItem(goodData) if GameAppInfo.IsJapanesePackage() and self.txt_Time then --该节点在日服专属的prefab下 UIGoldenHeroStoreExchange_JP,代码完全一致,多了个节点显示时间 self.txt_Time.text = UIUtils.GetLocalizedTxt(Const_IDS.IDS_JP_MoneyConsumption_Period) .. MDL.OperationActivity.GetTimePeriodDesc(self.activityType, self.activityId) end end function UIGoldenHeroStoreExchange:InitBuyItem(goodData) UIUtils.SetLabel(self.txt_Name, UTL.Item.GetItemDataSpliceByType(goodData.ItemID).Name) self.txt_Cost.text = goodData.BuyPrice UTL.Item.MoneyIcon(self.icon_Cost, goodData.MoneyID) UTL.Item.SetItemCell(self.item, goodData.ItemID, goodData.ItemNum) local canBuy = not CTL.PayMall.IsSoldOut(goodData) UIUtils.SetActive(self.group_SellOut, not canBuy) local isLimit, limitStr = CTL.PayMall.IsLimitedGood(goodData) UIUtils.SetActive(self.group_Limit, isLimit and canBuy) if isLimit and canBuy then if goodData.LimitBuyType == LuaConst.LimitBuyType.Forever then UIUtils.SetLabelText(self.lab_Limit, Const_IDS.IDS_GoldHeroActivity_Store_LimitBuyHint) else UIUtils.SetLabel(self.lab_Limit, CTL.PayMall.GetLimitedTitle(goodData)) end UIUtils.SetLabel(self.txt_LimitNum, limitStr) end end function UIGoldenHeroStoreExchange:OnBackButtonPressed() self:OnButtonClicked(self.btn_Cancel) end function UIGoldenHeroStoreExchange:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close or comp == self.btn_Cancel then self:CloseView() elseif comp == self.btn_Exchange then self:OnClickBuy() elseif comp == self.btn_Max then self:OnClickMax() elseif comp == self.event_Count then if not self.keyBoardView then self.keyBoardView = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIKeypad), {parentView = self, x = 45, y = 245, minNum = 1, maxNum = self.maxCount}, nil, nil); end end end function UIGoldenHeroStoreExchange:ExcuteKeyBoardBack(count, param) self.buyCount = count self:RefreshBuyCount() end function UIGoldenHeroStoreExchange:CloseKeyBoardView() self.keyBoardView:CloseView() self.keyBoardView = nil end function UIGoldenHeroStoreExchange:OnClickBuy() self.buyCount = tonumber(self.txt_Num.text) MDL.Purchase.PurchaseItemsReq(self.itemStoreId, self.buyCount, self.activityId, self.activityType) self:CloseView() end function UIGoldenHeroStoreExchange:OnPointerDown(comp, eventData) if comp == self.btn_Plus then self:OnClickPlus() self:OnPressPlus() elseif comp == self.btn_Minus then self:OnClickMinus() self:OnPressMinus() end end function UIGoldenHeroStoreExchange:OnPointerUp(comp, eventData) if comp == self.btn_Plus then self:OnPressPlusStop() elseif comp == self.btn_Minus then self:OnPressMinusStop() end end function UIGoldenHeroStoreExchange:RefreshBuyCount() if self.buyCount > self.maxCount then self.buyCount = self.maxCount self.pressPlus = false self:StopRepeatFunc(self.OnUpdateFun) end if self.buyCount < 1 then self.buyCount = 1 self.pressMinus = false self:StopRepeatFunc(self.OnUpdateFun) end self.txt_Num.text = self.buyCount local sum = self.buyCount * self.currencyCount UIUtils.SetLabel(self.txt_Cost, sum) end function UIGoldenHeroStoreExchange:OnClickPlus() self.buyCount = self.buyCount + 1 if self.buyCount > self.maxCount then self.buyCount = self.maxCount end self:RefreshBuyCount() end function UIGoldenHeroStoreExchange:OnClickMinus() self.buyCount = self.buyCount - 1 if self.buyCount < 1 then self.buyCount = 1 end self:RefreshBuyCount() end --检测按钮按住 function UIGoldenHeroStoreExchange:OnUpdateFun(deltaTime, timeSineUpdate) if self.pressPlus then self:PlusItemCount() end if self.pressMinus then self:MinusItemCount() end end function UIGoldenHeroStoreExchange:OnClickMax() self.buyCount = self.maxCount self:RefreshBuyCount() end function UIGoldenHeroStoreExchange:OnPressPlus() self.pressPlus = true self:StartRepeatFunc(self.OnUpdateFun, ChangeItemCountSpeed) end function UIGoldenHeroStoreExchange:PlusItemCount() self.buyCount = self.buyCount + 1 self:RefreshBuyCount() end function UIGoldenHeroStoreExchange:OnPressPlusStop() self.pressPlus = false self:StopRepeatFunc(self.OnUpdateFun) end function UIGoldenHeroStoreExchange:OnPressMinus() self.pressMinus = true self:StartRepeatFunc(self.OnUpdateFun, ChangeItemCountSpeed) end function UIGoldenHeroStoreExchange:MinusItemCount() self.buyCount = self.buyCount - 1 self:RefreshBuyCount() end function UIGoldenHeroStoreExchange:OnPressMinusStop() self.pressMinus = false self:StopRepeatFunc(self.OnUpdateFun) end function UIGoldenHeroStoreExchange:OnCloseActivitySelf(viewClassPath, activityId) if viewClassPath == self.__viewClassPath then if self.activityId and activityId == self.activityId then self:CloseView() end end end return UIGoldenHeroStoreExchange