local UIHeroAdvanced = UIViewClass() local EventSystem = require('Event/EventSystem') local resonance_info = require 'Proto/resonance_info_pb' function UIHeroAdvanced:OnOpened(context) self:RegistSystemEvent(EventID.UI_RefreshAdvancedInfo, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_HeroShow_UpdateHeroShow, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.RefreshPanel) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_EquipAdvanceMaterial, self.PlayEquipMaterialEffect) self:RegistSystemEvent(EventID.UI_PlayAdvanceJadeEffect, self.PlayAdvanceJadeEffect) self:RegistSystemEvent(EventID.UI_ResonanceChange_Refresh, self.RefreshResonanceLv) self:RefreshResonanceLv() CTL.FormationResonance.SetSubResonanceImage(self.icon_Resonance, resonance_info.Hero_Advance) self:RefreshPanel() end function UIHeroAdvanced: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.Hero_Advance))) end function UIHeroAdvanced:OnButtonClicked(comp) if comp == self.btn_Sweep then self:ClickSweepButton() elseif comp == self.btn_Equip then self:ClickEquipMaterial() elseif comp == self.btn_Advance then self:ClickAdvanceHero() elseif comp == self.btn_Enlarge then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroInfoView, {"Advance"}) elseif comp == self.group_Item.item.event_Click or comp == self.group_Item.btn_Get then local id = DataSheetManager.HeroAdvance:GetDataByAdvanceID(MDL.Advanced.GetHeroAdvancedInfo(MDL.HeroSelect.curSelectHeroID)).PointItem_Table[1].PointItemID UTL.ItemTips.ShowCommonTipsById(id) elseif comp == self.Cell_Equip01.btn_Chose then self:ClickMaterialSelf(1) elseif comp == self.Cell_Equip02.btn_Chose then self:ClickMaterialSelf(2) elseif comp == self.Cell_Equip03.btn_Chose then self:ClickMaterialSelf(3) elseif comp == self.Cell_Equip04.btn_Chose then self:ClickMaterialSelf(4) elseif comp == self.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.HeroAdvance}) elseif comp == self.btn_Resonance then UIManager.OpenView(Const_UI_Lua.UIEnum.UIResonanceInfo, {subResonanceID = resonance_info.Hero_Advance, isShowGoto = false}) end end function UIHeroAdvanced:ClickSweepButton() local heroId = MDL.HeroSelect.curSelectHeroID local itemTable = {} local sweepLevelUnlock = false for i = 1, 4 do if not CTL.Advanced.IsMaterialAlreadyEquip(heroId, i) then local indexItemData = MDL.Advanced.GetRequireMaterialTable(heroId)[i] local needCount = indexItemData.ItemNum - MDL.Currency.GetSoftTokenCountById(indexItemData.ItemID) if needCount > 0 then local levelId = MDL.Advanced.GetFirstLevelIdByItemId(indexItemData.ItemID) if levelId then table.insert(itemTable, {itemId = indexItemData.ItemID, itemCount = indexItemData.ItemNum, levelId = levelId, materialIndex = i}) else sweepLevelUnlock = true end end end end if #itemTable > 0 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIOneKeySweepView, itemTable) else if sweepLevelUnlock then CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroAdvanceNew_Hint_16"]) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroAdvanceNew_Hint_1"]) end end end function UIHeroAdvanced:ClickAdvanceHero() local heroId = MDL.HeroSelect.curSelectHeroID if CTL.Advanced.IsAdvanceItemEnough(heroId) then self:StartRepeatFunc(self.OnUpdateFun, 1.5) self.effect_BigBreakBurst:PlayUIEffect() CTL.Sound.PlayGameSound("UI_active_02") self.btn_Advance:SetGray(true, false) UIUtils.SetActive(self.btn_Block.gameObject, true) else CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroAdvanceLackOfItem"]) end end function UIHeroAdvanced:OnUpdateFun(deltaTime, timeSinceUpdate) MDL.Advanced.HeroAdvanceRequest(MDL.HeroSelect.curSelectHeroID) self.btn_Advance:SetGray(false, true) self:StopRepeatFunc(self.OnUpdateFun) UIUtils.SetActive(self.btn_Block.gameObject, false) end function UIHeroAdvanced:ClickEquipMaterial() local heroId = MDL.HeroSelect.curSelectHeroID local indexTable = CTL.Advanced.IsMaterialEnough(heroId) if indexTable then MDL.Advanced.MaterialEquipRequest(heroId, indexTable) else for i = 1, 4 do local advancedStep = MDL.Advanced.GetHeroAdvancedInfo(heroId) local advancedData = DataSheetManager.HeroAdvance:GetDataByAdvanceID(advancedStep) local itemId = advancedData.Item_Table[i].ItemID if CTL.Advanced.IsHasLevelCanSweep(itemId) then self:ClickSweepButton() return end end for i = 1, 4 do if not CTL.Advanced.IsMaterialAlreadyEquip(heroId, i) then self:ClickMaterialSelf(i) return end end end end function UIHeroAdvanced:PlayEquipMaterialEffect(indexTable) for i, v in ipairs(indexTable) do self["Cell_Equip0"..(v + 1)].effect_EquipMaterial:PlayUIEffect() CTL.Sound.PlayGameSound("UI_equipment_02") end end function UIHeroAdvanced:ClickMaterialSelf(index) local heroId = MDL.HeroSelect.curSelectHeroID local advancedStep = MDL.Advanced.GetHeroAdvancedInfo(heroId) local advancedData = DataSheetManager.HeroAdvance:GetDataByAdvanceID(advancedStep) local itemData = advancedData.Item_Table[index] local tokenCount = MDL.Currency.GetSoftTokenCountById(itemData.ItemID) or 0 local materialAttr = MDL.Advanced.GetMaterialAttrTableById(heroId, advancedStep, index) if tokenCount >= itemData.ItemNum or CTL.Advanced.IsMaterialAlreadyEquip(heroId, index) then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroAdvancedMaterial, {materialAttr, itemData, index}) else UIManager.OpenView(Const_UI_Lua.UIEnum.UISearchItemView, {itemData.ItemID, index, itemData.ItemNum}) end end function UIHeroAdvanced:PlayAdvanceJadeEffect(heroId) local totalStar, lightStar = MDL.Advanced.GetStarInfoOfAdvanced(heroId) local starTfPos = self.group_Star[lightStar].gameObject.transform.position self.effect_Star.transform:SetPosition(starTfPos.x, starTfPos.y, nil) self.effect_Star:PlayUIEffect() CTL.Sound.PlayGameSound("UI_bone_light") end function UIHeroAdvanced:RefreshPanel() local heroId = MDL.HeroSelect.curSelectHeroID UTL.Item.SetHeroIconByHeroId(self.img_Avatar, heroId, MDL.HeroAwaken.GetIsHeroAwaken(heroId)) self:RefreshStars(heroId) self:RefreshAdvancedTitle(heroId) self:RefreshMaterials(heroId) self:RefreshButton(heroId) end function UIHeroAdvanced:RefreshButton(heroId) if CTL.Advanced.IsCouldAdvance(heroId) then --是否可以进阶 if CTL.Advanced.IsReachMaxAdvanceLevel(heroId) then --是否达到最大进阶等级 self:SetCompActive(true) UIUtils.SetLabel(self.lab_Hint, UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeroAdvanceMax)) elseif CTL.Advanced.IsHeroLevelReachLimit(heroId) then --英雄等级是否达到了限制 self:SetCompActive(false, false) self:RefreshAdvancedPills(heroId) self.btn_Advance:SetRedPoint(CTL.Advanced.IsAdvanceItemEnough(heroId)) else self:SetCompActive(true) local LevelLimit = DataSheetManager.HeroAdvance:GetDataByAdvanceID(MDL.Advanced.GetHeroAdvancedInfo(heroId)).LevelLimit if GameAppInfo.IsVietnamPackage() then self:SetUnlockLabVN(true) local nobilityLevel = UTL.Color.FormatLightRedColor(UTL.Item.GetNobilityByTeamLevel(tonumber(LevelLimit))) self.lab_Unlock.text = UTL.Color.FormatGrayColor(string.FormatByIdsId(Const_IDS.IDS_HeroAdvanceLowerLv, nobilityLevel)) else UIUtils.SetActive(self.lab_Unlock, true) UIUtils.SetActive(self.lab_Hint, false) local nobilityLevel = UTL.Color.FormatLightRedColor(UTL.Item.GetNobilityByTeamLevel(tonumber(LevelLimit))) self.lab_Unlock.text = UTL.Color.FormatGrayColor(string.FormatByIdsId(Const_IDS.IDS_HeroAdvanceLowerLv, nobilityLevel)) end end else self:SetCompActive(false, true) self.btn_Equip:SetRedPoint(CTL.Advanced.IsMaterialEnough(heroId) ~= nil) self.btn_Sweep:SetRedPoint(MDL.Advanced.IsHeroCanGatherToAdvance(heroId)) end end function UIHeroAdvanced:SetCompActive(hintActive, equipActive) UIUtils.SetActive(self.btn_Advance, not hintActive and not equipActive) UIUtils.SetActive(self.group_Item.gameObject, not hintActive and not equipActive) UIUtils.SetActive(self.group_Cost, not hintActive and not equipActive) UIUtils.SetActive(self.btn_Equip, not hintActive and equipActive) UIUtils.SetActive(self.btn_Sweep, not hintActive and equipActive) UIUtils.SetActive(self.lab_Hint, hintActive) UIUtils.SetActive(self.lab_Unlock, false) -- 其他地区直接屏蔽越南独有的显示文本 if not GameAppInfo.IsVietnamPackage() then self:SetUnlockLabVN(false) end end function UIHeroAdvanced:SetUnlockLabVN(unlockActive) UIUtils.SetActive(self.lab_Unlock, unlockActive) UIUtils.SetActive(self.lab_Hint, false) end function UIHeroAdvanced:RefreshMaterials(heroId) local requireMaterialTable = MDL.Advanced.GetRequireMaterialTable(heroId) for i = 1, 4 do local cell = self["Cell_Equip0"..i] local itemId = requireMaterialTable[i].ItemID self:SetMaterialCell(cell, itemId) if CTL.Advanced.IsMaterialAlreadyEquip(heroId, i) then cell.effect_Add:StopUIEffect() UIUtils.SetActive(cell.img_NumBg, false) UIUtils.SetActive(cell.Mask.gameObject, false) UIUtils.SetActive(cell.img_SweepBg, false) else local tokenCount = MDL.Currency.GetSoftTokenCountById(itemId) or 0 UIUtils.SetActive(cell.img_NumBg, true) if tokenCount >= requireMaterialTable[i].ItemNum then UIUtils.SetLabel(cell.txt_Num, UTL.Color.FormatGreenColor(tokenCount).."/"..requireMaterialTable[i].ItemNum) cell.effect_Add:PlayUIEffect() UIUtils.SetActive(cell.Mask.gameObject, true) UIUtils.SetActive(cell.img_SweepBg, false) else UIUtils.SetLabel(cell.txt_Num, UTL.Color.FormatRedColor(tokenCount).."/"..requireMaterialTable[i].ItemNum) cell.effect_Add:StopUIEffect() UIUtils.SetActive(cell.Mask.gameObject, true) if CTL.Advanced.IsHasLevelCanSweep(itemId) then UIUtils.SetActive(cell.img_SweepBg, true) UIUtils.SetLabelText(cell.lab_Sweep, Const_IDS["IDS_HeroAdvanceNew_Hint_12"]) else UIUtils.SetActive(cell.img_SweepBg, false) end end end end end local ItemIconPathTemplate=ConstAssetPathConfig.ItemIconPath function UIHeroAdvanced:SetMaterialCell(cell, id) local itemData = DataSheetManager.ItemData:GetDataByID(id) local itemIcon = string.format(ItemIconPathTemplate, itemData.Icon) UIUtils.SetImageByAssetBundle(cell.img_Equip, itemIcon) UTL.Color.SetQualityImageByType(cell.img_Kuang, itemData.Color, UTL.Color.QualityType.Circle) end function UIHeroAdvanced:RefreshAdvancedPills(heroId) --刷新进阶丹图标 local advancedStep = MDL.Advanced.GetHeroAdvancedInfo(heroId) local advancedData = DataSheetManager.HeroAdvance:GetDataByAdvanceID(advancedStep) local advancedItemTable = advancedData.PointItem_Table UIUtils.SetActive(self.group_Cost, false) UIUtils.SetActive(self.group_Item.gameObject, false) for i, v in ipairs(advancedItemTable) do local itemId = v.PointItemID local itemNum = v.PointItemNum if MDL.Currency.IsMoneyTypeByItemID(itemId) then local count = MDL.Currency.GetMoneyCount(itemId) if count >= itemNum then count = itemNum else count = UTL.Color.FormatRedColor(itemNum) end UTL.Item.MoneyIcon(self.icon_Cost, itemId) self.txt_Cost.text = count UIUtils.SetActive(self.group_Cost, true) else local count = MDL.Bag.GetItemCount(itemId) or 0 if count >= itemNum then UIUtils.SetActive(self.group_Item.btn_Get, false) count = count .."/".. itemNum else UIUtils.SetActive(self.group_Item.btn_Get, true) count = UTL.Color.FormatRedColor(count) .."/".. itemNum end UTL.Item.SetItemCell(self.group_Item.item, itemId, count) UIUtils.SetActive(self.group_Item.gameObject, true) end end end function UIHeroAdvanced:RefreshStars(heroId) local totalStar, lightStar = MDL.Advanced.GetStarInfoOfAdvanced(heroId) local advancedData = DataSheetManager.HeroAdvance:GetDataByAdvanceID(MDL.Advanced.GetHeroAdvancedInfo(heroId)) CTL.Advanced.InstantiateStarCell(self, self.group_Star[1].gameObject, self.group_Star, totalStar, lightStar, advancedData.StarColorIcon, advancedData.StarLockIcon) end function UIHeroAdvanced:RefreshAdvancedTitle(heroId) local advancedStep = MDL.Advanced.GetHeroAdvancedInfo(heroId) local advancedData = DataSheetManager.HeroAdvance:GetDataByAdvanceID(advancedStep) local title = string.FormatByIdsId(Const_IDS[advancedData.AdvanceDesc], advancedData.Stage, advancedData.LightStar) UIUtils.SetLabel(self.lab_Advance, title) UIUtils.SetLabel(self.txt_OldAdvance, title) local descTitle, desc = CTL.Advanced.GetNextBigAdvanceTitleAndDesc(heroId, advancedStep + 1) self.txt_Info01.text = desc if CTL.Advanced.IsReachMaxAdvanceLevel(heroId) then UIUtils.SetActive(self.img_Arrow, false) UIUtils.SetActive(self.txt_NewAdvance, false) else UIUtils.SetActive(self.img_Arrow, true) UIUtils.SetActive(self.txt_NewAdvance, true) local advancedData = DataSheetManager.HeroAdvance:GetDataByAdvanceID(advancedStep + 1) local title = string.FormatByIdsId(Const_IDS[advancedData.AdvanceDesc], advancedData.Stage, advancedData.LightStar) UIUtils.SetLabel(self.txt_NewAdvance, title) if descTitle then UIUtils.SetLabel(self.txt_TitleInfo01, descTitle) UIUtils.SetActive(self.txt_TitleInfo01, true) else UIUtils.SetActive(self.txt_TitleInfo01, false) end end end return UIHeroAdvanced