Skip to content

Commit

Permalink
[New Main Menu] Fixed no UI after reloading level
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSeliv committed Oct 20, 2023
1 parent 7592324 commit 33462ec
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void UNMMHUDComponent::OnRegister()
{
Super::OnRegister();

const UNMMDataAsset* NewMainMenuDataAsset = UNMMSubsystem::Get(this).GetNewMainMenuDataAsset();
const UNMMDataAsset* NewMainMenuDataAsset = UNMMSubsystem::Get().GetNewMainMenuDataAsset();
checkf(NewMainMenuDataAsset, TEXT("ERROR: 'NewMainMenuDataAssetInternal' is null!"));
const AMyHUD& HUD = GetHUDChecked();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void UNMMPlayerControllerComponent::BeginPlay()
GetPlayerControllerChecked().SetupInputContexts(MenuInputContexts);

// Listen to set Menu game state once first spot is ready
UNMMSubsystem::Get(this).OnMainMenuSpotReady.AddUniqueDynamic(this, &ThisClass::OnMainMenuSpotReady);
UNMMSubsystem::Get().OnMainMenuSpotReady.AddUniqueDynamic(this, &ThisClass::OnMainMenuSpotReady);

// Disable auto camera possess by default, so it can be controlled by the spot
UMyCameraComponent* LevelCamera = UMyBlueprintFunctionLibrary::GetLevelCamera();
Expand Down Expand Up @@ -118,9 +118,6 @@ void UNMMPlayerControllerComponent::OnUnregister()
SaveGameDataInternal = nullptr;
}

// Kill subsystem
UNMMSubsystem::Deactivate();

Super::OnUnregister();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ UNMMSpotComponent::UNMMSpotComponent()
// Returns true if this spot is currently active and possessed by player
bool UNMMSpotComponent::IsActiveSpot() const
{
return UNMMSubsystem::Get(this).GetActiveMainMenuSpotComponent() == this;
return UNMMSubsystem::Get().GetActiveMainMenuSpotComponent() == this;
}

// Returns the Skeletal Mesh of the Bomber character
Expand Down Expand Up @@ -119,7 +119,7 @@ void UNMMSpotComponent::BeginPlay()
return;
}

UNMMSubsystem::Get(this).AddNewMainMenuSpot(this);
UNMMSubsystem::Get().AddNewMainMenuSpot(this);

UpdateCinematicData();
LoadMasterSequencePlayer();
Expand Down Expand Up @@ -148,6 +148,11 @@ void UNMMSpotComponent::OnUnregister()
MasterPlayerInternal = nullptr;
}

if (UNMMSubsystem* Subsystem = UNMMUtils::GetNewMainMenuSubsystem(this))
{
Subsystem->RemoveMainMenuSpot(this);
}

Super::OnUnregister();
}

