ULocalPlayer* UGameInstance::FindLocalPlayerFromUniqueNetId(TSharedPtr<FUniqueNetId> UniqueNetId) const { if (!UniqueNetId.IsValid()) { return nullptr; } return FindLocalPlayerFromUniqueNetId(*UniqueNetId); }
void UAmethystGameInstance::HandleControllerPairingChanged(int GameUserIndex, const FUniqueNetId& PreviousUser, const FUniqueNetId& NewUser) { if (CurrentState == AmethystGameInstanceState::WelcomeScreen) { // Don't care about pairing changes at welcome screen return; } #if Amethyst_CONSOLE_UI && PLATFORM_XBOXONE if (IgnorePairingChangeForControllerId != -1 && GameUserIndex == IgnorePairingChangeForControllerId) { // We were told to ignores IgnorePairingChangeForControllerId = -1; // Reset now so there there is no chance this remains in a bad state return; } if (PreviousUser.IsValid() && !NewUser.IsValid()) { // Treat this as a disconnect or signout, which is handled somewhere else return; } if (!PreviousUser.IsValid() && NewUser.IsValid()) { // Treat this as a signin ULocalPlayer * ControlledLocalPlayer = FindLocalPlayerFromControllerId(GameUserIndex); if (ControlledLocalPlayer != NULL && !ControlledLocalPlayer->GetCachedUniqueNetId().IsValid()) { // If a player that previously selected "continue without saving" signs into this controller, move them back to welcome screen HandleSignInChangeMessaging(); } return; } // Find the local player currently being controlled by this controller ULocalPlayer * ControlledLocalPlayer = FindLocalPlayerFromControllerId(GameUserIndex); // See if the newly assigned profile is in our local player list ULocalPlayer * NewLocalPlayer = FindLocalPlayerFromUniqueNetId(NewUser); // If the local player being controlled is not the target of the pairing change, then give them a chance // to continue controlling the old player with this controller if (ControlledLocalPlayer != nullptr && ControlledLocalPlayer != NewLocalPlayer) { UAmethystGameViewportClient * AmethystViewport = Cast<UAmethystGameViewportClient>(GetGameViewportClient()); if (AmethystViewport != nullptr) { AmethystViewport->ShowDialog( nullptr, EAmethystDialogType::Generic, NSLOCTEXT("ProfileMessages", "PairingChanged", "Your controller has been paired to another profile, would you like to switch to this new profile now? Selecting YES will sign out of the previous profile."), NSLOCTEXT("DialogButtons", "YES", "A - YES"), NSLOCTEXT("DialogButtons", "NO", "B - NO"), FOnClicked::CreateUObject(this, &UAmethystGameInstance::OnPairingUseNewProfile), FOnClicked::CreateUObject(this, &UAmethystGameInstance::OnPairingUsePreviousProfile) ); } } #endif }