local UICountryVotePanel = UIViewClass() function UICountryVotePanel:OnOpened(context) self:RegistSystemEvent(EventID.Country_OnGetJoinVoteInfo, self.UpdateView) self:RegistSystemEvent(EventID.Country_OnDoJoinVoteInfo, self.OnDoJoinVoteInfo) MDL.Country.CountryGetJoinVoteInfoReq() self:InitCountryInfo() UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_CountrySelection_MemberVoteBtn) self:SetTimeInfo() end function UICountryVotePanel:UpdateView(data) for i, collection in ipairs(self.group_Votes) do local voteData = MDL.Country.GetVoteDataByCountry(data.voteInfoList, i) if MDL.Country.IsFoundCountry(i) then UIUtils.SetActive(collection.img_Voted, true) UIUtils.SetActive(collection.btn_Vote, false) UIUtils.SetActive(collection.group_Lord, false) elseif voteData == nil then UIUtils.SetActive(collection.img_Voted, false) UIUtils.SetActive(collection.btn_Vote, true) collection.txt_Votes.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_MemberVotingValue, 0) UIUtils.SetActive(collection.group_Lord, false) else UIUtils.SetActive(collection.img_Voted, false) UIUtils.SetActive(collection.btn_Vote, true) collection.txt_Votes.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_MemberVotingValue, voteData.voteNum) UIUtils.SetActive(collection.group_Lord, i == data.guildLeaderChoice[1]) end end self:InitVoteNum(data) end function UICountryVotePanel:OnDoJoinVoteInfo(data, isLeader) local collection = self.group_Votes[data.country] collection.txt_Votes.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_MemberVotingValue, data.voteNum) UIUtils.SetActive(collection.group_Lord, isLeader) self.txt_RemainingVotes.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_MyVotingValue, 0) self.voteNum = 0 end function UICountryVotePanel:InitCountryInfo() for i, v in ipairs(self.group_Votes) do CTL.Country.SetCountryImage(v, i) end end function UICountryVotePanel:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() else for i, v in ipairs(self.group_Votes) do if comp == v.btn_Vote then if self.voteNum > 0 then local countryName = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_VoteConfirm, CTL.Country.GetCountryName(i)) UTL.MessageBox.ShowOKCancelBox("", countryName, function() MDL.Country.CountryDoJoinVoteReq(i) end ) else CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_CountrySelection_NoVotingValue) end end end end end function UICountryVotePanel:InitVoteNum(data) self.voteNum = data.remainTicket self.txt_RemainingVotes.text = string.FormatByIdsId(Const_IDS.IDS_CountrySelection_MyVotingValue, self.voteNum) end function UICountryVotePanel:SetTimeInfo() local time = MDL.Country.GetCurStateTime().stageEnd - UTL.Time.GetServerTimestamp() CTL.Country.SetCdTime(self.txt_Time, time, Const_IDS.IDS_CountrySelection_GuildVoting) self:StartRepeatFunc(self.CloseSelf, time, 1) end function UICountryVotePanel:CloseSelf() self:CloseView() end return UICountryVotePanel