public void Notification(string message, TimeSpan length)
 {
     BeforeState = this.State;
     State = NotificationState.Notification;
     VisualStateManager.GoToState(this, "StateNotification", true);
     textNotification.Text = message;
     notificationTimer.Interval = length;
     notificationTimer.Start();
 }
示例#2
0
 public Notification(
     NotificationTask taskType,
     NotificationState notificationType,
     int displayTime)
     : base(null)
 {
     this._task        = taskType;
     this._type        = notificationType;
     this._appearances = 0U;
     this._displayTime = displayTime <= 0 ? 5000 : displayTime;
 }
 public QuickMixNotification(
     string title,
     string text,
     NotificationState state,
     bool showWebHelpLink,
     int timeout)
     : base(NotificationTask.QuickMix, state, timeout)
 {
     this._title           = title;
     this._text            = text;
     this._showWebHelpLink = showWebHelpLink;
 }
示例#4
0
        private static string GetStateText(NotificationState state)
        {
            string          stateString = state.ToString();
            MatchCollection matches     = rx.Matches(stateString);
            var             sb          = new StringBuilder(stateString.ToLowerInvariant());

            foreach (var match in matches.OfType <Match>().OrderByDescending(m => m.Index))
            {
                sb.Insert(match.Index + 1, ' ');
            }
            return(string.Format("File Saver ({0})", sb));
        }
示例#5
0
        /// <summary>
        /// Applies the <see cref="IConfigurationItem" />to list of <see cref="NotificationState" />s.
        /// </summary>
        /// <param name="notificationStates">The notification states.</param>
        /// <param name="configItem">The configuration item.</param>
        /// <param name="configItemAttribute">The configuration item attribute.</param>
        /// <param name="expander">The expander control.</param>
        private void ApplyConfigurationItemToNotificationStateList(IList <NotificationState> notificationStates, IConfigurationItem configItem, ConfigurationItemAttribute configItemAttribute, Expander expander)
        {
            var configItemValue   = configItem.GetOrCreateConnectorNotificationConfiguration();
            var observationStates = Enum.GetValues(typeof(ObservationState)).Cast <ObservationState>().ToList();

            if (configItemAttribute is NotificationConfigurationItemAttribute notificationConfigurationItemAttribute)
            {
                this.RemoveNotSupportedObservationStates(observationStates, notificationConfigurationItemAttribute);
            }

            var useGlobalNotificationState = notificationStates.FirstOrDefault(n => n.IsUseGlobalSettings);

            if (useGlobalNotificationState == null)
            {
                useGlobalNotificationState                     = new NotificationState(notificationStates);
                useGlobalNotificationState.IsActive            = configItemValue.UseGlobalNotificationSettings;
                useGlobalNotificationState.Caption             = "Use global configuration"; // TODO load from resources
                useGlobalNotificationState.PropertyChanged    += (s, e) => this.NotificationStateChanged(useGlobalNotificationState, configItem, e.PropertyName);
                useGlobalNotificationState.IsUseGlobalSettings = true;
                notificationStates.Add(useGlobalNotificationState);
            }
            else
            {
                var newActiveState = configItemValue.UseGlobalNotificationSettings;
                if (useGlobalNotificationState.IsActive != newActiveState)
                {
                    useGlobalNotificationState.IsActive = configItemValue.UseGlobalNotificationSettings;
                }
            }

            foreach (var observationState in observationStates)
            {
                var notificationState = notificationStates.FirstOrDefault(n => n.ObservationState == observationState);
                if (notificationState == null)
                {
                    notificationState                  = new NotificationState(notificationStates);
                    notificationState.IsActive         = configItemValue.AsObservationStateFlag(observationState);
                    notificationState.ObservationState = observationState;
                    notificationState.Caption          = observationState.ToString(); // TODO load from resources
                    notificationState.PropertyChanged += (s, e) => this.NotificationStateChanged(notificationState, configItem, e.PropertyName);
                    notificationState.PropertyChanged += (s, e) => this.UpdateExpanderHeader(expander, notificationStates);
                    notificationStates.Add(notificationState);
                }
                else
                {
                    var newActiveState = configItemValue.UseGlobalNotificationSettings;
                    if (notificationState.IsActive != newActiveState)
                    {
                        notificationState.IsActive = configItemValue.AsObservationStateFlag(observationState);
                    }
                }
            }
        }
示例#6
0
 public Notification
 (
     string message,
     string contactTo,
     NotificationState state,
     NotificationType type
 )
 {
     Message   = message;
     ContactTo = contactTo;
     State     = state;
     Type      = type;
 }
        public void EnableNotifications()
        {
            lock (_notificationStateLock)
            {
                if (NotificationState != NotificationState.Enabled)
                {
                    _timer = new Timer(UpdateNotifications, null, _updateInterval, _updateInterval);

                    NotificationState = NotificationState.Enabled;

                    BroadcastNotificationStateChange(NotificationState.Enabled);
                }
            }
        }
 private async Task CreateNotification(IMessageContext context, ReportAddedToIncident e, int accountId,
                                       NotificationState state)
 {
     if (state == NotificationState.Email)
     {
         var email = new SendIncidentEmail(_configuration);
         await email.SendAsync(context, accountId.ToString(), e.Incident, e.Report);
     }
     else
     {
         var handler = new SendIncidentSms(_userRepository, _configuration);
         await handler.SendAsync(accountId, e.Incident, e.Report);
     }
 }
示例#9
0
 private async Task CreateNotification(ReportAddedToIncident e, int accountId,
                                       NotificationState state)
 {
     if (state == NotificationState.Email)
     {
         var email = new SendIncidentEmail(_commandBus);
         await email.SendAsync(accountId.ToString(), e.Incident, e.Report);
     }
     else
     {
         var handler = new SendIncidentSms(_userRepository);
         await handler.SendAsync(accountId, e.Incident, e.Report);
     }
 }
        public Task Delete(string notificationId, NotificationState state = NotificationState.Any)
        {
            switch (state)
            {
            case NotificationState.Any:
                return(Client.DeleteAsync(NotificationUri(notificationId)));

            case NotificationState.Pending:
                return(Client.DeleteAsync(NotificationUri(notificationId, PendingState)));

            case NotificationState.Archived:
                return(Client.DeleteAsync(NotificationUri(notificationId, ArchivedState)));
            }
            throw new InvalidOperationException("Unknown notification state");
        }
示例#11
0
        public void SetState(NotificationState newState, string message1, string message2, string message3, string link, RoutedUICommand linkHandler)
        {
            SetMessages(message1, message2, message3, link, linkHandler);
            switch (newState)
            {
            case NotificationState.Completed:
            {
                Icon       = "Images/confirmation32.png";
                Background = Brushes.Green;
                break;
            }

            case NotificationState.Error:
            {
                Icon       = "Images/error32.png";
                Background = Brushes.Red;
                break;
            }

            case NotificationState.Info:
            {
                Icon       = "Images/information32.png";
                Background = Brushes.DarkBlue;
                break;
            }

            case NotificationState.Warning:
            {
                Icon       = "Images/warning32.png";
                Background = Brushes.Gold;
                break;
            }

            case NotificationState.InProgress:
            {
                Icon       = "Images/inProgress.png";
                Background = Brushes.LightGreen;
                break;
            }

            case NotificationState.Paused:
            {
                Icon       = "Images/paused.png";
                Background = Brushes.LightGreen;
                break;
            }
            }
        }
        private void BroadcastNotificationStateChange(NotificationState notificationState)
        {
            switch (notificationState)
            {
            case NotificationState.Enabled:
                Clients.All.notificationEnabled();
                break;

            case NotificationState.Disabled:
                Clients.All.notificationDisabled();
                break;

            default:
                break;
            }
        }
