| 1 |
{ |
| 2 |
Copyright 2006-2022 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Global instance for @link(Notifications). |
| 17 |
It also captures CastleScript calls of @code(writeln()), to display |
| 18 |
them as notifications. } |
| 19 |
unit CastleGameNotifications |
| 20 |
deprecated 'create own instance of TCastleNotifications instead of relying in singleton in this unit'; |
| 21 |
|
| 22 |
{$I castleconf.inc} |
| 23 |
|
| 24 |
interface |
| 25 |
|
| 26 |
uses CastleNotifications; |
| 27 |
|
| 28 |
var |
| 29 |
Notifications: TCastleNotifications; |
| 30 |
|
| 31 |
implementation |
| 32 |
|
| 33 |
uses SysUtils, CastleScript; |
| 34 |
|
| 35 |
var |
| 36 |
PreviousOnScriptMessage: TCasScriptMessage; |
| 37 |
{$ifndef FPC}TestOnScriptMessage:TCasScriptMessage;{$endif} |
| 38 |
|
| 39 |
initialization |
| 40 |
Notifications := TCastleNotifications.Create(nil); |
| 41 |
|
| 42 |
{ replace OnScriptMessage to allow using Notifications from CastleScript } |
| 43 |
PreviousOnScriptMessage := OnScriptMessage; |
| 44 |
OnScriptMessage := {$ifdef FPC}@{$endif}Notifications.Show; |
| 45 |
finalization |
| 46 |
|
| 47 |
{ restore original OnScriptMessage } |
| 48 |
if Notifications <> nil then |
| 49 |
begin |
| 50 |
{$ifndef FPC}TestOnScriptMessage := Notifications.Show;{$endif} |
| 51 |
if {$ifndef FPC}@{$endif}OnScriptMessage = {$ifdef FPC}@Notifications.Show{$else}@TestOnScriptMessage{$endif}then |
| 52 |
OnScriptMessage := PreviousOnScriptMessage; |
| 53 |
end; |
| 54 |
|
| 55 |
FreeAndNil(Notifications); |
| 56 |
end. |