/// <summary> /// Called per Windows Message. /// </summary> /// <param name="args">WndEventArgs</param> public void OnWndProc(WndEventArgs args) { if (Utils.IsUnderRectangle(Utils.GetCursorPos(), this.position.X, this.position.Y, this.line.Width, 25f)) { #region Mouse var message = (WindowsMessages)args.Msg; if (message == WindowsMessages.WM_LBUTTONDOWN) { if (Utils.TickCount - this.clickTick < 0x5DC) { this.clickTick = Utils.TickCount; Notifications.RemoveNotification(this); this.Draw = this.Update = false; if (this.autoDispose) { this.Dispose(); } return; } this.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> /// 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; Notifications.RemoveNotification(this); this.position = Vector2.Zero; this.updatePosition = Vector2.Zero; this.state = 0; this.textFix = Vector2.Zero; this.flashing = false; this.flashInterval = 0; this.flashTick = 0; this.clickTick = 0; this.border = false; } }
/// <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; } } }