--[[ 宠物上阵界面 ]]-- local UIPetArray = UIViewClass() local Const_PosXZ_Array = { [1] = { 0.6, 0, 2 }, [2] = { -0.5, 0, 2 }, [3] = { -1.6, 0, 2 }, } local Const_PosXZ_Array_RatioPad4_3 = { [1] = { 0.3, 0, 2 }, [2] = { -0.5, 0, 2 }, [3] = { -1.3, 0, 2 }, } local Const_Rot_Array = { [1] = -15, [2] = 0, [3] = 15, } local ConstLightPath = "Assets/UI/Template/BattleDefaultLight/BattleLight.prefab" local CONST_BG_PREFAB = "Assets/GameLevels/Dynamic_ScenePrefab/UI2DCommonScene.prefab" local CONST_BG_IMAGE = "Assets/UI/Image/UI_BackGround/cwjh_bg_01.png" --region 系统函数 function UIPetArray:OnCreated() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.model_Show) end function UIPetArray:OnOpened(context) UIManager.ActiveUIModle(false, "UIPetArray") UTL.UIRender.Create2DSceneTrans(self.modelComponentDataHandle, CONST_BG_PREFAB, 1600, 0, 1600, CONST_BG_IMAGE, false) self:RegistSystemEvent(EventID.UI_Pet_UpdateSlotInfo, self.RefreshSlotInfo) self:RegistSystemEvent(EventID.UI_Pet_UpdateFormationInfo, self.RefreshSlotInfo) self:RegistSystemEvent(EventID.UI_Pet_UnlockAssistSlot, self.OnUnlockAssistSlot) self:RegistSystemEvent(EventID.UI_CloseAndRecoverView, self.OnCloseAndRecoverView) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_PetFormation2) self:InitDropEvent() self:RefreshSlotInfo() end function UIPetArray:OnClosed() UIManager.ActiveUIModle(true, "UIPetArray") UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) end function UIPetArray:OnUnlockAssistSlot(slot) self.group_Array[slot].group_PetAssistance.effect_Success:PlayUIEffect() end function UIPetArray:InitDropEvent() self.dropSlots = {} for i, v in ipairs(self.group_Array) do self:RegistTriggerEvent(v.img_Drop, UIEventTriggerType.BeginDrag) self:RegistTriggerEvent(v.img_Drop, UIEventTriggerType.Drag) self:RegistTriggerEvent(v.img_Drop, UIEventTriggerType.EndDrag) table.insert(self.dropSlots, v.img_Drop.gameObject) end for i, v in ipairs(self.group_Array) do self:RegistDropEvent(v.img_Drop, self.dropSlots) end end function UIPetArray:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) else for index, v in ipairs(self.group_Array) do if comp == v.group_PetAssistance.btn then self:OnClickAssistance(index) break elseif comp == v.img_Drop then --没上阵才能打开 local curSlotInfo = MDL.Pet.GetMainFormationInfo(index) if curSlotInfo then local petData = MDL.Pet.GetActiveInfo(curSlotInfo.petUniqId) if petData then return end end UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetChangeView, { panelType = CTL.Pet.ChangePetPanelType.Main, changeIndex = MDL.Pet.GetMainFormationSlotId(index) }) end end end end function UIPetArray:OnBeginDrag(comp, eventData) local slotIndex = self:GetSlotByDropComp(comp) local curSlotInfo = MDL.Pet.GetMainFormationInfo(slotIndex) if curSlotInfo then local petData = MDL.Pet.GetActiveInfo(curSlotInfo.petUniqId) if petData then self.draggingIndex = slotIndex UIUtils.SetActive(self.img_DragShow, true) UIUtils.SetImageByAssetBundle(self.img_DragShow, petData.Config.PetIcon) end end end function UIPetArray:OnDrag(comp, eventData) UIUtils.ScreenPointToWorldPointInRectangle(self.dragParent.gameObject, eventData) end function UIPetArray:OnEndDrag() UIUtils.SetActive(self.img_DragShow, false) end function UIPetArray:OnDrop(comp, eventData) if comp == nil then return end local dropIndex = self:GetSlotByDropComp(comp) if dropIndex > 0 then if self.draggingIndex then local fromSlotId = self.draggingIndex local toSlotId = dropIndex MDL.Pet.PetFormationChangeReq(MDL.Pet.FormationOptType.Main, fromSlotId, toSlotId) end end self.draggingIndex = nil UIUtils.SetActive(self.img_DragShow, false) end --endregion function UIPetArray:GetSlotByDropComp(comp) for i, v in ipairs(self.group_Array) do if comp.gameObject == v.img_Drop.gameObject then return i end end return 0 end function UIPetArray:SetHeadInfo(comp, i) local heroSlotIds = MDL.Player.GetHeroLinUpIds() local index = i * 2 - 1 local mainHero = heroSlotIds[index] local subHero = heroSlotIds[index + 1] if mainHero == 0 and subHero == 0 then UIUtils.SetActive(comp.gameObject, false) return end UIUtils.SetActive(comp.gameObject, true) if mainHero > 0 then UIUtils.SetActive(comp.img_MainHeroBg, true) UTL.Item.SetHeroIconByHeroId(comp.img_MainHero, mainHero, MDL.HeroAwaken.GetIsHeroAwaken(mainHero)) else UIUtils.SetActive(comp.img_MainHeroBg, false) end if subHero > 0 then UIUtils.SetActive(comp.img_SubHeroBg, true) UTL.Item.SetHeroIconByHeroId(comp.img_SubHero, subHero, MDL.HeroAwaken.GetIsHeroAwaken(subHero)) else UIUtils.SetActive(comp.img_SubHeroBg, false) end end function UIPetArray:SetRuneInfo(state_Rune, slotId) state_Rune:SetState(slotId - 1) end function UIPetArray:RefreshSlotInfo() local totalGs = 0 for i, arrayCollection in ipairs(self.group_Array) do arrayCollection.group_PetAssistance.effect_Unlockable:StopUIEffect() arrayCollection.group_PetAssistance.effect_AssistanceNew:StopUIEffect() --武将头像 UIUtils.SetActive(arrayCollection.group_Hero.gameObject, true) self:SetHeadInfo(arrayCollection.group_Hero, i) local mainGs, assistGs = 0, 0 local mainTriggerID = CTL.Pet.MAIN_SLOT_UNLOCK_ID[i] if MDL.Unlock.IsTriggerIdComplete(mainTriggerID) then local info = MDL.Pet.GetMainFormationInfo(i) if info then local mainPetData = MDL.Pet.GetActiveInfo(info.petUniqId) if mainPetData ~= nil then mainGs = MDL.Pet.GetSlotGs(info.slotId) arrayCollection.state_Slot:SetState(1) UIUtils.SetLabel(arrayCollection.txt_PetName, string.isNilOrEmpty(mainPetData.Info.petName) and UIUtils.GetLocalizedTxt(Const_IDS[mainPetData.Config.PetName]) or mainPetData.Info.petName) else arrayCollection.state_Slot:SetState(2) end self:SetRuneInfo(arrayCollection.state_Rune, info.slotId) else arrayCollection.state_Slot:SetState(2) end UIUtils.SetLabel(arrayCollection.txt_CE, mainGs) else arrayCollection.state_Slot:SetState(0) local triggerData = DataSheetManager.TriggerID:GetDataByID(mainTriggerID) UIUtils.SetLabel(arrayCollection.txt_UNlockTip, MDL.Unlock.GetDesByTriggerID(triggerData.Unlock_Table[1], false)) end --副宠 local state, subPetUniqId = MDL.Pet.GetAssistanceState(i) if state == MDL.Pet.AssistanceSlotState.LineUp then local subPetData = MDL.Pet.GetActiveInfo(subPetUniqId) assistGs = subPetData.Info.baseGS UIUtils.SetActive(arrayCollection.group_PetAssistance.img_AssistanceCE, true) UIUtils.SetActive(arrayCollection.group_PetAssistance.img_PetHead, true) UIUtils.SetActive(arrayCollection.group_PetAssistance.img_New, false) UIUtils.SetActive(arrayCollection.group_PetAssistance.img_Lock, false) UIUtils.SetImageByAssetBundle(arrayCollection.group_PetAssistance.img_PetHead, subPetData.Config.PetIcon) else UIUtils.SetActive(arrayCollection.group_PetAssistance.img_AssistanceCE, false) UIUtils.SetActive(arrayCollection.group_PetAssistance.img_PetHead, false) if state == MDL.Pet.AssistanceSlotState.Locked then UIUtils.SetActive(arrayCollection.group_PetAssistance.img_New, false) UIUtils.SetActive(arrayCollection.group_PetAssistance.img_Lock, true) --显示可解锁表现 local isTriggerUnlock = CTL.Pet.IsPetSlotUnlock(i) if isTriggerUnlock then arrayCollection.group_PetAssistance.effect_Unlockable:PlayUIEffect() end else UIUtils.SetActive(arrayCollection.group_PetAssistance.img_New, true) UIUtils.SetActive(arrayCollection.group_PetAssistance.img_Lock, false) arrayCollection.group_PetAssistance.effect_AssistanceNew:PlayUIEffect() end end UIUtils.SetLabel(arrayCollection.group_PetAssistance.txt_AssistanceCE, assistGs) arrayCollection.group_PetAssistance.btn:SetRedPoint(CTL.Pet.CheckAssistSlotIfLineUp(i)) totalGs = totalGs + mainGs + assistGs end self.txt_PowerNumber.text = totalGs self:LoadFormationModelShow() end function UIPetArray:LoadFormationModelShow() --先清空所有再创建 UTL.UIRender.DisposePlayerModel(self.modelComponentDataHandle) for i = 1, 3 do local info = MDL.Pet.GetMainFormationInfo(i) if info then local mainPetData = MDL.Pet.GetActiveInfo(info.petUniqId) if mainPetData then local path, _, modelXYZ, modelScale, _, _, _, modelIdleAnim = CTL.Pet.GetDevelopModelParam(mainPetData.Config, self.__viewClassPath) local pos = Const_PosXZ_Array[i] local resolutionRatio = UIUtils.GetScreenResolutionRatio() if resolutionRatio == LuaConst.ScreenResolutionRatio.RatioPad4_3 or resolutionRatio == LuaConst.ScreenResolutionRatio.RatioPadOther then pos = Const_PosXZ_Array_RatioPad4_3[i] end pos[2] = modelXYZ[2] UTL.UIRender.LoadEntityArrayModel(self.modelComponentDataHandle, path, ConstLightPath, pos, modelScale, Const_Rot_Array[i], modelIdleAnim) end end end end function UIPetArray:OnClickAssistance(index) local state, subPetUniqId = MDL.Pet.GetAssistanceState(index) if state == MDL.Pet.AssistanceSlotState.Locked then UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetUnlockAssistancePanel, CTL.Pet.SUB_SLOT_UNLOCK_CONFIG[index], Const_UI_Lua.UIEnum.UIUnlockAssistanceHeroPanel) elseif state == MDL.Pet.AssistanceSlotState.Unlock then UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetChangeView, { panelType = CTL.Pet.ChangePetPanelType.Assistance, changeIndex = index }) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetChangeView, { panelType = CTL.Pet.ChangePetPanelType.Assistance, changeIndex = index, changePetUniqId = subPetUniqId }) end end return UIPetArray