local UIGoldenHeroStoreExchange = require "View/GoldenHero/GoldenHeroStore/UIGoldenHeroStoreExchange" local UIGoldenHeroEnergyBuy = UIViewClass(UIGoldenHeroStoreExchange) function UIGoldenHeroEnergyBuy:InitView(context) self.activityId = context.param.activityId self.activityType = MDL.OperationActivity.ActivityType.GoldenHero UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_DrawCard_Title_QuickBuy) self.itemId = context.itemId self.energyType = context.param.energyType self.energyBuyCount = MDL.GoldenHeroMain.GetGoldHeroEnergyBuyCount(self.activityId, self.energyType) self.maxCanBuyCount = DataSheetManager.GoldHeroEnergyGetBuy:GetDataLengthByType_ID(self.energyType) self.leftCount = self.maxCanBuyCount - self.energyBuyCount if self.leftCount > 0 then self.energyBuyData = DataSheetManager.GoldHeroEnergyGetBuy:GetDataByType_ID(self.energyType, self.energyBuyCount + 1) else self.energyBuyData = DataSheetManager.GoldHeroEnergyGetBuy:GetDataByType_ID(self.energyType, self.maxCanBuyCount) end self.currencyCount = self.energyBuyData.CurrencyNum self.currencyId = self.energyBuyData.CurrencyID local hasCurrency = MDL.Currency.GetMoneyCount(self.currencyId) self.maxBuyCount = 0 for i, v in DataSheetManager.GoldHeroEnergyGetBuy:GetDataByType_ID(self.energyType) do if v.ID > self.energyBuyCount then hasCurrency = hasCurrency - v.CurrencyNum if hasCurrency < 0 then break end self.maxBuyCount = self.maxBuyCount + 1 end end self.buyCount = 1 self.maxCount = math.min(self.maxBuyCount, self.leftCount) self:InitBuyItem() 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 UIGoldenHeroEnergyBuy:InitBuyItem() UIUtils.SetLabel(self.txt_Name, UTL.Item.GetItemDataSpliceByType(self.itemId).Name) --self.txt_Cost.text = goodData.BuyPrice UTL.Item.MoneyIcon(self.icon_Cost, self.currencyId) UTL.Item.SetItemCell(self.item, self.itemId, self.energyBuyData.Energy) local canBuy = self.leftCount > 0 UIUtils.SetActive(self.group_Limit, canBuy) UIUtils.SetLabelText(self.lab_Limit, Const_IDS.IDS_GoldHeroActivity_Store_LimitBuyHint) if canBuy then self.txt_LimitNum.text = self.leftCount .. "/" .. self.maxCanBuyCount else self.txt_LimitNum.text = UTL.Color.FormatRedColor(self.leftCount .. "/" .. self.maxCanBuyCount) end end function UIGoldenHeroEnergyBuy:OnClickBuy() if self.isEnough then self.buyCount = tonumber(self.txt_Num.text) MDL.GoldenHeroMain.GoldHeroEnergyBuyReq(self.activityId, self.energyType, self.buyCount) self:CloseView() else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Store_CoinExchange_NotEnough) CTL.Sound.PlayGameSound("UI_invalid") end end function UIGoldenHeroEnergyBuy: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 = 0 local count = 0 for i, v in DataSheetManager.GoldHeroEnergyGetBuy:GetDataByType_ID(self.energyType) do if v.ID > self.energyBuyCount then sum = sum + v.CurrencyNum count = count + 1 if count >= self.buyCount then break end end end self.isEnough = MDL.Currency.IsMoneyEnough(self.currencyId, sum) if not self.isEnough then sum = UTL.Color.FormatRedColor(sum) end UIUtils.SetLabel(self.txt_Cost, sum) end return UIGoldenHeroEnergyBuy