Debian Codegraph @

examples/platformer/code/gameviewmenu.pas

raw
1 {
2 Copyright 2021-2021 Andrzej Kilijański, 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 { Simple "menu" user interface, that allows to run the game or quit. }
17 unit GameViewMenu;
18
19 interface
20
21 uses Classes,
22 CastleComponentSerialize, CastleUIControls, CastleControls,
23 CastleSoundEngine;
24
25 type
26 { Simple "menu" user interface, that allows to run the game or quit. }
27 TViewMenu = class(TCastleView)
28 published
29 { Components designed using CGE editor.
30 These fields will be automatically initialized at Start. }
31 ButtonPlay, ButtonOptions, ButtonCredits, ButtonQuit: TCastleButton;
32 private
33 procedure ClickPlay(Sender: TObject);
34 procedure ClickOptions(Sender: TObject);
35 procedure ClickCredits(Sender: TObject);
36 procedure ClickQuit(Sender: TObject);
37 public
38 constructor Create(AOwner: TComponent); override;
39 procedure Start; override;
40 end;
41
42 var
43 ViewMenu: TViewMenu;
44
45 implementation
46
47 uses CastleApplicationProperties, CastleWindow,
48 GameSound, GameViewPlay, GameViewOptions, GameViewCredits;
49
50 { TViewMenu ----------------------------------------------------------------- }
51
52 constructor TViewMenu.Create(AOwner: TComponent);
53 begin
54 inherited;
55 DesignUrl := 'castle-data:/gameviewmenu.castle-user-interface';
56 end;
57
58 procedure TViewMenu.Start;
59 begin
60 inherited;
61
62 ButtonPlay.OnClick := {$ifdef FPC}@{$endif}ClickPlay;
63 ButtonOptions.OnClick := {$ifdef FPC}@{$endif}ClickOptions;
64 ButtonCredits.OnClick := {$ifdef FPC}@{$endif}ClickCredits;
65
66 ButtonQuit.OnClick := {$ifdef FPC}@{$endif}ClickQuit;
67 // Hide "Quit" button on mobile/console platforms, where users don't expect such button
68 ButtonQuit.Exists := ApplicationProperties.ShowUserInterfaceToQuit;
69
70 { Play menu music }
71 SoundEngine.LoopingChannel[0].Sound := NamedSound('MenuMusic');
72 end;
73
74 procedure TViewMenu.ClickPlay(Sender: TObject);
75 begin
76 Container.View := ViewPlay;
77 end;
78
79 procedure TViewMenu.ClickOptions(Sender: TObject);
80 begin
81 Container.View := ViewOptions;
82 end;
83
84 procedure TViewMenu.ClickCredits(Sender: TObject);
85 begin
86 Container.View := ViewCredits;
87 end;
88
89 procedure TViewMenu.ClickQuit(Sender: TObject);
90 begin
91 Application.Terminate;
92 end;
93
94 end.