local UICountryPopupGuildAppoint = UIViewClass() function UICountryPopupGuildAppoint:OnOpened(context) self:RegistSystemEvent(EventID.Country_OnSearchGuild, self.OnSearchGuild) self:RegistSystemEvent(EventID.Country_OnGetGuildInfo, self.AddGuildInfo) self.curPage = 0 UIUtils.SetActive(self.btn_Cancel, false) self:Init(context) end function UICountryPopupGuildAppoint:Init(context) MDL.Country.CountryGetGuildInfoReq(self.curPage + 1, true) self.curTitleId = context.titleId self.curIndex = context.index self.isAppoint = true local seconds = DataSheetManager.ConstData:GetDataByID("CountryGuildAppointProtectTime").IntValue local timeStr = UTL.Time.GetShowTimeByMinutes(seconds/UTL.Time.TotalSecondsOneMinute) self.txt_Notice.text = string.FormatByIdsId(Const_IDS.IDS_Country_GuildAppointIntro2, timeStr) self.UICommonPopUp.txt_Title.text = string.FormatByIdsId(Const_IDS.IDS_Country_GuildAppointIntro, MDL.Country.GetGuildTitleColorName(self.curTitleId)) end function UICountryPopupGuildAppoint:AddGuildInfo(list, totalLength) self.totalLength = totalLength self.scroll_Details:ClearCells() for i, v in ipairs(list) do self.scroll_Details:AddData(v, 0) end self.curPage = self.curPage + 1 if self.curSelectGuild == nil and self.isAppoint then self.scroll_Details:SelectIndex(0) end if self.txt_GuildNum then self.txt_GuildNum.text = string.FormatByIdsId(Const_IDS.IDS_Country_CountryGuildNum, totalLength) end self.curAddCount = self.scroll_Details.Count end function UICountryPopupGuildAppoint:OnSearchGuild(list) self.scroll_Details:ClearCells() for i, v in ipairs(list) do self.scroll_Details:AddData(v, 0) end self.curPage = 0 self.totalLength = 0 self.curSelectGuild = nil if self.isAppoint and self.scroll_Details.Count > 0 then self.scroll_Details:SelectIndex(0) end end function UICountryPopupGuildAppoint:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Cancel then self.obj_InputField.text = nil UIUtils.SetActive(self.btn_Cancel, false) self.curPage = 0 self.scroll_Details:ClearCells() MDL.Country.CountryGetGuildInfoReq(self.curPage + 1, self.isAppoint) elseif comp == self.btn_Appoint then self:ChangeGuildTitle() elseif comp == self.btn_Search then self:SearchGuild() end end function UICountryPopupGuildAppoint:ChangeGuildTitle() if self.curSelectGuild.levelInCountry == MDL.Country.CountryGuildTitle.CountryPopulaceGuild then self:ClickAppoint() else CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Country_GuildAlreadyAppointedTip) end end function UICountryPopupGuildAppoint:OnValueChanged(comp, value) if comp == self.obj_InputField then local length = DataSheetManager.ConstData:GetDataByID("GuildNameCharNumlimit").IntValue self.obj_InputField.text = UTL.String.CutStrByLength(self.obj_InputField.text, length) end end function UICountryPopupGuildAppoint:SearchGuild() if string.isNilOrEmpty(self.obj_InputField.text) then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Chat_CantBlank) return end MDL.Country.CountrySearchGuildReq(self.obj_InputField.text) UIUtils.SetActive(self.btn_Cancel, true) end function UICountryPopupGuildAppoint:OnCellInit(scrollRect, index, cellTable, data) if index == self.totalLength - 1 then elseif self.curAddCount == index + 1 then MDL.Country.CountryGetGuildInfoReq(self.curPage + 1, self.isAppoint) end UTL.Item.SetAtlasSprite(cellTable.img_Emblem, "UI_Guild", DataSheetManager.GuildEmblem:GetDataByID(data.guildEmblemFrame).Image) cellTable.txt_Emblem.text = data.guildEmblemContent cellTable.txt_Name.text = data.guildName cellTable.txt_Server.text = CTL.CrossServer.GetServerShowStr(data.serverId) cellTable.txt_PeopleNum.text = data.guildNum cellTable.txt_PlayerName.text = data.guildLeadName cellTable.txt_BR_Num.text = data.guildGs cellTable.txt_Class.text = MDL.Country.GetGuildTitleColorName(data.levelInCountry) cellTable.state_Bg:SetState(index % 2) end function UICountryPopupGuildAppoint:OnCellClicked(scrollRect, index, cellTable, target, data) self.curSelectGuild = data if self.curSelectGuild.levelInCountry == MDL.Country.CountryGuildTitle.CountryPopulaceGuild then self.btn_Appoint:SetGray(false) else if target == nil then CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Country_GuildAlreadyAppointedTip) end self.btn_Appoint:SetGray(true, true) end if target == cellTable.btn_Guild then MDL.Country.CountryGetTargetGuildInfoReq(data.guildId) end end function UICountryPopupGuildAppoint:ClickAppoint() local jobName = MDL.Country.GetGuildTitleColorName(self.curTitleId) local str = string.FormatByIdsId(Const_IDS.IDS_Country_GuildAppointConfirm, CTL.CrossServer.GetServerShowStr(self.curSelectGuild.serverId), self.curSelectGuild.guildName, jobName) UTL.MessageBox.ShowOKCancelBox("", str, function() MDL.Country.CountryChangeGuildTitleReq(self.curSelectGuild.guildId, self.curTitleId, self.curIndex) end ) end return UICountryPopupGuildAppoint