local UIHeroAwakenSkill = UIViewClass() local EventSystem = require('Event/EventSystem') local SkillPath = "Assets/UI/Dynamic/UI_SkillIcon/%s.png" local MAX_SKILL_LEVEL = 3 local Const_Type_Normal = 1 local Const_Type_Spec = 3 local Const_Icon_Path = { [0] = "Assets/UI/Atlas/UI_HeroAwaken/wjjxjns_bg_09.png", [1] = "Assets/UI/Atlas/UI_HeroAwaken/wjjxjns_icon_02.png", [2] = "Assets/UI/Atlas/UI_HeroAwaken/wjjxjns_icon_01.png", [3] = "Assets/UI/Atlas/UI_HeroAwaken/wjjxjns_icon_03.png", } function UIHeroAwakenSkill:OnOpened(context) UIUtils.SetActive(self.context.parentView.currency_Info, false) self:RegistSystemEvent(EventID.UI_HeroAwaken_UpdateHeroSkillPoint, self.OnUpdateHeroSkillPoint) self:RegistSystemEvent(EventID.UI_HeroAwaken_UpdateHeroSkillInfo, self.OnUpdateHeroSkillInfo) local heroId = MDL.HeroSelect.curSelectHeroID self.resetCostCount = DataSheetManager.AwakenHeroNum:GetDataByID(heroId).HeroRebirthItem[2] self.bigSkillTemplateObj = self.skillTemplate_big.gameObject self.smallSkillTemplateObj = self.skillTemplate_small.gameObject self.skillNodeMap = {} self:InitSkillNode(heroId) self:OnSelectSkillNode(self.skillNodeMap[1], 1) self:OnUpdateHeroSkillPoint() end function UIHeroAwakenSkill:OnUpdateHeroSkillInfo(isReset, pointId) if isReset then for i, v in ipairs(self.bg_root) do self:UpdateSkillNodeItem(i) end else self:UpdateSkillNodeItem(pointId) for i, v in ipairs(self.bg_root) do self:UpdateEffect(i) end end if self.selectPointId then local node = self.skillNodeMap[self.selectPointId] self:OnSelectSkillNode(node, self.selectPointId) end end function UIHeroAwakenSkill:UpdateSkillNodeItem(pointId) local heroId = MDL.HeroSelect.curSelectHeroID local level = MDL.HeroAwaken.GetSkillLevel(heroId, 0, pointId) local item = self.skillNodeMap[pointId] if level > 0 then local levelCfg = DataSheetManager.HeroAwakenTalent:GetDataByHeroID_PointId_PointLevel(heroId, pointId, level) if levelCfg.TalentType == Const_Type_Normal then item.mask.fillAmount = 0 else item.mask.fillAmount = 1 - level / MAX_SKILL_LEVEL end else item.mask.fillAmount = 1 end self:UpdateEffect(pointId) end function UIHeroAwakenSkill:UpdateEffect(pointId) local item = self.skillNodeMap[pointId] local heroId = MDL.HeroSelect.curSelectHeroID local level = MDL.HeroAwaken.GetSkillLevel(heroId, 0, pointId) item.effect:StopUIEffect() local _, levelCfg = DataSheetManager.HeroAwakenTalent:TryGetDataByHeroID_PointId_PointLevel(heroId, pointId, level + 1) if levelCfg then local pointCount = MDL.HeroAwaken.GetHeroSkillPointNums(heroId) if pointCount >= levelCfg.TalentCost and CTL.HeroAwaken.CheckIfHeroSkillNearbyActive(heroId, pointId) and MDL.HeroAwaken.GetCurStar(heroId) >= levelCfg.Preconditions then item.effect:PlayUIEffect() end end end function UIHeroAwakenSkill:InitSkillNode(heroId) for i, v in ipairs(self.bg_root) do self:InitSkillNodeItem(v, heroId, i) self:UpdateSkillNodeItem(i) end end function UIHeroAwakenSkill:InitSkillNodeItem(parent, heroId, pointId) local cfg = DataSheetManager.HeroAwakenTalent:GetDataByHeroID_PointId_PointLevel(heroId, pointId, 1) local isBig = DataSheetManager.HeroAwakenTalent:TryGetDataByHeroID_PointId_PointLevel(cfg.HeroID, cfg.PointId, MAX_SKILL_LEVEL) local item = isBig and self:InstantiateCollection(self.root_skill, self.bigSkillTemplateObj) or self:InstantiateCollection(self.root_skill, self.smallSkillTemplateObj) local tf = item.gameObject.transform UIUtils.SetActive(tf, true) UIUtils.SetActive(item.choice, false) UIUtils.SetParent(tf, parent) tf:SetLocalPosition(0, 0, 0) self.skillNodeMap[pointId] = item self:SetSkillIcon(item.img_SkillsIcon, item.img_SkillsIconNoCircle, item.state_icon, cfg) end function UIHeroAwakenSkill:OnButtonClicked(comp) if comp == self.group_Bottom.Btn_LevelUp then MDL.HeroAwaken.AwakenHeroLearnSkillReq(MDL.HeroSelect.curSelectHeroID, false, self.selectPointId) elseif comp == self.btn_Enlarge then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, { id = LuaConst.NoteID.HeroAwakenSkill }) elseif comp == self.btn_Reset then if CTL.HeroAwaken.HasActiveHeroSkill(MDL.HeroSelect.curSelectHeroID) == false then CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroAwaken_ResetTips"]) return end local func = function() MDL.HeroAwaken.AwakenHeroLearnSkillReq(MDL.HeroSelect.curSelectHeroID, true, self.selectPointId) end UTL.MessageBox.ShowOKCancelBox(nil, string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_ResetTianZi, self.resetCostCount), func) else for pointId, node in pairs(self.skillNodeMap) do if comp == node.btn then self:OnSelectSkillNode(node, pointId) return end end end end function UIHeroAwakenSkill:OnSelectSkillNode(node, pointId) if self.selectPointId then local lastNode = self.skillNodeMap[self.selectPointId] UIUtils.SetActive(lastNode.choice, false) end self.selectPointId = pointId UIUtils.SetActive(node.choice, true) self:UpdateRightInfo() CTL.Sound.PlayGameSound("UI_badge") end function UIHeroAwakenSkill:SetSkillIcon(icon, iconNoCircle, state, cfg) if cfg.TalentType > 1 then if cfg.TalentID > 0 then if iconNoCircle then UIUtils.SetActive(iconNoCircle, false) UIUtils.SetActive(icon, true) end local deData = DataSheetManager.DevelopEffectData:GetDataByID(cfg.TalentID) UIUtils.SetImageByAssetBundle(icon, string.format(SkillPath, deData.Icon)) icon.transform:SetSizeDelta(100, 100) else if iconNoCircle then UIUtils.SetActive(iconNoCircle, true) UIUtils.SetActive(icon, false) end state:SetState(0) end else if iconNoCircle then UIUtils.SetActive(iconNoCircle, true) UIUtils.SetActive(icon, false) end state:SetState(cfg.AttrType[1]) end end function UIHeroAwakenSkill:SetRightSkillIcon(icon, iconNoCircle, bg, cfg) if cfg.TalentType > 1 then UIUtils.SetActive(bg, false) if cfg.TalentID > 0 then UIUtils.SetActive(icon, true) UIUtils.SetActive(iconNoCircle, false) local deData = DataSheetManager.DevelopEffectData:GetDataByID(cfg.TalentID) UIUtils.SetImageByAssetBundle(icon, string.format(SkillPath, deData.Icon)) icon.transform:SetSizeDelta(110, 110) else UIUtils.SetActive(icon, false) UIUtils.SetActive(iconNoCircle, true) UIUtils.SetImageByAssetBundle(iconNoCircle, Const_Icon_Path[0]) iconNoCircle:SetNativeSize() end else UIUtils.SetActive(bg, true) UIUtils.SetActive(icon, false) UIUtils.SetActive(iconNoCircle, true) UIUtils.SetImageByAssetBundle(iconNoCircle, Const_Icon_Path[cfg.AttrType[1]]) iconNoCircle.transform:SetSizeDelta(70, 70) end end function UIHeroAwakenSkill:UpdateRightInfo() local pointId = self.selectPointId local heroId = MDL.HeroSelect.curSelectHeroID local cfg = DataSheetManager.HeroAwakenTalent:GetDataByHeroID_PointId_PointLevel(heroId, pointId, 1) self:SetRightSkillIcon(self.group_Info1.img_SkillIcon, self.group_Info1.img_SkillIconNoCircle, self.group_Info1.img_SkillIconBg, cfg) UIUtils.SetLabel(self.group_Info1.txt_SkillName, UTL.String.FormatCombineTextByID(cfg.Desc_2)) local curLevel = MDL.HeroAwaken.GetSkillLevel(heroId, 0, pointId) UIUtils.SetGray(self.group_Info1.img_SkillIcon, curLevel == 0) UIUtils.SetGray(self.group_Info1.img_SkillIconNoCircle, curLevel == 0) if cfg.TalentType ~= Const_Type_Normal then UIUtils.SetActive(self.group_Info2.group_Skill, true) UIUtils.SetActive(self.group_Info2.group_Attr.gameObject, false) if cfg.TalentType == Const_Type_Spec then local _, desc = MDL.HeroStar.GetTalentNameAndDesc(cfg.TalentID) self.group_Info2.txt_SkillInfo.text = desc for i = 2, MAX_SKILL_LEVEL do local content local levelCfg = DataSheetManager.HeroAwakenTalent:GetDataByHeroID_PointId_PointLevel(heroId, pointId, i) local _, desc = MDL.HeroStar.GetTalentNameAndDesc(levelCfg.TalentID) if curLevel == i then content = UTL.Color.FormatTextByColor("e8d588", string.format("\n%s %s", string.FormatByIdsId(Const_IDS["IDS_TalentSkill_Level"], i), desc)) elseif curLevel > i then content = string.format("\n%s %s", string.FormatByIdsId(Const_IDS["IDS_TalentSkill_Level"], i), desc) else content = UTL.Color.FormatGrayColor(string.format("\n%s %s", string.FormatByIdsId(Const_IDS["IDS_TalentSkill_Level"], i), desc)) end if i == 2 then self.group_Info2.txt_level1.text = content else self.group_Info2.txt_level2.text = content end end else self.group_Info2.txt_SkillInfo.text = string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_TianZiOverUp1, math.ceil(cfg.PointNearbyUp * 100) .. "%") for i = 2, MAX_SKILL_LEVEL do local content local levelCfg = DataSheetManager.HeroAwakenTalent:GetDataByHeroID_PointId_PointLevel(heroId, pointId, i) if curLevel == i then content = UTL.Color.FormatTextByColor("e8d588", string.format("\n%s %s", string.FormatByIdsId(Const_IDS["IDS_TalentSkill_Level"], i), string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_TianZiOverUp2, math.ceil(levelCfg.PointNearbyUp * 100) .. "%"))) elseif curLevel > i then content = string.format("\n%s %s", string.FormatByIdsId(Const_IDS["IDS_TalentSkill_Level"], i), string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_TianZiOverUp2, math.ceil(levelCfg.PointNearbyUp * 100) .. "%")) else content = UTL.Color.FormatGrayColor(string.format("\n%s %s", string.FormatByIdsId(Const_IDS["IDS_TalentSkill_Level"], i), string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_TianZiOverUp2, math.ceil(levelCfg.PointNearbyUp * 100) .. "%"))) end if i == 2 then self.group_Info2.txt_level1.text = content else self.group_Info2.txt_level2.text = content end end end else UIUtils.SetActive(self.group_Info2.group_Attr.gameObject, true) UIUtils.SetActive(self.group_Info2.group_Skill, false) local result = CTL.HeroAwaken.GetHeroSkillAttr(heroId, pointId) for i, v in ipairs(self.group_Info2.group_Attr) do if #result >= i then UIUtils.SetActive(v.gameObject, true) UTL.Attr.SetAttrItemByCompName(v, result[i].attrType, result[i].attrValue, true) else UIUtils.SetActive(v.gameObject, false) end end end local isNearbyActive = CTL.HeroAwaken.CheckIfHeroSkillNearbyActive(heroId, pointId) local isBreakEnough = MDL.HeroAwaken.GetCurStar(cfg.HeroID) >= cfg.Preconditions if curLevel > 0 or (isNearbyActive and isBreakEnough) then local hasNext = DataSheetManager.HeroAwakenTalent:TryGetDataByHeroID_PointId_PointLevel(heroId, pointId, curLevel + 1) if hasNext then self.group_Bottom.state_Bottm:SetState(1) if curLevel == 0 then self.group_Bottom.Btn_LevelUp:SetText(Const_IDS.IDS_Bag_Item_Button_Activation) else self.group_Bottom.Btn_LevelUp:SetText(Const_IDS.IDS_Handbook_Hero_LevelUp_Button) end local curNum = MDL.HeroAwaken.GetHeroSkillPointNums(heroId) if curNum >= cfg.TalentCost then self.group_Bottom.text_Point.text = UTL.Color.FormatGreenColor(cfg.TalentCost) else self.group_Bottom.text_Point.text = UTL.Color.FormatRedColor(cfg.TalentCost) end else self.group_Bottom.state_Bottm:SetState(0) self.group_Bottom.text_Condition.text = UTL.Color.FormatTextByColor("e8d588", UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeroAwaken_TianZiLevelMax)) end else self.group_Bottom.state_Bottm:SetState(0) local condition1 = UIUtils.GetLocalizedTxt(Const_IDS.IDS_HeroAwaken_Condition1) local content_1 = isNearbyActive and UTL.Color.FormatGreenColor(condition1) or UTL.Color.FormatRedColor(condition1) local condition2 = string.FormatByIdsId(Const_IDS.IDS_HeroAwaken_Condition2, UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.HeroNum:GetDataByID(cfg.HeroID).NameIDS]), cfg.Preconditions) local content_2 if cfg.Preconditions > 0 then content_2 = isBreakEnough and UTL.Color.FormatGreenColor(condition2) or UTL.Color.FormatRedColor(condition2) else content_2 = "" end self.group_Bottom.text_Condition.text = content_1 .. "\n" .. content_2 end end function UIHeroAwakenSkill:OnUpdateHeroSkillPoint() self.txt_BottomNumber.text = MDL.HeroAwaken.GetHeroSkillPointNums(MDL.HeroSelect.curSelectHeroID) UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(self.txt_BottomNumber.transform) end function UIHeroAwakenSkill:OnClosed() UIUtils.SetActive(self.context.parentView.currency_Info, true) EventSystem.Dispatch(EventID.UI_Appearance_ChangePreviewAppearance, MDL.HeroSelect.GetAppearanceIDByHeroID(MDL.HeroSelect.curSelectHeroID)) end return UIHeroAwakenSkill