예제 #1
0
        /// <summary>
        /// Unlocks an award.
        /// </summary>
        /// <param name="award">The award to unlock.</param>
        /// <param name="gamertag">The gamer who unlocked the award.</param>
        public void UnlockAward(Award award, string gamertag)
        {
            // Make sure the award is in our list.
            if (Awards.Contains(award))
            {
                // Get the progress, make a new one if not found.
                AwardProgress findAward = GetAwardProgress(award, gamertag, true);

                // Only unlock if it hasn't been yet.
                if (!findAward.IsUnlocked)
                {
                    // Set the award's progress.
                    findAward.Progress = award.ProgressNeeded;

                    // Add it to the notification queue.
                    notifyList.Enqueue(findAward);

                    // Invoke the event.
                    if (AwardUnlocked != null)
                    {
                        AwardUnlocked(this, new AwardUnlockedEventArgs(award, gamertag));
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Determines if a given award has been unlocked.
        /// </summary>
        /// <param name="award"></param>
        /// <param name="gamertag"></param>
        /// <returns></returns>
        public bool IsAwardUnlocked(Award award, string gamertag)
        {
            // Find the AwardProgress, don't create it if it isn't there.
            AwardProgress findAward = GetAwardProgress(award, gamertag, false);

            // Return whether we found it and if it's unlocked.
            return(findAward != null && findAward.IsUnlocked);
        }
예제 #3
0
        public override void Draw(GameTime gameTime)
        {
            // if an announcement is being shown
            if (showAnnouncement)
            {
                // default to full opacity
                float opacity = 1f;

                // figure out if we're fading in or out and set the opacity accordingly
                if (announcementTimer < AnnouncementFadeLength)
                {
                    opacity = announcementTimer / AnnouncementFadeLength;
                }
                else if (announcementTimer > AnnouncementFadeLength + AnnouncementLength)
                {
                    opacity = 1f - ((announcementTimer - AnnouncementLength - AnnouncementFadeLength) / AnnouncementFadeLength);
                }

                // figure out the bounds based on the texture size and the Guide.NotificationPosition
                Rectangle announcementBounds = CalculateAnnouncementBounds();

                // make the colors
                Color color     = new Color(Color.White, opacity);
                Color fontColor = new Color(Color.Black, opacity);

                // start drawing. we use SaveState in case you have 3D rendering so it won't go bad
                AwardProgress awardProgress = notifyList.Peek();
                Award         award         = awardProgress.Award;
                spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);

                // draw the background
                spriteBatch.Draw(announcementBackground, announcementBounds, color);

                // draw the icon
                spriteBatch.Draw(award.Texture, GetIconBounds(announcementBounds), color);

                // draw the award name
                spriteBatch.DrawString(announcementFont, awardProgress.Gamertag, GetGamertagPosition(announcementBounds, awardProgress.Gamertag), fontColor);
                spriteBatch.DrawString(announcementFont, award.Name, GetNamePosition(announcementBounds), fontColor);
                if (awardProgress.IsUnlocked)
                {
                    spriteBatch.DrawString(announcementFont, AwardUnlockedMessage, GetMessagePosition(announcementBounds, AwardUnlockedMessage), fontColor);
                }
                else
                {
                    string message = string.Format("{0}/{1}", awardProgress.Progress, award.ProgressNeeded);
                    spriteBatch.DrawString(announcementFont, message, GetMessagePosition(announcementBounds, message), fontColor);
                }

                // done drawing
                spriteBatch.End();
            }

            base.Draw(gameTime);
        }
예제 #4
0
        /// <summary>
        /// Adds progress points to an award for a gamer, unlocking it if needed.
        /// </summary>
        /// <param name="award">The award to add progress.</param>
        /// <param name="gamertag">The gamer progressing the award.</param>
        /// <param name="progress">The number of progress points obtained.</param>
        public void AddAwardProgress(Award award, string gamertag, int progress)
        {
            // Make sure the award is in our list.
            if (Awards.Contains(award))
            {
                // Get the progress, make a new one if not found.
                AwardProgress findAward = GetAwardProgress(award, gamertag, true);

                // Only add points if it hasn't been unlocked yet.
                if (!findAward.IsUnlocked)
                {
                    // Get the last progress increment reached.
                    int lastIncrement = findAward.Progress / award.ProgressIncrement;

                    // Add to the award's progress and get the new progress increment.
                    findAward.Progress += progress;
                    int nextIncrement = findAward.Progress / award.ProgressIncrement;

                    // First, check again if it is unlocked.
                    if (findAward.IsUnlocked)
                    {
                        // Add it to the notification queue.
                        notifyList.Enqueue(findAward);

                        // Invoke the event.
                        if (AwardUnlocked != null)
                        {
                            AwardUnlocked(this, new AwardUnlockedEventArgs(award, gamertag));
                        }
                    }
                    // Otherwise, check for a partial progress notification.
                    else if (lastIncrement < nextIncrement)
                    {
                        // Round down the progress points and add it to the notification queue.
                        int roundedProgress = nextIncrement * award.ProgressIncrement;
                        notifyList.Enqueue(new AwardProgress
                        {
                            Award    = award,
                            Gamertag = gamertag,
                            Progress = roundedProgress
                        });
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Helper function. Acquires the AwardProgress for the given award and gamer.
        /// </summary>
        /// <param name="award">The award to search for.</param>
        /// <param name="gamertag">The gamer unlocking the award.</param>
        /// <param name="makeIfNotFound">
        /// True if a new AwardProgress should be created if it does not exist.
        /// </param>
        /// <returns>The appropriate AwardProgress object, or null if not found or created.</returns>
        private AwardProgress GetAwardProgress(Award award, string gamertag, bool makeIfNotFound)
        {
            // Try to find the AwardProgress.
            AwardProgress findProgress = currentAwards.Find(a => a.Award == award &&
                                                            a.Gamertag == gamertag);

            // If we didn't find it, make a new one if requested.
            if (findProgress == null && makeIfNotFound)
            {
                findProgress = new AwardProgress
                {
                    Award    = award,
                    Gamertag = gamertag
                };
                currentAwards.Add(findProgress);
            }

            return(findProgress);
        }
예제 #6
0
        /// <summary>
        /// Helper function. Acquires the AwardProgress for the given award and gamer.
        /// </summary>
        /// <param name="award">The award to search for.</param>
        /// <param name="gamertag">The gamer unlocking the award.</param>
        /// <param name="makeIfNotFound">
        /// True if a new AwardProgress should be created if it does not exist.
        /// </param>
        /// <returns>The appropriate AwardProgress object, or null if not found or created.</returns>
        private AwardProgress GetAwardProgress(Award award, string gamertag, bool makeIfNotFound)
        {
            // Try to find the AwardProgress.
            AwardProgress findProgress = currentAwards.Find(a => a.Award == award &&
                                                                 a.Gamertag == gamertag);

            // If we didn't find it, make a new one if requested.
            if (findProgress == null && makeIfNotFound)
            {
                findProgress = new AwardProgress
                {
                    Award = award,
                    Gamertag = gamertag
                };
                currentAwards.Add(findProgress);
            }

            return findProgress;
        }