Expand Down Expand Up @@ -315,7 +320,7 @@ void UNMMSpotComponent::OnMasterSequenceLoaded(TSoftObjectPtr<ULevelSequence> Lo
MasterPlayerInternal->Initialize(GetMasterSequence(), GetWorld()->PersistentLevel, CameraSettings);

// Notify that the spot is ready and finished loading
UNMMSubsystem::Get(this).OnMainMenuSpotReady.Broadcast(this);
UNMMSubsystem::Get().OnMainMenuSpotReady.Broadcast(this);

// Bind to react on cinematic finished, is pause instead of stop because of Settings.bPauseAtEnd
MasterPlayerInternal->OnPause.AddUniqueDynamic(this, &ThisClass::OnMasterSequencePaused);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ UNMMSubsystem& UNMMSubsystem::Get(const UObject* OptionalWorldContext/* = nullpt
return *ThisSubsystem;
}

// Deinitialize this subsystem. Is called when controller is killed
void UNMMSubsystem::Deactivate()
{
FSubsystemCollectionBase::DeactivateExternalSubsystem(StaticClass());
}

// Returns the data asset that contains all the assets and tweaks of New Main Menu game feature
const UNMMDataAsset* UNMMSubsystem::GetNewMainMenuDataAsset() const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void UNewMainMenuWidget::OnPlayButtonPressed()
{
// Start cinematic
// If should skip, then start the game instead
const UNMMSpotComponent* MainMenuSpot = UNMMSubsystem::Get(this).GetActiveMainMenuSpotComponent();
const UNMMSpotComponent* MainMenuSpot = UNMMSubsystem::Get().GetActiveMainMenuSpotComponent();
const FNMMCinematicRow& CinematicRow = MainMenuSpot ? MainMenuSpot->GetCinematicRow() : FNMMCinematicRow::Empty;
const ECGS NewState = !UNMMUtils::ShouldSkipCinematic(CinematicRow) ? ECGS::Cinematic : ECGS::GameStarting;
MyPC->ServerSetGameState(NewState);
Expand Down Expand Up @@ -140,7 +140,7 @@ void UNewMainMenuWidget::SwitchCurrentPlayer(int32 Incrementer)
USoundsSubsystem::Get().PlayUIClickSFX();

// Switch the Main Menu spot
const UNMMSpotComponent* MainMenuSpot = UNMMSubsystem::Get(this).MoveMainMenuSpot(Incrementer);
const UNMMSpotComponent* MainMenuSpot = UNMMSubsystem::Get().MoveMainMenuSpot(Incrementer);

// Update the chosen player mesh on the level
const FCustomPlayerMeshData& CustomPlayerMeshData = MainMenuSpot ? MainMenuSpot->GetMeshChecked().GetCustomPlayerMeshData() : FCustomPlayerMeshData::Empty;
Expand All @@ -154,7 +154,7 @@ void UNewMainMenuWidget::SwitchCurrentPlayer(int32 Incrementer)
void UNewMainMenuWidget::OnNextSkinButtonPressed()
{
APlayerCharacter* LocalPlayerCharacter = GetOwningPlayerPawn<APlayerCharacter>();
const UNMMSpotComponent* MainMenuSpot = UNMMSubsystem::Get(this).GetActiveMainMenuSpotComponent();
const UNMMSpotComponent* MainMenuSpot = UNMMSubsystem::Get().GetActiveMainMenuSpotComponent();
if (!ensureMsgf(LocalPlayerCharacter, TEXT("ASSERT: 'LocalPlayerCharacter' is not valid"))
|| !ensureMsgf(MainMenuSpot, TEXT("ASSERT: 'MainMenuSpot' is not valid")))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class NEWMAINMENU_API UNMMSubsystem : public UWorldSubsystem
/** Returns this Subsystem, is checked and wil crash if can't be obtained.*/
static UNMMSubsystem& Get(const UObject* OptionalWorldContext = nullptr);

/** Deinitialize this subsystem. Is called when controller is killed. */
static void Deactivate();

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMainMenuSpotReady, UNMMSpotComponent*, MainMenuSpotComponent);

/** Called when the spot was spawned on new level and it finished loading its Master Sequence. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ UWorld* FEditorUtilsLibrary::GetEditorWorld()
if (IsPIE())
{
FoundWorld = GEditor->GetCurrentPlayWorld();
if (!FoundWorld)
{
const FWorldContext* PIEWorldContext = GEditor->GetPIEWorldContext();
FoundWorld = PIEWorldContext ? PIEWorldContext->World() : nullptr;
}
}

if (!FoundWorld)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ bool UInputUtilsLibrary::IsInputContextEnabled(const UObject* WorldContext, cons
void UInputUtilsLibrary::SetInputContextEnabled(const UObject* WorldContext, bool bEnable, const UInputMappingContext* InInputContext, int32 Priority/* = 0*/)
{
UEnhancedInputLocalPlayerSubsystem* InputSubsystem = GetEnhancedInputSubsystem(WorldContext);
if (!ensureMsgf(InputSubsystem, TEXT("ASSERT: 'InputSubsystem' is not valid"))
|| !ensureMsgf(InInputContext, TEXT("ASSERT: 'InInputContext' is not valid")))
if (!InputSubsystem)
{
// Can be null on remote clients, do nothing
return;
}

if (!ensureMsgf(InInputContext, TEXT("ASSERT: 'InInputContext' is not valid")))
{
return;
}
Expand Down
5 changes: 5 additions & 0 deletions Source/Bomber/Private/Controllers/MyPlayerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ void AMyPlayerController::SetupInputContexts(const TArray<const UMyInputMappingC
// Removes input contexts from managed list
void AMyPlayerController::RemoveInputContexts(const TArray<const UMyInputMappingContext*>& InputContexts)
{
if (!IsLocalController())
{
return;
}

for (const UMyInputMappingContext* InputContextIt : InputContexts)
{
if (InputContextIt)
Expand Down

0 comments on commit 33462ec

Please sign in to comment.