-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQLPlayerController.cpp
More file actions
104 lines (93 loc) · 2.74 KB
/
QLPlayerController.cpp
File metadata and controls
104 lines (93 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//----------------------------------------
// Quarter Life
//
// MIT license
//
// (\-/)
// (='.'=)
// (")-(")o
//----------------------------------------
#include "QL.h"
#include "QLPlayerController.h"
//------------------------------------------------------------
//------------------------------------------------------------
AQLPlayerController::AQLPlayerController()
{
bGamePaused = false;
PauseMenuWidget = nullptr;
PauseMenu = nullptr;
}
//------------------------------------------------------------
//------------------------------------------------------------
void AQLPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
FInputActionBinding& PauseToggle = InputComponent->BindAction("Pause", EInputEvent::IE_Pressed, this, &AQLPlayerController::Pause);
PauseToggle.bExecuteWhenPaused = true;
}
//------------------------------------------------------------
// Design requirement:
// To resume the game, either click umg's resume button,
// or press pause key again. umg handles the first case,
// c++ handles the second case.
//
// note that removing umg from viewport does not mean
// release it from memory.
//------------------------------------------------------------
void AQLPlayerController::Pause()
{
// pause the game
if (!bGamePaused)
{
// only create once in the life cycle of player controller
if (!PauseMenu)
{
// create the pause menu
PauseMenu = CreateWidget<UQLPauseMenuWidget>(GetWorld(), PauseMenuWidget);
PauseMenu->SetPlayerController(this);
}
PauseGame();
}
// resume the game
else
{
ResumeGame();
}
}
//------------------------------------------------------------
//------------------------------------------------------------
bool AQLPlayerController::GetGamePaused()
{
return bGamePaused;
}
//------------------------------------------------------------
//------------------------------------------------------------
void AQLPlayerController::PauseGame()
{
// add the pause menu
if (PauseMenu)
{
bGamePaused = true;
bShowMouseCursor = true;
FInputModeGameAndUI InputMode;
InputMode.SetLockMouseToViewport(true);
SetInputMode(InputMode);
this->SetPause(true);
PauseMenu->AddToViewport();
}
}
//------------------------------------------------------------
//------------------------------------------------------------
void AQLPlayerController::ResumeGame()
{
// remove the pause menu
if (PauseMenu)
{
bGamePaused = false;
bShowMouseCursor = false;
FInputModeGameOnly InputMode;
SetInputMode(InputMode);
this->SetPause(false);
PauseMenu->RemoveFromViewport();
}
}