--[[ 宠物养成主界面 ]]-- local UIPetBasePanel = UIViewClass() local EventSystem = require('Event/EventSystem') local CONST_BG_PREFAB = ConstAssetPathConfig.Common2DScenePrefab local CONST_BG_IMAGE = ConstAssetPathConfig.CONST_BG_IMAGE local STATE_SWITCH_TIME = 8 local RESET_TIME = 15 local TAB_BASIC = 0 local TAB_LEVEL = 1 --region -------------------------------- 系统函数 ------------------------------------------------ function UIPetBasePanel:OnCreated() self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.model_Show) self.lastClickImg = nil self.curModelId = nil end function UIPetBasePanel:OnOpened(context) UIManager.ActiveUIModle(false, "UIPetBasePanel") self:RegistSystemEvent(EventID.UI_CloseAndRecoverView, self.OnCloseAndRecoverView) self:RegistSystemEvent(EventID.UI_Pet_UpdatePetInfo, self.RefreshPetList) self:RegistSystemEvent(EventID.UI_Pet_UpdateGlobalInfo, self.OnUpdateGlobalInfo) self:RegistSystemEvent(EventID.UI_Pet_PetLevelUp, self.OnPetLevelUp) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Pet_BreedReward, self.UpdateBreedRed) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.Formation_Pet_OneTimeNotice, self.UpdateOneTimeRed) self:RegistSystemEvent(EventID.UI_CheatGreenBg, self.SetCheatGreenBg) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_PetDevelop) CTL.Bag.RegisteEventByItemType(LuaConst.ItemType.Pet, self.UpdateGodCostMat, self, LuaConst.ItemMaterialsType.JingHunStone) self:RegistTriggerEvent(self.model_Show, UIEventTriggerType.Drag) UTL.UIRender.Create2DSceneTrans(self.modelComponentDataHandle, CONST_BG_PREFAB, 1600, 0, 1600, CONST_BG_IMAGE, false) local lastSelectId, lastSelectIndex = CTL.Pet.GetLastSelectInfo() self.curViewIndex = lastSelectIndex local selectPetUniqId = lastSelectId if selectPetUniqId == nil then selectPetUniqId = context and context.petUniqId end if selectPetUniqId then for i, v in ipairs(MDL.Pet.GetOrderedList(true)) do if v.Info.petUniqId == selectPetUniqId then self.selectHeadInfo = { isPreview = false, data = v, index = i } break end end end self:StartRepeatFunc(self.UpdateAnimRefresh, 1, -1) self:RefreshPetList() self:UpdateBreedRed() self:UpdateOneTimeRed() end function UIPetBasePanel:UpdateOneTimeRed() self.btn_Handbook:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Formation_Pet_OneTimeNotice)) end function UIPetBasePanel:OnUpdateGlobalInfo() if MDL.Pet.GetBagMaxCount() ~= self.curActiveBagCount then --格子数量改变,需要重新更新显示 self:RefreshPetList() end self:UpdateFollowState() end function UIPetBasePanel:OnClosed() if self.petTalkSoundId then CTL.Sound.StopById(self.petTalkSoundId) end if self.petIdleSoundId then CTL.Sound.StopById(self.petIdleSoundId) end CTL.Bag.UnRegisteEventByItemType(LuaConst.ItemType.Pet, self.UpdateGodCostMat, self, LuaConst.ItemMaterialsType.JingHunStone) if self.selectHeadInfo and self.selectHeadInfo.data.Info then CTL.Pet.SetLastSelectInfo(self.selectHeadInfo.data.Info.petUniqId, self.curViewIndex) else CTL.Pet.SetLastSelectInfo(nil, nil) end UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) UIManager.ActiveUIModle(true, "UIPetBasePanel") end function UIPetBasePanel:OnDrag(comp, eventData) UTL.UIRender.RotateEntity(self.modelComponentDataHandle, -eventData.delta.x * 0.2, true, false) end function UIPetBasePanel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIPetBasePanel:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.PetBase }) elseif comp == self.UITemplateTitlePanel.btn_close then self.selectHeadInfo = nil self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Handbook then CTL.Pet.OpenPetIllustratedHandbookUI() elseif comp == self.btn_Reproduction then CTL.Pet.EnterPetBreedRoom(self.selectHeadInfo.data.Info.petUniqId) elseif comp == self.btn_Edit then UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetRenamePanel, { petInfo = self.selectHeadInfo.data }, Const_UI_Lua.UIEnum.UIRenamePanel) elseif comp == self.btn_Release then UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetReleasePopUp, { petInfo = self.selectHeadInfo.data.Info, releaseType = CTL.Pet.ReleasePanelType.InBagRelease }) elseif comp == self.btn_SetFollow then if self.selectHeadInfo.data.Info.petUniqId == MDL.Pet.GetCurFollowPet() then return end MDL.Pet.ChangeFollowPetReq(self.selectHeadInfo.data.Info.petUniqId) elseif comp == self.btn_Share then CTL.Pet.SharePet(self.selectHeadInfo.data) elseif comp == self.btn_bag then CTL.Bag.SetCurrentShowItemType(MDL.Bag.BagType.Pet) CTL.Bag.OpenUIBagPanel() end end function UIPetBasePanel:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.btn_Click then self:OnClickCell(data, cellTable, index) end end function UIPetBasePanel:OnClickCell(data, cellTable, index) if data == nil then if index + 1 == self.cellNum then CTL.Pet.AddBagVolume() end return false end self.selectHeadInfo.type = data.cellType self.selectHeadInfo.isPreview = data.isPreview self.selectHeadInfo.index = index + 1 self.selectHeadInfo.data = data.petData self:UpdateViewShow() self:UpdateClickSelect(cellTable.img_Select) return true end function UIPetBasePanel:UpdateClickSelect(curImg) if self.lastClickImg then UIUtils.SetActive(self.lastClickImg, false) end UIUtils.SetActive(curImg, true) self.lastClickImg = curImg end function UIPetBasePanel:UpdateViewShow() self:RefreshModelShow() self:RefreshBase() --cheatLogic if self:HasCheatParam() then UTL.UIRender.SetCheatGreenBg(self.modelComponentDataHandle, self.cheatBgColor, self.cheatClearEff) end end function UIPetBasePanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loopscroll_Head then UIUtils.SetActive(cellTable.img_Select, false) if data == nil then self:SetPetHeadEmptyCell(cellTable, index) return end self:SetPetHeadCell(cellTable, data.isPreview, data.petData) -- 选中态 if self.selectHeadInfo.index == index + 1 then UIUtils.SetActive(cellTable.img_Select, true) self.lastClickImg = cellTable.img_Select end end end function UIPetBasePanel:OnValueChanged(comp, value) if comp == self.toggles_Btn then self.curViewIndex = value if value == TAB_BASIC then local param, curInfo = nil, self.selectHeadInfo.data if self.selectHeadInfo.isPreview then param = { petTypeID = curInfo.ID } else param = { petUniqueID = curInfo.Info.petUniqId } end if self.subView:IsViewOpened(Const_UI_Lua.UIEnum.UIPetDetailBase) == false then self.subView:CloseAll() self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIPetDetailBase), param) else EventSystem.Dispatch(EventID.UI_Pet_UpdateBasePanel, param) end elseif value == TAB_LEVEL then if self.subView:IsViewOpened(Const_UI_Lua.UIEnum.UIPetLevelUp) == false then self.subView:CloseAll() self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIPetLevelUp), { petUniqueID = self.selectHeadInfo.data.Info.petUniqId }) else EventSystem.Dispatch(EventID.UI_Pet_UpdateBasePanel, self.selectHeadInfo.data.Info.petUniqId) end end end end --endregion -------------------------------------------------------------------------------- function UIPetBasePanel:GetSelectPetConfig() local selectData = self.selectHeadInfo if selectData.data then if selectData.isPreview then local temp = selectData.data return DataSheetManager.PetData:GetDataByID_Stage(temp.ID, temp.Stage) else return selectData.data.Config end end return nil end function UIPetBasePanel:UpdateBreedRed() self.btn_Reproduction:SetRedPoint(CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Pet_BreedReward)) end function UIPetBasePanel:RefreshPetList() -- 宠物数量 local orderedList = MDL.Pet.GetOrderedList(true) self.curActiveBagCount = MDL.Pet.GetBagMaxCount() UIUtils.SetLabel(self.txt_Num, #orderedList .. "/" .. self.curActiveBagCount) if not self.selectHeadInfo then self.selectHeadInfo = { isPreview = false, data = orderedList[1], index = 1 } else --需要更新数据 if self.loopscroll_Head.Count > 0 then local isFind = false for i, v in ipairs(orderedList) do if (self.selectHeadInfo.isPreview and self.selectHeadInfo.data.ID == v.Config.ID) then self.selectHeadInfo.data = v self.selectHeadInfo.isPreview = false self.selectHeadInfo.index = i isFind = true break elseif (self.selectHeadInfo.isPreview == false and self.selectHeadInfo.data.Info.petUniqId == v.Info.petUniqId) then self.selectHeadInfo.data = v self.selectHeadInfo.index = i isFind = true break end end if isFind == false then self.selectHeadInfo.isPreview = false self.selectHeadInfo.data = orderedList[1] self.selectHeadInfo.index = 1 end end end self:UpdateViewShow() self.loopscroll_Head:ClearCells() local list = {} for _, v in ipairs(orderedList) do table.insert(list, {isPreview = false, petData = v}) end local unActiveList = MDL.Pet.GetUnActiveGodPetList() -- 未激活 if #unActiveList > 0 then for _, v in ipairs(unActiveList) do table.insert(list, {isPreview = true, petData = v}) end end local loadCount = self.curActiveBagCount == CTL.Pet.MAX_BAG_VOLUME and self.curActiveBagCount or self.curActiveBagCount + 1 self.cellNum = loadCount + #unActiveList for i = 1, self.cellNum do if i <= #list then self.loopscroll_Head:AddData(list[i], 0) else self.loopscroll_Head:AddData(nil, 0) end end end function UIPetBasePanel:CheckPetIfRed(petConfig, petInfo) if petInfo.petGeneration == 1 and CTL.RedPoint.GetRedPointActive(CTL.RedPoint.RedPointKey.Pet_BreedReward) then return true end if MDL.Pet.IsPetLineUpOrAssistance(petInfo.petUniqId) and CTL.Pet.CheckPetIfLevelUp(petConfig, petInfo) then return true end if petInfo.petQuality == MDL.Pet.PetQuality.God and CTL.Pet.CanGodPetBreak(petInfo) then return true end return false end function UIPetBasePanel:SetPetHeadCell(collection, isPreview, petInfoParam) if not isPreview then collection.head_State:SetState(2) local petInfo, petConfig = petInfoParam.Info, petInfoParam.Config CTL.Pet.SetPetIconComp(collection.img_Pet, collection.img_Qua, collection.txt_Level, petInfo.petType, petConfig.Stage, petInfo.petLevel ) UIUtils.SetActive(collection.sprite_BgZhen, MDL.Pet.IsPetLineUp(petInfo.petUniqId)) UIUtils.SetActive(collection.img_AssistanceIcon, MDL.Pet.IsPetAssistanceFight(petInfo.petUniqId)) if self:CheckPetIfRed(petConfig, petInfo) then UIUtils.SetActive(collection.img_RedPoint, true) else UIUtils.SetActive(collection.img_RedPoint, false) end UIUtils.SetLabel(collection.txt_Num, nil) else -- 预览神宠头像 collection.head_State:SetState(3) local petConfig = petInfoParam CTL.Pet.SetPetIconComp(collection.img_Pet, collection.img_Qua, nil, petConfig.ID, MDL.Pet.PetState.Basic) UIUtils.SetActive(collection.sprite_BgZhen, false) UIUtils.SetActive(collection.img_AssistanceIcon, false) if MDL.Pet.CanActiveGodPet(petConfig.ID) then UIUtils.SetActive(collection.img_RedPoint, true) else UIUtils.SetActive(collection.img_RedPoint, false) end --激活道具 local count = MDL.Bag.GetItemCount(petConfig.PieceItem) or 0 local showCount if count >= petConfig.PieceItemNum then showCount = UTL.Color.FormatGreenColor(count) .. "/" .. petConfig.PieceItemNum else showCount = UTL.Color.FormatRedColor(count) .. "/" .. petConfig.PieceItemNum end UIUtils.SetLabel(collection.txt_Num, showCount) end end function UIPetBasePanel:SetPetHeadEmptyCell(collection, index) if index + 1 < self.cellNum or self.curActiveBagCount == CTL.Pet.MAX_BAG_VOLUME then collection.head_State:SetState(1) -- 已解锁,但是为空 else collection.head_State:SetState(0) -- 未解锁 end UIUtils.SetActive(collection.img_RedPoint, false) end function UIPetBasePanel:RefreshBase() local curInfo = self.selectHeadInfo.data if not curInfo then return end UIUtils.SetActive(self.btn_Reproduction, false) local isBag = not self.selectHeadInfo.isPreview if isBag then local petInfo, petConfig = curInfo.Info, curInfo.Config self.txt_Title.text = CTL.Pet.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) CTL.Pet.FormatGrowUpScoreText(self.txt_BaseAttr, petInfo, petConfig) UIUtils.SetActiveByScale(self.toggles_Btn, true) UIUtils.SetActive(self.btn_Edit, true) --神宠隐藏放生按钮 if petInfo.petQuality == MDL.Pet.PetQuality.God then UIUtils.SetActive(self.btn_Release, false) else UIUtils.SetActive(self.btn_Release, true) end UIUtils.SetActive(self.group_bottom, true) UIUtils.SetLabel(self.txt_Power, petInfo.baseGS) self:RefreshSubView(true) self.toggles_Btn:SetRedPoint(0, petInfo.petQuality == MDL.Pet.PetQuality.God and CTL.Pet.CanGodPetBreak(petInfo)) self.toggles_Btn:SetRedPoint(1, MDL.Pet.IsPetLineUpOrAssistance(petInfo.petUniqId) and CTL.Pet.CheckPetIfLevelUp(petConfig, petInfo)) UIUtils.SetActive(self.btn_SetFollow, true) if petInfo.petQuality == MDL.Pet.PetQuality.Normal and petInfo.petGeneration == 1 then UIUtils.SetActive(self.btn_Reproduction, true) end UIUtils.SetActive(self.btn_Share, true) else local petConfig = curInfo self.txt_Title.text = nil UIUtils.SetLabelText(self.txt_Name, Const_IDS[petConfig.PetName]) CTL.Pet.SetPetStar(self.group_Star, 10, 1) self.group_Sign.state_Sign:SetState(0) UIUtils.SetLabel(self.txt_BaseAttr, CTL.Pet.GetGrowUpScore(petConfig.Talent_Table, 10, MDL.Pet.PetQuality.God)) UIUtils.SetLabelText(self.group_Sign.lab_SignGod, Const_IDS.IDS_GodPet) UIUtils.SetLabelText(self.group_Sign.txt_Type, Const_IDS.IDS_PetAdvance1) UIUtils.SetActiveByScale(self.toggles_Btn, false) UIUtils.SetActive(self.btn_Edit, false) UIUtils.SetActive(self.btn_Release, false) UIUtils.SetActive(self.group_bottom, false) self:RefreshSubView(false) self.toggles_Btn:SetRedPoint(1, false) UIUtils.SetActive(self.btn_SetFollow, false) UIUtils.SetActive(self.btn_Share, false) end self:UpdateFollowState() end function UIPetBasePanel:UpdateFollowState() if self.selectHeadInfo == nil then self.toggle_AutoFollow.isOn = false self.state_Set:SetState(0) return end if self.selectHeadInfo.isPreview then self.toggle_AutoFollow.isOn = false self.state_Set:SetState(0) else if self.selectHeadInfo.data.Info.petUniqId == MDL.Pet.GetCurFollowPet() then self.toggle_AutoFollow.isOn = true self.state_Set:SetState(1) else self.toggle_AutoFollow.isOn = false self.state_Set:SetState(0) end end end function UIPetBasePanel:RefreshSubView(isBagType) if self.curViewIndex == nil then self.toggles_Btn:SelectIndex(TAB_LEVEL) else if isBagType then self.toggles_Btn:SelectIndex(self.curViewIndex) else self.toggles_Btn:SelectIndex(TAB_BASIC) end end end function UIPetBasePanel:RefreshModelShow() local petConfig = self:GetSelectPetConfig() if petConfig then 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 end -- 播放出场动画 function UIPetBasePanel: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 UIPetBasePanel:UpdateAnimRefresh(deltaTime, timeSinceUpdate) if timeSinceUpdate >= RESET_TIME then self:Reset() return end if timeSinceUpdate >= STATE_SWITCH_TIME and self.isPlayingAnim == false then self:PlayAnim(self:GetSelectPetConfig()) end end -- 播放待机动画 function UIPetBasePanel:Reset() self.isPlayingAnim = false self:ResetRepeatFunc(self.UpdateAnimRefresh) end function UIPetBasePanel:UpdateGodCostMat() self.loopscroll_Head:UpdateIndex(self.loopscroll_Head.Count - 1) end function UIPetBasePanel:OnPetLevelUp() UTL.UIRender.PlayModelPsEffect(self.modelComponentDataHandle, ConstAssetPathConfig.AssetPath161) end function UIPetBasePanel:HasCheatParam() return self.cheatClearEff and self.cheatBgColor end function UIPetBasePanel:SetCheatGreenBg(color, clearEffect) UTL.UIRender.SetCheatGreenBg(self.modelComponentDataHandle, color, clearEffect) self.cheatBgColor = color self.cheatClearEff = clearEffect end return UIPetBasePanel