local UIAnniversaryPrepare = UIViewClass() local RefreshCountTime = 300 local RewardType = { Single = 1, Multi = 2, } function UIAnniversaryPrepare:OnOpened(context) self.activityId = context.activityId self.activityType = MDL.OperationActivity.ActivityType.AnniversaryPrepare self.fillWidth = self.FillArea.transform.sizeDelta.x self:RegistSystemEvent(EventID.UI_RefreshCurrency, self.SetFireItemCount) self:RegistSystemEvent(EventID.UI_OACommon_TaskInfoRefresh, self.SetTaskData) self:RegistSystemEvent(EventID.UI_OACommon_TaskRewardClaim, self.SetTaskData) self:RegistSystemEvent(EventID.UI_OACommon_TaskDataRefresh, self.SetTaskData) self:RegistSystemEvent(EventID.UI_AnniversaryPrepare_InfoUpdate, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_AnniversaryPrepare_FireSuccess, self.PlayFireEffect) self:RegistSystemEvent(EventID.New_Day_Refresh, self.NewDayRefreshTaskList) MDL.AnniversaryPrepare.InfoReq(self.activityId) MDL.OACommon.OATaskInfoReq(self.activityId) self.basicData = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) self.activityInfo = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS.IDS_AnniversaryPrepare_Title) UTL.Item.OnlyItemIconWithoutBg(self.img_Fire, self.basicData.SaluteItemID) self.refreshCount = 0 self:SetTime() self:StartRepeatFunc(self.SetTime, 1, -1) end function UIAnniversaryPrepare:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIAnniversaryPrepare:NewDayRefreshTaskList() MDL.OACommon.OATaskInfoReq(self.activityId) end function UIAnniversaryPrepare:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.UITemplateTitlePanel.btn_Info then UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.AnniversaryPrepare}) elseif comp == self.btn_Fire then if self.itemCount > 0 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIAnniversaryPrepareItemUse, { data = {Count = self.itemCount, CfgId = self.basicData.SaluteItemID}, desc = string.FormatByIdsKey("IDS_AnniversaryPrepare_Hint_5", self.basicData.SaluteRewardItemNum), activityId = self.activityId, playEffectFunc = self.PlayFireEffect }, Const_UI_Lua.UIEnum.UIBagItemUsePanel) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_AnniversaryPrepare_Hint_8) end elseif comp == self.btn_GiftInfo then UIManager.OpenView(Const_UI_Lua.UIEnum.UIAnniversaryPrepareReward, {activityId = self.activityId}) else for i = 1, #self.group_Chest do if comp == self.group_Chest[i].item.event_Click then if self.curHeat >= self.chestData[i].Heat and (not self.chestData[i].isGot or self.chestData[i].isGot == 0) then MDL.AnniversaryPrepare.RewardReq(self.activityId, i) else local rewardData = self.chestData[i].RewardData if rewardData.RewardType == RewardType.Single then UTL.ItemTips.ShowCommonTipsById(rewardData.Reward_Table[1].RewardID) end end return else local rewardData = self.chestData[i].RewardData if rewardData.RewardType == RewardType.Multi then local rewardTable = rewardData.Reward_Table for i, v in ipairs(self.group_Chest[i].RewardContent) do if comp == v.item.event_Click then UTL.ItemTips.ShowCommonTipsById(rewardTable[i].RewardID) return end end end end end end end function UIAnniversaryPrepare:PlayFireEffect() self.effect_Fireworks:PlayUIEffect() --延迟1秒显示奖励弹窗 self:StartRepeatFunc(self.ShowDelayRewardPanel, 0.4, 1) CTL.Sound.PlayGameSound("UI_firework") end function UIAnniversaryPrepare:ShowDelayRewardPanel() CTL.Reward.ShowDelayReward() -- 此时弹出奖励信息显示 MDL.AnniversaryPrepare.IsNeedDelayShowReward = false end function UIAnniversaryPrepare:SetTime() local deltaTime = self.activityInfo.endTime - UTL.Time.GetServerTimestamp() if deltaTime <= 0 then self:CloseView() end local timeCount, timeTips = deltaTime, UIUtils.GetLocalizedTxt(Const_IDS.IDS_AnniversaryPrepare_Hint_Second) if deltaTime >= UTL.Time.TotalSecondsOneDay then timeCount = math.floor(deltaTime / UTL.Time.TotalSecondsOneDay) timeTips = UIUtils.GetLocalizedTxt(Const_IDS.IDS_AnniversaryPrepare_Hint_Day) elseif deltaTime >= UTL.Time.TotalSecondsOneHour then timeCount = math.floor(deltaTime / UTL.Time.TotalSecondsOneHour) timeTips = UIUtils.GetLocalizedTxt(Const_IDS.IDS_AnniversaryPrepare_Hint_Hour) elseif deltaTime >= UTL.Time.TotalSecondsOneMinute then timeCount = math.floor(deltaTime / UTL.Time.TotalSecondsOneMinute) timeTips = UIUtils.GetLocalizedTxt(Const_IDS.IDS_AnniversaryPrepare_Hint_Minute) end self.txt_Time.text = UIUtils.GetLocalizedTxt(Const_IDS.IDS_AnniversaryPrepare_Hint_1) self.txt_Day.text = timeCount self.lab_Day.text = timeTips self.txt_TimeLoc.text = string.Concat(UIUtils.GetLocalizedTxt(Const_IDS.IDS_AnniversaryPrepare_Hint_1), timeCount, timeTips) self.refreshCount = self.refreshCount + 1 if self.refreshCount >= RefreshCountTime then MDL.AnniversaryPrepare.InfoReq(self.activityId) self.refreshCount = 0 end end function UIAnniversaryPrepare:RefreshPanel() self:SetProgressBarInfo() self:SetFireItemCount() end function UIAnniversaryPrepare:SetFireItemCount() self.itemCount = UTL.Item.GetItemStockCount(self.basicData.SaluteItemID) UIUtils.SetActive(self.img_NumBg, self.itemCount > 0) self.txt_Num.text = self.itemCount self.btn_Fire:SetRedPoint(self.itemCount > 0) end --展示宝箱奖励 function UIAnniversaryPrepare:SetProgressBarInfo() self.curHeat = MDL.AnniversaryPrepare.GetHeatProcess(self.activityId) self.txt_Hot.text = self.curHeat self.chestData = {} local rewardInfo = MDL.AnniversaryPrepare.GetRewardInfo(self.activityId) local maxValue = MDL.OperationActivity.AnniversaryPrepareReward:GetDataLengthByActivityID(self.activityId) local fillValue = 0 local curValueMin = 0 local curValueMax = 0 for i, v in MDL.OperationActivity.AnniversaryPrepareReward:GetEnumeratorByActivityID(self.activityId) do local offsetX = i / maxValue * self.fillWidth if self.group_Chest[i] == nil then self:InstantiateCollection(self.group_Chest, self.cell_Chest.gameObject) if GameAppInfo.IsVersionGreaterThan16000() then self:InitUITemplate(self.group_Chest[i].item, self.group_Chest[i].gameObject) end end local curChest = self.group_Chest[i] curChest.gameObject.transform:SetAnchoredPosition(offsetX, 0) local heatNum = v.HeatNum self.chestData[i] = { ID = v.ID, RewardData = v, Heat = heatNum, isGot = rewardInfo[i] and rewardInfo[i] == 1, } self:SetChestImgByState(curChest, self.chestData[i]) if self.curHeat >= heatNum then fillValue = i / maxValue curValueMin = heatNum if i == MDL.OperationActivity.AnniversaryPrepareReward:GetDataLengthByActivityID(self.activityId) then curValueMax = heatNum end else curValueMax = curValueMax == 0 and heatNum or curValueMax end end self.Fill.fillAmount = fillValue + (self.curHeat - curValueMin) / (curValueMax - curValueMin) / maxValue end function UIAnniversaryPrepare:SetChestImgByState(chest, data) local heatNum = data.Heat UIUtils.SetActive(chest.gameObject, true) local rewardData = data.RewardData local reward = rewardData.Reward_Table[1] UTL.Item.SetItemCell(chest.item, reward.RewardID, reward.RewardNum) if rewardData.RewardType == RewardType.Single then chest.state_Multi:SetState(0) elseif rewardData.RewardType == RewardType.Multi then UIUtils.SetImageByAssetBundle(chest.img_Item, rewardData.Icon) local rewardTable = rewardData.Reward_Table for i, v in ipairs(rewardTable) do local item = chest.RewardContent[i] if not item then item = self:InstantiateCollection(chest.RewardContent, self.template_Item.gameObject) if GameAppInfo.IsVersionGreaterThan16000() then self:InitUITemplate(item.item, item) end UIUtils.SetActive(item.gameObject, true) UTL.Item.SetItemCell(item.item, v.RewardID, v.RewardNum) end end chest.state_Multi:SetState(1) end chest.txt_Heat.text = heatNum chest.effect:StopUIEffect() local canGet = self.curHeat >= heatNum local isGot = data.isGot if canGet then if isGot then chest.state_Chest:SetState(2) else chest.effect:PlayUIEffect() chest.state_Chest:SetState(1) end else chest.state_Chest:SetState(0) end end function UIAnniversaryPrepare:SetTaskData() self.loop_Task:ReloadAll(MDL.OACommon.GetTaskData(self.activityId, 0)) end function UIAnniversaryPrepare:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Task then self:SetCellInfo(cellTable.item, data) local status = MDL.OACommon.GetTaskStatus(self.activityId, data.ID) local taskStateEnum = MDL.OACommon.ActivityTaskState if status == taskStateEnum.UnDone then cellTable.effect:StopUIEffect() UIUtils.SetActive(cellTable.img_Got, false) elseif status == taskStateEnum.Done then cellTable.effect:PlayUIEffect() UIUtils.SetActive(cellTable.img_Got, false) elseif status == taskStateEnum.Commit then cellTable.effect:StopUIEffect() UIUtils.SetActive(cellTable.img_Got, true) end local conditionData = MDL.OperationActivity.HotGenCondID:GetDataByCondID(data.CondID) local triggerData = conditionData.Task_Table[1] local triggerCount = MDL.OACommon.GetTriggerCount(self.activityId, triggerData.Trigger, triggerData.Param2) local targetParam, des = CTL.Hegemony.GetTriggerContentById(data.CondID, triggerCount, true) cellTable.txt_TaskDesc.text = des cellTable.txt_TaskNum.text = triggerCount .. "/" .. targetParam end end function UIAnniversaryPrepare:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Task then if target == cellTable.item.event_Click then local status = MDL.OACommon.GetTaskStatus(self.activityId, data.ID) if status == MDL.OACommon.ActivityTaskState.Done then MDL.OACommon.OATaskRewardReq(self.activityId, data.ID) else UTL.ItemTips.ShowCommonTipsById(data.TaskReward_Table[1].TaskRewardID) end end end end function UIAnniversaryPrepare:SetCellInfo(cellTable, data) local taskReward = data.TaskReward_Table[1] local itemData = DataSheetManager.ItemData:GetDataByID(taskReward.TaskRewardID) local itemIcon = string.format(ConstAssetPathConfig.ItemIconPath, itemData.Icon) UIUtils.SetImageByAssetBundle(cellTable.img_Item, itemIcon) UIUtils.SetGray(cellTable.img_Item, false) --道具数量 UTL.Item.SetItemCount(cellTable, taskReward.TaskRewardNum) end return UIAnniversaryPrepare