メインコンテンツまでスキップ

すべてを統合する - フレンドを管理する - (Unreal Engine モジュール)

Last updated on May 30, 2024

Connect the UI to get blocked players

  1. Open the BlockedPlayersWidget_Starter class CPP file, navigate to the GetBlockedPlayerList() function, and replace the current implementation with the code below. It will get the blocked player list using the ManagingFriendsSubsystem_Starter subsystem and then display it upon completion.

    void UBlockedPlayersWidget_Starter::GetBlockedPlayerList()
    {
    ensure(ManagingFriendsSubsystem);

    Ws_BlockedPlayers->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Loading);

    ManagingFriendsSubsystem->GetBlockedPlayerList(
    GetOwningPlayer(),
    FOnGetBlockedPlayerListComplete::CreateWeakLambda(this, [this](bool bWasSuccessful, TArray<UFriendData*> BlockedPlayers, const FString& ErrorMessage)
    {
    Lv_BlockedPlayers->SetUserFocus(GetOwningPlayer());
    Lv_BlockedPlayers->ClearListItems();

    if (bWasSuccessful)
    {
    Lv_BlockedPlayers->SetListItems(BlockedPlayers);
    Ws_BlockedPlayers->SetWidgetState(BlockedPlayers.IsEmpty() ?
    EAccelByteWarsWidgetSwitcherState::Empty :
    EAccelByteWarsWidgetSwitcherState::Not_Empty);
    }
    else
    {
    Ws_BlockedPlayers->ErrorMessage = FText::FromString(ErrorMessage);
    Ws_BlockedPlayers->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Error);
    }
    }
    ));
    }
  2. Add the following code to the NativeOnActivated(). It will bind the GetBlockedPlayerList function to the OnCachedBlockedPlayersDataUpdated, updating the displayed list as soon as the actual list changes.

    void UBlockedPlayersWidget_Starter::NativeOnActivated()
    {
    ...

    ManagingFriendsSubsystem->BindOnCachedBlockedPlayersDataUpdated(GetOwningPlayer(), FOnGetCacheBlockedPlayersDataUpdated::CreateUObject(this, &ThisClass::GetBlockedPlayerList));
    GetBlockedPlayerList();
    }
  3. In NativeOnDeactivated(), add the following code. Basically, it will stop listening to the blocked player list changes upon the widget closing.

    void UBlockedPlayersWidget_Starter::NativeOnDeactivated()
    {
    ManagingFriendsSubsystem->UnbindOnCachedBlockedPlayersDataUpdated(GetOwningPlayer());

    Super::NativeOnDeactivated();
    }

Connect the UI to unfriend, block, and unblock players

  1. Start with unfriending a friend. Open the ManagingFriendsSubsystem_Starter class CPP file. In the following function, replace the existing implementation with the following:

    void UManagingFriendsSubsystem_Starter::OnUnfriendButtonClicked(const APlayerController* PC, const FUniqueNetIdRepl FriendUserId, const FOnUnfriendComplete& OnComplete)
    {
    Unfriend(PC, FriendUserId, OnComplete);
    }
  2. Still in the same file, replace the existing implementation for OnBlockButtonClicked with the following to block a player:

    void UManagingFriendsSubsystem_Starter::OnBlockButtonClicked(const APlayerController* PC, const FUniqueNetIdRepl BlockedPlayerUserId, const FOnBlockPlayerComplete& OnComplete)
    {
    BlockPlayer(PC, BlockedPlayerUserId, OnComplete);
    }
  3. Open the BlockedPlayerWidgetEntry_Starter class CPP file. Replace the existing implementation for OnUnblockButtonClicked with the following to unblock a player:

    void UBlockedPlayerWidgetEntry_Starter::OnUnblockButtonClicked()
    {
    ensure(CachedBlockedPlayerData);
    ensure(ManagingFriendsSubsystem);

    ManagingFriendsSubsystem->UnblockPlayer(GetOwningPlayer(), CachedBlockedPlayerData->UserId);
    }

Resources