| | 1 | | using DCL.Helpers; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public class FriendsHUDView : MonoBehaviour |
| | 7 | | { |
| | 8 | | public const string NOTIFICATIONS_ID = "Friends"; |
| 1 | 9 | | static readonly int ANIM_PROPERTY_SELECTED = Animator.StringToHash("Selected"); |
| | 10 | | const string VIEW_PATH = "FriendsHUD"; |
| | 11 | | const int PREINSTANTIATED_FRIENDS_ENTRIES = 25; |
| | 12 | | const int PREINSTANTIATED_FRIENDS_REQUEST_ENTRIES = 5; |
| | 13 | |
|
| | 14 | | public Button closeButton; |
| | 15 | | public Button friendsButton; |
| | 16 | | public Button friendRequestsButton; |
| | 17 | | public FriendsTabView friendsList; |
| | 18 | | public FriendRequestsTabView friendRequestsList; |
| | 19 | | public GameObject spinner; |
| | 20 | |
|
| 23 | 21 | | public float notificationsDuration = 3f; |
| | 22 | |
|
| | 23 | | FriendsHUDController controller; |
| | 24 | |
|
| | 25 | | public event System.Action OnClose; |
| | 26 | |
|
| | 27 | | public static FriendsHUDView Create(FriendsHUDController controller) |
| | 28 | | { |
| 22 | 29 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<FriendsHUDView>(); |
| 22 | 30 | | view.Initialize(controller); |
| 22 | 31 | | return view; |
| | 32 | | } |
| | 33 | |
|
| | 34 | | internal List<FriendEntryBase> GetAllEntries() |
| | 35 | | { |
| 0 | 36 | | var result = new List<FriendEntryBase>(); |
| 0 | 37 | | result.AddRange(friendsList.GetAllEntries()); |
| 0 | 38 | | result.AddRange(friendRequestsList.GetAllEntries()); |
| 0 | 39 | | return result; |
| | 40 | | } |
| | 41 | |
|
| | 42 | | public void ShowSpinner() |
| | 43 | | { |
| 1 | 44 | | spinner.gameObject.SetActive(true); |
| | 45 | |
|
| 1 | 46 | | friendsList.gameObject.SetActive(false); |
| 1 | 47 | | friendRequestsList.gameObject.SetActive(false); |
| | 48 | |
|
| 1 | 49 | | friendsButton.interactable = false; |
| 1 | 50 | | friendRequestsButton.interactable = false; |
| 1 | 51 | | } |
| | 52 | |
|
| | 53 | | public void HideSpinner() |
| | 54 | | { |
| 11 | 55 | | spinner.gameObject.SetActive(false); |
| | 56 | |
|
| 11 | 57 | | friendsList.gameObject.SetActive(true); |
| 11 | 58 | | friendRequestsList.gameObject.SetActive(false); |
| | 59 | |
|
| 11 | 60 | | friendsButton.interactable = true; |
| 11 | 61 | | friendsButton.onClick.Invoke(); |
| | 62 | |
|
| 11 | 63 | | friendRequestsButton.interactable = true; |
| 11 | 64 | | } |
| | 65 | |
|
| | 66 | | private void Initialize(FriendsHUDController controller) |
| | 67 | | { |
| 22 | 68 | | this.controller = controller; |
| 22 | 69 | | friendsList.Initialize(this, PREINSTANTIATED_FRIENDS_ENTRIES); |
| 22 | 70 | | friendRequestsList.Initialize(this, PREINSTANTIATED_FRIENDS_REQUEST_ENTRIES); |
| | 71 | |
|
| 22 | 72 | | closeButton.onClick.AddListener(OnCloseButtonPressed); |
| | 73 | |
|
| 22 | 74 | | friendsButton.onClick.AddListener(() => |
| | 75 | | { |
| 37 | 76 | | friendsButton.animator.SetBool(ANIM_PROPERTY_SELECTED, true); |
| 37 | 77 | | friendRequestsButton.animator.SetBool(ANIM_PROPERTY_SELECTED, false); |
| 37 | 78 | | friendsList.gameObject.SetActive(true); |
| 37 | 79 | | friendRequestsList.gameObject.SetActive(false); |
| 37 | 80 | | Utils.ForceUpdateLayout(friendsList.transform as RectTransform); |
| 37 | 81 | | }); |
| | 82 | |
|
| 22 | 83 | | friendRequestsButton.onClick.AddListener(() => |
| | 84 | | { |
| 1 | 85 | | friendsButton.animator.SetBool(ANIM_PROPERTY_SELECTED, false); |
| 1 | 86 | | friendRequestsButton.animator.SetBool(ANIM_PROPERTY_SELECTED, true); |
| 1 | 87 | | friendsList.gameObject.SetActive(false); |
| 1 | 88 | | friendRequestsList.gameObject.SetActive(true); |
| 1 | 89 | | Utils.ForceUpdateLayout(friendRequestsList.transform as RectTransform); |
| 1 | 90 | | }); |
| | 91 | |
|
| 22 | 92 | | if (friendsButton.interactable) |
| 22 | 93 | | friendsButton.onClick.Invoke(); |
| 22 | 94 | | } |
| | 95 | |
|
| | 96 | | public void OnCloseButtonPressed() |
| | 97 | | { |
| 0 | 98 | | controller.SetVisibility(false); |
| 0 | 99 | | OnClose?.Invoke(); |
| 0 | 100 | | } |
| | 101 | |
|
| | 102 | | #if UNITY_EDITOR |
| | 103 | | [ContextMenu("AddFakeRequestReceived")] |
| | 104 | | public void AddFakeRequestReceived() |
| | 105 | | { |
| 0 | 106 | | string id1 = Random.Range(0, 1000000).ToString(); |
| 0 | 107 | | UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel() |
| | 108 | | { |
| | 109 | | userId = id1, |
| | 110 | | name = "Pravus-" + id1 |
| | 111 | | }); |
| | 112 | |
|
| 0 | 113 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 114 | | { |
| | 115 | | userId = id1, |
| | 116 | | action = FriendshipAction.REQUESTED_FROM |
| | 117 | | }); |
| 0 | 118 | | } |
| | 119 | |
|
| | 120 | | [ContextMenu("AddFakeRequestSent")] |
| | 121 | | public void AddFakeRequestSent() |
| | 122 | | { |
| 0 | 123 | | string id1 = Random.Range(0, 1000000).ToString(); |
| | 124 | |
|
| 0 | 125 | | UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel() |
| | 126 | | { |
| | 127 | | userId = id1, |
| | 128 | | name = "Brian-" + id1 |
| | 129 | | }); |
| | 130 | |
|
| 0 | 131 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 132 | | { |
| | 133 | | userId = id1, |
| | 134 | | action = FriendshipAction.REQUESTED_TO |
| | 135 | | }); |
| 0 | 136 | | } |
| | 137 | |
|
| | 138 | | [ContextMenu("AddFakeRequestSentAccepted")] |
| | 139 | | public void AddFakeRequestSentAccepted() |
| | 140 | | { |
| 0 | 141 | | string id1 = Random.Range(0, 1000000).ToString(); |
| | 142 | |
|
| 0 | 143 | | UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel() |
| | 144 | | { |
| | 145 | | userId = id1, |
| | 146 | | name = "Brian-" + id1 |
| | 147 | | }); |
| | 148 | |
|
| 0 | 149 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 150 | | { |
| | 151 | | userId = id1, |
| | 152 | | action = FriendshipAction.REQUESTED_TO |
| | 153 | | }); |
| | 154 | |
|
| 0 | 155 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 156 | | { |
| | 157 | | userId = id1, |
| | 158 | | action = FriendshipAction.APPROVED |
| | 159 | | }); |
| 0 | 160 | | } |
| | 161 | |
|
| | 162 | | [ContextMenu("AddFakeOnlineFriend")] |
| | 163 | | public void AddFakeOnlineFriend() |
| | 164 | | { |
| 0 | 165 | | string id1 = Random.Range(0, 1000000).ToString(); |
| | 166 | |
|
| 0 | 167 | | UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel() |
| | 168 | | { |
| | 169 | | userId = id1, |
| | 170 | | name = "Brian-" + id1 |
| | 171 | | }); |
| | 172 | |
|
| 0 | 173 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 174 | | { |
| | 175 | | userId = id1, |
| | 176 | | action = FriendshipAction.APPROVED |
| | 177 | | }); |
| | 178 | |
|
| 0 | 179 | | FriendsController.i.UpdateUserStatus(new FriendsController.UserStatus() |
| | 180 | | { userId = id1, presence = PresenceStatus.ONLINE }); |
| 0 | 181 | | } |
| | 182 | |
|
| | 183 | | [ContextMenu("AddFakeOfflineFriend")] |
| | 184 | | public void AddFakeOfflineFriend() |
| | 185 | | { |
| 0 | 186 | | string id1 = Random.Range(0, 1000000).ToString(); |
| | 187 | |
|
| 0 | 188 | | UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel() |
| | 189 | | { |
| | 190 | | userId = id1, |
| | 191 | | name = "Pravus-" + id1 |
| | 192 | | }); |
| | 193 | |
|
| 0 | 194 | | FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage() |
| | 195 | | { |
| | 196 | | userId = id1, |
| | 197 | | action = FriendshipAction.APPROVED |
| | 198 | | }); |
| | 199 | |
|
| 0 | 200 | | FriendsController.i.UpdateUserStatus(new FriendsController.UserStatus() |
| | 201 | | { userId = id1, presence = PresenceStatus.OFFLINE }); |
| 0 | 202 | | } |
| | 203 | | #endif |
| | 204 | | } |