| 1 |
{ |
| 2 |
Copyright 2019-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 SysUtils, Classes, |
| 22 |
CastleScene, CastleControls, CastleLog, CastleVectors, |
| 23 |
CastleFilesUtils, CastleSceneCore, CastleViewport, CastleComponentSerialize, |
| 24 |
CastleUIControls, CastleApplicationProperties, X3DNodes; |
| 25 |
|
| 26 |
type |
| 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 |
ButtonAnimationSqueeze, ButtonAnimationGear: TCastleButton; |
| 33 |
Scene1: TCastleScene; |
| 34 |
Viewport1: TCastleViewport; |
| 35 |
strict private |
| 36 |
procedure ClickAnimationSqueeze(Sender: TObject); |
| 37 |
procedure ClickAnimationGear(Sender: TObject); |
| 38 |
public |
| 39 |
constructor Create(AOwner: TComponent); override; |
| 40 |
procedure Start; override; |
| 41 |
procedure Update(const SecondsPassed: Single; |
| 42 |
var HandleInput: Boolean); override; |
| 43 |
end; |
| 44 |
|
| 45 |
var |
| 46 |
ViewMain: TViewMain; |
| 47 |
|
| 48 |
implementation |
| 49 |
|
| 50 |
constructor TViewMain.Create(AOwner: TComponent); |
| 51 |
begin |
| 52 |
inherited; |
| 53 |
DesignUrl := 'castle-data:/gameviewmain.castle-user-interface'; |
| 54 |
end; |
| 55 |
|
| 56 |
procedure TViewMain.Start; |
| 57 |
begin |
| 58 |
inherited; |
| 59 |
{ Assign OnClick events } |
| 60 |
ButtonAnimationSqueeze.OnClick := {$ifdef FPC}@{$endif}ClickAnimationSqueeze; |
| 61 |
ButtonAnimationGear.OnClick := {$ifdef FPC}@{$endif}ClickAnimationGear; |
| 62 |
end; |
| 63 |
|
| 64 |
procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean); |
| 65 |
begin |
| 66 |
inherited; |
| 67 |
LabelFps.Caption := 'FPS: ' + Container.Fps.ToString; |
| 68 |
end; |
| 69 |
|
| 70 |
procedure TViewMain.ClickAnimationSqueeze(Sender: TObject); |
| 71 |
var |
| 72 |
TimeSensor: TTimeSensorNode; |
| 73 |
begin |
| 74 |
ButtonAnimationSqueeze.Pressed := not ButtonAnimationSqueeze.Pressed; |
| 75 |
TimeSensor := Scene1.AnimationTimeSensor('squeeze'); |
| 76 |
if ButtonAnimationSqueeze.Pressed then |
| 77 |
{ setting InitialTime to TimeSensor.ElapsedTimeInCycle below |
| 78 |
means that we start animation from the moment it was stopped |
| 79 |
(so it looks like "unpause"). } |
| 80 |
TimeSensor.Start(true, true, TimeSensor.ElapsedTimeInCycle) |
| 81 |
else |
| 82 |
TimeSensor.Stop; |
| 83 |
end; |
| 84 |
|
| 85 |
procedure TViewMain.ClickAnimationGear(Sender: TObject); |
| 86 |
var |
| 87 |
TimeSensor: TTimeSensorNode; |
| 88 |
begin |
| 89 |
ButtonAnimationGear.Pressed := not ButtonAnimationGear.Pressed; |
| 90 |
TimeSensor := Scene1.AnimationTimeSensor('gear_rotate'); |
| 91 |
if ButtonAnimationGear.Pressed then |
| 92 |
{ setting InitialTime to TimeSensor.ElapsedTimeInCycle below |
| 93 |
means that we start animation from the moment it was stopped |
| 94 |
(so it looks like "unpause"). } |
| 95 |
TimeSensor.Start(true, true, TimeSensor.ElapsedTimeInCycle) |
| 96 |
else |
| 97 |
TimeSensor.Stop; |
| 98 |
end; |
| 99 |
|
| 100 |
end. |