local UITreasureSoulCrystalAdvanced = UIViewClass() local EventSystem = require('Event/EventSystem') local TreasureSoulStone = DataSheetManager.ConstData:GetDataByID("TreasureSoulStone").IntValue -- 魂晶升阶材料 -------------------- --[[ 参数说明: treasureId ——> 表示当前选中的宝物id (非必传) id ——> 服务器存储魂晶唯一id (必传) --]] function UITreasureSoulCrystalAdvanced:OnOpened(context) self:RegistSystemEvent(EventID.BagItem_Update, self.RefreshAdvancedMaterial) self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.RefreshItemCount) self:RegistSystemEvent(EventID.TreasureSoulCrystal_AdvancedSure, self.AdvancedSure) self:RegistSystemEvent(EventID.TreasureSoulCrystal_RefreshAdvancedSucceed, self.RefreshAdvancedSucceed) self.treasureId = context.treasureId self.soulInfo = MDL.Treasure.GetSoulCrystalById(context.id) self.soulData = self.soulInfo.soulData self.openSubIndex = 0 self.chooseSoulCrystalIDDic = {} self:InitPanel() end function UITreasureSoulCrystalAdvanced:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UITreasureSoulCrystalAdvanced:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Advanced then if self.treasureId then local equipDic = MDL.Treasure.GetEquipDicByTreasureId(self.treasureId) local soulCrystalState = equipDic[self.soulInfo.id] if soulCrystalState then CTL.Treasure.CheckTreasureSoulQualityUp(self.soulInfo.id, self.chooseSoulCrystalIDDic, self.treasureId, soulCrystalState.PosIndex) end else CTL.Treasure.CheckTreasureSoulQualityUp(self.soulInfo.id, self.chooseSoulCrystalIDDic) end elseif comp == self.btn_AttributeOverview then self:OpenAttributeOverview() elseif comp == self.btn_AttributeOverviewClickBg then UIUtils.SetActive(self.group_AttributeOverview, false) elseif comp == self.group_MainSoulCrystal.btn_Click then CTL.Tips.AddTipsMsg(Const_IDS.IDS_TreasureSoul_MainMaterial) elseif comp == self.btn_ClickBg then UIUtils.SetActive(self.group_ChooseSoulCrystal, false) elseif comp == self.obj_MaterialItem.event_Click then UTL.ItemTips.ShowCommonTipsById(TreasureSoulStone) elseif comp == self.btn_Coin then local coinCost = self.soulData.ColorUp_Table[1] -- 与策划协定潜规则 消耗表里默认第一个为货币消耗 UTL.ItemTips.ShowCommonTipsById(coinCost.ItemID) elseif comp == self.btn_OneKeyAdvanced then self:OneChooseSoulCrystal() else for i, v in ipairs(self.group_SubSoulCrystal) do if comp == v.btn_Click then self.openSubIndex = i self:OpenChooseSoulCrystal(v.gameObject) elseif comp == v.btn_Removing then self.chooseSoulCrystalIDDic[i] = nil self:RefreshSubSoulCrystal() end end end end function UITreasureSoulCrystalAdvanced:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loopScroll_SoulCrystal then UTL.Item.SetItemCell(cellTable.item, data.soulData.CrystalID) else for i, v in ipairs(self.img_AttributeOverviewBg) do -- 第一个默认为主御魂 if scrollRect == v.LoopScroll_SoulCrystalEquipTips 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)) UIUtils.SetLabel(cellTable.txt_Attributes, CTL.Treasure.GetQualityStrByPercentBlockId(data.AttrNum, data.PercentBlockId)) break end end end end function UITreasureSoulCrystalAdvanced:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loopScroll_SoulCrystal then if UIManager.IsViewOpened(EventID.TreasureSoulCrystal_UpdateShowPanel) then EventSystem.Dispatch(EventID.TreasureSoulCrystal_UpdateShowPanel, {showPlace = CTL.Treasure.SoulCrystalShowPlace.Advanced, id = data.id}) else local posX if self.openSubIndex == 1 then -- 在最左边的时候 posX = self.obj_tipRightPos:GetPosition() else posX = self.obj_tipLeftPos:GetPosition() end local param = {showPlace = CTL.Treasure.SoulCrystalShowPlace.Advanced, id = data.id, panelPosX = posX} UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSoulCrystalShow, param) end end end -------------------- function UITreasureSoulCrystalAdvanced:InitPanel() -- 设置标题 UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_TreasureSoul_ShengJie) -- 设置魂晶图标 UTL.Item.ItemSquareIcon(self.img_SoulCrystalIcon, nil, self.soulData.CrystalID) UTL.Color.SetQualityImageByType(self.img_SoulCrystalBg, self.soulData.Color, UTL.Color.QualityType.Circle) -- 设置魂晶名称 UIUtils.SetLabel(self.txt_SoulCrystalName, UTL.Item.GetItemColorName(self.soulData.CrystalID)) -- 设置魂晶魂属 UIUtils.SetLabel(self.txt_SoulCrystalAttributes, string.FormatByIdsId(Const_IDS.IDS_TreasureSoul_HunShu, CTL.Treasure.GetSoulCrystalTypeName(self.soulData.CrystalType))) -- 设置增加词条数 local curAttrNum = DataSheetManager.TreasureSoulBasicAttrWeight:GetDataBySoulID_Color(self.soulData.SoulID, self.soulData.Color).AttrNum local targetSoulData = DataSheetManager.TreasureSoulCrystalData:GetDataByCrystalID(self.soulData.ColorUpTarget) local targetAttrNum = DataSheetManager.TreasureSoulBasicAttrWeight:GetDataBySoulID_Color(targetSoulData.SoulID, targetSoulData.Color).AttrNum UIUtils.SetLabel(self.txt_Conditions, string.FormatByIdsId(Const_IDS.IDS_TreasureSoul_ShengJieTiSheng2, targetAttrNum - curAttrNum)) -- 初始化材料Item self:RefreshAdvancedMaterial() self:RefreshItemCount() -- 初始化主魂晶 UTL.Item.ItemSquareIcon(self.group_MainSoulCrystal.img_SubSoulCrystalIcon, nil, self.soulData.CrystalID) UTL.Color.SetQualityImageByType(self.group_MainSoulCrystal.img_SubSoulCrystalQualityBg, self.soulData.Color, UTL.Color.QualityType.Circle) UIUtils.SetLabel(self.group_MainSoulCrystal.txt_PowerNumber, UTL.Attr.CalculateFight(self.soulInfo.baseAttrList)) -- 设置按钮状态 if self.soulData.ColorUpTarget > 0 then self.obj_advancedState:SetState(0) else self.obj_advancedState:SetState(1) end -- 初始化副魂晶(默认为空) for i, v in ipairs(self.group_SubSoulCrystal) do v.obj_subState:SetState(1) end -- 关闭特殊界面 UIUtils.SetActive(self.group_ChooseSoulCrystal, false) UIUtils.SetActive(self.group_AttributeOverview, false) end -- 升阶完成 重新刷新一下界面 function UITreasureSoulCrystalAdvanced:RefreshAdvancedSucceed(advancedDic) if not advancedDic[self.soulInfo.id] then return end if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UITreasureSoulCrystalAdvancedSuccess) then EventSystem.Dispatch(EventID.TreasureSoulCrystal_RefreshAdvancedSuccess, {id = self.soulInfo.id, beforeData = advancedDic[self.soulInfo.id]}) else UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSoulCrystalAdvancedSuccess, {id = self.soulInfo.id, beforeData = advancedDic[self.soulInfo.id]}) end self.soulInfo = MDL.Treasure.GetSoulCrystalById(self.soulInfo.id) self.soulData = self.soulInfo.soulData if self.soulData.ColorUpTarget > 0 then self.openSubIndex = 0 self.chooseSoulCrystalIDDic = {} self:InitPanel() else -- 如果已经是最高级别魂晶则直接关闭界面 self:OnButtonClicked(self.UICommonPopUp.btn_Close) end end -- 刷新材料 function UITreasureSoulCrystalAdvanced:RefreshAdvancedMaterial() self.obj_materialState:SetState(1) for _, v in ipairs(self.soulData.ColorUp_Table) do if v.ItemID == TreasureSoulStone then self.obj_materialState:SetState(0) UTL.Item.SetItemCell(self.obj_MaterialItem, v.ItemID) UIUtils.SetActive(self.obj_MaterialItem.group_Count, true) UIUtils.SetLabel(self.obj_MaterialItem.lab_Count, CTL.Treasure.GetCostStr(TreasureSoulStone, v.ItemNum)) break end end end -- 刷新货币消耗 function UITreasureSoulCrystalAdvanced:RefreshItemCount() -- 刷新货币消耗 local coinCost = self.soulData.ColorUp_Table[1] -- 与策划协定潜规则 消耗表里默认第一个为货币消耗 UTL.Item.MoneyIcon(self.img_Coin, coinCost.ItemID) local ownItemCount = UTL.Item.GetItemStockCount(coinCost.ItemID) if ownItemCount < coinCost.ItemNum then UIUtils.SetLabel(self.txt_CoinNum, UTL.Color.FormatRedColor(coinCost.ItemNum)) else UIUtils.SetLabel(self.txt_CoinNum, UTL.Color.FormatGreenColor(coinCost.ItemNum)) end end -- 打开选中列表 function UITreasureSoulCrystalAdvanced:OpenChooseSoulCrystal(targetObj) UIUtils.SetActive(self.group_ChooseSoulCrystal, true) self.img_ChooseSoulCrystal.transform:SetPosition(targetObj.transform:GetPosition()) local posX, posY, posZ = self.img_ChooseSoulCrystal.transform:GetLocalPosition() self.img_ChooseSoulCrystal.transform:SetLocalPosition(posX + 60 , posY, posZ) if self.loopScroll_SoulCrystal.Count > 0 then self.loopScroll_SoulCrystal:ClearCells() end for _, v in MDL.Treasure.GetSoulCrystalIteratorByCrystalGroup(self.soulData.ColorUpConsume, false) do local isChoose = self:SoulCrystalIsChoose(v.id) if (not v.equip) and (not isChoose) and v.id ~= self.soulInfo.id then self.loopScroll_SoulCrystal:AddData(v, 0) end end UIUtils.SetActive(self.img_Empty, self.loopScroll_SoulCrystal.Count == 0) end -- 确定选中列表中的魂晶 function UITreasureSoulCrystalAdvanced:AdvancedSure(id) local isChoose, index = self:SoulCrystalIsChoose(id) if isChoose then self.chooseSoulCrystalIDDic[index] = nil end UIUtils.SetActive(self.group_ChooseSoulCrystal, false) self.chooseSoulCrystalIDDic[self.openSubIndex] = id self.openSubIndex = 0 self:RefreshSubSoulCrystal() end function UITreasureSoulCrystalAdvanced:RefreshSubSoulCrystal() for i, v in ipairs(self.group_SubSoulCrystal) do local id = self.chooseSoulCrystalIDDic[i] if id then v.obj_subState:SetState(0) local soulInfo = MDL.Treasure.GetSoulCrystalById(id) UTL.Item.ItemSquareIcon(v.img_SubSoulCrystalIcon, nil, soulInfo.soulData.CrystalID) UTL.Color.SetQualityImageByType(v.img_SubSoulCrystalQualityBg, soulInfo.soulData.Color, UTL.Color.QualityType.Circle) UIUtils.SetLabel(v.txt_PowerNumber, UTL.Attr.CalculateFight(soulInfo.baseAttrList)) else v.obj_subState:SetState(1) end end end function UITreasureSoulCrystalAdvanced:OpenAttributeOverview() UIUtils.SetActive(self.group_AttributeOverview, true) for i, v in ipairs(self.img_AttributeOverviewBg) do -- 第一个默认为主御魂 if i == 1 then UIUtils.SetActive(v.gameObject, true) UTL.Item.ItemSquareIcon(v.img_SubSoulCrystalIcon, nil, self.soulData.CrystalID) UTL.Color.SetQualityImageByType(v.img_SubSoulCrystalQualityBg, self.soulData.Color, UTL.Color.QualityType.Circle) v.LoopScroll_SoulCrystalEquipTips:ReloadAll(self.soulInfo.baseAttrList) else local id = self.chooseSoulCrystalIDDic[i - 1] -- 从第二个开始是第一个副御魂 if id then UIUtils.SetActive(v.gameObject, true) local soulInfo = MDL.Treasure.GetSoulCrystalById(id) UTL.Item.ItemSquareIcon(v.img_SubSoulCrystalIcon, nil, soulInfo.soulData.CrystalID) UTL.Color.SetQualityImageByType(v.img_SubSoulCrystalQualityBg, soulInfo.soulData.Color, UTL.Color.QualityType.Circle) v.LoopScroll_SoulCrystalEquipTips:ReloadAll(soulInfo.baseAttrList) else UIUtils.SetActive(v.gameObject, false) end end end end function UITreasureSoulCrystalAdvanced:SoulCrystalIsChoose(id) for i, v in pairs(self.chooseSoulCrystalIDDic) do if v == id then return true, i end end return false end function UITreasureSoulCrystalAdvanced:OneChooseSoulCrystal() -- 先清空当前选择的 for k, v in pairs(self.chooseSoulCrystalIDDic) do self.chooseSoulCrystalIDDic[k] = nil end local index = 1 for _, v in MDL.Treasure.GetSoulCrystalIteratorByCrystalGroup(self.soulData.ColorUpConsume, false) do if (not v.equip) and v.id ~= self.soulInfo.id then self.chooseSoulCrystalIDDic[index] = v.id index = index + 1 if index > #self.group_SubSoulCrystal then break end end end self:RefreshSubSoulCrystal() end return UITreasureSoulCrystalAdvanced