| 1 |
{ Simple "menu" user interface, that allows to run the game or quit. |
| 2 |
|
| 3 |
Feel free to use this code as a starting point for your own projects. |
| 4 |
This template code is in public domain, unlike most other CGE code which |
| 5 |
is covered by BSD or LGPL (see https://castle-engine.io/license). } |
| 6 |
unit GameViewMenu; |
| 7 |
|
| 8 |
interface |
| 9 |
|
| 10 |
uses Classes, |
| 11 |
CastleComponentSerialize, CastleUIControls, CastleControls; |
| 12 |
|
| 13 |
type |
| 14 |
{ Simple "menu" user interface, that allows to run the game or quit. } |
| 15 |
TViewMenu = class(TCastleView) |
| 16 |
published |
| 17 |
{ Components designed using CGE editor. |
| 18 |
These fields will be automatically initialized at Start. } |
| 19 |
ButtonPlay, ButtonQuit: TCastleButton; |
| 20 |
private |
| 21 |
procedure ClickPlay(Sender: TObject); |
| 22 |
procedure ClickQuit(Sender: TObject); |
| 23 |
public |
| 24 |
constructor Create(AOwner: TComponent); override; |
| 25 |
procedure Start; override; |
| 26 |
end; |
| 27 |
|
| 28 |
var |
| 29 |
ViewMenu: TViewMenu; |
| 30 |
|
| 31 |
implementation |
| 32 |
|
| 33 |
uses CastleApplicationProperties, CastleWindow, |
| 34 |
GameViewPlay; |
| 35 |
|
| 36 |
{ TViewMenu ----------------------------------------------------------------- } |
| 37 |
|
| 38 |
constructor TViewMenu.Create(AOwner: TComponent); |
| 39 |
begin |
| 40 |
inherited; |
| 41 |
DesignUrl := 'castle-data:/gameviewmenu.castle-user-interface'; |
| 42 |
end; |
| 43 |
|
| 44 |
procedure TViewMenu.Start; |
| 45 |
begin |
| 46 |
inherited; |
| 47 |
ButtonPlay.OnClick := {$ifdef FPC}@{$endif} ClickPlay; |
| 48 |
ButtonQuit.OnClick := {$ifdef FPC}@{$endif} ClickQuit; |
| 49 |
// Hide "Quit" button on mobile/console platforms, where users don't expect such button |
| 50 |
ButtonQuit.Exists := ApplicationProperties.ShowUserInterfaceToQuit; |
| 51 |
end; |
| 52 |
|
| 53 |
procedure TViewMenu.ClickPlay(Sender: TObject); |
| 54 |
begin |
| 55 |
Container.View := ViewPlay; |
| 56 |
end; |
| 57 |
|
| 58 |
procedure TViewMenu.ClickQuit(Sender: TObject); |
| 59 |
begin |
| 60 |
Application.Terminate; |
| 61 |
end; |
| 62 |
|
| 63 |
end. |