local UIHorseSoulMain = UIViewClass() local resonance_info = require 'Proto.resonance_info_pb' function UIHorseSoulMain:OnOpened(context) self:RegistSystemEvent(EventID.UI_ResonanceChange_Refresh, self.RefreshResonanceLv) self:RegistSystemEvent(EventID.UI_UpdateWarHorseInfo, self.RefreshEquipSlot) self:RegistSystemEvent(EventID.UI_Illustration_HorseLibrary_RefreshBase, self.RefreshLibraryAdd) self:RegistSystemEvent(EventID.HorseSoulPearl_UpdateBag, self.RefreshEquipSlot) self:RegistSystemEvent(EventID.HorseSoulPearl_UpdateBag, self.RefreshSoulItems) self:RegistSystemEvent(EventID.UI_HorseSoul_EquipUpdate, self.RefreshSoulItems) self:RegistSystemEvent(EventID.UI_CloseHorseSoulTips, self.OnCloseSoulTips) self:RegistSystemEvent(EventID.UI_HorseSoul_EquipOpt, self.ShowSkillUpgrade) CTL.FormationResonance.SetSubResonanceImage(self.icon_Resonance, resonance_info.Horse_Soul, self.lab_Name) -- 设置共鸣图片 self:RefreshResonanceLv() self:RefreshLibraryAdd() self.parentView = context.parentView self.cancelSelect = false self.soulSuit = MDL.HorseSoul.GetSoulSuitDataList() self.toggles:InstaniateToggles(#self.soulSuit) for i, v in ipairs(self.soulSuit) do self.toggles:SetToggleCompImage(i, "img_Pos", CTL.HorseSoul.PositionImage[i]) self.toggles:SetToggleActive(i, true) self.loop_Type:AddData(v, 0) end self.loop_Type:AddData(nil, 0) self.loop_Type:SelectIndex(#self.soulSuit) self:UpdateInfo(context.horseConfig) self:RefreshTypeText() self:CloseTipView() end function UIHorseSoulMain:OnButtonClicked(comp) if comp == self.btn_Resonance then UIManager.OpenView(Const_UI_Lua.UIEnum.UIResonanceInfo, {subResonanceID = resonance_info.Horse_Soul, isShowGoto = false}) elseif comp == self.btn_Type then local active = not self.loop_Type.gameObject.activeInHierarchy self:SetLoopTypeActive(active) UIUtils.SetActive(self.btn_Bottom, active) elseif comp == self.btn_Library then local active = not self.tip_Library.gameObject.activeInHierarchy UIUtils.SetActive(self.tip_Library, active) UIUtils.SetActive(self.btn_Bottom, active) elseif comp == self.btn_Go then CTL.HorseLibrary.OpenMainPanel() elseif comp == self.btn_Attr then self:RefreshAttrInfo() elseif comp == self.btn_Gather then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIHorseSoulGachaMain) elseif comp == self.btn_Equip then if #self.soulBagList > 0 or MDL.HorseSoul.CanEquip() then MDL.HorseSoul.HorseSoulEquipReq(MDL.HorseSoul.HorseSoulEquipType.AutoEquip, "", self.horseData.HorseID, 0, self.filterSuitId > 0 and self.filterSuitId or 0) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_HorseSoul_Hint_QuickEquip2) -- 暂无可装备的魂珠 end elseif comp == self.btn_Skill then local level, suitId = CTL.HorseSoul.GetSoulSkillLevel(self.horseData.HorseID) UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseSoulSkillInfo, {suitID = suitId, skillLevel = level, isInvalid = CTL.HorseSoul.IsSoulSkillInvalid(self.horseData.HorseID)}) elseif comp == self.btn_Empty then CTL.Tips.AddTipsMsg(Const_IDS.IDS_HorseSoul_TipsHint6) elseif comp == self.btn_Bottom then self:CloseTipView() elseif comp == self.btn_Next then self.parentView:SwitchHorseShow(1) elseif comp == self.btn_Before then self.parentView:SwitchHorseShow(-1) else for i, v in ipairs(self.group_Equipped) do local isSelect = false if comp == v.btn_Empty then self.toggles:SelectIndex(i - 1) isSelect = true elseif comp == v.btn_Equipped then self.toggles:SelectIndex(i - 1) CTL.HorseSoul.OpenSoulTips(self.horseData.HorseID, self.slotList[i].soulPearl) isSelect = true end if isSelect then UIUtils.SetActive(v.img_Selected, true) if self.selectEquipIndex ~= i then if self.selectEquipIndex then UIUtils.SetActive(self.group_Equipped[self.selectEquipIndex].img_Selected, false) end self.selectEquipIndex = i end break end end end end function UIHorseSoulMain:CloseTipView() UIUtils.SetActive(self.tip_Library, false) UIUtils.SetActive(self.tip_Attr, false) UIUtils.SetActive(self.btn_Bottom, false) self:SetLoopTypeActive(false) end function UIHorseSoulMain:OnValueChanged(comp, index) if comp == self.toggles then if self.filterSlotIndex ~= index + 1 then self.filterSlotIndex = index + 1 self:RefreshSoulItems() end end end function UIHorseSoulMain:UpdateInfo(horseConfig) self.horseData = horseConfig self.filterSlotIndex = self.filterSlotIndex and self.filterSlotIndex or 0 self.filterSuitId = self.filterSuitId and self.filterSuitId or -1 self.toggles:SelectIndex(self.filterSlotIndex >= 1 and self.filterSlotIndex - 1 or 0) self:RefreshEquipSlot() end function UIHorseSoulMain:RefreshEquipSlot() --更新装备槽位 self.slotList = MDL.HorseSoul.GetSoulSlotInfoByHorseId(self.horseData.HorseID) for i, v in ipairs(self.group_Equipped) do UIUtils.SetActive(v.img_Selected, false) UIUtils.SetActive(v.group_Star.gameObject, false) local soulId = self.slotList[i] and self.slotList[i].soulPearl CTL.HorseSoul.SetPositionImage(v.img_Pos, i) local ifHasSoul = CTL.HorseSoul.JudgeSoulId(soulId) v.state_Equipped:SetState(ifHasSoul and 1 or 0) if ifHasSoul then local soulInfo = MDL.HorseSoul.GetSoulInfoById(soulId) UTL.Color.SetQualityImageByType(v.img_quality, soulInfo.itemData.Color, UTL.Color.QualityType.Circle) UTL.Item.OnlyItemIconWithoutBg(v.img_Soul, soulInfo.cfgId) v.txt_Level.text = string.FormatByIdsKey("IDS_HorseSoul_Button3", soulInfo.levelInfo.level) v.btn_Equipped:SetRedPoint(CTL.HorseSoul.IsSoulPearlCanUpgrade(soulId)) UIUtils.SetActive(v.group_Star.gameObject, soulInfo.itemData.Color >= LuaConst.QualityColor.Gold) if soulInfo.itemData.Color >= LuaConst.QualityColor.Gold then CTL.HorseSoul.SetStarLevel(v.group_Star, soulInfo.star) end else v.btn_Empty:SetRedPoint(CTL.HorseSoul.IsPosCanEquip(i)) end end --更新技能相关 local level, suitId = CTL.HorseSoul.GetSoulSkillLevel(self.horseData.HorseID) self.state_Skill:SetState(level and 0 or 1) if level then local skillData = DataSheetManager.HorseSoulSuitData:GetDataByHorseSoulSuitID_HorseSoulSkillLevel(suitId, level) local isSuccess, nextSkillData = DataSheetManager.HorseSoulSuitData:TryGetDataByHorseSoulSuitID_HorseSoulSkillLevel(suitId, level + 1) UIUtils.SetImageByAssetBundle(self.img_Skill, skillData.HorseSoulSkillIcon) UIUtils.SetLabelText(self.txt_SkillName, Const_IDS[skillData.HorseSoulSkillName]) UIUtils.SetActive(self.group_Star.gameObject, skillData.SoulStar_Table[1] ~= nil or (isSuccess and nextSkillData.SoulStar_Table[1] ~= nil)) if skillData.SoulStar_Table[1] ~= nil or (isSuccess and nextSkillData.SoulStar_Table[1] ~= nil) then CTL.HorseSoul.SetStarLevel(self.group_Star, skillData.SoulStar_Table[1] and skillData.SoulStar_Table[1].NeedSoulStar or 0) end self.effect_Skill:PlayUIEffect(skillData.HorseSoulSkillEffect, 0) UIUtils.SetActive(self.group_NoEffect, CTL.HorseSoul.IsSoulSkillInvalid(self.horseData.HorseID)) else self.effect_Skill:StopUIEffect() end self.txt_Gs.text = CTL.HorseSoul.GetHorseSoulGs(self.horseData.HorseID) self.btn_Gather:SetRedPoint(MDL.HorseSoul.IsShowDrawTenCardRP()) -- 聚魂红点 end function UIHorseSoulMain:RefreshAttrInfo() local active = not self.tip_Attr.gameObject.activeInHierarchy UIUtils.SetActive(self.tip_Attr, active) UIUtils.SetActive(self.btn_Bottom, active) if active then --更新战力和属性 local attrList = CTL.HorseSoul.GetHorseSoulAttrs(self.horseData.HorseID) self.loop_Attr:ReloadAll(attrList) UIUtils.SetActive(self.img_AttrEmpty, self.loop_Attr.Count == 0) end end function UIHorseSoulMain:RefreshSoulItems() self.soulBagList = {} if self.loop_HorseSoul.Count > 0 then self.loop_HorseSoul:ClearCells() end for i, v in ipairs(MDL.HorseSoul.GetSoulItemList()) do local soulInfo = MDL.HorseSoul.GetSoulInfoById(v) local soulData = soulInfo.soulData if soulData.HorseSoulPositionID == self.filterSlotIndex then if self.filterSuitId < 0 or self.filterSuitId == soulData.HorseSoulSuitID then table.insert(self.soulBagList, soulInfo) end end end self.loop_HorseSoul:ReloadAll(self.soulBagList) UIUtils.SetActive(self.img_Empty, self.loop_HorseSoul.Count == 0) end function UIHorseSoulMain:RefreshTypeText() local data = self.soulSuit[self.filterSuitId] UIUtils.SetLabelText(self.txt_Type, data and Const_IDS[data.suitName] or Const_IDS.IDS_HorseSoul_MainHint2) if data then UIUtils.SetActive(self.img_TypeIcon, true) UTL.Item.SetAtlasSprite(self.img_TypeIcon, "UI_Horse", data.icon) else UIUtils.SetActive(self.img_TypeIcon, false) end end -- 刷新共鸣显示 function UIHorseSoulMain:RefreshResonanceLv() UIUtils.SetActive(self.btn_Resonance, MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Resonance)) local level = MDL.FormationResonance.GetSubResonanceLv(resonance_info.Horse_Soul) self.txt_ResonanceLv.text = string.FormatByIdsId(Const_IDS["IDS_Resonance_Level"], level) end function UIHorseSoulMain:RefreshLibraryAdd() local level = MDL.HorseLibrary.GetLibraryLevelAndScore() self.txt_LibraryLevel.text = string.FormatByIdsId(Const_IDS.IDS_HorseSoul_Button3, level) local addNum = 0 local addText = "+0%" if level > 0 then addNum = DataSheetManager.HorsePictorialScore:GetDataByLevelID(level).HorseSoulAddition addText = "+" .. UTL.Attr.FormatNumberToPercentage(addNum, 1) end self.txt_NowAdd.text = addText self.txt_LibraryAdd.text = addText local nextData for i, v in DataSheetManager.HorsePictorialScore:GetEnumerator() do if v.HorseSoulAddition > addNum then nextData = v break end end if nextData then self.state_Library:SetState(1) self.txt_NextLevel.text = string.FormatByIdsId(Const_IDS.IDS_HorseSoul_Button3, nextData.LevelID) self.txt_NextAdd.text = "+" .. UTL.Attr.FormatNumberToPercentage(nextData.HorseSoulAddition, 1) else self.state_Library:SetState(0) end end function UIHorseSoulMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Attr then UTL.Attr.SetAttrItemByCompName(cellTable, data.AttrType, math.floor(data.AttrNum * MDL.HorseSoul.GetHorsePictorialAdd() + 0.5), true) elseif scrollRect == self.loop_Type then UIUtils.SetLabelText(cellTable.txt_Type, data and Const_IDS[data.suitName] or Const_IDS.IDS_HorseSoul_MainHint2) if data then UIUtils.SetActive(cellTable.img_Icon, true) UTL.Item.SetAtlasSprite(cellTable.img_Icon, "UI_Horse", data.icon) else UIUtils.SetActive(cellTable.img_Icon, false) end elseif scrollRect == self.loop_HorseSoul then UTL.Item.SetItemCell(cellTable.item, data.cfgId) cellTable.item.txt_Level.text = data.levelInfo.level if self.cancelSelect then UIUtils.SetActive(cellTable.img_Select, false) end if data.equipHorseId then UIUtils.SetActive(cellTable.bg_Head, true) local horseData = DataSheetManager.HorseData:GetDataByHorseID(data.equipHorseId) UIUtils.SetImageByAssetBundle(cellTable.img_HorseHead, horseData.HorseIcon) cellTable.item.event_Click:SetRedPoint(CTL.HorseSoul.IsSoulPearlCanUpgrade(data.id)) else cellTable.item.event_Click:SetRedPoint(false) UIUtils.SetActive(cellTable.bg_Head, false) end if data.itemData.Color >= LuaConst.QualityColor.Gold then CTL.HorseSoul.SetStarLevel(cellTable.item.group_Star, data.star) end end end function UIHorseSoulMain:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_HorseSoul then if self.selectCell ~= nil then UIUtils.SetActive(self.selectCell.img_Select, false) end self.selectCell = cellTable self.selectIndex = index local pos = data.soulData.HorseSoulPositionID local slotEquipId = self.slotList[pos] and self.slotList[pos].soulPearl slotEquipId = CTL.HorseSoul.JudgeSoulId(slotEquipId) and slotEquipId or nil CTL.HorseSoul.OpenSoulTips(self.horseData.HorseID, data.id, slotEquipId) UIUtils.SetActive(cellTable.img_Select, true) elseif scrollRect == self.loop_Type then if target == cellTable.btn_Type then if data then if self.filterSuitId ~= data.suitId then self.filterSuitId = data.suitId or -1 self:RefreshTypeText() self:RefreshSoulItems() end else if self.filterSuitId ~= -1 then self.filterSuitId = -1 self:RefreshTypeText() self:RefreshSoulItems() end end self:SetLoopTypeActive(false) end end end function UIHorseSoulMain:OnCloseSoulTips() self.cancelSelect = true if self.selectIndex ~= nil then self.loop_HorseSoul:UpdateIndex(self.selectIndex) end if self.selectEquipIndex ~= nil then UIUtils.SetActive(self.group_Equipped[self.selectEquipIndex].img_Selected, false) end self.selectEquipIndex = nil self.selectIndex = nil self.selectCell = nil self.cancelSelect = false end function UIHorseSoulMain:ShowSkillUpgrade(oldData) local level, suitId = CTL.HorseSoul.GetSoulSkillLevel(self.horseData.HorseID) if level and level > oldData.level then local oldSuitId = oldData.suitId if not oldSuitId or suitId == oldData.suitId then UIManager.OpenView(Const_UI_Lua.UIEnum.UIHorseSoulBreakSuccess, {suitID = suitId, oldSkillLevel = oldData.level, skillLevel = level}) end end end function UIHorseSoulMain:SetLoopTypeActive(active) UIUtils.SetActive(self.loop_Type, active) self.state_Type:SetState(active and 1 or 0) end return UIHorseSoulMain