AchievementStage getAchieveStageById(int id) { Achievement temp = null; AchievementStage stage = AchievementStage.ACHIEVESTAGE_UNFINISH; for (int idx = 0; idx < _achievementArray.Count; idx++) { if (_achievementArray[idx].id == id) { temp = _achievementArray[idx]; break; } } if (temp != null) { if (getAchievementNum(temp.type) >= temp.typeConfig) { stage = AchievementStage.ACHIEVESTAGE_FINISHED_UNREWARD; if (PlayerPrefs.GetInt(KEY_ACHIEVENT_REWARD + temp.id, 0) != 0) { stage = AchievementStage.ACHIEVESTAGE_REWARDED; } else { } } else { } } return(stage); }
//------------------------------------------------------------------------------ // Method: Update // Author: Neil Holmes // Summary: updates the achievement display //------------------------------------------------------------------------------ public void Update(Rectangle displayArea, float timeStep) { float displayAmount; // increase the counter if an achievement is actively being displayed if (stage > AchievementStage.begin) counter += timeStep; else { // check the achievement list and look for any that need to be displayed if (unlockedAchievements.Count > 0) { // get the next achievement from the unlocked list achievement achievement = unlockedAchievements.Dequeue(); // store the achievement text this.achievementText = achievement.name; // set the icon texture to use iconTexture = achievement.icon; // build the value text valueText = "+" + achievement.value.ToString() + " Points"; // calculate the width of the text messageWidth = (int)messageFont.MeasureString(achievementText).X; // calculate the width of the value text valueWidth = (int)valueFont.MeasureString(valueText).X; // calculate the display width (and enforce minimum and maximum widths) displayWidth = messageWidth + (int)(messageWidthPad * displayScale); if (displayWidth < (minDisplayWidth * displayScale)) displayWidth = (int)(minDisplayWidth * displayScale); if (displayWidth > (maxDisplayWidth * displayScale)) { displayWidth = (int)(maxDisplayWidth * displayScale); messageWidth = (int)((maxDisplayWidth - messageWidthPad) * displayScale); } halfDisplayWidth = displayWidth / 2; // get screen width and height int screenWidth = displayArea.Width; int screenHeight = displayArea.Height; int halfScreenWidth = screenWidth / 2; // calculate the size of the screen safe zone int screenBorderSizeX = (int)(screenWidth * safeZoneScaleValue); int screenBorderSizeY = (int)(screenHeight * safeZoneScaleValue); // calculate the top middle of the achievement based on the requested positioning switch (positionMode) { case ICAchievementPosition.topLeft: displayPosition.X = screenBorderSizeX + halfDisplayWidth; displayPosition.Y = screenBorderSizeY - (int)(bannerYOffset * displayScale); break; case ICAchievementPosition.topMiddle: displayPosition.X = halfScreenWidth; displayPosition.Y = screenBorderSizeY - (int)(bannerYOffset * displayScale); break; case ICAchievementPosition.topRight: displayPosition.X = screenWidth - (screenBorderSizeX + halfDisplayWidth); displayPosition.Y = screenBorderSizeY - (int)(bannerYOffset * displayScale); break; case ICAchievementPosition.bottomLeft: displayPosition.X = screenBorderSizeX + halfDisplayWidth; displayPosition.Y = screenHeight - (screenBorderSizeY + bannerHeight + (int)(bannerYOffset * displayScale)); break; case ICAchievementPosition.bottomMiddle: displayPosition.X = halfScreenWidth; displayPosition.Y = screenHeight - (screenBorderSizeY + bannerHeight + (int)(bannerYOffset * displayScale)); break; case ICAchievementPosition.bottomRight: displayPosition.X = screenWidth - (screenBorderSizeX + halfDisplayWidth); displayPosition.Y = screenHeight - (screenBorderSizeY + bannerHeight + (int)(bannerYOffset * displayScale)); break; } // tell the achievement to start displaying stage = AchievementStage.begin; } } // process according to the current stage of achievement display switch (stage) { // do nothing case AchievementStage.idle: break; // initialise the achievement unlocked display ready to draw case AchievementStage.begin: // set the counter to zero and display flag to true counter = 0; display = true; // set the initial badge position badgeRect.X = (int)displayPosition.X - halfBadgeSize + halfDisplayWidth; badgeRect.Y = (int)displayPosition.Y; // set banner size to the right height, but zero width bannerRect.Y = badgeRect.Y + (int)(bannerYOffset * displayScale); bannerRect.Width = 0; bannerRect.Height = (int)(bannerHeight * displayScale); // set the text position textPosition.X = displayPosition.X - (messageWidth / 2) - (int)(textOffsetX * displayScale); textPosition.Y = bannerRect.Y + (int)(textOffsetY * displayScale); // set the value position if (valueWidth > messageWidth) valuePosition.X = displayPosition.X - (valueWidth / 2) - (int)(textOffsetX * displayScale); else valuePosition.X = textPosition.X; valuePosition.Y = bannerRect.Y + (int)(valueOffsetY * displayScale); // set the icon position iconRect.Y = bannerRect.Y + (int)(iconBorderSize * displayScale); iconRect.Height = bannerRect.Height - (int)(iconBorderSize * 2 * displayScale); iconRect.Width = iconRect.Height; iconRect.X = (int)displayPosition.X + (displayWidth / 2) - (int)(iconBorderSize * displayScale) - iconRect.Width; // set the alpha to it's initial value alpha = 0; // move on to the next step in the process stage ++; break; // makes the indie city badge appear on screen with zoom & rotation case AchievementStage.badgeAppear: // clamp counter to the appearance duration if (counter > badgeAppearDuration) counter = badgeAppearDuration; // calculate the fade-in for the badge alpha = (int)(255 * (counter / badgeAppearDuration)); // check if we have reached the end of this stage if (counter == badgeAppearDuration) { // we have reached the end of the badge appearance stage, reset counter and move on to the next stage counter = 0; stage ++; } break; // pause for a short time before revealing the banner case AchievementStage.badgeAppearPause: // check if we have reached the end of this stage if (counter >= badgeAppearPauseDuration) { // we have reached the end of this pause - reset counter and move on to the next stage counter = 0.0f; stage ++; } break; // reveal the banner along with the achievement text case AchievementStage.bannerReveal: // clamp counter to the banner reveal duration if (counter > bannerRevealDuration) counter = bannerRevealDuration; // calculate how much of the banner should be displayed displayAmount = counter / bannerRevealDuration; // set the banner width and where the badge should be positioned bannerRect.Width = (int)(displayWidth * displayAmount); bannerRect.X = (int)displayPosition.X + halfDisplayWidth - bannerRect.Width; badgeRect.X = bannerRect.X - halfBadgeSize; // check if we have reached the end of this stage if (counter == bannerRevealDuration) { // we have reached the end of the banner reveal stage- reset counter and move on to the next stage counter = 0.0f; stage ++; } break; // pause for a short time before removing the banner case AchievementStage.bannerRevealPause: // check if we have reached the end of this stage if (counter >= bannerRevealPauseDuration) { // we have reached the end of this pause - reset counter and move on to the next stage counter = 0.0f; stage++; } break; // remove the banner case AchievementStage.bannerRemove: // clamp counter to the banner removal duration if (counter > bannerRemoveDuration) counter = bannerRemoveDuration; // calculate how much of the banner should be displayed displayAmount = 1 - (counter / bannerRemoveDuration); // calculate how much of the banner should be displayed and where the badge should be positioned bannerRect.Width = (int)(displayWidth * displayAmount); bannerRect.X = (int)displayPosition.X + halfDisplayWidth - bannerRect.Width; badgeRect.X = bannerRect.X - halfBadgeSize; // check if we have reached the end of this stage if (counter == bannerRemoveDuration) { // we have reached the end of the banner removal stage- reset counter and move on to the next stage counter = 0.0f; stage ++; } break; // fade off the indiecity badge case AchievementStage.badgeRemove: if (counter < badgeRemoveDuration) { // calculate the fade-out for the badge alpha = (int)(255 * (1 - (counter / badgeRemoveDuration))); } else { // display finished - ensure everything is reset to the defaults alpha = 0; counter = 0; display = false; stage = AchievementStage.idle; } break; } }
//------------------------------------------------------------------------------ // Constructor: AchievementPopUp // Author: Neil Holmes // Summary: Constructor - prepares the achievement pop up system //------------------------------------------------------------------------------ public ICAchievementPopUp(Game game, GraphicsDeviceManager graphicsDeviceManager, ICAchievementPosition positionMode, ICAchievementScale scale) : base(game, graphicsDeviceManager, null, positionMode, scale) { // set the achievement display stage to 'idle' so nothing is displayed this.stage = AchievementStage.idle; // achievement pop-ups always have full brightness icons iconColor = Color.White; }