--[[ 神兽养成Base界面 context = {id = 1, selectIndex = 1} ]]-- local UIGodBeastBasePanel = UIViewClass() local STATE_SWITCH_TIME = 8 local RESET_TIME = 15 local GODBEAST_SCENE_BASE_PATH = ConstAssetPathConfig.GODBEAST_SCENE_BASE_PATH local BEAST_FORMATION_BG_IMG = ConstAssetPathConfig.BEAST_FORMATION_BG_IMG function UIGodBeastBasePanel:OnCreated() self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.model_Show) end function UIGodBeastBasePanel:OnOpened(context) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_Godbeast_Develop) UIManager.ActiveUIModle(false, "UIGodBeastBasePanel") -- 创建场景 UTL.UIRender.Create2DTextureBgScene( self.modelComponentDataHandle, BEAST_FORMATION_BG_IMG, GODBEAST_SCENE_BASE_PATH, nil, nil ) self.blackPlaneTrans = UTL.UIRender.GetSceneTrans(self.modelComponentDataHandle):Find("BlackPlane") local _, _, z = self.blackPlaneTrans:GetLocalPosition() self.blackPlaneTransZ = z local defaultScaleX, defaultScaleY, defaultScaleZ = self.blackPlaneTrans:GetLocalScale() self.defaultScaleX = defaultScaleX self.defaultScaleY = defaultScaleY self.defaultScaleZ = defaultScaleZ self.blackPlaneTrans:SetLocalPosition(0, 0, -5) self.blackPlaneTrans:SetLocalScale(13.55, 6.25, 1) self:InitParam(context) self:StartRepeatFunc(self.UpdateAnimRefresh, 1, -1) self:RegistSystemEvent(CTL.RedPoint.RedPointKey.GodBeast, self.RefreshToggleRp) self:RegistSystemEvent(EventID.UI_GodBeastRefresh, self.RefreshToggles) self:RegistTriggerEvent(self.model_Show, UIEventTriggerType.Drag) self:RegistSystemEvent(EventID.UI_CheatGreenBg, self.SetCheatGreenBg) self:RegistSystemEvent(EventID.UI_CheatAutoRotCamera, self.CheatAutoRotCamera) end function UIGodBeastBasePanel:InitParam(viewContext) self.lastShowID = nil self.dataList = MDL.GodBeast.GetSortedList() if viewContext and viewContext.toggleType then self.curToggleType = viewContext.toggleType else self.curToggleType = nil end -- 默认传入的神兽没有则默认选中第一个 if viewContext and viewContext.id then self:ShowById(viewContext.id) else self:ShowById(self.dataList[1].ID) end end function UIGodBeastBasePanel:OnClosed() self.blackPlaneTrans:SetLocalPosition(0, 0, self.blackPlaneTransZ) --恢复背景板默认位置 self.blackPlaneTrans:SetLocalScale(self.defaultScaleX, self.defaultScaleY, self.defaultScaleZ) --恢复背景板默认大小 CTL.Sound.StopGameSound(self.curShowData.GodBeastIdleShowAudio) UIManager.ActiveUIModle(true, "UIGodBeastBasePanel") UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) -- 保存context参数 self.context.id = self.curShowData.ID if self.curToggleType then self.context.toggleType = self.curToggleType end end function UIGodBeastBasePanel:ShowById(id) self.curShowData = DataSheetManager.GodBeastData:GetDataByID(id) CTL.GodBeast.SetSkillInfo(self.sprite_Skill, self.txt_SkillName, self.txt_SkillDesc, id) self:RefreshBtns() self:RefreshToggles() self:RefreshToggleRp() UTL.UIRender.LoadDevelop3DModel(self.modelComponentDataHandle, CTL.GodBeast.GetDevelopModelData(id)) self:PlayAnim() --cheatLogic if self:HasCheatParam() then UTL.UIRender.SetCheatGreenBg(self.modelComponentDataHandle, self.cheatBgColor, self.cheatClearEff) end end function UIGodBeastBasePanel:UpdateAnimRefresh(deltaTime, timeSinceUpdate) self.timeSinceUpdate = timeSinceUpdate if timeSinceUpdate >= RESET_TIME then self:Reset() return end if timeSinceUpdate >= STATE_SWITCH_TIME and self.isPlayingAnim == false then self:PlayAnim() end end function UIGodBeastBasePanel:StopModelEffect() UTL.UIRender.StopModelPsEffect(self.modelComponentDataHandle) end -- 播放出场动画 function UIGodBeastBasePanel:PlayAnim() self.isPlayingAnim = true self:StopModelEffect() if not string.isNilOrEmpty(self.curShowData.GodBeastShowEffect2) and self.curToggleType ~= CTL.GodBeast.BaseViewType.Talent then UTL.UIRender.PlayModelPsEffect(self.modelComponentDataHandle, self.curShowData.GodBeastShowEffect2) end self.playingSoundEvent = self.curShowData.GodBeastIdleShowAudio CTL.Sound.PlayGameSound(self.curShowData.GodBeastIdleShowAudio, true) UTL.UIRender.PlayRenderEntityTriggerAnim(self.modelComponentDataHandle, self.curShowData.ModelIdleShowAnim) end -- 播放待机动画 function UIGodBeastBasePanel:Reset() self.isPlayingAnim = false self:ResetRepeatFunc(self.UpdateAnimRefresh) end function UIGodBeastBasePanel:RefreshBtns() UIUtils.SetActive(self.btn_Before, true) UIUtils.SetActive(self.btn_Next, true) end function UIGodBeastBasePanel:GetToggleIndexByType(viewType) for index, viewName in ipairs(self.viewTypeList) do if viewType == viewName then return index - 1 end end return 0 end function UIGodBeastBasePanel:RefreshToggleRp() local godBeastID = self.curShowData.ID for i, viewName in ipairs(self.viewTypeList) do local index = i - 1 if viewName == CTL.GodBeast.BaseViewType.LevelUp then self.toggles:SetRedPoint(index, MDL.GodBeast.CanRaiseUp(godBeastID)) elseif viewName == CTL.GodBeast.BaseViewType.Break then self.toggles:SetRedPoint(index, MDL.GodBeast.CanBreak(godBeastID)) elseif viewName == CTL.GodBeast.BaseViewType.Talent then self.toggles:SetRedPoint(index, MDL.GodBeast.GetCurTalentPointBeastID(godBeastID) > 0) elseif viewName == CTL.GodBeast.BaseViewType.Detail then self.toggles:SetRedPoint(index, MDL.GodBeast.IsBeastCanActive(godBeastID)) end end end function UIGodBeastBasePanel:RefreshToggles() local beastInfo = MDL.GodBeast.GetGodBeastInfoByID(self.curShowData.ID) local toggleIDS = {} self.viewTypeList = {} if beastInfo then if MDL.GodBeast.IsBeastInLineup(beastInfo.godBeastId) then -- 喂养进修 table.insert(toggleIDS, Const_IDS.IDS_Godbeast_LevelUp1) table.insert(self.viewTypeList, CTL.GodBeast.BaseViewType.LevelUp) end -- 命轮(突破) table.insert(toggleIDS, Const_IDS.IDS_Godbeast_FateWheel) table.insert(self.viewTypeList, CTL.GodBeast.BaseViewType.Break) -- 天赋 table.insert(toggleIDS, Const_IDS.IDS_Godbeast_Talent1) table.insert(self.viewTypeList, CTL.GodBeast.BaseViewType.Talent) end table.insert(toggleIDS, Const_IDS.IDS_Fomation_Detail) table.insert(self.viewTypeList, CTL.GodBeast.BaseViewType.Detail) UTL.Toggle.InitToggleGroupByIDS(self.toggles, "text", toggleIDS) -- 设置Toggle for i, viewClass in ipairs (self.viewTypeList) do if viewClass == Const_UI_Lua.UIEnum.UIGodBeastInfo then self.toggles:SetToggleCompImage(i, "img_bg_icon", UTL.Toggle.GetToggleNormalIcon(UTL.Toggle.ToggleType.Information)) self.toggles:SetToggleCompImage(i, "img_SelectedIcon1", UTL.Toggle.GetToggleSelectedIcon(UTL.Toggle.ToggleType.Information)) elseif viewClass == Const_UI_Lua.UIEnum.UIGodBeastLevelUp then self.toggles:SetToggleCompImage(i, "img_bg_icon", UTL.Toggle.GetToggleNormalIcon(UTL.Toggle.ToggleType.GodBeastLevelUp)) self.toggles:SetToggleCompImage(i, "img_SelectedIcon1", UTL.Toggle.GetToggleSelectedIcon(UTL.Toggle.ToggleType.GodBeastLevelUp)) elseif viewClass == Const_UI_Lua.UIEnum.UIGodBeastTalent then self.toggles:SetToggleCompImage(i, "img_bg_icon", UTL.Toggle.GetToggleNormalIcon(UTL.Toggle.ToggleType.GodBeastTalent)) self.toggles:SetToggleCompImage(i, "img_SelectedIcon1", UTL.Toggle.GetToggleSelectedIcon(UTL.Toggle.ToggleType.GodBeastTalent)) elseif viewClass == Const_UI_Lua.UIEnum.UIGodBeastBreak then self.toggles:SetToggleCompImage(i, "img_bg_icon", UTL.Toggle.GetToggleNormalIcon(UTL.Toggle.ToggleType.HorseSoul)) self.toggles:SetToggleCompImage(i, "img_SelectedIcon1", UTL.Toggle.GetToggleSelectedIcon(UTL.Toggle.ToggleType.HorseSoul)) end end if self.curToggleType == nil then self.toggles:SelectIndex(0) else if self.lastShowID == self.curShowData.ID and self.subView:IsViewOpened(self.curToggleType) then return end self.toggles:SelectIndex(self:GetToggleIndexByType(self.curToggleType)) end -- 选中后设置last ID缓存 self.lastShowID = self.curShowData.ID end function UIGodBeastBasePanel:CloseSubView() if self.curView then self.curView:CloseView() self.curView = nil end end function UIGodBeastBasePanel:GetCurShowIndex() for i, data in ipairs(self.dataList) do if data.ID == self.curShowData.ID then return i end end end function UIGodBeastBasePanel:ArrowShow(delta) local targetIndex, dataLength = self:GetCurShowIndex(), #self.dataList targetIndex = targetIndex + delta if targetIndex <= 0 then targetIndex = dataLength elseif targetIndex > dataLength then targetIndex = 1 end self:ShowById(self.dataList[targetIndex].ID) end function UIGodBeastBasePanel:ShowViewByIndex(index) local isBackFromTalent = self.curToggleType == CTL.GodBeast.BaseViewType.Talent self:CloseSubView() if not self.subView:IsViewOpened(self.viewTypeList[index]) then if self.viewTypeList[index] == CTL.GodBeast.BaseViewType.Talent then UTL.UIRender.SetModelVisible(self.modelComponentDataHandle, false) UIUtils.SetActive(self.Bottom.gameObject, true) self:StopModelEffect() if self.curShowData then CTL.Sound.StopGameSound(self.curShowData.GodBeastIdleShowAudio) end else UTL.UIRender.SetModelVisible(self.modelComponentDataHandle, true) if isBackFromTalent then UIUtils.SetActive(self.Bottom.gameObject, false) UTL.UIRender.SetEntityEulerAngles(self.modelComponentDataHandle, self.curShowData.ModelRot, true, true) end end if not self:HasCheatParam() then self.curView = self.subView:OpenView(GetViewClass(self.viewTypeList[index]), {config = self.curShowData}) end self.curToggleType = self.viewTypeList[index] end end function UIGodBeastBasePanel:SetCheatGreenBg(color, clearEffect) --加神兽的时候不需要判断版本兼容老接口了 UTL.UIRender.SetCheatGreenBg(self.modelComponentDataHandle, color, clearEffect) self.cheatBgColor = color self.cheatClearEff = clearEffect end function UIGodBeastBasePanel:HasCheatParam() return self.cheatClearEff and self.cheatBgColor end --region ----------------------------------- 系统函数 ---------------------------------------------- function UIGodBeastBasePanel:OnValueChanged(comp, index) if comp == self.toggles then self:ShowViewByIndex(index + 1) end end function UIGodBeastBasePanel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIGodBeastBasePanel:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.GodBeast }) elseif comp == self.btn_Before then self:ArrowShow(-1) elseif comp == self.btn_Next then self:ArrowShow(1) elseif comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.btn_SkillTips then CTL.GodBeast.OpenSkillPreviewPanel(self.curShowData.ID) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() end end function UIGodBeastBasePanel:OnDrag(comp, eventData) UTL.UIRender.RotateEntity(self.modelComponentDataHandle, -eventData.delta.x * 0.2, true, true) end function UIGodBeastBasePanel:CheatAutoRotCamera(enable) if enable then self:StartRepeatFunc(self.AutoRotCameraFunc, 0) else self:StopRepeatFunc(self.AutoRotCameraFunc) end end function UIGodBeastBasePanel:AutoRotCameraFunc(dt, ts) UTL.UIRender.RotateEntity(self.modelComponentDataHandle, dt * 60, true, true) end --endregion return UIGodBeastBasePanel