local UIActivitiesMain = UIViewClass() local EventSystem = require('Event/EventSystem') local YELLOW_COLOR_STR = "%d/%d" local ACTIVATION_STR = UIUtils.GetLocalizedTxt(Const_IDS.IDS_Activity_Title_Activation) function UIActivitiesMain:OnCreated(context) self.CurrentIndex = -1 self.IconPath = ConstAssetPathConfig.IconPath1 end function UIActivitiesMain:OnOpened(context) MDL.Activities.RequestGetActivityInfo() if MDL.HeroMatch1v1.IsShowHeroMatch1v1Entry() and MDL.HeroMatch1v1.GetCurMatchTimeID() >= MDL.HeroMatch1v1.Enum_BigStage.Screening and MDL.HeroMatch1v1.GetCurMatchTimeID() <= MDL.HeroMatch1v1.Enum_BigStage.Finals and not MDL.HeroMatch1v1.GetMatchStageInfo(MDL.HeroMatch1v1.GetCurStageID()) then MDL.HeroMatch1v1.HeroMatchOpenRequest() end EventSystem.Dispatch(EventID.UI_UpdateClimbTowerInfo) self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.UpdateFunctionUnlock) self:RegistSystemEvent(EventID.UI_Activity_Refresh_Active, self.RefreshActive) self:RegistSystemEvent(EventID.UI_Activity_Refresh_ActiveReward, self.RefreshActiveReward) self:RegistSystemEvent(EventID.UI_Activity_Refresh_Toggle_RedPoint, self.UI_Activity_Refresh_Toggle_RedPoint) self:RegistSystemEvent(EventID.UI_Activity_Refresh_Cell_RedPoint, self.UI_Activity_Refresh_Cell_RedPoint) self:RegistSystemEvent(EventID.UI_Activity_Close, self.OnBackButtonPressed) self:RegistSystemEvent(EventID.Country_GuildLeaveCountry, self.UI_Activity_Refresh_Cell_RedPoint) self:RegistSystemEvent(EventID.UI_Activity_Refresh_ListOrder, self.RefreshListOrder) self:RegistSystemEvent(EventID.TimerWheelEndTimeOver, self.RefreshListOrder) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_Activity_FucName) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) self.toggle_Left = self.toggle_LeftTab MDL.Activities.GetActiveValue() self:RefreshLeftTab() self:UIAdjustRegion() self:UI_Activity_Refresh_Toggle_RedPoint() if context then if context.toggleIndex then self.toggle_Left:SelectIndex(context.toggleIndex) else self.toggle_Left:SelectIndex(0) end else self.toggle_Left:SelectIndex(0) end self:SetPushStyle(LuaConst.PushStyleEnum.HIDE) end function UIActivitiesMain:OnFocusChanged(isFocus) self.isFocus = isFocus if isFocus then --用hide模式push,活动很多,没办法一一监听事件,所以当焦点回来的时候刷新一下当前的数据 self.group_Scroll:RefreshCells() self:DisplayAwardBox() end end function UIActivitiesMain:OnValueChanged(comp, index) if comp == self.toggle_Left then self:SwitchMainType(index) self:SaveSelectedToggleIndex(self.CurrentIndex) self:CloseDetailViews() end end function UIActivitiesMain:CloseDetailViews() if self.detailView then self.detailView:CloseView() self.detailView = nil end end function UIActivitiesMain:SaveSelectedToggleIndex(index) if self.context then self.context.toggleIndex = index else self.context = { toggleIndex = index } end end function UIActivitiesMain:RefreshLeftTab() local toggleIdsList = {} for i, v in DataSheetManager.ActivityChildData:GetEnumerator() do local cfgData = MDL.Activities.GetActivityDatasByTabId(v.ID) if #cfgData > 0 then table.insert(toggleIdsList, Const_IDS[v.ActivityChildName]) self.toggle_Left:SetToggleActive(i, true) else self.toggle_Left:SetToggleActive(i, false) end end UTL.Toggle.InitToggleGroupByIDS(self.toggle_Left, "txt", toggleIdsList) --不存在任何活动,则该分类页签隐藏 for i, v in DataSheetManager.ActivityChildData:GetEnumerator() do local data = MDL.Activities.GetActivityDatasByTabId(i) if not data or #MDL.Activities.GetActivityDatasByTabId(i) <= 0 then self.toggle_Left:SetToggleActive(i, false) end end end function UIActivitiesMain:RefreshListOrder() self.group_Scroll:ReloadAll(MDL.Activities.GetActivityDatasByTabId(self.CurrentIndex + 1)) end function UIActivitiesMain:UIAdjustRegion() if GameAppInfo.IsVietnamPackage() then UIUtils.SetActive(self.Week_Activity, false) end end function UIActivitiesMain:SwitchMainType(index) self.CurrentIndex = index self.group_Scroll:ReloadAll(MDL.Activities.GetActivityDatasByTabId(index + 1)) end function UIActivitiesMain:OnClosed() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) EventSystem.Dispatch(EventID.UI_Activity_Main_RedPoint) end function UIActivitiesMain:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.group_Scroll then if target == cellTable.btn_Join then CTL.Activities.OpenActivityWindowByID(data.ID) if CTL.Activities.IsNeedFindNPC(data.ID) then if data.ID == LuaConst.ActivityType.RingDaily and MDL.Task.GetDailyRingTaskState() == MDL.Task.Enum_RingTaskState.Done then return end UIManager.RecoverTopView() CTL.HomeMain.CloseOpenView() end elseif target == cellTable.img_Click then self:CloseDetailViews() local isOpen, showTips = CTL.Activities.CanOpenDetailView(data.ID) if not isOpen then CTL.Sound.PlayGameSound("UI_invalid") --如果是群英讨逆\经典战役 未开启,直接提示,不打开详情界面 if showTips then CTL.Tips.AddTipsMsg(Const_IDS["IDS_BossChallenge_NotOpen"]) return end end self.detailView = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIActivitiesDetails), { activityId = data.ID, parentView = self }) elseif target == cellTable.event_info then local date, time, extra = CTL.Activities.GetDetailsTimeDesc(data) if GameAppInfo.IsVietnamPackage() then UIManager.OpenView(Const_UI_Lua.UIEnum.UIDescriptionPanel, { target = target, posType = LuaConst.DescriptionPanelType.Center, text = extra }) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIDescriptionPanel, { target = target, posType = LuaConst.DescriptionPanelType.RightLower, text = extra }) end else for i = 1, #cellTable.Content do if cellTable.Content[i].item.event_Click == target then local rewardDataItem = DataSheetManager.RewardClientShow:GetDataByClientShowID(data.RewardDisplay).ItemID UTL.ItemTips.ShowCommonTipsById(rewardDataItem[i]) end end end elseif scrollRect == self.ChestRewardScroll then UTL.ItemTips.ShowCommonTipsById(data.ItemID) elseif scrollRect == self.RewardScroll then local itemInfo = data[1] UTL.ItemTips.ShowCommonTipsById(itemInfo.ItemID) end end function UIActivitiesMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.group_Scroll then UIUtils.SetLabelText(cellTable.txt_Activities, Const_IDS[data.Activity]) UIUtils.SetImageByAssetBundle(cellTable.img_Icon, data.ActivityMainPicture) --玩法标识 if data.TypeTips > 0 then cellTable.group_Mode:SetState(data.TypeTips) else cellTable.group_Mode:SetState(0) end self:InitActivityCellStatusInfo(cellTable, data) elseif scrollRect == self.ChestRewardScroll then UTL.Item.SetItemCell(cellTable.item, data.ItemID, data.ItemNum) end end function UIActivitiesMain:InitActivityCellStatusInfo(cellTable, data) local isUnlock, condition = CTL.Activities.IsOpen(data.ID) UIUtils.SetActive(cellTable.event_info, false) UIUtils.SetActive(cellTable.group_Buy, false) if not isUnlock then cellTable.unlock_state:SetState(0) cellTable.txt_Condition04.text = condition UIUtils.SetActive(cellTable.group_Done, false) UIUtils.SetGray(cellTable.img_Icon, false) else if CTL.Activities.IsOpeningTime(data.ID) then self:InitActivityCellBtn(cellTable, data) else self:InitActivityCellOpenTime(cellTable, data) end local isDone = CTL.Activities.IsDone(data.ID) UIUtils.SetActive(cellTable.group_Done, isDone) UIUtils.SetActive(cellTable.img_IconMask, CTL.Activities.IsActivityCellSetGray(data.ID)) self:InitActivityCellRewards(cellTable, data) end end function UIActivitiesMain:InitActivityCellBtn(cellTable, data) cellTable.unlock_state:SetState(2) --参与次数 local countData = MDL.Activities.GetCountInfo(data.ID) self:SetBtnProgress(cellTable, countData) --可购买次数 UIUtils.SetActive(cellTable.group_Buy, countData.curCount == 0 and countData.curBuyCount > 0) --红点 local hasRedPoint = MDL.Activities.GetRedPointByID(data.ID) cellTable.btn_Join:SetRedPoint(hasRedPoint) --活跃度 if data.SheetType == CTL.Activities.ActivityType.Competition then cellTable.txt_progress_info.text = CTL.Activities.GetMatchActivityStateStr(data.ID) else local curActive, sumActive = MDL.Activities.GetActiveInfo(data.ID) if sumActive <= 0 then cellTable.txt_progress_info.text = ACTIVATION_STR..UIUtils.GetLocalizedTxt(Const_IDS.IDS_Activity_NoActivition) else if curActive == sumActive then cellTable.txt_progress_info.text = ACTIVATION_STR..string.format(YELLOW_COLOR_STR, curActive, sumActive) else cellTable.txt_progress_info.text = ACTIVATION_STR..curActive.."/"..sumActive end end end end function UIActivitiesMain:InitActivityCellOpenTime(cellTable, data) cellTable.unlock_state:SetState(1) if #data.Time_Table <= 0 then cellTable.txt_Time.text = CTL.Activities.GetMatchActivityStateStr(data.ID) else local date, time, extra = CTL.Activities.GetDetailsTimeDesc(data) if string.isNilOrEmpty(time) then cellTable.txt_Time.text = date else cellTable.txt_Time.text = date.."\n"..UTL.Color.FormatTextByColor("F9D891", time) end UIUtils.SetActive(cellTable.event_info, extra ~= nil) end end function UIActivitiesMain:InitActivityCellRewards(cellTable, data) if data.RewardDisplay > 0 then UIUtils.SetActive(cellTable.group_reward, true) local cfg = DataSheetManager.RewardClientShow:GetDataByClientShowID(data.RewardDisplay) local rewardData = DataSheetUtil.GetRewardClientShowItemTable(cfg) for i, v in ipairs(rewardData) do if not cellTable.Content[i] then self:InstantiateCellCollection(cellTable.cell.gameObject, cellTable.Content, cellTable.reward_item.gameObject) end UTL.Item.SetItemCell(cellTable.Content[i].item, v.ItemID, v.ItemNum) cellTable.Content[i].gameObject:SetActive(true) end for i = #rewardData + 1, #cellTable.Content do cellTable.Content[i].gameObject:SetActive(false) end else UIUtils.SetActive(cellTable.group_reward, false) end end function UIActivitiesMain:SetBtnProgress(cellTable, countData) if countData.isDisplayCountTxt then if countData.curCount == -1 then cellTable.btn_Join:SetText(Const_IDS.IDS_Activity_AttendButton) else local curCountStr = countData.curCount == 0 and UTL.Color.FormatRedColor(countData.curCount) or countData.curCount cellTable.btn_Join:SetText(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Activity_AttendButton).." ".. curCountStr.."/"..countData.sumCount) end else cellTable.btn_Join:SetText(Const_IDS.IDS_Activity_AttendButton) end end function UIActivitiesMain:SetActivityRewardTypeDesc(cellTable, index, rewardTip, state) local cell = cellTable.RewardGroup[index] if string.isNilOrEmpty(rewardTip) then UIUtils.SetActive(cell.gameObject, false) else UIUtils.SetActive(cell.gameObject, true) UIUtils.SetLabelText(cell.txt_ActivitiesReward, Const_IDS[rewardTip]) cell.state_RewardType:SetState(state - 1) end end function UIActivitiesMain:RefreshActiveReward(activityRewardType) if activityRewardType == MDL.Activities.ActivityRewardType.DayActivityReward then self:DisplayAwardBox() elseif activityRewardType == MDL.Activities.ActivityRewardType.WeekActivityReward then self:RefreshWeekActive() end end -- 刷新底部活跃度 function UIActivitiesMain:RefreshActive() self.group_Scroll:ReloadAll(MDL.Activities.GetActivityDatasByTabId(self.CurrentIndex + 1)) local CurActiveValue = MDL.Activities.GetCurActiveValue() --刷新底部活跃度数值 self.txt_Rate.text = CurActiveValue self:DisplayAwardBox() -- 刷新周活跃 self:RefreshWeekActive() end --展示宝箱奖励 function UIActivitiesMain:DisplayAwardBox() local CONST_WIDTH = self.FillArea.transform.sizeDelta.x local rewardscfg = MDL.Activities.GetActiveValue() local nodeRate = 1/#rewardscfg local fillValue = 0 self.CurActiveValue = MDL.Activities.GetCurActiveValue() self.chestData = {} local awardArray = MDL.Activities.GetAwardProgressStateArray() or {} for k, v in ipairs(rewardscfg) do local offsetX = CONST_WIDTH / #rewardscfg * k if self.chests[k] == nil then self:InstantiateCollection(self.chests, self.cell_Chest.gameObject) end local curChest = self.chests[k] curChest.gameObject.transform:SetAnchoredPosition(offsetX, 0) if k == 1 then local difvalue = self.CurActiveValue - v.ActivationNum if difvalue >= 0 then fillValue = fillValue + nodeRate else fillValue = fillValue + self.CurActiveValue/v.ActivationNum * nodeRate end else local lastActivationNum = rewardscfg[k-1].ActivationNum if self.CurActiveValue >= v.ActivationNum then fillValue = fillValue + nodeRate elseif self.CurActiveValue > lastActivationNum then fillValue = fillValue + (self.CurActiveValue - lastActivationNum) /(v.ActivationNum - lastActivationNum) * nodeRate end end self.chestData[k] = {} self.chestData[k].ID = v.ID self.chestData[k].ActivationNum = v.ActivationNum self.chestData[k].Item_Table = DataSheetManager.ActivationRewardRepeat:GetDataByAttrRepeatID(v.RewardRepeat).Item_Table self.chestData[k].isGot = awardArray[k] self:SetChestImgByState(curChest, DataSheetManager.Activation:GetDataByID(k), self.CurActiveValue >= v.ActivationNum, awardArray[k]) UIUtils.SetLabel(curChest.lab_Reward, v.ActivationNum) end self.Fill.fillAmount = fillValue end function UIActivitiesMain:SetChestImgByState(chest, chestData, canGet, isGot) UIUtils.SetActive(chest.gameObject, true) chest.effect_RewardHigh:StopUIEffect() chest.effect_RewardLow:StopUIEffect() UIUtils.SetImageByAssetBundle(chest.icon_Chest, chestData.BoxPic) if canGet then if isGot and isGot > 0 then chest.state_Chest:SetState(2) else chest.state_Chest:SetState(1) if chestData.BoxEffectType > 0 then chest.effect_RewardHigh:PlayUIEffect() UIUtils.SetActive(chest.effect_RewardHigh, self.isFocus ~= false) else chest.effect_RewardLow:PlayUIEffect() UIUtils.SetActive(chest.effect_RewardLow, self.isFocus ~= false) end end UIUtils.SetActive(chest.img_Dot_Unreached_01, true) else chest.state_Chest:SetState(0) UIUtils.SetActive(chest.img_Dot_Unreached_01, false) end end function UIActivitiesMain:ShowChestReward(Item_Table, locateX, index, isLast) local rewardData = Item_Table local _, tempY, tempZ = self.info_Reward.transform:GetPosition() self.info_Reward.transform:SetPosition(locateX, tempY, tempZ) local posX = self.info_Reward.transform:GetLocalPosition() posX = isLast and (posX - 120) or posX self.info_Reward.transform:SetLocalPosition(posX, nil, nil) UIUtils.SetActive(self.info_Reward, true) self.ChestRewardScroll:ReloadAll(rewardData) end function UIActivitiesMain:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIActivitiesMain:OnButtonClicked(comp) if not GameAppInfo.IsVersionGreaterThan122000() then --220修复 UIComponentCollection 函数OnLayerActive中 子节点在获取GraphicRaycaster时误拿的是根节点的。 if self.isFocus == false then return end end if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Calendar then UIManager.OpenView(Const_UI_Lua.UIEnum.UIActivitiesCalendar) elseif comp == self.img_Bottom then self:CloseDetailViews() elseif comp == self.btn_Close then UIUtils.SetActive(self.info_Reward, false) elseif comp == self.btn_WeekPopupClose then self:OpenOrCloseWeekPopup() elseif comp == self.Week_Box then if MDL.Activities.HasWeekRedPointRedPoint() then local weekActivationCfg = MDL.Activities.GetUnReceiveMaxData() MDL.Activities.RequestWeekActivityAward(weekActivationCfg.ID - 1) else self:OpenOrCloseWeekPopup() end elseif comp == self.btn_GoShop then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIShopMain, { TabEnum = CTL.PayMall.ShopMainTabEnum.WeekActivity }) else if self.Week_Popup.gameObject.activeSelf then for i, v in ipairs(self.group_Reward) do if comp == v.Item.event_Click and i >= 1 then-- 第一个为0节点展示 local weekActivationCfg = DataSheetManager.WeekActivation:GetDataByID(i - 1) local rewardRepeatData = DataSheetManager.WeekActivationRewardRepeat:GetDataByID(weekActivationCfg.RewardRepeat) local rewardData = rewardRepeatData.Item_Table[1] UTL.ItemTips.ShowCommonTipsById(rewardData.ItemID) return end end -- 这里因为chests内的ui使用了Canvas 所以需要单独监听来关闭周活跃界面 for i = 1, #self.chests do if comp == self.chests[i].event_Reward then self:OpenOrCloseWeekPopup() return end end else for i = 1, #self.chests do if comp == self.chests[i].event_Reward then if self.CurActiveValue >= self.chestData[i].ActivationNum and (not self.chestData[i].isGot or self.chestData[i].isGot == 0) then MDL.Activities.RequestDayActivityAward(i - 1) else local px = comp.transform:GetPosition() self:ShowChestReward(self.chestData[i].Item_Table, px, i, i == #self.chests) end return end end end end end function UIActivitiesMain:UI_Activity_Refresh_Cell_RedPoint() self.group_Scroll:RefreshCells() end function UIActivitiesMain:UI_Activity_Refresh_Toggle_RedPoint() for i, v in DataSheetManager.ActivityChildData:GetEnumerator() do local cfgData = MDL.Activities.GetActivityDatasByTabId(v.ID) if #cfgData > 0 then self.toggle_Left:SetRedPoint(i - 1, MDL.Activities.GetTabRedPointById(v.ID)) end end end ----新手引导方法 function UIActivitiesMain:MoveToId(id) local activityCfgDta = DataSheetManager.ActivityData:GetDataByID(id) local cfgData = MDL.Activities.GetActivityDatasByTabId(activityCfgDta.SheetType) for i, v in ipairs(cfgData) do if v.ID == id then self.group_Scroll:MoveIndex(i - 1) return i end end end function UIActivitiesMain:UpdateFunctionUnlock() self:RefreshActive() if self.CurrentIndex == 2 then -- 限时页签刷新cell(天地群雄玩法在GMS开关关闭后需要隐藏cell,这里加上刷新逻辑) self:SwitchMainType(self.CurrentIndex) end end function UIActivitiesMain:OpenOrCloseWeekPopup() if self.Week_Popup.gameObject.activeSelf then UIUtils.SetActive(self.Week_Popup, false) else UIUtils.SetActive(self.Week_Popup, true) local timeStr if GameAppInfo.IsVietnamPackage()then timeStr = string.format("%s %s", UTL.Time.GetDateDescAndTime({ [1] = 2 })) else timeStr = string.format("%s%s", UTL.Time.GetDateDescAndTime({ [1] = 2 })) end UIUtils.SetLabel(self.lab_WeekTitle, string.FormatByIdsId(Const_IDS.IDS_Weekactivition_Des2, timeStr)) -- 打开时判断是否已经初始化过 如果已经初始化过则直接刷新 self:RefreshWeekActivePopup() end end function UIActivitiesMain:RefreshWeekActive() local weekActivationCfg = MDL.Activities.GetUnReceiveMaxData() local curWeekActivityScore = MDL.Activities.GetCurWeekActivityScore() -- 刷新底部活跃进度 UIUtils.SetAtlasImageFillAmount(self.filledBar, curWeekActivityScore / weekActivationCfg.ActivationNum) self.Week_Box:SetRedPoint(MDL.Activities.HasWeekRedPointRedPoint()) -- 刷新底部活跃数值 UIUtils.SetLabel(self.lab_num, string.format("%s/%s", curWeekActivityScore, weekActivationCfg.ActivationNum)) -- 如果Week_Popup处于打开状态则刷新一下 if self.Week_Popup.gameObject.activeSelf then self:RefreshWeekActivePopup() end end function UIActivitiesMain:RefreshWeekActivePopup() local weekAwardArray = MDL.Activities.GetWeekAwardProgressStateArray() or {} local curWeekActivityScore = MDL.Activities.GetCurWeekActivityScore() -- 默认一个0节点 local item = self.group_Reward[1] local posX = 0 if not item then item = self:InstantiateCollection(self.group_Reward, self.group_PointTemplate.gameObject) UIUtils.SetActive(item.gameObject, true) item.gameObject.transform:SetLocalPosition(posX, 0, 0) end item.obj_State:SetState(2) UIUtils.SetLabel(item.txt_Point, 0) local posXInterval = self.img_PointProgress.transform.sizeDelta.x / #weekAwardArray local maxWeekActivityScore = 0 -- 刷新后续节点 for i, v in ipairs(weekAwardArray) do local weekActivationCfg = DataSheetManager.WeekActivation:GetDataByID(i) item = self.group_Reward[i + 1] if not item then item = self:InstantiateCollection(self.group_Reward, self.group_PointTemplate.gameObject) if GameAppInfo.IsVersionGreaterThan16000() then self:InitUITemplate(item.Item, item) end UIUtils.SetActive(item.gameObject, true) posX = posX + posXInterval item.gameObject.transform:SetLocalPosition(posX, 0, 0) -- 第一次初始化时设置一下道具 local rewardRepeatData = DataSheetManager.WeekActivationRewardRepeat:GetDataByID(weekActivationCfg.RewardRepeat) local rewardData = rewardRepeatData.Item_Table[1] if rewardData then UTL.Item.SetItemCell(item.Item, rewardData.ItemID, rewardData.ItemNum) end end if v == 0 then item.obj_State:SetState(0) else item.obj_State:SetState(1) end if maxWeekActivityScore < weekActivationCfg.ActivationNum then maxWeekActivityScore = weekActivationCfg.ActivationNum end UIUtils.SetLabel(item.txt_Point, weekActivationCfg.ActivationNum) end -- 不等间距设置进度 local reachIndex = 0 local downValue = 0 local upValue = 0 for i, v in DataSheetManager.WeekActivation:GetEnumerator() do if curWeekActivityScore >= v.ActivationNum then reachIndex = reachIndex + 1 downValue = v.ActivationNum else upValue = v.ActivationNum break end end local oneProgress = 1 / #weekAwardArray local intervalProgress = 0 if upValue > downValue then intervalProgress = (curWeekActivityScore - downValue) / (upValue - downValue) end UIUtils.SetAtlasImageFillAmount(self.img_PointProgress, oneProgress * reachIndex + oneProgress * intervalProgress) end return UIActivitiesMain