/// <summary> /// Called per Windows Message. /// </summary> /// <param name="args">WndEventArgs</param> public void OnWndProc(WndEventArgs args) { if (Utils.IsUnderRectangle(Drawing.WorldToScreen(Game.CursorPos), position.X, position.Y, line.Width, 25f)) { #region Mouse var message = (WindowsMessages)args.Msg; if (message == WindowsMessages.WM_LBUTTONDOWN) { if (Utils.TickCount - clickTick < 0x5DC) { clickTick = Utils.TickCount; Notifications.Free(handler); Draw = Update = false; if (autoDispose) { Dispose(); } return; } clickTick = Utils.TickCount; } #endregion } }
/// <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; } }
/// <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; } } }