local UISyncFourCountryWarMain = UIViewClass() local SyncFourCountryDailyCurrencyNumMax = DataSheetManager.ConstData:GetDataByID("SyncFourCountryDailyCurrencyNumMax").IntValue local SyncFourCountryStandardPersonalPoint = DataSheetManager.ConstData:GetDataByID("SyncFourCountryStandardPersonalPoint").IntValue function UISyncFourCountryWarMain:OnOpened(context) for i = 1, 4 do local countryData = DataSheetManager.CountryBase:GetDataByID(i) UIUtils.SetLocalizationImage(self.group_Country[i].img_CountryName, countryData.UnSelectImage) UIUtils.SetLocalizationImage(self.group_Country[i].select_Img, countryData.NamePath) end UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_SyncFourCountry_Title) self:RegistSystemEvent(EventID.UI_FourCountryWar_MainPanel, self.InitInfo) self:RegistSystemEvent(EventID.UI_TeamMatch_MatchTime, self.OnMatchExpression) self:RegistSystemEvent(EventID.UI_FourCountryWar_StageChange, self.OnStageChange) self:RegistSystemEvent(EventID.UI_CloseAndRecoverView, self.OnCloseAndRecoverView) MDL.SyncFourCountryWar.GetSyncFourCountryMainPanelReq() if CTL.Activities.IsOpeningTime(LuaConst.ActivityType.SyncFourCountryWar) then self.btn_Match:SetGray(false, true) self:UpdateTimer(CTL.TeamMatch.IsActivityMatchingById(LuaConst.ActivityType.SyncFourCountryWar)) else self.btn_Match:SetGray(true, true) self:RefreshOpenState() end self.btn_Match:SetText(CTL.TeamMatch.IsActivityMatchingById(LuaConst.ActivityType.SyncFourCountryWar) and UIUtils.GetLocalizedTxt(Const_IDS.IDS_UI_Word20) or UIUtils.GetLocalizedTxt(Const_IDS.IDS_Team_3v3_StartMatch)) UTL.UIRender.AdaptiveImageSizeFit(self.Bottom, true) CTL.SyncFourCountryWar.RemoveRedPoint() self.txt_Info.text = string.FormatByIdsId(Const_IDS.IDS_SyncFourCountry_StandardPersonalPoint, SyncFourCountryStandardPersonalPoint) end function UISyncFourCountryWarMain:OnMatchExpression(state) if CTL.TeamMatch.IsActivityMatchingById(LuaConst.ActivityType.SyncFourCountryWar) then self.btn_Match:SetText(Const_IDS.IDS_UI_Word20) self:UpdateTimer(state) else self:UpdateTimer(false) end end function UISyncFourCountryWarMain:OnStageChange() MDL.SyncFourCountryWar.GetSyncFourCountryMainPanelReq() end function UISyncFourCountryWarMain:UpdateTimer(state) if state then local maxTime = MDL.TeamDungeon.GetMaxMatchTime() local durTime = UTL.Time.GetServerTimestamp() - MDL.TeamMatch.GetStartMatchingTime() self.cdTimer:SetAndContinueTimer(true, durTime, maxTime) self.btn_Match:SetText(Const_IDS.IDS_UI_Word20) self.effect_Matching:PlayUIEffect() else self.cdTimer:EndTimer() self.btn_Match:SetText(Const_IDS.IDS_Team_3v3_StartMatch) self.effect_Matching:StopUIEffect() end end function UISyncFourCountryWarMain:InitInfo(data) self.txt_Honor.text = data.myScore self.txt_Rank.text = MDL.SyncFourCountryWar.GetRankText(data.myRank, data.myScore) if data.myScore <= 0 then self.myRank = 0 else self.myRank = data.myRank end if SyncFourCountryDailyCurrencyNumMax <= data.todayGetReward then self.txt_DailyRewards.text = UTL.Color.FormatRedColor(data.todayGetReward) .. "/" .. SyncFourCountryDailyCurrencyNumMax else self.txt_DailyRewards.text = UTL.Color.FormatGreenColor(data.todayGetReward) .. "/" .. SyncFourCountryDailyCurrencyNumMax end self.countryHeroList = data.freeHero self:OnButtonClicked(self.group_Country[1].btn) local activityData = DataSheetManager.ActivityData:GetDataByID(LuaConst.ActivityType.SyncFourCountryWar) local startTime = MDL.SyncFourCountryWar.GetStageTime()[2] local endTime = MDL.SyncFourCountryWar.GetStageTime()[3] - CTL.SyncFourCountryWar.GetEndTimeOffset(activityData) self.txt_OpenTime.text = os.date(UTL.Time.FormatDateEnum.YMD, startTime) .. " - " .. os.date(UTL.Time.FormatDateEnum.YMD, endTime) local desc, time = UTL.Time.GetDateDescAndTime(activityData.Time_Table) self.txt_CloseTime.text = desc .. " " .. time if MDL.SyncFourCountryWar.IsForecast() then self.state_Type:SetState(2) local dayStr = string.FormatByIdsId(Const_IDS.IDS_7DayActivityNew_Hint1, UIUtils.GetLocalizedTxt(Const_IDS.IDS_PreviewTime1)) local hourStr = string.FormatByIdsId(Const_IDS.IDS_7DayActivityNew_Hint1, UIUtils.GetLocalizedTxt(Const_IDS.IDS_PreviewTime2)) local minStr = string.FormatByIdsId(Const_IDS.IDS_7DayActivityNew_Hint1, UIUtils.GetLocalizedTxt(Const_IDS.IDS_PreviewTime3)) local secStr = string.FormatByIdsId(Const_IDS.IDS_7DayActivityNew_Hint1, UIUtils.GetLocalizedTxt(Const_IDS.IDS_PreviewTime4)) self.txt_Begin:SetDHMSStr(dayStr, hourStr, minStr, secStr) local offset = MDL.SyncFourCountryWar.GetStageTime()[2] - UTL.Time.GetServerTimestamp() self.txt_Begin:ResetAndBeginCustomTimer(false, offset, 0, 1) elseif MDL.SyncFourCountryWar.IsBattle() then self.state_Type:SetState(0) else self.state_Type:SetState(1) end end function UISyncFourCountryWarMain:RefreshOpenState() local activityData = DataSheetManager.ActivityData:GetDataByID(LuaConst.ActivityType.SyncFourCountryWar) local startdata = DataSheetManager.TimeRefresh:GetDataByID(activityData.Time_Table[1].StartTime) local startTime = UTL.Time.GetServerZeroTimestampByTimestamp(UTL.Time.GetServerTimestamp()) + startdata.HMS if startTime > UTL.Time.GetServerTimestamp() then self:StartRepeatFunc(self.ActiveBtnState, startTime - UTL.Time.GetServerTimestamp() + 1, 1) end end function UISyncFourCountryWarMain:ActiveBtnState() if CTL.Activities.IsOpeningTime(LuaConst.ActivityType.SyncFourCountryWar) then self.btn_Match:SetGray(false, true) end end function UISyncFourCountryWarMain:ClickCountryBtn(countryId) self.Loop_4CWFreeHero:ReloadAll(self.countryHeroList[countryId].FreeHeroIds) end --开始匹配\取消匹配 function UISyncFourCountryWarMain:OnClickBeginMatch() local state = CTL.TeamMatch.GetMatchOperationStateByActivityId(LuaConst.ActivityType.SyncFourCountryWar) if state ~= false then if state == CTL.TeamMatch.MatchOperationState.CancelMatch then CTL.TeamMatch.OnPressMatchButton(LuaConst.ActivityType.SyncFourCountryWar, MDL.TeamMatch.PlayerMatchOperateReq) CTL.Sound.PlayGameSound("UI_invalid") return end if CTL.Activities.IsOpeningTime(LuaConst.ActivityType.SyncFourCountryWar) then CTL.TeamMatch.OnPressMatchButton(LuaConst.ActivityType.SyncFourCountryWar, MDL.TeamMatch.PlayerMatchOperateReq) CTL.Sound.PlayGameSound("UI_click_01") else CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairPlay_3v3NotOpen"]) CTL.Sound.PlayGameSound("UI_invalid") end end end function UISyncFourCountryWarMain:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UISyncFourCountryWarMain:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UISyncFourCountryNote) elseif comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.btn_Match then self:OnClickBeginMatch() elseif comp == self.btn_Team then CTL.Team.OpenTeamPanel(LuaConst.ActivityType.SyncFourCountryWar) elseif comp == self.btn_Reward then UIManager.OpenView(Const_UI_Lua.UIEnum.UISyncFourCountryWarReward, { myRank = self.myRank }) elseif comp == self.btn_Shop then --店铺 UIManager.OpenView(Const_UI_Lua.UIEnum.UISyncFourCountryWarStore, nil, Const_UI_Lua.UIEnum.UIFairSoloTournamentStore) elseif comp == self.btn_Rank then UIManager.OpenView(Const_UI_Lua.UIEnum.UISyncFourCountryWarRank) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() else for i, v in ipairs(self.group_Country) do if v.btn == comp then UIUtils.SetActive(v.img_Select, true) self:ClickCountryBtn(i) else UIUtils.SetActive(v.img_Select, false) end end end end function UISyncFourCountryWarMain:OnCellInit(scrollRect, index, cellTable, data) UTL.Item.SetItemCell(cellTable.item_Hero, data) end function UISyncFourCountryWarMain:OnCellClicked(scrollRect, index, cellTable, target, data) UTL.ItemTips.ShowCommonTipsById(data) end return UISyncFourCountryWarMain