| 1 |
{ |
| 2 |
Copyright 2020-2023 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 |
{ Main view, where most of the application logic takes place. } |
| 17 |
unit GameViewMain; |
| 18 |
|
| 19 |
interface |
| 20 |
|
| 21 |
uses Classes, |
| 22 |
CastleComponentSerialize, CastleUIControls, CastleControls, |
| 23 |
CastleKeysMouse, CastleNotifications; |
| 24 |
|
| 25 |
type |
| 26 |
{ Main view, where most of the application logic takes place. } |
| 27 |
TViewMain = class(TCastleView) |
| 28 |
published |
| 29 |
{ Components designed using CGE editor. |
| 30 |
These fields will be automatically initialized at Start. } |
| 31 |
LabelFps: TCastleLabel; |
| 32 |
ButtonSendLog: TCastleButton; |
| 33 |
Notifications: TCastleNotifications; |
| 34 |
private |
| 35 |
procedure ClickSendLog(Sender: TObject); |
| 36 |
public |
| 37 |
constructor Create(AOwner: TComponent); override; |
| 38 |
procedure Start; override; |
| 39 |
procedure Stop; override; |
| 40 |
procedure Update(const SecondsPassed: Single; var HandleInput: boolean); override; |
| 41 |
function Press(const Event: TInputPressRelease): Boolean; override; |
| 42 |
end; |
| 43 |
|
| 44 |
var |
| 45 |
ViewMain: TViewMain; |
| 46 |
|
| 47 |
implementation |
| 48 |
|
| 49 |
uses CastleLog, |
| 50 |
GameLogHandler; |
| 51 |
|
| 52 |
{ TViewMain ----------------------------------------------------------------- } |
| 53 |
|
| 54 |
constructor TViewMain.Create(AOwner: TComponent); |
| 55 |
begin |
| 56 |
inherited; |
| 57 |
DesignUrl := 'castle-data:/gameviewmain.castle-user-interface'; |
| 58 |
end; |
| 59 |
|
| 60 |
procedure TViewMain.Start; |
| 61 |
begin |
| 62 |
inherited; |
| 63 |
ButtonSendLog.OnClick := {$ifdef FPC}@{$endif} ClickSendLog; |
| 64 |
LogNotifications := Notifications; |
| 65 |
end; |
| 66 |
|
| 67 |
procedure TViewMain.Stop; |
| 68 |
begin |
| 69 |
{ Don't let global variable LogNotifications point to no-longer-existing |
| 70 |
TCastleNotifications instance. } |
| 71 |
LogNotifications := nil; |
| 72 |
inherited; |
| 73 |
end; |
| 74 |
|
| 75 |
procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: boolean); |
| 76 |
begin |
| 77 |
inherited; |
| 78 |
{ This virtual method is executed every frame (many times per second). } |
| 79 |
LabelFps.Caption := 'FPS: ' + Container.Fps.ToString; |
| 80 |
end; |
| 81 |
|
| 82 |
function TViewMain.Press(const Event: TInputPressRelease): Boolean; |
| 83 |
begin |
| 84 |
Result := inherited; |
| 85 |
if Result then Exit; |
| 86 |
|
| 87 |
WritelnLog('Pressed: ' + Event.ToString); |
| 88 |
end; |
| 89 |
|
| 90 |
procedure TViewMain.ClickSendLog(Sender: TObject); |
| 91 |
begin |
| 92 |
WritelnLog('Button pressed'); |
| 93 |
end; |
| 94 |
|
| 95 |
end. |