// request next block of entries
        private void RequestNextBlockOfEntries()
        {
            // bail out if we are currently waiting for a page request to finish
            if (requestedPage != null) return;

            // request the next batch of entries
            lastRequestedPage.RequestNext();

            // set requested page so that we can monitor the status
            requestedPage = lastRequestedPage;
        }
        public void Update()
        {
            // do we have a current leaderboard?
            if (currentLeaderboard != null)
            {
                // are we currently waiting for a page request to finish?
                if (requestedPage != null)
                {
                    // check if the page request has completed and process accoringly
                    switch (requestedPage.PopulationState)
                    {
                        case ICELandaLib.LeaderboardPopulationState.LPS_PENDING:

                            // nothing to do yet...
                            break;

                        case ICELandaLib.LeaderboardPopulationState.LPS_INVALID:

                            // data request failed - bail out and release requested page so we can try again later!
                            requestedPage = null;
                            break;

                        case ICELandaLib.LeaderboardPopulationState.LPS_POPULATED:

                            // check to see if we recieved less entries than expected
                            if (requestedPage.Size < 20)
                            {
                                // if we recieved less than 20 entries then we must have reached the end of the leaderboard
                                // set no more entries to true so we dont constantly spam the website asking for more entries
                                noMoreEntries = true;
                            }

                            // got the data - copy it to our local list
                            for (uint i = 0; i < requestedPage.Size; i ++)
                            {
                                ICELandaLib.CoLeaderboardRow row = requestedPage.GetRow(i);
                                entries.Add(new leaderboardEntry(row.Rank.ToString() + " - " + row.UserName, row.Score.ToString()));
                            }

                            // increased the number of entries recieved
                            numEntriesReceived += (int)requestedPage.Size;

                            // store the last requested page and release the requested page ready for next time
                            lastRequestedPage = requestedPage;
                            requestedPage = null;
                            break;
                    }
                }
            }
        }
        // request first block of entries
        private void RequestFirstBlockOfEntries()
        {
            // bail out if we are currently waiting for a page request to finish
            if (requestedPage != null) return;

            // reset the entry display index etc ready for drawing the new leaderboard
            entryDisplayIndex = 0;
            entriesDisplayed = 0;

            // ensure that entries recieved and entries are reset
            numEntriesReceived = 0;
            noMoreEntries = false;
            entries.Clear();

            // request the first 20 entries
            currentLeaderboard = leaderboardManager.GetLeaderboardFromId(leaderboardUIDlist[currentLeaderboardIndex]);
            requestedPage = currentLeaderboard.GetGlobalPage(entriesPerBatch);
        }
        public ICLeaderboardsBrowser(Game game, GraphicsDeviceManager graphicsDeviceManager, ICELandaLib.CoLeaderboardManager leaderboardManager, ICLeaderboardScale scale, int[] leaderboardUIDlist)
        {
            // create a content manager to handle loading the textures we need
            ContentManager content = new ContentManager(game.Services);

            // store the graphics device for future reference
            this.graphicsDevice = game.GraphicsDevice;

            // store a handle to the leaderboard manager
            this.leaderboardManager = leaderboardManager;

            // store the scale we are using
            if (scale == ICLeaderboardScale.normal)
                displayScale = 1.0f;
            else
                displayScale = 0.5f;

            // store the ordered list of leaderboard UID values
            this.leaderboardUIDlist = leaderboardUIDlist;

            // create a sprite batch for rendering
            spriteBatch = new SpriteBatch(graphicsDevice);

            // load the leaderboard display textures
            bannerTexture = content.Load<Texture2D>(@"Content\ICLeaderboards\Shadow");

            // load the leaderboard fonts
            if (scale == ICLeaderboardScale.normal)
            {
                nameFont = content.Load<SpriteFont>(@"Content\ICLeaderboards\NameFont");
                valueFont = content.Load<SpriteFont>(@"Content\ICLeaderboards\ValueFont");
            }
            else
            {
                nameFont = content.Load<SpriteFont>(@"Content\ICLeaderboards\NameFontSmall");
                valueFont = content.Load<SpriteFont>(@"Content\ICLeaderboards\ValueFontSmall");
            }

            // by default we want to display the first leaderbaord in the list
            currentLeaderboardIndex = 0;

            // by default we want to display the leaderboard from the first entry onwards
            entryDisplayIndex = 0;

            // the number of leaderboard entries that were previously displayed
            entriesDisplayed = 0;

            // ensure leaderboard entries recieved, currentLeaderboard and requestedPage are all reset
            numEntriesReceived = 0;
            noMoreEntries = false;
            currentLeaderboard = null;
            requestedPage = null;
            lastRequestedPage = null;
            entries = new List<leaderboardEntry>();
        }