diff --git a/TheArchive.IL2CPP/Features/Dev/PageRundownPopupManager.cs b/TheArchive.IL2CPP/Features/Dev/PageRundownPopupManager.cs new file mode 100644 index 00000000..ce28d83d --- /dev/null +++ b/TheArchive.IL2CPP/Features/Dev/PageRundownPopupManager.cs @@ -0,0 +1,148 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using TheArchive.Core.Attributes; +using TheArchive.Core.FeaturesAPI; +using TheArchive.Interfaces; +using TheArchive.Loader; +using UnityEngine; +using static TheArchive.Utilities.Utils; + +namespace TheArchive.Features.Dev +{ + [HideInModSettings] + [EnableFeatureByDefault] + [DisallowInGameToggle] + [RundownConstraint(RundownFlags.RundownFive, RundownFlags.Latest)] + internal class PageRundownPopupManager : Feature + { + public override string Name => "PopupQueue"; + + public override string Group => FeatureGroups.Dev; + + public override string Description => "Popups, yay!"; + + public static new IArchiveLogger FeatureLogger { get; set; } + + public override void Init() + { + LoaderWrapper.ClassInjector.RegisterTypeInIl2Cpp(); + } + + public class ILoveWhenTheThingCrashesBecauseIdkYaaaaay : MonoBehaviour + { + protected PopupMessage _0; + protected PopupMessage _1; + protected PopupMessage _2; + protected PopupMessage _3; + protected PopupMessage _4; + protected PopupMessage _5; + protected PopupMessage _6; + protected PopupMessage _7; + protected PopupMessage _8; + protected PopupMessage _9; + + public const int MAX_POPUPS = 10; + + private int _count = 0; + + public ILoveWhenTheThingCrashesBecauseIdkYaaaaay(IntPtr ptr) : base(ptr) { } + + // Idk why but it seems to even work above 10 messages lmaoo + public void MagicJankCache(PopupMessage popupMessage) + { + var field = typeof(ILoveWhenTheThingCrashesBecauseIdkYaaaaay).GetField($"_{_count}", AnyBindingFlagss); + + if (field == null) + throw new InvalidOperationException("Please fix this, thanks!"); + + field.SetValue(this, popupMessage); + + _count++; + if(_count >= MAX_POPUPS) + { + _count = 0; + } + } + } + + private static readonly Queue _popupQueue = new Queue(); + private static ILoveWhenTheThingCrashesBecauseIdkYaaaaay _cache; + + public static void ShowPopup(PopupMessage popupMessage) + { + if(MainMenuGuiLayer.Current?.PageRundownNew == null) + { + FeatureLogger.Error("Called too early!"); + return; + } + + if (!MainMenuGuiLayer.Current.PageRundownNew.isActiveAndEnabled) + { + var pageRD = MainMenuGuiLayer.Current.PageRundownNew.gameObject; + + var enabledListener = pageRD.GetComponent(); + + if (enabledListener == null) + { + enabledListener = pageRD.AddComponent(); + _cache = pageRD.AddComponent(); + + enabledListener.OnEnabledSelf += PageRundownEnabled; + } + + _cache.MagicJankCache(popupMessage); + _popupQueue.Enqueue(popupMessage); + return; + } + + try + { + GlobalPopupMessageManager.ShowPopup(popupMessage); + } + catch (Exception ex) + { + FeatureLogger.Error("Failed to show single popup."); + FeatureLogger.Exception(ex); + } + } + + private static bool _runningAllPopups = false; + private static void PageRundownEnabled(GameObject go) + { + if (_popupQueue.Count <= 0) + return; + + if (_runningAllPopups) + return; + + LoaderWrapper.StartCoroutine(ShowAllPopups()); + } + + private static IEnumerator ShowAllPopups() + { + if (_runningAllPopups) + yield break; + + _runningAllPopups = true; + yield return new WaitForSeconds(0.1f); + + while (_popupQueue.Count > 0) + { + try + { + var popupMessage = _popupQueue.Dequeue(); + + GlobalPopupMessageManager.ShowPopup(popupMessage); + } + catch (Exception ex) + { + FeatureLogger.Error("Failed to show popup."); + FeatureLogger.Exception(ex); + } + } + + _runningAllPopups = false; + } + } +} diff --git a/TheArchive.IL2CPP/Features/Dev/UpdateNotifier.cs b/TheArchive.IL2CPP/Features/Dev/UpdateNotifier.cs index 4949cc27..865d53ff 100644 --- a/TheArchive.IL2CPP/Features/Dev/UpdateNotifier.cs +++ b/TheArchive.IL2CPP/Features/Dev/UpdateNotifier.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Linq; using TheArchive.Core.Attributes; using TheArchive.Core.Attributes.Feature.Settings; @@ -81,6 +82,7 @@ public override void OnButtonPressed(ButtonSetting setting) { UpdateChecker.CheckForUpdate((releaseInfo) => { + MainMenuGuiLayer.Current.ChangePage(eCM_MenuPage.CMP_RUNDOWN_NEW); ShowUpdatesPopup(showUpToDate: true); }); } @@ -140,7 +142,7 @@ public static void ShowUpdatesPopup(bool showUpToDate = false) updateText = $"{updateText}\n\n(This can be turned off in mod settings!)\n[Mod Settings] > [{FeatureGroups.ArchiveCore.Name}] > [{nameof(UpdateNotifier)}]"; } - GlobalPopupMessageManager.ShowPopup(new PopupMessage() + PageRundownPopupManager.ShowPopup(new PopupMessage() { BlinkInContent = true, BlinkTimeInterval = 0.2f, diff --git a/TheArchive.IL2CPP/Features/Special/RundownEightReminder.cs b/TheArchive.IL2CPP/Features/Special/RundownEightReminder.cs index f146436a..0f5675aa 100644 --- a/TheArchive.IL2CPP/Features/Special/RundownEightReminder.cs +++ b/TheArchive.IL2CPP/Features/Special/RundownEightReminder.cs @@ -3,6 +3,7 @@ using TheArchive.Core.Attributes; using TheArchive.Core.Attributes.Feature.Settings; using TheArchive.Core.FeaturesAPI; +using TheArchive.Features.Dev; using TheArchive.Features.QoL; using TheArchive.Loader; using UnityEngine; @@ -89,7 +90,7 @@ public static void ShowReminderPopup() var updateText = $"Hi, quick reminder that you have {noStoryDialog.Name} <#0f0>enabled and that might impact your Rundown 8 experience!\n\nConsider turning it <#F00>off in mod settings if you care about the Story!\n\nYou can find it under:\n[Mod Settings] > [{noStoryDialog.Group}] > [{noStoryDialog.Name}]"; - GlobalPopupMessageManager.ShowPopup(new PopupMessage() + PageRundownPopupManager.ShowPopup(new PopupMessage() { BlinkInContent = true, BlinkTimeInterval = 0.2f,