local UITreasureSoulCrystalRefinedPanel = UIViewClass() local RefinedHintTime = "UITreasureSoulCrystalRefinedPanel_RefinedHintTime" local EventSystem = require('Event/EventSystem') local TreasureSoulSource = DataSheetManager.ConstData:GetDataByID("TreasureSoulSource").IntValue -- 普通洗练材料 local TreasureSoulSpine = DataSheetManager.ConstData:GetDataByID("TreasureSoulSpine").IntValue -- 高级洗练材料 local TreasureSoulSpell = DataSheetManager.ConstData:GetDataByID("TreasureSoulSpell").IntValue -- 洗练锁定材料 -------------------- --[[ 参数说明 treasureId ——> 表示当前选中的宝物id id ——> 服务器存储魂晶唯一id --]] function UITreasureSoulCrystalRefinedPanel:OnOpened(context) self:RegistSystemEvent(EventID.TreasureSoulCrystal_UpdateRefined, self.OnTreasureRefined) self:RegistSystemEvent(EventID.TreasureSoulCrystal_UpdateRefinedLock, self.OnTreasureRefineLockUpdata) self:RegistSystemEvent(EventID.TreasureSoulCrystal_UpdateMaterialSelect, self.OnUpdateMaterialSelect) self.treasureId = context.treasureId self.soulInfo = MDL.Treasure.GetSoulCrystalById(context.id) local equipDic = MDL.Treasure.GetEquipDicByTreasureId(self.treasureId) self.equipPosIndex = equipDic[context.id].PosIndex self.refineID = 0 self.curUnlockRule = nil self.curPowerNumber = 0 self.newPowerUp = false self.lockCurPowerPosDic = {} self:InitPanel() end function UITreasureSoulCrystalRefinedPanel:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UITreasureSoulCrystalRefinedPanel:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Refined then self:ClickRefined(MDL.Treasure.RefineType.Once) elseif comp == self.btn_Refined_Ten then self:ClickRefined(MDL.Treasure.RefineType.Ten) elseif comp == self.btn_Result then UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSoulCrystalRefinedPanel02, {treasureId = self.treasureId, id = self.soulInfo.id, lockCurPowerPosDic = self.lockCurPowerPosDic}) elseif comp == self.btn_Reserve then if self.newPowerUp then UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_TreasureSoul_ReplaceConfirm3, nil, function() MDL.Treasure.TreasureSoulSlotAttrChooseReq(self.treasureId, self.equipPosIndex, false) end, Const_IDS.IDS_BUTTON_CANCEL, Const_IDS.IDS_GuildBoss_ButtonContinue) else MDL.Treasure.TreasureSoulSlotAttrChooseReq(self.treasureId, self.equipPosIndex, false) end elseif comp == self.btn_ReplaceOne or comp == self.btn_Replace then MDL.Treasure.TreasureSoulSlotAttrChooseReq(self.treasureId, self.equipPosIndex, true) elseif comp == self.btn_Coin or comp == self.btn_Coin_Ten then local refineItem = DataSheetManager.TreasureSoulRefineItem:GetDataByRefineID_LockNum(self.refineID, table.getDictCount(self.lockCurPowerPosDic)) if refineItem then local coinCost = refineItem.Item_Table[1] -- 与策划协定潜规则 消耗表里默认第一个为货币消耗 UTL.ItemTips.ShowCommonTipsById(coinCost.ItemID) end elseif comp == self.lockItem.event_Click then UTL.ItemTips.ShowCommonTipsById(TreasureSoulSpell) end end function UITreasureSoulCrystalRefinedPanel:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.scroll_MaterialList then local itemList = DataSheetManager.TreasureSoulRefineItem:GetDataByRefineID_LockNum(data.RefineID, table.getDictCount(self.lockCurPowerPosDic)) for _, v in ipairs(itemList.Item_Table) do if v.ItemID == TreasureSoulSource then UTL.Item.SetItemCell(cellTable.item, TreasureSoulSource) -- 设置消耗数量 UIUtils.SetActive(cellTable.item.group_Count, true) UIUtils.SetLabel(cellTable.item.lab_Count, CTL.Treasure.GetCostStr(TreasureSoulSource, v.ItemNum)) break elseif v.ItemID == TreasureSoulSpine then UTL.Item.SetItemCell(cellTable.item, TreasureSoulSpine) -- 设置消耗数量 UIUtils.SetActive(cellTable.item.group_Count, true) UIUtils.SetLabel(cellTable.item.lab_Count, CTL.Treasure.GetCostStr(TreasureSoulSpine, v.ItemNum)) break end end elseif scrollRect == self.Loop_RefinedBefore or scrollRect == self.Loop_RefinedAfter then if data.state == MDL.Treasure.SoulSlotAttrState.NotValue then cellTable.obj_cellState:SetState(1) UIUtils.SetLabelText(cellTable.txt_AttributesName, Const_IDS.IDS_TreasureSoul_NextWash) if self:IsNewAttr(index) then cellTable.effect_EmptyLight:PlayUIEffect() else cellTable.effect_EmptyLight:StopUIEffect() end elseif data.state == MDL.Treasure.SoulSlotAttrState.Effective then cellTable.effect_EmptyLight:StopUIEffect() 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 if scrollRect == self.Loop_RefinedBefore then -- 设置是否锁定 cellTable.obj_lockState:SetState(self.lockCurPowerPosDic[data.index] and 1 or 0) end end end end function UITreasureSoulCrystalRefinedPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.Loop_RefinedBefore then if target == cellTable.btn_Lock then if self.lockCurPowerPosDic[data.index] then self.lockCurPowerPosDic[data.index] = nil cellTable.obj_lockState:SetState(0) else if self.curUnlockRule then if table.getDictCount(self.lockCurPowerPosDic) < self.curUnlockRule.LockableNum then self.lockCurPowerPosDic[data.index] = 1 -- 这个1仅仅起占位作用,没有实际意义 cellTable.obj_lockState:SetState(1) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_TreasureSoul_LockedMax) end end end -- 刷新材料数量 self:RefreshLockMaterial() -- 刷新货币 self:RefreshItemCount() end elseif scrollRect == self.scroll_MaterialList then if self.refineID ~= data.RefineID then self.refineID = data.RefineID CTL.Treasure.SetLastSelectRefinedMaterialIndex(index) -- 刷新货币 self:RefreshItemCount() else local itemList = DataSheetManager.TreasureSoulRefineItem:GetDataByRefineID_LockNum(data.RefineID, table.getDictCount(self.lockCurPowerPosDic)) for _, v in ipairs(itemList.Item_Table) do if v.ItemID == TreasureSoulSource then UTL.ItemTips.ShowCommonTipsById(TreasureSoulSource) break elseif v.ItemID == TreasureSoulSpine then UTL.ItemTips.ShowCommonTipsById(TreasureSoulSpine) break end end end end end -------------------- function UITreasureSoulCrystalRefinedPanel:InitPanel() -- 设置标题 UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_TreasureSoul_XiLian) -- 设置魂晶图标 UTL.Item.ItemSquareIcon(self.img_SoulCrystalIcon, nil, self.soulInfo.cfgId) UTL.Color.SetQualityImageByType(self.img_SoulCrystalBg, self.soulInfo.soulData.Color, UTL.Color.QualityType.Circle) -- 设置魂晶名称 UIUtils.SetLabel(self.txt_SoulCrystalName, UTL.Item.GetItemColorName(self.soulInfo.cfgId)) -- 设置魂晶魂属 UIUtils.SetLabel(self.txt_SoulCrystalAttributes, string.FormatByIdsId(Const_IDS.IDS_TreasureSoul_HunShu, CTL.Treasure.GetSoulCrystalTypeName(self.soulInfo.soulData.CrystalType))) -- 初始化精炼材料 if self.scroll_MaterialList.Count > 0 then self.scroll_MaterialList:ClearCells() end for _, v in DataSheetManager.TreasureSoulRefineAttrWeight:GetEnumerator() do self.scroll_MaterialList:AddData(v, 0) end self.scroll_MaterialList:SelectIndex(CTL.Treasure.GetLastSelectRefinedMaterialIndex()) -- 初始化锁定消耗材料 UTL.Item.SetItemCell(self.lockItem, TreasureSoulSpell) -- 初始化当前属性 self:RefreshCurRefinedAttr(true) -- 初始化洗练属性 self:RefreshNewRefinedAttr() -- 计算锁定材料消耗数量 self:RefreshLockMaterial() end function UITreasureSoulCrystalRefinedPanel:RefreshCurRefinedAttr(init) local treasureInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) if not treasureInfo then return end local soulSlotInfo = treasureInfo.TreasureInfo.soulSlotInfos[self.equipPosIndex] if self.Loop_RefinedBefore.Count > 0 then self.Loop_RefinedBefore:ClearCells() end local unlockCount = 0 self.curPowerNumber = 0 -- 当前属性总战力 local unlockPower = false for _, v in ipairs(soulSlotInfo.slotAttrs) do self.Loop_RefinedBefore:AddData(v, 0) if v.state ~= MDL.Treasure.SoulSlotAttrState.NotOpen then unlockCount = unlockCount + 1 end -- 只有有属性的才需要计算战斗力 if v.state == MDL.Treasure.SoulSlotAttrState.Effective then self.curPowerNumber = self.curPowerNumber + UTL.Attr.CalculateSingleFight(v.attrType, v.attrValue) elseif v.state == MDL.Treasure.SoulSlotAttrState.NotValue then unlockPower = true end end -- 提示解锁属性 if unlockPower and not init then CTL.Tips.AddTipsMsg(Const_IDS.IDS_TreasureSoul_WashPromotion3) end -- 设置提示信息 self.curUnlockRule = DataSheetManager.TreasureSoulRefineRule:GetDataBySuffixNum(unlockCount) if self.curUnlockRule.UnlockPencen > 0 then UIUtils.SetActive(self.lab_RefinedBeforeInfo, true) UIUtils.SetLabel(self.lab_RefinedBeforeInfo, string.FormatByIdsId(Const_IDS.IDS_TreasureSoul_WashPromotion2, self.curUnlockRule.UnlockPencen * 100)) else UIUtils.SetActive(self.lab_RefinedBeforeInfo, false) end -- 设置当前战斗力 self.curPowerNumber = math.floor(self.curPowerNumber + 0.5) UIUtils.SetLabel(self.txt_PowerBeforeNumber, self.curPowerNumber) end function UITreasureSoulCrystalRefinedPanel:OnTreasureRefined(refineType) if refineType and refineType == MDL.Treasure.RefineType.Ten then -- 打开10条精炼界面 if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UITreasureSoulCrystalRefinedPanel02) then UIManager.OpenView(Const_UI_Lua.UIEnum.UITreasureSoulCrystalRefinedPanel02, {treasureId = self.treasureId, id = self.soulInfo.id, lockCurPowerPosDic = self.lockCurPowerPosDic}) end end self:RefreshItemCount() self:RefreshLockMaterial() self:RefreshCurRefinedAttr() self:RefreshNewRefinedAttr() end function UITreasureSoulCrystalRefinedPanel:OnTreasureRefineLockUpdata(lockCurPowerPosDic) self.lockCurPowerPosDic = lockCurPowerPosDic self:RefreshItemCount() self:RefreshLockMaterial() self.Loop_RefinedBefore:RefreshCells() end function UITreasureSoulCrystalRefinedPanel:OnUpdateMaterialSelect() self.scroll_MaterialList:SelectIndex(CTL.Treasure.GetLastSelectRefinedMaterialIndex()) self:RefreshItemCount() end function UITreasureSoulCrystalRefinedPanel:RefreshNewRefinedAttr() local treasureInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) if not treasureInfo then return end self.newPowerUp = false local soulSlotInfo = treasureInfo.TreasureInfo.soulSlotInfos[self.equipPosIndex] if soulSlotInfo.newSlotAttrs == nil or #soulSlotInfo.newSlotAttrs == 0 then -- 表示没有新的洗练属性 self.obj_RefinedState:SetState(0) else self.obj_RefinedState:SetState(soulSlotInfo.lastRefineType == MDL.Treasure.RefineType.Once and 1 or 2) if self.Loop_RefinedAfter.Count > 0 then self.Loop_RefinedAfter:ClearCells() end local newSlotAttrs = soulSlotInfo.newSlotAttrs[1] local newPowerNumber = 0 -- 新属性总战力 for _, v in ipairs(newSlotAttrs.newSlotAttrDetail) do if v.state == MDL.Treasure.SoulSlotAttrState.Effective then self.Loop_RefinedAfter:AddData(v, 0) newPowerNumber = newPowerNumber + UTL.Attr.CalculateSingleFight(v.attrType, v.attrValue) end end -- 设置当前战斗力 newPowerNumber = math.floor(newPowerNumber + 0.5) UIUtils.SetLabel(self.txt_PowerNewNumber, newPowerNumber) -- 设置战力差 if newPowerNumber ~= self.curPowerNumber then if newPowerNumber > self.curPowerNumber then self.obj_CEChangeState:SetState(0) self.newPowerUp = true UIUtils.SetLabel(self.txt_PowerChangeNumber, newPowerNumber - self.curPowerNumber) else self.obj_CEChangeState:SetState(1) UIUtils.SetLabel(self.txt_PowerChangeNumber, self.curPowerNumber - newPowerNumber) end else self.obj_CEChangeState:SetState(2) end self.btn_ReplaceOne:SetRedPoint(self.newPowerUp) self.btn_Replace:SetRedPoint(self.newPowerUp) end end function UITreasureSoulCrystalRefinedPanel:RefreshLockMaterial() -- 锁定消耗 local lockNum = table.getDictCount(self.lockCurPowerPosDic) local refineItem = DataSheetManager.TreasureSoulRefineItem:GetDataByRefineID_LockNum(self.refineID, lockNum) if lockNum > 0 then UIUtils.SetActive(self.group_Lock, true) local needItemNum = 0 for _, material in ipairs(refineItem.Item_Table) do if material.ItemID == TreasureSoulSpell then needItemNum = material.ItemNum break end end UIUtils.SetActive(self.lockItem.group_Count, true) UIUtils.SetLabel(self.lockItem.lab_Count, CTL.Treasure.GetCostStr(TreasureSoulSpell, needItemNum)) else UIUtils.SetActive(self.group_Lock, false) end -- 设置洗练道具消耗 for i = 1, self.scroll_MaterialList.Count do self.scroll_MaterialList:UpdateIndex(i - 1) -- c# 从0开始 end end function UITreasureSoulCrystalRefinedPanel:RefreshItemCount() -- 锁定消耗 local lockNum = table.getDictCount(self.lockCurPowerPosDic) local refineItem = DataSheetManager.TreasureSoulRefineItem:GetDataByRefineID_LockNum(self.refineID, lockNum) -- 设置货币消耗 local coinCost = refineItem.Item_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 if ownItemCount < coinCost.ItemNum*10 then UIUtils.SetLabel(self.txt_CoinNum_Ten, UTL.Color.FormatRedColor(coinCost.ItemNum*10)) else UIUtils.SetLabel(self.txt_CoinNum_Ten, UTL.Color.FormatGreenColor(coinCost.ItemNum*10)) end end -- 点击洗练判断 function UITreasureSoulCrystalRefinedPanel:ClickRefined(refineType) if self.refineID == 0 then return end if self.newPowerUp then local refinedHintTime = PersistentData.PlayerData:Get(RefinedHintTime, 0) -- 获取上一次本地保存的提示时间 if UTL.Time.IsTimestampSameDay(refinedHintTime) then MDL.Treasure.TreasureSoulSlotRefreshReq(self.treasureId, self.equipPosIndex, self.lockCurPowerPosDic, self.refineID, refineType) else UTL.MessageBox.ShowOKCancelToggleBox(nil, Const_IDS.IDS_TreasureSoul_ReplaceConfirm, UIUtils.GetLocalizedTxt(Const_IDS.IDS_WarZoneAuction_27), function() MDL.Treasure.TreasureSoulSlotAttrChooseReq(self.treasureId, self.equipPosIndex, true) end, function(isOn) if isOn then PersistentData.PlayerData:Set(RefinedHintTime, UTL.Time.GetServerTimestamp(), true) else PersistentData.PlayerData:Set(RefinedHintTime, refinedHintTime, true) end end, function() MDL.Treasure.TreasureSoulSlotRefreshReq(self.treasureId, self.equipPosIndex, self.lockCurPowerPosDic, self.refineID, refineType) end, Const_IDS.IDS_TreasureSoul_Replace, Const_IDS.IDS_GuildBoss_ButtonContinue) end else MDL.Treasure.TreasureSoulSlotRefreshReq(self.treasureId, self.equipPosIndex, self.lockCurPowerPosDic, self.refineID, refineType) end end function UITreasureSoulCrystalRefinedPanel:IsNewAttr(index) local treasureInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) local soulSlotInfo = treasureInfo.TreasureInfo.soulSlotInfos[self.equipPosIndex] if soulSlotInfo.newSlotAttrs == nil or #soulSlotInfo.newSlotAttrs == 0 then return false end local slot = soulSlotInfo.newSlotAttrs[1].newSlotAttrDetail[index + 1] -- c#从0开始 return slot.state == MDL.Treasure.SoulSlotAttrState.NotValue end function UITreasureSoulCrystalRefinedPanel:OnClosed() EventSystem.Dispatch(EventID.BagItem_Update) EventSystem.Dispatch(EventID.UI_RefreshCurrency) CTL.Treasure.SetLastSelectRefinedMaterialIndex(0) end return UITreasureSoulCrystalRefinedPanel