private void ShowMessage(MessageNotification mn) { mn.message.OnClick(); if (mn.message.ShowDialog()) { for (int i = 0; i < dialogPrefabs.Count; i++) { if (dialogPrefabs[i].CanDisplay(mn.message)) { if ((UnityEngine.Object)messageDialog != (UnityEngine.Object)null) { UnityEngine.Object.Destroy(messageDialog.gameObject); messageDialog = null; } messageDialog = Util.KInstantiateUI <MessageDialogFrame>(ScreenPrefabs.Instance.MessageDialogFrame.gameObject, GameScreenManager.Instance.ssOverlayCanvas.gameObject, false); MessageDialog dialog = Util.KInstantiateUI <MessageDialog>(dialogPrefabs[i].gameObject, GameScreenManager.Instance.ssOverlayCanvas.gameObject, false); messageDialog.SetMessage(dialog, mn.message); messageDialog.Show(true); break; } } } Messenger.Instance.RemoveMessage(mn.message); mn.Clear(); }
private void AddNotification(Notification notification) { notifications.Add(notification); notification.Idx = notificationIncrement++; Entry entry = null; entriesByMessage.TryGetValue(notification.titleText, out entry); if (entry == null) { GameObject label; if (notification.Type == NotificationType.Messages) { label = Util.KInstantiateUI(MessagesPrefab, MessagesFolder, false); } else { label = Util.KInstantiateUI(LabelPrefab, LabelsFolder, false); } label.GetComponentInChildren <NotificationAnimator>().Init(); label.gameObject.SetActive(true); KImage componentInChildren = label.GetComponentInChildren <KImage>(true); Button[] componentsInChildren = label.gameObject.GetComponentsInChildren <Button>(); ColorBlock colors = componentsInChildren[0].colors; if (notification.Type == NotificationType.Bad || notification.Type == NotificationType.DuplicantThreatening) { colors.normalColor = badColorBG; } else if (notification.Type == NotificationType.Messages) { colors.normalColor = messageColorBG; Debug.Assert(notification.GetType() == typeof(MessageNotification), $"Notification: \"{notification.titleText}\" is not of type MessageNotification"); componentsInChildren[1].onClick.AddListener(delegate { List <Notification> list = notifications.FindAll((Notification n) => n.titleText == notification.titleText); foreach (Notification item in list) { MessageNotification messageNotification = (MessageNotification)item; Messenger.Instance.RemoveMessage(messageNotification.message); messageNotification.Clear(); } }); } else if (notification.Type == NotificationType.Tutorial) { colors.normalColor = warningColorBG; } else { colors.normalColor = normalColorBG; } componentsInChildren[0].colors = colors; componentsInChildren[0].onClick.AddListener(delegate { OnClick(entry); }); if (notification.ToolTip != null) { label.GetComponentInChildren <ToolTip>().OnToolTip = delegate { ToolTip componentInChildren2 = label.GetComponentInChildren <ToolTip>(); componentInChildren2.ClearMultiStringTooltip(); componentInChildren2.AddMultiStringTooltip(notification.ToolTip(entry.notifications, notification.tooltipData), TooltipTextStyle); return(string.Empty); }; } entry = new Entry(label); entriesByMessage[notification.titleText] = entry; entries.Add(entry); LocText[] componentsInChildren2 = label.GetComponentsInChildren <LocText>(); LocText[] array = componentsInChildren2; foreach (LocText locText in array) { switch (notification.Type) { case NotificationType.Bad: locText.color = badColor; componentInChildren.sprite = icon_bad; break; case NotificationType.DuplicantThreatening: locText.color = badColor; componentInChildren.sprite = icon_bad; break; case NotificationType.Tutorial: locText.color = warningColor; componentInChildren.sprite = icon_warning; break; case NotificationType.Messages: locText.color = messageColor; componentInChildren.sprite = icon_message; break; default: locText.color = normalColor; componentInChildren.sprite = icon_normal; break; } componentInChildren.color = locText.color; string str = string.Empty; if (KTime.Instance.UnscaledGameTime - initTime > 5f && notification.playSound) { PlayDingSound(notification, 0); } else { str = "too early"; } if (AudioDebug.Get().debugNotificationSounds) { Debug.Log("Notification(" + notification.titleText + "):" + str); } } } entry.Add(notification); entry.UpdateMessage(notification, true); dirty = true; SortNotifications(); }