| 1 |
{ |
| 2 |
Copyright 2022-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 |
CastleVectors, CastleComponentSerialize, |
| 23 |
CastleUIControls, CastleControls, CastleKeysMouse, CastleScene; |
| 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 |
ButtonHeadlightOff, |
| 33 |
ButtonHeadlightDirectional, |
| 34 |
ButtonHeadlightSpotSmooth, |
| 35 |
ButtonHeadlightSpotSharp, |
| 36 |
ButtonHeadlightPoint: TCastleButton; |
| 37 |
HeadlightDirectional, |
| 38 |
HeadlightSpotSmooth, |
| 39 |
HeadlightSpotSharp, |
| 40 |
HeadlightPoint: TCastleAbstractLight; |
| 41 |
private |
| 42 |
procedure ClickHeadlightOff(Sender: TObject); |
| 43 |
procedure ClickHeadlightDirectional(Sender: TObject); |
| 44 |
procedure ClickHeadlightSpotSmooth(Sender: TObject); |
| 45 |
procedure ClickHeadlightSpotSharp(Sender: TObject); |
| 46 |
procedure ClickHeadlightPoint(Sender: TObject); |
| 47 |
public |
| 48 |
constructor Create(AOwner: TComponent); override; |
| 49 |
procedure Start; override; |
| 50 |
procedure Update(const SecondsPassed: Single; var HandleInput: Boolean); override; |
| 51 |
end; |
| 52 |
|
| 53 |
var |
| 54 |
ViewMain: TViewMain; |
| 55 |
|
| 56 |
implementation |
| 57 |
|
| 58 |
uses SysUtils; |
| 59 |
|
| 60 |
{ TViewMain ----------------------------------------------------------------- } |
| 61 |
|
| 62 |
constructor TViewMain.Create(AOwner: TComponent); |
| 63 |
begin |
| 64 |
inherited; |
| 65 |
DesignUrl := 'castle-data:/gameviewmain.castle-user-interface'; |
| 66 |
end; |
| 67 |
|
| 68 |
procedure TViewMain.Start; |
| 69 |
begin |
| 70 |
inherited; |
| 71 |
ButtonHeadlightOff.OnClick := {$ifdef FPC}@{$endif} ClickHeadlightOff; |
| 72 |
ButtonHeadlightDirectional.OnClick := {$ifdef FPC}@{$endif} ClickHeadlightDirectional; |
| 73 |
ButtonHeadlightSpotSmooth.OnClick := {$ifdef FPC}@{$endif} ClickHeadlightSpotSmooth; |
| 74 |
ButtonHeadlightSpotSharp.OnClick := {$ifdef FPC}@{$endif} ClickHeadlightSpotSharp; |
| 75 |
ButtonHeadlightPoint.OnClick := {$ifdef FPC}@{$endif} ClickHeadlightPoint; |
| 76 |
end; |
| 77 |
|
| 78 |
procedure TViewMain.Update(const SecondsPassed: Single; var HandleInput: Boolean); |
| 79 |
begin |
| 80 |
inherited; |
| 81 |
{ This virtual method is executed every frame (many times per second). } |
| 82 |
LabelFps.Caption := 'FPS: ' + Container.Fps.ToString; |
| 83 |
end; |
| 84 |
|
| 85 |
procedure TViewMain.ClickHeadlightOff(Sender: TObject); |
| 86 |
begin |
| 87 |
ButtonHeadlightOff.Pressed := true; |
| 88 |
ButtonHeadlightDirectional.Pressed := false; |
| 89 |
ButtonHeadlightSpotSmooth.Pressed := false; |
| 90 |
ButtonHeadlightSpotSharp.Pressed := false; |
| 91 |
ButtonHeadlightPoint.Pressed := false; |
| 92 |
|
| 93 |
HeadlightDirectional.Exists := false; |
| 94 |
HeadlightSpotSmooth.Exists := false; |
| 95 |
HeadlightSpotSharp.Exists := false; |
| 96 |
HeadlightPoint.Exists := false; |
| 97 |
end; |
| 98 |
|
| 99 |
procedure TViewMain.ClickHeadlightDirectional(Sender: TObject); |
| 100 |
begin |
| 101 |
ButtonHeadlightOff.Pressed := false; |
| 102 |
ButtonHeadlightDirectional.Pressed := true; |
| 103 |
ButtonHeadlightSpotSmooth.Pressed := false; |
| 104 |
ButtonHeadlightSpotSharp.Pressed := false; |
| 105 |
ButtonHeadlightPoint.Pressed := false; |
| 106 |
|
| 107 |
HeadlightDirectional.Exists := true; |
| 108 |
HeadlightSpotSmooth.Exists := false; |
| 109 |
HeadlightSpotSharp.Exists := false; |
| 110 |
HeadlightPoint.Exists := false; |
| 111 |
end; |
| 112 |
|
| 113 |
procedure TViewMain.ClickHeadlightSpotSmooth(Sender: TObject); |
| 114 |
begin |
| 115 |
ButtonHeadlightOff.Pressed := false; |
| 116 |
ButtonHeadlightDirectional.Pressed := false; |
| 117 |
ButtonHeadlightSpotSmooth.Pressed := true; |
| 118 |
ButtonHeadlightSpotSharp.Pressed := false; |
| 119 |
ButtonHeadlightPoint.Pressed := false; |
| 120 |
|
| 121 |
HeadlightDirectional.Exists := false; |
| 122 |
HeadlightSpotSmooth.Exists := true; |
| 123 |
HeadlightSpotSharp.Exists := false; |
| 124 |
HeadlightPoint.Exists := false; |
| 125 |
end; |
| 126 |
|
| 127 |
procedure TViewMain.ClickHeadlightSpotSharp(Sender: TObject); |
| 128 |
begin |
| 129 |
ButtonHeadlightOff.Pressed := false; |
| 130 |
ButtonHeadlightDirectional.Pressed := false; |
| 131 |
ButtonHeadlightSpotSmooth.Pressed := false; |
| 132 |
ButtonHeadlightSpotSharp.Pressed := true; |
| 133 |
ButtonHeadlightPoint.Pressed := false; |
| 134 |
|
| 135 |
HeadlightDirectional.Exists := false; |
| 136 |
HeadlightSpotSmooth.Exists := false; |
| 137 |
HeadlightSpotSharp.Exists := true; |
| 138 |
HeadlightPoint.Exists := false; |
| 139 |
end; |
| 140 |
|
| 141 |
procedure TViewMain.ClickHeadlightPoint(Sender: TObject); |
| 142 |
begin |
| 143 |
ButtonHeadlightOff.Pressed := false; |
| 144 |
ButtonHeadlightDirectional.Pressed := false; |
| 145 |
ButtonHeadlightSpotSmooth.Pressed := false; |
| 146 |
ButtonHeadlightSpotSharp.Pressed := false; |
| 147 |
ButtonHeadlightPoint.Pressed := true; |
| 148 |
|
| 149 |
HeadlightDirectional.Exists := false; |
| 150 |
HeadlightSpotSmooth.Exists := false; |
| 151 |
HeadlightSpotSharp.Exists := false; |
| 152 |
HeadlightPoint.Exists := true; |
| 153 |
end; |
| 154 |
|
| 155 |
end. |