Ejemplo n.º 1
0
        public static void CreateAndAddNotification(GermExposureMonitor.Instance monitor, string sicknessName)
        {
            string text = string.Format(DUPE_EXPOSED_TO_GERMS_NOTIFICATION, sicknessName);

            Notification.ClickCallback callback = new Notification.ClickCallback(Notification_Callback);
            MinionIdentity             minion   = monitor.gameObject.GetComponent <MinionIdentity>();
            ShowLocationObject         slo      = new ShowLocationObject(minion);

            slo.ShowLocation = MinionsLoaded && showLocation;
            Notification notification = new Notification(text, NotificationType.BadMinor, HashedString.Invalid,
                                                         (List <Notification> n, object d) => string.Format(DUPE_EXPOSED_TO_GERMS_TOOLTIP, sicknessName) + n.ReduceMessages(true),
                                                         null, false, 0, callback, slo);

            monitor.gameObject.AddOrGet <Notifier>().Add(notification);
            Action <object> act = null;

            act = x =>
            {
                monitor.gameObject.AddOrGet <Notifier>().Remove(notification);
                monitor.Unsubscribe((int)GameHashes.SleepFinished, act);
                monitor.Unsubscribe((int)GameHashes.DuplicantDied, act);
            };
            monitor.Subscribe((int)GameHashes.SleepFinished, act);
            monitor.Subscribe((int)GameHashes.DuplicantDied, act);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a notification, with a workaround for the new Automation Update.
 /// </summary>
 /// <param name="title">The notification title.</param>
 /// <param name="type">The notification type.</param>
 /// <param name="consolidate">The function to consolidate stacked notifications.</param>
 /// <param name="onClick">The function to call when the notification is selected.</param>
 /// <returns>The resulting notification.</returns>
 private static Notification CreateNotification(string title, NotificationType type,
                                                Func <List <Notification>, object, string> consolidate,
                                                Notification.ClickCallback onClick)
 {
     return(new Notification(title, type, HashedString.Invalid, consolidate,
                             null, false, 0.0f, onClick));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a notification, with a workaround for the new Automation Update.
        /// </summary>
        /// <param name="title">The notification title.</param>
        /// <param name="type">The notification type.</param>
        /// <param name="consolidate">The function to consolidate stacked notifications.</param>
        /// <param name="onClick">The function to call when the notification is selected.</param>
        /// <returns>The resulting notification.</returns>
        private static Notification CreateNotification(string title, NotificationType type,
                                                       Func <List <Notification>, object, string> consolidate,
                                                       Notification.ClickCallback onClick)
        {
            Notification notify = null;

            try {
                // A bit expensive to catch the exception vs testing the version, but it runs
                // only on the testing release, and does not happen often
                notify = DoCreateNotification(title, type, consolidate, onClick);
            } catch (MissingMethodException) {
                // Use reflection!
                var constructor = typeof(Notification).GetConstructor(BindingFlags.Instance |
                                                                      BindingFlags.Public | BindingFlags.NonPublic, null, NEW_NOTIFICATION_TYPES,
                                                                      null);
                if (constructor != null)
                {
                    try {
                        notify = constructor.Invoke(new object[] {
                            // New signature adds volume_attenuation (set it false)
                            title, type, HashedString.Invalid, consolidate, null, false, 0.0f,
                            onClick, null, null, false
                        }) as Notification;
                    } catch (Exception e) {
                        PUtil.LogException(e);
                    }
                }
                if (notify == null)
                {
                    PUtil.LogWarning("Unable to create notification - no constructor");
                }
            }
            return(notify);
        }