local UICountryEnfeoff = UIViewClass() function UICountryEnfeoff:OnOpened(context) self:RegistSystemEvent(EventID.Country_GetEnfeoffmentPanelInfo, self.UpdateInfo) self:RegistSystemEvent(EventID.Country_OnChangeGuildTitle, self.OnChangeGuildTitle) self:RegistSystemEvent(EventID.Country_OnMyJobChange, self.OnPermissionChange) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Nobility, self.UpdateSalaryBtnRp) MDL.Country.CountryGetEnfeoffmentPanelInfoReq() self:InitGuildTitle() self:UpdateSalaryBtnRp() UTL.UIRender.AdaptiveImageSizeFit(self.img_Bottom, true) end function UICountryEnfeoff:UpdateSalaryBtnRp() self.btn_Salary:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Country_SalaryReward)) end function UICountryEnfeoff:OnChangeGuildTitle(countryInfo, changeTitle) if self.allMainGuildList[2] and self.allMainGuildList[2].guildId == countryInfo.guildId then self:SetCollectionGuild(self.group_MainGuild[2], nil) self.allMainGuildList[2] = nil elseif self.allMainGuildList[3] and self.allMainGuildList[3].guildId == countryInfo.guildId then self:SetCollectionGuild(self.group_MainGuild[3], nil) self.allMainGuildList[3] = nil else for i, v in ipairs(self.allSubGuildList) do if v.guildId == countryInfo.guildId then local collection = self.group_SimpleGuild[v.levelIndex + 1] self:SetCollectionGuild(collection, nil) table.remove(self.allSubGuildList, i) break end end end if changeTitle.title == MDL.Country.CountryGuildTitle.CountryLeadGuild then if countryInfo.levelIndex == 0 then self:SetCollectionGuild(self.group_MainGuild[2], countryInfo) self.allMainGuildList[2] = countryInfo else self:SetCollectionGuild(self.group_MainGuild[3], countryInfo) self.allMainGuildList[3] = countryInfo end elseif changeTitle.title == MDL.Country.CountryGuildTitle.CountryEliteGuild then for i, v in ipairs(self.group_SimpleGuild) do if i == countryInfo.levelIndex + 1 then self:SetCollectionGuild(v, countryInfo) table.insert(self.allSubGuildList, countryInfo) break end end end end function UICountryEnfeoff:OnPermissionChange() self.hasPermission = self:IsHasPermission() self:SetAllMainGuildInfo(self.allMainGuildList[1], self.allMainGuildList[2], self.allMainGuildList[3]) self:SetSubGuildInfo(self.allSubGuildList) end function UICountryEnfeoff:UpdateInfo(info) self.hasPermission = self:IsHasPermission() local coreGuild1, coreGuild2 for i,v in ipairs(info.coreGuild) do if v.levelIndex == 0 then coreGuild1 = v elseif v.levelIndex == 1 then coreGuild2 = v end end self:SetAllMainGuildInfo(info.lordGuild, coreGuild1, coreGuild2) self:SetSubGuildInfo(info.eliteGuild) end function UICountryEnfeoff:SetAllMainGuildInfo(lordGuild, secondGuild, thirdGuild) self.allMainGuildList = { lordGuild, secondGuild, thirdGuild } for i, v in ipairs(self.group_MainGuild) do self:SetCollectionGuild(self.group_MainGuild[i], self.allMainGuildList[i]) end end function UICountryEnfeoff:SetSubGuildInfo(list) for i, v in ipairs(self.group_SimpleGuild) do local data = self:GetDataByIndex(list, i - 1) self:SetCollectionGuild(v, data) end self.allSubGuildList = list end function UICountryEnfeoff:GetDataByIndex(eliteGuild, index) for i, v in ipairs(eliteGuild) do if v.levelIndex == index then return v end end end function UICountryEnfeoff:OnButtonClicked(comp) if comp == self.btn_Guild then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryPopupGuildList) elseif comp == self.btn_Award then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryPopupSalary) elseif comp == self.btn_CloseOperation then UIUtils.SetActive(self.group_Operation, false) elseif comp == self.btn_Info then MDL.Country.CountryGetTargetGuildInfoReq(self.curSelectGuild.guildId) UIUtils.SetActive(self.group_Operation, false) elseif comp == self.btn_Salary then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountrySalaryBase) elseif comp == self.btn_Cancel then self:CancelTitle() UIUtils.SetActive(self.group_Operation, false) elseif comp == self.btn_Season then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryResetRewardPreview) elseif comp == self.btn_KingRight then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryKingRightPopUp) elseif comp == self.btn_Shop then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIShopMain, {TabEnum = CTL.PayMall.ShopMainTabEnum.GuoZhan}) -- 跳转国战 else for i, v in ipairs(self.group_SimpleGuild) do if comp == v.btn_Add then self:ClickAddSub(i) break elseif comp == v.img_InfoBg then self:ShowOperation(comp, i, false) break end end for i, v in ipairs(self.group_MainGuild) do if comp == v.btn_Add then self:ClickAddMain(i) break elseif comp == v.img_InfoBg then self:ShowOperation(comp, i, true) break end end end end function UICountryEnfeoff:ClickAddSub(index) if not CTL.Country.ShowResetState() then local titleId = self:GetTitleIdByIndex(index + 3) UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryPopupGuildAppoint, { titleId = titleId, index = index - 1 }) end end function UICountryEnfeoff:ClickAddMain(index) if not CTL.Country.ShowResetState() then local titleId = self:GetTitleIdByIndex(index) UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryPopupGuildAppoint, { titleId = titleId , index = index - 2}) end end function UICountryEnfeoff:ShowOperation(comp, index, isMain) local guildInfo = nil if isMain then guildInfo = self.allMainGuildList[index] else for i, v in ipairs(self.allSubGuildList) do if v.levelIndex + 1 == index then guildInfo = v break end end end if guildInfo and not string.isNilOrEmpty(guildInfo.guildId) then self.group_Operation.transform:SetPosition(comp.transform:GetPosition()) UIUtils.SetActive(self.group_Operation, true) if self.hasPermission then if isMain and index == 1 then UIUtils.SetActive(self.btn_Cancel, false) else UIUtils.SetActive(self.btn_Cancel, true) end else UIUtils.SetActive(self.btn_Cancel, false) end self.curSelectGuild = guildInfo else UIUtils.SetActive(self.group_Operation, false) end end function UICountryEnfeoff:SetCollectionGuild(collection, data) if data and not string.isNilOrEmpty(data.guildId) then UTL.Item.SetAtlasSprite(collection.img_Emblem, "UI_Guild", DataSheetManager.GuildEmblem:GetDataByID(data.guildEmblemFrame).Image) collection.txt_Emblem.text = data.guildEmblemContent collection.txt_Guild.text = data.guildName collection.txt_server.text = CTL.CrossServer.GetServerShowStr(data.serverId) collection.state_Guild:SetState(0) else if self.hasPermission then collection.state_Guild:SetState(1) else collection.state_Guild:SetState(2) end end end function UICountryEnfeoff:IsHasPermission() return MDL.Country.JobHasPermission(MDL.Country.GetMyJobId(), MDL.Country.AuthorityEnum.GuildAppoint2) end function UICountryEnfeoff:GetTitleIdByIndex(index) if index == 2 then return MDL.Country.CountryGuildTitle.CountryLeadGuild elseif index == 3 then return MDL.Country.CountryGuildTitle.CountryLeadGuild elseif index > 3 then return MDL.Country.CountryGuildTitle.CountryEliteGuild end end function UICountryEnfeoff:CancelTitle() local jobName = MDL.Country.GetGuildTitleColorName(self.curSelectGuild.levelInCountry) local name = self.curSelectGuild.guildName local serverId = CTL.CrossServer.GetServerShowStr(self.curSelectGuild.serverId) local str = string.FormatByIdsId(Const_IDS.IDS_Country_DismissGuildConfirm, serverId, name, jobName, name) UTL.MessageBox.ShowOKCancelBox("", str, function() self:MessageBoxOk() end ) UIUtils.SetActive(self.group_Operation, false) end function UICountryEnfeoff:MessageBoxOk() local lastTime = self.curSelectGuild.projectTime if lastTime and lastTime > 0 then local cdTime = os.difftime(lastTime, UTL.Time.GetServerTimestamp()) if cdTime > 0 then local name = self.curSelectGuild.guildName local timeStr = UTL.Time.FormatTimeForDayOrClock(cdTime) local tipStr = string.FormatByIdsId(Const_IDS.IDS_Country_GuildInProtectTimeTip, name, timeStr) CTL.Tips.AddTipsMsgAndPlaySound(tipStr) return end end MDL.Country.CountryChangeGuildTitleReq(self.curSelectGuild.guildId, MDL.Country.CountryGuildTitle.CountryPopulaceGuild) end function UICountryEnfeoff:InitGuildTitle() UIUtils.SetLabelText(self.group_MainGuild[1].lab_Title1, MDL.Country.GetGuildTitleName(MDL.Country.CountryGuildTitle.CountryKingGuild)) UIUtils.SetLabelText(self.group_MainGuild[2].lab_Title2, MDL.Country.GetGuildTitleName(MDL.Country.CountryGuildTitle.CountryLeadGuild)) UIUtils.SetLabelText(self.group_MainGuild[3].lab_Title3, MDL.Country.GetGuildTitleName(MDL.Country.CountryGuildTitle.CountryLeadGuild)) UIUtils.SetLabelText(self.lab_Title4, MDL.Country.GetGuildTitleName(MDL.Country.CountryGuildTitle.CountryEliteGuild)) UIUtils.SetLabelText(self.lab_Title5, MDL.Country.GetGuildTitleName(MDL.Country.CountryGuildTitle.CountryEliteGuild)) end return UICountryEnfeoff