Lost_Edge/Source/Lost_Edge/Private/MainGameModeBase.cpp

117 lines
2.9 KiB
C++

// Oleg Petruny proprietary.
#include "MainGameModeBase.h"
#include "Engine/World.h"
#include "GameFramework/SpectatorPawn.h"
#include "Kismet/GameplayStatics.h"
#include "UObject/ScriptInterface.h"
#include "CustomGameInstanceBase.h"
#include "CutsceneManager.h"
#include "DialogueManager.h"
#include "Levels/LevelBase.h"
#include "QuestManager.h"
#include "Widgets/WidgetsManager.h"
UWidgetsManager* AMainGameModeBase::_widgetsManager = nullptr;
UCutsceneManager* AMainGameModeBase::_cutsceneManager = nullptr;
UDialogueManager* AMainGameModeBase::_dialogueManager = nullptr;
UQuestManager* AMainGameModeBase::_questManager = nullptr;
ALevelBase* AMainGameModeBase::leadLevel = nullptr;
void AMainGameModeBase::StartPlay()
{
_widgetsManager = NewObject<UWidgetsManager>(this, widgetManagerClass);
_cutsceneManager = NewObject<UCutsceneManager>(this);
_dialogueManager = NewObject<UDialogueManager>(this);
_questManager = NewObject<UQuestManager>(this);
AGameModeBase::StartPlay();
_widgetsManager->Init();
}
void AMainGameModeBase::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
_cutsceneManager->LockCallback(true);
//_cutsceneManager->ClearQueue();
}
bool AMainGameModeBase::SetPause(APlayerController* PC, FCanUnpause CanUnpauseDelegate)
{
if(_widgetsManager)
{
if(IsPaused())
{
_widgetsManager->HideWidgets();
}
else
{
_widgetsManager->ShowWidgets();
}
}
return AGameModeBase::SetPause(PC, CanUnpauseDelegate);
}
UWidgetsManager* AMainGameModeBase::GetWidgetsManager()
{
return _widgetsManager;
}
UCutsceneManager* AMainGameModeBase::GetCutsceneManager()
{
return _cutsceneManager;
}
UDialogueManager* AMainGameModeBase::GetDialogueManager()
{
return _dialogueManager;
}
void AMainGameModeBase::CallNextLevelState()
{
if(leadLevel)
leadLevel->CallNextState();
}
void AMainGameModeBase::CallLevelEvent(int32 id)
{
if(leadLevel)
leadLevel->CallEvent(id);
}
void AMainGameModeBase::SwitchCameraMode()
{
static TWeakObjectPtr<APawn> _playerPawn = nullptr;
if(auto PC = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
if(auto pawn = PC->GetPawn())
{
if(!_playerPawn.IsValid())
{
auto spawnLoc = pawn->GetActorLocation();
auto spawnRot = pawn->GetActorRotation();
if(auto cameraPawn = GetWorld()->SpawnActor<APawn>(SpectatorClass, spawnLoc, spawnRot))
{
_playerPawn = pawn;
PC->Possess(cameraPawn);
}
}
else
{
PC->Possess(_playerPawn.Get());
pawn->Destroy();
_playerPawn = nullptr;
}
}
}
if(_widgetsManager)
{
_widgetsManager->UpdateWidgetsOwner();
}
}