예제 #1
0
        /// <summary>
        /// Adds an objective to the notifications collection, and then removes the objective 10 seconds later
        /// </summary>
        private void DisplayNotification(WvWObjectiveViewModel objectiveData)
        {
            const int SLEEP_TIME = 250;

            if (this.CanShowNotification(objectiveData))
            {
                if (!this.WvWNotifications.Contains(objectiveData))
                {
                    Task.Factory.StartNew(() =>
                    {
                        logger.Debug("Adding notification for \"{0}\" in {1}", objectiveData.Name, objectiveData.Map);
                        Threading.InvokeOnUI(() => this.WvWNotifications.Add(objectiveData));

                        if (this.UserData.NotificationDuration > 0)
                        {
                            // For X seconds, loop and sleep, with checks to see if notifications have been disabled
                            for (int i = 0; i < (this.UserData.NotificationDuration * 1000 / SLEEP_TIME); i++)
                            {
                                System.Threading.Thread.Sleep(SLEEP_TIME);
                                if (!this.CanShowNotification(objectiveData))
                                {
                                    logger.Debug("Removing notification for \"{0}\" in {1}", objectiveData.Name, objectiveData.Map);
                                    Threading.InvokeOnUI(() => this.WvWNotifications.Remove(objectiveData));
                                }
                            }

                            logger.Debug("Removing notification for \"{0}\" in {1}", objectiveData.Name, objectiveData.Map);

                            // TODO: I hate having this here, but due to a limitation in WPF, there's no reasonable way around this at this time
                            // This makes it so that the notifications can fade out before they are removed from the notification window
                            Threading.InvokeOnUI(() => objectiveData.IsRemovingNotification = true);
                            System.Threading.Thread.Sleep(SLEEP_TIME);
                            Threading.InvokeOnUI(() =>
                            {
                                this.WvWNotifications.Remove(objectiveData);
                                objectiveData.IsRemovingNotification = false;
                            });
                        }
                    }, TaskCreationOptions.LongRunning);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes the All Objectives collection
        /// </summary>
        private void InitializeAllObjectivesCollection()
        {
            lock (objectivesRefreshTimerLock)
            {
                logger.Debug("Initializing objectives");

                Threading.InvokeOnUI(() => this.AllObjectives.Clear());

                // Determine the current match. If this changes, we don't need to re-initialize since the actual objectives don't change - just the owners change
                var matchID = this.wvwService.GetMatchId(this.UserData.WorldSelection.ID);
                var objectives = this.wvwService.GetAllObjectives(matchID);

                while (objectives.Count() == 0 && this.startCallCount > 0)
                {
                    // If we started up while in the middle of a reset, the objectives count will return 0, so loop until we get it
                    Thread.Sleep(1000);
                    matchID = this.wvwService.GetMatchId(this.UserData.WorldSelection.ID);
                    objectives = this.wvwService.GetAllObjectives(matchID);
                }

                Threading.InvokeOnUI(() =>
                {
                    foreach (var obj in objectives)
                    {
                        logger.Debug("Initializing view model for {0} - {1}", obj.Name, obj.Map);
                        var vm = new WvWObjectiveViewModel(obj, this.UserData, this.Worlds, this.WvWNotifications);
                        this.AllObjectives.Add(vm);
                    }
                });
            }
        }
예제 #3
0
        /// <summary>
        /// Determines if we can show a notification for the given objective, based on user settings
        /// </summary>
        /// <param name="objectiveData">The objective's data</param>
        /// <returns>True if the notification can be shown, else false</returns>
        private bool CanShowNotification(WvWObjectiveViewModel objectiveData)
        {
            bool canShow = false;

            if (this.UserData.AreNotificationsEnabled)
            {
                var homeTeam = this.Worlds.First(t => t.WorldId == this.UserData.WorldSelection.ID);

                if (this.UserData.NotifyWhenHomeTakesObjective
                    && objectiveData.WorldOwner == homeTeam.Color)
                {
                    canShow = true;
                }
                else if (this.UserData.NotifyWhenHomeLosesObjective
                    && objectiveData.PrevWorldOwner == homeTeam.Color)
                {
                    canShow = true;
                }
                else if (this.UserData.NotifyWhenOtherTakesOtherObjective
                    && objectiveData.PrevWorldOwner != homeTeam.Color
                    && objectiveData.WorldOwner != homeTeam.Color)
                {
                    canShow = true;
                }

                if (canShow)
                {
                    switch (objectiveData.Map)
                    {
                        case WvWMap.BlueBorderlands:
                            canShow = this.UserData.AreBlueBorderlandsNotificationsEnabled;
                            break;
                        case WvWMap.GreenBorderlands:
                            canShow = this.UserData.AreGreenBorderlandsNotificationsEnabled;
                            break;
                        case WvWMap.RedBorderlands:
                            canShow = this.UserData.AreRedBorderlandsNotificationsEnabled;
                            break;
                        case WvWMap.EternalBattlegrounds:
                            canShow = this.UserData.AreEternalBattlegroundsNotificationsEnabled;
                            break;
                        default:
                            canShow = false;
                            break;
                    }
                }

                if (canShow)
                {
                    switch (objectiveData.Type)
                    {
                        case ObjectiveType.Castle:
                            canShow = this.UserData.AreCastleNotificationsEnabled;
                            break;
                        case ObjectiveType.Keep:
                            canShow = this.UserData.AreKeepNotificationsEnabled;
                            break;
                        case ObjectiveType.Tower:
                            canShow = this.UserData.AreTowerNotificationsEnabled;
                            break;
                        case ObjectiveType.Camp:
                            canShow = this.UserData.AreCampNotificationsEnabled;
                            break;
                        case ObjectiveType.BattlesHollow:
                        case ObjectiveType.BauersEstate:
                        case ObjectiveType.CarversAscent:
                        case ObjectiveType.OrchardOverlook:
                        case ObjectiveType.TempleofLostPrayers:
                            canShow = this.UserData.AreBloodlustNotificationsEnabled;
                            break;
                        default:
                            canShow = false;
                            break;
                    }
                }
            }

            return canShow;
        }