local UIOnlineReward = UIViewClass() local RewardCollectAnimationLoop = DataSheetManager.ConstData:GetDataByID("OnlineDialCartoon1").IntValue local NormalGapTime = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("OnlineDialCartoon2").FloatValue) local GapTimeList = DataSheetManager.ConstData:GetDataByID("OnlineDialCartoon3").IntListValue local FlashHoldTime = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("OnlineDialCartoon5").FloatValue) local FlashGapTime = FP.tonumberV1(DataSheetManager.ConstData:GetDataByID("OnlineDialCartoon6").FloatValue) local FlashTimes = DataSheetManager.ConstData:GetDataByID("OnlineDialCartoon4").IntValue local EventSystem = require('Event/EventSystem') local MilliCoefficient = 1000 function UIOnlineReward:OnOpened(context) self:RegistSystemEvent(EventID.UI_OnlineReward_Start, self.ShowRewardCollectAnimation) self:RegistSystemEvent(EventID.UI_OnlineReward_Refresh, self.RefreshPanel) self.allowClose = true --抽奖动画期间不允许关闭界面 self:RefreshPanel() UIUtils.SetLabelText(self.txt_CanCollect, Const_IDS.IDS_OnlineDial_Hint_4) if self.localization.CurState == 0 then UIUtils.SetLocalizationImage(self.img_TreasureBox, "mbzx_msz_01.png") end end function UIOnlineReward:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIOnlineReward:OnButtonClicked(comp) if comp == self.btn_Collect then self:OnClickCollect() elseif comp == self.btn_Close then if self.allowClose then self:CloseView() end else for i, v in ipairs(self.group_Items) do if comp == v.Item.event_Click then UTL.ItemTips.ShowCommonTipsById(DataSheetManager.OnlineDialSortOrder:GetDataByOrderID(i).ItemID) end end end end function UIOnlineReward:OnClickCollect() if CTL.OnlineReward.IsCanCollect() then CTL.Sound.PlayGameSound("UI_open") MDL.OnlineReward.StartRewardReq() else CTL.Sound.PlayGameSound("UI_invalid") CTL.Tips.AddTipsMsg(Const_IDS["IDS_OnlineDial_Hint_7"]) end end function UIOnlineReward:CheckIfClose() if CTL.OnlineReward.IsRewardFinished() then self:CloseView() EventSystem.Dispatch(EventID.UI_WelfareBase_RefreshEventList) end end function UIOnlineReward:RefreshPanel() self:CheckIfClose() self:RefreshItems() self:RefreshTime() end ---刷新按钮倒计时 function UIOnlineReward:RefreshTime() if self.allowClose then self.btn_Collect:SetText(Const_IDS.IDS_OnlineDial_Hint_2) self.btn_Collect:SetGray(false) local leftTime = MDL.OnlineReward.GetLeftTime() self.txt_NextChance:ResetAndBeginCustomTimer(false, leftTime, 0, UIUtils.GetLocalizedTxt(Const_IDS["IDS_OnlineDial_Hint_3"]), 1) if leftTime <= 0 then self.effect_ButtonSparks:PlayUIEffect() else self.effect_ButtonSparks:StopUIEffect() end end end function UIOnlineReward:RefreshItems() local rewardList = MDL.OnlineReward.GetRewardList() for i, v in ipairs(self.group_Items) do local data = DataSheetManager.OnlineDialSortOrder:GetDataByOrderID(i) UTL.Item.SetItemCell(v.Item, data.ItemID, data.ItemNum) local isCollected = rewardList[i] == 1 UIUtils.SetActive(v.img_Collected, isCollected) UIUtils.SetActive(v.img_Selected, false) if data.IsEffect and not isCollected then v.effect_Rare:PlayUIEffect() else v.effect_Rare:StopUIEffect() end end end ---开始抽奖动画 function UIOnlineReward:ShowRewardCollectAnimation(orderId) ---改变按钮和相关的控件的各种状态 self.allowClose = false self.btn_Collect:SetGray(true) self.effect_ButtonSparks:StopUIEffect() self.btn_Collect:SetText(Const_IDS.IDS_OnlineDial_Hint_8) self.txt_NextChance:EndTimer() UIUtils.SetActive(self.txt_CanCollect, false) ---初始化变量 self.index = 1 self.loopBoxList = {} self.flashTimes = FlashTimes self.isPlayEffect = false ---根据现有未领取奖励的数量*圈数+被抽到物品在未领取列表的index算出总格子数 --获取现在还没有被领取过的奖励的列表 for i, v in ipairs(MDL.OnlineReward.GetRewardList()) do if v == 0 then table.insert(self.loopBoxList, i) end end --获取该orderId在未获取奖励列表的位置 local orderIndex = 0 for i, v in ipairs(self.loopBoxList) do if v == orderId then orderIndex = i end end local loopLength = #self.loopBoxList if loopLength > 1 then self.needNum = loopLength * RewardCollectAnimationLoop + orderIndex else self.needNum = 0 end self:StartRepeatFunc(self.OnUpdateFun, NormalGapTime) end function UIOnlineReward:OnUpdateFun(deltaTime, timeSinceUpdate) if self.needNum > 0 then ---转动格子数(通过显隐选中态) local gapTime = self.needNum <= #GapTimeList and (GapTimeList[self.needNum] / MilliCoefficient) or NormalGapTime if timeSinceUpdate >= gapTime then self:PlaySelectAnimation() self.needNum = self.needNum - 1 self.index = self.needNum > 0 and self.index + 1 or self.index self:ResetRepeatFunc(self.OnUpdateFun) end else if self.flashTimes > 0 then ---走到被抽中的格子,闪烁 if timeSinceUpdate >= FlashHoldTime + FlashGapTime then self:FlashSelectActive(true) self.flashTimes = self.flashTimes - 1 self:ResetRepeatFunc(self.OnUpdateFun) elseif timeSinceUpdate >= FlashHoldTime then self:FlashSelectActive(false) end if not self.isPlayEffect then --第一次要播放特效 self.isPlayEffect = true self:PlaySelectEffect() end else ---结束了抽奖动画要发送领奖协议 MDL.OnlineReward.StartReceiveRewardReq() self.allowClose = true self:StopRepeatFunc(self.OnUpdateFun) self.index = 1 self.loopBoxList = {} end end end function UIOnlineReward:PlaySelectEffect() local length = #self.loopBoxList self.index = self.index > length and 1 or self.index local realIndex = self.loopBoxList[self.index] local boxNode = self.group_Items[realIndex] self.effect_SelectedItem.gameObject.transform:SetParent(boxNode.img_Selected.transform, false) self.effect_SelectedItem:PlayUIEffect() end function UIOnlineReward:PlaySelectAnimation() local length = #self.loopBoxList self.index = self.index > length and 1 or self.index local realIndex = self.loopBoxList[self.index] UIUtils.SetActive(self.group_Items[realIndex].img_Selected, true) CTL.Sound.PlayGameSound("UI_treasures_roll") local lastIndex = self.index - 1 lastIndex = lastIndex <= 0 and length or lastIndex local realLastIndex = self.loopBoxList[lastIndex] UIUtils.SetActive(self.group_Items[realLastIndex].img_Selected, false) end function UIOnlineReward:FlashSelectActive(active) local length = #self.loopBoxList self.index = self.index > length and 1 or self.index local realIndex = self.loopBoxList[self.index] UIUtils.SetActive(self.group_Items[realIndex].img_Selected, active) end function UIOnlineReward:OnClosed() if not self.allowClose then MDL.OnlineReward.StartReceiveRewardReq() end end return UIOnlineReward