示例#13
0
        /// <summary>
        ///     Safe disposal callback
        /// </summary>
        /// <param name="safe">Is Pre-Finailized / Safe (values not cleared by GC)</param>
        private void Dispose(bool safe)
        {
            if (Notifications.IsValidNotification(this))
            {
                Notifications.RemoveNotification(this);
            }

            if (safe)
            {
                Text = null;

                TextColor   = new ColorBGRA();
                BoxColor    = new ColorBGRA();
                BorderColor = new ColorBGRA();

                Font.Dispose();
                Font = null;

                line.Dispose();
                sprite.Dispose();
                Draw   = false;
                Update = false;

                duration = 0;

                if (handler != null)
                {
                    Notifications.Free(handler);
                }

                position       = Vector2.Zero;
                updatePosition = Vector2.Zero;

                state            = 0;
                decreasementTick = 0;

                textFix = Vector2.Zero;

                flashing      = false;
                flashInterval = 0;
                flashTick     = 0;
                clickTick     = 0;

                border = false;
            }
        }
        public void DisableNotifications()
        {
            lock (_notificationStateLock)
            {
                if (NotificationState == NotificationState.Enabled)
                {
                    if (_timer != null)
                    {
                        _timer.Dispose();
                    }

                    NotificationState = NotificationState.Disabled;

                    BroadcastNotificationStateChange(NotificationState.Disabled);
                }
            }
        }
示例#15
0
        /// <summary>
        ///     Notification Constructor
        /// </summary>
        /// <param name="text">Display Text</param>
        /// <param name="duration">Duration (-1 for Infinite)</param>
        /// <param name="dispose">Auto Dispose after notification duration end</param>
        public Notification(string text, int duration = -0x1, bool dispose = false)
        {
            // Setting GUID
            this.id = Guid.NewGuid().ToString("N");

            // Setting main values
            this.Text        = text;
            this.state       = NotificationState.Idle;
            this.border      = true;
            this.autoDispose = dispose;

            // Preload Text
            this.Font.PreloadText(text);

            // Calling Show
            this.Show(duration);
        }
示例#16
0
        /// <summary>
        ///     Safe disposal callback
        /// </summary>
        /// <param name="safe">Is Pre-Finailized / Safe (values not cleared by GC)</param>
        private void Dispose(bool safe)
        {
            if (Notifications.IsValidNotification(this))
            {
                Notifications.RemoveNotification(this);
            }

            if (safe)
            {
                this.Text = null;

                this.TextColor   = new ColorBGRA();
                this.BoxColor    = new ColorBGRA();
                this.BorderColor = new ColorBGRA();

                this.Font.Dispose();
                this.Font = null;

                this.line.Dispose();
                this.sprite.Dispose();
                this.Draw   = false;
                this.Update = false;

                this.duration = 0;

                if (this.handler != null)
                {
                    Notifications.Free(this.handler);
                }

                this.position       = Vector2.Zero;
                this.updatePosition = Vector2.Zero;

                this.state            = 0;
                this.decreasementTick = 0;

                this.textFix = Vector2.Zero;

                this.flashing      = false;
                this.flashInterval = 0;
                this.flashTick     = 0;
                this.clickTick     = 0;

                this.border = false;
            }
        }
示例#17
0
        public virtual async Task UpdateAsync(long id, NotificationState state, int retryCount, string failureDetail, DateTime?nextExecutionTimestamp)
        {
            var data = await _context.Notifications.FindAsync(id);

            if (data != null)
            {
                data.State                  = state;
                data.RetryCount             = retryCount;
                data.FailureDetail          = failureDetail;
                data.NextExecutionTimestamp = nextExecutionTimestamp;
                data.LastUpdatedTimestamp   = DateTime.UtcNow;

                _context.Notifications.Update(data);

                await _context.SaveChangesAsync();
            }
        }
示例#18
0
        /// <summary>
        ///     Show an inactive Notification, returns boolean if successful or not.
        /// </summary>
        /// <param name="newDuration">Duration (-1 for Infinite)</param>
        /// <returns></returns>
        public bool Show(int newDuration = -0x1)
        {
            if (this.Draw || this.Update)
            {
                this.state = NotificationState.AnimationShowShrink;
                return(false);
            }

            this.startT   = Utils.GameTimeTickCount;
            this.duration = newDuration;

            this.TextColor.A   = 0xFF;
            this.BoxColor.A    = 0xFF;
            this.BorderColor.A = 0xFF;

            this.position = new Vector2(Drawing.Width - 200f, Notifications.GetLocation(this));

            return(this.Draw = this.Update = true);
        }
示例#19
0
 public BellumGensNotificationWrapper(TeamInvite invite, NotificationState state)
 {
     if (state == NotificationState.Accepted)
     {
         Notification = new BellumGensNotification()
         {
             Title    = $"{invite.InvitedUser.UserName} has accepted your invitation to join {invite.TeamInfo.TeamName}!",
             Icon     = invite.InvitedUser.AvatarFull,
             Data     = invite.InvitedUserId,
             Renotify = true,
             Actions  = new List <BellumGensNotificationAction>()
             {
                 new BellumGensNotificationAction()
                 {
                     Action = "viewuser",
                     Title  = "View player"
                 }
             }
         };
     }
 }
示例#20
0
 public BellumGensNotificationWrapper(TeamApplication application, NotificationState state)
 {
     if (state == NotificationState.Accepted)
     {
         Notification = new BellumGensNotification()
         {
             Title    = $"You have been accepted to join team {application.Team.TeamName}",
             Icon     = application.Team.TeamAvatar,
             Data     = application.TeamId,
             Renotify = true,
             Actions  = new List <BellumGensNotificationAction>()
             {
                 new BellumGensNotificationAction()
                 {
                     Action = "viewteam",
                     Title  = "View team"
                 }
             }
         };
     }
 }
示例#21
0
 public Notification(string text, NotificationState state)
 {
     RelativeSizeAxes = Axes.X;
     Height           = 30;
     Y      = -30;
     Anchor = Anchor.TopCentre;
     Origin = Anchor.TopCentre;
     AddRangeInternal(new Drawable[]
     {
         new Box
         {
             RelativeSizeAxes = Axes.Both,
             Colour           = state == NotificationState.Bad ? Color4.Red : Color4.Green
         },
         new SpriteText
         {
             Anchor = Anchor.Centre,
             Origin = Anchor.Centre,
             Text   = text
         }
     });
 }
