local UITreasureSoulCrystalPanel = UIViewClass() local resonance_info = require 'Proto/resonance_info_pb' local TreasureSoulPitOpenCondition = DataSheetManager.ConstData:GetDataByID("TreasureSoulPitOpenCondition").IntListValue -------------------- function UITreasureSoulCrystalPanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_UpdateTreasureInfo, self.RefreshSoulCrystalGroup) self:RegistSystemEvent(EventID.UI_UpdateTreasureInfo, self.RefreshBagPanel) self:RegistSystemEvent(EventID.TreasureSoulCrystal_UpdateBag, self.RefreshBagPanel) self:RegistSystemEvent(EventID.UI_ResonanceChange_Refresh, self.RefreshResonanceLv) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshSoulCrystalGroupRedPoint) self:RegistSystemEvent(EventID.TreasureSoulCrystal_RefreshEquipEffect, self.RefreshEquipEffect) -- 设置共鸣 self:RefreshResonanceLv() CTL.FormationResonance.SetSubResonanceImage(self.icon_Resonance, resonance_info.Treasure_Soul, self.lab_Name) -- 设置共鸣图片 self.curToggleIndex = 0 self.treasureId = context.treasureId self:RefreshSoulCrystalGroup() self:InitToggles() UIUtils.SetActive(self.panel_ItemSources, false) UIUtils.SetActive(self.btn_CloseItemSources, false) end function UITreasureSoulCrystalPanel:OnButtonClicked(comp) if comp == self.btn_Equip then local soulCrystalIdList = CTL.Treasure.GetBestSoulCrystalInfoList(self.treasureId) if #soulCrystalIdList > 0 then MDL.Treasure.TreasureSoulEquipOptReq(true, true, self.treasureId, soulCrystalIdList) end elseif comp == self.btn_SoulCrystalProperty then local equipDic = MDL.Treasure.GetEquipDicByTreasureId(self.treasureId) if next(equipDic) then UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSoulCrystalProperty, {treasureId = self.treasureId}) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_TreasureSoul_NoEffectiveAttr) end elseif comp == self.btn_Resonance then UIManager.OpenView(Const_UI_Lua.UIEnum.UIResonanceInfo, {subResonanceID = resonance_info.Treasure_Soul, isShowGoto = false}) elseif comp == self.btn_ItemSources or comp == self.btn_CloseItemSources then self:OnClickItemSource() else self:ClickEquipmentSoulCrystal(comp) end end function UITreasureSoulCrystalPanel:OnValueChanged(comp, state) if comp == self.toggles then self.curToggleIndex = state self:RefreshBagPanel() end end function UITreasureSoulCrystalPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.group_RecommendSoulCrystal then local soulCrystalTypeData = DataSheetManager.TreasureSoulCrystalType:GetDataByCrystalType(data) if soulCrystalTypeData then UIUtils.SetImageByAssetBundle(cellTable.img_RecommendSoulCrystaliconLight, soulCrystalTypeData.LightIconName) cellTable.img_RecommendSoulCrystaliconLight:SetNativeSize() if CTL.Treasure.RecommendIndexIsActive(self.treasureId, index + 1) then -- c# 从0开始 cellTable.effect_SCLight:PlayUIEffect(CTL.Treasure.SoulCrystalEffect[data], -1) else cellTable.effect_SCLight:StopUIEffect() end else logging.error(LTAG.ERROR, "宝物赋魂[UITreasureSoulCrystalPanel:OnCellInit] : 没有找到 CrystalType = ", data, " 的赋魂系别数据") end elseif scrollRect == self.loopScroll_SoulCrystal then UIUtils.SetActive(cellTable.img_Arrow, CTL.Treasure.IsBetterSoulCrystal(self.treasureId, data.id)) UTL.Item.SetItemCell(cellTable.item, data.soulData.CrystalID) elseif scrollRect == self.loop_ItemSources then cellTable.txt_ItemSources.text = data.desc cellTable.state_ItemSources:SetState(data.isUnlock) end end function UITreasureSoulCrystalPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loopScroll_SoulCrystal then local posX, posY = self.obj_tipRightPos:GetPosition() local param = {showPlace = CTL.Treasure.SoulCrystalShowPlace.Bag, id = data.id, treasureId = self.treasureId, panelPosX = posX, panelPosY = posY} UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSoulCrystalShow, param) -- 重新设置一下cell的选中状态 UIUtils.SetActive(cellTable.sprite_Select, true) -- 需要重置孔位点击 for i, item in ipairs(self.group_Equipment) do UIUtils.SetActive(item.img_Selected, false) end elseif scrollRect == self.loop_ItemSources then if target == cellTable.btn_ItemSources then if data.isUnlock > 0 then CTL.ItemSources.ExecuteSourceFunctionById(data.sourceId) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Formation_RelationShip_Closed) end end end end -------------------- function UITreasureSoulCrystalPanel:InitToggles() local tagCount = DataSheetManager.TreasureSoulCrystalType:GetDataCount() + 1 -- 魂晶种类之外还有一个All页签,需要数量需要 + 1 self.toggles:InstaniateToggles(tagCount) -- 初始化第一个Toggle(一定是All页签) self.toggles:GetToggleComponent(1, "obj_toggleState"):SetState(1) self.toggles:SetToggleIDS(1, "txt_Grow", Const_IDS.IDS_TreasureSoul_All) self.toggles:SetToggleActive(1, true) -- 初始化后续的Toggle for i, v in DataSheetManager.TreasureSoulCrystalType:GetEnumerator() do self.toggles:GetToggleComponent(i + 1, "obj_toggleState"):SetState(0) local lightIcon = self.toggles:GetToggleComponent(i + 1, "img_bg_icon") UIUtils.SetImageByAssetBundle(lightIcon, v.LightIconName) lightIcon:SetNativeSize() local selectIcon = self.toggles:GetToggleComponent(i + 1, "img_Selected") UIUtils.SetImageByAssetBundle(selectIcon, v.SelectIconName) selectIcon:SetNativeSize() self.toggles:SetToggleActive(i + 1, true) end self.toggles:SetToggleActiveFromIndex(tagCount, false) -- 设置选中 self.toggles:SelectIndex(0) end function UITreasureSoulCrystalPanel:RefreshTreasureInfo(treasureId) self.treasureId = treasureId self:RefreshSoulCrystalGroup() self.loopScroll_SoulCrystal:RefreshCells(false) -- 刷新一键装备红点 self.btn_Equip:SetRedPoint(CTL.Treasure.CheckTreasureSoulHasBetter(self.treasureId)) end -- 刷新装备中的魂晶 & 倾好列表 function UITreasureSoulCrystalPanel:RefreshSoulCrystalGroup() local treasureInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) if not treasureInfo then return end local level = MDL.TreasureLibrary.GetLibraryLevelAndScore() local soulSlotInfo -- 设置孔位状态 for i, item in ipairs(self.group_Equipment) do -- 优先判断孔位是否解锁 local unlockLevel = TreasureSoulPitOpenCondition[i] if level < unlockLevel then -- 孔位尚未解锁 item.obj_emptyState:SetState(0) item.btn_Empty:SetGray(false, true) -- 只有尚未解锁时可以点击按钮 else local soulSlotInfo = treasureInfo.TreasureInfo.soulSlotInfos[i] if string.isNilOrEmpty(soulSlotInfo.soulCrystalId) then -- 为空表示孔位尚未镶嵌魂晶 item.obj_emptyState:SetState(1) else item.obj_emptyState:SetState(2) local soulInfo = MDL.Treasure.GetSoulCrystalById(soulSlotInfo.soulCrystalId) UTL.Item.ItemSquareIcon(item.img_SoulCrystalIcon, nil, soulInfo.cfgId) UTL.Color.SetQualityImageByType(item.img_SoulCrystalIconBg, soulInfo.soulData.Color, UTL.Color.QualityType.Circle) -- 设置红点箭头 UIUtils.SetActive(item.img_Arrow, CTL.Treasure.CheckTreasureSoulSlotAttr(self.treasureId, i) or CTL.Treasure.CheckTreasureSoulRefined(soulSlotInfo.soulCrystalId) or CTL.Treasure.CheckTreasureSoulAdvanced(soulSlotInfo.soulCrystalId) or CTL.Treasure.CheckTreasureSoulHasBetter(self.treasureId, soulSlotInfo.soulCrystalId)) end end item.effect_EquippedSuccessfully:StopUIEffect() UIUtils.SetActive(item.img_Selected, false) end -- 刷新魂晶倾好 self.group_RecommendSoulCrystal:ReloadAll(treasureInfo.TreasureData.CrystalPour) end -- 刷新装备中的魂晶红点 function UITreasureSoulCrystalPanel:RefreshSoulCrystalGroupRedPoint() local treasureInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) if not treasureInfo then return end local level = MDL.TreasureLibrary.GetLibraryLevelAndScore() for i, item in ipairs(self.group_Equipment) do -- 优先判断孔位是否解锁 local unlockLevel = TreasureSoulPitOpenCondition[i] if level >= unlockLevel then -- 孔位尚未解锁 local soulSlotInfo = treasureInfo.TreasureInfo.soulSlotInfos[i] if not string.isNilOrEmpty(soulSlotInfo.soulCrystalId) then -- 为空表示孔位尚未镶嵌魂晶 -- 更新红点箭头 UIUtils.SetActive(item.img_Arrow, CTL.Treasure.CheckTreasureSoulSlotAttr(self.treasureId, i) or CTL.Treasure.CheckTreasureSoulRefined(soulSlotInfo.soulCrystalId) or CTL.Treasure.CheckTreasureSoulAdvanced(soulSlotInfo.soulCrystalId)) end end end end -- 刷新魂晶背包 function UITreasureSoulCrystalPanel:RefreshBagPanel() if self.loopScroll_SoulCrystal.Count > 0 then self.loopScroll_SoulCrystal:ClearCells() end for _, v in MDL.Treasure.GetSoulCrystalIteratorByType(self.curToggleIndex) do if not v.equip then self.loopScroll_SoulCrystal:AddData(v, 0) end end -- 空状态显示 UIUtils.SetActive(self.img_Empty, self.loopScroll_SoulCrystal.Count == 0) -- 刷新一键装备红点 self.btn_Equip:SetRedPoint(CTL.Treasure.CheckTreasureSoulHasBetter(self.treasureId)) end -- 刷新共鸣显示 function UITreasureSoulCrystalPanel:RefreshResonanceLv() UIUtils.SetActive(self.btn_Resonance, MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.Resonance)) UIUtils.SetLabel(self.txt_ResonanceLv, string.FormatByIdsId(Const_IDS["IDS_Resonance_Level"], MDL.FormationResonance.GetSubResonanceLv(resonance_info.Treasure_Soul))) end -- 刷新装备、卸下特效 function UITreasureSoulCrystalPanel:RefreshEquipEffect(treasureId, posList) if treasureId == self.treasureId then for _, index in ipairs(posList) do local item = self.group_Equipment[index] item.effect_EquippedSuccessfully:PlayUIEffect() end end end -- 点击装备中魂晶事件 function UITreasureSoulCrystalPanel:ClickEquipmentSoulCrystal(comp) for i, item in ipairs(self.group_Equipment) do if comp == item.btn_Empty then CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_TreasureSoul_PitUnlock, TreasureSoulPitOpenCondition[i])) else if comp == item.btn_Equipped then self.loopScroll_SoulCrystal:SelectIndex(-1) -- 将背包里的选中取消 local treasureInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) if treasureInfo then local soulSlotInfo = treasureInfo.TreasureInfo.soulSlotInfos[i] if not string.isNilOrEmpty(soulSlotInfo.soulCrystalId) then UIUtils.SetActive(item.img_Selected, true) local posX, posY = self.obj_tipBottomPos:GetPosition() local param = {showPlace = CTL.Treasure.SoulCrystalShowPlace.Equip, id = soulSlotInfo.soulCrystalId, treasureId = self.treasureId, panelPosX = posX, panelPosY = posY} UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSoulCrystalShow, param) end end else UIUtils.SetActive(item.img_Selected, false) end end end end --点击道具获取途径 function UITreasureSoulCrystalPanel:OnClickItemSource() if self.panel_ItemSources.gameObject.activeSelf then self.loop_ItemSources:ClearCells() UIUtils.SetActive(self.panel_ItemSources, false) UIUtils.SetActive(self.btn_CloseItemSources, false) else self:OpenItemSources() end end function UITreasureSoulCrystalPanel:OpenItemSources() self.loop_ItemSources:ClearCells() UIUtils.SetActive(self.panel_ItemSources, true) UIUtils.SetActive(self.btn_CloseItemSources, true) local sourcesList = MDL.ItemSources.GetTreasureSoulCrystalItemSourcesById() for i, v in ipairs(sourcesList) do -- 一级页签换成二级页签ID if v.sourceId == MDL.ItemSources.SourceType.PayMall then v.sourceId = MDL.ItemSources.SourceType.TreasureSoulCrystal end self.loop_ItemSources:AddData(v, 0) end end return UITreasureSoulCrystalPanel