local UIDyeAppearanceBase = UIViewClass() local UIHeroLightEffectTool = require "View/Common/UIHeroLightEffectTool" local SCENE_PATH = ConstAssetPathConfig.DyeBgPath local function SortByQuality(cfg1, cfg2) return cfg1.Quality < cfg2.Quality end function UIDyeAppearanceBase:OnOpened(context) if UNITY_EDITOR then AuxUtil.AddMouseEventHelper(self.gameObject) end CTL.Setting.Set5SSkin(true) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_CollectionAP_Entrance) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) self:RegistSystemEvent(EventID.UI_DyeAppearance_ChangeModelPartDye, self.OnChangeModelPartDye) self:RegistSystemEvent(EventID.UI_DyeAppearance_SwitchTabIndex, self.OnSwitchTabIndex) self:RegistSystemEvent(EventID.UI_CloseAndRecoverView, self.OnCloseAndRecoverView) self:RegistSystemEvent(EventID.UI_DyeAppearance_UpdateInfo, self.UpdateToggleRed) self:RegistSystemEvent(EventID.UI_DyeAppearance_UpdateModelDye, self.OnUpdateModelDye) self:RegistSystemEvent(EventID.UI_DyeAppearance_UpdateDrawCardRed, self.UpdateToggleRed) self:RegistSystemEvent(EventID.UI_Appearance_Refresh, self.OnWeaponChanged) self:RegistSystemEvent(EventID.UI_LightEffect_PutOnLightEffect, self.OnLightEffectChanged) self:RegistTriggerEvent(self.heroShow, UIEventTriggerType.Drag) self:RegistTriggerEvent(self.heroShow, UIEventTriggerType.EndDrag) self.CameraCtrl = CameraController.Instance UIManager.ActiveUIModle(false, "UIDyeAppearanceBase") self:InitHeroModel() self:InitToggles() self.toggles_Group:SelectIndex(context.selectTabIndex or 0) end function UIDyeAppearanceBase:InitHeroModel() local heroId, appearanceId = self.context.heroId, self.context.appearanceId self.heroLightEffectDatas = UIHeroLightEffectTool.CreateHeroLightEffectDatas(true) self.modelComponentDataHandle = UTL.UIRender.CreateModelComponentDatas(self.heroShow) UTL.UIRender.Create3DSceneTrans(self.modelComponentDataHandle, SCENE_PATH, 2000, 0, 2000, 0, 327, 0, UTL.UIRender.LayerActiveType.HeroShow) local heroShowId, modelPath, modelScale, heroEffectPath, lightPath = UTL.UIRender.GetShowHeroData(heroId, nil, appearanceId) local heroData = DataSheetManager.HeroAppearance:GetDataByID(appearanceId) lightPath = heroData.PreviewModelLight_New UTL.UIRender.CreatePlayerModel(self.modelComponentDataHandle, heroShowId, modelPath, lightPath, true, nil, nil, true) end function UIDyeAppearanceBase:OnDrag(comp, eventData) if Input.touchCount <= 1 then self.CameraCtrl:RotatingByManual(eventData.delta) else if not self.lastEventData1 then self.lastEventData1 = eventData self.lastEventDataPos1 = eventData.position elseif self.lastEventData1 ~= eventData then self.lastEventData2 = eventData self.lastEventDataPos2 = eventData.position end if not self.lastEventData1 or not self.lastEventData2 then return end local lastDistance = Vector2.Distance(self.lastEventDataPos1, self.lastEventDataPos2) local thisDistance = Vector2.Distance(self.lastEventData1.position, self.lastEventData2.position) if lastDistance ~= thisDistance then self.CameraCtrl:ScalingByManual(thisDistance > lastDistance) end self.lastEventDataPos1 = self.lastEventData1.position self.lastEventDataPos2 = self.lastEventData2.position end end function UIDyeAppearanceBase:OnEndDrag(comp, eventData) self.lastEventData1 = nil self.lastEventData2 = nil end function UIDyeAppearanceBase:InitToggles() self.tabInfoList = {} for i, v in DataSheetManager.CollectionAPSuit:GetEnumerator() do if v.Quality < CTL.DyeAppearance.SuitQuality_Middle and v.IsInit == false then table.insert(self.tabInfoList, v) end end table.sort(self.tabInfoList, SortByQuality) local idsList = { Const_IDS.IDS_Chat_Icon_Dangqian1 } for i, v in ipairs(self.tabInfoList) do table.insert(idsList, Const_IDS[v.Name]) end table.insert(self.tabInfoList, 1, 0) UTL.Toggle.InitToggleGroupByIDS(self.toggles_Group, "txt", idsList) for i, v in ipairs(self.tabInfoList) do if i > 1 then if v.Quality == CTL.DyeAppearance.SuitQuality_Middle then self.toggles_Group:GetToggleComponent(i, "state"):SetState(1) elseif v.Quality == CTL.DyeAppearance.SuitQuality_Best then self.toggles_Group:GetToggleComponent(i, "state"):SetState(3) else self.toggles_Group:GetToggleComponent(i, "state"):SetState(2) end else self.toggles_Group:GetToggleComponent(i, "state"):SetState(0) end end end function UIDyeAppearanceBase:UpdateToggleRed() local drawRed = CTL.DyeAppearance.CheckDrawCardRed(self.context.appearanceId) local red_tab1 = CTL.DyeAppearance.CheckNoticeRed(self.context.appearanceId) or drawRed self.toggles_Group:SetRedPoint(0, red_tab1) for i = 2, #self.tabInfoList do self.toggles_Group:SetRedPoint(i - 1, drawRed) end end function UIDyeAppearanceBase:OnValueChanged(comp, index) if comp == self.toggles_Group then if index > 0 and CTL.DyeAppearance.CheckIfUnSave(self.context.appearanceId) then self.toggles_Group:SelectIndex(0, false) local func1 = function() self.toggles_Group:SelectIndex(index) self:OnSwitchTab(index) self.isSwitchingTab = true MDL.DyeAppearance.SetCurColorReq(self.context.appearanceId, CTL.DyeAppearance.GetRecordColorList()) end local func2 = function() CTL.DyeAppearance.RecoverDyeRecord(self.context.appearanceId) self.toggles_Group:SelectIndex(index) self:OnSwitchTab(index) end UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_CollectionAP_Tip4, func1, func2) return end self:OnSwitchTab(index) end end function UIDyeAppearanceBase:OnSwitchTab(tabIndex) self.curTabIndex = tabIndex self.subView:CloseAll() if tabIndex == 0 then self:OnResetModelDye(true) self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIDyeAppearanceCurrent), { heroId = self.context.heroId, appearanceId = self.context.appearanceId }) else local suitId = self.tabInfoList[tabIndex + 1].ID self:OnChangeModelSuit(suitId) self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIDyeAppearanceSuit), { heroId = self.context.heroId, appearanceId = self.context.appearanceId, suitId = suitId }) end self:UpdateToggleRed() end function UIDyeAppearanceBase:OnResetModelDye(isResetLight) UTL.UIRender.SetModelDye(self.modelComponentDataHandle, self.context.appearanceId, CTL.DyeAppearance.GetRecordColorList(), 2) UTL.UIRender.ChangeEntityWeapon(self.modelComponentDataHandle, self.context.heroId, MDL.HeroSelect.GetWeaponAppearanceIDByID(self.context.heroId), 0, true, true) if isResetLight then UIHeroLightEffectTool.StopHeroLightEffect(self.heroLightEffectDatas) local heroLightEffects = MDL.LightEffect.GetHeroWearLightEffectIDList(self.context.heroId) if heroLightEffects then self:BeginHeroLightEffect(heroLightEffects) end end end function UIDyeAppearanceBase:OnChangeModelPartDye(partIndex, partId) CTL.DyeAppearance.SetPartRecordColor(partIndex, partId) UTL.UIRender.SetModelDye(self.modelComponentDataHandle, self.context.appearanceId, CTL.DyeAppearance.GetRecordColorList(), 2) end function UIDyeAppearanceBase:OnChangeModelSuit(suitId) local suitCfg = DataSheetManager.CollectionAPSuit:GetDataByID(suitId) UTL.UIRender.SetModelDye(self.modelComponentDataHandle, self.context.appearanceId, suitCfg.PartList, 2) --修改神兵 if suitCfg.MagicWeaponID > 0 then UTL.UIRender.ChangeEntityWeapon(self.modelComponentDataHandle, self.context.heroId, suitCfg.MagicWeaponID, 0, true, true) end --修改特效 UIHeroLightEffectTool.StopHeroLightEffect(self.heroLightEffectDatas) local effectList = {} if suitCfg.LightEffectID1 > 0 then table.insert(effectList, suitCfg.LightEffectID1) end if suitCfg.LightEffectID2 > 0 then table.insert(effectList, suitCfg.LightEffectID2) end if suitCfg.LightEffectID3 > 0 then table.insert(effectList, suitCfg.LightEffectID3) end if #effectList > 0 then self:BeginHeroLightEffect(effectList) else local heroLightEffects = MDL.LightEffect.GetHeroWearLightEffectIDList(self.context.heroId) if heroLightEffects then self:BeginHeroLightEffect(heroLightEffects) end end end function UIDyeAppearanceBase:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIDyeAppearanceBase:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:TryExit(true,false) elseif comp == self.UITemplateTitlePanel.btn_Home then self:TryExit(true,true) end end function UIDyeAppearanceBase:TryExit(isCheck, isHome) if isCheck and CTL.DyeAppearance.CheckIfUnSave(self.context.appearanceId) then local func1 = function() MDL.DyeAppearance.SetCurColorReq(self.context.appearanceId, CTL.DyeAppearance.GetRecordColorList()) self:TryExit(false, isHome) end local func2 = function() self:TryExit(false, isHome) end UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_CollectionAP_Tip4, func1, func2) return end if isHome then CTL.HomeMain.CloseViewBackHomeMain() else self:CloseView(true) end end function UIDyeAppearanceBase:BeginHeroLightEffect(heroLightEffects) for _, lightEffectID in ipairs(heroLightEffects) do UIHeroLightEffectTool.PlayHeroLightEffect(self.heroLightEffectDatas, self, 0, UIHeroLightEffectTool.PlayLightEffectFuncEnum.LuaView, lightEffectID, nil) end end function UIDyeAppearanceBase:OnClosed() UIManager.ActiveUIModle(true, "UIDyeAppearanceBase") CTL.Setting.Set5SSkin(false) UIHeroLightEffectTool.StopHeroLightEffect(self.heroLightEffectDatas) UTL.UIRender.DisposeModelComponentData(self.modelComponentDataHandle) self.context.selectTabIndex = self.curTabIndex UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) end function UIDyeAppearanceBase:OnSwitchTabIndex(index) if self.curTabIndex == index then self:OnSwitchTab(index) else self.toggles_Group:SelectIndex(index) end end function UIDyeAppearanceBase:AuxUtilPlayPsEffect(effectPath) return UTL.UIRender.PlayPsEffect(self.modelComponentDataHandle, effectPath) end function UIDyeAppearanceBase:OnUpdateModelDye() if self.isSwitchingTab then self.isSwitchingTab = false return end self:OnResetModelDye(false) end function UIDyeAppearanceBase:OnWeaponChanged() UTL.UIRender.ChangeEntityWeapon(self.modelComponentDataHandle, self.context.heroId, MDL.HeroSelect.GetWeaponAppearanceIDByID(self.context.heroId), 0, true, true) end function UIDyeAppearanceBase:OnLightEffectChanged() UIHeroLightEffectTool.StopHeroLightEffect(self.heroLightEffectDatas) local heroLightEffects = MDL.LightEffect.GetHeroWearLightEffectIDList(self.context.heroId) if heroLightEffects then self:BeginHeroLightEffect(heroLightEffects) end end return UIDyeAppearanceBase