| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | public class NotificationsController : MonoBehaviour |
| | 4 | | { |
| | 5 | | const int NOTIFICATION_DURATION = 5; |
| | 6 | |
|
| 0 | 7 | | public static NotificationsController i { get; private set; } |
| | 8 | | public static bool disableWelcomeNotification = false; |
| | 9 | |
|
| 0 | 10 | | public bool allowNotifications { get; set; } |
| | 11 | |
|
| 206 | 12 | | void Awake() { i = this; } |
| | 13 | |
|
| | 14 | | NotificationHUDController controller; |
| | 15 | |
|
| | 16 | | public void Initialize(NotificationHUDController controller) |
| | 17 | | { |
| 0 | 18 | | this.controller = controller; |
| 0 | 19 | | allowNotifications = true; |
| 0 | 20 | | } |
| | 21 | |
|
| 20 | 22 | | public void Dispose() { controller.Dispose(); } |
| | 23 | |
|
| | 24 | | public void ShowNotificationFromJson(string notificationJson) |
| | 25 | | { |
| 0 | 26 | | if (!allowNotifications) |
| 0 | 27 | | return; |
| | 28 | |
|
| 0 | 29 | | Notification.Model model = JsonUtility.FromJson<Notification.Model>(notificationJson); |
| 0 | 30 | | ShowNotification(model); |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | public void ShowNotification(Notification.Model notification) |
| | 34 | | { |
| 4 | 35 | | if (!allowNotifications) |
| 4 | 36 | | return; |
| | 37 | |
|
| 0 | 38 | | controller?.ShowNotification(notification); |
| 0 | 39 | | } |
| | 40 | |
|
| | 41 | | public void ShowNotification(Notification notification) |
| | 42 | | { |
| 2 | 43 | | if (!allowNotifications) |
| 0 | 44 | | return; |
| | 45 | |
|
| 2 | 46 | | controller?.ShowNotification(notification); |
| 2 | 47 | | } |
| | 48 | |
|
| 5 | 49 | | public void DismissAllNotifications(string groupID) { controller?.DismissAllNotifications(groupID); } |
| | 50 | |
|
| | 51 | | public void ShowWelcomeNotification() |
| | 52 | | { |
| 0 | 53 | | if (!allowNotifications || disableWelcomeNotification) |
| 0 | 54 | | return; |
| | 55 | |
|
| | 56 | | //TODO(Brian): This should be triggered entirely by kernel |
| 0 | 57 | | string notificationText = $"Welcome, {UserProfile.GetOwnUserProfile().userName}!"; |
| 0 | 58 | | Vector2Int currentCoords = CommonScriptableObjects.playerCoords.Get(); |
| 0 | 59 | | string parcelName = MinimapMetadata.GetMetadata().GetSceneInfo(currentCoords.x, currentCoords.y)?.name; |
| | 60 | |
|
| 0 | 61 | | if (!string.IsNullOrEmpty(parcelName)) |
| | 62 | | { |
| 0 | 63 | | notificationText += $" You are in {parcelName} {currentCoords.x}, {currentCoords.y}"; |
| | 64 | | } |
| | 65 | |
|
| 0 | 66 | | Notification.Model model = new Notification.Model() |
| | 67 | | { |
| | 68 | | message = notificationText, |
| | 69 | | scene = "", |
| | 70 | | type = NotificationFactory.Type.GENERIC_WITHOUT_BUTTON, |
| | 71 | | timer = NOTIFICATION_DURATION |
| | 72 | | }; |
| | 73 | |
|
| 0 | 74 | | controller.ShowNotification(model); |
| 0 | 75 | | } |
| | 76 | | } |