--[[ 宠物阵容界面,会被分享界面继承 ]]-- local UIPetFormation = UIViewClass() local CONST_BG_PREFAB = ConstAssetPathConfig.Common2DScenePrefab local CONST_BG_IMAGE = ConstAssetPathConfig.CONST_BG_IMAGE2 local STATE_SWITCH_TIME = 8 local RESET_TIME = 15 local MAX_RUNE_SKILL = 7 function UIPetFormation:OnCreated() for i, collection in ipairs(self.group_LeftHead) do UIUtils.SetActive(collection.group_Pet, true) end end function UIPetFormation:OnOpened(context) UIManager.ActiveUIModle(false, "UIPetFormation") self:RegistTriggerEvent(self.model_Show, UIEventTriggerType.Drag) self:RegistSystemEvent(EventID.UI_CloseAndRecoverView, self.OnCloseAndRecoverView) self.attrItemTemplateObj = self.group_PetAttrList[1].gameObject self.runeSkillList = {} if self.loc_Develop.CurState ~= 1 then UIUtils.SetLocalizationImage(self.img_CultivateIcon, "zr_msz_yc.png") end self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.model_Show) UTL.UIRender.Create2DSceneTrans(self.modelComponentDataHandle, CONST_BG_PREFAB, 1600, 0, 1600, CONST_BG_IMAGE, false) self:StartRepeatFunc(self.UpdateAnimRefresh, 1, -1) self:Init() end function UIPetFormation:Init() UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_PetFormation1) self:RegistSystemEvent(EventID.UI_Pet_UpdateSlotInfo, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_Pet_UpdatePetInfo, self.OnUpdatePetInfo) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Formation_Pet_AssistLineUp, self.UpdateArrayRed) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Formation_Pet_OneTimeNotice, self.UpdateOneTimeRed) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Formation_Pet_Rune, self.UpdateRuneRed) UIUtils.SetActive(self.group_New, false) self.curSelectInfo = nil -- 当前选中信息 self.selectSlotIndex = CTL.Pet.RecordSelectFormationIndex or nil self:RefreshPanel() self:UpdateArrayRed() self:UpdateOneTimeRed() end function UIPetFormation:OnUpdatePetInfo() if self.curSelectInfo == nil then return end local petInfo, petConfig = self.curSelectInfo.Info, self.curSelectInfo.Config CTL.Pet.SetPetName(self.txt_Name, petInfo, petConfig) end function UIPetFormation:UpdateArrayRed() self.btn_Array:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Formation_Pet_AssistLineUp)) end function UIPetFormation:OnClosed() if self.petTalkSoundId then CTL.Sound.StopById(self.petTalkSoundId) end if self.petIdleSoundId then CTL.Sound.StopById(self.petIdleSoundId) end CTL.Pet.RecordSelectFormationIndex = self.selectSlotIndex UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) UIManager.ActiveUIModle(true, "UIPetFormation") end function UIPetFormation:OnDrag(comp, eventData) UTL.UIRender.RotateEntity(self.modelComponentDataHandle, -eventData.delta.x * 0.2, true, false) end function UIPetFormation:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIPetFormation:UpdateRuneRed() local isRed = false if self.curSelectInfo then local slotInfo = MDL.Pet.GetSlotInfoByPetUniqueID(self.curSelectInfo.Info.petUniqId) isRed = CTL.Pet.GetRuneRed(slotInfo.slotId) end self.btn_Rune:SetRedPoint(isRed) end function UIPetFormation:UpdatePetRed() if self.curSelectInfo then UIUtils.SetActive(self.cultivate_Upgrade, CTL.Pet.CheckPetIfLevelUp(self.curSelectInfo.Config, self.curSelectInfo.Info)) local slotInfo = MDL.Pet.GetSlotInfoByPetUniqueID(self.curSelectInfo.Info.petUniqId) self.btn_ChangePet:SetRedPoint(CTL.Pet.CheckMainSlotIfLineUp(slotInfo.slotId)) end end function UIPetFormation: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.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.PetFormation }) elseif comp == self.btn_ChangePet then local slotInfo = MDL.Pet.GetSlotInfoByPetUniqueID(self.curSelectInfo.Info.petUniqId) UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetChangeView, { panelType = CTL.Pet.ChangePetPanelType.Main, changeIndex = slotInfo.slotId, changePetUniqId = self.curSelectInfo.Info.petUniqId }) elseif comp == self.btn_Array then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPetArray) elseif comp == self.btn_Edit then UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetRenamePanel, { petInfo = self.curSelectInfo }, Const_UI_Lua.UIEnum.UIRenamePanel) elseif comp == self.btn_Rune then local slotInfo = MDL.Pet.GetSlotInfoByPetUniqueID(self.curSelectInfo.Info.petUniqId) UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGodPetRuneBase, { petUniqueID = self.curSelectInfo.Info.petUniqId, slotId = slotInfo.slotId }) elseif comp == self.btn_Cultivate then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPetBasePanel, { petUniqId = self.curSelectInfo.Info.petUniqId }) else for i, v in ipairs(self.group_LeftHead) do if comp == v.group_Add then UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetChangeView, { panelType = CTL.Pet.ChangePetPanelType.Main, changeIndex = i }) return elseif comp == v.btn_Pet then self:UpdateSelect(i) return end end for i, v in ipairs(self.cells) do if comp == v.btn_Skill then local skill = self:GetSkillByIndex(i) CTL.Pet.ShowSkillTips(skill) return end if comp == v.img_Locked then CTL.Pet.ShowSkillUnlockTips(i) return end end for i, v in ipairs(self.Attr_arr) do if comp == v.btn_Attr then self:ShowTalentDesc(i, comp) return end end end end function UIPetFormation:GetSkillByIndex(index) return self.curSelectInfo.Info.congenitalSkill[index] end function UIPetFormation:ShowTalentDesc(index, comp) CTL.Pet.ShowTalentDesc(self.curSelectInfo.Config, self.curSelectInfo.Info, index, comp) end function UIPetFormation:RefreshPanel() local index for i, collection in ipairs(self.group_LeftHead) do local slotInfo = MDL.Pet.GetSlotInfoBySlotId(i) if index == nil then if slotInfo and MDL.Pet.GetActiveInfo(slotInfo.petUniqId) then index = i end end self:SetSlotHead(collection, i, slotInfo and slotInfo.petUniqId) end self:UpdateSelect(self.selectSlotIndex or index) end function UIPetFormation:UpdateOneTimeRed() self.btn_Cultivate:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Formation_Pet_OneTimeNotice)) end function UIPetFormation:UpdateSelect(idx) self.selectSlotIndex = idx local slotInfo = MDL.Pet.GetSlotInfoBySlotId(idx) if slotInfo then self.curSelectInfo = MDL.Pet.GetActiveInfo(slotInfo.petUniqId) end if self.curSelectInfo == nil then UIUtils.SetActive(self.group_Name, false) UIUtils.SetActive(self.ani_Right, false) UIUtils.SetActive(self.ani_Bottom, false) return end self.state_Rune:SetState(idx - 1) UIUtils.SetActive(self.group_Name, true) UIUtils.SetActive(self.ani_Right, true) UIUtils.SetActive(self.ani_Bottom, true) for i, v in ipairs(self.group_LeftHead) do if i ~= idx then UIUtils.SetImageByAssetBundle(v.bg_Select, ConstAssetPathConfig.AssetPath162) else UIUtils.SetImageByAssetBundle(v.bg_Select, ConstAssetPathConfig.AssetPath163) end end local petInfo, petConfig = self.curSelectInfo.Info, self.curSelectInfo.Config self:ShowBasicInfo(petInfo, petConfig, slotInfo.attr.attrs, slotInfo.talismanSkill, MDL.Pet.GetSlotGs(idx)) self:UpdateRuneRed() self:UpdatePetRed() end function UIPetFormation:UpdateRuneSkill(skills) for i = 1, MAX_RUNE_SKILL do if skills[i] and skills[i] > 0 then self.runeSkillList[i] = skills[i] else self.runeSkillList[i] = -1 end end --羁绊符文在最后一个位置 local relationSkill = CTL.Pet.GetRelationSkill(self.curSelectInfo.Info.petUniqId) if relationSkill > 0 then self.runeSkillList[MAX_RUNE_SKILL] = relationSkill end self.LoopScroll:ReloadAll(self.runeSkillList) end function UIPetFormation:OnCellInit(scrollRect, index, cellTable, data) cellTable.effect_ItemJiBan:StopUIEffect() if data == -1 then UIUtils.SetActive(cellTable.group_Locked, true) UIUtils.SetActive(cellTable.group_Info, false) else UIUtils.SetActive(cellTable.group_Locked, false) UIUtils.SetActive(cellTable.group_Info, true) --可能是羁绊符文,因此用TryGet来读表 local success, runeCfg = DataSheetManager.PetRuneSkill:TryGetDataByPetRuneID(data) if success == false then runeCfg = DataSheetManager.PetRelationSkill:GetDataByRelationSkillID(data) if runeCfg then cellTable.effect_ItemJiBan:PlayUIEffect() end end UIUtils.SetLabelText(cellTable.txt_Level, CTL.Pet.RuneSkillLevelIDS[runeCfg.RuneLevel]) UIUtils.SetImageByAssetBundle(cellTable.sprite_Skill, runeCfg.RuneIcon) end if index == MAX_RUNE_SKILL - 1 then cellTable.sprite_BtnKuangState:SetState(1) else cellTable.sprite_BtnKuangState:SetState(0) end end function UIPetFormation:OnCellClicked(scrollRect, index, cellTable, target, data) if data > 0 then CTL.Pet.ShowRuneSkillTips(data) else if self.LoopScroll.Count - 1 == index then --最后一个特殊提示 CTL.Tips.AddTipsMsg(Const_IDS.IDS_Pet_RelationActiveTips) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Pet_RuneGetSkillWay3) end end end function UIPetFormation:GetRuneAttrValue(runeAttr, attrType) for i = 1, #runeAttr, 2 do if runeAttr[i] == attrType then return runeAttr[i + 1] end end return 0 end function UIPetFormation:UpdateAttrs(baseAttrs, extraAttrs, relationSkillId) local index = 0 local runeAttr if relationSkillId and relationSkillId > 0 then local cfg = DataSheetManager.PetRelationSkill:GetDataByRelationSkillID(relationSkillId) runeAttr = cfg.Attr end for i, v in ipairs(baseAttrs) do local value = extraAttrs and extraAttrs[i] + v or v if runeAttr then value = value + self:GetRuneAttrValue(runeAttr, i) end if value > 0 then index = index + 1 local attrItem = self.group_PetAttrList[index] if attrItem == nil then attrItem = self:InstantiateCollection(self.group_PetAttrList, self.attrItemTemplateObj) end UIUtils.SetActive(attrItem.gameObject, true) UTL.Attr.SetAttrItemByCompName(attrItem, i, math.floor(value + 0.5), true, true) end end for i = index + 1, #self.group_PetAttrList do UIUtils.SetActive(self.group_PetAttrList[i].gameObject, false) end end function UIPetFormation:SetSlotHead(collection, index, petUniqueID) local mainTriggerID = CTL.Pet.MAIN_SLOT_UNLOCK_ID[index] local activeInfo = MDL.Pet.GetActiveInfo(petUniqueID) if activeInfo then UIUtils.SetActive(collection.group_Info, false) UIUtils.SetActive(collection.btn_Pet, true) UIUtils.SetActive(collection.img_PetHead, true) UIUtils.SetImageByAssetBundle(collection.img_PetHead, activeInfo.Config.PetIcon) else UIUtils.SetActive(collection.group_Info, true) UIUtils.SetActive(collection.img_PetHead, false) if not MDL.Unlock.IsTriggerIdComplete(mainTriggerID) then UIUtils.SetActive(collection.btn_Pet, false) UIUtils.SetActive(collection.group_Add, false) local triggerData = DataSheetManager.TriggerID:GetDataByID(mainTriggerID) UIUtils.SetLabel(collection.txt_Locked, MDL.Unlock.GetDesByTriggerID(triggerData.Unlock_Table[1], false)) else UIUtils.SetActive(collection.btn_Pet, true) UIUtils.SetActive(collection.group_Add, true) UIUtils.SetLabel(collection.txt_Locked, nil) end end collection.btn_Pet:SetRedPoint(self:GetPetHeadRed(index)) end function UIPetFormation:GetPetHeadRed(index) local isRed = CTL.Pet.GetRuneRed(index) if isRed == false then local slotInfo = MDL.Pet.GetSlotInfoBySlotId(index) if slotInfo then local data = MDL.Pet.GetActiveInfo(slotInfo.petUniqId) if data then isRed = CTL.Pet.CheckPetIfLevelUp(data.Config, data.Info) end end end if isRed == false then isRed = CTL.Pet.CheckMainSlotIfLineUp(index) end return isRed end function UIPetFormation:UpdateModelShow(petConfig) if self.curModelId and self.curModelId == petConfig.PetModelID then return end self.curModelId = petConfig.PetModelID UTL.UIRender.LoadDevelop3DModel(self.modelComponentDataHandle, CTL.Pet.GetDevelopModelParam(petConfig)) self:PlayAnim(petConfig) if self.petTalkSoundId then CTL.Sound.StopById(self.petTalkSoundId) self.petTalkSoundId = nil end if string.isNilOrEmpty(petConfig.PetTalkAudio) == false then self.petTalkSoundId = CTL.Sound.PlayGameSound(petConfig.PetTalkAudio, true) end end -- 播放出场动画 function UIPetFormation:PlayAnim(petConfig) if petConfig then self.isPlayingAnim = true self.petIdleSoundId = CTL.Sound.PlayGameSound(petConfig.PetIdleShowAudio, true) UTL.UIRender.PlayRenderEntityTriggerAnim(self.modelComponentDataHandle, petConfig.ModelIdleShowAnim) end end function UIPetFormation:UpdateAnimRefresh(deltaTime, timeSinceUpdate) if self.curSelectInfo == nil then return end if timeSinceUpdate >= RESET_TIME then self:Reset() return end if timeSinceUpdate >= STATE_SWITCH_TIME and self.isPlayingAnim == false then self:PlayAnim(self.curSelectInfo.Config) end end -- 播放待机动画 function UIPetFormation:Reset() self.isPlayingAnim = false self:ResetRepeatFunc(self.UpdateAnimRefresh) end function UIPetFormation:ShowBasicInfo(petInfo, petConfig, extraAttrs, talismanSkill, power) UIUtils.SetLabel(self.txt_Power, power) self.txt_Lv.text = string.FormatByIdsId(Const_IDS.IDS_PetLevel1, UTL.Item.GetNobilityByTeamLevel(petInfo.petLevel)) --成长积分 CTL.Pet.FormatGrowUpScoreText(self.txt_BaseAttr, petInfo, petConfig) --基本信息 self.txt_Title.text = self:GetPetTitle(petInfo) CTL.Pet.SetPetName(self.txt_Name, petInfo, petConfig) CTL.Pet.SetPetStar(self.group_Star, petInfo.petPedigree, petInfo.petGeneration) CTL.Pet.SetPetSign(self.group_Sign, petInfo, petConfig) --技能 self:SetPetSkill(petInfo) --资质 CTL.Pet.SetPetAptitude(self.Attr_arr, petInfo, petConfig) --属性 self:UpdateAttrs(petInfo.attr.attrs, extraAttrs, self:GetPetRelationSkill(petInfo)) self:UpdateModelShow(petConfig) --符文技能 self:UpdateRuneSkill(talismanSkill) end function UIPetFormation:GetPetTitle(petInfo) return CTL.Pet.GetPetTitle(petInfo) end function UIPetFormation:GetPetRelationSkill(petInfo) return CTL.Pet.GetRelationSkill(petInfo.petUniqId) end function UIPetFormation:SetPetSkill(petInfo) CTL.Pet.SetTalentSkillGroup(self.cells, petInfo.congenitalSkill) end return UIPetFormation