From 39ab5e17a8009e09de094b2ab41c23fe3c1acc7d Mon Sep 17 00:00:00 2001 From: Oleg Petruny Date: Wed, 11 Dec 2024 21:43:01 +0100 Subject: [PATCH] Levels --- .../Lost_Edge/Private/CameraModeBase.cpp | 2 +- .../Private/CustomGameInstanceBase.cpp | 1 - .../Lost_Edge/Private/CutsceneManager.cpp | 7 ++-- .../Lost_Edge/Private/DialogueManager.cpp | 7 ++-- .../Modificators/InteractableModificator.cpp | 7 ++-- .../Lost_Edge/Private/Levels/Checkpoint.cpp | 3 +- .../Lost_Edge/Private/Levels/Checkpoint.h | 1 + .../Lost_Edge/Private/Levels/Level1.cpp | 1 - .../Lost_Edge/Private/Levels/Level2.cpp | 1 - .../Lost_Edge/Private/Levels/Level3.cpp | 1 - .../Lost_Edge/Private/Levels/Level4.cpp | 1 - .../Lost_Edge/Private/Levels/Level5.cpp | 1 - .../Lost_Edge/Private/Levels/LevelBase.cpp | 12 +++---- .../Lost_Edge/Private/Levels/LevelBase.h | 16 +++++++-- .../Source/Lost_Edge/Private/PlayerBase.cpp | 33 ++++++++++--------- .../Widgets/MainMenu/MainMenuWidget.cpp | 10 +++--- 16 files changed, 48 insertions(+), 56 deletions(-) diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CameraModeBase.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CameraModeBase.cpp index 53501c4..7410b09 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CameraModeBase.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CameraModeBase.cpp @@ -39,7 +39,7 @@ void ACameraModeBase::BeginPlay() { if(auto inputSubsystem = ULocalPlayer::GetSubsystem(PC->GetLocalPlayer())) { - if(auto GI = Cast(GetWorld()->GetGameInstance())) + if(auto GI = UCustomGameInstanceBase::GetGameInstance()) { inputSubsystem->ClearAllMappings(); for(auto& inputContext : GI->inputContexts) diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CustomGameInstanceBase.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CustomGameInstanceBase.cpp index 9c53d08..b4da336 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CustomGameInstanceBase.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CustomGameInstanceBase.cpp @@ -1,6 +1,5 @@ // Oleg Petruny proprietary. - #include "CustomGameInstanceBase.h" #include "EnhancedInputLibrary.h" diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CutsceneManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CutsceneManager.cpp index 953c846..ab9817b 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CutsceneManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/CutsceneManager.cpp @@ -20,12 +20,9 @@ UCutsceneManager::UCutsceneManager() { static ConstructorHelpers::FObjectFinder 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(world->GetGameInstance())) - { - GI->inputContexts.Add(_inputContext); - } + GI->inputContexts.Add(_inputContext); } } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/DialogueManager.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/DialogueManager.cpp index a9bbbd1..a9c3a44 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/DialogueManager.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/DialogueManager.cpp @@ -22,12 +22,9 @@ UDialogueManager::UDialogueManager() { static ConstructorHelpers::FObjectFinder 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(world->GetGameInstance())) - { - GI->inputContexts.Add(_inputContext); - } + GI->inputContexts.Add(_inputContext); } } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.cpp index c527544..43d477a 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Interactable/Modificators/InteractableModificator.cpp @@ -11,12 +11,9 @@ void UInteractableModificator::OnRegister() { UActorComponent::OnRegister(); - if(auto world = GetWorld()) + if(auto GI = UCustomGameInstanceBase::GetGameInstance()) { - if(auto GI = Cast(world->GetGameInstance())) - { - GI->AppendInteractableModificatorClass(this->GetClass()); - } + GI->AppendInteractableModificatorClass(this->GetClass()); } } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Checkpoint.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Checkpoint.cpp index 7cca7d5..b9a2beb 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Checkpoint.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Checkpoint.cpp @@ -1,12 +1,11 @@ // Oleg Petruny proprietary. - #include "Checkpoint.h" #include "CustomGameInstanceBase.h" void ACheckpoint::SaveGame() { - if(auto GI = Cast(GetWorld()->GetGameInstance())) + if(auto GI = UCustomGameInstanceBase::GetGameInstance()) GI->SaveGame(GetFName()); } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Checkpoint.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Checkpoint.h index 6f452f8..ebe7b9a 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Checkpoint.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Checkpoint.h @@ -6,6 +6,7 @@ #include "Checkpoint.generated.h" +/** Simple actor for game save */ UCLASS(Blueprintable, BlueprintType, MinimalAPI) class ACheckpoint : public AActor { diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level1.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level1.cpp index 9a4c982..3d7fd6d 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level1.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level1.cpp @@ -1,6 +1,5 @@ // Oleg Petruny proprietary. - #include "Level1.h" #include "Atmosphere/AtmosphericFog.h" diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level2.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level2.cpp index 5c6a12e..9915566 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level2.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level2.cpp @@ -1,6 +1,5 @@ // Oleg Petruny proprietary. - #include "Level2.h" void ALevel2::BeginPlay() diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level3.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level3.cpp index b80c2f3..82126eb 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level3.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level3.cpp @@ -1,6 +1,5 @@ // Oleg Petruny proprietary. - #include "Level3.h" #include "Atmosphere/AtmosphericFog.h" diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level4.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level4.cpp index 9851fce..6622d1f 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level4.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level4.cpp @@ -1,6 +1,5 @@ // Oleg Petruny proprietary. - #include "Level4.h" #include "Atmosphere/AtmosphericFog.h" diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level5.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level5.cpp index cfe7740..cf35120 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level5.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/Level5.cpp @@ -1,6 +1,5 @@ // Oleg Petruny proprietary. - #include "Level5.h" #include "Atmosphere/AtmosphericFog.h" diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.cpp index 9686572..6cf735f 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.cpp @@ -1,6 +1,5 @@ // Oleg Petruny proprietary. - #include "LevelBase.h" #include "Engine/StaticMesh.h" @@ -23,14 +22,11 @@ void ALevelBase::BeginPlay() { AMainGameModeBase::leadLevel = TStrongObjectPtr{ this }; - if(auto world = GetWorld()) + if(auto GI = UCustomGameInstanceBase::GetGameInstance()) { - if(auto GI = Cast(world->GetGameInstance())) + for(TActorIterator it(GetWorld()); it; ++it) { - for(TActorIterator 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(GetWorld()->GetGameInstance())) + if(auto GI = UCustomGameInstanceBase::GetGameInstance()) GI->OnLevelBeginned.Broadcast(GetFName()); } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.h b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.h index 6536b3f..3c9929d 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.h +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Levels/LevelBase.h @@ -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> onBeginPlaySequences; + /** Cache of actors that hold instantiated animations on BeginPlay */ TArray onBeginPlaySequencesActors; + /** Current state of level */ UPROPERTY(BlueprintReadOnly) int32 state = -1; - UPROPERTY(EditDefaultsOnly) - TArray> stateSequences; }; diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.cpp index b09a74a..375ad49 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/PlayerBase.cpp @@ -89,7 +89,7 @@ void APlayerBase::BeginPlay() { if(auto inputSubsystem = ULocalPlayer::GetSubsystem(playerController->GetLocalPlayer())) { - if(auto GI = Cast(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(GetWorld()->GetGameInstance())) - { - TSet instancedActivators; - for(auto& act : GI->interactionsActivators) - { - if(instancedActivators.Contains(act)) - continue; - instancedActivators.Add(act); + auto GI = UCustomGameInstanceBase::GetGameInstance(); + if(!GI) + return; - auto component = NewObject(this, act); - component->interactableActivatedDelegate.BindUObject(this, &APlayerBase::InteractableActivated); - component->interactableDeactivatedDelegate.BindUObject(this, &APlayerBase::InteractableDeactivated); - component->SetupAttachment(camera); - component->RegisterComponent(); - interactableActivators.Add(component); - } + TSet instancedActivators; + for(auto& act : GI->interactionsActivators) + { + if(instancedActivators.Contains(act)) + continue; + instancedActivators.Add(act); + + auto component = NewObject(this, act); + component->interactableActivatedDelegate.BindUObject(this, &APlayerBase::InteractableActivated); + component->interactableDeactivatedDelegate.BindUObject(this, &APlayerBase::InteractableDeactivated); + component->SetupAttachment(camera); + component->RegisterComponent(); + interactableActivators.Add(component); } } diff --git a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Widgets/MainMenu/MainMenuWidget.cpp b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Widgets/MainMenu/MainMenuWidget.cpp index 9943ef7..47e1a66 100644 --- a/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Widgets/MainMenu/MainMenuWidget.cpp +++ b/UnrealProject/Lost_Edge/Source/Lost_Edge/Private/Widgets/MainMenu/MainMenuWidget.cpp @@ -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); } }