Exemplo n.º 1
0
        /// <summary>
        /// Initializes this <see cref="ClanUserEntry"/> object.
        /// </summary>
        /// <param name="user">The user all associated with this <see cref="ClanUserEntry"/> object.</param>
        /// <param name="userState">The state of <paramref name="user"/> in currently shown Clan.</param>
        /// <param name="localState">The state of local user in currently shown Clan.</param>
        /// <param name="onKick">Method called after clicking <see cref="_kickButton"/>.</param>
        /// <param name="onPromote">Method called after clicking <see cref="_promoteButton"/>.</param>
        /// <param name="onShowProfile">Method called after clicking <see cref="_profileButton"/>.</param>
        public void SetUser(IApiUser user, ClanUserState userState, ClanUserState localState, Action <ClanUserEntry> onSelected,
                            Action <IApiUser> onKick, Action <IApiUser> onPromote, Action <IApiUser> onShowProfile)
        {
            // Setting basic information based on supplied parameters.
            _usernameText.text = user.Username;
            _rankImage.sprite  = GetRankSprite(userState);
            _rankImage.gameObject.SetActive(_rankImage.sprite != null);

            // If local user is the same as supplied user, show their name in green color
            // and disable kick and promote options.
            if (user.Id == NakamaSessionManager.Instance.Account.User.Id)
            {
                _usernameText.color = Color.green;
                _kickButton.gameObject.SetActive(false);
                _promoteButton.gameObject.SetActive(false);
            }
            // If local user cannot manager supplied user (because local user's ClanUserState is lower
            // or local user does not belong to this clan), disable kick and promote options.
            else if (CanManageUser(localState, userState) == false)
            {
                _kickButton.gameObject.SetActive(false);
                _promoteButton.gameObject.SetActive(false);
            }
            // Add listeners to buttons
            else
            {
                _kickButton.onClick.AddListener(() => onKick?.Invoke(user));
                _promoteButton.onClick.AddListener(() => onPromote?.Invoke(user));
            }
            _profileButton.onClick.AddListener(() => onShowProfile?.Invoke(user));
            _panelButton.onClick.AddListener(() => onSelected(this));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the list of members of a clan.
        /// Instantiates UI containing found user data.
        /// If local user is a part of this clan, updates their <see cref="MyUserState"/>
        /// using <see cref="SetMyState(ClanUserState)"/>.
        /// </summary>
        private void OnClanUserListReceived(List <IGroupUserListGroupUser> userList)
        {
            _clanMembers.Clear();
            // Removing previous results
            foreach (Transform child in _clanUserList)
            {
                Destroy(child.gameObject);
            }

            // Searching through results in order to find local user.
            // If local user belongs to this clan, set their MyUserState
            // Knowing the role of local user in searched clan allows for better UI handling
            ClanUserState myState = ClanUserState.None;

            foreach (IGroupUserListGroupUser user in userList)
            {
                if (user.User.Id == NakamaSessionManager.Instance.Account.User.Id)
                {
                    myState = (ClanUserState)user.State;
                    SetMyState(myState);
                    break;
                }
            }

            // Adding entries for each user found
            foreach (IGroupUserListGroupUser user in userList)
            {
                Debug.Log("Found user in clan: " + user.User.Username);
                ClanUserEntry userEntry = Instantiate(_clanUserEntryPrefab, _clanUserList);
                userEntry.SetUser(user.User, (ClanUserState)user.State, myState, OnUserSelected, OnUserKick, OnUserPromote, OnUserShowProfile);
                _clanMembers.Add(userEntry);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a sprite associated with supplied rank.
        /// Only Admin and Superadmin have rank sprites.
        /// </summary>
        private Sprite GetRankSprite(ClanUserState userState)
        {
            switch (userState)
            {
            case ClanUserState.Superadmin: return(_superadminRankSprite);

            case ClanUserState.Admin: return(_adminRankSprite);

            default: return(null);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Changes the <see cref="MyUserState"/>.
 /// If user has <see cref="ClanUserState.Superadmin"/> privileges, this enables <see cref="_removeClanButton"/>.
 /// </summary>
 private void SetMyState(ClanUserState state)
 {
     if (state == ClanUserState.Superadmin)
     {
         _removeClanButton.gameObject.SetActive(true);
     }
     else
     {
         _removeClanButton.gameObject.SetActive(false);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Returns true if user <paramref name="localState"/> can kick and promote user with <paramref name="managedUser"/>.
        /// </summary>
        private bool CanManageUser(ClanUserState localState, ClanUserState managedUser)
        {
            switch (localState)
            {
            case ClanUserState.Superadmin:
                return(true);

            case ClanUserState.Admin:
                return
                    (managedUser == ClanUserState.Member ||
                     managedUser == ClanUserState.JoinRequest);

            case ClanUserState.Member:
                return(false);

            case ClanUserState.JoinRequest:
                return(false);

            default:
                return(false);
            }
        }