/// <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); }
/// <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; } } }