-
Notifications
You must be signed in to change notification settings - Fork 0
/
MCUEGameMode.cpp
97 lines (82 loc) · 2.29 KB
/
MCUEGameMode.cpp
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
// Copyright Epic Games, Inc. All Rights Reserved.
#include "MCUEGameMode.h"
#include "MCUEHUD.h"
#include "MCUECharacter.h"
#include "UObject/ConstructorHelpers.h"
#include "Blueprint/UserWidget.h"
#include "MCUECharacter.h"
#include "Kismet/GameplayStatics.h"
//#include <Runtime/Engine/Private/GameplayStatics.cpp>
void AMCUEGameMode::BeginPlay()
{
ApplyHUDChanges();
}
void AMCUEGameMode::ApplyHUDChanges()
{
// remove the previous hud since we are applying a new one
if (CurrentWidget != nullptr)
{
CurrentWidget->RemoveFromParent();
}
// check the hud state and apply the hud corresponding to whatever hud should be open
switch(HUDState)
{
case EHUDState::HS_Ingame:
{
ApplyHUD(IngameHUDClass, false, false);
}
case EHUDState::HS_Inventory:
{
ApplyHUD(InventoryHUDClass, true, true);
}
case EHUDState::HS_Craft_Menu:
{
ApplyHUD(CraftMenuHUDClass, true, true);
}
default:
{
ApplyHUD(IngameHUDClass, false, false);
}
}
}
EHUDState AMCUEGameMode::GetHUDState()
{
return EHUDState();
}
void AMCUEGameMode::ChangeHUDState(EHUDState NewState)
{
HUDState = NewState;
ApplyHUDChanges();
}
bool AMCUEGameMode::ApplyHUD(TSubclassOf<class UUserWidget> WidgetToApply, bool ShowMouseCursor, bool EnableClickEvents)
{
// Get a ref to the player and the controller
AMCUECharacter* MyCharacter = Cast<AMCUECharacter>(UGameplayStatics::GetPlayerCharacter(this, 0));
APlayerController* MyController = GetWorld()->GetFirstPlayerController();
if (WidgetToApply != nullptr)
{
MyController->bShowMouseCursor = ShowMouseCursor;
MyController->bEnableClickEvents = EnableClickEvents;
CurrentWidget = CreateWidget<UUserWidget>(GetWorld(), WidgetToApply);
if (CurrentWidget != nullptr)
{
CurrentWidget->AddToViewport();
return true;
}
else {
return false;
}
} else{
return false;
}
}
AMCUEGameMode::AMCUEGameMode()
: Super()
{
// set default pawn class to our Blueprinted character
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnClassFinder(TEXT("/Game/FirstPersonCPP/Blueprints/FirstPersonCharacter"));
DefaultPawnClass = PlayerPawnClassFinder.Class;
// use our custom HUD class
HUDClass = AMCUEHUD::StaticClass();
HUDState = EHUDState::HS_Ingame;
}