|
|
|
|
| #include "Player/LyraLocalPlayer.h"
|
|
|
| #include "AudioMixerBlueprintLibrary.h"
|
| #include "Engine/World.h"
|
| #include "GameFramework/PlayerController.h"
|
| #include "Settings/LyraSettingsLocal.h"
|
| #include "Settings/LyraSettingsShared.h"
|
| #include "CommonUserSubsystem.h"
|
|
|
| #include UE_INLINE_GENERATED_CPP_BY_NAME(LyraLocalPlayer)
|
|
|
| class UObject;
|
|
|
| ULyraLocalPlayer::ULyraLocalPlayer()
|
| {
|
| }
|
|
|
| void ULyraLocalPlayer::PostInitProperties()
|
| {
|
| Super::PostInitProperties();
|
|
|
| if (ULyraSettingsLocal* LocalSettings = GetLocalSettings())
|
| {
|
| LocalSettings->OnAudioOutputDeviceChanged.AddUObject(this, &ULyraLocalPlayer::OnAudioOutputDeviceChanged);
|
| }
|
| }
|
|
|
| void ULyraLocalPlayer::SwitchController(class APlayerController* PC)
|
| {
|
| Super::SwitchController(PC);
|
|
|
| OnPlayerControllerChanged(PlayerController);
|
| }
|
|
|
| bool ULyraLocalPlayer::SpawnPlayActor(const FString& URL, FString& OutError, UWorld* InWorld)
|
| {
|
| const bool bResult = Super::SpawnPlayActor(URL, OutError, InWorld);
|
|
|
| OnPlayerControllerChanged(PlayerController);
|
|
|
| return bResult;
|
| }
|
|
|
| void ULyraLocalPlayer::InitOnlineSession()
|
| {
|
| OnPlayerControllerChanged(PlayerController);
|
|
|
| Super::InitOnlineSession();
|
| }
|
|
|
| void ULyraLocalPlayer::OnPlayerControllerChanged(APlayerController* NewController)
|
| {
|
|
|
| FGenericTeamId OldTeamID = FGenericTeamId::NoTeam;
|
| if (ILyraTeamAgentInterface* ControllerAsTeamProvider = Cast<ILyraTeamAgentInterface>(LastBoundPC.Get()))
|
| {
|
| OldTeamID = ControllerAsTeamProvider->GetGenericTeamId();
|
| ControllerAsTeamProvider->GetTeamChangedDelegateChecked().RemoveAll(this);
|
| }
|
|
|
|
|
| FGenericTeamId NewTeamID = FGenericTeamId::NoTeam;
|
| if (ILyraTeamAgentInterface* ControllerAsTeamProvider = Cast<ILyraTeamAgentInterface>(NewController))
|
| {
|
| NewTeamID = ControllerAsTeamProvider->GetGenericTeamId();
|
| ControllerAsTeamProvider->GetTeamChangedDelegateChecked().AddDynamic(this, &ThisClass::OnControllerChangedTeam);
|
| LastBoundPC = NewController;
|
| }
|
|
|
| ConditionalBroadcastTeamChanged(this, OldTeamID, NewTeamID);
|
| }
|
|
|
| void ULyraLocalPlayer::SetGenericTeamId(const FGenericTeamId& NewTeamID)
|
| {
|
|
|
| }
|
|
|
| FGenericTeamId ULyraLocalPlayer::GetGenericTeamId() const
|
| {
|
| if (ILyraTeamAgentInterface* ControllerAsTeamProvider = Cast<ILyraTeamAgentInterface>(PlayerController))
|
| {
|
| return ControllerAsTeamProvider->GetGenericTeamId();
|
| }
|
| else
|
| {
|
| return FGenericTeamId::NoTeam;
|
| }
|
| }
|
|
|
| FOnLyraTeamIndexChangedDelegate* ULyraLocalPlayer::GetOnTeamIndexChangedDelegate()
|
| {
|
| return &OnTeamChangedDelegate;
|
| }
|
|
|
| ULyraSettingsLocal* ULyraLocalPlayer::GetLocalSettings() const
|
| {
|
| return ULyraSettingsLocal::Get();
|
| }
|
|
|
| ULyraSettingsShared* ULyraLocalPlayer::GetSharedSettings() const
|
| {
|
| if (!SharedSettings)
|
| {
|
|
|
|
|
| bool bCanLoadBeforeLogin = PLATFORM_DESKTOP;
|
|
|
| if (bCanLoadBeforeLogin)
|
| {
|
| SharedSettings = ULyraSettingsShared::LoadOrCreateSettings(this);
|
| }
|
| else
|
| {
|
|
|
| SharedSettings = ULyraSettingsShared::CreateTemporarySettings(this);
|
| }
|
| }
|
|
|
| return SharedSettings;
|
| }
|
|
|
| void ULyraLocalPlayer::LoadSharedSettingsFromDisk(bool bForceLoad)
|
| {
|
| FUniqueNetIdRepl CurrentNetId = GetCachedUniqueNetId();
|
| if (!bForceLoad && SharedSettings && CurrentNetId == NetIdForSharedSettings)
|
| {
|
|
|
| return;
|
| }
|
|
|
| ensure(ULyraSettingsShared::AsyncLoadOrCreateSettings(this, ULyraSettingsShared::FOnSettingsLoadedEvent::CreateUObject(this, &ULyraLocalPlayer::OnSharedSettingsLoaded)));
|
| }
|
|
|
| void ULyraLocalPlayer::OnSharedSettingsLoaded(ULyraSettingsShared* LoadedOrCreatedSettings)
|
| {
|
|
|
| if (ensure(LoadedOrCreatedSettings))
|
| {
|
|
|
| SharedSettings = LoadedOrCreatedSettings;
|
|
|
| NetIdForSharedSettings = GetCachedUniqueNetId();
|
| }
|
| }
|
|
|
| void ULyraLocalPlayer::OnAudioOutputDeviceChanged(const FString& InAudioOutputDeviceId)
|
| {
|
| FOnCompletedDeviceSwap DevicesSwappedCallback;
|
| DevicesSwappedCallback.BindUFunction(this, FName("OnCompletedAudioDeviceSwap"));
|
| UAudioMixerBlueprintLibrary::SwapAudioOutputDevice(GetWorld(), InAudioOutputDeviceId, DevicesSwappedCallback);
|
| }
|
|
|
| void ULyraLocalPlayer::OnCompletedAudioDeviceSwap(const FSwapAudioOutputResult& SwapResult)
|
| {
|
| if (SwapResult.Result == ESwapAudioOutputDeviceResultState::Failure)
|
| {
|
| }
|
| }
|
|
|
| void ULyraLocalPlayer::OnControllerChangedTeam(UObject* TeamAgent, int32 OldTeam, int32 NewTeam)
|
| {
|
| ConditionalBroadcastTeamChanged(this, IntegerToGenericTeamId(OldTeam), IntegerToGenericTeamId(NewTeam));
|
| }
|
|
|
|
|