Exemplo n.º 1
0
        public override async void Show(bool isMuteButtonClick = false)
        {
            base.Show(isMuteButtonClick);

            try
            {
                IApiUserGroupList groupList = await _connection.Client.ListUserGroupsAsync(_connection.Session);

                foreach (var group in groupList.UserGroups)
                {
                    _state.UserClan      = group.Group;
                    _state.UserClanRank  = group.State;
                    _state.DisplayedClan = _state.UserClan;
                    _state.SubMenu       = ClanSubMenu.Details;
                    // user can only belong to one clan in this game
                    break;
                }
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning("Error fetching user clan: " + e.Message);
            }

            RefreshUI(_state);

            _connection.Socket.ReceivedNotification += NotificationReceived;
        }
        /// <summary>
        /// Sets fields of this panel to show <see cref="PlayerData"/> gathered from <paramref name="user"/>.
        /// </summary>
        /// <param name="user">User to be displayed in this panel.</param>
        private async void PopulateDataAsync(IApiUser user)
        {
            StorageObjectId personalStorageId = new StorageObjectId();

            personalStorageId.Collection = "personal";
            personalStorageId.UserId     = _connection.Session.UserId;
            personalStorageId.Key        = "player_data";

            IApiStorageObjects personalStorageObjects = await _connection.Client.ReadStorageObjectsAsync(_connection.Session, personalStorageId);

            PlayerData playerData        = new PlayerData();
            IUserGroupListUserGroup clan = null;

            try
            {
                IApiUserGroupList clanList = await _connection.Client.ListUserGroupsAsync(_connection.Session);

                // user should only be in one clan.
                clan = clanList.UserGroups.Any() ? clanList.UserGroups.First() : null;
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning("Error fetching user clans " + e.Message);
            }

            CardCollection cardCollection = null;

            try
            {
                var response = await _connection.Client.RpcAsync(_connection.Session, "load_user_cards", "");

                cardCollection = response.Payload.FromJson <CardCollection>();
            }
            catch (ApiResponseException e)
            {
                throw e;
            }

            _usernameText.text = user.Username;
            _statsText.text    = GenerateStats(playerData).TrimEnd();

            _clanNameText.text = clan == null ?
                                 "<i><color=#b0b0b0>[Not a clan member yet]</color></i>" :
                                 clan.Group.Name;

            List <string> deckIds = cardCollection.GetDeckList();

            for (int i = 0; i < deckIds.Count; i++)
            {
                Card card = cardCollection.GetDeckCard(deckIds[i]);
                _cardSlots[i].SetCard(card);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the clan this user has joined.
        /// If user hasn't joined any clan yet, null will be returned.
        /// In this demo users can join only one clan at a time.
        /// </summary>
        public static async Task <IUserGroupListUserGroup> GetUserClanAsync(Client client, ISession session, string userId)
        {
            try
            {
                IApiUserGroupList clans = await client.ListUserGroupsAsync(session, userId, null, 1, null);

                if (clans.UserGroups.Count() > 0)
                {
                    IUserGroupListUserGroup userGroup = clans.UserGroups.ElementAt(0);
                    return(userGroup);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                Debug.LogWarning("An exception has occured when listing user clans: " + e);
                return(null);
            }
        }
        /// <summary>
        /// Checks whether local user is a member of a clan, then disables or enables <see cref="_showClan"/>
        /// button accordingly. Shows this menu.
        /// </summary>
        public async override void Show(bool isMuteButtonClick = false)
        {
            IApiUserGroupList clanList = null;

            try
            {
                clanList = await _connection.Client.ListUserGroupsAsync(_connection.Session);
            }
            catch (ApiResponseException e)
            {
                Debug.LogWarning("Error showing clan leaderboards: " + e.Message);
                return;
            }

            _userClan = clanList.UserGroups.FirstOrDefault();

            if (_userClan != null)
            {
                _showClan.gameObject.SetActive(true);
            }
            else
            {
                // User is not a member of any clan
                // Hiding clan score tab
                if (_showClan.interactable)
                {
                    // Last showed tab is clan tab
                    // Switching to other tab
                    ShowGlobalLeaderboards();
                }

                _showClan.gameObject.SetActive(false);
            }

            base.Show(isMuteButtonClick);
        }