This commit is contained in:
Oleg Petruny 2024-12-11 21:43:01 +01:00
parent 0226afe5ae
commit 39ab5e17a8
16 changed files with 48 additions and 56 deletions

View File

@ -39,7 +39,7 @@ void ACameraModeBase::BeginPlay()
{ {
if(auto inputSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer())) if(auto inputSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer()))
{ {
if(auto GI = Cast<UCustomGameInstanceBase>(GetWorld()->GetGameInstance())) if(auto GI = UCustomGameInstanceBase::GetGameInstance())
{ {
inputSubsystem->ClearAllMappings(); inputSubsystem->ClearAllMappings();
for(auto& inputContext : GI->inputContexts) for(auto& inputContext : GI->inputContexts)

View File

@ -1,6 +1,5 @@
// Oleg Petruny proprietary. // Oleg Petruny proprietary.
#include "CustomGameInstanceBase.h" #include "CustomGameInstanceBase.h"
#include "EnhancedInputLibrary.h" #include "EnhancedInputLibrary.h"

View File

@ -20,13 +20,10 @@ UCutsceneManager::UCutsceneManager()
{ {
static ConstructorHelpers::FObjectFinder<UInputMappingContext> asset{ TEXT("/Script/EnhancedInput.InputMappingContext'/Game/Input/IMC_Cutscene.IMC_Cutscene'") }; static ConstructorHelpers::FObjectFinder<UInputMappingContext> asset{ TEXT("/Script/EnhancedInput.InputMappingContext'/Game/Input/IMC_Cutscene.IMC_Cutscene'") };
_inputContext = asset.Object; _inputContext = asset.Object;
if(auto world = GetWorld()) if(auto GI = UCustomGameInstanceBase::GetGameInstance())
{
if(auto GI = Cast<UCustomGameInstanceBase>(world->GetGameInstance()))
{ {
GI->inputContexts.Add(_inputContext); GI->inputContexts.Add(_inputContext);
} }
}
} }
void UCutsceneManager::EnqueueSequence(ULevelSequence* sequence, FCutsceneEndCallback endCallback) void UCutsceneManager::EnqueueSequence(ULevelSequence* sequence, FCutsceneEndCallback endCallback)

View File

@ -22,13 +22,10 @@ UDialogueManager::UDialogueManager()
{ {
static ConstructorHelpers::FObjectFinder<UInputMappingContext> asset{ TEXT("/Script/EnhancedInput.InputMappingContext'/Game/Input/IMC_Dialogue.IMC_Dialogue'") }; static ConstructorHelpers::FObjectFinder<UInputMappingContext> asset{ TEXT("/Script/EnhancedInput.InputMappingContext'/Game/Input/IMC_Dialogue.IMC_Dialogue'") };
_inputContext = asset.Object; _inputContext = asset.Object;
if(auto world = GetWorld()) if(auto GI = UCustomGameInstanceBase::GetGameInstance())
{
if(auto GI = Cast<UCustomGameInstanceBase>(world->GetGameInstance()))
{ {
GI->inputContexts.Add(_inputContext); GI->inputContexts.Add(_inputContext);
} }
}
} }
void UDialogueManager::PlayDialogue(FDialogueEnqueProperties properties, FDialogueEndCallback endCallback) void UDialogueManager::PlayDialogue(FDialogueEnqueProperties properties, FDialogueEndCallback endCallback)

View File

@ -11,13 +11,10 @@ void UInteractableModificator::OnRegister()
{ {
UActorComponent::OnRegister(); UActorComponent::OnRegister();
if(auto world = GetWorld()) if(auto GI = UCustomGameInstanceBase::GetGameInstance())
{
if(auto GI = Cast<UCustomGameInstanceBase>(world->GetGameInstance()))
{ {
GI->AppendInteractableModificatorClass(this->GetClass()); GI->AppendInteractableModificatorClass(this->GetClass());
} }
}
} }
const UInputMappingContext* UInteractableModificator::GetMappingContext() const const UInputMappingContext* UInteractableModificator::GetMappingContext() const

View File

@ -1,12 +1,11 @@
// Oleg Petruny proprietary. // Oleg Petruny proprietary.
#include "Checkpoint.h" #include "Checkpoint.h"
#include "CustomGameInstanceBase.h" #include "CustomGameInstanceBase.h"
void ACheckpoint::SaveGame() void ACheckpoint::SaveGame()
{ {
if(auto GI = Cast<UCustomGameInstanceBase>(GetWorld()->GetGameInstance())) if(auto GI = UCustomGameInstanceBase::GetGameInstance())
GI->SaveGame(GetFName()); GI->SaveGame(GetFName());
} }

View File

@ -6,6 +6,7 @@
#include "Checkpoint.generated.h" #include "Checkpoint.generated.h"
/** Simple actor for game save */
UCLASS(Blueprintable, BlueprintType, MinimalAPI) UCLASS(Blueprintable, BlueprintType, MinimalAPI)
class ACheckpoint : public AActor class ACheckpoint : public AActor
{ {

View File

@ -1,6 +1,5 @@
// Oleg Petruny proprietary. // Oleg Petruny proprietary.
#include "Level1.h" #include "Level1.h"
#include "Atmosphere/AtmosphericFog.h" #include "Atmosphere/AtmosphericFog.h"

View File

@ -1,6 +1,5 @@
// Oleg Petruny proprietary. // Oleg Petruny proprietary.
#include "Level2.h" #include "Level2.h"
void ALevel2::BeginPlay() void ALevel2::BeginPlay()

View File

@ -1,6 +1,5 @@
// Oleg Petruny proprietary. // Oleg Petruny proprietary.
#include "Level3.h" #include "Level3.h"
#include "Atmosphere/AtmosphericFog.h" #include "Atmosphere/AtmosphericFog.h"

View File

@ -1,6 +1,5 @@
// Oleg Petruny proprietary. // Oleg Petruny proprietary.
#include "Level4.h" #include "Level4.h"
#include "Atmosphere/AtmosphericFog.h" #include "Atmosphere/AtmosphericFog.h"

View File

@ -1,6 +1,5 @@
// Oleg Petruny proprietary. // Oleg Petruny proprietary.
#include "Level5.h" #include "Level5.h"
#include "Atmosphere/AtmosphericFog.h" #include "Atmosphere/AtmosphericFog.h"

View File

@ -1,6 +1,5 @@
// Oleg Petruny proprietary. // Oleg Petruny proprietary.
#include "LevelBase.h" #include "LevelBase.h"
#include "Engine/StaticMesh.h" #include "Engine/StaticMesh.h"
@ -23,16 +22,13 @@ void ALevelBase::BeginPlay()
{ {
AMainGameModeBase::leadLevel = TStrongObjectPtr<ALevelBase>{ this }; AMainGameModeBase::leadLevel = TStrongObjectPtr<ALevelBase>{ this };
if(auto world = GetWorld()) if(auto GI = UCustomGameInstanceBase::GetGameInstance())
{
if(auto GI = Cast<UCustomGameInstanceBase>(world->GetGameInstance()))
{ {
for(TActorIterator<AMinigame> it(GetWorld()); it; ++it) for(TActorIterator<AMinigame> it(GetWorld()); it; ++it)
{ {
GI->inputContexts.Add(it->GetInputMappings()); GI->inputContexts.Add(it->GetInputMappings());
} }
} }
}
ALevelScriptActor::BeginPlay(); ALevelScriptActor::BeginPlay();
@ -62,7 +58,7 @@ void ALevelBase::IterateToState(int32 to)
void ALevelBase::BroadcastNewLevelBeginPlay() void ALevelBase::BroadcastNewLevelBeginPlay()
{ {
if(auto GI = Cast<UCustomGameInstanceBase>(GetWorld()->GetGameInstance())) if(auto GI = UCustomGameInstanceBase::GetGameInstance())
GI->OnLevelBeginned.Broadcast(GetFName()); GI->OnLevelBeginned.Broadcast(GetFName());
} }

View File

@ -6,15 +6,24 @@
#include "LevelBase.generated.h" #include "LevelBase.generated.h"
/**
* Expands basic UE level script actor.
* Has int type level states and events.
* Brodcasts level instantiation by CustomGameInstance::OnLevelBeginned(FName).
* On BeginPlay applies last save data if valid,
* and instantiate all sequencers from array onBeginPlaySequences.
*/
UCLASS(BlueprintType) UCLASS(BlueprintType)
class ALevelBase : public ALevelScriptActor class ALevelBase : public ALevelScriptActor
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
/** Iterates throught level states */
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
inline void CallNextState() { ++state; NextState(); } inline void CallNextState() { ++state; NextState(); }
/** Calls specific event id in level */
UFUNCTION(BlueprintImplementableEvent) UFUNCTION(BlueprintImplementableEvent)
void CallEvent(int32 id); void CallEvent(int32 id);
@ -23,9 +32,11 @@ public:
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
/** Notifies level to process current state */
UFUNCTION(BlueprintImplementableEvent) UFUNCTION(BlueprintImplementableEvent)
void NextState(); void NextState();
/** Shortcut for iterating from current to expected state */
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void IterateToState(int32 to); void IterateToState(int32 to);
@ -33,12 +44,13 @@ protected:
void StartLevelAnimations(); void StartLevelAnimations();
void ApplySaveData(); void ApplySaveData();
/** List of level animations for instantiation on level BeginPlay */
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
TArray<TSoftObjectPtr<class ULevelSequence>> onBeginPlaySequences; TArray<TSoftObjectPtr<class ULevelSequence>> onBeginPlaySequences;
/** Cache of actors that hold instantiated animations on BeginPlay */
TArray<class ALevelSequenceActor*> onBeginPlaySequencesActors; TArray<class ALevelSequenceActor*> onBeginPlaySequencesActors;
/** Current state of level */
UPROPERTY(BlueprintReadOnly) UPROPERTY(BlueprintReadOnly)
int32 state = -1; int32 state = -1;
UPROPERTY(EditDefaultsOnly)
TArray<TSoftObjectPtr<class ULevelSequence>> stateSequences;
}; };

View File

@ -89,7 +89,7 @@ void APlayerBase::BeginPlay()
{ {
if(auto inputSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(playerController->GetLocalPlayer())) if(auto inputSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(playerController->GetLocalPlayer()))
{ {
if(auto GI = Cast<UCustomGameInstanceBase>(GetWorld()->GetGameInstance())) if(auto GI = UCustomGameInstanceBase::GetGameInstance())
{ {
inputSubsystem->ClearAllMappings(); inputSubsystem->ClearAllMappings();
for(auto& inputContext : GI->inputContexts) for(auto& inputContext : GI->inputContexts)
@ -257,8 +257,10 @@ void APlayerBase::UpdatePitch(float min, float max)
void APlayerBase::LoadInteractablesActivators() void APlayerBase::LoadInteractablesActivators()
{ {
if(auto GI = Cast<UCustomGameInstanceBase>(GetWorld()->GetGameInstance())) auto GI = UCustomGameInstanceBase::GetGameInstance();
{ if(!GI)
return;
TSet<UClass*> instancedActivators; TSet<UClass*> instancedActivators;
for(auto& act : GI->interactionsActivators) for(auto& act : GI->interactionsActivators)
{ {
@ -273,7 +275,6 @@ void APlayerBase::LoadInteractablesActivators()
component->RegisterComponent(); component->RegisterComponent();
interactableActivators.Add(component); interactableActivators.Add(component);
} }
}
} }
void APlayerBase::InteractableActivated(AInteractable* interactable, EActivatorType type) void APlayerBase::InteractableActivated(AInteractable* interactable, EActivatorType type)

View File

@ -14,15 +14,13 @@ bool UMainMenuWidget::Initialize()
{ {
if(ButtonLoadLastSave) if(ButtonLoadLastSave)
{ {
if(auto GI = UCustomGameInstanceBase::GetGameInstance()) auto GI = UCustomGameInstanceBase::GetGameInstance();
{ if(GI && GI->saveData)
if(GI->saveData)
{ {
ButtonLoadLastSave->SetIsEnabled(true); ButtonLoadLastSave->SetIsEnabled(true);
ButtonLoadLastSave->SetRenderOpacity(1.0f); ButtonLoadLastSave->SetRenderOpacity(1.0f);
} }
} }
}
//FWidgetAnimationDynamicEvent closeFinished; //FWidgetAnimationDynamicEvent closeFinished;
//closeFinished.BindDynamic(this, &UMainMenuWidget::Closed); //closeFinished.BindDynamic(this, &UMainMenuWidget::Closed);