local UIDirectionalGiftBase = UIViewClass() local UIANIMATIONTIME = 0.2 local BaseBackGround = "OperationActivity/PushGift/UIDirectionGifts/UIDirectionalGiftCurrency" local PushGiftNodeName = "event_PushGift" local PayMallNodeName = "event_Store" -------------------- function UIDirectionalGiftBase:OnOpened(context) if not CTL.Unlock.CheckIfFuncUnlock(MDL.Unlock.FunctionType.PushGift, self) then return end self.scrollCanvasGroup = self.Panel_Scroll:GetComponent(typeof(UnityEngine.CanvasGroup)) self:AnimToOpen() --打开界面请求服务器开始计时 MDL.PushGift.AcquireRealPushGiftReq() self.curSelectTabData = nil self.giftView = nil self.isSpecial = context.isSpecial self:RegistSystemEvent(EventID.UI_OperationActivity_InfoChanged, self.UpdateInfo) self:RegistSystemEvent(EventID.UI_PushGift_TimeRefresh, self.UpdateInfo) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.CheckIfFuncUnlock) self:UpdateTabs() self:SelectTab(context.giftInfo) end function UIDirectionalGiftBase:OnButtonClicked(comp) if comp == self.btn_Close then self:AnimToClose() end end function UIDirectionalGiftBase:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loopScroll_Tab then local info = MDL.OperationActivity.PushGiftData:GetDataByActivityID_ID(data.activityId, data.giftId) if info then UIUtils.SetLabel(cellTable.txt_Unselect, info.PushTabName) UIUtils.SetLabel(cellTable.txt_Select, info.PushTabName) local offset = data.endTime - UTL.Time.GetServerTimestamp() if offset > 0 then cellTable.cdTimer_Unselect:ResetAndBeginCustomTimer(false, offset, 0, "{0}:{1}:{2}", 1) cellTable.cdTimer_Select:ResetAndBeginCustomTimer(false, offset, 0, "{0}:{1}:{2}", 1) end end end end function UIDirectionalGiftBase:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loopScroll_Item then UTL.ItemTips.ShowCommonTipsById(data.RewardID) elseif scrollRect == self.loopScroll_Tab then self.selectIndex = index self:OnSelectData(data) end end function UIDirectionalGiftBase:OnUIAnimationStoped(id) if self.closeScaleAnim == id then self:CloseView(true) elseif self.openScaleAnim == id then self.scrollCanvasGroup.alpha = 1 end end function UIDirectionalGiftBase:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end -------------------- function UIDirectionalGiftBase:UpdateTabs() local infoArray = MDL.PushGift.GetPushGiftArray(self.isSpecial) self.loopScroll_Tab:ReloadAll(infoArray) end function UIDirectionalGiftBase:SelectTab(giftInfo) local index = 0 local infoArray = MDL.PushGift.GetPushGiftArray(self.isSpecial) if giftInfo then for i, v in ipairs(infoArray) do if giftInfo.activityId == v.activityId and giftInfo.giftId == v.giftId then index = i - 1 break end end end if #infoArray > index then self.loopScroll_Tab:SelectIndex(index, true) end end function UIDirectionalGiftBase:AnimToOpen() local homeMainTrans = UIManager.FindViewTransform(Const_UI_Lua.UIEnum.UIHomeMain, nil, false) if homeMainTrans then local nodeName = self.isSpecial and PayMallNodeName or PushGiftNodeName local node = UTL.UIRender.FindInChildren(homeMainTrans, nodeName) if node then self.scrollCanvasGroup.alpha = 0 local oriParent = self.Panel_Gift.parent local oriPosX, oriPosY = self.Panel_Gift:GetLocalPosition() local oriSiblingIndex = self.Panel_Gift:GetSiblingIndex() self.Panel_Gift:SetParent(node, false) self.Panel_Gift:SetParent(oriParent, true) UIUtils.SetSiblingIndex(self.Panel_Gift, oriSiblingIndex) self.Panel_Gift:SetLocalScale(0, 0) self:MoveToPos(self.Panel_Gift, oriPosX, oriPosY, UIANIMATIONTIME, false) self.openScaleAnim = self:ScaleToSize(self.Panel_Gift, 1, 1, UIANIMATIONTIME, true) end end end --播放关闭动画 function UIDirectionalGiftBase:AnimToClose() --查找对应的节点 local homeMainTrans = UIManager.FindViewTransform(Const_UI_Lua.UIEnum.UIHomeMain, nil, false) if homeMainTrans then local nodeName = self.isSpecial and PayMallNodeName or PushGiftNodeName local node = UTL.UIRender.FindInChildren(homeMainTrans, nodeName) if node then self.scrollCanvasGroup.alpha = 0 local oriParent = self.Panel_Gift.parent local oriPosX, oriPosY = self.Panel_Gift:GetLocalPosition() self.Panel_Gift:SetParent(node, false) self.Panel_Gift:SetParent(oriParent, true) local tarX, tarY = self.Panel_Gift:GetLocalPosition() self.Panel_Gift:SetLocalPosition(oriPosX, oriPosY) self:MoveToPos(self.Panel_Gift, tarX, tarY, UIANIMATIONTIME, false) self.closeScaleAnim = self:ScaleToSize(self.Panel_Gift, 0, 0, UIANIMATIONTIME, true) else self:CloseView(true) end else self:CloseView(true) end end function UIDirectionalGiftBase:OnSelectData(data) self.curSelectTabData = data local info = MDL.OperationActivity.PushGiftData:GetDataByActivityID_ID(data.activityId, data.giftId) --为空传入不同的界面参数 local __, giftBackGroundData = DataSheetManager.PushGiftBackGround:TryGetDataByID(info.RewardId) self:CloseGiftCommonView() if giftBackGroundData == nil or string.isNilOrEmpty(giftBackGroundData.BackGround) then self.giftView = self.ui_SubView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.OperationActivity.UIDirectionalGiftCommon), {giftData = data, parentView = self}, BaseBackGround) else self.giftView = self.ui_SubView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.OperationActivity.UIDirectionalGiftCommon), {giftData = data, giftBackGroundData = giftBackGroundData, parentView = self}, giftBackGroundData.BackGround) end self.state_Special:SetState(CTL.PushGift.IsSpecialPushGift(data.activityId, data.giftId) and 1 or 0) end function UIDirectionalGiftBase:CloseGiftCommonView() if self.giftView then self.giftView:CloseView() self.giftView = nil end end function UIDirectionalGiftBase:CheckIfFuncUnlock(funcId, isUnlock) if funcId and funcId == MDL.Unlock.FunctionType.PushGift then CTL.Unlock.CheckIfFuncUnlock(funcId, self) end end function UIDirectionalGiftBase:UpdateInfo() if self.isSpecial then local giftInfo = MDL.PushGift.GetPushGiftInfo(self.curSelectTabData.activityId, self.curSelectTabData.giftId) if giftInfo then self:OnSelectData(giftInfo) else self:AnimToClose() end else self:UpdateTabs() self:UpdateSelectTabData() local infoArray = MDL.PushGift.GetPushGiftArray() if self.curSelectTabData == nil then -- 当前选中的tab数据被清,说明已经过期 if #infoArray > 0 then self.loopScroll_Tab:SelectIndex(0, true) else self:OnTimeEnd() end else local index = 0 for i, v in ipairs(infoArray) do if v.giftId == self.curSelectTabData.giftId then index = i - 1 break end end if #infoArray > 0 then self.loopScroll_Tab:SelectIndex(index, true) end end end end function UIDirectionalGiftBase:UpdateSelectTabData() if self.curSelectTabData then local infoArray = MDL.PushGift.GetPushGiftArray(self.isSpecial) local hasContains = false for i, v in ipairs(infoArray) do if v.giftId == self.curSelectTabData.giftId then hasContains = true break end end if hasContains then if self.curSelectTabData.endTime - UTL.Time.GetServerTimestamp() <= 0 then -- 过期,清理数据 self:ClearOverdueData() end else self:ClearOverdueData() end end end function UIDirectionalGiftBase:ClearOverdueData() if self.giftView then self.giftView:SetGiftData(nil) self.curSelectTabData = nil end end function UIDirectionalGiftBase:OnTimeEnd() if MDL.PushGift.GetIfExpire() then if self.giftView then self.giftView:SetTimeEnd() end else self:CloseView(true) end end return UIDirectionalGiftBase