local UITreasureBasePanel = UIViewClass() local EventSystem = require("Event.EventSystem") local ToggleIndex = { Break = 0, Soul = 1, Info = 2, } local ModelPos = { NotLoad = 0, FarPos = 1, NearPos = 2, } local ModelAnimTime = 0.5 function UITreasureBasePanel:OnCreated() if GameAppInfo.IsVersionGreaterThan19000() then --删除版本判断时,需要同步删除界面上的treasureModel节点 self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.newTreasureModel) self:RegistTriggerEvent(self.newTreasureModel, UIEventTriggerType.Drag) end end function UITreasureBasePanel:OnDrag(comp, eventData) UTL.UIRender.RotateEntity(self.modelComponentDataHandle, -eventData.delta.x * 0.2) end function UITreasureBasePanel:AutoRotate(deltaTime, timeSinceUpdate) UTL.UIRender.RotateEntity(self.modelComponentDataHandle, deltaTime*10) end function UITreasureBasePanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_UpdateTreasureInfo, self.RefreshTreasure) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshTreasureSkill) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshSoulToggleBtnRp) self:RegistSystemEvent(EventID.TreasureSoulCrystal_UpdateBag, self.RefreshAllArrowRp) self:RegistSystemEvent(EventID.UI_Treasure_SaveCurrentTabIndex, self.SaveCurrentTabIndex) self:RegistSystemEvent(EventID.UI_CheatGreenBg, self.SetCheatGreenBg) self:RegistSystemEvent(EventID.UI_CheatAutoRotCamera, self.CheatAutoRotCamera) UIManager.ActiveUIModle(false, "UITreasureBasePanel") -- 界面标题 UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_Treasure_Title_1"]) self.treasureId = context.treasureId self.isFormation = context.isFormation self.showIndex = 1 self:InitPreviewTreasureList() self:SelectTreasureByIndex() -- 设置Toggle self:InitToggles() if context.selectIndex then self:TryToSelectToggleByIndex(context.selectIndex) end end function UITreasureBasePanel:InitPreviewTreasureList() self.previewList = {} if self.isFormation then local slotIds = MDL.Formation.GetSlotHeroIds() for i = 1, #slotIds do if slotIds[i] and slotIds[i] > 0 then local equipTreasure = MDL.Treasure.GetTreasureInfoByHeroId(slotIds[i]) if equipTreasure then table.insert(self.previewList, equipTreasure) end end end else self.previewList = MDL.Treasure.GetSortedTreasureList() end local isMulti = #self.previewList > 1 UIUtils.SetActive(self.btn_Before, isMulti) UIUtils.SetActive(self.btn_Next, isMulti) end function UITreasureBasePanel:SelectTreasureByIndex() for i = 1, #self.previewList do if self.previewList[i].TreasureID == self.treasureId then self.showIndex = i break end end self:RefreshTreasure(self.showIndex) end function UITreasureBasePanel:RefreshTreasure(showIndex) if showIndex then self.showIndex = showIndex self.treasureId = self.previewList[self.showIndex].TreasureID else if self.isFormation then --如果从阵容界面进入,穿戴一个未被装备的宝物,需要更新previewList self:InitPreviewTreasureList() end if self.lastHeroId then local id = MDL.Treasure.GetTreasureInfoByHeroId(self.lastHeroId).TreasureID for i = 1, #self.previewList do if self.previewList[i].TreasureID == id then self.showIndex = i self.treasureId = id break end end end end self:RefreshBaseInfo(self.treasureId) self:UpdateToggle(self.treasureId) self.toggles.toggles[ToggleIndex.Break]:SetRedPoint(CTL.Treasure.IfTreasureCanBreak(self.treasureId)) self.toggles.toggles[ToggleIndex.Info]:SetRedPoint(CTL.Treasure.IfTreasureCanActive(self.treasureId)) self:RefreshSoulToggleBtnRp() self:RefreshTreasureSkill() if self.lastTreasureId and self.lastTreasureId == self.treasureId then return else self.lastTreasureId = self.treasureId end self:ShowTreasureModel(self.treasureId) if self.context then self.context.treasureId = self.treasureId self.context.isFormation = self.isFormation else self.context = {treasureId = self.treasureId, isFormation = self.isFormation} end self:RefreshChangeBtnRp() end function UITreasureBasePanel:RefreshSoulToggleBtnRp() local isShowRp = CTL.Treasure.IfTreasureCanSoulPanel(self.treasureId) self.toggles.toggles[ToggleIndex.Soul]:SetRedPoint(isShowRp) if isShowRp then self.toggles:SetToggleCompActive(ToggleIndex.Soul + 1, "img_YelPoint", false) else self.toggles:SetToggleCompActive(ToggleIndex.Soul + 1, "img_YelPoint", CTL.Treasure.IfTreasureCanSoulRefined(self.treasureId)) end end --按照宝物刷新装备英雄以及是否显示更换按钮 function UITreasureBasePanel:RefreshBaseInfo(treasureId) local equipHeroId = MDL.Treasure.GetTreasureEquipHeroId(treasureId) if equipHeroId then self.lastHeroId = equipHeroId UIUtils.SetActive(self.btn_Change, true) UIUtils.SetActive(self.group_Hero.gameObject, true) UTL.Item.ItemSquareIconByHeroId(equipHeroId, self.img_Head, self.img_BgHead, self.txt_HeroName, MDL.HeroAwaken.GetIsHeroAwaken(equipHeroId)) else self.lastHeroId = nil UIUtils.SetActive(self.btn_Change, false) UIUtils.SetActive(self.group_Hero.gameObject, false) end self:RefreshRelationInfo(treasureId, equipHeroId) end -- 更新宝物羁绊 function UITreasureBasePanel:RefreshRelationInfo(treasureID, equipHeroID) -- 魂晶界面不需要宝物羁绊 if self.lastToggleIndex == ToggleIndex.Soul then UIUtils.SetActive(self.group_FetterHero, false) return end local relationHeroID = CTL.Treasure.GetTreasureRelationHero(treasureID) local relationState = CTL.Treasure.GetTreasureHeroRelationState(treasureID, equipHeroID) UIUtils.SetActive(self.img_Gray, relationState == CTL.Treasure.RelationState.NoHero) UIUtils.SetActive(self.effect_Active, relationState == CTL.Treasure.RelationState.ActiveRelation) if relationHeroID > 0 then UTL.Item.ItemSquareIconByHeroId(relationHeroID, self.img_Hero, self.bg_Hero, MDL.HeroAwaken.GetIsHeroAwaken(relationHeroID)) local isShowRelationHero = relationState ~= CTL.Treasure.RelationState.NoRelation and MDL.HideGolden.IsShowGoldenByID(LuaConst.ShowGoldenType.Hero, relationHeroID) UIUtils.SetActive(self.group_FetterHero, isShowRelationHero) else UIUtils.SetActive(self.group_FetterHero, false) end end function UITreasureBasePanel:TryToSelectToggleByIndex(index) if self.toggles.toggles[index].gameObject.activeSelf then self.toggles.toggles[index].isOn = true else self.toggles.toggles[ToggleIndex.Info].isOn = true end end function UITreasureBasePanel:UpdateToggle(treasureId) if CTL.Treasure.IsTreasureActive(treasureId) then UIUtils.SetActive(self.toggles.toggles[ToggleIndex.Break].gameObject, true) -- 这里需要根据开启条件判断 local equipHeroId = MDL.Treasure.GetTreasureEquipHeroId(treasureId) if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.TreasureSoul) and equipHeroId then UIUtils.SetActive(self.toggles.toggles[ToggleIndex.Soul].gameObject, true) self.toggles:SelectIndex(self.lastToggleIndex or 0) else UIUtils.SetActive(self.toggles.toggles[ToggleIndex.Soul].gameObject, false) if self.lastToggleIndex == ToggleIndex.Soul then self.toggles:SelectIndex(ToggleIndex.Info) end end else self.toggles:SelectIndex(ToggleIndex.Info) UIUtils.SetActive(self.toggles.toggles[ToggleIndex.Break].gameObject, false) UIUtils.SetActive(self.toggles.toggles[ToggleIndex.Soul].gameObject, false) end if self.rightPanel and (self.lastTreasureId and self.lastTreasureId ~= self.treasureId) then self.rightPanel:RefreshTreasureInfo(self.treasureId) end end function UITreasureBasePanel:OnValueChanged(comp, state) if comp == self.toggles then if self.lastToggleIndex ~= state then self.lastToggleIndex = state self.subView:CloseAll() if state == ToggleIndex.Break then self:MoveModelToNear() self.obj_TreasureSoul:SetState(0) self.rightPanel = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UITreasureBreak), {treasureId = self.treasureId}) elseif state == ToggleIndex.Info then self:MoveModelToNear() self.obj_TreasureSoul:SetState(0) self.rightPanel = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UITreasureInfo), {treasureId = self.treasureId}) elseif state == ToggleIndex.Soul then self:MoveModelToFar() self.obj_TreasureSoul:SetState(1) self.rightPanel = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UITreasureSoulCrystalPanel), {treasureId = self.treasureId}) end self:RefreshBaseInfo(self.treasureId) else --子界面执行一个刷新方法 self.rightPanel:RefreshTreasureInfo(self.treasureId) end end end function UITreasureBasePanel:ShowTreasureModel(id) local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(id) UIUtils.SetLabelText(self.txt_TreasureName, Const_IDS[treasureData.TreasureName]) self.txt_TreasureTalent.text = treasureData.TreasureTalent if GameAppInfo.IsVersionGreaterThan19000() then UTL.UIRender.CreateTreasure3DModel(self.modelComponentDataHandle, id) if treasureData.IsRotation then self:StartRepeatFunc(self.AutoRotate, 0, -1, true) else self:StopRepeatFunc(self.AutoRotate) end else self.treasureModel:Show2DBGModel(treasureData.TreasureMode, nil, 1, treasureData.TreasurePreviewModelLight, nil, treasureData.TreasureShowEffect) self.treasureModel:SetSceneTexture(ConstAssetPathConfig.Path40) if not string.isNilOrEmpty(treasureData.TreasureAnim) then self.treasureModel:PlayModelAnimation(treasureData.TreasureAnim) end --self.treasureModel:SetNodePos(0.45, 0.9, 0) self.treasureModel:SetModelRot(0, treasureData.Angle, 0) self.treasureModel:SetNodeRot(treasureData.AngleX, 0, treasureData.AngleZ) self.treasureModel:SetModelRotation(treasureData.IsRotation) self.treasureModel:SetSceneShadowPlane(false) end self:StopRepeatFunc(self.MoveModelNear) self:StopRepeatFunc(self.MoveModelFar) if self.lastToggleIndex == ToggleIndex.Soul then self:SetModelPos(treasureData.PositionX2, treasureData.PositionY2, treasureData.PositionZ2) -- 模型远点 else self:SetModelPos(treasureData.PositionX, treasureData.PositionY, treasureData.PositionZ) -- 模型近点 end --cheatLogic if self.cheatClearEff and self.cheatBgColor then if GameAppInfo.IsVersionGreaterThan19000() then UTL.UIRender.SetCheatGreenBg(self.modelComponentDataHandle, self.cheatBgColor, self.cheatClearEff) else self.treasureModel:SetCheatGreenBg(self.cheatBgColor, self.cheatClearEff) end end end function UITreasureBasePanel:SetCheatGreenBg(color, clearEffect) if GameAppInfo.IsVersionGreaterThan19000() then UTL.UIRender.SetCheatGreenBg(self.modelComponentDataHandle, color, clearEffect) else self.treasureModel:SetCheatGreenBg(color, clearEffect) end self.cheatBgColor = color self.cheatClearEff = clearEffect end function UITreasureBasePanel:CheatAutoRotCamera(enable) if enable then self:StartRepeatFunc(self.AutoRotCameraFunc, 0) else self:StopRepeatFunc(self.AutoRotCameraFunc) end end function UITreasureBasePanel:AutoRotCameraFunc(dt, ts) UTL.UIRender.RotateEntity(self.modelComponentDataHandle, dt * 60) end function UITreasureBasePanel:OnClickNext() local nextIndex = self.showIndex + 1 if nextIndex > #self.previewList then nextIndex = 1 end self:RefreshTreasure(nextIndex) end function UITreasureBasePanel:OnClickLast() local lastIndex = self.showIndex - 1 if lastIndex <= 0 then lastIndex = #self.previewList end self:RefreshTreasure(lastIndex) end function UITreasureBasePanel:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UITreasureBasePanel: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_Before then self:StopRepeatFunc(self.MoveModelNear) self:StopRepeatFunc(self.MoveModelFar) self:OnClickLast() elseif comp == self.btn_Next then self:StopRepeatFunc(self.MoveModelNear) self:StopRepeatFunc(self.MoveModelFar) self:OnClickNext() elseif comp == self.btn_Change then UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureChangeView, {treasureId = self.treasureId}, "WarHorse/UIWarHorseChangeView") elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.Treasure}) elseif comp == self.btn_Enlarge then UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureBreakDetail, {treasureId = self.treasureId, onlyShowSkill = true}, "HeroShow/UIHeroInfoView") elseif comp == self.btn_SkillTips then UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSkillTips, {treasureId = self.treasureId, treasureSkillId = self.treasureSkillId}, "Common/UITalentSkillTips") end end function UITreasureBasePanel:OnClosed() UIManager.ActiveUIModle(true, "UITreasureBasePanel") if self.isFormation == true then local heroId = MDL.Treasure.GetTreasureEquipHeroId(self.treasureId) if heroId then MDL.HeroSelect.curSelectHeroID = heroId end end if GameAppInfo.IsVersionGreaterThan19000() then UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) end end function UITreasureBasePanel:RefreshTreasureSkill() local activeInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) if activeInfo and activeInfo.TreasureInfo.starLevel > 0 then local treasureInfo = activeInfo.TreasureInfo local treasureStarData = DataSheetManager.TreasureStar:GetDataByTreasureID_Star(self.treasureId, treasureInfo.starLevel - 1) self.treasureSkillId = treasureStarData.TreasureSkill else local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(self.treasureId) self.treasureSkillId = treasureData.TreasureSkill end local treasureSkillData = DataSheetManager.TreasureSkillData:GetDataByTreasureSkill(self.treasureSkillId) UIUtils.SetImageByAssetBundle(self.sprite_Skill, treasureSkillData.TreasureSkillIcon) UIUtils.SetLabel(self.txt_SkillName, string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_BreakThrough_SkillName), UIUtils.GetLocalizedTxt(Const_IDS[treasureSkillData.TreasureSkillName]))) UIUtils.SetLabel(self.txt_SkillLevel, CTL.Treasure.IsTreasureActive(self.treasureId) and string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_BreakThrough_Level), treasureSkillData.SkillLevel) or "") self:RefreshAllArrowRp() end function UITreasureBasePanel:RefreshAllArrowRp() self:RefreshArrowRpByIndex(self.btn_Before, self.showIndex - 1) self:RefreshArrowRpByIndex(self.btn_Next, self.showIndex + 1) end function UITreasureBasePanel:SaveCurrentTabIndex() self.context.selectIndex = self.showIndex - 1 -- C#从0开始 end function UITreasureBasePanel:RefreshArrowRpByIndex(btn, index) if index <= 0 then index = #self.previewList end if index > #self.previewList then index = 1 end local treasureId = self.previewList[index].TreasureID btn:SetRedPoint(CTL.Treasure.IfTreasureCanActive(treasureId) or CTL.Treasure.IfTreasureCanBreak(treasureId) or CTL.Treasure.IfTreasureCanSoulPanel(treasureId)) end function UITreasureBasePanel:RefreshChangeBtnRp() self.btn_Change:SetRedPoint(CTL.Treasure.IfHasBetterTreasureToEquip(self.treasureId)) end function UITreasureBasePanel:InitToggles() self.toggles:SetToggleCompImage(1, "img_bg_icon", UTL.Toggle.GetToggleNormalIcon(UTL.Toggle.ToggleType.Breakthrough)) self.toggles:SetToggleCompImage(1, "img_Selected", UTL.Toggle.GetToggleSelectedIcon(UTL.Toggle.ToggleType.Breakthrough)) self.toggles:SetToggleCompImage(2, "img_bg_icon", UTL.Toggle.GetToggleNormalIcon(UTL.Toggle.ToggleType.Information)) self.toggles:SetToggleCompImage(2, "img_Selected", UTL.Toggle.GetToggleSelectedIcon(UTL.Toggle.ToggleType.Information)) self.toggles:SetToggleCompImage(3, "img_bg_icon", UTL.Toggle.GetToggleNormalIcon(UTL.Toggle.ToggleType.TreasureSoul)) self.toggles:SetToggleCompImage(3, "img_Selected", UTL.Toggle.GetToggleSelectedIcon(UTL.Toggle.ToggleType.TreasureSoul)) end --region-------------------------------------------界面模型动画相关-------------------------------------------- function UITreasureBasePanel:MoveModelToNear() if self.modelPosType ~= ModelPos.NearPos then self:StopRepeatFunc(self.MoveModelNear) self:StopRepeatFunc(self.MoveModelFar) self:StartRepeatFunc(self.MoveModelNear, 0.02) self.modelPosType = ModelPos.NearPos end end function UITreasureBasePanel:MoveModelNear(deltaTime, timeSinceUpdate) if timeSinceUpdate > ModelAnimTime then self:StopRepeatFunc(self.MoveModelNear) timeSinceUpdate = ModelAnimTime end local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(self.treasureId) local ratio = timeSinceUpdate / ModelAnimTime local x = UTL.UIRender.GetLerpValue(self.modelPosX, treasureData.PositionX, ratio) local y = UTL.UIRender.GetLerpValue(self.modelPosY, treasureData.PositionY, ratio) local z = UTL.UIRender.GetLerpValue(self.modelPosZ, treasureData.PositionZ, ratio) self:SetModelPos(x, y, z) end function UITreasureBasePanel:MoveModelToFar() if self.modelPosType ~= ModelPos.FarPos then self:StopRepeatFunc(self.MoveModelNear) self:StopRepeatFunc(self.MoveModelFar) self:StartRepeatFunc(self.MoveModelFar, 0.02) self.modelPosType = ModelPos.FarPos end end function UITreasureBasePanel:MoveModelFar(deltaTime, timeSinceUpdate) if timeSinceUpdate > ModelAnimTime then self:StopRepeatFunc(self.MoveModelFar) timeSinceUpdate = ModelAnimTime end local treasureData = DataSheetManager.TreasureData:GetDataByTreasureID(self.treasureId) local ratio = timeSinceUpdate / ModelAnimTime local x = UTL.UIRender.GetLerpValue(self.modelPosX, treasureData.PositionX2, ratio) local y = UTL.UIRender.GetLerpValue(self.modelPosY, treasureData.PositionY2, ratio) local z = UTL.UIRender.GetLerpValue(self.modelPosZ, treasureData.PositionZ2, ratio) self:SetModelPos(x, y, z) end function UITreasureBasePanel:SetModelPos(posX, posY, posZ) if GameAppInfo.IsVersionGreaterThan19000() then UTL.UIRender.SetHeroParentPos(self.modelComponentDataHandle, posX, posY, posZ) local fixValue = UTL.UIRender.GetDistanceFixValue(self.modelComponentDataHandle) self.modelPosX = posX + fixValue self.modelPosY = posY self.modelPosZ = posZ UTL.UIRender.SetHeroParentPos(self.modelComponentDataHandle, posX, posY, posZ) else self.treasureModel:SetNodePos(posX, posY, posZ) local fixValue = self.treasureModel:GetDistanceFixValue() self.modelPosX = posX + fixValue self.modelPosY = posY self.modelPosZ = posZ self.treasureModel:SetNodePos(self.modelPosX, self.modelPosY, self.modelPosZ) end end --endregion return UITreasureBasePanel