local UICountryChooseView = UIViewClass() local VoteStage = { NotOpen = 1, Open = 2, Stop = 3, } function UICountryChooseView:OnOpened(context) self.countryArray = { self.panel_CountryWei, self.panel_CountryShu, self.panel_CountryWu, self.panel_CountryQun, self.panel_CountryHan } self:RegistSystemEvent(EventID.Country_RefreshSelectInfo, self.UpdateInfo) self:RegistSystemEvent(EventID.Country_OnGetJoinVoteInfo, self.UpdateVoteInfo) self:RegistSystemEvent(EventID.Country_OnDoJoinVoteInfo, self.OnDoJoinVoteInfo) MDL.Country.C2GCountrySelectInfo() UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_Country_FunctionName) UIUtils.SetActive(self.UITemplateTitlePanel.fit_Right, false) end function UICountryChooseView:OnClosed() UIUtils.SetActive(self.UITemplateTitlePanel.fit_Right, true) end function UICountryChooseView:UpdateInfo() self:ShowTimeInfo() self:ShowSovereignList() self:InitBtn() self:SetMapCountryInfo() local info = MDL.Country.GetMyGuildInfo() if info and info.country > 0 then self:OnClickMapBtn(info.country) else self:OnClickMapBtn(1) end end function UICountryChooseView:UpdateVoteInfo(data) for i = 1, MDL.Country.CountryType.Qun do local collection = self.countryArray[i] local voteData = MDL.Country.GetVoteDataByCountry(data.voteInfoList, i) if MDL.Country.IsFoundCountry(i) then elseif voteData == nil then collection.state_Vote:SetState(0) collection.txt_Votes.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_MemberVotingValue, 0) UIUtils.SetActive(collection.group_Lord, false) else collection.state_Vote:SetState(0) collection.txt_Votes.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_MemberVotingValue, voteData.voteNum) UIUtils.SetActive(collection.group_Lord, data.guildLeaderChoice[1] == i) end end end function UICountryChooseView:OnDoJoinVoteInfo(data, isLeader) local collection = self.countryArray[data.country] collection.txt_Votes.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_MemberVotingValue, data.voteNum) UIUtils.SetActive(collection.group_Lord, isLeader) end function UICountryChooseView:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Action then local curStage = MDL.Country.GetCurStage() if curStage <= MDL.Country.Stage.SignUp then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryGuildRankView) elseif curStage <= MDL.Country.Stage.SovereignChooseAfter then self:OnClickVoteBtn() else self:OnClickApplyBtn() end elseif comp == self.btn_Rank then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryGuildListPanel) elseif comp == self.UITemplateTitlePanel.btn_Info then CTL.Country.OpenCountryChooseNoteView() elseif comp == self.btn_KingRight then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryKingRightPopUp) else for i, v in ipairs(self.countryArray) do if v.map_Btn == comp then self:OnClickMapBtn(i) break elseif v.group_MainGuild.btn == comp then self:ClickOpenGuildInfoView(i, nil) break elseif v.group_SubGuild1.btn == comp then self:ClickOpenGuildInfoView(i, 1) break elseif v.group_SubGuild2.btn == comp then self:ClickOpenGuildInfoView(i, 2) break end end end end --左侧四国君主信息 function UICountryChooseView:ShowSovereignList() local curStage = MDL.Country.GetCurStage() if curStage <= MDL.Country.Stage.SignUp then UIUtils.SetActive(self.group_Country, false) else local list = MDL.Country.GetSovereignGuildList() for i = 1, MDL.Country.CountryType.Qun do self:ShowSovereign(self.ver_Country[i], list[i], i) end UIUtils.SetActive(self.group_Country, true) end end function UICountryChooseView:ShowSovereign(collection, data, index) if data then collection.txt_GuildName.text = data.guildName collection.lab_ServerName.text = CTL.CrossServer.GetServerShowStr(data.serverId) UTL.Item.SetAtlasSprite(collection.ico_GuildBg, "UI_Guild", DataSheetManager.GuildEmblem:GetDataByID(data.guildEmblemFrame).Image) collection.txt_TitleGuildName.text = data.guildEmblemContent if data.country > 0 then CTL.Country.SetCountryImage(collection, data.country) UIUtils.SetActive(collection.img_Flag, true) UIUtils.SetActive(collection.img_Empty, false) else --CTL.Country.SetCountryImage(collection, 1) UIUtils.SetActive(collection.img_Flag, false) UIUtils.SetActive(collection.img_Empty, true) end local curStage = MDL.Country.GetCurStage() if curStage <= MDL.Country.Stage.SovereignChooseAfter then self:SovereignChooseBefore(collection, index) elseif curStage <= MDL.Country.Stage.AdjustmentChoose then self:SovereignChooseAfter(collection, index) end else UIUtils.SetActive(collection.img_Empty, true) UIUtils.SetActive(collection.img_Flag, false) UIUtils.SetActive(collection.ico_GuildBg, false) UIUtils.SetLabelText(collection.txt_Info, Const_IDS.IDS_GuildApply_Label7) end end function UICountryChooseView:SovereignChooseBefore(collection, index) local curIndex = self:GetCurIndex() local formatStrIds if curIndex == index then if index == 4 then formatStrIds = Const_IDS.IDS_CountrySelection_GuildStauts5 collection.state_Txt:SetState(0) else formatStrIds = Const_IDS.IDS_CountrySelection_GuildStauts2 collection.state_Txt:SetState(1) end elseif curIndex > index then formatStrIds = Const_IDS.IDS_CountrySelection_GuildStauts3 collection.state_Txt:SetState(0) else if index == 4 then formatStrIds = Const_IDS.IDS_CountrySelection_GuildStauts4 collection.state_Txt:SetState(2) else formatStrIds = Const_IDS.IDS_CountrySelection_GuildStauts1 collection.state_Txt:SetState(2) end end local timeStruct = self:GetTimeStruct(index + 2) if index == 4 then collection.txt_Info.text = string.FormatByIdsId(formatStrIds, os.date(UTL.Time.FormatDateEnum.HM, timeStruct.stageStart)) else collection.txt_Info.text = string.FormatByIdsId(formatStrIds, os.date(UTL.Time.FormatDateEnum.HM, timeStruct.stageStart), os.date(UTL.Time.FormatDateEnum.HM, timeStruct.stageEnd)) end end function UICountryChooseView:SovereignChooseAfter(collection, index) collection.txt_Time.text = nil local count = MDL.Country.GetAcceptGuildNum()[index] if count < 2 then count = UTL.Color.FormatGreenColor(count) end collection.txt_Info.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_GuildNumber, count, 2) collection.state_Txt:SetState(2) end function UICountryChooseView:GetCurIndex() local curStage = MDL.Country.GetCurStage() if curStage == MDL.Country.Stage.Sovereign1Choose then return 1 elseif curStage == MDL.Country.Stage.Sovereign2Choose then return 2 elseif curStage == MDL.Country.Stage.Sovereign3Choose then return 3 elseif curStage == MDL.Country.Stage.SovereignChooseAfter then return 4 end return 0 end function UICountryChooseView:GetTimeStruct(index) local stageIndex = index + 1 local allStageTime = MDL.Country.GetAllStageTime() return allStageTime[stageIndex] end --顶部阶段时间 function UICountryChooseView:ShowTimeInfo() local selectIndex = MDL.Country.GetViewStage() local times = MDL.Country.GetViewStageTime() for i, v in ipairs(self.stages) do v.localLab_UnTime.text = os.date(UTL.Time.FormatDateEnum.YMDHM, times[i].stageStart) v.localLab_Time.text = os.date(UTL.Time.FormatDateEnum.YMDHM, times[i].stageStart) if i == selectIndex then v.lab_Switch:SetState(1) else v.lab_Switch:SetState(0) end end if selectIndex == MDL.Country.ViewStage.SignUp then self.Slider.value = 0.115 self.brightState:SetState(1) elseif selectIndex == MDL.Country.ViewStage.Sovereign1Choose then selectIndex = 1 self.Slider.value = 0.373 self.brightState:SetState(2) elseif selectIndex == MDL.Country.ViewStage.CoreChoose then selectIndex = 2 self.Slider.value = 0.64 self.brightState:SetState(3) elseif selectIndex == MDL.Country.ViewStage.CountryBuild then selectIndex = 3 self.Slider.value = 1 self.brightState:SetState(4) end end --按钮文字状态 function UICountryChooseView:InitBtn() local curStage = MDL.Country.GetCurStage() local info = MDL.Country.GetMyGuildInfo() UIUtils.SetActive(self.btn_Rank, true) if curStage <= MDL.Country.Stage.SignUp then UIUtils.SetActive(self.btn_Action, true) self.btn_Action:SetText(Const_IDS.IDS_CountrySelection_CheckGuildBtn) local structTime = self:GetTimeStruct(curStage) local countTime = structTime.stageEnd - UTL.Time.GetServerTimestamp() CTL.Country.SetCdTime(self.cdTime, countTime, Const_IDS.IDS_CountrySelection_EvaluatingCountdown) UIUtils.SetActive(self.btn_Rank, false) elseif curStage <= MDL.Country.Stage.SovereignChooseAfter then self.cdTime:EndTimer() local info = MDL.Country.GetMyGuildInfo() if info then if MDL.Country.MyIsSovereign() then UIUtils.SetActive(self.btn_Action, true) self.btn_Action:SetText(Const_IDS.IDS_CountrySelection_MemberVoteBtn) self:SetSovereignInfo() elseif MDL.Country.MyIsCore() then UIUtils.SetLabelText(self.txt_Tip, Const_IDS.IDS_CountrySelection_GuildVoteEliteGuildReminder) UIUtils.SetActive(self.btn_Action, false) else self:SetSelectTips() UIUtils.SetActive(self.btn_Action, false) end else UIUtils.SetActive(self.btn_Action, false) UIUtils.SetLabelText(self.txt_Tip, Const_IDS.IDS_ERRORCODE_1319_InfoCode_Guild_PlayerNotInGuild) end elseif curStage == MDL.Country.Stage.CoreChoose then if info then if MDL.Country.MyIsSovereign() then self.btn_Action:SetText(Const_IDS.IDS_CountrySelection_RecruitBtn) local allStageTime = MDL.Country.GetAllStageTime() local countTime = allStageTime[curStage + 1].stageEnd - UTL.Time.GetServerTimestamp() UIUtils.SetActive(self.btn_Action, true) CTL.Country.SetCdTime(self.cdTime, countTime, Const_IDS.IDS_CountrySelection_RecruitCountdown) elseif MDL.Country.MyIsCore() then self.btn_Action:SetText(Const_IDS.IDS_CountrySelection_ApplyBtn) local allStageTime = MDL.Country.GetAllStageTime() local countTime = allStageTime[curStage + 1].stageEnd - UTL.Time.GetServerTimestamp() CTL.Country.SetCdTime(self.cdTime, countTime, Const_IDS.IDS_CountrySelection_ApplyCountdown) else UIUtils.SetActive(self.btn_Action, false) self:SetSelectTips() end else UIUtils.SetActive(self.btn_Action, false) UIUtils.SetLabelText(self.txt_Tip, Const_IDS.IDS_ERRORCODE_1319_InfoCode_Guild_PlayerNotInGuild) end elseif curStage == MDL.Country.Stage.AdjustmentChoose then UIUtils.SetActive(self.btn_Action, false) if MDL.Guild.GetMyGuildInfo().isEndTriaRun then local allStageTime = MDL.Country.GetAllStageTime() local countTime = allStageTime[curStage + 1].stageEnd - UTL.Time.GetServerTimestamp() CTL.Country.SetCdTime(self.cdTime, countTime, Const_IDS.IDS_CountrySelection_CountryOpenCountdown) else UIUtils.SetLabelText(self.txt_Tip, Const_IDS.IDS_Country_TrialGuildCannotJoin) end end end function UICountryChooseView:SetSovereignInfo() local info = MDL.Country.GetMyGuildInfo() if MDL.Country.MyIsSovereign() then local list = MDL.Country.GetSovereignGuildList() local allStageTime = MDL.Country.GetAllStageTime() local index = 0 for i, v in ipairs(list) do if v.guildId == info.guildId then index = i break end end local curStage = MDL.Country.GetCurStage() local myStage = MDL.Country.GetStageByViewIndex(index) local myTime = allStageTime[myStage + 1] if myStage == 6 then local countTime = myTime.stageStart - UTL.Time.GetServerTimestamp() if countTime <= 0 then self.txt_Tip.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_GuildVoteEnd, CTL.Country.GetCountryFullName(info.country)) self.voteStage = VoteStage.Stop else CTL.Country.SetCdTime(self.cdTime, countTime, Const_IDS.IDS_CountrySelection_GuildVoteAutoExecute) end self.voteStage = VoteStage.Stop UIUtils.SetActive(self.btn_Action, false) elseif myStage == 1 then if MDL.Country.MyIsCore() then UIUtils.SetLabelText(self.txt_Tip, Const_IDS.IDS_CountrySelection_GuildVoteEliteGuildReminder) else self:SetSelectTips() end elseif myStage == curStage then local countTime = myTime.stageEnd - UTL.Time.GetServerTimestamp() self.voteStage = VoteStage.Open CTL.Country.SetCdTime(self.cdTime, countTime, Const_IDS.IDS_CountrySelection_GuildVoting) self:CountryGetJoinVoteInfoReq() elseif myStage < curStage and curStage < MDL.Country.Stage.CoreChoose then self.txt_Tip.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_GuildVoteEnd, CTL.Country.GetCountryFullName(info.country)) self.voteStage = VoteStage.Stop else local countTime = myTime.stageStart - UTL.Time.GetServerTimestamp() CTL.Country.SetCdTime(self.cdTime, countTime, Const_IDS.IDS_CountrySelection_GuildVoteNotOpen) self.voteStage = VoteStage.NotOpen end else end end function UICountryChooseView:CountryGetJoinVoteInfoReq() if not self.getJoinVoteInfoReq then MDL.Country.CountryGetJoinVoteInfoReq() self.getJoinVoteInfoReq = true end end function UICountryChooseView:OnClickVoteBtn() if self.voteStage == VoteStage.Open then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryVotePanel) elseif self.voteStage == VoteStage.NotOpen then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_CountrySelection_GuildVoteNotOpenTip) elseif self.voteStage == VoteStage.Stop then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_CountrySelection_MemberVoteEnd) end end function UICountryChooseView:OnClickMapBtn(index) local id = CTL.Country.GetCountryIdByIndex(index) local countryBase = DataSheetManager.CountryBase:GetDataByID(id) CTL.Country.SetCountryImage(self.group_CountryInfo, id) UIUtils.SetLabelText(self.group_CountryInfo.txt_Country, Const_IDS[countryBase.CountryIntro]) UIUtils.SetActive(self.group_CountryInfo.gameObject, true) self.selectState:SetState(index - 1) end --中间地图展示信息 function UICountryChooseView:SetMapCountryInfo() local list = MDL.Country.GetSovereignGuildList() local curStage = MDL.Country.GetCurStage() if curStage <= MDL.Country.Stage.SignUp then for i = 1, 4 do self:SetEmptyAtSelectStage(i, nil) end UIUtils.SetLabelText(self.txt_Title, Const_IDS.IDS_CountrySelection_KingGuildSelect) elseif curStage <= MDL.Country.Stage.SovereignChooseAfter then for i = 1, 4 do if MDL.Country.IsFoundCountry(i) then self:SetMapCountryAtSelectStage(i, MDL.Country.GetSovereignGuildByCountry(i)) else self:SetEmptyAtSelectStage(i, MDL.Country.GetSovereignGuildByCountry(i)) end end UIUtils.SetLabelText(self.txt_Title, Const_IDS.IDS_CountrySelection_KingGuildSelect) elseif curStage >= MDL.Country.Stage.CoreChoose then self:SetMapCountryAtRecruitStage(1, MDL.Country.GetSovereignGuildByCountry(1)) self:SetMapCountryAtRecruitStage(2, MDL.Country.GetSovereignGuildByCountry(2)) self:SetMapCountryAtRecruitStage(3, MDL.Country.GetSovereignGuildByCountry(3)) self:SetMapCountryAtRecruitStage(4, MDL.Country.GetSovereignGuildByCountry(4)) UIUtils.SetLabelText(self.txt_Title, Const_IDS.IDS_CountryRecruite_KingGuildList) end end function UICountryChooseView:SetEmptyAtSelectStage(index, data) if self.voteStage ~= VoteStage.Open then local collection = self.countryArray[index] collection.state_Vote:SetState(1) UIUtils.SetActive(collection.group_MainGuild.gameObject, false) UIUtils.SetActive(collection.group_SubGuild1.gameObject, false) UIUtils.SetActive(collection.group_SubGuild2.gameObject, false) end end function UICountryChooseView:SetMapCountryAtSelectStage(index, data) local collection = self.countryArray[index] collection.state_Vote:SetState(1) if data then self:SetCollectionGuild(collection.group_MainGuild, data) UIUtils.SetActive(collection.group_MainGuild.gameObject, true) else UIUtils.SetActive(collection.group_MainGuild.gameObject, false) end UIUtils.SetActive(collection.group_SubGuild1.gameObject, false) UIUtils.SetActive(collection.group_SubGuild2.gameObject, false) end function UICountryChooseView:SetMapCountryAtRecruitStage(index, data) local collection = self.countryArray[index] collection.state_Vote:SetState(1) if data then self:SetCollectionGuild(collection.group_MainGuild, data) UIUtils.SetActive(collection.group_MainGuild.gameObject, true) local coreList = MDL.Country.GetCoreGuildByCountry(data.country) if coreList[1] then self:SetCollectionGuild(collection.group_SubGuild1, coreList[1]) UIUtils.SetActive(collection.group_SubGuild1.gameObject, true) else UIUtils.SetActive(collection.group_SubGuild1.gameObject, false) end if coreList[2] then self:SetCollectionGuild(collection.group_SubGuild2, coreList[2]) UIUtils.SetActive(collection.group_SubGuild2.gameObject, true) else UIUtils.SetActive(collection.group_SubGuild2.gameObject, false) end else UIUtils.SetActive(collection.group_MainGuild.gameObject, false) UIUtils.SetActive(collection.group_SubGuild1.gameObject, false) UIUtils.SetActive(collection.group_SubGuild2.gameObject, false) end end function UICountryChooseView:OnClickApplyBtn() if MDL.Country.MyIsSovereign() then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryRecruitPanel) elseif MDL.Country.MyIsCore() then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryDefectedPanel) end end function UICountryChooseView:SetCollectionGuild(collection, data) collection.txt_GuildName.text = data.guildName collection.lab_ServerName.text = CTL.CrossServer.GetServerShowStr(data.serverId) UTL.Item.SetAtlasSprite(collection.ico_GuildBg, "UI_Guild", DataSheetManager.GuildEmblem:GetDataByID(data.guildEmblemFrame).Image) collection.txt_TitleGuildName.text = data.guildEmblemContent end function UICountryChooseView:ClickOpenGuildInfoView(countryId, index) local guildId = nil if index then local coreList = MDL.Country.GetCoreGuildByCountry(countryId) if coreList[index] then guildId = coreList[index].guildId end else guildId = MDL.Country.GetSovereignGuildByCountry(countryId).guildId end if guildId then MDL.Country.CountryGetTargetGuildInfoReq(guildId) end end function UICountryChooseView:SetSelectTips() if not MDL.Guild.GetMyGuildInfo().isEndTriaRun then UIUtils.SetLabelText(self.txt_Tip, Const_IDS.IDS_Country_TrialGuildCannotJoin) else UIUtils.SetLabelText(self.txt_Tip, Const_IDS.IDS_CountrySelection_GuildVoteNormalGuildReminder) end end return UICountryChooseView