local NewYear_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') NewYear_Controller.ViewName = { UINewYearMain = "UINewYearMain", UINewYearGiftMain = "UINewYearGiftMain", UINewYearGiftPopup = "UINewYearGiftPopup", UINewYearLoginReward = "UINewYearLoginReward", UINewYearStorePanel = "UINewYearStorePanel", UINewYearTaskPanel = "UINewYearTaskPanel", UINewYearPray = "UINewYearPray", UINewYearPrayReward = "UINewYearPrayReward", UINewYearPrayMyExchange = "UINewYearPrayMyExchange", UINewYearExchangeConfirm = "UINewYearExchangeConfirm", UINewYearExchange = "UINewYearExchange", UINewYearExchangeInitiate = "UINewYearExchangeInitiate", SceneQuizMain = "SceneQuizMain", SceneQuizReward = "SceneQuizReward", SceneQuizBetView = "SceneQuizBetView", SceneQuizPreliminary = "SceneQuizPreliminary", SceneQuizRank = "SceneQuizRank", SceneQuizBattleInfo = "SceneQuizBattleInfo", } NewYear_Controller.ViewTitle = { ExchangeConfirmTitle = "ExchangeConfirmTitle", ExchangeInitiateTitle = "ExchangeInitiateTitle", PrayRewardTitle = "PrayRewardTitle", PrayMyExchangeTitle = "PrayMyExchangeTitle", GiftPopupTitle = "GiftPopupTitle", } function NewYear_Controller.OnStartup() EventSystem.Regist(EventID.BagItem_Update, private.RefreshRedPoint) EventSystem.Regist(EventID.UI_OACommon_RedPointChanged, private.RefreshRedPoint) EventSystem.Regist(EventID.UI_DirectGift_GiftInfoUpdate, private.RefreshRedPoint) EventSystem.Regist(EventID.UI_NewYear_LoginRewardRefresh, private.RefreshRedPoint) EventSystem.Regist(EventID.UI_NewYear_ExchangeExchangeSuccess, private.RefreshRedPoint) EventSystem.Regist(EventID.UI_SceneQuiz_StageChange, private.RefreshRedPoint) EventSystem.Regist(EventID.UI_SceneQuiz_MyInfoRefresh, private.RefreshRedPoint) EventSystem.Regist(EventID.DeepLink_Event,private.OnDeepLink) EventSystem.Regist(EventID.UI_OperationActivity_InfoChanged, private.CheckFuncOpenIssue) EventSystem.Regist(EventID.UI_ExpelMonster_MainUIClosed, private.OnExpelMonsterMainUIClosed) private.ActivityType = MDL.OperationActivity.ActivityType.NewYear private.tempWeightDict = {} private.tempTotalWeight = {} private.activityEndTimerHandle = {} end function NewYear_Controller.OpenCurrencyPanel(viewName, activityType, activityId, currency_Info) local modeData = MDL.OperationActivity.ActivityBaseData[activityType]:GetDataByActivityID(activityId) local prefabData = DataSheetManager.NewYearPrefabData:GetDataByModeID(modeData.PrefabMode) CTL.Currency.OpenCurrencyPanel(private.GetViewClassPath(viewName), currency_Info, CTL.Currency.GetCurrentTypeIds(prefabData[viewName])) end function private.RefreshRedPoint() local info = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType) if info then local activityId for i, v in pairs(info) do if CTL.OperationActivity.IsOperationActivityOpen(v) then activityId = i break end end if activityId and activityId > 0 then if CTL.OACommon.IsHasTaskRedPoint(activityId) or CTL.OACommon.IsHasGiftRedPoint(activityId) or NewYear_Controller.IsHasLoginReward(activityId) or NewYear_Controller.IsCanPrayReward(activityId) or NewYear_Controller.IsShowActivityRedPoint(activityId) or CTL.SceneQuiz.IsShowRedPoint() then CTL.RedPoint.AddRedPoint(CTL.RedPoint.RedPointKey.NewYear_RegularFunctions) else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.NewYear_RegularFunctions) end else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.NewYear_RegularFunctions) end else CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.NewYear_RegularFunctions) end EventSystem.Dispatch(EventID.UI_NewYear_RefreshRp) end function NewYear_Controller.IsHasLoginReward(activityId) local loginReward = MDL.NewYear.GetLoginReward(activityId) if loginReward then local sheetData = MDL.OperationActivity.NewYearLoginReward and MDL.OperationActivity.NewYearLoginReward:GetDataByActivityID_Day(activityId) if sheetData then for i, v in ipairs(sheetData) do if loginReward[i] == 0 then return true end end end end return false end function NewYear_Controller.IsCanPrayReward(activityId) local modeData = MDL.OperationActivity.ActivityBaseData[private.ActivityType]:GetDataByActivityID(activityId) --祈福材料是否齐全 for i, v in ipairs(modeData.LuckyBagItem) do if UTL.Item.GetItemStockCount(v) == 0 then return false end end return true end --整个活动期间只显示一次红点 local NewYearActivityRpKey = "NewYearActivityRpKey" function NewYear_Controller.IsShowActivityRedPoint(activityId) if not private.tempSaveId then private.tempSaveId = PersistentData.PlayerData:Get(NewYearActivityRpKey, 0) end return private.tempSaveId ~= activityId end function NewYear_Controller.SetActivityRedPoint(activityId) if private.tempSaveId ~= activityId then PersistentData.PlayerData:Set(NewYearActivityRpKey, activityId, true) private.tempSaveId = activityId private.RefreshRedPoint() end end function NewYear_Controller.GetRandomDialogue(groupId) if not private.tempWeightDict[groupId] then local totalWeight = 0 private.tempWeightDict[groupId] = {} for index, v in DataSheetManager.ActivityText:GetDataByGroupID_ChildID(groupId) do local weight = v.Weight for i = totalWeight, totalWeight + weight do private.tempWeightDict[groupId][i] = v.ChildID end totalWeight = totalWeight + weight end private.tempTotalWeight[groupId] = totalWeight end local randomWeight = math.random(1, private.tempTotalWeight[groupId]) local randomChildId = private.tempWeightDict[groupId][randomWeight] local randomData = DataSheetManager.ActivityText:GetDataByGroupID_ChildID(groupId, randomChildId) if not randomData then logging.error(LTAG.ERROR, "新年活动:随机权重", randomWeight, "没有落在有效区间", private.tempWeightDict[groupId], "中,找不到有效ChildID,使用默认的第一个数据替代!!!请程序检查!!!") randomData = DataSheetManager.ActivityText:GetDataByGroupID_ChildID(groupId, 1) end return randomData.Sentence end function NewYear_Controller.SetCommonTitle(activityId, viewTitle, commonPop) local titleData = NewYear_Controller.GetViewPrefabPath(activityId, viewTitle) UTL.Item.SetLocalizationImage(commonPop.loc_Title, commonPop.img_Title, titleData[1]) commonPop.img_Title:SetNativeSize() UIUtils.SetLabelText(commonPop.txt_Title, Const_IDS[titleData[2]]) end function NewYear_Controller.OpenMainPanel() local info = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType) if info then for activityId, v in pairs(info) do if CTL.OperationActivity.IsOperationActivityOpen(v) then NewYear_Controller.OpenAndPushAllView(activityId, NewYear_Controller.ViewName.UINewYearMain, {activityId = activityId}) return true end end end return false end function private.OnDeepLink(key) if key ~= LuaConst.Deeplink.Ceremony then return end --在强制引导时不打开,清掉deeplink存储 if CTL.PlayerGuide.IsForceGuiding() then return end local newYearType = MDL.OperationActivity.ActivityType.NewYear local activityId = private.GetCurActivityId() if activityId > 0 and CTL.OperationActivity.IsOperationActivityTypeOpen(newYearType) and CTL.OperationActivity.IsOperationActivityTypeUnlock(newYearType) and MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.NewYear) then --在城镇里 if BattleDataGetter.IsOnlineTownLevel() then local mainViewPath = private.GetViewClassPath(NewYear_Controller.ViewName.UINewYearMain) if not UIManager.IsViewOpened(mainViewPath) then NewYear_Controller.OpenMainPanel() end end end end function private.GetCurActivityId() local info = MDL.OperationActivity.GetOperationActivityInfo(MDL.OperationActivity.ActivityType.NewYear) if info then for i, v in pairs(info) do if CTL.OperationActivity.IsOperationActivityOpen(v) then return i end end end return 0 end function NewYear_Controller.OpenAndPushAllView(activityId, viewName, context) UIManager.OpenAndPushAll(private.GetViewClassPath(viewName), context, NewYear_Controller.GetViewPrefabPath(activityId, viewName)) end function NewYear_Controller.OpenView(activityId, viewName, context) UIManager.OpenView(private.GetViewClassPath(viewName), context, NewYear_Controller.GetViewPrefabPath(activityId, viewName)) end function private.CheckFuncOpenIssue() if CTL.OperationActivity.IsOperationActivityTypeOpen(private.ActivityType) and CTL.OperationActivity.IsOperationActivityTypeUnlock(private.ActivityType) and MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.NewYear) then return end if UIManager.IsViewOpened(private.GetViewClassPath(NewYear_Controller.ViewName.UINewYearMain)) then CTL.Tips.AddTipsMsg(Const_IDS.IDS_GoldHeroActivity_TimeHint3) for _, value in pairs(NewYear_Controller.ViewName) do UIManager.CloseView(private.GetViewClassPath(value)) UIManager.RecoverView() end end end --- 获取viewClass脚本路径,因为不同版本界面逻辑相差很小,目前没有新建脚本继承,所以脚本都使用默认ID:1所对应的路径脚本 --- @param viewName prefabData表字段名 function private.GetViewClassPath(viewName) local prefabData = DataSheetManager.NewYearPrefabData:GetDataByModeID(1) if not prefabData then logging.error(LTAG.ERROR, "NewYearPrefabData表中没有modeId为", prefabData, "的数据,请策划检查!!!") return end local viewPath = prefabData[viewName] if not viewPath then logging.error(LTAG.ERROR, "NewYearPrefabData表中modeId为", prefabData, "的数据中没有界面名称为", viewName, "的路径数据,请程序检查!!!") return end return viewPath end function NewYear_Controller.GetViewPrefabPath(activityId, viewName) local modeData = MDL.OperationActivity.ActivityBaseData[private.ActivityType]:GetDataByActivityID(activityId) if not modeData then logging.error(LTAG.ERROR, "AMS表hot16BackGround中没有activityId为", activityId, "的数据,请策划检查!!!") return end local prefabData = DataSheetManager.NewYearPrefabData:GetDataByModeID(modeData.PrefabMode) if not prefabData then logging.error(LTAG.ERROR, "NewYearPrefabData表中没有modeId为", modeData.PrefabMode, "的数据,请策划检查!!!") return end if not prefabData[viewName] then logging.error(LTAG.ERROR, "NewYearPrefabData表中modeId为", modeData.PrefabMode, "的数据中没有界面名称为", viewName, "的路径数据,请程序检查!!!") return end return prefabData[viewName] end function NewYear_Controller.SetEndTimer(activityId) if private.activityEndTimerHandle[activityId] then TimerUtil.Remove(private.activityEndTimerHandle[activityId]) private.activityEndTimerHandle[activityId] = nil end local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType, activityId) if activityInfo then local nowTime = UTL.Time.GetServerTimestamp() local endTime = activityInfo.endTime if endTime > nowTime then local deltaTime = endTime - nowTime if deltaTime <= UTL.Time.TotalSecondsOneDay then private.activityEndTimerHandle[activityId] = TimerUtil.Interval(function() private.EndAndCloseActivity(activityId) end, deltaTime, 1) end else private.EndAndCloseActivity(activityId) end end end function private.EndAndCloseActivity(activityId) logging.log(LTAG.LOG, "NewYear ActivityEnd, activityId: ", activityId) if private.activityEndTimerHandle[activityId] then TimerUtil.Remove(private.activityEndTimerHandle[activityId]) private.activityEndTimerHandle[activityId] = nil end UIManager.CloseView(Const_UI_Lua.UIEnum.UICurrencyExchange) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPayMallPopUp) UIManager.CloseView(Const_UI_Lua.UIEnum.UIBagItemTips) UIManager.CloseView(Const_UI_Lua.UIEnum.OperationActivity.UIGetActivityItemPanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UICommonNoteView) for i, v in pairs(NewYear_Controller.ViewName) do if v~= NewYear_Controller.ViewName.UINewYearMain then UIManager.CloseView(NewYear_Controller.GetViewPrefabPath(activityId, v)) end end local mainViewPath = NewYear_Controller.GetViewPrefabPath(activityId, NewYear_Controller.ViewName.UINewYearMain) if UIManager.IsViewOpened(mainViewPath) then UIManager.CloseView(mainViewPath) UIManager.RecoverView() end end function private.OnExpelMonsterMainUIClosed() local mainViewPath = private.GetViewClassPath(NewYear_Controller.ViewName.UINewYearMain) UIManager.CloseView(mainViewPath) NewYear_Controller.OpenMainPanel() end function NewYear_Controller.IsInCfgNewYearPeriod() local time = DataSheetManager.ConstData:GetDataByID("SpecialNewYearLabelTime").IntListValue if UTL.Time.IsServerInOpeningTime(time[1], time[2]) then return true end return false end --获取直购消耗的货币类型和数量 function NewYear_Controller.GetMoneyIdAndNum(giftID) local giftData = MDL.OperationActivity.CommonGiftReward:GetDataByID(giftID) if giftData.GoldIngot and giftData.GoldIngot > 0 then return MDL.Currency.CurrencyType.GoldIngot, giftData.GoldIngot elseif giftData.DragonJade and giftData.DragonJade > 0 then return MDL.Currency.CurrencyType.DragonJade, giftData.DragonJade end end --礼包购买是否使用的是游戏货币 function NewYear_Controller.IsItemBuyGift(giftID) local giftData = MDL.OperationActivity.CommonGiftReward:GetDataByID(giftID) if giftData.GoldIngot and giftData.GoldIngot > 0 then return true elseif giftData.DragonJade and giftData.DragonJade > 0 then return true end return false end return NewYear_Controller