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 GI = Cast<UCustomGameInstanceBase>(GetWorld()->GetGameInstance()))
if(auto GI = UCustomGameInstanceBase::GetGameInstance())
{
inputSubsystem->ClearAllMappings();
for(auto& inputContext : GI->inputContexts)

View File

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

View File

@ -20,12 +20,9 @@ UCutsceneManager::UCutsceneManager()
{
static ConstructorHelpers::FObjectFinder<UInputMappingContext> asset{ TEXT("/Script/EnhancedInput.InputMappingContext'/Game/Input/IMC_Cutscene.IMC_Cutscene'") };
_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);
}
}

View File

@ -22,12 +22,9 @@ UDialogueManager::UDialogueManager()
{
static ConstructorHelpers::FObjectFinder<UInputMappingContext> asset{ TEXT("/Script/EnhancedInput.InputMappingContext'/Game/Input/IMC_Dialogue.IMC_Dialogue'") };
_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);
}
}

View File

@ -11,12 +11,9 @@ void UInteractableModificator::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());
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,5 @@
// Oleg Petruny proprietary.
#include "LevelBase.h"
#include "Engine/StaticMesh.h"
@ -23,14 +22,11 @@ void ALevelBase::BeginPlay()
{
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());
}
}
@ -62,7 +58,7 @@ void ALevelBase::IterateToState(int32 to)
void ALevelBase::BroadcastNewLevelBeginPlay()
{
if(auto GI = Cast<UCustomGameInstanceBase>(GetWorld()->GetGameInstance()))
if(auto GI = UCustomGameInstanceBase::GetGameInstance())
GI->OnLevelBeginned.Broadcast(GetFName());
}

View File

@ -6,15 +6,24 @@
#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)
class ALevelBase : public ALevelScriptActor
{
GENERATED_BODY()
public:
/** Iterates throught level states */
UFUNCTION(BlueprintCallable)
inline void CallNextState() { ++state; NextState(); }
/** Calls specific event id in level */
UFUNCTION(BlueprintImplementableEvent)
void CallEvent(int32 id);
@ -23,9 +32,11 @@ public:
protected:
virtual void BeginPlay() override;
/** Notifies level to process current state */
UFUNCTION(BlueprintImplementableEvent)
void NextState();
/** Shortcut for iterating from current to expected state */
UFUNCTION(BlueprintCallable)
void IterateToState(int32 to);
@ -33,12 +44,13 @@ protected:
void StartLevelAnimations();
void ApplySaveData();
/** List of level animations for instantiation on level BeginPlay */
UPROPERTY(EditDefaultsOnly)
TArray<TSoftObjectPtr<class ULevelSequence>> onBeginPlaySequences;
/** Cache of actors that hold instantiated animations on BeginPlay */
TArray<class ALevelSequenceActor*> onBeginPlaySequencesActors;
/** Current state of level */
UPROPERTY(BlueprintReadOnly)
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 GI = Cast<UCustomGameInstanceBase>(GetWorld()->GetGameInstance()))
if(auto GI = UCustomGameInstanceBase::GetGameInstance())
{
inputSubsystem->ClearAllMappings();
for(auto& inputContext : GI->inputContexts)
@ -257,22 +257,23 @@ void APlayerBase::UpdatePitch(float min, float max)
void APlayerBase::LoadInteractablesActivators()
{
if(auto GI = Cast<UCustomGameInstanceBase>(GetWorld()->GetGameInstance()))
{
TSet<UClass*> instancedActivators;
for(auto& act : GI->interactionsActivators)
{
if(instancedActivators.Contains(act))
continue;
instancedActivators.Add(act);
auto GI = UCustomGameInstanceBase::GetGameInstance();
if(!GI)
return;
auto component = NewObject<UInteractableActivator>(this, act);
component->interactableActivatedDelegate.BindUObject(this, &APlayerBase::InteractableActivated);
component->interactableDeactivatedDelegate.BindUObject(this, &APlayerBase::InteractableDeactivated);
component->SetupAttachment(camera);
component->RegisterComponent();
interactableActivators.Add(component);
}
TSet<UClass*> instancedActivators;
for(auto& act : GI->interactionsActivators)
{
if(instancedActivators.Contains(act))
continue;
instancedActivators.Add(act);
auto component = NewObject<UInteractableActivator>(this, act);
component->interactableActivatedDelegate.BindUObject(this, &APlayerBase::InteractableActivated);
component->interactableDeactivatedDelegate.BindUObject(this, &APlayerBase::InteractableDeactivated);
component->SetupAttachment(camera);
component->RegisterComponent();
interactableActivators.Add(component);
}
}

View File

@ -14,13 +14,11 @@ bool UMainMenuWidget::Initialize()
{
if(ButtonLoadLastSave)
{
if(auto GI = UCustomGameInstanceBase::GetGameInstance())
auto GI = UCustomGameInstanceBase::GetGameInstance();
if(GI && GI->saveData)
{
if(GI->saveData)
{
ButtonLoadLastSave->SetIsEnabled(true);
ButtonLoadLastSave->SetRenderOpacity(1.0f);
}
ButtonLoadLastSave->SetIsEnabled(true);
ButtonLoadLastSave->SetRenderOpacity(1.0f);
}
}