local UIDivineWeaponAwakenSkillTreePanel = UIViewClass() local WEAPON_AWAKEN_TYPE = 1 local DEFAULT_SELECT_POINT = 101 local SMALL_POINT_TYPE = 2 local function GetHighestDigit(number) while number >= 10 do number = math.floor(number / 10) end return number end function UIDivineWeaponAwakenSkillTreePanel:OnCreated() self.pointDataMap = {} self.bigPointDataMap = {} self.currSkillPointCollection = nil self.pointId = -1 end function UIDivineWeaponAwakenSkillTreePanel:OnOpened(context) self.weaponId = context.weaponId for i = 1, 4 do local collection = self[string.format("img_SkillBg%s", i)] local line = self[string.format("img_line%s", i)] self.bigPointDataMap[i] = {collection = collection, line = line, smallPointIdList = {}} end for _, v in DataSheetManager.MagicWeaponAwakenTalent:GetDataByMagicWeaponID_PointID_PointLevel(self.weaponId) do if v.PointType == SMALL_POINT_TYPE and (not self.pointDataMap[v.PointID]) then local collection = self[string.format("img_SkillBg%s", v.PointID)] local line = self[string.format("img_line%s", v.PointID)] UIUtils.SetActive(collection.img_Selected, false) local pointData = {collection = collection, line = line} self.pointDataMap[v.PointID] = pointData local bigPointId = GetHighestDigit(v.PointID) table.insert(self.bigPointDataMap[bigPointId].smallPointIdList, v.PointID) end end self:Init(context) end function UIDivineWeaponAwakenSkillTreePanel:Init(context) self:RegistSystemEvent(EventID.UI_HeroAwaken_UpdateWeaponAwakenSkillInfo, self.OnUpdateWeaponAwakenSkillInfo) self:RefreshPointIcon() self:RefreshTree() self:OnSelectPoint(DEFAULT_SELECT_POINT, self.pointDataMap[DEFAULT_SELECT_POINT]) end function UIDivineWeaponAwakenSkillTreePanel:GetPointLevel(pointId) return MDL.HeroAwaken.GetSkillLevel(self.weaponId, WEAPON_AWAKEN_TYPE, pointId) end function UIDivineWeaponAwakenSkillTreePanel:GetCurrPointNum() return MDL.HeroAwaken.GetAwakenInfoParam(self.weaponId, "curWeaponSkillPointNums") end function UIDivineWeaponAwakenSkillTreePanel:GetUsedPointNum() return CTL.HeroAwaken.GetWeaponSkillUsedPointNum(self.weaponId) end function UIDivineWeaponAwakenSkillTreePanel:OnUpdateWeaponAwakenSkillInfo() self:RefreshTree() self:RefreshPointInfo() end function UIDivineWeaponAwakenSkillTreePanel:RefreshPointIcon() for i = 1, 4 do local cfg = DataSheetManager.MagicWeaponAwakenTalent:GetDataByMagicWeaponID_PointID_PointLevel(self.weaponId, i, 0) UIUtils.SetImageByAssetBundle(self.bigPointDataMap[i].collection.img_SkillIcon, cfg.Icon) end local recordMap = {} for _, v in DataSheetManager.MagicWeaponAwakenTalent:GetDataByMagicWeaponID_PointID_PointLevel(self.weaponId) do if v.PointType == SMALL_POINT_TYPE and (not recordMap[v.PointID]) then UIUtils.SetImageByAssetBundle(self.pointDataMap[v.PointID].collection.img_SkillIcon, v.Icon) end end end --刷新tree function UIDivineWeaponAwakenSkillTreePanel:RefreshTree() for id, _ in pairs(self.pointDataMap) do self:RefreshTreePoint(id) end for i = 2, 4 do self:RefreshTreeBigPoint(i) end end --刷新单个tree point function UIDivineWeaponAwakenSkillTreePanel:RefreshTreePoint(pointId) local pointData = self.pointDataMap[pointId] local level = self:GetPointLevel(pointId) UIUtils.SetGray(pointData.collection.img_SkillIcon, level == 0) UIUtils.SetActive(pointData.line, level > 0) local maxLevel = DataSheetManager.MagicWeaponAwakenTalent:GetDataLengthByMagicWeaponID_PointID_PointLevel(self.weaponId, pointId) UIUtils.SetLabel(pointData.collection.txt_Point, string.format("%s/%s", level, maxLevel)) if self:CanPlayEffect(pointId) then pointData.collection.effect:PlayUIEffect() else pointData.collection.effect:StopUIEffect() end end --刷新单个tree big point function UIDivineWeaponAwakenSkillTreePanel:RefreshTreeBigPoint(pointId) local bigPointData = self.bigPointDataMap[pointId] local line = bigPointData.line if line then local isDisplay = false for _, v in ipairs(bigPointData.smallPointIdList) do local level = self:GetPointLevel(v) if level > 0 or self:CanPlayEffect(v) then isDisplay = true break end end UIUtils.SetActive(line, isDisplay) end end function UIDivineWeaponAwakenSkillTreePanel:OnButtonClicked(comp) if comp == self.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() else for pointId, v in pairs(self.pointDataMap) do if comp == v.collection.event_Click then self:OnSelectPoint(pointId, v) end end for k, v in pairs(self.bigPointDataMap) do if comp == v.collection.event_Click then local cfg = DataSheetManager.MagicWeaponAwakenTalent:GetDataByMagicWeaponID_PointID_PointLevel(self.weaponId, k, 0) CTL.Tips.OpenHeroSkillTips(self.BigPointTips, self.weaponId, cfg.SkillID, true) end end end self:ButtonClicked(comp) end function UIDivineWeaponAwakenSkillTreePanel:ButtonClicked(comp) if comp == self.btn_Upgrade then if not self:canUpgrade() then return end MDL.HeroAwaken.AwakenWeaponLearnSkillReq(self.weaponId, false, self.pointId) elseif comp == self.btn_Reset then if not self:canReset() then return end local resetCfg = DataSheetManager.AwakenHeroNum:GetDataByID(self.weaponId).WeaponRebirthItem local content = string.FormatByIdsId(Const_IDS["IDS_HeroAwaken_ResetLingShi"], resetCfg[2]) UTL.MessageBox.ShowOKCancelBox(Const_IDS.IDS_LightEffect_ChongZhi, content, function() MDL.HeroAwaken.AwakenWeaponLearnSkillReq(self.weaponId, true, self.pointId) end ) elseif comp == self.btn_Guide then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.WeaponAwakenSkill}) end end function UIDivineWeaponAwakenSkillTreePanel:canUpgrade() if not CTL.HeroAwaken.CheckWeaponAwakenSkillUpgradePrecondition(self.weaponId, self.pointId, CTL.HeroAwaken.SkillUpgradePrecondition.Star) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_44373_InfoCode_HeroAwaken_NeedPrecondition) return false end if not CTL.HeroAwaken.CheckWeaponAwakenSkillUpgradePrecondition(self.weaponId, self.pointId, CTL.HeroAwaken.SkillUpgradePrecondition.UsedPointNum) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_44373_InfoCode_HeroAwaken_NeedPrecondition) return false end if not CTL.HeroAwaken.CheckWeaponAwakenSkillUpgradePrecondition(self.weaponId, self.pointId, CTL.HeroAwaken.SkillUpgradePrecondition.NeedPoint) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_44373_InfoCode_HeroAwaken_NeedPrecondition) return false end if not CTL.HeroAwaken.CheckWeaponAwakenSkillUpgradePrecondition(self.weaponId, self.pointId, CTL.HeroAwaken.SkillUpgradePrecondition.NoNeedPoint) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_44373_InfoCode_HeroAwaken_NeedPrecondition) return false end if not CTL.HeroAwaken.CheckWeaponAwakenSkillUpgradePrecondition(self.weaponId, self.pointId, CTL.HeroAwaken.SkillUpgradePrecondition.Cost) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_ERRORCODE_44375_InfoCode_HeroAwaken_WeaponSklllLack) return false end return true end function UIDivineWeaponAwakenSkillTreePanel:CanPlayEffect(pointId) for _, v in pairs(CTL.HeroAwaken.SkillUpgradePrecondition) do if not CTL.HeroAwaken.CheckWeaponAwakenSkillUpgradePrecondition(self.weaponId, pointId, v) then return false end end return true end function UIDivineWeaponAwakenSkillTreePanel:canReset() local resetCfg = DataSheetManager.AwakenHeroNum:GetDataByID(self.weaponId).WeaponRebirthItem if UTL.Item.GetItemStockCount(resetCfg[1]) < resetCfg[2] then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Guild_CommonFail5) return false end if self:GetUsedPointNum() <= 0 then CTL.Tips.AddTipsMsg(Const_IDS.IDS_HeroAwaken_ResetLingshiTips) return false end return true end function UIDivineWeaponAwakenSkillTreePanel:RefreshPointInfo() local level = self:GetPointLevel(self.pointId) --信息 local cfg = DataSheetManager.MagicWeaponAwakenTalent:GetDataByMagicWeaponID_PointID_PointLevel(self.weaponId, self.pointId, level == 0 and 1 or level) UIUtils.SetImageByAssetBundle(self.img_SkillIcon, cfg.Icon) UIUtils.SetGray(self.img_SkillIcon, level == 0) UIUtils.SetLabel(self.txt_SkillName, UTL.String.FormatCombineTextByID(cfg.Desc_2)) --每个等级的效果 local maxLevel = DataSheetManager.MagicWeaponAwakenTalent:GetDataLengthByMagicWeaponID_PointID_PointLevel(self.weaponId, self.pointId) self.loop_TalentSkill:ClearCells() local nextLevelCfg for i = 1, maxLevel do local cfg = DataSheetManager.MagicWeaponAwakenTalent:GetDataByMagicWeaponID_PointID_PointLevel(self.weaponId, self.pointId, i) self.loop_TalentSkill:AddData(cfg, 0) if i == level + 1 then nextLevelCfg = cfg end end if nextLevelCfg then local allHasMetCondition = true local conditionTextList = {} --觉醒条件 local color = UTL.Color.White if CTL.HeroAwaken.CheckWeaponAwakenSkillUpgradePrecondition(self.weaponId, self.pointId, CTL.HeroAwaken.SkillUpgradePrecondition.Star) then color = UTL.Color.White else allHasMetCondition = false color = UTL.Color.Red end local text = UTL.Color.FormatTextByColor(color, string.FormatByIdsId(Const_IDS["IDS_HeroAwaken_WeaponAwakenTo"], nextLevelCfg.Preconditions)) table.insert(conditionTextList, text) --花费的灵识点数 if CTL.HeroAwaken.CheckWeaponAwakenSkillUpgradePrecondition(self.weaponId, self.pointId, CTL.HeroAwaken.SkillUpgradePrecondition.UsedPointNum) then color = UTL.Color.White else allHasMetCondition = false color = UTL.Color.Red end local num = self:GetUsedPointNum() text = UTL.Color.FormatTextByColor(color, string.FormatByIdsId(Const_IDS["IDS_HeroAwaken_SkillSpended"], string.format("%s/%s", num, nextLevelCfg.NeedPointNum))) table.insert(conditionTextList, text) --前置结点 if #nextLevelCfg.NeedPoint > 0 then local nameList = {} color = UTL.Color.White for i, v in ipairs(nextLevelCfg.NeedPoint) do local needPointCfg = DataSheetManager.MagicWeaponAwakenTalent:GetDataByMagicWeaponID_PointID_PointLevel(self.weaponId, v, nextLevelCfg.NeedPointLevel[i]) table.insert(nameList, UTL.String.FormatCombineTextByID(needPointCfg.Desc_2)) local level = self:GetPointLevel(v) if level < nextLevelCfg.NeedPointLevel[i] then allHasMetCondition = false color = UTL.Color.Red break end end text = UTL.Color.FormatTextByColor(color, string.FormatByIdsId(Const_IDS["IDS_HeroAwaken_SkillLearned"], table.concat(nameList, " "))) table.insert(conditionTextList, text) end --互斥结点 local nameList = {} color = UTL.Color.White local hasMetNoNeedPointCondition = true local _, cfg = DataSheetManager.MagicWeaponAwakenNoNeedPoint:TryGetDataByMagicWeaponID(self.weaponId) UIUtils.SetLabel(self.txt_ExclusiveSkills, "") if cfg then for i, v in ipairs(cfg.NoNeedPoint_Table) do local isFound = false for _, pointId in ipairs(v.PointID) do if pointId == self.pointId then isFound = true break end end if isFound then for _, pointId in ipairs(v.PointID) do if pointId ~= self.pointId then local level = self:GetPointLevel(pointId) if level > 0 and hasMetNoNeedPointCondition then allHasMetCondition = false hasMetNoNeedPointCondition = false color = UTL.Color.Red end local noNeedPointCfg = DataSheetManager.MagicWeaponAwakenTalent:GetDataByMagicWeaponID_PointID_PointLevel(self.weaponId, pointId, 1) table.insert(nameList, UTL.String.FormatCombineTextByID(noNeedPointCfg.Desc_2)) end end text = string.FormatByIdsId(Const_IDS["IDS_HeroAwaken_SkillNotLearned"], table.concat(nameList, " ")) UIUtils.SetLabel(self.txt_ExclusiveSkills, text) text = UTL.Color.FormatTextByColor(color, text) table.insert(conditionTextList, text) break end end end if not allHasMetCondition then self.state_Upgrade:SetState(2) local index = 0 for i, v in ipairs(conditionTextList) do local cell = self.group_Condition[i] if not cell then cell = self:InstantiateCollection(self.group_Condition, self.group_Condition[1].gameObject) end UIUtils.SetActive(cell.gameObject, true) UIUtils.SetLabel(cell.txt_Condition, v) index = i end for i = index + 1, #self.group_Condition do UIUtils.SetActive(self.group_Condition[i].gameObject, false) end else self.state_Upgrade:SetState(0) local text = UTL.Color.FormatTextByColor(self:GetCurrPointNum() >= nextLevelCfg.Cost and UTL.Color.Green or UTL.Color.Red, nextLevelCfg.Cost) UIUtils.SetLabel(self.txt_Cost, text) end else self.state_Upgrade:SetState(1) end --当前灵识点数 UIUtils.SetLabel(self.txt_Point, self:GetCurrPointNum()) end function UIDivineWeaponAwakenSkillTreePanel:OnSelectPoint(pointId, data) if self.currSkillPointCollection then UIUtils.SetActive(self.currSkillPointCollection.img_Selected, false) end self.pointId = pointId self.currSkillPointCollection = data.collection UIUtils.SetActive(self.currSkillPointCollection.img_Selected, true) self:RefreshPointInfo() end function UIDivineWeaponAwakenSkillTreePanel:OnCellInit(scrollRect, index, cellTable, data) local level = self:GetPointLevel(data.PointID) UIUtils.SetLabel(cellTable.txt_Level, string.FormatByIdsId(Const_IDS["IDS_TalentSkill_Level"], data.PointLevel)) UIUtils.SetLabel(cellTable.txt_Talent, UTL.String.FormatCombineTextByID(data.Desc_3)) if level == data.PointLevel then cellTable.state_Talent:SetState(2) else if level > data.PointLevel then cellTable.state_Talent:SetState(1) else cellTable.state_Talent:SetState(0) end end end return UIDivineWeaponAwakenSkillTreePanel