示例#22
0
        private UpdateMessageStateReply UpdateMessageState(int messageId, NotificationState newState)
        {
            try
            {
                if (this.ServiceProvider.AuthenticationService.IsAuthenticated)
                {
                    var apiModel = new UpdateMessageStateModel
                    {
                        Id    = messageId,
                        State = newState
                    };

                    var serializedMessageModel = JsonConvert.SerializeObject(apiModel);

                    using (var webClient = new WebClient())
                    {
                        webClient.Headers.Add("AuthToken", this.ServiceProvider.AuthenticationService.CurrentAuthToken);
                        webClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");

                        var replyResultContent = webClient.UploadString(FirebaseConstants.UpdateMessageStateApiUrl, Http.Put, serializedMessageModel);

                        if (!string.IsNullOrEmpty(replyResultContent))
                        {
                            var replyResultModel = JsonConvert.DeserializeObject <UpdateMessageStateReply>(replyResultContent);
                            if (replyResultModel != null)
                            {
                                return(replyResultModel);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(UpdateMessageStateReply.Error(ex));
            }

            return(UpdateMessageStateReply.Error(ExceptionConstants.UnspecifiedErrorOccurred));
        }
示例#23
0
 private async Task CreateNotification(IMessageContext context, ReportAddedToIncident e, int accountId,
                                       NotificationState state)
 {
     if (state == NotificationState.BrowserNotification)
     {
         var notification = new Notification($"Application: {e.Incident.ApplicationName}\r\n{e.Incident.Name}");
         notification.Actions.Add(new NotificationAction()
         {
             Title  = "Assign to me",
             Action = "AssignToMe"
         });
         notification.Actions.Add(new NotificationAction()
         {
             Title  = "View",
             Action = "View"
         });
         notification.Icon      = "/favicon-32x32.png";
         notification.Timestamp = e.Report.CreatedAtUtc;
         notification.Title     = e.IsNewIncident == true
             ? "New incident"
             : "Re-opened incident";
         notification.Data = new
         {
             applicationId = e.Incident.ApplicationId,
             incidentId    = e.Incident.Id
         };
         await _notificationService.SendBrowserNotification(accountId, notification);
     }
     else if (state == NotificationState.Email)
     {
         var email = new SendIncidentEmail(_configuration);
         await email.SendAsync(context, accountId.ToString(), e.Incident, e.Report);
     }
     else
     {
         var handler = new SendIncidentSms(_userRepository, _configuration);
         await handler.SendAsync(accountId, e.Incident, e.Report);
     }
 }
示例#24
0
        public void NoExistingCetusCycleNotificationStates()
        {
            var cetusCycle = new CetusCycle {
                Id = "1"
            };

            worldStateProcess.ProcessCetusCycle(null, cetusCycle);

            // new states will be added
            var expected = new NotificationState {
                WfStatId = "1", WfStatType = nameof(WFStatType.CetusCycle)
            };
            var actual = worldStateProcess.NewNotificationStates[0];

            Assert.Equal(expected.WfStatId, actual.WfStatId);
            Assert.Equal(expected.WfStatType, actual.WfStatType);

            // nothing to delete
            Assert.Empty(worldStateProcess.ExpiredNotificationStates);

            // no FCM
            Assert.Empty(worldStateProcess.NotificationMessages);
        }
示例#25
0
        public async static void ProcessGetInboxResponse(Client client, GetInboxResponse getInboxResponse)
        {
            var notifcation_count = getInboxResponse.Inbox.Notifications.Count();

            switch (getInboxResponse.Result)
            {
            case GetInboxResponse.Types.Result.Unset:
                break;

            case GetInboxResponse.Types.Result.Failure:
                APIConfiguration.Logger.InboxStatusUpdate($"There was an error, viewing your notifications!", ConsoleColor.Red);
                break;

            case GetInboxResponse.Types.Result.Success:
                if (getInboxResponse.Inbox.Notifications.Count > 0)
                {
                    APIConfiguration.Logger.InboxStatusUpdate($"We got {notifcation_count} new notification(s).", ConsoleColor.Magenta);
                    RepeatedField <string> notificationIDs      = new RepeatedField <string>();
                    RepeatedField <string> categorieIDs         = new RepeatedField <string>();
                    RepeatedField <Int64>  createTimestampMsIDs = new RepeatedField <Int64>();

                    foreach (var notification in getInboxResponse.Inbox.Notifications)
                    {
                        notificationIDs.Add(notification.NotificationId);
                        createTimestampMsIDs.Add(notification.CreateTimestampMs);
                        categorieIDs.Add(notification.Category);
                    }

                    NotificationState notificationState = NotificationState.Viewed;
                    //await client.Misc.OptOutPushNotificationCategory(categorieIDs).ConfigureAwait(false);
                    UpdateNotificationResponse updateNotificationResponse = await client.Misc.UpdateNotification(notificationIDs, createTimestampMsIDs, notificationState).ConfigureAwait(false);

                    APIConfiguration.Logger.InboxStatusUpdate($"Notifications {updateNotificationResponse.State}.", ConsoleColor.Magenta);
                }
                break;
            }
        }
示例#26
0
        public void ExistingCetusCycleNotificationStateStillActive()
        {
            var state = new NotificationState {
                WfStatId = "1"
            };
            var cetusCycle = new CetusCycle
            {
                Id          = "1",
                State       = "test",
                ShortString = "test",
                Expiry      = DateTime.UtcNow + TimeSpan.FromMinutes(1)
            };

            worldStateProcess.ProcessCetusCycle(state, cetusCycle);

            // nothing to add
            Assert.Empty(worldStateProcess.NewNotificationStates);

            // nothing to delete
            Assert.Empty(worldStateProcess.ExpiredNotificationStates);

            // no fcm
            Assert.Empty(worldStateProcess.NotificationMessages);
        }
示例#27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="changeId"></param>
        public void GenerateNotificationStates(string changeId)
        {
            ActivityDateChange change = Db.DateChanges.SingleOrDefault(c => c.Id.ToString().Equals(changeId));

            // Liste aller in betroffenen Kurs eingetragenen User generieren
            List <OccurrenceSubscription> subscriptionList = new List <OccurrenceSubscription>();

            subscriptionList = change.Date.Activity.Occurrence.Subscriptions.ToList();

            // schon bestehende NotificationStates löschen (nur solange die Notifications manuell erzeugt werden)
            change.NotificationStates.Clear();

            //Für jeden User einen notificationState anlegen
            foreach (OccurrenceSubscription s in subscriptionList)
            {
                NotificationState nState = new NotificationState();
                nState.ActivityDateChange = change;
                nState.IsNew  = true;
                nState.UserId = s.UserId;
                change.NotificationStates.Add(nState);
            }

            Db.SaveChanges();
        }
示例#28
0
        /// <summary>
        ///     Show an inactive Notification, returns boolean if successful or not.
        /// </summary>
        /// <param name="newDuration">Duration (-1 for Infinite)</param>
        /// <returns></returns>
        public bool Show(int newDuration = -0x1)
        {
            if (Draw || Update)
            {
                state = NotificationState.AnimationShowShrink;
                return false;
            }

            handler = Notifications.Reserve(GetId(), handler);
            if (handler != null)
            {
                duration = newDuration;

                TextColor.A = 0xFF;
                BoxColor.A = 0xFF;
                BorderColor.A = 0xFF;

                position = new Vector2(Drawing.Width - 200f, Notifications.GetLocation(handler));

                decreasementTick = GetNextDecreasementTick();

                return Draw = Update = true;
            }

            return false;
        }
示例#29
0
    public Settings()
    {
        this.version = VERSION;
        this.notificationState = NotificationState.All;
        this.soundState = SoundState.All;
        this.keyboard = new Dictionary<KeyboardAction, KeyCode>();
        this.paid_player = new Dictionary<string, Player>();
        this.secret_player = new Dictionary<string, Player>();
        this.challenge_player = new Dictionary<string, Player>();
        this.allowReplayBackup = true;
        this.selectedLanguage = AvailableLanguage.FR;

        // -- Setup Keyboard
        this.keyboard.Add(KeyboardAction.Passe, KeyCode.A);
        // --

        ResetDefaultPlayer();
        this.default_team = new Dictionary<string, Team>();
        this.default_compo = new Dictionary<string, Composition>();
        this.selected_stadium_name = "Stadium_0";


        // ----- Default Compo
        Composition compo_psg = new Composition("PSG", "psg");
        compo_psg.SetPosition(0, 0, 0);
        compo_psg.SetPosition(1, 1, 1);
        compo_psg.SetPosition(2, 2, 2);
        compo_psg.SetPosition(3, 3, 3);
        compo_psg.SetPosition(4, 5, 5);
        Default_compo.Add("psg", compo_psg);

        Composition compo_fr = new Composition("FRANCE", "fr");
        compo_fr.SetPosition(0, 3, 3);
        compo_fr.SetPosition(1, 1, 3);
        compo_fr.SetPosition(2, 2, 5);
        compo_fr.SetPosition(3, 1, 2);
        compo_fr.SetPosition(4, 5, 4);
        Default_compo.Add("fr", compo_fr);
        // -------------------

        // ----- Default Team FOR DEBUG
        string[] def_sound = new string[] { "Musics/Team/PSG/Allez", "Musics/Team/PSG/Clap" };
        Team psg = new Team("PSG", compo_psg, def_sound, "psg");

        psg.add_player(new Player(4, 6, 10, 4, "Lombrix", "D_00_lombrix"));
        psg.add_player(new Player(1, 4, 6, 10, "Itectori", "D_01_itectori"));
        psg.add_player(new Player(3, 2, 10, 7, "PlayWithCube", "D_02_pwc"));
        psg.add_player(new Player(7, 4, 4, 8, "GPasDNom", "D_03_gpasdnom"));

        //psg.add_player(new Player(4, 6, 10, 4, "Lombrix"));
        //psg.add_player(new Player(1, 4, 6, 10, "Itectori"));
        //psg.add_player(new Player(3, 2, 10, 7, "PlayWithCube"));
        //psg.add_player(new Player(7, 4, 4, 8, "GPasDNom"));

        psg.add_player(new Player(1, 1, 6, 8, "Epitechien"));
        default_team.Add("psg", psg);

        def_sound = new string[] { };
        Team fr = new Team("France", compo_fr, def_sound, "fr");

        fr.add_player(new Player(4, 6, 10, 4, "Lombrix", "D_00_lombrix"));
        fr.add_player(new Player(1, 4, 6, 10, "Itectori", "D_01_itectori"));
        fr.add_player(new Player(3, 2, 10, 7, "PlayWithCube", "D_02_pwc"));
        fr.add_player(new Player(7, 4, 4, 8, "GPasDNom", "D_03_gpasdnom"));

        //fr.add_player(new Player(4, 6, 10, 4, "Lombrix"));
        //fr.add_player(new Player(1, 4, 6, 10, "Itectori"));
        //fr.add_player(new Player(3, 2, 10, 7, "PlayWithCube"));
        //fr.add_player(new Player(7, 4, 4, 8, "GPasDNom"));

        fr.add_player(new Player(8, 7, 5, 7, "Epiteen"));
        default_team.Add("fr", fr);
        // ------------------
        selected_team = fr;
    }
        /// <summary>
        ///     Called per game tick for update
        /// </summary>
        public void OnUpdate()
        {
            if (!Update)
            {
                return;
            }

            switch (state)
            {
                case NotificationState.Idle:
                {
                    #region Duration End Handler

                    if (!flashing && duration > 0x0 && TextColor.A == 0x0 && BoxColor.A == 0x0 && BorderColor.A == 0x0)
                    {
                        Update = Draw = false;
                        if (autoDispose)
                        {
                            Dispose();
                        }

                        Notifications.Free(handler);

                        return;
                    }

                    #endregion

                    #region Decreasement Tick

                    if (!flashing && duration > 0x0 && Utils.TickCount - decreasementTick > 0x0)
                    {
                        if (TextColor.A > 0x0)
                        {
                            TextColor.A--;
                        }
                        if (BoxColor.A > 0x0)
                        {
                            BoxColor.A--;
                        }
                        if (BorderColor.A > 0x0)
                        {
                            BorderColor.A--;
                        }

                        decreasementTick = GetNextDecreasementTick();
                    }

                    #endregion

                    #region Flashing

                    if (flashing)
                    {
                        if (Utils.TickCount - flashTick > 0x0)
                        {
                            if (TextColor.A > 0x0 && BoxColor.A > 0x0 && BorderColor.A > 0x0)
                            {
                                if (duration > 0x0)
                                {
                                    if (TextColor.A == 0x0 && BoxColor.A == 0x0 && BorderColor.A == 0x0)
                                    {
                                        Update = Draw = false;
                                        if (autoDispose)
                                        {
                                            Dispose();
                                        }

                                        Notifications.Free(handler);

                                        return;
                                    }
                                }

                                flashingBytes[0x0] = --TextColor.A;
                                flashingBytes[0x1] = --BoxColor.A;
                                flashingBytes[0x2] = --BorderColor.A;

                                TextColor.A = 0x0;
                                BoxColor.A = 0x0;
                                BorderColor.A = 0x0;
                            }
                            else
                            {
                                TextColor.A = flashingBytes[0x0];
                                BoxColor.A = flashingBytes[0x1];
                                BorderColor.A = flashingBytes[0x2];

                                if (TextColor.A > 0x0)
                                {
                                    TextColor.A--;
                                }
                                if (BoxColor.A > 0x0)
                                {
                                    BoxColor.A--;
                                }
                                if (BorderColor.A > 0x0)
                                {
                                    BorderColor.A--;
                                }

                                if (duration > 0x0)
                                {
                                    if (TextColor.A == 0x0 && BoxColor.A == 0x0 && BorderColor.A == 0x0)
                                    {
                                        Update = Draw = false;
                                        if (autoDispose)
                                        {
                                            Dispose();
                                        }

                                        Notifications.Free(handler);

                                        return;
                                    }
                                }
                            }
                            flashTick = Utils.TickCount + flashInterval;
                        }
                    }

                    #endregion

                    #region Mouse

                    var mouseLocation = Drawing.WorldToScreen(Game.CursorPos);
                    if (Utils.IsUnderRectangle(mouseLocation, position.X, position.Y, line.Width, 25f))
                    {
                        TextColor.A = 0xFF;
                        BoxColor.A = 0xFF;
                        BorderColor.A = 0xFF;

                        var textDimension = Font.MeasureText(sprite, Text);
                        if (textDimension.Width + 0x10 > line.Width)
                        {
                            var extra = textDimension.Width - 0xB4;
                            if (updatePosition == Vector2.Zero)
                            {
                                textFix = new Vector2(position.X, position.Y);
                                updatePosition = new Vector2(position.X - extra, position.Y);
                            }
                            if (updatePosition != Vector2.Zero && position.X > updatePosition.X)
                            {
                                position.X -= 1f;
                                line.Width += 1f;
                            }
                        }
                    }
                    else if (updatePosition != Vector2.Zero)
                    {
                        if (position.X < textFix.X)
                        {
                            position.X += 1f;
                            line.Width -= 1f;
                        }
                        else
                        {
                            textFix = Vector2.Zero;
                            updatePosition = Vector2.Zero;
                        }
                    }

                    #endregion

                    #region Movement

                    var location = Notifications.GetLocation();
                    if (location != -0x1 && position.Y > location)
                    {
                        if (Notifications.IsFirst((int) position.Y))
                        {
                            handler = Notifications.Reserve(GetId(), handler);
                            if (handler != null)
                            {
                                if (updatePosition != Vector2.Zero && textFix != Vector2.Zero)
                                {
                                    position.X = textFix.X;
                                    textFix = Vector2.Zero;
                                    line.Width = 190f;
                                }

                                updatePosition = new Vector2(position.X, Notifications.GetLocation(handler));
                                state = NotificationState.AnimationMove;
                            }
                        }
                    }

                    #endregion

                    break;
                }
                case NotificationState.AnimationMove:
                {
                    #region Movement

                    if (Math.Abs(position.Y - updatePosition.Y) > float.Epsilon)
                    {
                        var value = (updatePosition.Distance(new Vector2(position.X, position.Y - 0x1)) <
                                     updatePosition.Distance(new Vector2(position.X, position.Y + 0x1)))
                            ? -0x1
                            : 0x1;
                        position.Y += value;
                    }
                    else
                    {
                        updatePosition = Vector2.Zero;
                        state = NotificationState.Idle;
                    }

                    #endregion

                    break;
                }
                case NotificationState.AnimationShowShrink:
                {
                    #region Shrink

                    if (Math.Abs(line.Width - 0xB9) < float.Epsilon)
                    {
                        handler = Notifications.Reserve(GetId(), handler);
                        if (handler != null)
                        {
                            state = NotificationState.AnimationShowMove;
                            updatePosition = new Vector2(position.X, Notifications.GetLocation(handler));
                        }
                        return;
                    }
                    line.Width--;
                    position.X++;

                    #endregion

                    break;
                }
                case NotificationState.AnimationShowMove:
                {
                    #region Movement

                    if (Math.Abs(Notifications.GetLocation() + 0x1E - updatePosition.Y) < float.Epsilon)
                    {
                        updatePosition.Y = Notifications.GetLocation();
                    }

                    if (Math.Abs(position.Y - updatePosition.Y) > float.Epsilon)
                    {
                        var value = (updatePosition.Distance(new Vector2(position.X, position.Y - 0.5f)) <
                                     updatePosition.Distance(new Vector2(position.X, position.Y + 0.5f)))
                            ? -0.5f
                            : 0.5f;
                        position.Y += value;
                    }
                    else
                    {
                        updatePosition = Vector2.Zero;
                        state = NotificationState.AnimationShowGrow;
                    }

                    #endregion

                    break;
                }
                case NotificationState.AnimationShowGrow:
                {
                    #region Growth

                    if (Math.Abs(line.Width - 0xBE) < float.Epsilon)
                    {
                        state = NotificationState.Idle;
                        return;
                    }
                    line.Width++;
                    position.X--;

                    #endregion

                    break;
                }
            }
        }
示例#31
0
        /// <summary>
        ///     Called per game tick for update
        /// </summary>
        public void OnUpdate()
        {
            if (!this.Update)
            {
                return;
            }

            switch (this.state)
            {
            case NotificationState.Idle:
            {
                #region Duration End Handler

                if (!this.flashing && this.duration > 0x0 && this.TextColor.A == 0x0 && this.BoxColor.A == 0x0 &&
                    this.BorderColor.A == 0x0)
                {
                    this.Update = this.Draw = false;
                    if (this.autoDispose)
                    {
                        this.Dispose();
                    }

                    Notifications.Free(this.handler);

                    return;
                }

                #endregion

                #region Decreasement Tick

                if (!this.flashing && this.duration > 0x0 && Environment.TickCount - this.decreasementTick > 0x0)
                {
                    if (this.TextColor.A > 0x0)
                    {
                        this.TextColor.A--;
                    }
                    if (this.BoxColor.A > 0x0)
                    {
                        this.BoxColor.A--;
                    }
                    if (this.BorderColor.A > 0x0)
                    {
                        this.BorderColor.A--;
                    }

                    this.decreasementTick = this.GetNextDecreasementTick();
                }

                #endregion

                #region Flashing

                if (this.flashing)
                {
                    if (Environment.TickCount - this.flashTick > 0x0)
                    {
                        if (this.TextColor.A > 0x0 && this.BoxColor.A > 0x0 && this.BorderColor.A > 0x0)
                        {
                            if (this.duration > 0x0)
                            {
                                if (this.TextColor.A == 0x0 && this.BoxColor.A == 0x0 &&
                                    this.BorderColor.A == 0x0)
                                {
                                    this.Update = this.Draw = false;
                                    if (this.autoDispose)
                                    {
                                        this.Dispose();
                                    }

                                    Notifications.Free(this.handler);

                                    return;
                                }
                            }

                            this.flashingBytes[0x0] = --this.TextColor.A;
                            this.flashingBytes[0x1] = --this.BoxColor.A;
                            this.flashingBytes[0x2] = --this.BorderColor.A;

                            this.TextColor.A   = 0x0;
                            this.BoxColor.A    = 0x0;
                            this.BorderColor.A = 0x0;
                        }
                        else
                        {
                            this.TextColor.A   = this.flashingBytes[0x0];
                            this.BoxColor.A    = this.flashingBytes[0x1];
                            this.BorderColor.A = this.flashingBytes[0x2];

                            if (this.TextColor.A > 0x0)
                            {
                                this.TextColor.A--;
                            }
                            if (this.BoxColor.A > 0x0)
                            {
                                this.BoxColor.A--;
                            }
                            if (this.BorderColor.A > 0x0)
                            {
                                this.BorderColor.A--;
                            }

                            if (this.duration > 0x0)
                            {
                                if (this.TextColor.A == 0x0 && this.BoxColor.A == 0x0 &&
                                    this.BorderColor.A == 0x0)
                                {
                                    this.Update = this.Draw = false;
                                    if (this.autoDispose)
                                    {
                                        this.Dispose();
                                    }

                                    Notifications.Free(this.handler);

                                    return;
                                }
                            }
                        }
                        this.flashTick = Environment.TickCount + this.flashInterval;
                    }
                }

                #endregion

                #region Mouse

                var mouseLocation = Game.MouseScreenPosition;
                if (Utils.IsUnderRectangle(
                        mouseLocation,
                        this.position.X,
                        this.position.Y,
                        this.line.Width,
                        25f))
                {
                    this.TextColor.A   = 0xFF;
                    this.BoxColor.A    = 0xFF;
                    this.BorderColor.A = 0xFF;

                    var textDimension = this.Font.MeasureText(this.sprite, this.Text, FontDrawFlags.Center);
                    if (textDimension.Width + 0x10 > this.line.Width)
                    {
                        var extra = textDimension.Width - 0xB4;
                        if (this.updatePosition == Vector2.Zero)
                        {
                            this.textFix        = new Vector2(this.position.X, this.position.Y);
                            this.updatePosition = new Vector2(this.position.X - extra, this.position.Y);
                        }
                        if (this.updatePosition != Vector2.Zero && this.position.X > this.updatePosition.X)
                        {
                            this.position.X -= 1f;
                            this.line.Width += 1f;
                        }
                    }
                }
                else if (this.updatePosition != Vector2.Zero)
                {
                    if (this.position.X < this.textFix.X)
                    {
                        this.position.X += 1f;
                        this.line.Width -= 1f;
                    }
                    else
                    {
                        this.textFix        = Vector2.Zero;
                        this.updatePosition = Vector2.Zero;
                    }
                }

                #endregion

                #region Movement

                var location = Notifications.GetLocation();
                if (location != -0x1 && this.position.Y > location)
                {
                    if (Notifications.IsFirst((int)this.position.Y))
                    {
                        this.handler = Notifications.Reserve(this.GetId(), this.handler);
                        if (this.handler != null)
                        {
                            if (this.updatePosition != Vector2.Zero && this.textFix != Vector2.Zero)
                            {
                                this.position.X = this.textFix.X;
                                this.textFix    = Vector2.Zero;
                                this.line.Width = 190f;
                            }

                            this.updatePosition = new Vector2(
                                this.position.X,
                                Notifications.GetLocation(this.handler));
                            this.state = NotificationState.AnimationMove;
                        }
                    }
                }

                #endregion

                break;
            }

            case NotificationState.AnimationMove:
            {
                #region Movement

                if (Math.Abs(this.position.Y - this.updatePosition.Y) > float.Epsilon)
                {
                    var value =
                        (this.updatePosition.Distance(new Vector2(this.position.X, this.position.Y - 0x1))
                         < this.updatePosition.Distance(new Vector2(this.position.X, this.position.Y + 0x1)))
                                    ? -0x1
                                    : 0x1;
                    this.position.Y += value;
                }
                else
                {
                    this.updatePosition = Vector2.Zero;
                    this.state          = NotificationState.Idle;
                }

                #endregion

                break;
            }

            case NotificationState.AnimationShowShrink:
            {
                #region Shrink

                if (Math.Abs(this.line.Width - 0xB9) < float.Epsilon)
                {
                    this.handler = Notifications.Reserve(this.GetId(), this.handler);
                    if (this.handler != null)
                    {
                        this.state          = NotificationState.AnimationShowMove;
                        this.updatePosition = new Vector2(
                            this.position.X,
                            Notifications.GetLocation(this.handler));
                    }
                    return;
                }
                this.line.Width--;
                this.position.X++;

                #endregion

                break;
            }

            case NotificationState.AnimationShowMove:
            {
                #region Movement

                if (Math.Abs(Notifications.GetLocation() + 0x1E - this.updatePosition.Y) < float.Epsilon)
                {
                    this.updatePosition.Y = Notifications.GetLocation();
                }

                if (Math.Abs(this.position.Y - this.updatePosition.Y) > float.Epsilon)
                {
                    var value =
                        (this.updatePosition.Distance(new Vector2(this.position.X, this.position.Y - 0.5f))
                         < this.updatePosition.Distance(new Vector2(this.position.X, this.position.Y + 0.5f)))
                                    ? -0.5f
                                    : 0.5f;
                    this.position.Y += value;
                }
                else
                {
                    this.updatePosition = Vector2.Zero;
                    this.state          = NotificationState.AnimationShowGrow;
                }

                #endregion

                break;
            }

            case NotificationState.AnimationShowGrow:
            {
                #region Growth

                if (Math.Abs(this.line.Width - 0xBE) < float.Epsilon)
                {
                    this.state = NotificationState.Idle;
                    return;
                }
                this.line.Width++;
                this.position.X--;

                #endregion

                break;
            }
            }
        }
示例#32
0
        /// <summary>
        ///     Safe disposal callback
        /// </summary>
        /// <param name="safe">Is Pre-Finailized / Safe (values not cleared by GC)</param>
        private void Dispose(bool safe)
        {
            if (Notifications.IsValidNotification(this))
            {
                Notifications.RemoveNotification(this);
            }

            if (safe)
            {
                this.Text = null;

                this.TextColor = new ColorBGRA();
                this.BoxColor = new ColorBGRA();
                this.BorderColor = new ColorBGRA();

                this.Font.Dispose();
                this.Font = null;

                this.line.Dispose();
                this.sprite.Dispose();
                this.Draw = false;
                this.Update = false;

                this.duration = 0;

                if (this.handler != null)
                {
                    Notifications.Free(this.handler);
                }

                this.position = Vector2.Zero;
                this.updatePosition = Vector2.Zero;

                this.state = 0;
                this.decreasementTick = 0;

                this.textFix = Vector2.Zero;

                this.flashing = false;
                this.flashInterval = 0;
                this.flashTick = 0;
                this.clickTick = 0;

                this.border = false;
            }
        }
示例#33
0
        /// <summary>
        ///     Show an inactive Notification, returns boolean if successful or not.
        /// </summary>
        /// <param name="newDuration">Duration (-1 for Infinite)</param>
        /// <returns></returns>
        public bool Show(int newDuration = -0x1)
        {
            if (this.Draw || this.Update)
            {
                this.state = NotificationState.AnimationShowShrink;
                return false;
            }

            this.handler = Notifications.Reserve(this.GetId(), this.handler);
            if (this.handler != null)
            {
                this.duration = newDuration;

                this.TextColor.A = 0xFF;
                this.BoxColor.A = 0xFF;
                this.BorderColor.A = 0xFF;

                this.position = new Vector2(Drawing.Width - 200f, Notifications.GetLocation(this.handler));

                this.decreasementTick = this.GetNextDecreasementTick();

                return this.Draw = this.Update = true;
            }

            return false;
        }
示例#34
0
        /// <summary>
        ///     Called per game tick for update
        /// </summary>
        public void OnUpdate()
        {
            if (!this.Update)
            {
                return;
            }

            switch (this.state)
            {
                case NotificationState.Idle:
                    {
                        if (!this.flashing && this.duration > 0x0 && this.TextColor.A == 0x0 && this.BoxColor.A == 0x0
                            && this.BorderColor.A == 0x0)
                        {
                            this.Update = this.Draw = false;
                            if (this.autoDispose)
                            {
                                this.Dispose();
                            }

                            Notifications.Free(this.handler);

                            return;
                        }

                        if (!this.flashing && this.duration > 0x0 && Environment.TickCount - this.decreasementTick > 0x0)
                        {
                            if (this.TextColor.A > 0x0)
                            {
                                this.TextColor.A--;
                            }

                            if (this.BoxColor.A > 0x0)
                            {
                                this.BoxColor.A--;
                            }

                            if (this.BorderColor.A > 0x0)
                            {
                                this.BorderColor.A--;
                            }

                            this.decreasementTick = this.GetNextDecreasementTick();
                        }

                        

                        if (this.flashing)
                        {
                            if (Environment.TickCount - this.flashTick > 0x0)
                            {
                                if (this.TextColor.A > 0x0 && this.BoxColor.A > 0x0 && this.BorderColor.A > 0x0)
                                {
                                    if (this.duration > 0x0)
                                    {
                                        if (this.TextColor.A == 0x0 && this.BoxColor.A == 0x0
                                            && this.BorderColor.A == 0x0)
                                        {
                                            this.Update = this.Draw = false;
                                            if (this.autoDispose)
                                            {
                                                this.Dispose();
                                            }

                                            Notifications.Free(this.handler);

                                            return;
                                        }
                                    }

                                    this.flashingBytes[0x0] = --this.TextColor.A;
                                    this.flashingBytes[0x1] = --this.BoxColor.A;
                                    this.flashingBytes[0x2] = --this.BorderColor.A;

                                    this.TextColor.A = 0x0;
                                    this.BoxColor.A = 0x0;
                                    this.BorderColor.A = 0x0;
                                }
                                else
                                {
                                    this.TextColor.A = this.flashingBytes[0x0];
                                    this.BoxColor.A = this.flashingBytes[0x1];
                                    this.BorderColor.A = this.flashingBytes[0x2];

                                    if (this.TextColor.A > 0x0)
                                    {
                                        this.TextColor.A--;
                                    }

                                    if (this.BoxColor.A > 0x0)
                                    {
                                        this.BoxColor.A--;
                                    }

                                    if (this.BorderColor.A > 0x0)
                                    {
                                        this.BorderColor.A--;
                                    }

                                    if (this.duration > 0x0)
                                    {
                                        if (this.TextColor.A == 0x0 && this.BoxColor.A == 0x0
                                            && this.BorderColor.A == 0x0)
                                        {
                                            this.Update = this.Draw = false;
                                            if (this.autoDispose)
                                            {
                                                this.Dispose();
                                            }

                                            Notifications.Free(this.handler);

                                            return;
                                        }
                                    }
                                }

                                this.flashTick = Environment.TickCount + this.flashInterval;
                            }
                        }

                        

                        #region Mouse

                        var mouseLocation = Game.MouseScreenPosition;
                        if (Utils.IsUnderRectangle(
                            mouseLocation, 
                            this.position.X, 
                            this.position.Y, 
                            this.line.Width, 
                            25f))
                        {
                            this.TextColor.A = 0xFF;
                            this.BoxColor.A = 0xFF;
                            this.BorderColor.A = 0xFF;

                            var textDimension = this.Font.MeasureText(this.sprite, this.Text, FontDrawFlags.Center);
                            if (textDimension.Width + 0x10 > this.line.Width)
                            {
                                var extra = textDimension.Width - 0xB4;
                                if (this.updatePosition == Vector2.Zero)
                                {
                                    this.textFix = new Vector2(this.position.X, this.position.Y);
                                    this.updatePosition = new Vector2(this.position.X - extra, this.position.Y);
                                }

                                if (this.updatePosition != Vector2.Zero && this.position.X > this.updatePosition.X)
                                {
                                    this.position.X -= 1f;
                                    this.line.Width += 1f;
                                }
                            }
                        }
                        else if (this.updatePosition != Vector2.Zero)
                        {
                            if (this.position.X < this.textFix.X)
                            {
                                this.position.X += 1f;
                                this.line.Width -= 1f;
                            }
                            else
                            {
                                this.textFix = Vector2.Zero;
                                this.updatePosition = Vector2.Zero;
                            }
                        }

                        #endregion

                        #region Movement

                        var location = Notifications.GetLocation();
                        if (location != -0x1 && this.position.Y > location)
                        {
                            if (Notifications.IsFirst((int)this.position.Y))
                            {
                                this.handler = Notifications.Reserve(this.GetId(), this.handler);
                                if (this.handler != null)
                                {
                                    if (this.updatePosition != Vector2.Zero && this.textFix != Vector2.Zero)
                                    {
                                        this.position.X = this.textFix.X;
                                        this.textFix = Vector2.Zero;
                                        this.line.Width = 190f;
                                    }

                                    this.updatePosition = new Vector2(
                                        this.position.X, 
                                        Notifications.GetLocation(this.handler));
                                    this.state = NotificationState.AnimationMove;
                                }
                            }
                        }

                        #endregion

                        break;
                    }

                case NotificationState.AnimationMove:
                    {
                        if (Math.Abs(this.position.Y - this.updatePosition.Y) > float.Epsilon)
                        {
                            var value = this.updatePosition.Distance(
                                new Vector2(this.position.X, this.position.Y - 0x1))
                                        < this.updatePosition.Distance(
                                            new Vector2(this.position.X, this.position.Y + 0x1))
                                            ? -0x1
                                            : 0x1;
                            this.position.Y += value;
                        }
                        else
                        {
                            this.updatePosition = Vector2.Zero;
                            this.state = NotificationState.Idle;
                        }

                        break;
                    }

                case NotificationState.AnimationShowShrink:
                    {
                        if (Math.Abs(this.line.Width - 0xB9) < float.Epsilon)
                        {
                            this.handler = Notifications.Reserve(this.GetId(), this.handler);
                            if (this.handler != null)
                            {
                                this.state = NotificationState.AnimationShowMove;
                                this.updatePosition = new Vector2(
                                    this.position.X, 
                                    Notifications.GetLocation(this.handler));
                            }

                            return;
                        }

                        this.line.Width--;
                        this.position.X++;

                        break;
                    }

                case NotificationState.AnimationShowMove:
                    {
                        if (Math.Abs(Notifications.GetLocation() + 0x1E - this.updatePosition.Y) < float.Epsilon)
                        {
                            this.updatePosition.Y = Notifications.GetLocation();
                        }

                        if (Math.Abs(this.position.Y - this.updatePosition.Y) > float.Epsilon)
                        {
                            var value =
                                this.updatePosition.Distance(new Vector2(this.position.X, this.position.Y - 0.5f))
                                < this.updatePosition.Distance(new Vector2(this.position.X, this.position.Y + 0.5f))
                                    ? -0.5f
                                    : 0.5f;
                            this.position.Y += value;
                        }
                        else
                        {
                            this.updatePosition = Vector2.Zero;
                            this.state = NotificationState.AnimationShowGrow;
                        }

                        break;
                    }

                case NotificationState.AnimationShowGrow:
                    {
                        if (Math.Abs(this.line.Width - 0xBE) < float.Epsilon)
                        {
                            this.state = NotificationState.Idle;
                            return;
                        }

                        this.line.Width++;
                        this.position.X--;

                        break;
                    }
            }
        }
示例#35
0
        /// <summary>
        ///     Notification Constructor
        /// </summary>
        /// <param name="text">Display Text</param>
        /// <param name="duration">Duration (-1 for Infinite)</param>
        /// <param name="dispose">Auto Dispose after notification duration end</param>
        public Notification(string text, int duration = -0x1, bool dispose = false)
        {
            // Setting GUID
            this.id = Guid.NewGuid().ToString("N");

            // Setting main values
            this.Text = text;
            this.state = NotificationState.Idle;
            this.border = true;
            this.autoDispose = dispose;

            // Preload Text
            this.Font.PreloadText(text);

            // Calling Show
            this.Show(duration);
        }
示例#36
0
        /// <summary>
        ///     Called per game tick for update
        /// </summary>
        public void OnUpdate()
        {
            if (!this.Update)
            {
                return;
            }

            switch (this.state)
            {
            case NotificationState.Idle:
            {
                #region Duration End Handler

                if (!this.flashing && this.duration > 0x0 && this.TextColor.A == 0x0 && this.BoxColor.A == 0x0 &&
                    this.BorderColor.A == 0x0)
                {
                    this.Update = this.Draw = false;
                    if (this.autoDispose)
                    {
                        this.Dispose();
                    }

                    Notifications.RemoveNotification(this);

                    return;
                }

                #endregion

                #region Decreasement Tick

                var t = Math.Max(0, this.startT + this.duration - Utils.GameTimeTickCount + 500);
                if (!this.flashing && this.duration > 0x0 && t < 500)
                {
                    var alpha = (byte)(255 * ((float)t / 500));
                    this.TextColor.A   = alpha;
                    this.BoxColor.A    = alpha;
                    this.BorderColor.A = alpha;
                }

                #endregion

                #region Flashing

                if (this.flashing)
                {
                    if (Utils.TickCount - this.flashTick > 0x0)
                    {
                        if (this.TextColor.A > 0x0 && this.BoxColor.A > 0x0 && this.BorderColor.A > 0x0)
                        {
                            if (this.duration > 0x0)
                            {
                                if (this.TextColor.A == 0x0 && this.BoxColor.A == 0x0 &&
                                    this.BorderColor.A == 0x0)
                                {
                                    this.Update = this.Draw = false;
                                    if (this.autoDispose)
                                    {
                                        this.Dispose();
                                    }

                                    Notifications.RemoveNotification(this);

                                    return;
                                }
                            }

                            this.flashingBytes[0x0] = --this.TextColor.A;
                            this.flashingBytes[0x1] = --this.BoxColor.A;
                            this.flashingBytes[0x2] = --this.BorderColor.A;

                            this.TextColor.A   = 0x0;
                            this.BoxColor.A    = 0x0;
                            this.BorderColor.A = 0x0;
                        }
                        else
                        {
                            this.TextColor.A   = this.flashingBytes[0x0];
                            this.BoxColor.A    = this.flashingBytes[0x1];
                            this.BorderColor.A = this.flashingBytes[0x2];

                            if (this.TextColor.A > 0x0)
                            {
                                this.TextColor.A--;
                            }
                            if (this.BoxColor.A > 0x0)
                            {
                                this.BoxColor.A--;
                            }
                            if (this.BorderColor.A > 0x0)
                            {
                                this.BorderColor.A--;
                            }

                            if (this.duration > 0x0)
                            {
                                if (this.TextColor.A == 0x0 && this.BoxColor.A == 0x0 &&
                                    this.BorderColor.A == 0x0)
                                {
                                    this.Update = this.Draw = false;
                                    if (this.autoDispose)
                                    {
                                        this.Dispose();
                                    }

                                    Notifications.RemoveNotification(this);

                                    return;
                                }
                            }
                        }
                        this.flashTick = Utils.TickCount + this.flashInterval;
                    }
                }

                #endregion

                #region Mouse

                var mouseLocation = Drawing.WorldToScreen(Game.CursorPos);
                if (Utils.IsUnderRectangle(
                        mouseLocation,
                        this.position.X,
                        this.position.Y,
                        this.line.Width,
                        25f))
                {
                    this.TextColor.A   = 0xFF;
                    this.BoxColor.A    = 0xFF;
                    this.BorderColor.A = 0xFF;

                    var textDimension = this.Font.MeasureText(this.sprite, this.Text);
                    if (textDimension.Width + 0x10 > this.line.Width)
                    {
                        var extra = textDimension.Width - 0xB4;
                        if (this.updatePosition == Vector2.Zero)
                        {
                            this.textFix        = new Vector2(this.position.X, this.position.Y);
                            this.updatePosition = new Vector2(this.position.X - extra, this.position.Y);
                        }
                        if (this.updatePosition != Vector2.Zero && this.position.X > this.updatePosition.X)
                        {
                            this.position.X -= 1f;
                            this.line.Width += 1f;
                        }
                    }
                }
                else if (this.updatePosition != Vector2.Zero)
                {
                    if (this.position.X < this.textFix.X)
                    {
                        this.position.X += 1f;
                        this.line.Width -= 1f;
                    }
                    else
                    {
                        this.textFix        = Vector2.Zero;
                        this.updatePosition = Vector2.Zero;
                    }
                }

                #endregion

                #region Movement

                var location = Notifications.GetLocation();
                if (location != -0x1 && this.position.Y > location)
                {
                    if (this.updatePosition != Vector2.Zero && this.textFix != Vector2.Zero)
                    {
                        this.position.X = this.textFix.X;
                        this.textFix    = Vector2.Zero;
                        this.line.Width = 190f;
                    }

                    this.updatePosition    = new Vector2(this.position.X, Notifications.GetLocation(this));
                    this.state             = NotificationState.AnimationMove;
                    this.moveStartT        = Utils.GameTimeTickCount;
                    this.moveStartPosition = this.position;
                }

                #endregion

                break;
            }

            case NotificationState.AnimationMove:
            {
                #region Movement

                if (Math.Abs(this.position.Y - this.updatePosition.Y) > float.Epsilon)
                {
                    var percentT = Math.Min(1, ((float)Utils.GameTimeTickCount - this.moveStartT) / 500);

                    this.position.Y = this.moveStartPosition.Y
                                      + (this.updatePosition.Y - this.moveStartPosition.Y) * percentT;
                }
                else
                {
                    this.updatePosition = Vector2.Zero;
                    this.state          = NotificationState.Idle;
                }

                #endregion

                break;
            }

            case NotificationState.AnimationShowShrink:
            {
                #region Shrink

                if (Math.Abs(this.line.Width - 0xB9) < float.Epsilon)
                {
                    this.state          = NotificationState.AnimationShowMove;
                    this.updatePosition = new Vector2(this.position.X, Notifications.GetLocation(this));
                    return;
                }
                this.line.Width--;
                this.position.X++;

                #endregion

                break;
            }

            case NotificationState.AnimationShowMove:
            {
                #region Movement

                if (Math.Abs(Notifications.GetLocation() + 0x1E - this.updatePosition.Y) < float.Epsilon)
                {
                    this.updatePosition.Y = Notifications.GetLocation();
                }

                if (Math.Abs(this.position.Y - this.updatePosition.Y) > float.Epsilon)
                {
                    var value =
                        (this.updatePosition.Distance(new Vector2(this.position.X, this.position.Y - 0.5f))
                         < this.updatePosition.Distance(new Vector2(this.position.X, this.position.Y + 0.5f)))
                                    ? -0.5f
                                    : 0.5f;
                    this.position.Y += value;
                }
                else
                {
                    this.updatePosition = Vector2.Zero;
                    this.state          = NotificationState.AnimationShowGrow;
                }

                #endregion

                break;
            }

            case NotificationState.AnimationShowGrow:
            {
                #region Growth

                if (Math.Abs(this.line.Width - 0xBE) < float.Epsilon)
                {
                    this.state = NotificationState.Idle;
                    return;
                }
                this.line.Width++;
                this.position.X--;

                #endregion

                break;
            }
            }
        }
        /// <summary>
        ///     Called per game tick for update
        /// </summary>
        public void OnUpdate()
        {
            if (!Update)
            {
                return;
            }

            switch (state)
            {
                case NotificationState.Idle:
                {
                    #region Duration End Handler

                    if (!flashing && duration > 0x0 && TextColor.A == 0x0 && BoxColor.A == 0x0 && BorderColor.A == 0x0)
                    {
                        Update = Draw = false;
                        if (autoDispose)
                        {
                            Dispose();
                        }

                        Notifications.RemoveNotification(this);

                        return;
                    }

                    #endregion

                    #region Decreasement Tick

                    var t = Math.Max(0, startT + duration - Utils.GameTimeTickCount + 500);
                    if (!flashing && duration > 0x0 && t < 500 )
                    {
                        var alpha = (byte)(255 * ((float)t / 500));
                        TextColor.A = alpha;
                        BoxColor.A = alpha;
                        BorderColor.A = alpha;
                    }

                    #endregion

                    #region Flashing

                    if (flashing)
                    {
                        if (Utils.TickCount - flashTick > 0x0)
                        {
                            if (TextColor.A > 0x0 && BoxColor.A > 0x0 && BorderColor.A > 0x0)
                            {
                                if (duration > 0x0)
                                {
                                    if (TextColor.A == 0x0 && BoxColor.A == 0x0 && BorderColor.A == 0x0)
                                    {
                                        Update = Draw = false;
                                        if (autoDispose)
                                        {
                                            Dispose();
                                        }

                                        Notifications.RemoveNotification(this);

                                        return;
                                    }
                                }

                                flashingBytes[0x0] = --TextColor.A;
                                flashingBytes[0x1] = --BoxColor.A;
                                flashingBytes[0x2] = --BorderColor.A;

                                TextColor.A = 0x0;
                                BoxColor.A = 0x0;
                                BorderColor.A = 0x0;
                            }
                            else
                            {
                                TextColor.A = flashingBytes[0x0];
                                BoxColor.A = flashingBytes[0x1];
                                BorderColor.A = flashingBytes[0x2];

                                if (TextColor.A > 0x0)
                                {
                                    TextColor.A--;
                                }
                                if (BoxColor.A > 0x0)
                                {
                                    BoxColor.A--;
                                }
                                if (BorderColor.A > 0x0)
                                {
                                    BorderColor.A--;
                                }

                                if (duration > 0x0)
                                {
                                    if (TextColor.A == 0x0 && BoxColor.A == 0x0 && BorderColor.A == 0x0)
                                    {
                                        Update = Draw = false;
                                        if (autoDispose)
                                        {
                                            Dispose();
                                        }

                                        Notifications.RemoveNotification(this);

                                        return;
                                    }
                                }
                            }
                            flashTick = Utils.TickCount + flashInterval;
                        }
                    }

                    #endregion

                    #region Mouse

                    var mouseLocation = Drawing.WorldToScreen(Game.CursorPos);
                    if (Utils.IsUnderRectangle(mouseLocation, position.X, position.Y, line.Width, 25f))
                    {
                        TextColor.A = 0xFF;
                        BoxColor.A = 0xFF;
                        BorderColor.A = 0xFF;

                        var textDimension = Font.MeasureText(sprite, Text);
                        if (textDimension.Width + 0x10 > line.Width)
                        {
                            var extra = textDimension.Width - 0xB4;
                            if (updatePosition == Vector2.Zero)
                            {
                                textFix = new Vector2(position.X, position.Y);
                                updatePosition = new Vector2(position.X - extra, position.Y);
                            }
                            if (updatePosition != Vector2.Zero && position.X > updatePosition.X)
                            {
                                position.X -= 1f;
                                line.Width += 1f;
                            }
                        }
                    }
                    else if (updatePosition != Vector2.Zero)
                    {
                        if (position.X < textFix.X)
                        {
                            position.X += 1f;
                            line.Width -= 1f;
                        }
                        else
                        {
                            textFix = Vector2.Zero;
                            updatePosition = Vector2.Zero;
                        }
                    }

                    #endregion

                    #region Movement

                    var location = Notifications.GetLocation();
                    if (location != -0x1 && position.Y > location)
                    {
                        if (updatePosition != Vector2.Zero && textFix != Vector2.Zero)
                        {
                            position.X = textFix.X;
                            textFix = Vector2.Zero;
                            line.Width = 190f;
                        }

                        updatePosition = new Vector2(position.X, Notifications.GetLocation(this));
                        state = NotificationState.AnimationMove;
                        moveStartT = Utils.GameTimeTickCount;
                        moveStartPosition = position;
                    }

                    #endregion

                    break;
                }
                case NotificationState.AnimationMove:
                {
                    #region Movement

                    if (Math.Abs(position.Y - updatePosition.Y) > float.Epsilon)
                    {
                        var percentT = Math.Min(1, ((float)Utils.GameTimeTickCount - moveStartT) / 500);

                        position.Y = moveStartPosition.Y + (updatePosition.Y - moveStartPosition.Y) * percentT;
                    }
                    else
                    {
                        updatePosition = Vector2.Zero;
                        state = NotificationState.Idle;
                    }

                    #endregion

                    break;
                }
                case NotificationState.AnimationShowShrink:
                {
                    #region Shrink

                    if (Math.Abs(line.Width - 0xB9) < float.Epsilon)
                    {
                        state = NotificationState.AnimationShowMove;
                        updatePosition = new Vector2(position.X, Notifications.GetLocation(this));
                        return;
                    }
                    line.Width--;
                    position.X++;

                    #endregion

                    break;
                }
                case NotificationState.AnimationShowMove:
                {
                    #region Movement

                    if (Math.Abs(Notifications.GetLocation() + 0x1E - updatePosition.Y) < float.Epsilon)
                    {
                        updatePosition.Y = Notifications.GetLocation();
                    }

                    if (Math.Abs(position.Y - updatePosition.Y) > float.Epsilon)
                    {
                        var value = (updatePosition.Distance(new Vector2(position.X, position.Y - 0.5f)) <
                                     updatePosition.Distance(new Vector2(position.X, position.Y + 0.5f)))
                            ? -0.5f
                            : 0.5f;
                        position.Y += value;
                    }
                    else
                    {
                        updatePosition = Vector2.Zero;
                        state = NotificationState.AnimationShowGrow;
                    }

                    #endregion

                    break;
                }
                case NotificationState.AnimationShowGrow:
                {
                    #region Growth

                    if (Math.Abs(line.Width - 0xBE) < float.Epsilon)
                    {
                        state = NotificationState.Idle;
                        return;
                    }
                    line.Width++;
                    position.X--;

                    #endregion

                    break;
                }
            }
        }
        /// <summary>
        ///     Safe disposal callback
        /// </summary>
        /// <param name="safe">Is Pre-Finailized / Safe (values not cleared by GC)</param>
        private void Dispose(bool safe)
        {
            if (Notifications.IsValidNotification(this))
            {
                Notifications.RemoveNotification(this);
            }

            if (safe)
            {
                Text = null;

                TextColor = new ColorBGRA();
                BoxColor = new ColorBGRA();
                BorderColor = new ColorBGRA();

                Font.Dispose();
                Font = null;

                line.Dispose();
                sprite.Dispose();
                Draw = false;
                Update = false;

                duration = 0;

                if (handler != null)
                {
                    Notifications.Free(handler);
                }

                position = Vector2.Zero;
                updatePosition = Vector2.Zero;

                state = 0;
                decreasementTick = 0;

                textFix = Vector2.Zero;

                flashing = false;
                flashInterval = 0;
                flashTick = 0;
                clickTick = 0;

                border = false;
            }
        }
示例#39
0
 public async Task <IEnumerable <NotificationModel> > ListModelWaitedAsync(NotificationState state)
 {
     return(await Queryable.Where(NotificationExpression.Waiting(state)).Select(NotificationExpression.Model).ToListAsync());
 }
 public static Expression <Func <Notification, bool> > Waiting(NotificationState state)
 {
     return(Notification => Notification.State == (NotificationState)state);
 }