local UITreasureSoulCrystalShow = UIViewClass() local EventSystem = require('Event/EventSystem') -------------------- --[[ 参数说明: treasureId ——> 表示当前选中的宝物id showPlace ——> 在 Treasure_Controller.SoulCrystalShowPlace 定义,用于表示该界面打开的位置 id ——> 服务器存储魂晶唯一id panelPosX ——> 界面X位置 panelPosY ——> 界面Y位置 --]] function UITreasureSoulCrystalShow:OnOpened(context) self:RegistSystemEvent(EventID.TreasureSoulCrystal_UpdateShowPanel, self.RefreshShowPanel) self:RefreshShowPanel(context) end function UITreasureSoulCrystalShow:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UITreasureSoulCrystalShow:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.btn_Refined then if self.showPlace == CTL.Treasure.SoulCrystalShowPlace.Equip then self:CloseView() UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSoulCrystalRefinedPanel, {treasureId = self.treasureId, id = self.soulInfo.id}) end elseif comp == self.btn_Advance then self:CloseView() if self.showPlace == CTL.Treasure.SoulCrystalShowPlace.Equip then UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSoulCrystalAdvanced, {treasureId = self.treasureId, id = self.soulInfo.id}) else UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSoulCrystalAdvanced, {id = self.soulInfo.id}) end elseif comp == self.btn_AdvancedSure then self:CloseView() EventSystem.Dispatch(EventID.TreasureSoulCrystal_AdvancedSure, self.soulInfo.id) elseif comp == self.btn_Equipment then -- 装备魂晶 self:EquipmentSoulCrystal() elseif comp == self.btn_remove then self:RemoveSoulCrystal() end end function UITreasureSoulCrystalShow:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.LoopScroll_SoulCrystalEquipTips then if data.AttrType then -- 设置属性名字 local attrData = DataSheetManager.AttrData:GetDataByID(data.AttrType) local str = UIUtils.GetLocalizedTxt(Const_IDS[attrData.Name]) -- 定义一个str变量 用于字符串的记录 UIUtils.SetLabel(cellTable.txt_AttributesName, CTL.Treasure.GetQualityStrByPercentBlockId(str, data.PercentBlockId)) -- 设置属性值 和 百分比 local basicAttrWeight = CTL.Treasure.GetBasicAttrWeight(self.soulInfo.soulData.SoulID, self.soulInfo.soulData.Color, data.AttrType) if basicAttrWeight then str = string.format("%s/%s", data.AttrNum, basicAttrWeight.AttrMaxNum) UIUtils.SetLabel(cellTable.txt_Attributes, CTL.Treasure.GetQualityStrByPercentBlockId(str, data.PercentBlockId)) -- 百分比保留小数点后一位,保留方式 四舍五入 local percentage = (data.AttrNum / basicAttrWeight.AttrMaxNum) str = UTL.String.GetPercentFormatFloat(percentage*100, 0, 1) UIUtils.SetLabel(cellTable.txt_Percentage, CTL.Treasure.GetQualityStrByPercentBlockId(str, data.PercentBlockId)) end elseif data.attrType then if data.state == MDL.Treasure.SoulSlotAttrState.NotValue then cellTable.obj_cellState:SetState(1) UIUtils.SetLabelText(cellTable.txt_AttributesName, Const_IDS.IDS_TreasureSoul_NextWash) else cellTable.obj_cellState:SetState(0) -- 设置属性名字 local attrData = DataSheetManager.AttrData:GetDataByID(data.attrType) local str = UIUtils.GetLocalizedTxt(Const_IDS[attrData.Name]) -- 定义一个str变量 用于字符串的记录 UIUtils.SetLabel(cellTable.txt_AttributesName, CTL.Treasure.GetQualityStrByPercentBlockId(str, data.percentBlockId)) -- 设置属性值 和 百分比状态 local refineAttrWeight = CTL.Treasure.GetRefineAttrWeight(data.refineID, data.attrType) if refineAttrWeight then str = string.format("%s/%s", data.attrValue, refineAttrWeight.AttrMaxNum) UIUtils.SetLabel(cellTable.txt_Attributes, CTL.Treasure.GetQualityStrByPercentBlockId(str, data.percentBlockId)) -- 百分比保留小数点后一位,保留方式 四舍五入 local percentage = (data.attrValue - refineAttrWeight.AttrMinNum) / (refineAttrWeight.AttrMaxNum - refineAttrWeight.AttrMinNum) UIUtils.SetLabel(cellTable.txt_Percentage, UTL.String.GetPercentFormatFloat(percentage*100, 0, 1)) UIUtils.SetAtlasImageFillAmount(cellTable.img_ProgressBar, percentage / 1) end end elseif data.contextIds then UIUtils.SetLabelText(cellTable.lab_Title, data.contextIds) UIUtils.SetActive(cellTable.obj_PowerRoot, true) UIUtils.SetLabel(cellTable.txt_PowerNumber, data.gs) elseif data.isItemSource then local sourcesList = MDL.ItemSources.GetItemSourcesById(self.soulInfo.cfgId) for i, sourceData in ipairs(sourcesList) do local item = cellTable.Content[i] if not item then item = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, cellTable.Content[1].gameObject) end UIUtils.SetActive(item.gameObject, true) item.txt_ItemSources.text = sourceData.desc item.state_ItemSources:SetState(sourceData.isUnlock) end end elseif scrollRect == self.loop_ItemSources then cellTable.txt_ItemSources.text = data.desc cellTable.state_ItemSources:SetState(data.isUnlock) end end function UITreasureSoulCrystalShow:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.LoopScroll_SoulCrystalEquipTips then for i, itemCell in ipairs(cellTable.Content) do if target == itemCell.btn_ItemSources then local sourcesList = MDL.ItemSources.GetItemSourcesById(self.soulInfo.cfgId) local sourceData = sourcesList[i] if sourceData.isUnlock > 0 then EventSystem.Dispatch(EventID.UI_PayMall_SaveCurrentShopTabIndex) -- 保存一下商城打开的页签 EventSystem.Dispatch(EventID.UI_Treasure_SaveCurrentTabIndex) -- 保存一下宝物页签 保证商城切换回来 可以调到该页签 self:CloseView() CTL.ItemSources.ExecuteSourceFunctionById(sourceData.sourceId, self.soulInfo.cfgId) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_Formation_RelationShip_Closed) end end end end end -------------------- function UITreasureSoulCrystalShow:InitPanel() if self.showPlace == CTL.Treasure.SoulCrystalShowPlace.Reborn then self.state_Btn:SetState(3) -- 什么按钮都没有 仅仅展示 -- 这种模式下 界面的开关、canvas由父界面管理 需要将对应的UI关掉 UIUtils.SetActive(self.btn_Close.gameObject, false) --目前这里走不到 但是不一定后续需求会走到这里 这次修改无法测试 if not GameAppInfo.IsVersionGreaterThan18000() then local canvas = self.gameObject:GetComponent(typeof(UnityEngine.Canvas)) canvas.overrideSorting = false end else -- 需要恢复对应UI UIUtils.SetActive(self.btn_Close.gameObject, true) local canvas = self.gameObject:GetComponent(typeof(UnityEngine.Canvas)) canvas.overrideSorting = true if self.showPlace == CTL.Treasure.SoulCrystalShowPlace.Equip then self.state_Btn:SetState(0) -- 有 卸下、洗练、升阶 按钮 -- 洗练有单独的开启条件 需要判断一下是否开启了洗练 UIUtils.SetActive(self.btn_Refined.gameObject, MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.TreasureSoulWash)) -- 升阶需要判断是否已经满级 if self.soulInfo.soulData.ColorUpTarget == 0 then UIUtils.SetActive(self.btn_Advance, false) end -- 装备中的魂晶 洗练、升阶、卸下 需要显示红点 UIUtils.SetActive(self.img_YelPoint, CTL.Treasure.CheckTreasureSoulSlotAttr(self.treasureId, self.equipPosIndex) or CTL.Treasure.CheckTreasureSoulRefined(self.soulInfo.id)) self.btn_Advance:SetRedPoint(CTL.Treasure.CheckTreasureSoulAdvanced(self.soulInfo.id)) self.btn_remove:SetRedPoint(CTL.Treasure.CheckTreasureSoulHasBetter(self.treasureId, self.soulInfo.id)) elseif self.showPlace == CTL.Treasure.SoulCrystalShowPlace.Bag then self.state_Btn:SetState(1) -- 有 升阶、装备 按钮 self.btn_Advance:SetRedPoint(false) self.btn_Equipment:SetRedPoint(CTL.Treasure.IsBetterSoulCrystal(self.treasureId, self.soulInfo.id)) -- 升阶需要判断是否已经满级 if self.soulInfo.soulData.ColorUpTarget == 0 then UIUtils.SetActive(self.btn_Advance, false) end elseif self.showPlace == CTL.Treasure.SoulCrystalShowPlace.Advanced then self.state_Btn:SetState(2) -- 有 确定 按钮 end end -- 设置魂晶展示 UTL.Item.SetItemCell(self.item, self.soulInfo.cfgId) UIUtils.SetLabel(self.txt_SoulCrystaName, UTL.Item.GetItemColorName(self.soulInfo.cfgId)) UIUtils.SetLabel(self.txt_SoulCrystaAttributes, string.FormatByIdsId(Const_IDS.IDS_TreasureSoul_HunShu, CTL.Treasure.GetSoulCrystalTypeName(self.soulInfo.soulData.CrystalType))) local soulCrystalTypeData = DataSheetManager.TreasureSoulCrystalType:GetDataByCrystalType(self.soulInfo.soulData.CrystalType) if soulCrystalTypeData then UIUtils.SetImageByAssetBundle(self.img_SoulCrystalIcon, soulCrystalTypeData.LightIconName) self.img_SoulCrystalIcon:SetNativeSize() end -- 清空属性列表 if self.LoopScroll_SoulCrystalEquipTips.Count > 0 then self.LoopScroll_SoulCrystalEquipTips:ClearCells() end -- 基础属性展示 self.LoopScroll_SoulCrystalEquipTips:AddData({contextIds = Const_IDS.IDS_TreasureSoul_JiChuShuXing, gs = self.soulInfo.attrGS}, 0) for _, v in ipairs(self.soulInfo.baseAttrList) do self.LoopScroll_SoulCrystalEquipTips:AddData(v, 1) end -- 孔位属性展示 if self.showPlace == CTL.Treasure.SoulCrystalShowPlace.Equip then local treasureInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) local slotAttrs = treasureInfo.TreasureInfo.soulSlotInfos[self.equipPosIndex].slotAttrs if #slotAttrs > 0 then -- 计算洗练属性战力 local attrGS = 0 for _, v in ipairs(slotAttrs) do if v.state == MDL.Treasure.SoulSlotAttrState.Effective then attrGS = attrGS + UTL.Attr.CalculateSingleFight(v.attrType, v.attrValue) end end attrGS = math.floor(attrGS + 0.5) self.LoopScroll_SoulCrystalEquipTips:AddData({contextIds = Const_IDS.IDS_TreasureSoul_XiLianShuXing, gs = attrGS}, 0) for _, v in ipairs(slotAttrs) do self.LoopScroll_SoulCrystalEquipTips:AddData(v, 2) end end end --获取途径 if CTL.ItemSources.IsShowItemSource(self.soulInfo.cfgId) then self.LoopScroll_SoulCrystalEquipTips:AddData({isItemSource = true}, 3) end end function UITreasureSoulCrystalShow:RefreshShowPanel(context) self.treasureId = context.treasureId self.showPlace = context.showPlace self.soulInfo = MDL.Treasure.GetSoulCrystalById(context.id) if self.showPlace == CTL.Treasure.SoulCrystalShowPlace.Equip then local equipDic = MDL.Treasure.GetEquipDicByTreasureId(self.treasureId) self.equipPosIndex = equipDic[context.id].PosIndex end local _, selfPosY, selfPosZ = self.img_EquipTipsBg.transform:GetPosition() self.img_EquipTipsBg.transform:SetPosition(context.panelPosX, context.panelPosY and context.panelPosY or selfPosY, selfPosZ) self:InitPanel() end function UITreasureSoulCrystalShow:EquipmentSoulCrystal() local treasureInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) for i, v in ipairs(treasureInfo.TreasureInfo.soulSlotInfos) do if string.isNilOrEmpty(v.soulCrystalId) then MDL.Treasure.TreasureSoulEquipOptReq(true, false, self.treasureId, {self.soulInfo.id}, i) return end end local index = CTL.Treasure.GetChangeSoulCrystalIndex(self.treasureId, self.soulInfo.id) if index > 0 then MDL.Treasure.TreasureSoulEquipOptReq(true, false, self.treasureId, {self.soulInfo.id}, index) else -- 如果上面没有return,表示宝物已经装备满了 CTL.Tips.AddTipsMsg(Const_IDS.IDS_TreasureSoul_SetTips) end end function UITreasureSoulCrystalShow:RemoveSoulCrystal() MDL.Treasure.TreasureSoulEquipOptReq(false, false, self.treasureId, {self.soulInfo.id}, self.equipPosIndex) end return UITreasureSoulCrystalShow