local UIDivineWeaponAct = UIViewClass() local EventSystem = require('Event/EventSystem') local OnceAcitveGapTime = 0.3 function UIDivineWeaponAct:OnOpened(context) self:RegistSystemEvent(EventID.UI_DivineWeapon_Update,self.RefreshInfo) self:RegistSystemEvent(EventID.UI_DivineWeapon_ActiveOneStep, self.ActiveOneStep) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshCost) end function UIDivineWeaponAct:Init(data) self.isExcuteActiveOnce = false UIManager.CloseView(Const_UI_Lua.UIEnum.UIHeroAdvancedTips) self:StopRepeatFunc(self.PlayPhaseActiveEffect) self:ShowWeaponInfo(data) end function UIDivineWeaponAct:ShowWeaponInfo(data) self.data = data self.context = {data = self.data} self:RefreshInfo(true) self:SetSkillIcon() for i=1,5 do self:RegistTriggerEvent(self.group_Skill[i].event_Skill, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(self.group_Skill[i].event_Skill, UIEventTriggerType.PointerUp) end end function UIDivineWeaponAct:SetPanelInfo(isUpdate) if self.heroInfo then if not isUpdate then self:ShowTips(self.curShowAttrIndex,self.heroInfo.magicWeaponActivePhase) end if not self.heroInfo.isMagicWeaponActive then self.curShowAttrIndex = self.heroInfo.magicWeaponActivePhase + 1 self.attrpanel.gameObject:SetActive(true) self:ShowAttr(self.curShowAttrIndex) self:SetState() UIUtils.SetGray(self.img_WeaponSkill,true) UIUtils.SetActive(self.lab_Actived,false) else --隐藏显示 self.curShowAttrIndex = nil self.attrpanel.gameObject:SetActive(false) self:SetState() self.group_Item01.gameObject:SetActive(false) self.group_Item02.gameObject:SetActive(false) UIUtils.SetActive(self.lab_Actived,true) UIUtils.SetGray(self.img_WeaponSkill,false) end else self.event_Act:SetGray(true,true) self.event_ActInOnce:SetGray(true, true) self.Loc_ChangeColor:SetState(1) self.event_Act:SetRedPoint(false) self.event_ActInOnce:SetRedPoint(false) self.attrpanel.gameObject:SetActive(false) UIUtils.SetGray(self.img_WeaponSkill,true) UIUtils.SetActive(self.lab_Actived,false) local totalNum = 5 for i=1,totalNum do self.group_Skill[i].sprite_completed.gameObject:SetActive(true) self.group_Skill[i].sprite_gray.gameObject:SetActive(true) self.group_Skill[i].Skill:StopUIEffect() end end local nextData = DataSheetManager.MagicWeaponStar:GetDataByMagicWeaponID_Star(self.data.MagicWeaponID, self.data.Star and self.data.Star or 0) local weaponData = DataSheetManager.MagicWeaponData:GetDataByMagicWeaponID(nextData.MagicWeaponID) UIUtils.SetLabel(self.txt_TreasureTalent, weaponData.MagicWeaponTalent) UIUtils.SetLabel(self.lab_TreasureName, UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[weaponData.MagicWeaponName]), weaponData.MagicWeaponQuality)) -- 神兵名 if self.data.Star then UIUtils.SetLabel(self.txt_Break, string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Handbook_Hero_BreakLevel), self.data.Star)) -- 突破等级 end end function UIDivineWeaponAct:ShowTips() if self.curShowAttrIndex and self.curShowAttrIndex == self.heroInfo.magicWeaponActivePhase then CTL.Sound.PlayGameSound("UI_active_01") UIManager.CloseView(Const_UI_Lua.UIEnum.UIHeroAdvancedTips) UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroAdvancedTips, {isWeapon = true, attr = self.data.Attr_Table[self.curShowAttrIndex].AttrRepeat}) if self.heroInfo.isMagicWeaponActive then self.effect:PlayUIEffect(ConstAssetPathConfig.AssetPath124,1.5) self:StartRepeatFunc(self.OnUpdateFun, 1.5) MDL.DivineWeapon.SetActiveState(true) CTL.Sound.PlayGameSound("UI_active_02") end end end function UIDivineWeaponAct:OnClosed() MDL.DivineWeapon.SetActiveState(false) -- 防止一键激活进程中断导致的未发刷新事件 所以关闭的时候调用一下刷新事件 EventSystem.Dispatch(EventID.UI_DivineWeapon_Update) end function UIDivineWeaponAct:OnUpdateFun(deltaTime, timeSinceUpdate) UIManager.OpenAndPush(Const_UI_Lua.UIEnum.UIDivineWeaponSuccess, {data = self.data}, nil, "DivineWeapon/UIDivineWeaponBasePanel") MDL.DivineWeapon.SetActiveState(false) end function UIDivineWeaponAct:SetState() local completedCount = 0 local selectIndex = 0 local garyCount = 0 local setGrayAt = 0 local totalNum = 5 if self.curShowAttrIndex then completedCount = self.curShowAttrIndex -1 selectIndex = self.curShowAttrIndex garyCount = 5 - self.curShowAttrIndex elseif self.heroInfo and self.heroInfo.isMagicWeaponActive then completedCount = 5 else garyCount = 5 end for i=1,completedCount do self.group_Skill[i].sprite_completed.gameObject:SetActive(true) self.group_Skill[i].sprite_gray.gameObject:SetActive(false) self.group_Skill[i].Skill:StopUIEffect() self.group_Skill[i].Skill:PlayUIEffect(ConstAssetPathConfig.AssetPath125,-1) end if selectIndex > 0 then self.group_Skill[selectIndex].sprite_completed.gameObject:SetActive(true) self.group_Skill[selectIndex].sprite_gray.gameObject:SetActive(true) self.group_Skill[selectIndex].Skill:StopUIEffect() self.group_Skill[selectIndex].Skill:PlayUIEffect(ConstAssetPathConfig.AssetPath126,-1) end setGrayAt = 5-garyCount+1 for i=setGrayAt,totalNum do self.group_Skill[i].sprite_completed.gameObject:SetActive(true) self.group_Skill[i].sprite_gray.gameObject:SetActive(true) self.group_Skill[i].Skill:StopUIEffect() end end function UIDivineWeaponAct:RefreshInfo(isUpdate) -- 一键激活标志位失效 self.isExcuteActiveOnce = false self.heroInfo = MDL.HeroSelect.GetHeroInfo(self.data.MagicWeaponID) if self.heroInfo then self.curActivePhase = self.heroInfo.magicWeaponActivePhase if self.heroInfo.isMagicWeaponActive then UIUtils.SetLabelText(self.labLocal_Info,Const_IDS[self.data.ActivationSkillDes]) else UIUtils.SetLabelText(self.labLocal_Info,Const_IDS[self.data.NotActivationSkillDes]) end self.event_Act.gameObject:SetActive(not self.heroInfo.isMagicWeaponActive) self.event_ActInOnce.gameObject:SetActive(not self.heroInfo.isMagicWeaponActive) else self.curActivePhase = 0 UIUtils.SetLabelText(self.labLocal_Info,Const_IDS[self.data.NotActivationSkillDes]) end self:SetCostInfo(self.data,self.heroInfo) self:SetPanelInfo(isUpdate) end function UIDivineWeaponAct:OnPointerDown(comp, eventData) if comp == self.event_Skill01 then self:ShowAttr(1) elseif comp == self.event_Skill02 then self:ShowAttr(2) elseif comp == self.event_Skill03 then self:ShowAttr(3) elseif comp == self.event_Skill04 then self:ShowAttr(4) elseif comp == self.event_Skill05 then self:ShowAttr(5) end end function UIDivineWeaponAct:OnPointerUp(comp, eventData) if comp == self.event_Skill01 then self:HideAttr(1) elseif comp == self.event_Skill02 then self:HideAttr(2) elseif comp == self.event_Skill03 then self:HideAttr(3) elseif comp == self.event_Skill04 then self:HideAttr(4) elseif comp == self.event_Skill05 then self:HideAttr(5) end end function UIDivineWeaponAct:HideAttr(index) if self.curShowAttrIndex == index then return end if self.curShowAttrIndex == nil then self.attrpanel.gameObject:SetActive(false) return end self:ShowAttr(self.curShowAttrIndex) end function UIDivineWeaponAct:ShowAttr(index) self.attrState:SetState(index-1) self.attrpanel.gameObject:SetActive(true) self.attrpanel:SetAnchoredPosition(0,0) self:SetAttr(self.txt_Info1,self:GetAttr(self.data.Attr_Table[index].AttrRepeat)[1]) end function UIDivineWeaponAct:SetAttr(text,attrInfo) local attrData = DataSheetManager.AttrData:GetDataByID(attrInfo.AttrType) if attrData then UIUtils.SetLabel(text,UIUtils.GetLocalizedTxt(Const_IDS[attrData.Name])..UTL.Color.FormatGreenColor("+"..attrInfo.AttrNum)) end end function UIDivineWeaponAct:GetAttr(id) local data = DataSheetManager.MagicWeaponAttrRepeat:GetDataByAttrRepeatID(id) if data then return data.Attr_Table end return nil end function UIDivineWeaponAct:SetSkillIcon() local skillData = DataSheetManager.SkillData:GetDataByID(self.data.ActivationMusouSkillID) local skillPath = ConstAssetPathConfig.skillPath..skillData.Icon..".png" UIUtils.SetImageByAssetBundle(self.img_WeaponSkill,skillPath) end function UIDivineWeaponAct:RefreshCost() self:SetCostInfo(self.data,self.heroInfo) end function UIDivineWeaponAct:SetCostInfo(data,heroInfo) local index = 1 if heroInfo then index = heroInfo.magicWeaponActivePhase+1 end self.itemNotEnough = false if heroInfo == nil or ( heroInfo and not heroInfo.isMagicWeaponActive) then -- 神兵激活默认道具为1个 local costInfo = MDL.DivineWeapon.GetCostInfo(data.Item_Table[index].ItemRepeat) UTL.Item.ItemIconWithoutBg(self.DetailMoneyIcon, costInfo[1].ItemID) UIUtils.SetLabel(self.txt_NumCost, self:GetItemStr(costInfo[1].ItemID, costInfo[1].ItemNum)) end self.event_Act:SetGray(self.itemNotEnough,true) self.event_ActInOnce:SetGray(self.itemNotEnough,true) self.Loc_ChangeColor:SetState(self.itemNotEnough and 1 or 0) self.event_Act:SetRedPoint(not self.itemNotEnough) self.event_ActInOnce:SetRedPoint(not self.itemNotEnough) end function UIDivineWeaponAct:GetItemStr(id,needCount) local haveCount = MDL.Bag.GetItemCount(id) if needCount<=haveCount then return UTL.Color.FormatQualityText(haveCount,1).."/"..needCount else self.itemNotEnough = true return UTL.Color.FormatRedColor(haveCount).."/"..needCount end end function UIDivineWeaponAct:OnButtonClicked(comp) if self.event_Act == comp then if self.heroInfo == nil then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Hero_NotEngouh"]) return end if self.itemNotEnough then local costInfo = MDL.DivineWeapon.GetCostInfo(self.data.Item_Table[1].ItemRepeat) UTL.ItemTips.ShowCommonTipsById(costInfo[1].ItemID) EventSystem.Dispatch(EventID.UI_ItemTips_OpenItemSource) CTL.Tips.AddTipsMsg(Const_IDS["IDS_MagicWeapon_NotEngouh"]) return end if self.isExcuteActiveOnce then return end MDL.DivineWeapon.ActiveDivineWeaponRequest(self.data.MagicWeaponID) elseif self.event_ActInOnce == comp then if self.heroInfo == nil then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Hero_NotEngouh"]) return end if self.itemNotEnough then local costInfo = MDL.DivineWeapon.GetCostInfo(self.data.Item_Table[1].ItemRepeat) UTL.ItemTips.ShowCommonTipsById(costInfo[1].ItemID) EventSystem.Dispatch(EventID.UI_ItemTips_OpenItemSource) CTL.Tips.AddTipsMsg(Const_IDS["IDS_MagicWeapon_NotEngouh"]) return end if self.isExcuteActiveOnce then return end MDL.DivineWeapon.OneKeyActiveWeaponRequest(self.data.MagicWeaponID) elseif self.group_Item01.event_Click == comp then UTL.ItemTips.ShowCommonTipsById(self.itemId1) elseif self.group_Item02.event_Click == comp then UTL.ItemTips.ShowCommonTipsById(self.itemId2) elseif self.btn_Enlarge == comp then UIManager.OpenView(Const_UI_Lua.UIEnum.UIDivineWeaponBreakInfoView, {weaponId = self.data.MagicWeaponID}, "HeroShow/UIHeroInfoView") elseif self.btn_DetailMoneyIcon == comp then local costInfo = MDL.DivineWeapon.GetCostInfo(self.data.Item_Table[1].ItemRepeat) UTL.ItemTips.ShowCommonTipsById(costInfo[1].ItemID) EventSystem.Dispatch(EventID.UI_ItemTips_OpenItemSource) end end function UIDivineWeaponAct:ActiveOneStep(heroId, targetActivePhase) if self.heroInfo.heroId == heroId then if self.curActivePhase < targetActivePhase then self.targetActivePhase = targetActivePhase self.isExcuteActiveOnce = true self:PlayPhaseActiveEffect() end end end function UIDivineWeaponAct:PlayPhaseActiveEffect() if self.curActivePhase == self.targetActivePhase then self.curShowAttrIndex = self.curActivePhase + 1 > #self.group_Skill and self.curActivePhase or self.curActivePhase + 1 EventSystem.Dispatch(EventID.UI_DivineWeapon_Update) else self.curActivePhase = self.curActivePhase + 1 local skillCmp = self.group_Skill[self.curActivePhase] if skillCmp then -- 当前突破点位播放特效 skillCmp.sprite_completed.gameObject:SetActive(true) skillCmp.sprite_gray.gameObject:SetActive(false) skillCmp.Skill:StopUIEffect() skillCmp.Skill:PlayUIEffect(ConstAssetPathConfig.AssetPath125,-1) -- 当前突破点位激活属性显示 UIManager.CloseView(Const_UI_Lua.UIEnum.UIHeroAdvancedTips) UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroAdvancedTips, {isWeapon = true, attr = self.data.Attr_Table[self.curActivePhase].AttrRepeat}) end self:StartRepeatFunc(self.PlayPhaseActiveEffect, OnceAcitveGapTime, 1, true, true) end end return UIDivineWeaponAct