local UITreasureSoulCrystalRefinedPanel02 = 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 UITreasureSoulCrystalRefinedPanel02:OnOpened(context) self:RegistSystemEvent(EventID.TreasureSoulCrystal_UpdateRefined, self.OnTreasureRefined) self.treasureId = context.treasureId local equipDic = MDL.Treasure.GetEquipDicByTreasureId(self.treasureId) self.equipPosIndex = equipDic[context.id].PosIndex self.refineID = 0 self.curPowerNumber = 0 self.newPowerUp = false self.lockCurPowerPosDic = context.lockCurPowerPosDic self.curChooseIndex = 1 self:InitPanel() end function UITreasureSoulCrystalRefinedPanel02:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UITreasureSoulCrystalRefinedPanel02:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.btn_Refined then self:ClickRefined(MDL.Treasure.RefineType.Ten) elseif comp == self.btn_Replace then MDL.Treasure.TreasureSoulSlotAttrChooseReq(self.treasureId, self.equipPosIndex, true, self.curChooseIndex) elseif comp == self.btn_Coin 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 UITreasureSoulCrystalRefinedPanel02: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, CTL.Treasure.GetCostStr(TreasureSoulSource, v.ItemNum*10)) break elseif v.ItemID == TreasureSoulSpine then UTL.Item.SetItemCell(cellTable.item, TreasureSoulSpine, CTL.Treasure.GetCostStr(TreasureSoulSpine, v.ItemNum*10)) break end end elseif scrollRect == self.Loop_RefinedBefore then if data.state == MDL.Treasure.SoulSlotAttrState.NotValue then cellTable.obj_cellState:SetState(1) UIUtils.SetLabelText(cellTable.txt_AttributesName, Const_IDS.IDS_TreasureSoul_NextWash) UIUtils.SetActive(cellTable.uiScrollTxt_Attributes, false) 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]) local arrtibutesFirst = CTL.Treasure.GetQualityStrByPercentBlockId(str, data.percentBlockId) local arrtibutesSecond UIUtils.SetLabel(cellTable.txt_AttributesName, arrtibutesFirst) UIUtils.SetActive(cellTable.uiScrollTxt_Attributes, false) local refineAttrWeight = CTL.Treasure.GetRefineAttrWeight(data.refineID, data.attrType) if refineAttrWeight then str = string.format("%s/%s", data.attrValue, refineAttrWeight.AttrMaxNum) arrtibutesSecond = CTL.Treasure.GetQualityStrByPercentBlockId(str, data.percentBlockId) if GameAppInfo.IsJapanesePackage() then cellTable.uiScrollTxt_Attributes:SetText(string.format("%s%s", arrtibutesFirst, arrtibutesSecond)) UIUtils.SetActive(cellTable.txt_AttributesName, false) UIUtils.SetActive(cellTable.uiScrollTxt_Attributes, true) else UIUtils.SetLabel(cellTable.txt_Attributes, arrtibutesSecond) UIUtils.SetActive(cellTable.txt_AttributesName, true) UIUtils.SetActive(cellTable.uiScrollTxt_Attributes, false) end -- 百分比保留小数点后一位,保留方式 四舍五入 local percentage = (data.attrValue - refineAttrWeight.AttrMinNum) / (refineAttrWeight.AttrMaxNum - refineAttrWeight.AttrMinNum) UIUtils.SetLabel(cellTable.txt_Percentage, UTL.String.GetPercentFormatFloat(percentage*100, 1, 1)) UIUtils.SetAtlasImageFillAmount(cellTable.img_ProgressBar, percentage / 1) end cellTable.obj_lockState:SetState(self.lockCurPowerPosDic[data.index] and 1 or 0) end elseif scrollRect == self.loop_After then self:RefreshRefineAfter(cellTable,data, index) end end function UITreasureSoulCrystalRefinedPanel02:RefreshRefineAfter(cellTable, data, index) UIUtils.SetActive(cellTable.best_BG, index == 0) UIUtils.SetActive(cellTable.img_BG, index%2 == 0) for _, v in ipairs(cellTable.group_RefinedAfters) do UIUtils.SetActive(v.gameObject, false) end UIUtils.SetLabel(cellTable.txt_PowerNewNumber, data.totalAttr) if data.totalAttr ~= self.curPowerNumber then if data.totalAttr > self.curPowerNumber then cellTable.obj_CEChangeState:SetState(0) self.newPowerUp = true UIUtils.SetLabel(cellTable.txt_PowerChangeNumber, data.totalAttr - self.curPowerNumber) else cellTable.obj_CEChangeState:SetState(1) UIUtils.SetLabel(cellTable.txt_PowerChangeNumber, self.curPowerNumber - data.totalAttr) end else cellTable.obj_CEChangeState:SetState(2) end if self.newPowerUp then self.btn_Replace:SetRedPoint(true) end for i, v in ipairs(data.newSlotAttrDetail) do if v.state == MDL.Treasure.SoulSlotAttrState.Effective then UIUtils.SetActive(cellTable.group_RefinedAfters[i].gameObject, true) cellTable.group_RefinedAfters[i].obj_cellState:SetState(0) local attrData = DataSheetManager.AttrData:GetDataByID(v.attrType) local str = UIUtils.GetLocalizedTxt(Const_IDS[attrData.Name]) local arrtibutesFirst = CTL.Treasure.GetQualityStrByPercentBlockId(str, v.percentBlockId) local refineAttrWeight = CTL.Treasure.GetRefineAttrWeight(v.refineID, v.attrType) str = string.format("%s/%s", v.attrValue, refineAttrWeight.AttrMaxNum) local arrtibutesSecond = CTL.Treasure.GetQualityStrByPercentBlockId(str, v.percentBlockId) if GameAppInfo.IsJapanesePackage() then cellTable.group_RefinedAfters[i].uiScrollTxt_Attributes:SetText(string.format("%s%s", arrtibutesFirst, arrtibutesSecond)) UIUtils.SetActive(cellTable.group_RefinedAfters[i].txt_AttributesName, false) UIUtils.SetActive(cellTable.group_RefinedAfters[i].uiScrollTxt_Attributes, true) else UIUtils.SetLabel(cellTable.group_RefinedAfters[i].txt_AttributesName, arrtibutesFirst) UIUtils.SetLabel(cellTable.group_RefinedAfters[i].txt_Attributes, arrtibutesSecond) UIUtils.SetActive(cellTable.group_RefinedAfters[i].txt_AttributesName, true) UIUtils.SetActive(cellTable.group_RefinedAfters[i].uiScrollTxt_Attributes, false) end local percentage = (v.attrValue - refineAttrWeight.AttrMinNum) / (refineAttrWeight.AttrMaxNum - refineAttrWeight.AttrMinNum) UIUtils.SetLabel(cellTable.group_RefinedAfters[i].txt_Percentage, UTL.String.GetPercentFormatFloat(percentage*100, 0, 1)) UIUtils.SetAtlasImageFillAmount(cellTable.group_RefinedAfters[i].img_ProgressBar, percentage / 1) end end end function UITreasureSoulCrystalRefinedPanel02: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() EventSystem.Dispatch(EventID.TreasureSoulCrystal_UpdateMaterialSelect) 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 UITreasureSoulCrystalRefinedPanel02:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.loop_After then self.curChooseIndex = index end end function UITreasureSoulCrystalRefinedPanel02:InitPanel() 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() self:RefreshNewRefinedAttr() self:RefreshLockMaterial() end function UITreasureSoulCrystalRefinedPanel02:RefreshCurRefinedAttr() 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 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) end end self.curUnlockRule = DataSheetManager.TreasureSoulRefineRule:GetDataBySuffixNum(unlockCount) self.curPowerNumber = math.floor(self.curPowerNumber + 0.5) UIUtils.SetLabel(self.txt_PowerBeforeNumber, self.curPowerNumber) end function UITreasureSoulCrystalRefinedPanel02:OnTreasureRefined() self:RefreshItemCount() self:RefreshLockMaterial() self:RefreshCurRefinedAttr() self:RefreshNewRefinedAttr() end function UITreasureSoulCrystalRefinedPanel02:RefreshNewRefinedAttr() local treasureInfo = MDL.Treasure.GetTreasureInfo(self.treasureId) if not treasureInfo then return end self.newPowerUp = false self.btn_Replace:SetRedPoint(false) local soulSlotInfo = treasureInfo.TreasureInfo.soulSlotInfos[self.equipPosIndex] local titleStr = string.FormatByIdsId(Const_IDS.IDS_TreasureSoul_NewWashHint_3, #soulSlotInfo.newSlotAttrs) UIUtils.SetLabel(self.lab_RefinedInfo,titleStr) self.loop_After:ReloadAll(soulSlotInfo.newSlotAttrs) if #soulSlotInfo.newSlotAttrs > 0 then self.loop_After:SelectIndex(0) end end function UITreasureSoulCrystalRefinedPanel02: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*10)) else UIUtils.SetActive(self.group_Lock, false) end for i = 1, self.scroll_MaterialList.Count do self.scroll_MaterialList:UpdateIndex(i - 1) end end function UITreasureSoulCrystalRefinedPanel02: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*10 then UIUtils.SetLabel(self.txt_CoinNum, UTL.Color.FormatRedColor(coinCost.ItemNum*10)) else UIUtils.SetLabel(self.txt_CoinNum, UTL.Color.FormatGreenColor(coinCost.ItemNum*10)) end end -- 点击洗练判断 function UITreasureSoulCrystalRefinedPanel02: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, self.curChooseIndex) 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 UITreasureSoulCrystalRefinedPanel02: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] return slot.state == MDL.Treasure.SoulSlotAttrState.NotValue end function UITreasureSoulCrystalRefinedPanel02:OnClosed() EventSystem.Dispatch(EventID.TreasureSoulCrystal_UpdateRefinedLock, self.lockCurPowerPosDic) end return UITreasureSoulCrystalRefinedPanel02