local UIHeroLightEffectTool = require "View/Common/UIHeroLightEffectTool" local UICountryOfficial = UIViewClass() local StandUpCount = 6 local Camera_StandUp = "Camera_StandUp" local Camera_Down = "Camera_Down" local ScenePos = {1078.98, 49.76, 487.46} local SceneRot = {0, 90, 0} function UICountryOfficial:OnOpened(context) self:RegistSystemEvent(EventID.Country_OnGetOfficialPanelInfo, self.OnGetOfficialPanelInfo) self:RegistSystemEvent(EventID.Country_OnCountrySetOfficial, self.OnCountrySetOfficial) self.playerSlots = {} self.curPlayingCameraName = nil self.curIsStandUp = true self.entityDict = {} self.heroInfoDict = {} self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.group_Frame) self:InitPanel() self:InitScene() MDL.Country.CountryGetOfficialPanelInfoReq() UIUtils.SetActive(self.Second_Floor.gameObject, false) UIUtils.SetActive(self.First_Floor.gameObject, true) end function UICountryOfficial:OnCreated() self.heroLightEffectDatas = UIHeroLightEffectTool.CreateHeroLightEffectDatas(true) end function UICountryOfficial:OnCountrySetOfficial(officialInfo) local info = MDL.Country.GetOfficialInfo() local removeInfo = nil for i, v in ipairs(info.officialList) do if v.showInfo.acid == officialInfo.showInfo.acid then removeInfo = v table.remove(info.officialList, i) break end end if self.curIsStandUp then if officialInfo.position ~= MDL.Country.CountryJob.CountryPopulace then local index = self:GetIndexByJobId(officialInfo.position) if index then self:SetPlayerInfo(officialInfo.showInfo, index, officialInfo.position) table.insert(info.officialList, officialInfo) end end if removeInfo then local index = self:GetIndexByJobId(removeInfo.position) if index then self:SetPlayerInfo(nil, index, removeInfo.position) end end else if officialInfo.position ~= MDL.Country.CountryJob.CountryPopulace then table.insert(info.officialList, officialInfo) self:SetPlayerInfo(officialInfo.showInfo, officialInfo.index + 1, officialInfo.position) else self:SetPlayerInfo(nil, removeInfo.index + 1, removeInfo.position) end end end function UICountryOfficial:OnGetOfficialPanelInfo() local info = MDL.Country.GetOfficialInfo() if info then self.group_Frame:DisposeAllEntity() self:StopHeroLightEffect() if self.curIsStandUp then self:ShowTopPlayer() else self:ShowDownPlayer() end end end function UICountryOfficial:ShowTopPlayer() local info = MDL.Country.GetOfficialInfo() if info then local officialList = info.officialList for k, v in pairs(MDL.Country.CountryJob) do if v < MDL.Country.CountryJob.CountryElite then local list = MDL.Country.GetCountryOfficial(officialList, v) local index = self:GetIndexByJobId(v) self:SetPlayerInfo(list[1] and list[1].showInfo, index, v) end end end end function UICountryOfficial:ShowDownPlayer() local info = MDL.Country.GetOfficialInfo() for i = 1, 6 do self:SetPlayerInfo(self:GetElitePlayInfo(i - 1), i, MDL.Country.CountryJob.CountryElite) end UIUtils.SetActive(self.Second_Floor.gameObject, true) UIUtils.SetActive(self.First_Floor.gameObject, false) end function UICountryOfficial:GetElitePlayInfo(index) local info = MDL.Country.GetOfficialInfo() local list = MDL.Country.GetCountryOfficial(info.officialList, MDL.Country.CountryJob.CountryElite) for i, v in ipairs(list) do if v.index == index then return v.showInfo end end end function UICountryOfficial:OnClosed() self:RecoverPosition() UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) self:StopHeroLightEffect() end function UICountryOfficial:RecoverPosition() for modelPos, v in pairs(self.playerSlots) do modelPos:SetLocalPosition(v.posX, v.posY, v.posZ) end end function UICountryOfficial:OnButtonClicked(comp) -- 播放动画时不能点击其他功能 if not string.isNilOrEmpty(self.curPlayingCameraName) then return end if comp == self.btn_Down then self:RecoverPosition() self.curPlayingCameraName = Camera_Down UIUtils.SetActive(self.btn_Down, false) UIUtils.SetActive(self.group_Main, false) self:PlayUIAnimation(self.curPlayingCameraName, true) elseif comp == self.btn_Up then self:RecoverPosition() self.curPlayingCameraName = Camera_StandUp UIUtils.SetActive(self.btn_Up, false) UIUtils.SetActive(self.group_Main, false) self:PlayUIAnimation(self.curPlayingCameraName, true) elseif comp == self.btn_Power then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryCheckPanel) else self:ClickAddBtn(comp) end end function UICountryOfficial:OnUIAnimationStoped(playingID) self.group_Frame:DisposeAllEntity() UTL.UIRender.DisposeWeaponSoul(self.modelComponentDataHandle) UIUtils.SetActive(self.group_Main, true) if self.curPlayingCameraName == Camera_Down then UIUtils.SetActive(self.btn_Up, true) self.curIsStandUp = false self.group_Main:SetState(1) self:ShowDownPlayer() elseif self.curPlayingCameraName == Camera_StandUp then UIUtils.SetActive(self.btn_Down, true) self.curIsStandUp = true self.group_Main:SetState(0) self:ShowTopPlayer() end self.curPlayingCameraName = nil end -------------------- function UICountryOfficial:InitScene() -- 加载场景 local data = MDL.Country.GetMyCountryInfo() local countryData = DataSheetManager.CountryBase:GetDataByID(data.countryID) UTL.UIRender.Create3DSceneTrans(self.modelComponentDataHandle, countryData.UIPath, 0, 0, 0, 0, 0, 0, UTL.UIRender.LayerActiveType.CountryOfficial) local locationTf = UTL.UIRender.GetSceneTrans(self.modelComponentDataHandle):Find("location") self.standUpModelParentTf = locationTf:Find("StandUp") self.downModelParentTf = locationTf:Find("Down") end function UICountryOfficial:SetPlayerInfo(headInfo, index, jobId) if headInfo then local modelPos = self.curIsStandUp and self.standUpModelParentTf:Find(index) or self.downModelParentTf:Find(index) --ipad 分辨率自适应问题导致的模型显示不准确需要手动矫正单独处理 local resolutionRatio = UIUtils.GetScreenResolutionRatio() if resolutionRatio == LuaConst.ScreenResolutionRatio.RatioPad4_3 or resolutionRatio == LuaConst.ScreenResolutionRatio.RatioPadOther then modelPos:SetLocalScale(1.35, 1.35, 1.35) local x ,y, z = modelPos:GetLocalPosition() local attr = { posX = x, posY = y, posZ = z } self.playerSlots[modelPos] = attr if index == 1 then x = x + 1.5 z = z - 0.6 elseif index == 2 then x = x + 1.7 z = z - 0.2 elseif index == 3 then x = x + 1.3 z = z + 0.15 elseif index == 4 then x = x + 2 z = z + 0.15 elseif index == 5 then x = x + 2 z = z + 0.45 else x = x + 2 z = z + 0.65 end modelPos:SetLocalPosition(x, y, z) end local modelPath, _, modelScale, animCtrlPath, heroEffectPath = UTL.UIRender.LoadRankListOtherHorseHero(headInfo) local renderEntity = UTL.UIRender.CreateRenderEntity(modelPos, modelPath, modelScale, animCtrlPath, true) local entityId = self.group_Frame:AddEntity(renderEntity) self.entityDict[index] = entityId self.heroInfoDict[index] = headInfo -- 加载饰品 self:StopHeroLightEffect() self:BeginHeroLightEffect(headInfo.lightEffectIds,{ modelPos = modelPos, isUseHighEffect = true }) -- 加载武器 local weaponId = headInfo.WeaponAppearanceID > 0 and headInfo.WeaponAppearanceID or headInfo.HeroID UTL.UIRender.LoadMagicWeapon(headInfo.HeroID, headInfo.WeaponAppearanceID, headInfo.MagicWeaponBreak, headInfo.IsActiveMagicWeapon, renderEntity, false) -- 切换武器光效 local battleModelId, effectLevel = UTL.UIRender.GetTownWeaponEffectId(headInfo.HeroID, headInfo.HeroBreakNums, headInfo.IsActiveMagicWeapon, headInfo.WeaponAppearanceID) UTL.UIRender.ChangeWeaponEffect(renderEntity, battleModelId, effectLevel) UTL.UIRender.SetRenderEntityDye(renderEntity, headInfo.HeroAppearanceID, headInfo.dyeCurPartList, 1) -- 加载武器 local weaponSoul = CTL.DivineWeaponForgeSoul.GetWeaponSoulSkillByProtoMap(headInfo.HeroID, headInfo.weaponSoul) if weaponSoul then UTL.UIRender.LoadWeaponSoulByEntity(self.modelComponentDataHandle, renderEntity, weaponSoul) end else local entityId = self.entityDict[index] if entityId then self.group_Frame:DisposeEntity(entityId) self.entityDict[index] = nil end end -- End 加载模型相关 End -- -- Start 设置UI Start -- self:SetPlayerUI(self.curIsStandUp and self.First_Floor[index] or self.Second_Floor[index], headInfo, jobId) end function UICountryOfficial:InitPanel() -- 初始化国别 local data = MDL.Country.GetMyCountryInfo() if data.countryID == MDL.Country.CountryType.Wei then self.state_Country:SetState(2) elseif data.countryID == MDL.Country.CountryType.Shu then self.state_Country:SetState(1) elseif data.countryID == MDL.Country.CountryType.Wu then self.state_Country:SetState(3) elseif data.countryID == MDL.Country.CountryType.Qun then self.state_Country:SetState(0) end UIUtils.SetLabel(self.txt_Country, MDL.Country.GetCountryTitle(data.reignTitle, data.countryID)) UIUtils.SetActive(self.btn_Up, false) UIUtils.SetActive(self.btn_Down, true) end function UICountryOfficial:SetPlayerUI(item, data, jobId) if data then -- 有英雄 item.state_Official:SetState(0) -- 区服 UIUtils.SetLabel(item.txt_Server, CTL.CrossServer.GetServerShowStr(data.ShowServerId)) --UIUtils.SetLabel(item.txt_Server, string.FormatByIdsId(Const_IDS.IDS_CrossSever_SeverSuffixText2, data.ShowServerId)) -- 势力 local emblemContent = data.EmblemContent if string.isNilOrEmpty(emblemContent) then UIUtils.SetActive(item.img_Emblem, false) else UIUtils.SetActive(item.img_Emblem, true) UIUtils.SetLabel(item.txt_Emblem, emblemContent) local guildEmblemCfg = DataSheetManager.GuildEmblem:GetDataByID(data.EmblemFrame) if guildEmblemCfg then UTL.Item.SetAtlasSprite(item.img_Emblem, "UI_Guild", guildEmblemCfg.Image) end end UIUtils.SetLabel(item.txt_Name, data.name) else -- 无英雄 if self:CanChangeJob(jobId) then -- 有权限设置 item.state_Official:SetState(2) else item.state_Official:SetState(1) end end -- 设置头衔 --todo repeat UIUtils.SetLabelText(item.txt_Position, Const_IDS[MDL.Country.GetJobName(jobId)]) UIUtils.SetImageByAssetBundle(item.img_Position, MDL.Country.GetJobImagePath(jobId)) end function UICountryOfficial:ClickAddBtn(comp) local floorObj = self.curIsStandUp and self.First_Floor or self.Second_Floor for i, v in ipairs(floorObj) do if comp == v.btn_Add then if self.entityDict[i] then -- 有英雄 CTL.PlayerInteract.OpenFriendInteractView(self.heroInfoDict[i].acid, MDL.PlayerInteract.OccasionType.CountryOfficial) else local jobId = self:GetJobIdByIndex(i) if not CTL.Country.ShowResetState() then if self.curIsStandUp then UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryPopupNationalAppoint, { jobId = jobId }) else UIManager.OpenView(Const_UI_Lua.UIEnum.UICountryPopupNationalAppoint, { jobId = jobId, index = i - 1 }) end end end break end end end function UICountryOfficial:CountryOfficialPlayModelEffect(path, param) return AuxUtil.PlayPsEffect(path, param.modelPos, 0) end function UICountryOfficial:GetJobIdByIndex(index) if self.curIsStandUp then for i, v in DataSheetManager.CountryJob:GetEnumerator() do if v.PosID == index then return v.ID end end else return MDL.Country.CountryJob.CountryElite end end function UICountryOfficial:GetIndexByJobId(jobId) return DataSheetManager.CountryJob:GetDataByID(jobId).PosID end function UICountryOfficial:CanChangeJob(targetJobId) return MDL.Country.CanChangeJobById(MDL.Country.GetMyJobId(), targetJobId) end function UICountryOfficial:StopHeroLightEffect(isDispose) UIHeroLightEffectTool.StopHeroLightEffect(self.heroLightEffectDatas) if isDispose then self.heroLightEffectDatas = nil end end function UICountryOfficial:BeginHeroLightEffect(heroLightEffects,param) for _, lightEffectID in ipairs(heroLightEffects) do UIHeroLightEffectTool.PlayHeroLightEffect(self.heroLightEffectDatas,self, 0, UIHeroLightEffectTool.PlayLightEffectFuncEnum.CountryOfficial,lightEffectID, param) end end return UICountryOfficial