--[[ 宠物符文学习 ]]-- local UIGodPetRuneStudy = UIViewClass() function UIGodPetRuneStudy:OnCreated() for i, v in DataSheetManager.PetRuneLock:GetEnumerator() do if #v.Item_Table > 0 then self.lockMatId = v.Item_Table[1].ItemID break end end UTL.Item.ItemSquareIcon(self.img_LockProp, nil, self.lockMatId) UIUtils.SetActive(self.group_Tips, false) end function UIGodPetRuneStudy:OnOpened(context) self.lockItemList = { [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0, } self:RegistSystemEvent(EventID.UI_Pet_RefreshRuneSubView, self.UpdateInfo) self:RegistSystemEvent(EventID.UI_Pet_RuneOpt, self.OnRuneOpt) self:RegistSystemEvent(EventID.BagItem_Update, self.UpdateCostMat) self:RegistSystemEvent(EventID.UI_Pet_RuneStudySuccess, self.OnRuneStudySuccess) self.slotId = context.slotId self.petUniqId = context.petUniqId self:UpdateInfo() if CTL.Pet.CheckRuneStudy(self.slotId) then CTL.Pet.RemoveRuneStudyRed(self.slotId) end end --dict:Key是背包id function UIGodPetRuneStudy:OnRuneOpt(dict) local id = next(dict) if id == nil then CTL.Tips.AddTipsMsg(Const_IDS["IDS_Pet_ClickSkillFirst"]) return end local targetSkillCfg = MDL.Pet.GetRuneCfgByID(id) local slotInfo = MDL.Pet.GetSlotInfoBySlotId(self.slotId) for i, v in ipairs(slotInfo.talismanSkill) do local cfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(v) if cfg.RuneType == targetSkillCfg.RuneType then --已有同类型,如果等级没已学的高,不允许学习 if cfg.RuneLevel >= targetSkillCfg.RuneLevel then CTL.Tips.AddTipsMsg(Const_IDS["IDS_ERRORCODE_4062_InfoCode_Pet_Born35"]) return end --有同类型 + 已锁定 if self:IsLockSameType(targetSkillCfg.RuneType) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_Pet_LockAlready) return end if CTL.Pet.GetRuneOptConfirm(CTL.Pet.RuneOptConfirmKey_ReplaceSame) == false then local content = string.FormatByIdsId(Const_IDS.IDS_Pet_SkillReplace1, UIUtils.GetLocalizedTxt(Const_IDS[cfg.RuneName])) UTL.MessageBox.ShowOKCancelToggleBox(nil, content, UIUtils.GetLocalizedTxt(Const_IDS.IDS_EquipRefine_QuickTips2), function() MDL.Pet.PetTalismanLearnReq(id, self.slotId) end, function(isOn) CTL.Pet.SetRuneOptConfirm(CTL.Pet.RuneOptConfirmKey_ReplaceSame, isOn) end) else MDL.Pet.PetTalismanLearnReq(id, self.slotId) end return end end if self.isItemEnough then if CTL.Pet.GetRuneOptConfirm(CTL.Pet.RuneOptConfirmKey_ReplaceRand) == false then local content = string.FormatByIdsId(Const_IDS.IDS_Pet_SkillReplace2, UIUtils.GetLocalizedTxt(Const_IDS[targetSkillCfg.RuneName])) CTL.Pet.ShowOKCancelToggleBox(content, function() MDL.Pet.PetTalismanLearnReq(id, self.slotId, self.lockItemList) end, function(isOn) CTL.Pet.SetRuneOptConfirm(CTL.Pet.RuneOptConfirmKey_ReplaceRand, isOn) end, self.lockMatId, self.txt_LockNum.text, self.txt_Lock.text) else MDL.Pet.PetTalismanLearnReq(id, self.slotId, self.lockItemList) end else CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_1v1RewardPlus_LackItem, self.lockItemName)) end end function UIGodPetRuneStudy:UpdateInfo() local slotInfo = MDL.Pet.GetSlotInfoBySlotId(self.slotId) self.activeSkillCount = #slotInfo.talismanSkill for i, v in ipairs(self.group_RuneSkill) do local skillId = slotInfo.talismanSkill[i] if skillId then UIUtils.SetActive(v.group_Content, true) UIUtils.SetActive(v.img_Empty, false) self:SetLearnedSkillItem(v, skillId, i) else UIUtils.SetActive(v.group_Content, false) UIUtils.SetActive(v.img_Empty, true) end end --羁绊技能 self.relationSkill = CTL.Pet.GetRelationSkill(self.petUniqId) if self.relationSkill > 0 then self.group_RelationSkill.state_Skill:SetState(1) local cfg = DataSheetManager.PetRelationSkill:GetDataByRelationSkillID(self.relationSkill) UIUtils.SetImageByAssetBundle(self.group_RelationSkill.img_SkillIcon, cfg.RuneIcon) UIUtils.SetLabelText(self.group_RelationSkill.txt_Level, CTL.Pet.RuneSkillLevelIDS[cfg.RuneLevel]) self.group_RelationSkill.effect_ItemJiBan:PlayUIEffect() else self.group_RelationSkill.state_Skill:SetState(0) self.group_RelationSkill.effect_ItemJiBan:StopUIEffect() end self:UpdateCostMat() end function UIGodPetRuneStudy:SetLearnedSkillItem(col, skillId, index) local cfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(skillId) UIUtils.SetImageByAssetBundle(col.img_SkillIcon, cfg.RuneIcon) UIUtils.SetLabelText(col.txt_Level, CTL.Pet.RuneSkillLevelIDS[cfg.RuneLevel]) UIUtils.SetLabelText(col.txt_SkillName, Const_IDS[cfg.RuneName]) if self.lockItemList[index] > 0 then col.state_lock:SetState(0) else col.state_lock:SetState(1) end end function UIGodPetRuneStudy:UpdateCostMat() local curCount = MDL.Bag.GetItemCount(self.lockMatId) or 0 local costCount = 0 if self.activeSkillCount > 0 then local lockCfg = DataSheetManager.PetRuneLock:GetDataByID(self.activeSkillCount) local lockNum = self:GetLockCount() if lockNum > 0 then costCount = lockCfg.Item_Table[lockNum].ItemNum self.lockItemName = UTL.Item.GetItemColorName(lockCfg.Item_Table[lockNum].ItemID) end end if costCount > 0 then if curCount >= costCount then self.txt_Lock.text = UTL.Color.FormatGreenColor(UTL.String.GetCountStr(curCount)) .. "/" .. UTL.String.GetCountStr(costCount) else self.txt_Lock.text = UTL.Color.FormatRedColor(UTL.String.GetCountStr(curCount)) .. "/" .. UTL.String.GetCountStr(costCount) end else self.txt_Lock.text = UTL.String.GetCountStr(curCount) .. "/0" end self.isItemEnough = curCount >= costCount self:UpdateLockNum() end function UIGodPetRuneStudy:GetLockCount() local lockCount = 0 for i, v in ipairs(self.lockItemList) do if v > 0 then lockCount = lockCount + 1 end end return lockCount end function UIGodPetRuneStudy:IsLockSameType(runeType) local slotInfo = MDL.Pet.GetSlotInfoBySlotId(self.slotId) for i, v in ipairs(self.lockItemList) do if v > 0 then local cfg = DataSheetManager.PetRuneSkill:GetDataByPetRuneID(slotInfo.talismanSkill[i]) if cfg.RuneType == runeType then return true end end end return false end function UIGodPetRuneStudy:OnButtonClicked(comp) if comp == self.click_LockProp then UTL.ItemTips.ShowCommonTipsById(self.lockMatId) elseif comp == self.btn_Notice then UIUtils.SetActive(self.group_Tips, true) elseif comp == self.btn_TipsClose then UIUtils.SetActive(self.group_Tips, false) elseif comp == self.group_RelationSkill.rect_Click then if self.relationSkill > 0 then CTL.Pet.ShowRuneSkillTips(self.relationSkill) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIPetRuneIllustratedHandbook, { tabIndex = 1 }) end else for i, v in ipairs(self.group_RuneSkill) do if comp == v.click_Lock then self:TryLockItem(i, v) break elseif comp == v.rect_Click then local skillId = MDL.Pet.GetSlotInfoBySlotId(self.slotId).talismanSkill[i] if skillId and skillId > 0 then CTL.Pet.ShowRuneSkillTips(skillId) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Pet_RuneGetSkillWay3) end break end end end end function UIGodPetRuneStudy:TryLockItem(i, col) if self.lockItemList[i] > 0 then self.lockItemList[i] = 0 col.state_lock:SetState(1) self:UpdateCostMat() return end local curLockNum = self:GetLockCount() local lockCfg = DataSheetManager.PetRuneLock:GetDataByID(self.activeSkillCount) if lockCfg.LockNum < curLockNum + 1 then --不能再锁了 CTL.Tips.AddTipsMsg(Const_IDS["IDS_Pet_SkillLockNum"]) return end self.lockItemList[i] = 1 col.state_lock:SetState(0) self:UpdateCostMat() end function UIGodPetRuneStudy:UpdateLockNum() local maxCount = DataSheetManager.PetRuneLock:GetDataByID(self.activeSkillCount).LockNum local curLockNum = self:GetLockCount() self.txt_LockNum.text = string.FormatByIdsId(Const_IDS.IDS_Pet_SkillLockNum2, curLockNum .. "/" .. maxCount) end function UIGodPetRuneStudy:OnRuneStudySuccess(newRuneId) CTL.Sound.PlayGameSound("UI_breakout_01") local slotInfo = MDL.Pet.GetSlotInfoBySlotId(self.slotId) for i, v in ipairs(slotInfo.talismanSkill) do if newRuneId == v then if self.group_RuneSkill[i] then self.group_RuneSkill[i].effect_LearnSuccess:PlayUIEffect() end break end end end function UIGodPetRuneStudy:OnClosed() CTL.Pet.TryRemoveStudyRed(self.slotId) end return UIGodPetRuneStudy