Debian Codegraph @

examples/fps_game/code/gameviewmenu.pas

raw
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 menu, at the start of the game. }
17 unit GameViewMenu;
18
19 interface
20
21 uses Classes,
22 CastleVectors, CastleUIControls, CastleControls, CastleKeysMouse,
23 CastleSoundEngine;
24
25 type
26 TViewMenu = class(TCastleView)
27 published
28 { Components designed using CGE editor.
29 These fields will be automatically initialized at Start. }
30 ButtonPlay: TCastleButton;
31 ButtonQuit: TCastleButton;
32 ButtonOptions: TCastleButton;
33 ButtonCredits: TCastleButton;
34 private
35 procedure ClickCredits(Sender: TObject);
36 procedure ClickPlay(Sender: TObject);
37 procedure ClickOptions(Sender: TObject);
38 procedure ClickQuit(Sender: TObject);
39 public
40 constructor Create(AOwner: TComponent); override;
41 procedure Start; override;
42 procedure Stop; override;
43 end;
44
45 var
46 ViewMenu: TViewMenu;
47
48 implementation
49
50 uses CastleApplicationProperties, CastleWindow,
51 GameViewOptions, GameViewPlay, GameViewCredits, GameViewportUnderUi;
52
53 constructor TViewMenu.Create(AOwner: TComponent);
54 begin
55 inherited;
56 DesignUrl := 'castle-data:/gameviewmenu.castle-user-interface';
57 DesignPreload := true; // make it fast to transition to this view
58 end;
59
60 procedure TViewMenu.Start;
61 begin
62 inherited;
63
64 ButtonPlay.OnClick := {$ifdef FPC}@{$endif} ClickPlay;
65 ButtonOptions.OnClick := {$ifdef FPC}@{$endif} ClickOptions;
66 ButtonQuit.OnClick := {$ifdef FPC}@{$endif} ClickQuit;
67 ButtonCredits.OnClick := {$ifdef FPC}@{$endif} ClickCredits;
68
69 // Hide "Quit" button on mobile/console platforms, where users don't expect such button
70 ButtonQuit.Exists := ApplicationProperties.ShowUserInterfaceToQuit;
71
72 InsertBack(ViewportUnderUi);
73 end;
74
75 procedure TViewMenu.Stop;
76 begin
77 RemoveControl(ViewportUnderUi);
78 inherited;
79 end;
80
81 procedure TViewMenu.ClickCredits(Sender: TObject);
82 begin
83 Container.View := ViewCredits;
84 end;
85
86 procedure TViewMenu.ClickPlay(Sender: TObject);
87 begin
88 Container.View := ViewPlay;
89 end;
90
91 procedure TViewMenu.ClickOptions(Sender: TObject);
92 begin
93 ViewOptions.OverGame := false;
94 Container.View := ViewOptions;
95 end;
96
97 procedure TViewMenu.ClickQuit(Sender: TObject);
98 begin
99 Application.Terminate;
100 end;
101
102 end.