local UIDivineWeaponAwaken = UIViewClass() local resonance_info = require 'Proto/resonance_info_pb' local EventSystem = require('Event/EventSystem') function UIDivineWeaponAwaken:OnOpened(context) self:RegistSystemEvent(EventID.UI_ResonanceChange_Refresh, self.RefreshResonanceLv) self:RegistSystemEvent(EventID.BagItem_Update, self.HandleItemUpdate) self:RegistSystemEvent(EventID.UI_HeroAwaken_WeaponAwaken, self.RefreshInfo) self:RegistSystemEvent(EventID.UI_HeroAwaken_UpdateWeaponBreakInfo, self.RefreshInfo) self:RegistSystemEvent(EventID.UI_HeroAwaken_OnBigBreakExp, self.OnBigBreakExp) for i, v in ipairs(self.group_Advanced.group_unStage) do self:RegistTriggerEvent(v, UIEventTriggerType.PointerDown) self:RegistTriggerEvent(v, UIEventTriggerType.PointerUp) end self:RefreshResonanceLv() end function UIDivineWeaponAwaken:Init(magicWeaponData) --武将id与神兵id一致,因此可以直接取数据 local heroId = magicWeaponData.MagicWeaponID self.weaponId = heroId self:RefreshInfo() end function UIDivineWeaponAwaken:RefreshInfo() local heroId = self.weaponId local isWeaponAwaken = MDL.HeroAwaken.GetIsWeaponAwaken(heroId) if isWeaponAwaken == false then --未觉醒时需要预览觉醒神兵,更换外观 local awakenHeroData = DataSheetManager.AwakenHeroNum:GetDataByID(heroId) EventSystem.Dispatch(EventID.UI_WeaponAppearance_ChangePreviewAppearance, awakenHeroData.WeaponAppearance) else EventSystem.Dispatch(EventID.UI_WeaponAppearance_ChangePreviewAppearance, MDL.HeroSelect.GetWeaponAppearanceIDByID(heroId)) end self:HandleLayout(heroId, isWeaponAwaken) self:HandleMiddle(heroId, isWeaponAwaken) self:HandleBottom(heroId, isWeaponAwaken) end function UIDivineWeaponAwaken:HandleLayout(heroId, isWeaponAwaken) if isWeaponAwaken then UIUtils.SetActive(self.group_Exam.gameObject, false) UIUtils.SetActive(self.group_Advanced.gameObject, true) else UIUtils.SetActive(self.group_Exam.gameObject, true) UIUtils.SetActive(self.group_Advanced.gameObject, false) end end function UIDivineWeaponAwaken:HandleMiddle(heroId, isWeaponAwaken) if isWeaponAwaken then local curBigStar, curSmallStar = MDL.HeroAwaken.GetCurWeaponStar(heroId) self.group_Advanced.txt_OldStar.text = string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_Level, curBigStar) local nextData = MDL.HeroAwaken.GetNextWeaponStarData(heroId) if nextData == nil then --已达最大觉醒等级 self.group_Advanced.obj_state:SetState(0) UIUtils.SetActive(self.group_Advanced.group_NextLevel, false) self:HandleBreakStarExp(heroId, true) else self.group_Advanced.obj_state:SetState(1) UIUtils.SetActive(self.group_Advanced.group_NextLevel, true) self.group_Advanced.txt_Title.text = string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_LevelActivate, curBigStar + 1) self.group_Advanced.txt_NextLevel.text = string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_Level, curBigStar + 1) self:HandleBreakStarExp(heroId, false, curBigStar, curSmallStar) self.group_Advanced.txt_NewStar.text = string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_Level, curBigStar + 1) local attrData = DataSheetManager.MagicWeaponAwakenStarAttr:GetDataByAttrRepeatID(nextData.AttrSpecial) for i, v in ipairs(self.group_Advanced.group_Attr) do if i <= #attrData.Attr_Table then local attr = attrData.Attr_Table[i] local attrName = DataSheetManager.AttrData:GetDataByID(attr.AttrType).Name local attrValue = attr.AttrNum v.text = UIUtils.GetLocalizedTxt(Const_IDS[attrName]) .. UTL.Color.FormatGreenColor("+" .. attrValue) else local count = nextData.SkillPoint[#nextData.SkillPoint] or 0 if count > 0 then v.text = UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeroAwaken_LingShiSkill) .. UTL.Color.FormatGreenColor("+" .. count) else v.text = nil end break end end end else local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) if MDL.HeroAwaken.GetIsHeroAwaken(heroId) then self.group_Exam.txt_Condition1.text = UTL.Color.FormatGreenColor(string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_HeroUnlockAwaken, UIUtils.GetLocalizedTxt(Const_IDS[heroData.NameIDS]))) else self.group_Exam.txt_Condition1.text = UTL.Color.FormatRedColor(string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_HeroUnlockAwaken, UIUtils.GetLocalizedTxt(Const_IDS[heroData.NameIDS]))) end end end function UIDivineWeaponAwaken:HandleBreakStarExp(heroId, isFull, bigBreak, smallBreak) if isFull then for i, v in ipairs(self.group_Advanced.group_unStage) do UIUtils.SetActive(v, false) end for i, v in ipairs(self.group_Advanced.group_Stage) do UIUtils.SetActive(v, true) end for i, v in ipairs(self.group_Advanced.group_Effect) do UIUtils.SetActive(v, false) end UIUtils.SetActive(self.group_Advanced.group_StageTitle, false) UIUtils.SetActive(self.group_Advanced.effect_hint, false) else for i, v in ipairs(self.group_Advanced.group_Stage) do if i == #self.group_Advanced.group_Stage then UIUtils.SetActive(v, smallBreak == i - 1) UIUtils.SetActive(self.group_Advanced.group_Effect[i], smallBreak == i - 1) else if smallBreak >= i then UIUtils.SetActive(v, true) UIUtils.SetActive(self.group_Advanced.group_Effect[i], true) else UIUtils.SetActive(v, false) UIUtils.SetActive(self.group_Advanced.group_Effect[i], false) end end end self:HandleStarAttr(heroId, bigBreak, smallBreak + 1) end end function UIDivineWeaponAwaken:HandleStarAttr(heroId, bigBreak, smallBreak) local attr = CTL.HeroAwaken.GetWeaponSmallBreakAttr(heroId, bigBreak, smallBreak) if self.group_Advanced.group_unStage[smallBreak] and attr then UIUtils.SetActive(self.group_Advanced.group_StageTitle, true) self.group_Advanced.group_StageTitle.transform:SetParent(self.group_Advanced.group_unStage[smallBreak].transform, false) self.group_Advanced.txt_StageAttr.text = attr UIUtils.SetActive(self.group_Advanced.effect_hint, true) self.group_Advanced.effect_hint.transform:SetParent(self.group_Advanced.group_unStage[smallBreak].transform, false) else UIUtils.SetActive(self.group_Advanced.group_StageTitle, false) UIUtils.SetActive(self.group_Advanced.effect_hint, false) end end function UIDivineWeaponAwaken:HandleItemUpdate() local isWeaponAwaken = MDL.HeroAwaken.GetIsWeaponAwaken(self.weaponId) self:HandleBottom(self.weaponId, isWeaponAwaken) end function UIDivineWeaponAwaken:HandleBottom(heroId, isWeaponAwaken) if isWeaponAwaken then local nextData = MDL.HeroAwaken.GetNextWeaponStarData(heroId) if nextData then local curBigStar, curSmallStar = MDL.HeroAwaken.GetCurWeaponStar(heroId) local starData = DataSheetManager.MagicWeaponAwakenStar:GetDataByMagicWeaponID_Star(heroId, curBigStar) local isBigBreak = curSmallStar == #starData.Item - 1 if isBigBreak and curBigStar + 1 > MDL.HeroAwaken.GetCurStar(heroId) then --不允许超过武将突破数 for i, v in ipairs(self.group_Advanced.group_Item) do UIUtils.SetActive(v.gameObject, false) end UIUtils.SetActive(self.group_Advanced.btn_Break, false) UIUtils.SetLabelText(self.group_Advanced.txt_limit, Const_IDS.IDS_WeaponAwaken_NeedAwakenHeroLevel) else if isBigBreak then self.group_Advanced.btn_Break:SetText(Const_IDS.IDS_HeroAwaken_LevelUp2) else self.group_Advanced.btn_Break:SetText(Const_IDS.IDS_HeroAwaken_LevelUp1) end local itemEnough = true local itemTable = DataSheetManager.MagicWeaponAwakenStarItem:GetDataByItemRepeatID(starData.Item[curSmallStar + 1]).Item_Table for i, v in ipairs(self.group_Advanced.group_Item) do if #itemTable >= i then UIUtils.SetActive(v.gameObject, true) local itemID = itemTable[i].ItemID local itemNum = itemTable[i].ItemNum v.ItemID = itemID local curCount = MDL.Bag.GetItemCount(itemID) if curCount < itemNum then curCount = UTL.Color.FormatRedColor(curCount) itemEnough = false else curCount = UTL.Color.FormatGreenColor(curCount) end UTL.Item.SetItemCell(v, itemID, curCount .. "/" .. itemNum) else UIUtils.SetActive(v.gameObject, false) end end self.isItemEnough = itemEnough self.group_Advanced.btn_Break:SetRedPoint(itemEnough) end end else local itemEnough = true local data = DataSheetManager.AwakenHeroNum:GetDataByID(self.weaponId).ActivationCost local curCount = MDL.Bag.GetItemCount(data[1]) if curCount < data[2] then curCount = UTL.Color.FormatRedColor(curCount) itemEnough = false else curCount = UTL.Color.FormatGreenColor(curCount) end UTL.Item.SetItemCell(self.group_Exam.item_Awaken, data[1], curCount .. "/" .. data[2]) self.isItemEnough = itemEnough self.group_Exam.btn_bottom:SetRedPoint(itemEnough) end end function UIDivineWeaponAwaken:RefreshResonanceLv() if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Resonance) then UIUtils.SetActive(self.btn_Resonance, true) else UIUtils.SetActive(self.btn_Resonance, false) end UIUtils.SetLabel(self.txt_ResonanceLv, string.FormatByIdsId(Const_IDS["IDS_Resonance_Level"], MDL.FormationResonance.GetSubResonanceLv(resonance_info.Weapon_Break))) end function UIDivineWeaponAwaken:OnButtonClicked(comp) if comp == self.group_Exam.item_Awaken.event_Click then local data = DataSheetManager.AwakenHeroNum:GetDataByID(self.weaponId).ActivationCost UTL.ItemTips.ShowCommonTipsById(data[1]) elseif comp == self.btn_Resonance then UIManager.OpenView(Const_UI_Lua.UIEnum.UIResonanceInfo, { subResonanceID = resonance_info.Weapon_Break, isShowGoto = false }) elseif comp == self.group_Exam.btn_bottom then if MDL.HeroAwaken.GetIsHeroAwaken(self.weaponId) == false then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_44383_InfoCode_HeroAwaken_NotEnough) return end if self.isItemEnough == false then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Equip_Enchance_CoinNotEnough) return end MDL.HeroAwaken.WeaponAwakenReq(self.weaponId) elseif comp == self.group_Advanced.btn_Tips2 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroAwakenBreakInfo, { type = 1, heroId = self.weaponId }, Const_UI_Lua.UIEnum.UIHeroBreakInfoView) elseif comp == self.group_Advanced.btn_Break then if self.isItemEnough == false then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Equip_Enchance_CoinNotEnough) return end MDL.HeroAwaken.AwakenWeaponBreakReq(self.weaponId) elseif comp == self.btn_Return then EventSystem.Dispatch(EventID.UI_HeroAwaken_ReturnBreak, true) else for i, v in ipairs(self.group_Exam.group_Item) do if comp == v.btn_click then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroAwakenpopup, { state = i - 1, heroId = self.weaponId }) break end end for i, v in ipairs(self.group_Advanced.group_Item) do if comp == v.event_Click then UTL.ItemTips.ShowCommonTipsById(v.ItemID) break end end end end function UIDivineWeaponAwaken:OnPointerDown(comp, eventData) local index = nil for i, v in ipairs(self.group_Advanced.group_unStage) do if v.gameObject == comp.gameObject then index = i break end end local heroId = self.weaponId local curBigStar = MDL.HeroAwaken.GetCurWeaponStar(heroId) self:HandleStarAttr(heroId, curBigStar, index) end function UIDivineWeaponAwaken:OnPointerUp(comp, eventData) local heroId = self.weaponId local isWeaponAwaken = MDL.HeroAwaken.GetIsWeaponAwaken(heroId) self:HandleMiddle(heroId, isWeaponAwaken) end function UIDivineWeaponAwaken:OnBigBreakExp() self.group_Advanced.effect_big:PlayUIEffect() end return UIDivineWeaponAwaken