local UIWidgetBase = require_ex('Common/Core/UIWidgetBase') ActivityRewardRegistrationInfo = HL.Class('ActivityRewardRegistrationInfo', UIWidgetBase) ActivityRewardRegistrationInfo.m_activityId = HL.Field(HL.String) << "" ActivityRewardRegistrationInfo.m_activity = HL.Field(HL.Any) ActivityRewardRegistrationInfo.m_totalDays = HL.Field(HL.Number) << -1 ActivityRewardRegistrationInfo.m_rewards = HL.Field(HL.Userdata) ActivityRewardRegistrationInfo.m_getRewardCell = HL.Field(HL.Function) ActivityRewardRegistrationInfo.m_genCellFunc = HL.Field(HL.Function) local START_ANIM_TIME = 0.6 local SCROLL_ANIM_TIME = 0.3 local stateTable = { NotComplete = 1, Complete = 2, Done = 3, } ActivityRewardRegistrationInfo.m_isPopup = HL.Field(HL.Boolean) << false ActivityRewardRegistrationInfo.m_firstCanReceiveDay = HL.Field(HL.Number) << 1 ActivityRewardRegistrationInfo.m_showingCellCount = HL.Field(HL.Number) << 0 ActivityRewardRegistrationInfo.m_listCells = HL.Field(HL.Any) ActivityRewardRegistrationInfo.m_firstTimeFocus = HL.Field(HL.Boolean) << true ActivityRewardRegistrationInfo.m_isInit = HL.Field(HL.Boolean) << true ActivityRewardRegistrationInfo.InitActivityRewardRegistrationInfo = HL.Method(HL.Table) << function(self, args) self:_InitInfo(args) self:_InitBigRewards() self:_InitPosition() self:_InitController() end ActivityRewardRegistrationInfo._InitInfo = HL.Method(HL.Table) << function(self, args) self.m_isInit = true self:_StartCoroutine(function() coroutine.wait(START_ANIM_TIME) self.m_isInit = false end) self.m_isPopup = args.isPopup or false self.m_animation = args.animation self:RegisterMessage(MessageConst.ON_ACTIVITY_CHECK_IN, function(arg) self:_OnActivityCheckIn(arg) end) self:RegisterMessage(MessageConst.ON_ACTIVITY_UPDATED, function(arg) local modifyId = unpack(arg) if modifyId == self.m_activityId then self:_OnActivityCheckIn(arg) end end) self:RegisterMessage(MessageConst.CHECK_IN_REWARD, function(arg) self:OnRewardInfo(arg) end) self.m_activityId = args.activityId self.m_activity = GameInstance.player.activitySystem:GetActivity(self.m_activityId) self:_RefreshRewardDays() self.m_rewards = Tables.CheckInRewardTable[self.m_activityId].stageList self.m_totalDays = #self.m_rewards self.m_firstCanReceiveDay = self.m_activity.loginDays for index = 1,self.m_totalDays do if self:_GetState(index) == stateTable.Complete then self.m_firstCanReceiveDay = index break end end self.m_canGetReward = self.m_activity.loginDays ~= self.m_activity.rewardDays.Count self.view.receiveAllBtn.gameObject:SetActive(self.m_canGetReward) self.view.activityCommonInfo:InitActivityCommonInfo(args) self.m_getRewardCell = UIUtils.genCachedCellFunction(self.view.rewardScrollList) self.view.rewardScrollList.onUpdateCell:RemoveAllListeners() self.view.rewardScrollList.onUpdateCell:AddListener(function(obj, csIndex) self:_OnUpdateCell(self.m_getRewardCell(obj), LuaIndex(csIndex)) end) self.view.rewardScrollList:UpdateCount(self.m_totalDays) self.view.receiveAllBtn.onClick:AddListener(function() if self.m_canGetReward then GameInstance.player.activitySystem:GetActivity(self.m_activityId):GainReward(self.m_allRewardDays) else Notify(MessageConst.SHOW_TOAST,Language.LUA_ACTIVITY_CHECK_IN_RECEIVE_FAIL) end end) self.view.receiveRedDot:InitRedDot("ActivityCheckIn",self.m_activityId) self.m_listCells = UIUtils.genCellCache(self.view.stateNode) self.m_listCells:Refresh(self.m_totalDays, function(cell, index) self:_RefreshDots(cell,index) end) end ActivityRewardRegistrationInfo._InitPosition = HL.Method() << function(self) local cellPixel = (self.view.cellRectTransform.rect.width + self.view.rewardScrollList.space.x) local leftPixel = (self.m_firstCanReceiveDay - 1) * cellPixel local totalPixel = self.view.rewardScrollList:GetPadding().left + self.view.rewardScrollList:GetPadding().right + cellPixel * self.m_totalDays - self.view.rewardScrollList.space.x - self.view.rewardScrollListRectTransform.rect.width local normalizedPosition = leftPixel / totalPixel self.view.rewardScrollRect.horizontalNormalizedPosition = lume.clamp(normalizedPosition, 0 ,1) self.view.rewardFocusBtn.onClick:AddListener(function() self:_FocusBigReward() end) end ActivityRewardRegistrationInfo._FocusBigReward = HL.Method() << function(self) local day = self.m_bigRewards[self.m_bigRewardIndex].day if self.m_firstCanReceiveDay > 1 then local cell = self:_GetCell(self.m_firstCanReceiveDay - 1) if cell then cell.button.interactable = true end end UIUtils.setAsNaviTarget(nil) self.view.rewardScrollList:ScrollToIndex(day) self:_StartCoroutine(function() coroutine.wait(SCROLL_ANIM_TIME) local cell = self:_GetCell(day) if cell then self:_SetNaviTarget(day) cell.animation:Play("reward_cell_focusremind") end end) end ActivityRewardRegistrationInfo.m_focusIndex = HL.Field(HL.Number) << 0 ActivityRewardRegistrationInfo.m_isBack = HL.Field(HL.Boolean) << false ActivityRewardRegistrationInfo._InitController = HL.Method() << function(self) if DeviceInfo.usingController then if self.m_isPopup then self:_StartCoroutine(function() coroutine.wait(START_ANIM_TIME) self:_SetNaviTarget(self.m_firstCanReceiveDay) end) else self.view.rewardScrollListSelectableNaviGroup.onIsTopLayerChanged:AddListener(function(active) if active then if self.m_firstCanReceiveDay > 1 then local cell = self:_GetCell(self.m_firstCanReceiveDay - 1) if cell then cell.button.interactable = true end end else self.m_focusIndex = 0 end end) end end end ActivityRewardRegistrationInfo._SetNaviTarget = HL.Method(HL.Number) << function(self, index) if index == 0 or not DeviceInfo.usingController then return end local cell = self:_GetCell(index) if cell then local target = cell.button self:_ToggleCell(index, true) UIUtils.setAsNaviTarget(target) else logger.error(string.format("SetNaviTarget Fail!Cell %d Not Found!", index)) end end ActivityRewardRegistrationInfo._OnEnable = HL.Override() << function(self) if self.m_activity and DeviceInfo.usingController then self:_StartCoroutine(function() coroutine.step() self.m_isBack = true self.view.rewardScrollList:UpdateShowingCells(function(csIndex, obj) self:_OnUpdateCell(self.m_getRewardCell(obj), LuaIndex(csIndex)) end) self.m_isBack = false coroutine.wait(START_ANIM_TIME) self:_SetNaviTarget(self.m_focusIndex) end) end end ActivityRewardRegistrationInfo.m_bigRewards = HL.Field(HL.Table) ActivityRewardRegistrationInfo.m_bigRewardIndex = HL.Field(HL.Number) << 0 ActivityRewardRegistrationInfo.m_carouselCoroutine = HL.Field(HL.Any) ActivityRewardRegistrationInfo.m_animation = HL.Field(HL.Any) ActivityRewardRegistrationInfo._InitBigRewards = HL.Method() << function(self) self.m_bigRewards = {} self.m_bigRewardIndex = 0 local found = false for index = 1,self.m_totalDays do local csIndex = CSIndex(index) if self.m_rewards[csIndex].isKeyReward then table.insert(self.m_bigRewards,{ day = index, reward = self.m_rewards[csIndex], }) if not found and not self.m_getIfRewarded[index] then self.m_bigRewardIndex = #self.m_bigRewards - 1 found = true end end end self:_LoadBigReward(true) self.view.leftBtn.onClick:AddListener(function() self:_RestartCarousel() self:_LoadBigReward(false) end) self.view.rightBtn.onClick:AddListener(function() self:_RestartCarousel() self:_LoadBigReward(true) end) self:_RestartCarousel() self.view.searchBtn.onClick:AddListener(function() self:_Search() end) end ActivityRewardRegistrationInfo._RestartCarousel = HL.Method() << function(self) if self.m_carouselCoroutine then self:_ClearCoroutine(self.m_carouselCoroutine) end self.m_carouselCoroutine = self:_StartCoroutine(function() while true do coroutine.wait(Tables.checkInInfoTable[self.m_activityId].CheckInRewardChangeTime) self:_LoadBigReward(true) end end) end ActivityRewardRegistrationInfo._LoadBigReward = HL.Method(HL.Boolean) << function(self, next) local animName if self.m_bigRewardIndex == 1 then animName = self.m_isPopup and "bannerchange_page_in" or "activityrewardregistration_state_changepage_out" else animName = self.m_isPopup and "bannerchange_page_out" or "activityrewardregistration_state_changepage_in" end self.m_animation:Play(animName) if next then self.m_bigRewardIndex = self.m_bigRewardIndex % #self.m_bigRewards + 1 else self.m_bigRewardIndex = self.m_bigRewardIndex == 1 and #self.m_bigRewards or self.m_bigRewardIndex - 1 end local index = self.m_bigRewardIndex local reward = self.m_bigRewards[index].reward self.view.dayTxt.text = self.m_bigRewards[index].day self.view.nameTxt.text = reward.rewardName local isChar = reward.charId ~= "" local canReceive = self:_GetState(self.m_bigRewards[index].day) ~= stateTable.Done if isChar and not canReceive then self.view.tipsText.text = Language.LUA_ACTIVITY_CHECK_IN_1_CHAR_RECEIVED elseif isChar and canReceive then self.view.tipsText.text = Language.LUA_ACTIVITY_CHECK_IN_1_CHAR_RECEIVE elseif not isChar and not canReceive then self.view.tipsText.text = Language.LUA_ACTIVITY_CHECK_IN_1_RECEIVED elseif not isChar and canReceive then self.view.tipsText.text = Language.LUA_ACTIVITY_CHECK_IN_1_RECEIVE end if reward.charId ~= "" then self.view.searchBtn.gameObject:SetActive(true) self.m_searchInfo = { isChar = true, charId = reward.charId, } elseif reward.weaponId ~= "" then self.view.searchBtn.gameObject:SetActive(true) self.m_searchInfo = { isChar = false, weaponId = reward.weaponId, } else self.view.searchBtn.gameObject:SetActive(false) end end ActivityRewardRegistrationInfo.m_getIfRewarded = HL.Field(HL.Table) ActivityRewardRegistrationInfo.m_allRewardDays = HL.Field(HL.Table) ActivityRewardRegistrationInfo.m_canGetReward = HL.Field(HL.Boolean) << false ActivityRewardRegistrationInfo._RefreshDots = HL.Method(HL.Any,HL.Number) << function(self,cell,index) local color if self.m_getIfRewarded[index] then color = "Black" elseif index <= self.m_activity.loginDays then color = "Yellow" elseif self.m_rewards[CSIndex(index)].isKeyReward then color = "Pink" else color = "White" end local circle if self.m_rewards[CSIndex(index)].isKeyReward and self.m_getIfRewarded[index] then circle = "BigRewardBlack" elseif self.m_rewards[CSIndex(index)].isKeyReward then circle = "BigRewardWhite" else circle = "NoBigReward" end local today if index == self.m_activity.loginDays then today = "Today" else today = "NotToday" end cell.stateController:SetState(color) cell.stateController:SetState(circle) cell.stateController:SetState(today) end ActivityRewardRegistrationInfo._GetState = HL.Method(HL.Number).Return(HL.Number) << function(self,index) local state = stateTable.NotComplete if self.m_getIfRewarded[index] then state = stateTable.Done elseif index <= self.m_activity.loginDays then state = stateTable.Complete end return state end ActivityRewardRegistrationInfo.m_searchInfo = HL.Field(HL.Table) ActivityRewardRegistrationInfo._Search = HL.Method() << function(self) local info = self.m_searchInfo if info.isChar then local previewCharInfo = GameInstance.player.charBag:CreateClientInitialGachaPoolChar(info.charId) local perfectCharInfo = GameInstance.player.charBag:CreateClientPerfectGachaPoolCharInfo(info.charId) PhaseManager:OpenPhase(PhaseId.CharInfo, { initCharInfo = { instId = previewCharInfo.instId, templateId = previewCharInfo.templateId, charInstIdList = { previewCharInfo.instId }, maxCharInstIdList = { perfectCharInfo.instId }, isShowPreview = true, } },nil,true) else local weaponId = info.weaponId local showWeaponPreviewArgs = { isWeaponPreview = true, weaponId = weaponId, weaponGroups = {}, } if PhaseManager:CheckCanOpenPhase(PhaseId.Wiki, nil, true) and not PhaseManager:CheckIsInTransition() then local fadeTimeBoth = UIConst.CHAR_INFO_TRANSITION_BLACK_SCREEN_DURATION local dynamicFadeData = UIUtils.genDynamicBlackScreenMaskData("Activity->Wiki", fadeTimeBoth, fadeTimeBoth, function() PhaseManager:OpenPhase(PhaseId.Wiki, showWeaponPreviewArgs) end) GameAction.ShowBlackScreen(dynamicFadeData) end end end ActivityRewardRegistrationInfo._OnDestroy = HL.Override() << function(self) GameInstance.player.charBag:ClearAllClientCharAndItemData() end ActivityRewardRegistrationInfo.OnRewardInfo = HL.Method(HL.Table) << function(self, args) local rewardPack = unpack(args) local reward = { items = rewardPack.itemBundleList, chars = rewardPack.chars, onComplete = function() if DeviceInfo.usingController then self:_SetNaviTarget(self.m_focusIndex) end end } Notify(MessageConst.SHOW_SYSTEM_REWARDS, reward) end ActivityRewardRegistrationInfo._OnActivityCheckIn = HL.Method(HL.Any) << function(self, args) self:_RefreshRewardDays() self.view.rewardScrollList:UpdateShowingCells(function(csIndex, obj) self:_OnUpdateCell(self.m_getRewardCell(obj), LuaIndex(csIndex)) end) self.m_canGetReward = self.m_activity.loginDays ~= self.m_activity.rewardDays.Count self.view.receiveAllBtn.gameObject:SetActive(self.m_canGetReward) self.m_listCells:Refresh(self.m_totalDays, function(cell, index) self:_RefreshDots(cell,index) end) end ActivityRewardRegistrationInfo._OnUpdateCell = HL.Method(HL.Table, HL.Number) << function(self, cell, index) if self.m_isBack then if DeviceInfo.usingController then self:_ToggleCell(index, false) return end end local state = self:_GetState(index) cell.levelTxt.text = index cell.gameObject.name = "Cell" .. tostring(index) local rewardId = self.m_rewards[CSIndex(index)].rewardId local rewardBundles = UIUtils.getRewardItems(rewardId) cell.rewardCellCache = cell.rewardCellCache or UIUtils.genCellCache(cell.itemBlack) cell.rewardCellCache:Refresh(#rewardBundles, function(innerCell, innerIndex) local reward = { id = rewardBundles[innerIndex].id, count = rewardBundles[innerIndex].count, forceHidePotentialStar = true, } innerCell:InitItem(reward, function() if not DeviceInfo.usingController and state == stateTable.Complete then GameInstance.player.activitySystem:GetActivity(self.m_activityId):GainReward({index}) else innerCell:ShowTips() end end) innerCell:SetExtraInfo({ tipsPosTransform = innerCell.view.content, isSideTips = true, }) innerCell.view.stateController:SetState(state == stateTable.Done and "Done" or "Nrl") end) if state == stateTable.NotComplete then cell.stateController:SetState(self.m_rewards[CSIndex(index)].isKeyReward and "Senior" or "Nrl") elseif state == stateTable.Complete then cell.stateController:SetState("Receive") elseif state == stateTable.Done then cell.stateController:SetState("Done") end cell.button.onClick:RemoveAllListeners() cell.button.onClick:AddListener(function() if state == stateTable.Complete then AudioManager.PostEvent("Au_UI_Event_CheckInPanel_Receive") GameInstance.player.activitySystem:GetActivity(self.m_activityId):GainReward({index}) else AudioManager.PostEvent("Au_UI_Button_Common") end end) cell.redDot:InitRedDot("ActivityCheckInReward",state == "Receive") if DeviceInfo.usingController then if self.m_isInit and not self.m_isPopup and index == self.m_firstCanReceiveDay - 1 then cell.button.interactable = false end if state == stateTable.Complete then cell.button:ChangeActionOnSetNaviTarget(CS.Beyond.Input.ActionOnSetNaviTarget.PressConfirmTriggerOnClick) else cell.button:ChangeActionOnSetNaviTarget(CS.Beyond.Input.ActionOnSetNaviTarget.None) end cell.getRewardKeyHint.gameObject:SetActive(false) self:_ToggleCell(index, false) cell.detailKeyHint.gameObject:SetActive(false) cell.button.onIsNaviTargetChanged = function(isTarget) self:_ToggleCell(index, isTarget) end else self:_StartCoroutine(function() coroutine.wait(START_ANIM_TIME) cell.inputBindingGroupMonoTarget.enabled = true end) end end ActivityRewardRegistrationInfo._GetCell = HL.Method(HL.Number).Return(HL.Any) << function(self, index) local oriCell = self.view.rewardScrollList:Get(CSIndex(index)) return oriCell and self.m_getRewardCell(oriCell) end ActivityRewardRegistrationInfo._ToggleCell = HL.Method(HL.Number, HL.Boolean) << function(self, index, active) local cell = self:_GetCell(index) if cell then InputManagerInst:ToggleGroup(cell.inputBindingGroupMonoTarget.groupId, active) InputManagerInst:ToggleBinding(cell.button.onClick.bindingId, active and self:_GetState(index) == stateTable.Complete) cell.detailKeyHint.gameObject:SetActive(active) cell.getRewardKeyHint.gameObject:SetActive(active) if active then self.m_focusIndex = index end end end ActivityRewardRegistrationInfo._RefreshRewardDays = HL.Method() << function(self) self.m_getIfRewarded = {} for i = 1,self.m_activity.rewardDays.Count do local rewardDay = self.m_activity.rewardDays[CSIndex(i)] self.m_getIfRewarded[rewardDay] = true end self.m_allRewardDays = {} for day = 1,self.m_activity.loginDays do if not self.m_getIfRewarded[day] then table.insert(self.m_allRewardDays,day) end end end HL.Commit(ActivityRewardRegistrationInfo) return ActivityRewardRegistrationInfo