local UICountryMain = UIViewClass() local HanIndex = 99 local HanMapBgImagePath = ConstAssetPathConfig.HanMapBgImagePath local SelfMapBgImagePath = ConstAssetPathConfig.SelfMapBgImagePath local EnemyMapBgImagePath = ConstAssetPathConfig.EnemyMapBgImagePath function UICountryMain:OnOpened(context) self:RegistSystemEvent(EventID.Country_OnGetFoundCountry, self.SetAllCountry) self:RegistSystemEvent(EventID.Country_OnUpdateMyCountry, self.UpdateMyCountry) self:RegistSystemEvent(EventID.Country_OnGetDonatePanelInfo, self.OnUpdateCountryCurrency) self:RegistSystemEvent(EventID.Country_GetStatue, self.ShowCountryReset) self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.renderModel) UIUtils.SetActive(self.img_Self, false) for i, v in ipairs(self.group_KingInfo) do self:SetMapName(i, v.lab_City, v.img_Go, v.img_LabBg) end MDL.Country.CountryGetMainPanelInfoReq() self.curNotice = true end function UICountryMain:OnClosed() UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) end function UICountryMain:SetAllCountry() local allCountry = MDL.Country.GetCountryInfo() if allCountry then local data = MDL.Country.GetMyCountryInfo() self:SetCountryInfo(data) for i, v in ipairs(allCountry) do if v.countryID ~= HanIndex then local collection = self.group_KingInfo[v.countryID] if MDL.Country.GetCurStage() == MDL.Country.Stage.CountryReset then UIUtils.SetActive(collection.HeroHead.gameObject, false) UIUtils.SetActive(collection.img_Ttile, false) collection.txt_PlayerName.text = nil else self:SetHeadInfo(collection, v.officialList) UIUtils.SetActive(collection.img_Overlord, v.isDominate) end end end end end function UICountryMain:UpdateMyCountry() local data = MDL.Country.GetMyCountryInfo() self:SetCountryInfo(data) if self.curNotice then self:SetNotice() else self:SetTitle() end end function UICountryMain:OnUpdateCountryCurrency(msg) if msg.Dominating and msg.Dominating > 0 then self.group_CountryInfo.txt_Info2.text = msg.CountryMoney self.group_CountryInfo.txt_Info1.text = msg.Dominating end end function UICountryMain:OnButtonClicked(comp) if comp == self.btn_Setting then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountrySetPanel) elseif comp == self.btn_Donate then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryPopupContribute) elseif comp == self.btn_Policy then elseif comp == self.btn_Rank then CTL.Rank.OpenRankPanelByType(MDL.Rank.RankType.Country) elseif comp == self.btn_Event then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryDiary, nil, Const_UI_Lua.UIEnum.UIGuildDiary) elseif comp == self.group_CountryInfo.btn_Edit then self:ClickEdit() else for i, v in ipairs(self.group_KingInfo) do if v.btn_Map == comp then if i == 5 then CTL.Country.GoCountryMap(HanIndex) else CTL.Country.GoCountryMap(i) end break elseif i ~= 5 and v.HeroHead.img_PlayerAvatarBg == comp then self:ShowPlayerInteract(i) end end end end function UICountryMain:OnValueChanged(comp, index) if comp == self.group_CountryInfo.group_Toggle then if index == 0 then self:SetNotice() else self:SetTitle() end end end function UICountryMain:SetCountryInfo(data) if MDL.Country.GetCurStage() == MDL.Country.Stage.CountryReset then self:ShowCountryReset() else self.group_CountryInfo.txt_Info1.text = data.dominating self.group_CountryInfo.txt_Info2.text = data.money self.group_CountryInfo.txt_Notice.text = MDL.Country.GetCountryNotice(data.notice, data.countryID) CTL.Country.SetCountryImage(self.group_CountryInfo, data.countryID) local countryData = DataSheetManager.CountryBase:GetDataByID(data.countryID) UIUtils.SetImageByAssetBundle(self.group_CountryInfo.img_NameBg, countryData.CountryPlatePath) self.group_CountryInfo.txt_Country.text = MDL.Country.GetCountryTitle(data.reignTitle, data.countryID) UIUtils.SetActive(self.group_CountryInfo.gameObject, true) UIUtils.SetActive(self.group_CountryReset, false) end end function UICountryMain:SetNotice() local data = MDL.Country.GetMyCountryInfo() self.group_CountryInfo.txt_Notice.text = MDL.Country.GetCountryNotice(data.notice, data.countryID) self.curNotice = true end function UICountryMain:SetTitle() local data = MDL.Country.GetMyCountryInfo() self.group_CountryInfo.txt_Notice.text = MDL.Country.GetCountryAnnouncement(data.declaration, data.countryID) self.curNotice = false end function UICountryMain:SetMapName(country, textComp, img_go, img_LabBg) if country == 5 then country = HanIndex end local countryData = DataSheetManager.CountryBase:GetDataByID(country) local mapInfo = DataSheetManager.LevelInfoData:GetDataByLevelID(countryData.SceneId) UIUtils.SetLabelText(textComp, Const_IDS[mapInfo.LevelNameIDS]) UIUtils.SetActive(img_go, BattleDataGetter.GetCurLevelID() ~= countryData.SceneId) if BattleDataGetter.GetCurLevelID() == countryData.SceneId then CTL.Character.SetImgPortrait(self.img_HeroHead, MDL.Character.GetCurWearPortrait()) if country == MDL.Country.CountryType.Wei then self.state_Pos:SetState(3) elseif country == MDL.Country.CountryType.Shu then self.state_Pos:SetState(1) elseif country == MDL.Country.CountryType.Wu then self.state_Pos:SetState(2) elseif country == MDL.Country.CountryType.Qun then self.state_Pos:SetState(0) elseif country == MDL.Country.CountryType.Han then self.state_Pos:SetState(4) end UIUtils.SetActive(self.img_Self, true) end if country == HanIndex then UIUtils.SetImageByAssetBundle(img_LabBg, HanMapBgImagePath) elseif country == MDL.Country.GetMyCountryId() then UIUtils.SetImageByAssetBundle(img_LabBg, SelfMapBgImagePath) else UIUtils.SetImageByAssetBundle(img_LabBg, EnemyMapBgImagePath) end end function UICountryMain:SetHeadInfo(collection, officialList) local data = MDL.Country.GetCountryLeader(officialList) CTL.Character.SetPortraitAndFrame(collection.HeroHead, data.showInfo.PortraitId, data.showInfo.FrameId) collection.txt_PlayerName.text = data.showInfo.name end function UICountryMain:ClickEdit() local id = MDL.Country.GetMyJobId() if self.curNotice then if CTL.Country.ShowResetState() then elseif MDL.Country.JobHasPermission(id, MDL.Country.AuthorityEnum.CountryAnnouncement) then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryPublicNotice, { isNotice = true }, Const_UI_Lua.UIEnum.UIGuildPublicNotice) else CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Guild_CommonFail4) end else if CTL.Country.ShowResetState() then elseif MDL.Country.JobHasPermission(id, MDL.Country.AuthorityEnum.CountryNotice) then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryPublicNotice, { isNotice = false }, Const_UI_Lua.UIEnum.UIGuildPublicNotice) else CTL.Tips.AddTipsMsgAndPlaySound(Const_IDS.IDS_Guild_CommonFail4) end end end function UICountryMain:ShowPlayerInteract(index) local countryInfo = MDL.Country.GetFoundCountryInfo(index) local data = MDL.Country.GetCountryLeader(countryInfo.officialList) CTL.PlayerInteract.OpenFriendInteractView(data.showInfo.acid) end function UICountryMain:GetCountryLeaderInfo() local basicInfo = MDL.Country.GetStatueBasicInfo() if basicInfo then for i, v in ipairs(basicInfo) do if v.countryInfo.countryJobId == MDL.Country.CountryJob.CountryKing then local roleInfo = CTL.Player.RoleSceneBasicToCommonRoleInfo(v) return roleInfo end end end end function UICountryMain:ShowCountryReset() local playerInfo = self:GetCountryLeaderInfo() if playerInfo then UIUtils.SetActive(self.group_CountryInfo.gameObject, false) UIUtils.SetActive(self.group_CountryReset, true) local info = MDL.Country.GetKingCountry() local countryData = DataSheetManager.CountryBase:GetDataByID(info.countryID) UIUtils.SetImageByAssetBundle(self.img_Flag, countryData.LogoPath) UIUtils.SetLocalizationImage(self.img_Country, countryData.NamePath) CTL.Country.SetCountryState(self.state_Country, info.countryID) self.txt_Country.text = MDL.Country.GetCountryTitle(info.reignTitle, info.countryID) self.txt_PlayerName.text = playerInfo.name self.lab_ServerName.text = CTL.CrossServer.GetServerShowStr(playerInfo.ShowServerId) self.txt_TitleGuildName.text = playerInfo.EmblemContent self.txt_GuildName.text = playerInfo.guildName UTL.Item.SetAtlasSprite(self.ico_GuildBg, "UI_Guild", DataSheetManager.GuildEmblem:GetDataByID(playerInfo.EmblemFrame).Image) local closeTime = MDL.Country.GetAllStageTime()[MDL.Country.Stage.CountryReset + 1] local countDown = closeTime.stageEnd - UTL.Time.GetServerTimestamp() CTL.Country.SetTitleShow(self.titleTemplate) if countDown > 0 then local dayStr = string.FormatByIdsId(Const_IDS.IDS_Country_CeremonyCountdown, UIUtils.GetLocalizedTxt(Const_IDS.IDS_DirectGift_TimeHint_1)) local hourStr = string.FormatByIdsId(Const_IDS.IDS_Country_CeremonyCountdown, UIUtils.GetLocalizedTxt(Const_IDS.IDS_DirectGift_TimeHint_2)) local minStr = string.FormatByIdsId(Const_IDS.IDS_Country_CeremonyCountdown, UIUtils.GetLocalizedTxt(Const_IDS.IDS_DirectGift_TimeHint_3)) local secStr = string.FormatByIdsId(Const_IDS.IDS_Country_CeremonyCountdown, UIUtils.GetLocalizedTxt(Const_IDS.IDS_DirectGift_TimeHint_4)) self.txt_Countdown:SetDHMSStr(dayStr, hourStr, minStr, secStr) self.txt_Countdown:ResetAndBeginCustomTimer(false, countDown, 0, nil) end UIUtils.SetActive(self.group_Country, false) UTL.Item.SetLocalizationImage(self.hanCountry, self.han_Img, countryData.NamePath) UIUtils.SetLabelText(self.han_Txt, Const_IDS[countryData.CountryName]) if not self.initResetView then CTL.Country.SetRenderModel(self.modelComponentDataHandle, self.renderModel, playerInfo) self.initResetView = true CTL.Country.LvBuMoShenPlayAni(playerInfo.HeroID, playerInfo.HeroAppearanceID) end else UIUtils.SetActive(self.group_CountryReset, false) end end return UICountryMain