static SpecialEventManager() { AutoUpdateSpecialEventTimer = new Timer { Interval = TimeSpan .FromHours(1) .TotalMilliseconds }; AutoUpdateSpecialEventTimer.Elapsed += AutoUpdateSpecialEventTimer_Tick; SpecialEventLayers = new Dictionary <string, SpecialEventLayerContent>(); CurrentInstanceName = null; CurrentInstance = null; foreach (var specialEventLayer in GetSpecialEventLayers()) { var name = specialEventLayer .GetType() .Name; name = name .Remove(name.Length - 5, 5); SpecialEventLayers.Add( name, specialEventLayer); } AutoUpdateSpecialEventTimer.Start(); }
#pragma warning disable SS002 // DateTime.Now was referenced private static bool LoadEvent(string specialEventName, SpecialEventLayerContent specialEventLayer) { var currentTime = DateTime.Now; if (!specialEventLayer.EventTimeSatisfied(currentTime) || !specialEventLayer.LoadEvent()) { return(false); } CurrentInstanceName = specialEventName; CurrentInstance = specialEventLayer; MainWindow.Instance.RootLayout.Children.Add(CurrentInstance); MainWindow.Instance.SettingsFlyout.SpecialEventToggle.IsEnabled = true; MainWindow.Instance.SettingsFlyout.SpecialEventEnabled = CurrentInstance.EventEnabled; MainWindow.Instance.SettingsFlyout.BgmVolume = SettingsManager.AppSettings.BgmVolume; MainWindow.Instance.SettingsFlyout.SpecialEventPanel.Visibility = Visibility.Visible; EventUpdated?.Invoke(null, EventArgs.Empty); return(true); }
#pragma warning restore SS002 // DateTime.Now was referenced private static void UnloadEvent() { MainWindow.Instance.SettingsFlyout.SpecialEventPanel.Visibility = Visibility.Collapsed; MainWindow.Instance.SettingsFlyout.SpecialEventToggle.IsEnabled = false; if (CurrentInstance == null) { EventUpdated?.Invoke(null, EventArgs.Empty); return; } CurrentInstance.UnloadEvent(); MainWindow.Instance.RootLayout.Children.Remove(CurrentInstance); CurrentInstanceName = null; CurrentInstance = null; EventUpdated?.Invoke(null, EventArgs.Empty); }