local UIGVGFightCityGuardingArray = UIViewClass() --[[ 攻城略地 护城阵 context = { cityId --选中城池Id } --]] local GVGFightHelpListNum = DataSheetManager.ConstData:GetDataByID("GVGFightHelpListNum").IntValue local GVGFightProtectionStart = DataSheetManager.ConstData:GetDataByID("GVGFightProtectionStart").IntValue local GVGFightProtectionEnd = DataSheetManager.ConstData:GetDataByID("GVGFightProtectionEnd").IntValue -------------------- function UIGVGFightCityGuardingArray:OnCreated() self.costEnough = false self.costItem = 0 end function UIGVGFightCityGuardingArray:OnOpened(context) self:RegistSystemEvent(EventID.GVGFight_RefreshCityState, self.RefreshCityState) self:RegistSystemEvent(EventID.UI_Guild_SelfInfoRefresh, self.RefreshGuildFlag) self:RegistSystemEvent(EventID.GVGFight_RefreshAssistNum, self.RefreshAssistNum) self:RegistSystemEvent(EventID.GVGFight_RefreshAssistInfo, self.RefreshAssistInfo) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.RefreshHelpCost) self:RegistSystemEvent(EventID.GVGFight_RefreshGVGFightState, self.RefreshGVGState) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.GVGFightAssist, self.RefreshAssistRp) self.cityCfgData = DataSheetManager.GVGFightCity:GetDataByCityID(context.cityId) self:InitPanel() -- 请求助力相关信息 MDL.GVGFight.GVGAssistInfoReq() end function UIGVGFightCityGuardingArray:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIGVGFightCityGuardingArray:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView(false) elseif comp == self.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.GVGFightGuardingArray, params = {UTL.Time.GetDiffLocalStrById(GVGFightProtectionStart), UTL.Time.GetDiffLocalStrById(GVGFightProtectionEnd)}}) elseif comp == self.btn_Assistance then if self.costEnough then MDL.GVGFight.GVGAssistReq() else local itemData = DataSheetManager.ItemData:GetDataByID(self.costItem) local name = UIUtils.GetLocalizedTxt(Const_IDS[itemData.Name]) CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_GVGFight_Protection_Tips1, name)) end elseif comp == self.btn_Open then MDL.GVGFight.GVGCityGuardingArrayOpenReq(self.cityCfgData.CityID) end end function UIGVGFightCityGuardingArray:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.Loop_CGADonate then UIUtils.SetLabel(cellTable.txt_Time, UTL.Time.FormatTimeCompletely(data.time)) local gvgFightHelpData = DataSheetManager.GVGFightHelp:GetDataByGVGFightHelpTimes(data.id) UIUtils.SetLabel(cellTable.txt_CGADonate, string.FormatByIdsId(Const_IDS[gvgFightHelpData.HelpListIDS], data.name)) end end -------------------- function UIGVGFightCityGuardingArray:InitPanel() -- 设置标题 UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_GVGFight_Protection_Title) -- 设置城池图片 UIUtils.SetImageByAssetBundle(self.img_City, self.cityCfgData.CityImage) self.img_City:SetNativeSize() -- 初始化势力令旗 self:RefreshGuildFlag() -- 初始化助力次数 self:RefreshAssistNum() -- 初始化城池状态 self:RefreshCityState() -- 初始化助力记录 self:RefreshAssistInfo() -- 设置开启时间判断 local timeStamp = UTL.Time.GetServerTimestamp() if timeStamp > UTL.Time.GetConfigTimestampById(GVGFightProtectionStart) or timeStamp < UTL.Time.GetConfigTimestampById(GVGFightProtectionEnd) then self.btn_Open:SetGray(false, true) else self.btn_Open:SetGray(true, true) end -- 刷新红点 self:RefreshAssistRp(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.GVGFightAssist)) -- 设置提示信息 UIUtils.SetLabel(self.txt_CountDown, string.FormatByIdsId(Const_IDS.IDS_GVGFight_Protection_Tips11, UTL.Time.GetDiffLocalStrById(GVGFightProtectionStart), UTL.Time.GetDiffLocalStrById(GVGFightProtectionEnd))) end -- 刷新势力令旗 function UIGVGFightCityGuardingArray:RefreshGuildFlag() -- 刷新令旗 local guildFlagNum = MDL.GVGFight.GetGuildFlag() UIUtils.SetLabel(self.txt_GuildFlagNum, guildFlagNum) if guildFlagNum < self.cityCfgData.CityProtectionCostNum then UIUtils.SetLabel(self.txt_ConsumeFlagNum, UTL.Color.FormatRedColor(self.cityCfgData.CityProtectionCostNum)) else UIUtils.SetLabel(self.txt_ConsumeFlagNum, UTL.Color.FormatGreenColor(self.cityCfgData.CityProtectionCostNum)) end end -- 刷新助力次数 function UIGVGFightCityGuardingArray:RefreshAssistNum() -- 刷新助力次数 local assistNum = MDL.GVGFight.GetAssistNum() local _, gvgFightHelpData = DataSheetManager.GVGFightHelp:TryGetDataByGVGFightHelpTimes(assistNum + 1) -- 使用下一次助力次数显示 if gvgFightHelpData then UIUtils.SetActive(self.group_DonateFlag, true) self.btn_Assistance:SetGray(false, true) local helpCostNum = gvgFightHelpData.HelpCostNum if helpCostNum == 0 then self.costEnough = true UIUtils.SetActive(self.img_Coin, false) UIUtils.SetLabelText(self.txt_Coin, Const_IDS.IDS_GVGFight_Protection_FreeHelp) else UIUtils.SetActive(self.img_Coin, true) self:RefreshHelpCost() UTL.Item.MoneyIcon(self.img_Coin, gvgFightHelpData.HelpCostItem) end -- 增加令旗显示 UIUtils.SetLabel(self.txt_GetFlagNum, "+" .. gvgFightHelpData.HelpAcquireNum) else UIUtils.SetActive(self.group_DonateFlag, false) UIUtils.SetActive(self.img_Coin, false) self.btn_Assistance:SetGray(true) UIUtils.SetLabelText(self.txt_Coin, Const_IDS.IDS_GVGFight_Protection_Tips3) end end -- 刷新城池状态 function UIGVGFightCityGuardingArray:RefreshCityState() local cityInfo = MDL.GVGFight.GetCityOuterInfo(self.cityCfgData.CityID) -- 是否开启护城阵 if cityInfo and cityInfo.isCityGuardingArray then UIUtils.SetActive(self.effect_Shield, true) self.effect_Shield:PlayUIEffect() self.state_Btn:SetState(1) else self.effect_Shield:StopUIEffect() UIUtils.SetActive(self.effect_Shield, false) self.state_Btn:SetState(0) end end -- 刷新助力记录 function UIGVGFightCityGuardingArray:RefreshAssistInfo() UIUtils.SetLabel(self.lab_CGADonate, string.FormatByIdsId(Const_IDS.IDS_GVGFight_Protection_HelpList2, MDL.GVGFight.GetAssistInfoCount(), GVGFightHelpListNum)) MDL.GVGFight.ResetAssistInfoIterator() CSExt.CSFunc_ReloadAll(self.Loop_CGADonate, MDL.GVGFight.EnumAssistInfoIterator) end -- 刷新道具数量信息 function UIGVGFightCityGuardingArray:RefreshHelpCost() local assistNum = MDL.GVGFight.GetAssistNum() local _, gvgFightHelpData = DataSheetManager.GVGFightHelp:TryGetDataByGVGFightHelpTimes(assistNum + 1) -- 使用下一次助力次数显示 if gvgFightHelpData then local helpCostNum = gvgFightHelpData.HelpCostNum if helpCostNum == 0 then self.costEnough = true return end self.costItem = gvgFightHelpData.HelpCostItem local coinCount = UTL.Item.GetItemStockCount(gvgFightHelpData.HelpCostItem) if coinCount < helpCostNum then self.costEnough = false UIUtils.SetLabel(self.txt_Coin, UTL.Color.FormatRedColor(helpCostNum)) else self.costEnough = true UIUtils.SetLabel(self.txt_Coin, helpCostNum) end end end -- 阶段切换事件 function UIGVGFightCityGuardingArray:RefreshGVGState() local curGVGFightState = MDL.GVGFight.GetCurGVGFightState() if curGVGFightState == MDL.GVGFight.GVGFightStage.OffSeason then self:OnBackButtonPressed() end end function UIGVGFightCityGuardingArray:RefreshAssistRp(active) self.btn_Assistance:SetRedPoint(active) end return UIGVGFightCityGuardingArray