File size: 2,151 Bytes
7fd553e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | // Copyright Epic Games, Inc. All Rights Reserved.
#include "GameFeatureAction_SplitscreenConfig.h"
#include "Engine/GameInstance.h"
#include "Engine/GameViewportClient.h"
#include "GameFeatures/GameFeatureAction_WorldActionBase.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(GameFeatureAction_SplitscreenConfig)
#define LOCTEXT_NAMESPACE "LyraGameFeatures"
//////////////////////////////////////////////////////////////////////
// UGameFeatureAction_SplitscreenConfig
TMap<FObjectKey, int32> UGameFeatureAction_SplitscreenConfig::GlobalDisableVotes;
void UGameFeatureAction_SplitscreenConfig::OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context)
{
Super::OnGameFeatureDeactivating(Context);
for (int32 i = LocalDisableVotes.Num() - 1; i >= 0; i-- )
{
FObjectKey ViewportKey = LocalDisableVotes[i];
UGameViewportClient* GVP = Cast<UGameViewportClient>(ViewportKey.ResolveObjectPtr());
const FWorldContext* WorldContext = GEngine->GetWorldContextFromGameViewport(GVP);
if (GVP && WorldContext)
{
if (!Context.ShouldApplyToWorldContext(*WorldContext))
{
// Wrong context so ignore it, dead objects count as part of this context
continue;
}
}
int32& VoteCount = GlobalDisableVotes[ViewportKey];
if (VoteCount <= 1)
{
GlobalDisableVotes.Remove(ViewportKey);
if (GVP && WorldContext)
{
GVP->SetForceDisableSplitscreen(false);
}
}
else
{
--VoteCount;
}
LocalDisableVotes.RemoveAt(i);
}
}
void UGameFeatureAction_SplitscreenConfig::AddToWorld(const FWorldContext& WorldContext, const FGameFeatureStateChangeContext& ChangeContext)
{
if (bDisableSplitscreen)
{
if (UGameInstance* GameInstance = WorldContext.OwningGameInstance)
{
if (UGameViewportClient* VC = GameInstance->GetGameViewportClient())
{
FObjectKey ViewportKey(VC);
LocalDisableVotes.Add(ViewportKey);
int32& VoteCount = GlobalDisableVotes.FindOrAdd(ViewportKey);
VoteCount++;
if (VoteCount == 1)
{
VC->SetForceDisableSplitscreen(true);
}
}
}
}
}
#undef LOCTEXT_NAMESPACE
|