Debian Codegraph @

examples/platformer/code/gameviewpause.pas

raw
1 {
2 Copyright 2021-2024 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 { View pause. }
17 unit GameViewPause;
18
19 interface
20
21 uses Classes,
22 CastleUIControls, CastleControls, CastleKeysMouse;
23
24 type
25 TViewPause = class(TCastleView)
26 published
27 { Components designed using CGE editor.
28 These fields will be automatically initialized at Start. }
29 ButtonMenu: TCastleButton;
30 ButtonResume: TCastleButton;
31 private
32 procedure ClickResume(Sender: TObject);
33 procedure ClickMenu(Sender: TObject);
34 public
35 constructor Create(AOwner: TComponent); override;
36 procedure Start; override;
37 function Press(const Event: TInputPressRelease): Boolean; override;
38 end;
39
40 var
41 ViewPause: TViewPause;
42
43 implementation
44
45 uses CastleSoundEngine,
46 GameSound, GameViewMenu;
47
48 constructor TViewPause.Create(AOwner: TComponent);
49 begin
50 inherited;
51 DesignUrl := 'castle-data:/gameviewpause.castle-user-interface';
52 end;
53
54 procedure TViewPause.ClickResume(Sender: TObject);
55 begin
56 Container.PopView(Self);
57 end;
58
59 procedure TViewPause.ClickMenu(Sender: TObject);
60 begin
61 Container.View := ViewMenu;
62 end;
63
64 procedure TViewPause.Start;
65 begin
66 inherited;
67 ButtonResume.OnClick := {$ifdef FPC}@{$endif}ClickResume;
68 ButtonMenu.OnClick := {$ifdef FPC}@{$endif}ClickMenu;
69
70 { Play menu music }
71 SoundEngine.LoopingChannel[0].Sound := NamedSound('MenuMusic');
72 end;
73
74 function TViewPause.Press(const Event: TInputPressRelease): Boolean;
75 begin
76 Result := inherited;
77 if Result then Exit;
78
79 // allow to exit pause with the same key as entering pause: Escape
80 if Event.IsKey(keyEscape) then
81 begin
82 ClickResume(nil);
83 Result := true;
84 end;
85 end;
86
87 end.