local UIHeroLightEffectTool = require "View/Common/UIHeroLightEffectTool" local UIHeroShowPanel = UIViewClass() local EventSystem = require('Event/EventSystem') local LevelUpEffectPath = ConstAssetPathConfig.LevelUpEffectPath local PsGroupPath = ConstAssetPathConfig.PsGroupPath; local LvBuFaXiangCameraPath = ConstAssetPathConfig.LvBuFaXiangCameraPath local ToggleTypeMap = { [MDL.HeroSelect.ToggleViewNameList.Advanced] = UTL.Toggle.ToggleType.HeroFetterAdvanced, [MDL.HeroSelect.ToggleViewNameList.LevelUp] = UTL.Toggle.ToggleType.Upgrade, [MDL.HeroSelect.ToggleViewNameList.Awaken] = UTL.Toggle.ToggleType.HeroAwaken, [MDL.HeroSelect.ToggleViewNameList.Break] = UTL.Toggle.ToggleType.Breakthrough, [MDL.HeroSelect.ToggleViewNameList.AwakenSkill] = UTL.Toggle.ToggleType.HeroAwakenSkill, [MDL.HeroSelect.ToggleViewNameList.Strenthen] = UTL.Toggle.ToggleType.Strenthen, [MDL.HeroSelect.ToggleViewNameList.Relation] = UTL.Toggle.ToggleType.HeroFetter, [MDL.HeroSelect.ToggleViewNameList.Appearance] = UTL.Toggle.ToggleType.Appearance, [MDL.HeroSelect.ToggleViewNameList.Info] = UTL.Toggle.ToggleType.Information, } local ToggleIDSMap = { [MDL.HeroSelect.ToggleViewNameList.Advanced] = Const_IDS.IDS_HeroAdvance, [MDL.HeroSelect.ToggleViewNameList.LevelUp] = Const_IDS.IDS_HeroLevelUp, [MDL.HeroSelect.ToggleViewNameList.Awaken] = Const_IDS.IDS_HeroAwaken_FunctionName, [MDL.HeroSelect.ToggleViewNameList.Break] = Const_IDS.IDS_HeroStarUp, [MDL.HeroSelect.ToggleViewNameList.AwakenSkill] = Const_IDS.IDS_HeroAwaken_TianZi, [MDL.HeroSelect.ToggleViewNameList.Strenthen] = Const_IDS.IDS_HeroStrenthen_StrenthenBtn, [MDL.HeroSelect.ToggleViewNameList.Relation] = Const_IDS.IDS_Relation, [MDL.HeroSelect.ToggleViewNameList.Appearance] = Const_IDS.IDS_Appearance_Title, [MDL.HeroSelect.ToggleViewNameList.Info] = Const_IDS.IDS_HeroInfo, } local MouseScrollWheel = "Mouse ScrollWheel" local MouseScrollWheel = "Mouse ScrollWheel" -- TODO -- 优化前:进入界面时 会同时加载4国场景、加载展示模型、设置UI,峰值压力较大 -- 优化后:进入界面时 会先加载界面(不设置具体UI内容)、加载4国场景和展示模型、设置UI,尽量降低了峰值压力 -- 还存在的问题: -- 1、由于加载场景的接口没有单独拆分,所以加载场景和展示模是同时加载,峰值还是比较大, -- 后续将加载场景接口单独拆分,实现 加载UI(不设置具体UI内容)、加载场景、分帧加载武将、设置UI,以便进一步降低峰值压力 -- 2、使用分帧加载后。由于武将先加载、界面后设置,具体的表现效果有一点肉眼上的延迟 需要重新考虑效果 function UIHeroShowPanel:OnCreated() UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_HeroUIShow) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.OnFunctionUnlockUpdate) self:RegistSystemEvent(EventID.UI_HeroBreak_BreakSuccess, self.RefreshHeroModelBreakEffect) self:RegistSystemEvent(EventID.UI_HeroShow_PlayLevelUpEffect, self.PlayLevelUpEffect) self:RegistSystemEvent(EventID.UI_Appearance_ChangePreviewAppearance, self.ChangePreviewAppearance) -- 切换武将外观-时装 self:RegistSystemEvent(EventID.UI_HeroAwaken_ChangeAwakenShow, self.ChangeAwakenShow) self:RegistSystemEvent(EventID.UI_HeroAwaken_ReturnBreak, self.OnReturnBreak) self:RegistSystemEvent(EventID.UI_LightEffect_ChangePreviewLightEffect, self.ChangePreviewLightEffect) -- 切换武将外观-光效 self:RegistSystemEvent(EventID.UI_LightEffect_CheckLvBuFaXiangCamera, self.CheckLvBuFaXiangCameraSetting) -- 检查切换吕布法相摄像机 self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.heroShow) -- Start 增加角色旋转 self.CameraCtrl = CameraController.Instance self:RegistTriggerEvent(self.heroShow, UIEventTriggerType.Drag) self:RegistTriggerEvent(self.heroShow, UIEventTriggerType.EndDrag) -- End 增加角色旋转 self._distThreshold = 2 self.isClickCloseButton = false self.heroLightEffectDatas = UIHeroLightEffectTool.CreateHeroLightEffectDatas(true) self.lastEventData1 = nil self.lastEventData2 = nil self.lastEventDataPos1 = Vector2.zero self.lastEventDataPos2 = Vector2.zero if GameAppInfo.IsPCOrMacPackage() then self:StartRepeatFunc(self.UpdateInputMouseScrollWheel, 0, 0) end end function UIHeroShowPanel:UpdateInputMouseScrollWheel() local delta = Input.GetAxis(MouseScrollWheel) if math.abs(delta) < 0.001 then return end self.CameraCtrl:ScalingByManual(delta > 0) end function UIHeroShowPanel:OnDrag(comp, eventData) if Input.touchCount <= 1 then self.CameraCtrl:RotatingByManual(eventData.delta) else if not self.lastEventData1 then self.lastEventData1 = eventData self.lastEventDataPos1 = eventData.position elseif self.lastEventData1 ~= eventData then self.lastEventData2 = eventData self.lastEventDataPos2 = eventData.position end if not self.lastEventData1 or not self.lastEventData2 then return end local lastDistance = Vector2.Distance(self.lastEventDataPos1, self.lastEventDataPos2) local thisDistance = Vector2.Distance(self.lastEventData1.position, self.lastEventData2.position) if lastDistance ~= thisDistance then self.CameraCtrl:ScalingByManual(thisDistance>lastDistance) end self.lastEventDataPos1 = self.lastEventData1.position self.lastEventDataPos2 = self.lastEventData2.position end end function UIHeroShowPanel:OnEndDrag(comp, eventData) self.lastEventData1 = nil self.lastEventData2 = nil end function UIHeroShowPanel:OnFocusChanged(isFocus) if isFocus then CTL.HeroSelect.ForceOpenRelationPopup() end end function UIHeroShowPanel:PlayLevelUpEffect() CTL.Sound.PlayGameSound("UI_upgrade_01") --后续需要处理,一键升级返回时的音效 --CTL.Sound.PlayGameSound("UI_upgrade_02") UTL.UIRender.PlayModelPsEffect(self.modelComponentDataHandle, LevelUpEffectPath) end function UIHeroShowPanel:AddFuncToggle(toggleIDSArray, toggleTypeArray, type) table.insert(self.toggleTypeList, type) table.insert(toggleIDSArray, ToggleIDSMap[type]) table.insert(toggleTypeArray, ToggleTypeMap[type]) end function UIHeroShowPanel:RefreshToggleUnlock() local heroId = MDL.HeroSelect.curSelectHeroID self.toggleTypeList = {} local toggleIDS = {} local toggleType = {} --- 上阵武将显示全部养成页签 local isLineUp = MDL.Player.HeroIsLineUp(heroId) local isHasHero = MDL.HeroSelect.IsHasHero(heroId) if isLineUp then -- 进阶 if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Advanced) then self:AddFuncToggle(toggleIDS, toggleType, MDL.HeroSelect.ToggleViewNameList.Advanced) end -- 升级 self:AddFuncToggle(toggleIDS, toggleType, MDL.HeroSelect.ToggleViewNameList.LevelUp) end if isLineUp or isHasHero then -- 突破/觉醒 if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Break) then if CTL.HeroAwaken.IsShowHeroAwakenEntry(heroId) then self:AddFuncToggle(toggleIDS, toggleType, MDL.HeroSelect.ToggleViewNameList.Awaken) else self:AddFuncToggle(toggleIDS, toggleType, MDL.HeroSelect.ToggleViewNameList.Break) end end --觉醒技能 if MDL.HeroAwaken.GetIsHeroAwaken(heroId) then self:AddFuncToggle(toggleIDS, toggleType, MDL.HeroSelect.ToggleViewNameList.AwakenSkill) end -- 修炼 if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.HeroStrenthen) then self:AddFuncToggle(toggleIDS, toggleType, MDL.HeroSelect.ToggleViewNameList.Strenthen) end end -- 羁绊 if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.HeroRelation) then self:AddFuncToggle(toggleIDS, toggleType, MDL.HeroSelect.ToggleViewNameList.Relation) end -- 时装 if (MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.HeroAppearance) and MDL.Appearance.GetHasAppearanceByHeroID(MDL.HeroSelect.curSelectHeroID, MDL.Appearance.AppearanceType.Hero)) or MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.LightEffect) then self:AddFuncToggle(toggleIDS, toggleType, MDL.HeroSelect.ToggleViewNameList.Appearance) end self:AddFuncToggle(toggleIDS, toggleType, MDL.HeroSelect.ToggleViewNameList.Info) UTL.Toggle.InitToggleGroupByIDS(self.toggles_Group, "txt", toggleIDS) for i, ttype in ipairs(toggleType) do self.toggles_Group:SetToggleCompImage(i, "img_bg_icon", UTL.Toggle.GetToggleNormalIcon(ttype)) self.toggles_Group:SetToggleCompImage(i, "img_SelectedIcon1", UTL.Toggle.GetToggleSelectedIcon(ttype)) end end function UIHeroShowPanel:OnClickTownButton() if self.initBlend then UTL.UIRender.SetBlendTime(self.modelComponentDataHandle, 0.5) end self.isClickCloseButton = self.isFormation self:CloseView(true) end function UIHeroShowPanel:OnOpened(context) MDL.HeroSelect.isWearingLvBuFaXiangCamera = false self.isFirstOpen = true self:UpdateHeroShow() self:InitHero() self:StartRepeatFunc(self.DelayInitPanel, 0.12, 1) UIManager.ActiveUIModle(false, "UIHeroShowPanel") CTL.Setting.SetUIShadowDistance(6) CTL.Setting.Set5SSkin(true) end function UIHeroShowPanel:InitHero() local heroId = MDL.HeroSelect.curSelectHeroID local isAwaken = false if self.context then isAwaken = self.context.subViewName == MDL.HeroSelect.ToggleViewNameList.Awaken end if isAwaken and MDL.HeroAwaken.GetIsHeroAwaken(MDL.HeroSelect.curSelectHeroID) == false then self:SetAwakenModel() return end self:StopHeroLightEffect() local scenePath, modelPath, equipTable, modelScale, lightPath, heroEffectPath, heroLightEffects = CTL.HeroDetail.GetHeroShowDetail(heroId) -- 卸载之前的模型 UTL.UIRender.DisposePlayerModel(self.modelComponentDataHandle) -- 初始场景 self:UpdateSceneShow(isAwaken and MDL.HeroSelect.ToggleViewNameList.Awaken) -- 模型设置 UTL.UIRender.CreatePlayerModel(self.modelComponentDataHandle, heroId, nil, nil, true) -- 铸魂天命 if MDL.DivineWeaponForgeSoul.IsWeaponSoulActive(heroId) then UTL.UIRender.LoadPlayerWeaponSoul(self.modelComponentDataHandle, MDL.DivineWeaponForgeSoul.GetWeaponForgeSoulSkillsLv(heroId)) end self.modelPath = modelPath; self:BeginHeroLightEffect(heroLightEffects) self:CheckLvBuFaXiangCameraSetting() end function UIHeroShowPanel:DelayInitPanel() local heroId = MDL.HeroSelect.curSelectHeroID local subViewName if CTL.Formation.IsHeroInFormation(heroId) then subViewName = MDL.HeroSelect.ToggleViewNameList.Advanced else subViewName = MDL.HeroSelect.ToggleViewNameList.Info end if self.context then self.isFormation = self.context.isFormation self.ifBlend = self.context.ifBlend self.initBlend = self.context.initBlend subViewName = self.context.subViewName self.appearanceType = self.context.appearanceType self.lightEffectID = self.context.lightEffectID self.fashionID = self.context.fashionID self.isHideArrow = self.context.isHideArrow or false end MDL.HeroSelect.SortHeroOrder() self:RegistSystemEvent(EventID.UI_HeroShow_UpdateHeroShow, self.UpdateHeroShow) self:RegistSystemEvent(EventID.UI_RefreshHeroExp, self.UpdateRedPoint) self:RegistSystemEvent(EventID.BagItem_Update, self.UpdateRedPoint) self:RegistSystemEvent(EventID.UI_Appearance_Refresh, self.UpdateRedPoint) self:RegistSystemEvent(EventID.UI_LightEffect_Refresh, self.UpdateRedPoint) self:RegistSystemEvent(EventID.UI_HeroAwaken_UpdateHeroSkillPoint, self.UpdateRedPoint) self:RegistSystemEvent(EventID.UI_HeroAwaken_NoticeEnableAwake, self.UpdateRedPoint) self:RegistSystemEvent(EventID.UI_HeroBreak_Breakthrough, self.UpdateRedPoint) self:RegistSystemEvent(EventID.UI_HeroAwaken_UpdateTaskInfo, self.UpdateRedPoint) self:RegistSystemEvent(EventID.UI_Appearance_ChangePreviewAppearance, self.ChangePreviewAppearance) -- 切换武将外观 self:RegistSystemEvent(EventID.UI_HeroShow_SwitchHeroById, self.SwitchHeroById) if UNITY_EDITOR then AuxUtil.AddMouseEventHelper(self.gameObject) end if self.ifBlend then UTL.UIRender.SetBlendTime(self.modelComponentDataHandle, 0.5) self.context.initBlend = true self.context.ifBlend = false end UIUtils.SetActive(self.img_Previewing, false) --默认选中显礼要求 非上阵武将 默认选中第一个 local index = self.context and self.context.toggleIndex for i, v in ipairs(self.toggleTypeList) do if v == subViewName then index = i end end if index then self.toggles_Group:SelectIndex(index - 1) else self.toggles_Group:SelectIndex(0) end if CTL.HeroSelect.GetIsHeroAppearanceViewToHeroShow() then CTL.HeroSelect.SetIsHeroAppearanceViewToHeroShow(false) else self.soundId = CTL.Sound.PlayGameSound(CTL.HeroSelect.GetHeroSound(heroId, "CultivateSound")) end --CameraController.Instance:SetDOF(true, 2.5, 7, 53, 4) self.dragDict = {} end function UIHeroShowPanel:OnValueChanged(comp, index) if comp == self.toggles_Group then local toggleIndex = index + 1 local type = self.toggleTypeList[toggleIndex] self:OnSwitchTabType(type, toggleIndex) self:UpdateSceneShow(type) end end function UIHeroShowPanel:OnSwitchTabType(type, toggleIndex) if type ~= MDL.HeroSelect.ToggleViewNameList.Appearance or self.lastSelectTabType == type then CTL.Appearance.CurAppearanceIndex = 0 end self.lastSelectTabType = type if type == MDL.HeroSelect.ToggleViewNameList.AwakenSkill then UIUtils.SetActive(self.group_root, false) UTL.UIRender.DisposePlayerModel(self.modelComponentDataHandle) else UIUtils.SetActive(self.group_root, true) end if self.heroSubView then self.heroSubView:CloseView() end if type == MDL.HeroSelect.ToggleViewNameList.Appearance then self.heroSubView = self.panelRoot:OpenView(GetViewClass(type), {appearanceType = self.appearanceType, lightEffectID = self.lightEffectID, fashionID = self.fashionID, parentView = self}) self.appearanceType = nil self.lightEffectID = nil self.fashionID = nil else self.heroSubView = self.panelRoot:OpenView(GetViewClass(type), {parentView = self}) end if self.context then self.context.toggleIndex = toggleIndex self.context.subViewName = type else self.context = { toggleIndex = toggleIndex, subViewName = type } end end function UIHeroShowPanel:OnClosed() CTL.Setting.SetUIShadowDistance(0) CTL.Setting.Set5SSkin(false) if not self.isClickCloseButton then UTL.UIRender.CancelBlend(self.modelComponentDataHandle) end UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) UIManager.ActiveUIModle(true, "UIHeroShowPanel") if self.soundId then CTL.Sound.StopById(self.soundId) end self:StopHeroLightEffect(true) self:SetActiveLvBuFaXiangCamera(false,true) self.parentTrans = nil --CameraController.Instance:SetDOF(false, 2.5, 7, 53, 4) UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) end function UIHeroShowPanel:UpdateSceneShow(switchType) if switchType and switchType == MDL.HeroSelect.ToggleViewNameList.Awaken then local scenePath = CTL.HeroDetail.GetHeroShowDetail(MDL.HeroSelect.curSelectHeroID, true) UTL.UIRender.Create3DSceneTrans(self.modelComponentDataHandle, scenePath, 2000, 0, 2000, 0, 327, 0, UTL.UIRender.LayerActiveType.HeroShow) if scenePath == CTL.HeroDetail.AWAKEN_SCENE_PATH then UTL.UIRender.SetSceneTransPosition(self.modelComponentDataHandle, 2000, -50, 2000) UTL.UIRender.SetSceneTransRotation(self.modelComponentDataHandle, 150) end else local scenePath = CTL.HeroDetail.GetHeroShowDetail(MDL.HeroSelect.curSelectHeroID) UTL.UIRender.Create3DSceneTrans(self.modelComponentDataHandle, scenePath, 2000, 0, 2000, 0, 327, 0, UTL.UIRender.LayerActiveType.HeroShow) end end function UIHeroShowPanel:SwitchHeroById(heroId) MDL.HeroSelect.curSelectHeroID = heroId self:StopHeroLightEffect() EventSystem.Dispatch(EventID.UI_HeroShow_UpdateHeroShow, true) local scenePath, modelPath, equipTable, modelScale, lightPath, heroEffectPath, heroLightEffects = CTL.HeroDetail.GetHeroShowDetail(heroId) self.modelPath = modelPath; -- 卸载之前的模型 UTL.UIRender.DisposePlayerModel(self.modelComponentDataHandle) UTL.UIRender.SetBlendTime(self.modelComponentDataHandle, 0) --强制执行一次OnLayerActive true 重置虚拟相机位置 self.heroShow.curActive = false local index, switchType = self:GetTargetIndex() -- 更换场景 self:UpdateSceneShow(switchType) --由于这里强制重置了,当前如果为法相相机也需要重置掉 self:SetActiveLvBuFaXiangCamera(false, true) -- 模型设置 UTL.UIRender.CreatePlayerModel(self.modelComponentDataHandle, heroId, nil, nil, true) -- 铸魂天命 if MDL.DivineWeaponForgeSoul.IsWeaponSoulActive(heroId) then UTL.UIRender.LoadPlayerWeaponSoul(self.modelComponentDataHandle, MDL.DivineWeaponForgeSoul.GetWeaponForgeSoulSkillsLv(heroId)) end -- 更换场景 self.soundId = CTL.Sound.PlayGameSound(CTL.HeroSelect.GetHeroSound(heroId, "CultivateSound")) if index then if index > 1 then self.toggles_Group:SelectIndex(index - 1) else self.toggles_Group:SelectIndex(0) end else self.toggles_Group:SelectIndex(0) end self:BeginHeroLightEffect(heroLightEffects) self:CheckLvBuFaXiangCameraSetting() end function UIHeroShowPanel:GetTargetIndex() if self.lastSelectTabType then local index = self:GetToggleTypeIndex(self.lastSelectTabType) if index then return index, self.lastSelectTabType else local switchType if self.lastSelectTabType == MDL.HeroSelect.ToggleViewNameList.Awaken then switchType = MDL.HeroSelect.ToggleViewNameList.Break elseif self.lastSelectTabType == MDL.HeroSelect.ToggleViewNameList.Break then switchType = MDL.HeroSelect.ToggleViewNameList.Awaken end if switchType then index = self:GetToggleTypeIndex(switchType) end return index, switchType end end return nil end function UIHeroShowPanel:RefreshHeroModelBreakEffect(heroId) -- 已废弃,但是数据还在所以不删除只注释掉 --local heroEffectPath = DataSheetManager.HeroStar:GetDataByHeroID_Star(heroId, MDL.HeroStar.GetHeroStarLevel(heroId)).HeroStarShowEffect --self.heroShow:RefreshHeroEffect(heroEffectPath) end function UIHeroShowPanel:OnClickLastHero() local heroId = MDL.HeroSelect.curSelectHeroID local pendingCount = MDL.HeroSelect.GetPendingActiveCount() if MDL.HeroSelect.IsHasHero(heroId) then --通过ID获取上一个显示的武将的Index local lastIndex = MDL.HeroSelect.GetSortedHeroDataIndex(heroId) - 1 --上一个索引 if lastIndex <= pendingCount then if self.isFormation then lastIndex = MDL.Player.GetLineUpHeroCount() + pendingCount else lastIndex = MDL.HeroSelect.GetLastHasHeroIndex() end end self:SwitchHeroById(MDL.HeroSelect.GetSortedHeroIdByIndex(lastIndex)) else local unactiveHeroData = MDL.HeroSelect.GetUnactiveHeroData() local lastIndex = MDL.HeroSelect.GetHeroIndexById(unactiveHeroData, heroId) - 1 if lastIndex < 1 then lastIndex = #unactiveHeroData end self:SwitchHeroById(unactiveHeroData[lastIndex].ID) end end function UIHeroShowPanel:OnClickNextHero() local heroId = MDL.HeroSelect.curSelectHeroID local pendingCount = MDL.HeroSelect.GetPendingActiveCount() if MDL.HeroSelect.IsHasHero(heroId) then local lastHasHeroIndex = MDL.HeroSelect.GetLastHasHeroIndex() --通过ID获取下一个显示的武将的Index local nextIndex = MDL.HeroSelect.GetSortedHeroDataIndex(heroId) + 1 if self.isFormation then if nextIndex > lastHasHeroIndex or not MDL.Player.HeroIsLineUp(MDL.HeroSelect.GetSortedHeroIdByIndex(nextIndex)) then nextIndex = 1 + pendingCount end else if nextIndex > lastHasHeroIndex then nextIndex = 1 + pendingCount end end self:SwitchHeroById(MDL.HeroSelect.GetSortedHeroIdByIndex(nextIndex)) else local unactiveHeroData = MDL.HeroSelect.GetUnactiveHeroData() local nextIndex = MDL.HeroSelect.GetHeroIndexById(unactiveHeroData, heroId) + 1 if nextIndex > #unactiveHeroData then nextIndex = 1 end self:SwitchHeroById(unactiveHeroData[nextIndex].ID) end end function UIHeroShowPanel:UpdateRedPoint() local heroId = MDL.HeroSelect.curSelectHeroID self:UpdateSwitchArrowRedPoint(heroId) self:UpdateToggleRedPoint(heroId) end function UIHeroShowPanel:UpdateSwitchArrowRedPoint(heroId) if not MDL.HeroSelect.IsHasHero(heroId) then self.btn_NextHero:SetRedPoint(false) self.btn_LastHero:SetRedPoint(false) UIUtils.SetActive(self.btn_NextHero, not (MDL.HeroSelect.GetHeroUnActiveCount() == 1) and not self.isHideArrow) UIUtils.SetActive(self.btn_LastHero, not (MDL.HeroSelect.GetHeroUnActiveCount() == 1) and not self.isHideArrow) return end local index = MDL.HeroSelect.GetSortedHeroDataIndex(heroId) local nextIndex = index + 1 local lastIndex = index - 1 local finalHeroIndex = MDL.HeroSelect.GetLastHasHeroIndex() local pendingCount = MDL.HeroSelect.GetPendingActiveCount() if self.isFormation then if nextIndex > finalHeroIndex or not MDL.Player.HeroIsLineUp(MDL.HeroSelect.GetSortedHeroIdByIndex(nextIndex)) then nextIndex = 1 + pendingCount end else if nextIndex > finalHeroIndex then nextIndex = 1 + pendingCount end end if lastIndex < 1 + pendingCount then if self.isFormation then lastIndex = MDL.Player.GetLineUpHeroCount() + pendingCount else lastIndex = finalHeroIndex end end local heroId = MDL.HeroSelect.curSelectHeroID local nextHeroId = MDL.HeroSelect.GetSortedHeroIdByIndex(nextIndex) if heroId ~= nextHeroId then UIUtils.SetActive(self.btn_NextHero, true and not self.isHideArrow) local isBreak = MDL.HeroSelect.IsHasHero(nextHeroId) and CTL.HeroStar.IsHeroCanBreakthrough(nextHeroId) local isRankUp = MDL.Player.HeroIsLineUp(nextHeroId) and (CTL.HeroSelect.IsBagExpEnoughLevelUp(nextHeroId) or MDL.HeroSelect.IsCanRankUp(nextHeroId)) or false local isAdvance = MDL.Player.HeroIsLineUp(nextHeroId) and (MDL.Advanced.IsHeroCanAdvance(nextHeroId) or MDL.Advanced.IsHeroCanGatherToAdvance(nextHeroId)) or false if MDL.Player.HeroIsLineUp(nextHeroId) then self.btn_NextHero:SetRedPoint(isBreak or isRankUp or isAdvance) UIUtils.SetActive(self.next_YelPoint, false) else self.btn_NextHero:SetRedPoint(false) UIUtils.SetActive(self.next_YelPoint, isBreak or isRankUp or isAdvance) end else UIUtils.SetActive(self.btn_NextHero, false and not self.isHideArrow) end local lastHeroId = MDL.HeroSelect.GetSortedHeroIdByIndex(lastIndex) if heroId ~= lastHeroId then UIUtils.SetActive(self.btn_LastHero, true and not self.isHideArrow) local isBreak = MDL.HeroSelect.IsHasHero(lastHeroId) and CTL.HeroStar.IsHeroCanBreakthrough(lastHeroId) local isRankUp = MDL.Player.HeroIsLineUp(lastHeroId) and (CTL.HeroSelect.IsBagExpEnoughLevelUp(lastHeroId) or MDL.HeroSelect.IsCanRankUp(lastHeroId)) or false local isAdvance = MDL.Player.HeroIsLineUp(lastHeroId) and (MDL.Advanced.IsHeroCanAdvance(lastHeroId) or MDL.Advanced.IsHeroCanGatherToAdvance(lastHeroId)) or false self.btn_LastHero:SetRedPoint(isBreak or isRankUp or isAdvance) if MDL.Player.HeroIsLineUp(lastHeroId) then self.btn_LastHero:SetRedPoint(isBreak or isRankUp or isAdvance) UIUtils.SetActive(self.last_YelPoint, false) else self.btn_LastHero:SetRedPoint(false) UIUtils.SetActive(self.last_YelPoint, isBreak or isRankUp or isAdvance) end else UIUtils.SetActive(self.btn_LastHero, false and not self.isHideArrow) end end --更新武将信息 function UIHeroShowPanel:UpdateHeroShow() local heroId = MDL.HeroSelect.curSelectHeroID self:RefreshToggleUnlock(heroId) self:UpdateSwitchArrowRedPoint(heroId) self:UpdateToggleRedPoint(heroId) self:UpdateWeaponInfo(heroId) local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) CTL.HeroSelect.SetHeroName(heroId, self.loc_Name, self.img_Name, self.txt_Name) if MDL.HeroAwaken.GetIsHeroAwaken(heroId) then self.effect_name:PlayUIEffect() UIUtils.SetActive(self.awaken_name_bg, true) else self.effect_name:StopUIEffect() UIUtils.SetActive(self.awaken_name_bg, false) end if self.loc_Name.CurState == 0 then UIUtils.SetLocalizationImage(self.img_Country, "country_"..heroData.Kingdom..".png") else UIUtils.SetLocalizationImage(self.img_CountryLoc, "country_"..heroData.Kingdom..".png") self.img_CountryLoc:SetNativeSize() end UIUtils.SetLabel(self.txt_Intelligence, CTL.HeroSelect.GetHeroIntelligence(heroId)) --设置英雄资质 CTL.HeroSelect.ShowCV(self.txt_CV, heroId) end --红点机制刷新toggle,有待扩充 function UIHeroShowPanel:UpdateToggleRedPoint(heroId) self.toggles_Group:SetAllRedPoint(false) -- 是否上阵 if MDL.Player.HeroIsLineUp(heroId) then --武将升级页面 if CTL.HeroSelect.IsBagExpEnoughLevelUp(heroId) or MDL.HeroSelect.IsCanRankUp(heroId) then self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.LevelUp, true) else self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.LevelUp, false) end --武将进阶页面 if MDL.Advanced.IsHeroCanAdvance(heroId) or MDL.Advanced.IsHeroCanGatherToAdvance(heroId) then self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Advanced, true) else self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Advanced, false) end -- 时装 - 这里需要两个判断条件,功能解锁和武将是否有皮肤 if (MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.LightEffect) and CTL.LightEffect.IsShowLightEffectRedPoint(heroId)) -- 光效 or (MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.HeroAppearance) and MDL.Appearance.GetHasAppearanceByHeroID(heroId, MDL.Appearance.AppearanceType.Hero)) then -- 时装 self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Appearance, CTL.Appearance.IsShowAppearanceRedPoint(heroId) or CTL.LightEffect.IsShowLightEffectRedPoint(heroId)) else self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Appearance, false) end -- 武将突破页面 if CTL.HeroStrenthen.CalculateAllRedPoint(heroId) then self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Strenthen, true) else self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Strenthen, false) end end -- 是否激活 if MDL.HeroSelect.IsHasHero(heroId) then --武将突破页面 if CTL.HeroStar.IsHeroCanBreakthrough(heroId) then self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Break, true) else self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Break, false) end if CTL.HeroAwaken.CheckAwakenRed(heroId) then self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Awaken, true) else self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Awaken, false) end if CTL.HeroAwaken.CheckHeroSkillRed(heroId) then self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.AwakenSkill, true) else self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.AwakenSkill, false) end -- 时装 - 这里需要两个判断条件,功能解锁和武将是否有皮肤 if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.LightEffect) -- 光效 or (MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.HeroAppearance) and MDL.Appearance.GetHasAppearanceByHeroID(heroId, MDL.Appearance.AppearanceType.Hero)) then -- 时装 self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Appearance, CTL.Appearance.IsShowAppearanceRedPoint(heroId) or CTL.LightEffect.IsShowLightEffectRedPoint(heroId)) else self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Appearance, false) end -- 武将突破页面 if CTL.HeroStrenthen.CalculateAllRedPoint(heroId) then self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Strenthen, true) else self:RefreshToggleRedPoint(MDL.HeroSelect.ToggleViewNameList.Strenthen, false) end end end function UIHeroShowPanel:GetToggleTypeIndex(type) for i, v in ipairs(self.toggleTypeList) do if v == type then return i end end return nil end function UIHeroShowPanel:RefreshToggleRedPoint(type, value) local index = self:GetToggleTypeIndex(type) if index then if type == MDL.HeroSelect.ToggleViewNameList.Appearance and not CTL.HeroSelect.IsSkipHeroRedPoint(MDL.HeroSelect.curSelectHeroID) then self.toggles_Group:SetRedPoint(index - 1, value) self.toggles_Group:SetToggleCompActive(index, "img_YelPoint", false) else if MDL.Player.HeroIsLineUp(MDL.HeroSelect.curSelectHeroID) then self.toggles_Group:SetRedPoint(index - 1, value) self.toggles_Group:SetToggleCompActive(index, "img_YelPoint", false) else self.toggles_Group:SetRedPoint(index - 1, false) self.toggles_Group:SetToggleCompActive(index, "img_YelPoint", value) end end end end function UIHeroShowPanel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIHeroShowPanel:OnButtonClicked(obj) if (obj == self.btn_LastHero) then self:OnClickLastHero() elseif (obj == self.btn_NextHero) then self:OnClickNextHero() elseif obj == self.UITemplateTitlePanel.btn_close then self:OnClickTownButton() elseif obj == self.group_Artifact.Button then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIDivineWeaponBasePanel, { data = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(MDL.HeroSelect.curSelectHeroID) }) elseif obj == self.UITemplateTitlePanel.btn_Home then if self.initBlend then UTL.UIRender.SetBlendTime(self.modelComponentDataHandle, 0.5) end CTL.Formation.TempSelectedHeroId = nil MDL.HeroSelect.curSelectHeroID = 0 CTL.HomeMain.CloseViewBackHomeMain() end end --未觉醒前要显示觉醒模型 function UIHeroShowPanel:ChangeAwakenShow(isOpen) if MDL.HeroAwaken.GetIsHeroAwaken(MDL.HeroSelect.curSelectHeroID) == false then if isOpen then self:SetAwakenModel() else self:ChangePreviewAppearance(MDL.HeroSelect.GetAppearanceIDByHeroID(MDL.HeroSelect.curSelectHeroID), nil, MDL.HeroSelect.ToggleViewNameList.Awaken) end end end function UIHeroShowPanel:SetAwakenModel() local awakenHeroData = DataSheetManager.AwakenHeroNum:GetDataByID(MDL.HeroSelect.curSelectHeroID) local appearanceID = awakenHeroData.HeroAppearance local weaponAppearanceID = awakenHeroData.WeaponAppearance self:ChangePreviewAppearance(appearanceID, weaponAppearanceID, MDL.HeroSelect.ToggleViewNameList.Awaken) end function UIHeroShowPanel:OnReturnBreak(isBreak) if self.heroSubView then self.heroSubView:CloseView() end if isBreak then self.heroSubView = self.panelRoot:OpenView(GetViewClass(MDL.HeroSelect.ToggleViewNameList.Break), {parentView = self}) else self.heroSubView = self.panelRoot:OpenView(GetViewClass(MDL.HeroSelect.ToggleViewNameList.Awaken), {parentView = self}) end end -- 这里只是外观预览切换模型 function UIHeroShowPanel:ChangePreviewAppearance(AppearanceID, weaponAppearanceID, switchType) self:StopHeroLightEffect() local scenePath, modelPath, equipTable, modelScale, lightPath, heroEffectPath, heroLightEffects = CTL.HeroDetail.GetHeroShowDetail(MDL.HeroSelect.curSelectHeroID) self.modelPath = modelPath; local heroData, monsterData = {}, {} local intelligence = CTL.HeroSelect.GetHeroIntelligence(MDL.HeroSelect.curSelectHeroID) if AppearanceID > 0 then --时装资源没下载好,显示原皮 if CTL.HotFix.CanHeroLoad(MDL.HeroSelect.curSelectHeroID, true, AppearanceID) then heroData = DataSheetManager.HeroAppearance:GetDataByID(AppearanceID) else heroData = DataSheetManager.HeroNum:GetDataByID(MDL.HeroSelect.curSelectHeroID) end monsterData = DataSheetManager.MonsterModelData:GetDataByID(heroData.PreviewModel) else heroData = DataSheetManager.HeroNum:GetDataByID(MDL.HeroSelect.curSelectHeroID) monsterData = DataSheetManager.MonsterModelData:GetDataByID(heroData.PreviewModel) end local heroModelEffect = "" if not string.isNilOrEmpty(monsterData.ModelPsEffect) then heroModelEffect = monsterData.ModelPsEffect end self.modelPath = monsterData.Path if SettingAPI.deviceLevel == 0 then lightPath = heroData.PreviewModelLight else lightPath = heroData.PreviewModelLight_New end -- 卸载之前的模型 UTL.UIRender.DisposePlayerModel(self.modelComponentDataHandle) -- 更换场景 self:UpdateSceneShow(switchType) -- 模型设置 UTL.UIRender.CreatePlayerModel(self.modelComponentDataHandle, MDL.HeroSelect.curSelectHeroID, monsterData.Path, lightPath, true, heroModelEffect, weaponAppearanceID, true) local partList = MDL.DyeAppearance.GetDyeAppearancePartList(AppearanceID) if partList then UTL.UIRender.SetModelDye(self.modelComponentDataHandle, AppearanceID, partList, 2) end -- 铸魂天命 if MDL.DivineWeaponForgeSoul.IsWeaponSoulActive(MDL.HeroSelect.curSelectHeroID) then UTL.UIRender.LoadPlayerWeaponSoul(self.modelComponentDataHandle, MDL.DivineWeaponForgeSoul.GetWeaponForgeSoulSkillsLv(MDL.HeroSelect.curSelectHeroID)) end UIUtils.SetLabel(self.txt_Intelligence, intelligence) --设置英雄资质 -- 预览中 local appearanceWearID = MDL.HeroSelect.GetAppearanceIDByHeroID(MDL.HeroSelect.curSelectHeroID) UIUtils.SetActive(self.img_Previewing, appearanceWearID ~= AppearanceID) self:BeginHeroLightEffect(heroLightEffects) end -- 预览外观光效 function UIHeroShowPanel:ChangePreviewLightEffect(lightEffectID) self:StopHeroLightEffect() local selectedlightEffects = {} if type(lightEffectID) == 'number' then if lightEffectID > 0 then table.insert(selectedlightEffects, lightEffectID) end elseif type(lightEffectID) == 'table' then for _, value in ipairs(lightEffectID) do table.insert(selectedlightEffects, value) end end local heroLightEffects = self:HandleHeroLightEffect(selectedlightEffects) self:BeginHeroLightEffect(heroLightEffects) self:CheckLvBuFaXiangCameraSetting(heroLightEffects) end --将玩家身上的同类型光效替换 function UIHeroShowPanel:HandleHeroLightEffect(selectedlightEffects) local heroLightEffects = MDL.LightEffect.GetHeroWearLightEffectIDList(MDL.HeroSelect.curSelectHeroID) local lightEffects = {} for _, effectId in ipairs(selectedlightEffects) do table.insert(lightEffects, effectId) end if heroLightEffects then for _, id in ipairs(heroLightEffects) do local flag = true local lightEffect1Data = DataSheetManager.LightEffect:GetDataByID(id) for _, effectId in ipairs(selectedlightEffects) do local lightEffect2Data = DataSheetManager.LightEffect:GetDataByID(effectId) if lightEffect1Data.Type == lightEffect2Data.Type then flag = false break end end if flag then table.insert(lightEffects, id) end end end return lightEffects end function UIHeroShowPanel:StopHeroLightEffect(isDispose) UIHeroLightEffectTool.StopHeroLightEffect(self.heroLightEffectDatas) if isDispose then self.heroLightEffectDatas = nil end end function UIHeroShowPanel:BeginHeroLightEffect(heroLightEffects) for _, lightEffectID in ipairs(heroLightEffects) do UIHeroLightEffectTool.PlayHeroLightEffect(self.heroLightEffectDatas, self, 0, UIHeroLightEffectTool.PlayLightEffectFuncEnum.LuaView, lightEffectID, nil) end end -- 拉远摄像机根据配置 function UIHeroShowPanel:CheckLvBuFaXiangCameraSetting(previewLightEffectId) local useCamera = false if previewLightEffectId then useCamera = CTL.LightEffect.CheckHeroUseEffectIsUseFXCamera(previewLightEffectId) else --非预览时判断自身是否有使用 local heroLightEffects = MDL.LightEffect.GetHeroWearLightEffectIDList(MDL.HeroSelect.curSelectHeroID) useCamera = CTL.LightEffect.CheckHeroUseEffectIsUseFXCamera(heroLightEffects) end local isImmediate = false if self.isFirstOpen then isImmediate = true self.isFirstOpen = false end self:SetActiveLvBuFaXiangCamera(useCamera, isImmediate) end function UIHeroShowPanel:SetActiveLvBuFaXiangCamera(isActive,isImmediate) if isActive then -- parentTrans的查找结果是会变化的,不能缓存 self.parentTrans = UTL.UIRender.TryGetModelRoot(self.modelComponentDataHandle) if not MDL.HeroSelect.isWearingLvBuFaXiangCamera then --先把摄像机切回到默认的,直接切容易导致镜头天旋地转的bug UIModelUtils.SetVirtualCamera(LuaConst.VirtualCameraType.UIShowVirtualCamera, self.parentTrans, 0) self.lvbuFaXiangCamera = UIModelUtils.LoadTargetCamera(LvBuFaXiangCameraPath, self.parentTrans, isImmediate and 0 or 0.5) MDL.HeroSelect.isWearingLvBuFaXiangCamera = true end else if MDL.HeroSelect.isWearingLvBuFaXiangCamera then UIModelUtils.ReturnTargetCamera(LvBuFaXiangCameraPath, self.lvbuFaXiangCamera) UIModelUtils.SetVirtualCamera(LuaConst.VirtualCameraType.UIShowVirtualCamera, self.parentTrans, isImmediate and 0 or 0.5) MDL.HeroSelect.isWearingLvBuFaXiangCamera = false end end end function UIHeroShowPanel:AuxUtilPlayPsEffect(effectPath) return UTL.UIRender.PlayPsEffect(self.modelComponentDataHandle, effectPath) end function UIHeroShowPanel:UpdateWeaponInfo(id) if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Weapon) then UIUtils.SetActive(self.group_Artifact.gameObject, false) return end UIUtils.SetActive(self.group_Artifact.gameObject, true) local heroInfo = MDL.HeroSelect.GetHeroInfo(id) if heroInfo then self:SetDivineWeaponItem(id, heroInfo.isMagicWeaponActive, heroInfo.magicWeaponLevel) UIUtils.SetActive(self.group_Artifact.img_Upgrade, CTL.DivineWeapon.IfDivineWeaponCanUpgrade(id)) UIUtils.SetActive(self.group_Artifact.gameObject, true) else UIUtils.SetActive(self.group_Artifact.gameObject, false) end end --设置神兵格子 function UIHeroShowPanel:SetDivineWeaponItem(heroId, isActive, level) local comp = self.group_Artifact local data = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(heroId) local isAwaken = MDL.HeroAwaken.GetIsWeaponAwaken(heroId) UTL.Color.SetQualityImageByType(comp.img_Kuang, CTL.HeroAwaken.GetWeaponQuality(heroId, isAwaken), UTL.Color.QualityType.FormationMagicWeaponBg) if isAwaken then CTL.HeroAwaken.SetWeaponItemImage(comp.img_Artifact, heroId) else local itemIcon = string.format(MDL.Bag.ItemIconPathTemplete, data.MagicWeaponPicture) UIUtils.SetImageByAssetBundle(comp.img_Artifact, itemIcon) end comp.effect_WeaponQuality:StopUIEffect() UIUtils.SetActive(self.group_Artifact.mask_Activation, not isActive) if isActive then UIUtils.SetActive(comp.bg_Break, true) if isAwaken then local awakenLevel = MDL.HeroAwaken.GetCurWeaponStar(heroId) UIUtils.SetLabel(comp.txt_Break, string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_AwakenLevelNum, awakenLevel)) elseif level > 0 then comp.txt_Break.text = "+" .. level else UIUtils.SetActive(comp.bg_Break, false) end --品质特效 UTL.Color.PlayQualityEffect(comp.effect_WeaponQuality, data.EffectID, UTL.Color.EffectType.Formation) else UIUtils.SetActive(comp.bg_Break, false) end end function UIHeroShowPanel:OnFunctionUnlockUpdate(fucId, isUnlock) self:RefreshToggleUnlock() if fucId == MDL.Unlock.FunctionType.AwakenActivity then if not isUnlock then if self.lastSelectTabType == MDL.HeroSelect.ToggleViewNameList.AwakenSkill then self.toggles_Group:SelectIndex(0) end end end end return UIHeroShowPanel