local UIEquipmentRefinePopUp = UIViewClass() local EventSystem = require('Event/EventSystem') local EMPTY_ATTR_TYPE = 0 local QUALITY_WARN_RED = 5 function UIEquipmentRefinePopUp:OnOpened(context) self.unableClickTypes = {} self.clickLeftAttrType = nil --选中的左边词条 self.clickRightAttrType = nil --选中的右边词条 self.selectEmptyIndex = nil --空词条类型都为0,加个标识表明选中第几个空词条 self.needPlayEffect = false self:RegistSystemEvent(EventID.UI_Refine_Success, self.OnRefineSuccess) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS["IDS_EquipRefine_Button"]) UIUtils.SetActive(self.UICommonPopUp.group_Tab, false) UIUtils.SetActive(self.UICommonPopUp.img_Info, true) local leftInfo = self.context.equippedEquipInfo local rightInfo = self.context.tarEquipInfo local heroId = MDL.Equipment.GetEquipHeroId(leftInfo.ID) self:InitEquipAttr(self.Panel_ItemLeft, leftInfo, heroId) self:InitEquipAttr(self.Panel_ItemRight, rightInfo) self:UpdateCost() end function UIEquipmentRefinePopUp:OnClosed() UIUtils.SetActive(self.UICommonPopUp.img_Info, false) end function UIEquipmentRefinePopUp:InitEquipAttr(comps, info, heroId) if heroId then UTL.Item.SetHeroIconByHeroId(comps.img_PlayerHead, heroId, MDL.HeroAwaken.GetIsHeroAwaken(heroId)) end local itemData = info.ItemData local color = itemData.Color UTL.Color.SetQualityImageByType(comps.img_ItemInfoBg, color, UTL.Color.QualityType.EquipFragmentComposeBase) UTL.Color.SetQualityImageByType(comps.img_ItemInfoBg2, color, UTL.Color.QualityType.EquipRefineIcon) UTL.Item.SetItemCell(comps.ItemBase, itemData.ID) comps.txt_ItemName.text = UTL.Color.FormatQualityText(UIUtils.GetLocalizedTxt(Const_IDS[itemData.Name]), color) self:UpdateAttrCell(comps.loop_EquipAttr, info) end function UIEquipmentRefinePopUp:OnResetRefine() table.clear(self.unableClickTypes) self.clickLeftAttrType = nil self.clickRightAttrType = nil self.selectEmptyIndex = nil self:UpdateInfo(true, true) end function UIEquipmentRefinePopUp:OnRefineSuccess() local lastAttrType = self.clickRightAttrType self:OnResetRefine() self.needPlayEffect = true local cellIndex, data = self:GetLeftCellData(lastAttrType) if cellIndex then self.Panel_ItemLeft.loop_EquipAttr:UpdateIndex(cellIndex, data) end end function UIEquipmentRefinePopUp:UpdateInfo(isLeft, isRight) if isLeft then local leftInfo = self.context.equippedEquipInfo self:UpdateAttrCell(self.Panel_ItemLeft.loop_EquipAttr, leftInfo) end if isRight then local rightInfo = self.context.tarEquipInfo self:UpdateAttrCell(self.Panel_ItemRight.loop_EquipAttr, rightInfo) end self:UpdateCost() end function UIEquipmentRefinePopUp:UpdateAttrCell(loopScroll, info) local refineMaxNum = info.EquipData.MaxRefineNum MDL.Equipment.SetEquipAttrIteratorData(info.RefineAttrs, EMPTY_ATTR_TYPE, refineMaxNum) CSExt.CSFunc_ReloadAll(loopScroll, MDL.Equipment.EnumEquipAttrIterator) end function UIEquipmentRefinePopUp:GetLeftCellData(attrType) local info = self.context.equippedEquipInfo local refineNum = info.RefineAttrs and #info.RefineAttrs or 0 if attrType == EMPTY_ATTR_TYPE then --选中空词条 return refineNum, EMPTY_ATTR_TYPE end for i = 1, refineNum do if info.RefineAttrs[i].AttrType == attrType then return i - 1, info.RefineAttrs[i] end end logging.error(LTAG.ERROR, "GetLeftCellIndex Fail", attrType, info.RefineAttrs) end function UIEquipmentRefinePopUp:OnCellInit(scrollRect, index, cellTable, data) UIUtils.SetActive(cellTable.group_Mark, true) local isEmpty = data == EMPTY_ATTR_TYPE if isEmpty then cellTable.state_empty:SetState(0) else cellTable.state_empty:SetState(1) local quality if scrollRect == self.Panel_ItemLeft.loop_EquipAttr then quality = CTL.Equipment.GetRefineAttrQuality(self.context.equippedEquipInfo.EquipData.RefineID, data) else quality = CTL.Equipment.GetRefineAttrQuality(self.context.tarEquipInfo.EquipData.RefineID, data) end local attrName = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.AttrData:GetDataByID(data.AttrType).Name]) cellTable.txt_EquipAttrTitle.text = UTL.Color.FormatQualityText(attrName, quality) cellTable.txt_EquipAttrNum.text = UTL.Color.FormatQualityText(data.AttrNum, quality) end if scrollRect == self.Panel_ItemLeft.loop_EquipAttr then if isEmpty then UIUtils.SetActive(cellTable.img_NotActive, self.unableClickTypes[EMPTY_ATTR_TYPE] == true) if self.clickLeftAttrType and self.clickLeftAttrType == EMPTY_ATTR_TYPE and (self.selectEmptyIndex == nil or self.selectEmptyIndex == index) then cellTable.state_select:SetState(1) --默认选中第一个空词条 self.selectEmptyIndex = index else cellTable.state_select:SetState(0) end else UIUtils.SetActive(cellTable.img_NotActive, self.unableClickTypes[data.AttrType] == true) if self.clickLeftAttrType and self.clickLeftAttrType == data.AttrType then cellTable.state_select:SetState(1) else cellTable.state_select:SetState(0) end end else if isEmpty then UIUtils.SetActive(cellTable.img_NotActive, true) cellTable.state_select:SetState(0) --右侧的空词条不显示勾选框 UIUtils.SetActive(cellTable.group_Mark, false) else UIUtils.SetActive(cellTable.img_NotActive, false) if self.clickRightAttrType and self.clickRightAttrType == data.AttrType then cellTable.state_select:SetState(1) else cellTable.state_select:SetState(0) end end end if self.needPlayEffect then cellTable.effect_refine:PlayUIEffect() self.needPlayEffect = false end end function UIEquipmentRefinePopUp:OnCellClicked(scrollRect, index, cellTable, target, data) if self.clickRightAttrType == nil and scrollRect == self.Panel_ItemLeft.loop_EquipAttr then --无选中 CTL.Tips.AddTipsMsg(Const_IDS["IDS_EquipRefine_WrongHint4"]) else if scrollRect == self.Panel_ItemRight.loop_EquipAttr then if data ~= EMPTY_ATTR_TYPE then self.clickRightAttrType = data.AttrType self:UpdateClickType() end else local isEmpty = data == EMPTY_ATTR_TYPE if isEmpty and self.unableClickTypes[EMPTY_ATTR_TYPE] == true then CTL.Tips.AddTipsMsg(Const_IDS["IDS_EquipRefine_WrongHint5"]) return end if isEmpty == false and self.unableClickTypes[data.AttrType] then CTL.Tips.AddTipsMsg(Const_IDS["IDS_EquipRefine_WrongHint5"]) return end self.clickLeftAttrType = isEmpty and EMPTY_ATTR_TYPE or data.AttrType self.selectEmptyIndex = isEmpty and index self:UpdateInfo(true, false) end end end function UIEquipmentRefinePopUp:UpdateClickType() if self.clickRightAttrType == nil then return end table.clear(self.unableClickTypes) self.selectEmptyIndex = nil local isSame = false local refineAttr = self.context.equippedEquipInfo.RefineAttrs if refineAttr then for _, attr in ipairs(refineAttr) do if attr.AttrType == self.clickRightAttrType then isSame = true break end end end if isSame then --与选中项有相同属性,默认选中同属性且其他属性不可选 self.clickLeftAttrType = self.clickRightAttrType for _, attr in ipairs(refineAttr) do if attr.AttrType ~= self.clickRightAttrType then self.unableClickTypes[attr.AttrType] = true end end self.unableClickTypes[EMPTY_ATTR_TYPE] = true else --与选中项没有相同属性,默认选中空词条 local isEmpty = CTL.Equipment.GetIfRefineAttrEmpty(self.context.equippedEquipInfo) if isEmpty then self.clickLeftAttrType = EMPTY_ATTR_TYPE else self.clickLeftAttrType = nil end end self:UpdateInfo(true, true) end local SILVERCOIN_ICON_PATH = "Dynamic/Item/icon_dj_tb" function UIEquipmentRefinePopUp:UpdateCost() local flag, code = self:GetIfRefineCode() if flag == false then self.btn_Refine:SetGray(code == Const_IDS["IDS_EquipRefine_WrongHint3"], true) UIUtils.SetLabelText(self.txt_Btn, Const_IDS["IDS_EquipRefine_Button"]) return end self.btn_Refine:SetGray(false) local leftInfo = self.context.equippedEquipInfo local rightInfo = self.context.tarEquipInfo local itemId = leftInfo.EquipData.RefineItem local itemNum = rightInfo.EquipData.RefineItemNum local moneyVal = MDL.Currency.IsMoneyEnough(itemId, itemNum) and itemNum or UTL.Color.FormatRedColor(itemNum) self.txt_Btn.text = UIUtils.GetLocalizedTxt(Const_IDS["IDS_EquipRefine_Button"]) .. UTL.Item.GetImageAndText(SILVERCOIN_ICON_PATH, 1.5, moneyVal) end function UIEquipmentRefinePopUp:GetIfRefineCode() if self.clickRightAttrType == nil or self.clickLeftAttrType == nil then return false, Const_IDS["IDS_EquipRefine_WrongHint3"] end if self.clickRightAttrType == self.clickLeftAttrType then local leftInfo = self.context.equippedEquipInfo local rightInfo = self.context.tarEquipInfo --左边比右边的属性小时,不允许洗炼 local leftAttrValue for _, attr in ipairs(leftInfo.RefineAttrs) do if attr.AttrType == self.clickLeftAttrType then leftAttrValue = attr.AttrNum break end end local rightAttrValue for _, attr in ipairs(rightInfo.RefineAttrs) do if attr.AttrType == self.clickRightAttrType then rightAttrValue = attr.AttrNum break end end if rightAttrValue <= leftAttrValue then return false, Const_IDS["IDS_EquipRefine_NoBetterAttr"] end end return true end function UIEquipmentRefinePopUp:OnBackButtonPressed() self:OnButtonClicked(self.UICommonPopUp.btn_Close) end function UIEquipmentRefinePopUp:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close then self:CloseView() EventSystem.Dispatch(EventID.UI_UpdateEquipmentInfo) elseif comp == self.UICommonPopUp.img_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.EquipRefine }) elseif comp == self.btn_Refine then local flag, code = self:GetIfRefineCode() if flag == false then CTL.Tips.AddTipsMsg(code) return end if self.clickLeftAttrType ~= EMPTY_ATTR_TYPE then --左边的高品质加提示窗 local leftInfo = self.context.equippedEquipInfo local leftAttrData for _, attr in ipairs(leftInfo.RefineAttrs) do if attr.AttrType == self.clickLeftAttrType then leftAttrData = attr break end end local quality = CTL.Equipment.GetRefineAttrQuality(leftInfo.EquipData.RefineID, leftAttrData) if quality >= QUALITY_WARN_RED then local content = quality == QUALITY_WARN_RED and Const_IDS.IDS_EquipRefine_RedAttrWarn or Const_IDS.IDS_EquipRefine_GoldenAttrWarn UTL.MessageBox.ShowOKCancelBox(nil, content, function() MDL.Equipment.EquipRefineReq(self.context.equippedEquipInfo.ID, self.clickLeftAttrType, self.context.tarEquipInfo.ID, self.clickRightAttrType) end, nil) return end end MDL.Equipment.EquipRefineReq(self.context.equippedEquipInfo.ID, self.clickLeftAttrType, self.context.tarEquipInfo.ID, self.clickRightAttrType) end end return UIEquipmentRefinePopUp