| | 1 | | using System; |
| | 2 | | using SocialFeaturesAnalytics; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.UI; |
| | 5 | |
|
| | 6 | | public class FriendsHUDComponentView : BaseComponentView, IFriendsHUDComponentView |
| | 7 | | { |
| | 8 | | private const int FRIENDS_LIST_TAB_INDEX = 0; |
| | 9 | | private const int FRIENDS_REQUEST_TAB_INDEX = 1; |
| | 10 | |
|
| | 11 | | [SerializeField] internal GameObject loadingSpinner; |
| | 12 | | [SerializeField] internal Button closeButton; |
| | 13 | | [SerializeField] internal Button friendsTabFocusButton; |
| | 14 | | [SerializeField] internal Button friendRequestsTabFocusButton; |
| | 15 | | [SerializeField] internal FriendsTabComponentView friendsTab; |
| | 16 | | [SerializeField] internal FriendRequestsTabComponentView friendRequestsTab; |
| | 17 | | [SerializeField] private Model model; |
| | 18 | |
|
| | 19 | | public event Action<FriendRequestEntryModel> OnFriendRequestApproved |
| | 20 | | { |
| 1 | 21 | | add => friendRequestsTab.OnFriendRequestApproved += value; |
| 1 | 22 | | remove => friendRequestsTab.OnFriendRequestApproved -= value; |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public event Action<FriendRequestEntryModel> OnCancelConfirmation |
| | 26 | | { |
| 1 | 27 | | add => friendRequestsTab.OnCancelConfirmation += value; |
| 1 | 28 | | remove => friendRequestsTab.OnCancelConfirmation -= value; |
| | 29 | | } |
| | 30 | |
|
| | 31 | | public event Action<FriendRequestEntryModel> OnRejectConfirmation |
| | 32 | | { |
| 1 | 33 | | add => friendRequestsTab.OnRejectConfirmation += value; |
| 1 | 34 | | remove => friendRequestsTab.OnRejectConfirmation -= value; |
| | 35 | | } |
| | 36 | |
|
| | 37 | | public event Action<string> OnFriendRequestSent |
| | 38 | | { |
| 1 | 39 | | add => friendRequestsTab.OnFriendRequestSent += value; |
| 1 | 40 | | remove => friendRequestsTab.OnFriendRequestSent -= value; |
| | 41 | | } |
| | 42 | |
|
| | 43 | | public event Action<FriendEntryModel> OnWhisper |
| | 44 | | { |
| 1 | 45 | | add => friendsTab.OnWhisper += value; |
| 1 | 46 | | remove => friendsTab.OnWhisper -= value; |
| | 47 | | } |
| | 48 | |
|
| | 49 | | public event Action<string> OnDeleteConfirmation |
| | 50 | | { |
| 0 | 51 | | add => friendsTab.OnDeleteConfirmation += value; |
| 1 | 52 | | remove => friendsTab.OnDeleteConfirmation -= value; |
| | 53 | | } |
| | 54 | |
|
| | 55 | | public event Action OnRequireMoreFriends |
| | 56 | | { |
| 2 | 57 | | add => friendsTab.OnRequireMoreEntries += value; |
| 1 | 58 | | remove => friendsTab.OnRequireMoreEntries -= value; |
| | 59 | | } |
| | 60 | |
|
| | 61 | | public event Action OnRequireMoreFriendRequests |
| | 62 | | { |
| 2 | 63 | | add => friendRequestsTab.OnRequireMoreEntries += value; |
| 1 | 64 | | remove => friendRequestsTab.OnRequireMoreEntries -= value; |
| | 65 | | } |
| | 66 | |
|
| | 67 | | public event Action<string> OnSearchFriendsRequested |
| | 68 | | { |
| 1 | 69 | | add => friendsTab.OnSearchRequested += value; |
| 1 | 70 | | remove => friendsTab.OnSearchRequested -= value; |
| | 71 | | } |
| | 72 | |
|
| | 73 | | public event Action OnFriendListDisplayed; |
| | 74 | | public event Action OnRequestListDisplayed; |
| | 75 | |
|
| | 76 | | public event Action OnClose; |
| | 77 | |
|
| 2 | 78 | | public RectTransform Transform => transform as RectTransform; |
| | 79 | |
|
| 15 | 80 | | public int FriendCount => friendsTab.Count; |
| 14 | 81 | | public int FriendRequestCount => friendRequestsTab.Count; |
| 0 | 82 | | public int FriendRequestSentCount => friendRequestsTab.SentCount; |
| 0 | 83 | | public int FriendRequestReceivedCount => friendRequestsTab.ReceivedCount; |
| 1 | 84 | | public bool IsFriendListActive => friendsTab.gameObject.activeInHierarchy; |
| 0 | 85 | | public bool IsRequestListActive => friendRequestsTab.gameObject.activeInHierarchy; |
| | 86 | |
|
| | 87 | | public static FriendsHUDComponentView Create() |
| | 88 | | { |
| 23 | 89 | | var view = Instantiate(Resources.Load<GameObject>("SocialBarV1/FriendsHUD")) |
| | 90 | | .GetComponent<FriendsHUDComponentView>(); |
| 23 | 91 | | return view; |
| | 92 | | } |
| | 93 | |
|
| | 94 | | public void Initialize(IChatController chatController, |
| | 95 | | IFriendsController friendsController, |
| | 96 | | ISocialAnalytics socialAnalytics) |
| | 97 | | { |
| 23 | 98 | | friendsTab.Initialize(chatController, friendsController, socialAnalytics); |
| 23 | 99 | | } |
| | 100 | |
|
| | 101 | | public void RefreshFriendsTab() |
| | 102 | | { |
| 1 | 103 | | friendsTab.RefreshControl(); |
| 1 | 104 | | } |
| | 105 | |
|
| | 106 | | public override void Awake() |
| | 107 | | { |
| 23 | 108 | | base.Awake(); |
| | 109 | |
|
| 23 | 110 | | friendsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_LIST_TAB_INDEX)); |
| 23 | 111 | | friendRequestsTabFocusButton.onClick.AddListener(() => FocusTab(FRIENDS_REQUEST_TAB_INDEX)); |
| 23 | 112 | | closeButton.onClick.AddListener(() => |
| | 113 | | { |
| 0 | 114 | | OnClose?.Invoke(); |
| 0 | 115 | | Hide(); |
| 0 | 116 | | }); |
| | 117 | |
|
| 23 | 118 | | friendRequestsTab.Expand(); |
| 23 | 119 | | } |
| | 120 | |
|
| | 121 | | public void HideLoadingSpinner() |
| | 122 | | { |
| 2 | 123 | | loadingSpinner.SetActive(false); |
| 2 | 124 | | model.isLoadingSpinnerActive = false; |
| 2 | 125 | | } |
| | 126 | |
|
| | 127 | | public void ShowLoadingSpinner() |
| | 128 | | { |
| 3 | 129 | | loadingSpinner.SetActive(true); |
| 3 | 130 | | model.isLoadingSpinnerActive = true; |
| 3 | 131 | | } |
| | 132 | |
|
| | 133 | | public FriendEntryBase GetEntry(string userId) |
| | 134 | | { |
| 14 | 135 | | return (FriendEntryBase) friendsTab.Get(userId) ?? friendRequestsTab.Get(userId); |
| | 136 | | } |
| | 137 | |
|
| 0 | 138 | | public void DisplayFriendUserNotFound() => friendRequestsTab.ShowUserNotFoundNotification(); |
| | 139 | |
|
| | 140 | | public void Show() |
| | 141 | | { |
| 2 | 142 | | model.visible = true; |
| 2 | 143 | | gameObject.SetActive(true); |
| 2 | 144 | | AudioScriptableObjects.dialogOpen.Play(true); |
| 2 | 145 | | } |
| | 146 | |
|
| | 147 | | public void Hide() |
| | 148 | | { |
| 1 | 149 | | model.visible = false; |
| 1 | 150 | | gameObject.SetActive(false); |
| 1 | 151 | | AudioScriptableObjects.dialogClose.Play(true); |
| 1 | 152 | | } |
| | 153 | |
|
| | 154 | | public void Set(string userId, FriendEntryModel model) |
| | 155 | | { |
| 7 | 156 | | friendRequestsTab.Remove(userId); |
| 7 | 157 | | friendsTab.Enqueue(userId, model); |
| 7 | 158 | | } |
| | 159 | |
|
| | 160 | | public void Remove(string userId) |
| | 161 | | { |
| 5 | 162 | | friendRequestsTab.Remove(userId); |
| 5 | 163 | | friendsTab.Remove(userId); |
| 5 | 164 | | } |
| | 165 | |
|
| | 166 | | public void Set(string userId, FriendRequestEntryModel model) |
| | 167 | | { |
| 6 | 168 | | friendRequestsTab.Enqueue(userId, model); |
| 6 | 169 | | friendsTab.Remove(userId); |
| 6 | 170 | | } |
| | 171 | |
|
| 3 | 172 | | public bool IsActive() => gameObject.activeInHierarchy; |
| | 173 | |
|
| | 174 | | public void ShowRequestSendError(FriendRequestError error) |
| | 175 | | { |
| | 176 | | switch (error) |
| | 177 | | { |
| | 178 | | case FriendRequestError.AlreadyFriends: |
| 0 | 179 | | friendRequestsTab.ShowAlreadyFriendsNotification(); |
| | 180 | | break; |
| | 181 | | } |
| 0 | 182 | | } |
| | 183 | |
|
| | 184 | | public void ShowRequestSendSuccess() |
| | 185 | | { |
| 0 | 186 | | friendRequestsTab.ShowRequestSuccessfullySentNotification(); |
| 0 | 187 | | } |
| | 188 | |
|
| 2 | 189 | | public void ShowMoreFriendsToLoadHint(int hiddenCount) => friendsTab.ShowMoreFriendsToLoadHint(hiddenCount); |
| | 190 | |
|
| 1 | 191 | | public void HideMoreFriendsToLoadHint() => friendsTab.HideMoreFriendsToLoadHint(); |
| | 192 | |
|
| | 193 | | public void ShowMoreRequestsToLoadHint(int hiddenCount) => |
| 2 | 194 | | friendRequestsTab.ShowMoreEntriesToLoadHint(hiddenCount); |
| | 195 | |
|
| 1 | 196 | | public void HideMoreRequestsToLoadHint() => friendRequestsTab.HideMoreFriendsToLoadHint(); |
| | 197 | |
|
| 14 | 198 | | public bool ContainsFriend(string userId) => friendsTab.Get(userId) != null; |
| | 199 | |
|
| 14 | 200 | | public bool ContainsFriendRequest(string userId) => friendRequestsTab.Get(userId) != null; |
| | 201 | |
|
| 0 | 202 | | public void EnableSearchMode() => friendsTab.EnableSearchMode(); |
| | 203 | |
|
| 0 | 204 | | public void DisableSearchMode() => friendsTab.DisableSearchMode(); |
| | 205 | |
|
| | 206 | | public void UpdateBlockStatus(string userId, bool blocked) |
| | 207 | | { |
| 0 | 208 | | UpdateBlockStatus(blocked, friendsTab.Get(userId)); |
| 0 | 209 | | UpdateBlockStatus(blocked, friendRequestsTab.Get(userId)); |
| 0 | 210 | | } |
| | 211 | |
|
| | 212 | | public void ClearAll() |
| | 213 | | { |
| 1 | 214 | | friendsTab.Clear(); |
| 1 | 215 | | friendRequestsTab.Clear(); |
| 1 | 216 | | } |
| | 217 | |
|
| | 218 | | public override void RefreshControl() |
| | 219 | | { |
| 0 | 220 | | if (model.isLoadingSpinnerActive) |
| 0 | 221 | | ShowLoadingSpinner(); |
| | 222 | | else |
| 0 | 223 | | HideLoadingSpinner(); |
| | 224 | |
|
| 0 | 225 | | if (model.visible) |
| 0 | 226 | | Show(); |
| | 227 | | else |
| 0 | 228 | | Hide(); |
| | 229 | |
|
| 0 | 230 | | FocusTab(model.focusedTabIndex); |
| 0 | 231 | | } |
| | 232 | |
|
| | 233 | | internal void FocusTab(int index) |
| | 234 | | { |
| 15 | 235 | | model.focusedTabIndex = index; |
| | 236 | |
|
| 15 | 237 | | if (index == FRIENDS_LIST_TAB_INDEX) |
| | 238 | | { |
| 8 | 239 | | friendsTab.Show(); |
| 8 | 240 | | friendRequestsTab.Hide(); |
| 8 | 241 | | OnFriendListDisplayed?.Invoke(); |
| 0 | 242 | | } |
| 7 | 243 | | else if (index == FRIENDS_REQUEST_TAB_INDEX) |
| | 244 | | { |
| 7 | 245 | | friendsTab.Hide(); |
| 7 | 246 | | friendRequestsTab.Show(); |
| 7 | 247 | | OnRequestListDisplayed?.Invoke(); |
| 0 | 248 | | } |
| | 249 | | else |
| 0 | 250 | | throw new IndexOutOfRangeException(); |
| | 251 | | } |
| | 252 | |
|
| | 253 | | private void UpdateBlockStatus(bool blocked, FriendEntryBase friendEntry) |
| | 254 | | { |
| 0 | 255 | | if (friendEntry == null) return; |
| 0 | 256 | | var friendModel = friendEntry.Model; |
| 0 | 257 | | friendModel.blocked = blocked; |
| 0 | 258 | | friendEntry.RefreshControl(); |
| 0 | 259 | | } |
| | 260 | |
|
| | 261 | | [Serializable] |
| | 262 | | private struct Model |
| | 263 | | { |
| | 264 | | public int focusedTabIndex; |
| | 265 | | public bool isLoadingSpinnerActive; |
| | 266 | | public bool visible; |
| | 267 | | } |
| | 268 | | } |