local UIOneKeySweepView = UIViewClass() local SliderSensitivityParam = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("SliderSensitivityParam").FloatValue) local FastBattleItemID = DataSheetManager.ConstData:GetDataByID("FastBattleItemID").IntValue local LevelEnergyCost = 5 local FastSweepSpeed = 0 local NormalSweepSpeed = 0.6 function UIOneKeySweepView:OnOpened(context) self.itemTable = context self:RegistSystemEvent(EventID.UI_SweepItem_Refresh, self.OnSweepFubenRefresh) UIUtils.SetLabelText(self.UICommonPopUp.txt_Title, Const_IDS.IDS_HeroAdvanceNew_Hint_2) UIUtils.SetLabelText(self.lab_ClickStart, Const_IDS.IDS_HeroAdvanceNew_Hint_4) UIUtils.SetActive(self.lab_ClickStart, true) self:RefreshTargetItems() self.dragDict = {} self:SetPushStyle(LuaConst.PushStyleEnum.HIDE) UIUtils.SetActive(self.btn_ContinueSweep, false) UIUtils.SetActive(self.btn_OneKeySweep, true) UIUtils.SetActive(self.btn_OneKeyEquip, false) UIUtils.SetActive(self.btn_Quit, false) UIUtils.SetActive(self.mask_Skip, false) self:InitBtn() end function UIOneKeySweepView:InitBtn() local hasFastItem = UTL.Item.GetItemStockCount(FastBattleItemID) > 0 if hasFastItem then UIUtils.SetActive(self.btn_FastItemSweep, true) UIUtils.SetActive(self.btn_OneKeySweep, true) self.btn_OneKeySweep:SetText(Const_IDS.IDS_FastBattle_EnergySweep) self.btn_FastItemSweep:SetText(Const_IDS.IDS_FastBattle_FastBattleTokenSweep) else UIUtils.SetActive(self.btn_FastItemSweep, false) UIUtils.SetActive(self.btn_OneKeySweep, true) self.btn_OneKeySweep:SetText(Const_IDS.IDS_HeroAdvanceNew_Button_1) end end function UIOneKeySweepView:OnBackButtonPressed() self:OnButtonClicked(self.btn_Quit) end function UIOneKeySweepView:OnButtonClicked(comp) if comp == self.UICommonPopUp.btn_Close or comp == self.btn_Quit then self:CloseView() elseif comp == self.btn_OneKeyEquip then self:ClickEquipMaterial() elseif comp == self.mask_Skip then --self:SkipSweep() self:QuickMove() elseif comp == self.btn_OneKeySweep or comp == self.btn_ContinueSweep then self.useFastBattleItem = false self:ClickOneKeySweep() elseif comp == self.btn_FastItemSweep then self.useFastBattleItem = true self:ClickOneKeySweep() end end function UIOneKeySweepView:ClickOneKeySweep() if self.useFastBattleItem then self:ClickOneKeySweepByFastBattleItem() else self:ClickOneKeySweepByEnergy() end end function UIOneKeySweepView:ClickOneKeySweepByEnergy() if LevelEnergyCost > MDL.Player.GetEnergyValue() then UTL.ItemTips.OpenAboutEnergyPillView() return end if self:IsAllEnough() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_HeroAdvanceNew_Hint_1"]) else MDL.Sweep.SweepMultiItemReq(self.itemTable) end end function UIOneKeySweepView:ClickOneKeySweepByFastBattleItem() local remainCount = UTL.Item.GetItemStockCount(FastBattleItemID) if remainCount > 0 then MDL.Sweep.SweepMultiItemReq(self.itemTable, 0, true) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_FastBattle_NotEnough) end end function UIOneKeySweepView:ClickEquipMaterial() local heroId = MDL.HeroSelect.curSelectHeroID local indexTable = CTL.Advanced.IsMaterialEnough(heroId) if indexTable then MDL.Advanced.MaterialEquipRequest(heroId, indexTable) end self:CloseView() end function UIOneKeySweepView:RefreshTargetItems() if self.loop_SweepTarget.Count > 0 then self.loop_SweepTarget:ClearCells() end for i, v in ipairs(self.itemTable) do self.loop_SweepTarget:AddData(v, 0) end end function UIOneKeySweepView:OnSweepFubenRefresh(list, stopType) self.noEnergy = stopType == 1 UIUtils.SetActive(self.lab_ClickStart, false) UIUtils.SetActive(self.mask_Skip, true) self.btn_OneKeySweep:SetGray(true) self.btn_OneKeySweep:SetText(Const_IDS.IDS_HeroAdvanceNew_Hint_15) UIUtils.SetActive(self.btn_FastItemSweep, false) self.curList = list self.showIndex = 1 if #list == 1 and self.loop_OneKeySweep.Count == 0 then self:MoveShow() return end self.loop_OneKeySweep:ClearCells() self:StartRepeatFunc(self.OnUpdateFun, NormalSweepSpeed) end function UIOneKeySweepView:OnUpdateFun(deltaTime, timeSinceUpdate) self:MoveShow() end function UIOneKeySweepView:MoveShow() local data = self.curList[self.showIndex] if data then self.loop_OneKeySweep:AddData({itemData = data, showIndex = self.showIndex}, 0) self.showIndex = self.showIndex + 1 end if self.curList[self.showIndex] == nil then --计算所有道具的大合集 local totalData = CTL.Sweep.CalculateAllItemTable(self.curList) self.loop_OneKeySweep:AddData({itemData = totalData, showIndex = self.showIndex, isFinished = true}, 1) self.loop_OneKeySweep:MoveEnd() self:RefreshTargetItems() self:StopRepeatFunc(self.OnUpdateFun) UIUtils.SetActive(self.mask_Skip, false) UIUtils.SetActive(self.btn_OneKeySweep, false) self.btn_OneKeySweep:SetGray(false) self.btn_OneKeySweep:SetText(Const_IDS.IDS_HeroAdvanceNew_Button_1) local isHasEquip = self:IsHasEquip() UIUtils.SetActive(self.btn_OneKeyEquip, isHasEquip) UIUtils.SetActive(self.btn_Quit, not isHasEquip) UIUtils.SetActive(self.btn_FastItemSweep, not isHasEquip) UIUtils.SetActive(self.btn_ContinueSweep, self.noEnergy and not self:IsAllEnough()) if isHasEquip then UIUtils.SetActive(self.btn_FastItemSweep, false) else if self.useFastBattleItem then self.btn_ContinueSweep:SetText(Const_IDS.IDS_FastBattle_EnergySweep) UIUtils.SetActive(self.btn_FastItemSweep, true) else local remainCount = UTL.Item.GetItemStockCount(FastBattleItemID) if remainCount > 0 then UIUtils.SetActive(self.btn_FastItemSweep, true) self.btn_ContinueSweep:SetText(Const_IDS.IDS_FastBattle_EnergySweep) else UIUtils.SetActive(self.btn_FastItemSweep, false) self.btn_ContinueSweep:SetText(Const_IDS.IDS_HeroAdvanceNew_Button_3) end end end if isHasEquip then CTL.PlayerGuide.TryStartSweepEquipGuide() end end if self.showIndex > 2 then self.loop_OneKeySweep:MoveEnd() end end function UIOneKeySweepView:SkipSweep() self:StopRepeatFunc(self.OnUpdateFun) for i = self.showIndex, #self.curList do self.loop_OneKeySweep:AddData({itemData = self.curList[self.showIndex], showIndex = self.showIndex}, 0) self.showIndex = self.showIndex + 1 end self:MoveShow() end function UIOneKeySweepView:QuickMove() self:StopRepeatFunc(self.OnUpdateFun) self:StartRepeatFunc(self.OnUpdateFun, FastSweepSpeed) end function UIOneKeySweepView:IsAllEnough() for i, v in ipairs(self.itemTable) do local needCount = v.itemCount - MDL.Currency.GetSoftTokenCountById(v.itemId) if needCount > 0 then return false end end return true end function UIOneKeySweepView:IsHasEquip() for i, v in ipairs(self.itemTable) do local needCount = v.itemCount - MDL.Currency.GetSoftTokenCountById(v.itemId) if needCount <= 0 then return true end end return false end function UIOneKeySweepView:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_SweepTarget then local hasCount = MDL.Currency.GetSoftTokenCountById(data.itemId) if hasCount < data.itemCount then hasCount = UTL.Color.FormatRedColor(hasCount) else hasCount = UTL.Color.FormatGreenColor(hasCount) end UTL.Item.SetItemCell(cellTable.item, data.itemId, hasCount .. "/" .. data.itemCount) elseif scrollRect == self.loop_OneKeySweep then if data then if data.isFinished then local itemDatas = data.itemData for i, itemData in ipairs(itemDatas) do local contentItem = cellTable.Content[i] if not contentItem then contentItem = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, self.itemTemplate_Reward.gameObject) end UTL.Item.SetItemCell(contentItem.item, itemData.ItemId, itemData.ItemCount) if self:GetLevelIdByItemId(itemData.ItemId) then contentItem.effect_RequireItem:PlayUIEffect() else contentItem.effect_RequireItem:StopUIEffect() end UIUtils.SetActive(contentItem.gameObject, true) end for i = #itemDatas + 1, #cellTable.Content do UIUtils.SetActive(cellTable.Content[i].gameObject, false) end cellTable.effect_Finish:PlayUIEffect() CTL.Sound.PlayGameSound("UI_wipe_success") else local rewardDatas = data.itemData.RewardItem for i, rewardData in ipairs(rewardDatas) do local contentItem = cellTable.Content[i] if not contentItem then contentItem = self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, self.itemTemplate_Reward.gameObject) end UTL.Item.SetItemCell(contentItem.item, rewardData.ItemId, rewardData.ItemCount) local levelId = self:GetLevelIdByItemId(rewardData.ItemId) if levelId then cellTable.txt_Chapter.text = CTL.LevelSelect.GetLevelWholeNameById(levelId) contentItem.effect_RequireItem:PlayUIEffect() CTL.Sound.PlayGameSound("UI_wipe") else contentItem.effect_RequireItem:StopUIEffect() end UIUtils.SetActive(contentItem.gameObject, true) end for i = #rewardDatas + 1, #cellTable.Content do UIUtils.SetActive(cellTable.Content[i].gameObject, false) end cellTable.txt_Times.text = string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Sweep_Times), data.showIndex) self.loop_OneKeySweep:RegistTriggerEvent(cellTable.drag_Obj, UIEventTriggerType.BeginDrag, index) self.loop_OneKeySweep:RegistTriggerEvent(cellTable.drag_Obj, UIEventTriggerType.Drag, index) self.loop_OneKeySweep:RegistTriggerEvent(cellTable.drag_Obj, UIEventTriggerType.EndDrag, index) self.dragDict[cellTable.drag_Obj.gameObject] = cellTable.ItemScrollView.gameObject end end end end function UIOneKeySweepView:GetLevelIdByItemId(itemId) for i, v in ipairs(self.itemTable) do if v.itemId == itemId then return v.levelId end end return nil end function UIOneKeySweepView:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_OneKeySweep then for i,v in ipairs(cellTable.Content) do if v.item.event_Click == target then if data.isFinished then UTL.ItemTips.ShowCommonTipsById(data.itemData[i].ItemId) else UTL.ItemTips.ShowCommonTipsById(data.itemData.RewardItem[i].ItemId) end break end end elseif scrollRect == self.loop_SweepTarget then local heroId = MDL.HeroSelect.curSelectHeroID local advancedStep = MDL.Advanced.GetHeroAdvancedInfo(heroId) local advancedData = DataSheetManager.HeroAdvance:GetDataByAdvanceID(advancedStep) local itemData = advancedData.Item_Table[data.materialIndex] local materialAttr = MDL.Advanced.GetMaterialAttrTableById(heroId, advancedStep, data.materialIndex) UIManager.OpenView(Const_UI_Lua.UIEnum.UIHeroAdvancedMaterial, {materialAttr, itemData, data.materialIndex}) end end function UIOneKeySweepView:Cell_OnBeginDrag(scrollRect, index, comp, eventData) if math.abs(eventData.delta.x) > SliderSensitivityParam then self.curDragObj = self.dragDict[comp.gameObject] else self.curDragObj = self.loop_OneKeySweep.gameObject end UIUtils.ExecuteBeginDrag(self.curDragObj, eventData) end function UIOneKeySweepView:Cell_OnDrag(scrollRect, index, comp, eventData) UIUtils.ExecuteDrag(self.curDragObj, eventData) end function UIOneKeySweepView:Cell_OnEndDrag(scrollRect, index, comp, eventData) UIUtils.ExecuteEndDrag(self.curDragObj, eventData) end return UIOneKeySweepView