| | 1 | | using System.Collections.Generic; |
| | 2 | | using DCL.NotificationModel; |
| | 3 | |
|
| | 4 | | namespace DCL.Components |
| | 5 | | { |
| | 6 | | internal class CameraModeAreasController |
| | 7 | | { |
| | 8 | | private const string NOTIFICATION_GROUP = "CameraModeLockedByScene"; |
| | 9 | | private const float NOTIFICATION_TIME = 3; |
| | 10 | |
|
| 1 | 11 | | private static readonly Model notificationModel = new Model() |
| | 12 | | { |
| | 13 | | type = Type.CAMERA_MODE_LOCKED_BY_SCENE, |
| | 14 | | groupID = NOTIFICATION_GROUP, |
| | 15 | | timer = NOTIFICATION_TIME |
| | 16 | | }; |
| | 17 | |
|
| | 18 | | private CameraMode.ModeId initialCameraMode; |
| 4 | 19 | | private readonly List<ICameraModeArea> insideAreasList = new List<ICameraModeArea>(); |
| | 20 | |
|
| | 21 | | public void AddInsideArea(in ICameraModeArea area) |
| | 22 | | { |
| 17 | 23 | | if (!IsPlayerInsideAnyArea()) |
| | 24 | | { |
| 10 | 25 | | initialCameraMode = CommonScriptableObjects.cameraMode.Get(); |
| 10 | 26 | | CommonScriptableObjects.cameraModeInputLocked.Set(true); |
| 10 | 27 | | ShowCameraModeLockedNotification(); |
| | 28 | | } |
| | 29 | |
|
| 17 | 30 | | CommonScriptableObjects.cameraMode.Set(area.cameraMode); |
| 17 | 31 | | insideAreasList.Add(area); |
| 17 | 32 | | } |
| | 33 | |
|
| | 34 | | public void RemoveInsideArea(in ICameraModeArea area) |
| | 35 | | { |
| 17 | 36 | | int affectingAreasCount = insideAreasList.Count; |
| | 37 | |
|
| 17 | 38 | | if (affectingAreasCount == 0) |
| | 39 | | { |
| 0 | 40 | | return; |
| | 41 | | } |
| | 42 | |
|
| 17 | 43 | | if (affectingAreasCount == 1) |
| | 44 | | { |
| | 45 | | // reset to initial state of camera mode |
| 10 | 46 | | ResetCameraMode(); |
| | 47 | |
|
| | 48 | | //remove notification |
| 10 | 49 | | HideCameraModeLockedNotification(); |
| 10 | 50 | | } |
| 7 | 51 | | else if (IsTheActivelyAffectingArea(area)) |
| | 52 | | { |
| | 53 | | // set camera mode to the previous area the player is in |
| 1 | 54 | | CommonScriptableObjects.cameraMode.Set(insideAreasList[affectingAreasCount - 2].cameraMode); |
| | 55 | | } |
| | 56 | |
|
| 17 | 57 | | insideAreasList.Remove(area); |
| 17 | 58 | | } |
| | 59 | |
|
| | 60 | | public void ChangeAreaMode(in ICameraModeArea area, in CameraMode.ModeId mode) |
| | 61 | | { |
| 2 | 62 | | if (IsTheActivelyAffectingArea(area)) |
| | 63 | | { |
| 2 | 64 | | CommonScriptableObjects.cameraMode.Set(mode); |
| | 65 | | } |
| 2 | 66 | | } |
| | 67 | |
|
| | 68 | | private bool IsPlayerInsideAnyArea() |
| | 69 | | { |
| 0 | 70 | | return insideAreasList.Count > 0; |
| | 71 | | } |
| | 72 | |
|
| | 73 | | private void ResetCameraMode() |
| | 74 | | { |
| 10 | 75 | | CommonScriptableObjects.cameraMode.Set(initialCameraMode); |
| 10 | 76 | | CommonScriptableObjects.cameraModeInputLocked.Set(false); |
| 10 | 77 | | } |
| | 78 | |
|
| | 79 | | private bool IsTheActivelyAffectingArea(in ICameraModeArea area) |
| | 80 | | { |
| 9 | 81 | | int affectingAreasCount = insideAreasList.Count; |
| | 82 | |
|
| 9 | 83 | | if (affectingAreasCount == 0) |
| | 84 | | { |
| 0 | 85 | | return false; |
| | 86 | | } |
| | 87 | |
|
| 9 | 88 | | return insideAreasList[affectingAreasCount - 1] == area; |
| | 89 | | } |
| | 90 | |
|
| | 91 | | internal virtual void ShowCameraModeLockedNotification() |
| | 92 | | { |
| 10 | 93 | | NotificationsController.i?.ShowNotification(notificationModel); |
| 10 | 94 | | } |
| | 95 | |
|
| | 96 | | internal virtual void HideCameraModeLockedNotification() |
| | 97 | | { |
| 10 | 98 | | NotificationsController.i?.DismissAllNotifications(NOTIFICATION_GROUP); |
| 10 | 99 | | } |
| | 100 | | } |
| | 101 | | } |