local UICountryRecruitPanel = UIViewClass() function UICountryRecruitPanel:OnOpened(context) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_CountrySelection_Phase3) self:RegistSystemEvent(EventID.Country_OnGetInviteInfo, self.OnGetInviteInfo) self:RegistSystemEvent(EventID.Country_OnInviteGuild, self.OnInviteGuild) self:SetCountryInfo() MDL.Country.CountryGetInviteInfoReq() end function UICountryRecruitPanel:OnGetInviteInfo(msg) self.leadGuild = msg.leadGuild.guildInfo self:SetMainGuildsInfo(msg) self.inviteGuildList = msg.inviteGuildList self.applyGuildList = msg.applyGuildList self:UpdateRecruitList(msg.eliteGuild) self:SetTimeInfo(msg.finishTime) end function UICountryRecruitPanel:OnInviteGuild(guildId) table.insert(self.inviteGuildList, guildId) self.LoopScroll_CountryRecruit:RefreshCells(false) end function UICountryRecruitPanel:SetMainGuildsInfo(data) self:SetGuildInfo(self.group_Main, data.leadGuild.guildInfo[1]) self:SetGuildInfo(self.group_Sub1, data.leadGuild.guildInfo[2]) self:SetGuildInfo(self.group_Sub2, data.leadGuild.guildInfo[3]) end function UICountryRecruitPanel:SetGuildInfo(collection, data) if data then collection.lab_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 UIUtils.SetActive(collection.ico_GuildBg, true) UIUtils.SetActive(collection.group_Empty, false) UIUtils.SetActive(collection.group_SubGuildIcon, true) else UIUtils.SetActive(collection.ico_GuildBg, false) UIUtils.SetActive(collection.group_Empty, true) UIUtils.SetActive(collection.group_SubGuildIcon, false) UIUtils.SetLabelText(collection.lab_GuildName, Const_IDS.IDS_GuildApply_Label7) end end function UICountryRecruitPanel:SetCountryInfo() local data = MDL.Country.GetMyGuildInfo() CTL.Country.SetCountryImage(self, data.country) end function UICountryRecruitPanel:UpdateRecruitList(list) self.LoopScroll_CountryRecruit:ReloadAll(list) end function UICountryRecruitPanel:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.group_Sub2.btn then MDL.Country.CountryGetTargetGuildInfoReq(self.leadGuild[3].guildId) elseif comp == self.group_Sub1.btn then MDL.Country.CountryGetTargetGuildInfoReq(self.leadGuild[2].guildId) elseif comp == self.group_Main.btn then MDL.Country.CountryGetTargetGuildInfoReq(self.leadGuild[1].guildId) end end function UICountryRecruitPanel:SetTimeInfo(timeStamp) local time = MDL.Country.GetCurStateTime().stageEnd - UTL.Time.GetServerTimestamp() CTL.Country.SetCdTime(self.txt_Time, time, Const_IDS.IDS_CountryRecruite_InviteCountdown) self:StartRepeatFunc(self.CloseSelf, time, 1) end function UICountryRecruitPanel:CloseSelf() self:CloseView() end function UICountryRecruitPanel:OnCellInit(scrollRect, index, cellTable, data) self:SetGuildInfo(cellTable, data) cellTable.lab_LimitReached.text = nil cellTable.btn_Application:SetGray(false) if data.country > 0 then CTL.Country.SetCountryImage(cellTable, data.country) UIUtils.SetActive(cellTable.img_Country, true) UIUtils.SetActive(cellTable.btn_Accept, false) cellTable.btn_Application:SetGray(true, true) UIUtils.SetActive(cellTable.btn_Application, true) CTL.Country.SetCountyBgImage(cellTable.img_Flag, false) else CTL.Country.SetCountryImage(cellTable, 1) CTL.Country.SetCountyBgImage(cellTable.img_Flag, true) UIUtils.SetActive(cellTable.img_Country, false) if table.containValue(self.inviteGuildList, data.guildId) then UIUtils.SetActive(cellTable.btn_Application, false) UIUtils.SetActive(cellTable.btn_Accept, false) UIUtils.SetLabelText(cellTable.lab_LimitReached, Const_IDS.IDS_CountryRecruite_Invited) elseif table.containValue(self.applyGuildList, data.guildId) then UIUtils.SetActive(cellTable.btn_Application, false) UIUtils.SetActive(cellTable.btn_Accept, true) else UIUtils.SetActive(cellTable.btn_Application, true) UIUtils.SetActive(cellTable.btn_Accept, false) end end if #self.leadGuild >= 3 then UIUtils.SetActive(cellTable.btn_Application, false) UIUtils.SetActive(cellTable.btn_Accept, false) cellTable.lab_LimitReached.text = nil end cellTable.lab_GuildNum.text = data.guildNum cellTable.txt_PowerNumber.text = data.guildGs cellTable.lab_GuildLord.text = data.guildLeadName end function UICountryRecruitPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.btn_Application then self:ClickApplication(index, data) elseif target == cellTable.btn_Accept then self:ClickAccept(index, data) elseif target == cellTable.btn then MDL.Country.CountryGetTargetGuildInfoReq(data.guildId) elseif target == cellTable.btn_Player then CTL.PlayerInteract.OpenFriendInteractView(data.guildLeadAcid) end end function UICountryRecruitPanel:ClickApplication(index, data) if data.country > 0 then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_CountryRecruite_TargetInCountryTip) elseif #self.leadGuild < 3 then if MDL.Guild.CheckLeader(1) then local countryName = string.FormatByIdsId(Const_IDS.IDS_CountryRecruite_InviteConfirm, data.guildName) UTL.MessageBox.ShowOKCancelBox("", countryName, function() MDL.Country.CountryInviteGuildReq(data.guildId) end ) else CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Guild_OnlyLead) end else CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_CountryRecruite_GuildNumLimit) end end function UICountryRecruitPanel:ClickAccept(index, data) if #self.leadGuild < 3 then if MDL.Guild.CheckLeader(1) then local countryName = string.FormatByIdsId(Const_IDS.IDS_CountryRecruite_AgreeConfirm, data.guildName) UTL.MessageBox.ShowOKCancelBox("", countryName, function() MDL.Country.CountryAcceptApplyReq(data.guildId) end ) else CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Guild_OnlyLead) end else CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_CountryRecruite_GuildNumLimit) end end return UICountryRecruitPanel