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