local UICurrencyPanel = UIViewClass() local EventSystem = require('Event/EventSystem') local SpecialActivityItemId = { --用来在点击+号的时候直接跳转到直购礼包界面 2003, --金将抽卡道具 2051, --彩金抽卡道具 } local TimeInerval = 5 local defaultCurrentInfo = {MDL.Currency.CurrencyType.SilverCoin, MDL.Currency.CurrencyType.GoldIngot, MDL.Currency.CurrencyType.Energy} local maxCurrentInfoCount = 4 local ItemIconPath = ConstAssetPathConfig.ItemIconPath function UICurrencyPanel:OnOpened(context) self.param = context.param self:RegistSystemEvent(EventID.UI_Energy_Refresh, self.RefreshEnergy) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.RefreshInfo) self:RegistSystemEvent(EventID.UI_Shop_Refresh_Currency, self.RefreshCurrency) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshInfo) self:RegistSystemEvent(EventID.UI_GoldenHero_RefreshCurrency, self.RefreshInfo) self:RegistSystemEvent(EventID.UI_Guild_SelfInfoRefresh, self.RefreshGuildCurrency) self:RegistSystemEvent(EventID.UI_ChangAnSiege_RefreshCurrency, self.RefreshInfo) self:RegistSystemEvent(EventID.UI_ExpelMonster_RefreshCurrency, self.RefreshInfo) self:RegistSystemEvent(EventID.UI_SlgGvE_Material_Update_Info, self.RefreshSlgGvECurrency) self.energy_Info.gameObject:SetActive(false) self.energy_Close.gameObject:SetActive(false) self:RefreshEnergy() ---按顺序传入需要显示的货币参数,体力会单独处理。不传默认为银币|元宝|体力 self:RefreshInfo(context.currencyTypeIds) self.belongViewClass = context.viewClassPath end function UICurrencyPanel:RefreshGuildCurrency() if self.currentInfo and table.containValue(self.currentInfo, MDL.Currency.CurrencyType.GuildWuZi) then self:RefreshInfo() end end function UICurrencyPanel:RefreshSlgGvECurrency() if self.currentInfo then for i, v in ipairs(CTL.SlgGvE.MaterialsItemId) do if table.containValue(self.currentInfo, v) then self:RefreshInfo() break end end end end function UICurrencyPanel:RefreshInfo(context) if not self.currentInfo or context then --说明是第一次打开页面需要赋值,或者是需要变更显示的信息 self.currentInfo = context or defaultCurrentInfo end self.group_Energy.gameObject:SetActive(false) for i, v in ipairs(self.group_Currency) do UIUtils.SetActive(v.gameObject, false) end local currencyIndex = 0 for i = 1, maxCurrentInfoCount do local curInfo = self.currentInfo[i] if not curInfo then break end if curInfo == MDL.Currency.CurrencyType.Energy then self.group_Energy.gameObject:SetActive(true) else currencyIndex = currencyIndex + 1 self:RefreshCellInfoByType(curInfo, currencyIndex) end end end function UICurrencyPanel:RefreshCellInfoByType(itemID, index) if index > #self.group_Currency then return end local cell = self.group_Currency[index] local itemData = DataSheetManager.ItemData:GetDataByID(itemID) UIUtils.SetActive(cell.gameObject, true) UTL.Item.SetCurrencyImageIcon(cell.icon_Currency, itemID) local itemCount = UTL.Item.GetItemStockCount(itemID) UIUtils.SetLabel(cell.txt_Currency, tostring(itemCount)) UIUtils.SetActive(cell.add_Currency, itemData.MoneyGetSign) if MDL.Currency.IsGoldHeroCurrencyTypeByItemID(itemID) then local isInFuncTime = MDL.GoldenHeroMain.IsActivityInFuncTime(self.param.activityId) local maxValue = MDL.GoldenHeroMain.GetGoldHeroEnergyMaxCount(itemID) UIUtils.SetActive(cell.add_Currency, isInFuncTime) UIUtils.SetLabel(cell.txt_Currency, tostring(itemCount .. "/" .. maxValue)) elseif MDL.Currency.IsSuperGoldCurrencyTypeByItemID(itemID) then local isInFuncTime = MDL.SuperGoldMain.IsActivityInFuncTime(self.param.activityId) local heroType = MDL.SuperGoldMain.GetHeroTypeByActivityId(self.param.activityId) local bossData = DataSheetManager.SuperGoldBossData:GetDataByHeroType(heroType) local maxValue = bossData.BossMaxEnergy UIUtils.SetActive(cell.add_Currency, isInFuncTime) UIUtils.SetLabel(cell.txt_Currency, tostring(itemCount .. "/" .. maxValue)) end end function UICurrencyPanel:RefreshEnergy() self.txt_Energy.text = MDL.Player.GetEnergyValue() .. "/" .. DataSheetManager.ConstData:GetDataByID("MaxEnergy").IntValue if MDL.Player.GetEnergyValue() >= DataSheetManager.ConstData:GetDataByID("MaxEnergy").IntValue then self.txt_Next:EndTimer() self.txt_Time:EndTimer() self.energy_State:SetState(0) else self.notFull = true self.energy_State:SetState(1) --local value = MDL.Player.GetEnergyInfo().energyRestoreTime + DataSheetManager.ConstData:GetDataByID("RestoreEnergyTime").IntValue self.txt_Next:ResetAndBeginTimer(false, MDL.Player.GetNextEnergyTime()) local maxValue = (DataSheetManager.ConstData:GetDataByID("MaxEnergy").IntValue - MDL.Player.GetEnergyValue() - 1) * DataSheetManager.ConstData:GetDataByID("RestoreEnergyTime").IntValue self.txt_Time:ResetAndBeginTimer(false, MDL.Player.GetNextEnergyTime() + maxValue) end end function UICurrencyPanel:ShowEnergyInfo() if self.isShowEnery then self.energy_Info.gameObject:SetActive(false) self.isShowEnery = false self:StopRepeatFunc(self.OnUpdateFun) self.energy_Close.gameObject:SetActive(false) else self.isShowEnery = true self.energy_Info.gameObject:SetActive(true) self.energy_Close.gameObject:SetActive(true) self:RefreshEnergy() self:StartRepeatFunc(self.OnUpdateFun, 0) end end function UICurrencyPanel:OnUpdateFun(deltaTime, timeSinceUpdate) if self.timeValue == nil then self.timeValue = 0 end self.timeValue = self.timeValue + deltaTime if self.txt_Next:IsTimerEnding() and self.notFull then CTL.Player.AddEnergy(MDL.Player.GetEnergyValue()) end if self.timeValue >= TimeInerval then self.energy_Info.gameObject:SetActive(false) self:StopRepeatFunc(self.OnUpdateFun) self.isShowEnery = false self.energy_Close.gameObject:SetActive(false) self.timeValue = 0 end end function UICurrencyPanel:OnButtonClicked(comp) if comp == self.energy_Bg then self:ShowEnergyInfo() elseif comp == self.energy_Close then if self.isShowEnery then self:ShowEnergyInfo() end elseif comp == self.add_Energy then UTL.ItemTips.OpenAboutEnergyPillView() elseif comp == self.btn_Energy then UTL.ItemTips.ShowCommonTipsById(MDL.Currency.CurrencyType.Energy) else local currencyIndex = 1 local currencyLen = #self.currentInfo > maxCurrentInfoCount and maxCurrentInfoCount or #self.currentInfo for i, v in ipairs(self.group_Currency) do if currencyIndex > currencyLen then break end local currentID = self.currentInfo[currencyIndex] -- 跳过体力值属性 if currentID == MDL.Currency.CurrencyType.Energy then currencyIndex = currencyIndex + 1 currentID = self.currentInfo[currencyIndex] end if comp == v.btn_Currency then UTL.ItemTips.ShowCommonTipsById(currentID) return elseif comp == v.add_Currency then if CTL.DrawStraws.IsConsumeItem(currentID) then CTL.DrawStraws.HUDJumpFunction() elseif currentID == MDL.Currency.CurrencyType.GoldIngot then UIManager.OpenView(Const_UI_Lua.UIEnum.UICurrencyExchange) elseif currentID == MDL.Currency.CurrencyType.DragonJade then CTL.ItemSources.ExecuteSourceFunctionById(MDL.ItemSources.SourceType.Recharge) elseif MDL.Currency.IsGoldHeroCurrencyTypeByItemID(currentID) then if not CTL.GoldenHeroMain.OpenEnergyBuyViewByAttack(self.param.activityId, self.param.energyType, currentID) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_WorldBoss_NoBuyTimes) end elseif MDL.Currency.IsSuperGoldCurrencyTypeByItemID(currentID) then if not MDL.SuperGoldBoss.OpenEnergyBuyView(self.param.activityId, currentID) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_WorldBoss_NoBuyTimes) end elseif self.param and CTL.Monopoly.IsDice(self.param.activityId, currentID) then --先判断是否需要显示活动道具获取界面 local activityType = MDL.OperationActivity.ActivityType.Monopoly if CTL.OperationActivity.IsNeedOpenGetActivityItemPanel(currentID, activityType, self.param.activityId) then CTL.OperationActivity.OpenGetActivityItemPanel(currentID, self.param.activityId, activityType) else CTL.PayMall.OpenPayMallPopUp(CTL.Monopoly.GetDiceStoreData()) end elseif self.param and CTL.Turntable.IsDrawItem(self.param.activityId, currentID) then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.OperationActivity.UIOACommonDirectGiftPanel, {activityType = self.param.activityType, activityId = self.param.activityId}) elseif self.param and CTL.HorseRear.IsFeedItem(self.param.activityId, currentID) then --先判断是否需要显示活动道具获取界面 if self.param and CTL.OperationActivity.IsNeedOpenGetActivityItemPanel(currentID, self.param.activityType, self.param.activityId) then CTL.OperationActivity.OpenGetActivityItemPanel(currentID, self.param.activityId, self.param.activityType) else CTL.HorseRear.OpenFeedItemPayPopView(self.param.activityId) end elseif self.param and CTL.GodBeastActivity.IsFeedItem(self.param.activityId, currentID) then --先判断是否需要显示活动道具获取界面 if CTL.OperationActivity.IsNeedOpenGetActivityItemPanel(currentID, self.param.activityType, self.param.activityId) then CTL.OperationActivity.OpenGetActivityItemPanel(currentID, self.param.activityId, self.param.activityType) else CTL.GodBeastActivity.OpenFeedItemPayPopView(self.param.activityId) end elseif table.containValue(SpecialActivityItemId, currentID) then if self.param.activityType == MDL.OperationActivity.ActivityType.GoldHeroReprint then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGoldHeroReprintRecharge, {activityType = self.param.activityType, activityId = self.param.activityId}) else UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.OperationActivity.UIOACommonDirectGiftPanel, {activityType = self.param.activityType, activityId = self.param.activityId}) end elseif currentID == MDL.Currency.CurrencyType.GuildCapital then UIManager.OpenView(Const_UI_Lua.UIEnum.UIGuildContribute) else for _, v in MDL.OperationActivity.StoreGoodsData:GetEnumerator() do if v.ItemID == currentID then UTL.ItemTips.OpenQuickPurchaseView(v.ID) break end end end end currencyIndex = currencyIndex + 1 end end end function UICurrencyPanel:RefreshCurrency(newCurrencyInfo, viewClass, paramContext) if viewClass and self.belongViewClass ~= viewClass then return end if paramContext then self.param = paramContext end if newCurrencyInfo and #newCurrencyInfo > 0 then self:RefreshInfo(newCurrencyInfo) end end return UICurrencyPanel