Class TCastleNotifications

Unit

Declaration

type TCastleNotifications = class(TCastleUserInterfaceFont)

Description

Notifications displayed on the screen. Each message disappears after a short time. Suitable for game messages like "Picked up 20 ammo". Call Show to display a message.

This is a TCastleUserInterface descendant, so to use it — just add it to TCastleWindowBase.Controls or TCastleControlBase.Controls. Use TCastleUserInterface anchors to automatically position it on the screen, for example:

Notifications := TCastleNotifications.Create(Owner);
Notifications.Anchor(hpMiddle);
Notifications.Anchor(vpMiddle);
Notifications.TextAlignment := hpMiddle; // looks best, when anchor is also in the middle

Hierarchy

Overview

Fields

Public nested const DefaultMaxMessages = 4;
Public nested const DefaultTimeout = 5.0;
Public nested const DefaultFade = 1.0;

Methods

Protected procedure PreferredSize(var PreferredWidth, PreferredHeight: Single); override;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure Show(const s: string); overload;
Public procedure Show(s: TStringList); overload;
Public procedure Clear;
Public procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override;
Public procedure Render; override;

Properties

Public property Color: TCastleColor read FColor write FColor;
Public property History: TCastleStringList read FHistory;
Published property MaxMessages: integer read FMaxMessages write FMaxMessages default DefaultMaxMessages;
Published property Timeout: Single read FTimeout write FTimeout default DefaultTimeout;
Published property Fade: Single read FFade write FFade default DefaultFade;
Published property CollectHistory: boolean read FCollectHistory write FCollectHistory default false;
Published property TextAlignment: THorizontalPosition read FTextAlignment write FTextAlignment default hpLeft;
Published property ColorPersistent: TCastleColorPersistent read FColorPersistent ;

Description

Fields

Public nested const DefaultMaxMessages = 4;
 
Public nested const DefaultTimeout = 5.0;
 
Public nested const DefaultFade = 1.0;
 

Methods

Protected procedure PreferredSize(var PreferredWidth, PreferredHeight: Single); override;
 
Public constructor Create(AOwner: TComponent); override;
 
Public destructor Destroy; override;
 
Public procedure Show(const s: string); overload;

Show new message. An overloaded version that takes a single string will detect newlines in the string automatically so a message may be multi-line. The messages will be automatically broken to fit on the screen width with given font.

Public procedure Show(s: TStringList); overload;
 
Public procedure Clear;

Clear all messages.

Public procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override;
 
Public procedure Render; override;
 

Properties

Public property Color: TCastleColor read FColor write FColor;

Color used to draw subsequent messages. Default value is white.

Public property History: TCastleStringList read FHistory;

All the messages passed to Show, collected only if CollectHistory. May be Nil when not CollectHistory.

Published property MaxMessages: integer read FMaxMessages write FMaxMessages default DefaultMaxMessages;

How many message lines should be visible on the screen, at maximum.

Published property Timeout: Single read FTimeout write FTimeout default DefaultTimeout;

How long a given message should be visible on the screen, in seconds. Message stops being visible when this timeout passed, or when we need more space for new messages (see MaxMessages).

Note that the Fade time is already included in this value, so a message is normally visible only for the Timeout - Fade seconds, and then it starts fading out.

Published property Fade: Single read FFade write FFade default DefaultFade;
 
Published property CollectHistory: boolean read FCollectHistory write FCollectHistory default false;

Turn this on to have all the messages you pass to Show be collected inside History string list. History is expanded by Show, it is cleared by Clear, just like the notifications on screen. However, unlike the visible messages, it has unlimited size (messages there are not removed when MaxMessages or Timeout take action), and messages inside are not broken to honour screen width.

This is useful if you want to show the player a history of messages (in case they missed the message in game).

Published property TextAlignment: THorizontalPosition read FTextAlignment write FTextAlignment default hpLeft;

Alignment of the text inside.

Published property ColorPersistent: TCastleColorPersistent read FColorPersistent ;

Color that can be visually edited in Castle Game Engine Editor, Lazarus and Delphi. Normal user code does not need to deal with this, instead read or write Color directly.

See also
Color
Color used to draw subsequent messages.

Generated by PasDoc 0.16.0.