Skip to content

Commit bbe682a

Browse files
committed
Make HUD and In-Game menu work in multiplayer, moved In-Game Menu to separated widget
1 parent 8ce03b1 commit bbe682a

File tree

15 files changed

+439
-259
lines changed

15 files changed

+439
-259
lines changed
44 Bytes
Binary file not shown.
835 Bytes
Binary file not shown.
-152 KB
Binary file not shown.
32.1 KB
Binary file not shown.

Source/Bomber/Private/Controllers/MyPlayerController.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "Globals/MyInputAction.h"
1616
#include "Globals/SingletonLibrary.h"
1717
#include "LevelActors/PlayerCharacter.h"
18-
#include "UI/InGameWidget.h"
18+
#include "UI/InGameMenuWidget.h"
1919
#include "UI/MainMenuWidget.h"
2020
#include "UI/MyHUD.h"
2121
#include "UI/SettingsWidget.h"
@@ -303,7 +303,6 @@ void AMyPlayerController::OnPossess(APawn* InPawn)
303303

304304
SetControlRotation(FRotator::ZeroRotator);
305305

306-
BroadcastOnPossessed();
307306
BroadcastOnSetPlayerState();
308307

309308
BindInputActions();
@@ -314,7 +313,8 @@ void AMyPlayerController::OnRep_Pawn()
314313
{
315314
Super::OnRep_Pawn();
316315

317-
BroadcastOnPossessed();
316+
// Notify client about pawn change
317+
GetOnNewPawnNotifier().Broadcast(GetPawn());
318318

319319
BindInputActions();
320320
}
@@ -556,10 +556,10 @@ void AMyPlayerController::OnWidgetsInitialized()
556556
}
557557

558558
// Listens to handle input on opening and closing the InGame Menu widget
559-
UInGameWidget* InGameWidget = USingletonLibrary::GetInGameWidget();
560-
if (ensureMsgf(InGameWidget, TEXT("ASSERT: 'InGameWidget' is not valid")))
559+
UInGameMenuWidget* InGameMenuWidget = USingletonLibrary::GetInGameMenuWidget();
560+
if (ensureMsgf(InGameMenuWidget, TEXT("ASSERT: 'InGameMenuWidget' is not valid")))
561561
{
562-
InGameWidget->OnToggledInGameMenu.AddUniqueDynamic(this, &ThisClass::OnToggledInGameMenu);
562+
InGameMenuWidget->OnToggledInGameMenu.AddUniqueDynamic(this, &ThisClass::OnToggledInGameMenu);
563563
}
564564

565565
// Listens to handle input on opening and closing the Settings widget
@@ -570,23 +570,6 @@ void AMyPlayerController::OnWidgetsInitialized()
570570
}
571571
}
572572

573-
// Is called on server and on client when this controller possesses new player character
574-
void AMyPlayerController::BroadcastOnPossessed()
575-
{
576-
if (!OnPossessed.IsBound())
577-
{
578-
return;
579-
}
580-
581-
APlayerCharacter* PlayerCharacter = GetPawn<APlayerCharacter>();
582-
if (!PlayerCharacter)
583-
{
584-
return;
585-
}
586-
587-
OnPossessed.Broadcast(PlayerCharacter);
588-
}
589-
590573
// Is called on server and on client the player state is set
591574
void AMyPlayerController::BroadcastOnSetPlayerState()
592575
{

Source/Bomber/Private/GameFramework/MyPlayerState.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "Globals/SingletonLibrary.h"
88
#include "LevelActors/PlayerCharacter.h"
99
//---
10-
#include "PoolManager.h"
1110
#include "Net/UnrealNetwork.h"
1211

1312
/* ---------------------------------------------------
@@ -106,12 +105,6 @@ void AMyPlayerState::ServerUpdateEndState_Implementation()
106105
return;
107106
}
108107

109-
const UPoolManager* PoolManager = USingletonLibrary::GetPoolManager();
110-
if (!PoolManager)
111-
{
112-
return;
113-
}
114-
115108
// handle timer is 0
116109
if (CurrentGameState == ECurrentGameState::EndGame) // game was finished
117110
{
@@ -132,7 +125,7 @@ void AMyPlayerState::ServerUpdateEndState_Implementation()
132125
const int32 PlayerNum = USingletonLibrary::GetAlivePlayersNum();
133126
const APawn* PawnOwner = GetPawn();
134127
if (!PawnOwner
135-
|| !PoolManager->IsActive(PawnOwner)) // is dead owner
128+
|| !PawnOwner->GetController()) // is dead owner
136129
{
137130
if (PlayerNum <= 0) // last players were blasted together
138131
{
@@ -149,7 +142,7 @@ void AMyPlayerState::ServerUpdateEndState_Implementation()
149142
}
150143
else if (PlayerNum == 1) // is alive owner and is the last player
151144
{
152-
if (PawnOwner->GetController<APlayerController>()) // is player
145+
if (PawnOwner->IsPlayerControlled())
153146
{
154147
EndGameStateInternal = EEndGameState::Win;
155148
}
@@ -169,3 +162,9 @@ void AMyPlayerState::ServerUpdateEndState_Implementation()
169162
OnEndGameStateChanged.Broadcast(EndGameStateInternal);
170163
}
171164
}
165+
166+
// Is called on clients to apply current End-Game state
167+
void AMyPlayerState::OnRep_EndGameState()
168+
{
169+
OnEndGameStateChanged.Broadcast(EndGameStateInternal);
170+
}

Source/Bomber/Private/Globals/SingletonLibrary.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#include "Globals/MyGameInstance.h"
1616
#include "LevelActors/PlayerCharacter.h"
1717
#include "UI/MyHUD.h"
18-
#include "UI/InputControlsWidget.h"
18+
#include "UI/InGameWidget.h"
19+
#include "UI/InGameMenuWidget.h"
1920
//---
2021
#include "Engine.h"
2122
#include "PoolManager.h"
@@ -394,13 +395,20 @@ UMainMenuWidget* USingletonLibrary::GetMainMenuWidget()
394395
return MyHUD ? MyHUD->GetMainMenuWidget() : nullptr;
395396
}
396397

397-
// Returns the In-Game Menu widget
398+
// Returns the In-Game widget
398399
UInGameWidget* USingletonLibrary::GetInGameWidget()
399400
{
400401
const AMyHUD* MyHUD = GetMyHUD();
401402
return MyHUD ? MyHUD->GetInGameWidget() : nullptr;
402403
}
403404

405+
// Returns the In-Game Menu widget
406+
UInGameMenuWidget* USingletonLibrary::GetInGameMenuWidget()
407+
{
408+
const UInGameWidget* InGameWidget = GetInGameWidget();
409+
return InGameWidget ? InGameWidget->GetInGameMenuWidget() : nullptr;
410+
}
411+
404412
// Returns specified player character, by default returns local player
405413
APlayerCharacter* USingletonLibrary::GetPlayerCharacter(int32 PlayerIndex)
406414
{

0 commit comments

Comments
 (0)