Debian Codegraph @

examples/user_interface/zombie_fighter_alternative_short_lived_views/code/gameviewmainmenu.pas

raw
1 {
2 Copyright 2016-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 { Game view with main menu. }
17 unit GameViewMainMenu;
18
19 interface
20
21 uses Classes, CastleControls, CastleUIControls;
22
23 type
24 TViewMainMenu = class(TCastleView)
25 published
26 { Components designed using CGE editor.
27 These fields will be automatically initialized at Start. }
28 ButtonNewGame, ButtonQuit: TCastleButton;
29 strict private
30 procedure ClickNewGame(Sender: TObject);
31 procedure ClickQuit(Sender: TObject);
32 public
33 constructor Create(AOwner: TComponent); override;
34 procedure Start; override;
35 end;
36
37 implementation
38
39 uses CastleColors, CastleWindow, CastleFilesUtils, CastleApplicationProperties,
40 CastleUtils, CastleComponentSerialize,
41 GameViewLoading;
42
43 { TViewMainMenu ------------------------------------------------------------- }
44
45 constructor TViewMainMenu.Create(AOwner: TComponent);
46 begin
47 inherited;
48 DesignUrl := 'castle-data:/gameviewmainmenu.castle-user-interface';
49 end;
50
51 procedure TViewMainMenu.Start;
52 begin
53 inherited;
54
55 { attach events }
56 ButtonNewGame.OnClick := {$ifdef FPC}@{$endif}ClickNewGame;
57 ButtonQuit.OnClick := {$ifdef FPC}@{$endif}ClickQuit;
58
59 // on some platforms, showing "Quit" button is not standard
60 ButtonQuit.Exists := ApplicationProperties.ShowUserInterfaceToQuit;
61 end;
62
63 procedure TViewMainMenu.ClickNewGame(Sender: TObject);
64 begin
65 Container.View := TViewLoading.CreateUntilStopped;
66 end;
67
68 procedure TViewMainMenu.ClickQuit(Sender: TObject);
69 begin
70 Application.Terminate;
71 end;
72
73 end.