Beispiel #1
0
    // Turn on an achievement notification for the given color
    public void TurnOnAchievementNotification(string achievementType, bool fromQueue)
    {
        AchievementNotification achievementNotificationProperties = achievementNotification.GetComponent <AchievementNotification> ();

        //If you are calling this method as a result of the achievement notification ending and having more to display in the queue, you need to pop the queue for the next achievement to display
        if (fromQueue)
        {
            achievementType = achievementsWaitingToBeThrown.Dequeue().ToString();
        }

        // If the achievement notification is already on the screen, queue the achievement trying to display to be displayed once the achievement notification is available
        // The value fromQueue lets this method know that if this is being called from the queue being dequeued, it should not queue the achievement calling it, but rather display it
        if (achievementNotification.activeInHierarchy && !fromQueue)
        {
            achievementsWaitingToBeThrown.Enqueue(achievementType);
            //Throws the achievement to the screen if there is no achievement currently displayed, or there is one "displayed" (but off screen) and the next one is being called from the queue
        }
        else
        {
            Sounds.singleton.PlayAchievementUnlockedSound();
            bool isColorAchievement = isAchievementTypeAColorBarrier(achievementType);

            if (!achievementType.Equals("SecretAchievement"))
            {
                string foregroundImageColor = (isColorAchievement || achievementType.Equals("Black")) ? achievementType : "White";
                achievementNotificationProperties.setForegroundImageColor(foregroundImageColor);
                achievementNotificationProperties.setForegroundImage(achievementType);
            }
            else
            {
                achievementNotificationProperties.setForegroundImageColor("Black");
                achievementNotificationProperties.setForegroundImage("Black");
            }

            achievementNotificationProperties.specificAchievementText.GetComponent <Text>().text = Achievement.singleton.getAchievementTypeToAchievementLabel(achievementType);

            if (!achievementType.Equals("SecretAchievement"))
            {
                //This will set the text indicating the amount of a certain achievement obtained by looking at the increments array for the achievement that was just passed
                int[] incrementsArray = GetIncrementsArrayByAchievementType(achievementType);
                achievementNotificationProperties.setForegroundText(incrementsArray[GetHighestLevelOfAchievementByAchievementType(achievementType) - 1].ToString());
            }
            else
            {
                achievementNotificationProperties.setForegroundText("???");
            }

            UIController.singleton.IncrementAchievementsCollectedInRound();

            // Feedback from people said they would rather this not vibrate as they think they've lost a heart.
            //if(Sounds.singleton.GetSoundsAreOn()) Handheld.Vibrate ();

            achievementNotification.SetActive(true);
        }
    }
        private async Task UpdateAchievements()
        {
            await BackupData.WaitForInitAsync();

            Achievements.Clear();
            if (IsLoggedIn) //current user is logged in to the server
            {
                try
                {
                    var newlyUnlocked = await IoCManager.Resolve <IAchievementFetcher>().UpdateAchievements();

                    AchievementNotification.QueueAchievementNotifications(newlyUnlocked);

                    var achievementCounter = 0;
                    var unlockedCounter    = 0;
                    foreach (var achievement in DbManager.DataAccess.Achievements().GetAchievements())
                    {
                        Achievements.Add(AchievementViewModel.CreateFrom(achievement));

                        if (achievement.IsUnlocked)
                        {
                            unlockedCounter++;
                        }

                        achievementCounter++;
                    }

                    Score            = $"{Strings.AchievementsScreenView_Score} {AppSharedData.CurrentAchievementsScore()}";
                    AchievementCount = $"{unlockedCounter + "/" + achievementCounter}{Strings.AchievementsScreenView_Achievement_Count}";
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);

                    if ((((WebException)e.InnerException).Response as HttpWebResponse)?.StatusCode == HttpStatusCode.InternalServerError)
                    {
                        await IoCManager.Resolve <INavigationService>()
                        .DisplayAlert(Strings.Alert_Server_Error_Title,
                                      Strings.Alert_Server_Error_Description,
                                      Strings.Alert_Confirm);
                    }
                    else
                    {
                        await IoCManager.Resolve <INavigationService>()
                        .DisplayAlert(Strings.Alert_Network_Error_Title,
                                      Strings.Alert_Network_Error_Description,
                                      Strings.Alert_Confirm);
                    }
                }
            }
        }