--[[ 布阵界面--模板 用于 阵容--》布阵 继承该界面的子界面有 1、演武校场——》布阵 UICommonLineUpView 2、天地群雄——》布阵 UICommonLineUpView ]] local UIArray = UIViewClass() local UIEffectPath = { LockEffect = ConstAssetPathConfig.LockEffect, BeingSelected = ConstAssetPathConfig.BeingSelected, OnDropEffect = ConstAssetPathConfig.OnDropEffect, AllowLineUpEffect = ConstAssetPathConfig.AllowLineUpEffect, EmptySpaceEffect = ConstAssetPathConfig.AllowLineUpEffect, } local CheckParams = { FormationIndex = 0, MainHeroIndex = 0, SubHeroIndex = 0, heroIdList = nil, isHeroFormation = true } local ArrayCameraPos = Vector3.New(-992.1, -999.3, -999.3) local ArrayCameraRot = Vector3.New(-6.28, -87.75, -0.04) local DefaultFov = 30 -- TODO -- 优化前:进入界面时 会同时加载场景、6个武将(战斗模)、设置各种UI,导致峰值压力非常大 -- 优化后:进入界面时 会先加载场景、设置UI,同时开启分帧加载武将,延迟0.16加载一个武将,来降低进入界面时的峰值压力 -- 还存在的问题: -- 1、后续优化是将加载场景接口单独拆分,实现 加载UI(不设置具体UI内容)、加载场景、设置UI、分帧加载武将,以便进一步降低峰值压力 -- 2、这个界面(布阵)每次打开不管什么情况下 都会重新加载场景、武将, -- 在和助阵界面互相切换的时候,使用的场景、武将模型、武将占位一模一样,需要根据条件只加载一次场景和武将,仅切换UI的状态, -- 而不是像现在 打开布阵——>切换助阵:先加载场景、6个武将,切换时卸载场景、武将,在重新加载场景、武将。 -- 3、使用分帧加载后。由于武将是一个一个出现,表现效果需要重新考虑一下 function UIArray:OnOpened(context) local resolutionRatio = UIUtils.GetScreenResolutionRatio() self.loc_HeroPosition:SetState((LuaConst.ScreenResolutionRatio.Ratio1920_1080 <= resolutionRatio and resolutionRatio <= LuaConst.ScreenResolutionRatio.Ratio2114_1080) and 1 or 0) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_Fomation_Array) self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.ModelShow) UTL.UIRender.Create2DSceneTrans(self.modelComponentDataHandle, ConstAssetPathConfig.Common2DScenePrefab, 1600, 0, 1600, ConstAssetPathConfig.BGPath_1, false) UnityEngine.Input.multiTouchEnabled = false; self:RegistSystemEvent(EventID.UI_LineUp_OnLineUpHeroIdsResp, self.RefreshArrayInfo) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.UpdateUnlockBtns) self:RegistSystemEvent(EventID.UI_AssistanceFight_TeamworkBuffChange, self.TeamworkBuffChange) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Formation_AssistFight, self.UpdateUnlockBtns) self.originModelIDList = {} self.effectId = {} self.frameLoadList = {} self:RegistHeroPanel() self.oldIndex = nil self.dropIndex = nil self.ArrayShow:EnterArrayShowWithCameraParam(ArrayCameraPos, ArrayCameraRot, DefaultFov) self:RefreshArrayInfo() self:UpdateUnlockBtns() self:TeamworkBuffChange() -- 取消分帧加载标志位 if self.context then self.context["cancelFrameLoadHero"] = nil if next(self.context) == nil then self.context = nil end end end function UIArray:RegistHeroPanel() self.heroPanel = {} self.heroEffect = {} self.heroPanelId = {} for i = 1, 6 do self.heroPanel[i] = self["Hero0"..i] self.heroEffect[i] = self["HeroEffect0"..i] self.heroPanelId["Hero0"..i] = i self:RegistTriggerEvent(self.heroPanel[i], UIEventTriggerType.BeginDrag) self:RegistTriggerEvent(self.heroPanel[i], UIEventTriggerType.Drag) self:RegistTriggerEvent(self.heroPanel[i], UIEventTriggerType.EndDrag) self:RegistTriggerEvent(self.heroPanel[i], UIEventTriggerType.Drop) self:RegistTriggerEvent(self.heroPanel[i], UIEventTriggerType.PointerClick) end end function UIArray:OnClosed() UnityEngine.Input.multiTouchEnabled = true for k,v in pairs(self.effectId) do AuxUtil.StopPsEffect(v) end if self.availableEffectId then AuxUtil.StopPsEffect(self.availableEffectId) end if self.dropEffectId then AuxUtil.StopPsEffect(self.dropEffectId) end UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) end function UIArray:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIArray:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Change then self:ChangeShowProperties() elseif comp == self.btn_TeamInfoBg then self:ChangeShowProperties() elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.Formation}) elseif comp == self.btn_AssistanceFight then self:GotoAssistancePanel(1) elseif comp == self.group_TeamBuff then -- 助阵连携说明提示 UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonTipsPanel) else for i = 1, 3 do if comp == self.group_TeamGs[i].btn_Check then CheckParams.FormationIndex = i CheckParams.MainHeroIndex = i * 2 - 1 CheckParams.SubHeroIndex = i * 2 UIManager.OpenView(Const_UI_Lua.UIEnum.UIAssistanceInfoTips, CheckParams) end end end end function UIArray:ConvertIndex(index) if index == 1 or index == 2 then return "Left" elseif index == 3 or index == 4 then return "Middle" elseif index == 5 or index == 6 then return "Right" end end function UIArray:RefreshArrayInfo() self:SetLineUpHeroModel() self:SetLineUpHeroPower() self:RefreshPanelEffect() self:RefreshTeamWork() if self.dropIndex then CTL.Sound.PlayGameSound("UI_sound_Qiejiang") if self.dropEffectId then AuxUtil.StopPsEffect(self.dropEffectId) end local dropHeroTrans = self.ArrayShow:GetHeroModelTransform(self.dropIndex) if dropHeroTrans.childCount > 0 then self.dropEffectId = SystemManager.PlayPsEffect(UIEffectPath.OnDropEffect, dropHeroTrans:GetChild(0)) end self.dropIndex = nil end end function UIArray:RefreshProperties() self:RefreshSinglePropertiesScroll(self.loop_PropertiesLeft, 1, 2) self:RefreshSinglePropertiesScroll(self.loop_PropertiesMiddle, 3, 4) self:RefreshSinglePropertiesScroll(self.loop_PropertiesRight, 5, 6) end local ShowAttrNum = 13 function UIArray:RefreshSinglePropertiesScroll(loopScroll, mainIndex, viceIndex) local mainHeroId = MDL.Player.GetHeroLinUpIds()[mainIndex] local viceHeroId = MDL.Player.GetHeroLinUpIds()[viceIndex] local mainAttrList = nil local viceAttrList = nil local length = 0 if mainHeroId and mainHeroId > 0 then mainAttrList = MDL.HeroDetail.GetAttrDataFromSheet(MDL.HeroDetail.GetTotalAttr(mainHeroId)) length = ShowAttrNum end if viceHeroId and viceHeroId > 0 then viceAttrList = MDL.HeroDetail.GetAttrDataFromSheet(MDL.HeroDetail.GetTotalAttr(viceHeroId)) length = ShowAttrNum end for i = 1, length do local attr = {} if mainAttrList then attr.main = mainAttrList[i] else attr.main = nil end if viceAttrList then attr.vice = viceAttrList[i] else attr.vice = nil end if loopScroll.Count >= length then loopScroll:UpdateIndex(i - 1, attr) else loopScroll:AddData(attr, 0) end end end function UIArray:RefreshPropertiesCell(cellTable, data) local totalValue = 0 if data.main then UIUtils.SetLabel(cellTable.txt_MainAttr, data.main.Value) UIUtils.SetLabel(cellTable.txt_AttrName, UIUtils.GetLocalizedTxt(Const_IDS[data.main.Name])) totalValue = totalValue + data.main.Value else UIUtils.SetLabel(cellTable.txt_MainAttr, 0) UIUtils.SetLabel(cellTable.txt_AttrName, nil) end if data.vice then UIUtils.SetLabel(cellTable.txt_SubAttr, data.vice.Value) --UIUtils.SetLabel(cellTable.txt_Properties, UIUtils.GetLocalizedTxt(Const_IDS[data.vice.Name])) totalValue = totalValue + data.vice.Value else UIUtils.SetLabel(cellTable.txt_SubAttr, 0) end UIUtils.SetLabel(cellTable.txt_TotalAttr, totalValue) UTL.Attr.SetAttrIconByAttrIcon(cellTable.img_AttrIcon, data.main.Icon) UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(cellTable.group_AttrTitle) end function UIArray:SetLineUpHeroModel() local arrayIdList = MDL.Player.GetHeroLinUpIds() table.clearArray(self.frameLoadList) self:StopRepeatFunc(self.FrameLoadFormationHero) local isInit = table.getDictCount(self.originModelIDList) == 0 for i, v in ipairs(arrayIdList) do if v and v > 0 then if isInit == false or (self.context and self.context.cancelFrameLoadHero) then self:LoadHeroModel(v, i) else table.insert(self.frameLoadList, { heroId = v, index = i }) end end end if #self.frameLoadList > 0 then self:StartRepeatFunc(self.FrameLoadFormationHero, 0.12) end end function UIArray:FrameLoadFormationHero() local frameData = table.remove(self.frameLoadList, 1) self:LoadHeroModel(frameData.heroId, frameData.index) if #self.frameLoadList == 0 then self:StopRepeatFunc(self.FrameLoadFormationHero) end end function UIArray:SetLineUpHeroPower() local arrayIdList = MDL.Player.GetHeroLinUpIds() local powers = MDL.Player.GetHeroLinUpPower() self.txt_PowerNumber.text = MDL.Player.GetLineUpGs() for i, v in ipairs(self.group_TeamGs) do local mainIndex = i + (i - 1) if not powers[mainIndex] or powers[mainIndex] <= 0 then if arrayIdList[mainIndex] < 0 then local arrayData = DataSheetManager.BattleArray:GetDataByArrayID(mainIndex) local unLockParamVal = tonumber(arrayData.UnlockConditionParam) local isLevel = DataSheetManager.BarrierChosenData:GetDataByID(unLockParamVal) ~= nil local template = UIUtils.GetLocalizedTxt(Const_IDS[arrayData.UnlockDes]) if isLevel then local unLockIDS = DataSheetManager.BarrierChosenData:GetDataByID(unLockParamVal).BarrierNum local unLockInfo = UIUtils.GetLocalizedTxt(Const_IDS[unLockIDS]) v.txt_PowerNumber.text = string.format(template, unLockInfo) else v.txt_PowerNumber.text = string.format(template, arrayData.UnlockConditionParam) end UIUtils.SetActive(v.img_PowerIcon, false) else v.txt_PowerNumber.text = 0 UIUtils.SetActive(v.img_PowerIcon, true) end else v.txt_PowerNumber.text = MDL.Player.GetFormationGS(i) UIUtils.SetActive(v.img_PowerIcon, true) end end CheckParams.heroIdList = arrayIdList end function UIArray:ChangeShowProperties() if self.change then UIUtils.SetActive(self.group_TeamInfo.gameObject, false) self.change = false else UIUtils.SetActive(self.group_TeamInfo.gameObject, true) self.change = true self:RefreshProperties() end end function UIArray:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_PropertiesLeft or scrollRect == self.loop_PropertiesMiddle or scrollRect == self.loop_PropertiesRight then self:RefreshPropertiesCell(cellTable, data) end end function UIArray:OnBeginDrag(comp, eventData) if #self.frameLoadList > 0 then return -- 分帧加载尚未完成 end self.dragItemId = MDL.Player.GetHeroLinUpIds()[self.heroPanelId[comp.name]] self.oldIndex = nil local data = MDL.HeroSelect.GetHeroInfo(self.dragItemId) if not data then return end self:RefreshHeroCell(self.cell_ArrayHero, data) UIUtils.SetActive(self.cell_ArrayHero.gameObject, true) end function UIArray:OnDrag(comp, eventData) if self.cell_ArrayHero.gameObject.activeSelf then UIUtils.ScreenPointToWorldPointInRectangle(self.cell_ArrayHero.gameObject, eventData) if eventData.pointerEnter then self:ShowAvailableEffectDuringDrag(self.heroPanelId[eventData.pointerEnter.name]) end end end function UIArray:OnEndDrag(comp, eventData) UIUtils.SetActive(self.cell_ArrayHero.gameObject, false) self.oldIndex = nil self:RefreshPanelEffect() self:StopEffectDuringDrag() end function UIArray:OnDrop(comp, eventData) if #self.frameLoadList > 0 then return -- 分帧加载尚未完成 end if not eventData.pointerEnter or not self.dragItemId or self.dragItemId <= 0 then self.dragItemId = nil return end local index = self.heroPanelId[eventData.pointerEnter.name] if MDL.Array.IsArrayPositionUnlock(index) then self.dropIndex = index CTL.Array.LineUpHeroIdsRequest(index, self.dragItemId) else self:ShowLevelUnlockTipTxt(index) end end function UIArray:OnPointerClick(comp, eventData) if self.cell_ArrayHero.gameObject.activeSelf then return end local index = self.heroPanelId[eventData.pointerEnter.name] if MDL.Array.IsArrayPositionUnlock(index) then self:GotoAssistancePanel(index) elseif index then self:ShowLevelUnlockTipTxt(index) end end function UIArray:ShowLevelUnlockTipTxt(index) local arrayData = DataSheetManager.BattleArray:GetDataByArrayID(index) local unLockParamVal = tonumber(arrayData.UnlockConditionParam) local isLevel = DataSheetManager.BarrierChosenData:GetDataByID(unLockParamVal) ~= nil if isLevel then local unLockIDS = DataSheetManager.BarrierChosenData:GetDataByID(unLockParamVal).BarrierNum local unLockInfo = UIUtils.GetLocalizedTxt(Const_IDS[unLockIDS]) CTL.Tips.AddTipsMsg(Const_IDS[arrayData.UnlockDes], unLockInfo) else CTL.Tips.AddTipsMsg(Const_IDS[arrayData.UnlockDes], arrayData.UnlockConditionParam) end end function UIArray:ShowAvailableEffectDuringDrag(index) if index and self.oldIndex ~= index then self.oldIndex = index self:StopEffectDuringDrag() local arrayIds = MDL.Player.GetHeroLinUpIds() if arrayIds[index] and arrayIds[index] >= 0 then self.availableEffectId = SystemManager.PlayPsEffect(UIEffectPath.AllowLineUpEffect, self.ArrayShow:GetHeroModelTransform(index)) end end end function UIArray:StopEffectDuringDrag() if self.availableEffectId then AuxUtil.StopPsEffect(self.availableEffectId) self.availableEffectId = nil end end function UIArray:RefreshPanelEffect() local arrayIds = MDL.Player.GetHeroLinUpIds() for i = 1, 6 do if arrayIds[i] < 0 then self:PlayUIEffect(UIEffectPath.LockEffect, i) end end end function UIArray:PlayUIEffect(path, index) if self.effectId[index] then AuxUtil.StopPsEffect(self.effectId[index]) end self.effectId[index] = SystemManager.PlayPsEffect(path, self.ArrayShow:GetHeroModelTransform(index)) end function UIArray:RefreshHeroCell(cellTable, data) local id = data.heroId UIUtils.SetLabel(cellTable.txt_ArrayCE, data.Gs) --上阵图标显示 if MDL.Player.HeroIsLineUp(id) then UIUtils.SetActive(cellTable.group_BgZhen.gameObject, true) else UIUtils.SetActive(cellTable.group_BgZhen.gameObject, false) end UTL.Item.SetHeroIconByHeroId(cellTable.btn_ClickItem, id, MDL.HeroAwaken.GetIsHeroAwaken(id)) UTL.Color.SetQualityImageByType(cellTable.img_Quality, CTL.HeroAwaken.GetHeroQuality(id, MDL.HeroAwaken.GetIsHeroAwaken(id)), UTL.Color.QualityType.HeroSelectBg) end function UIArray:UpdateUnlockBtns() UIUtils.SetActive(self.btn_AssistanceFight, MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.AssistanceFight)) self.btn_AssistanceFight:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Formation_AssistFight)) -- 助阵连携buff显隐 UIUtils.SetActive(self.group_TeamBuff, MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.FormationTeamWork)) end --region ********************* 连携 ***************************** function UIArray:RefreshTeamWork() self:RefreshFormationTeamWork(self.group_TeamBuff1, 1) self:RefreshFormationTeamWork(self.group_TeamBuff2, 2) self:RefreshFormationTeamWork(self.group_TeamBuff3, 3) end function UIArray:RefreshFormationTeamWork(group_TeamBuff, formationIndex) local mainHeroId = MDL.Player.GetHeroLinUpIds()[formationIndex * 2 - 1] local subHeroId = MDL.Player.GetHeroLinUpIds()[formationIndex * 2] if mainHeroId <= 0 then CTL.AssistanceFight.SetActiveFormationIcon(group_TeamBuff.img_TeamBuff, 1) UIUtils.SetGray(group_TeamBuff.img_TeamBuff, true) for i, v in ipairs (group_TeamBuff.group_Light) do UIUtils.SetActive(group_TeamBuff.group_Light[i], false) end return end UIUtils.SetGray(group_TeamBuff.img_TeamBuff, false) CTL.AssistanceFight.SetActiveFormationIcon(group_TeamBuff.img_TeamBuff, DataSheetManager.HeroNum:GetDataByID(mainHeroId).Kingdom) local qualityLevel = CTL.AssistanceFight.CalculateFormationBuffLevel(mainHeroId, subHeroId) UIUtils.SetGray(group_TeamBuff.img_TeamBuff, qualityLevel == 0) if CTL.AssistanceFight.IsPlayTeamworkEft(formationIndex, qualityLevel) then group_TeamBuff.Effect_Activation:PlayUIEffect() end for i, v in ipairs (group_TeamBuff.group_Light) do UIUtils.SetActive(group_TeamBuff.group_Light[i], qualityLevel >= i) end end function UIArray:TeamworkBuffChange() MDL.FormationResonance.OpenDelayResonanceShow() CTL.AssistanceFight.ShowTeamworkBuff() end --endregion ********************* 连携 ***************************** function UIArray:GotoAssistancePanel(index) if self.context then self.context["cancelFrameLoadHero"] = true -- 增加一个标志位用来记录是否是从助阵界面返回,助阵界面返回时不使用分帧加载 else self.context = {cancelFrameLoadHero = true} end CTL.AssistanceFight.OpenAssistancePanel(index) end function UIArray:LoadHeroModel(heroId, index) if self.originModelIDList[heroId] then local modelIndex = self.originModelIDList[heroId] UTL.UIRender.SetRenderEntityParentByIndex(self.modelComponentDataHandle, self.ArrayShow:GetHeroModelTransform(index), modelIndex) else self.originModelIDList[heroId] = index local appearanceID = MDL.HeroSelect.GetAppearanceIDByHeroID(heroId) local curWeaponAppearanceId = MDL.HeroSelect.GetWeaponAppearanceIDByID(heroId) local _, modelPath, modelScale = UTL.UIRender.GetBattleHeroData(heroId, 2, nil, 0, appearanceID) local dir, actorDir, prefab = string.match(modelPath, "(%S*)/(%S*)/(%S*)") local animCtrlPath = string.gsub(modelPath, prefab, actorDir .. "_ZhuCheng.controller") UTL.UIRender.LoadEntityArrayModel(self.modelComponentDataHandle, modelPath, nil, nil, modelScale, nil, nil, animCtrlPath) local heroInfo = MDL.HeroSelect.GetHeroInfo(heroId) UTL.UIRender.ChangeEntityWeapon(self.modelComponentDataHandle, heroId, curWeaponAppearanceId, heroInfo.magicWeaponLevel, heroInfo.isMagicWeaponActive, true, true) UTL.UIRender.SetRenderEntityModelEffect(self.modelComponentDataHandle, heroId, appearanceID, false) local partList = MDL.DyeAppearance.GetDyeAppearancePartList(appearanceID) if partList then UTL.UIRender.SetModelDye(self.modelComponentDataHandle, appearanceID, partList, 1) end UTL.UIRender.SetRenderEntityParent(self.modelComponentDataHandle, self.ArrayShow:GetHeroModelTransform(index)) end end return UIArray