すべてを統合する - フレンドを管理する - (Unreal Engine モジュール)
Connect the UI to get blocked players
Open the
BlockedPlayersWidget_Starter
class CPP file, navigate to theGetBlockedPlayerList()
function, and replace the current implementation with the code below. It will get the blocked player list using theManagingFriendsSubsystem_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->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);
}
}
));
}Add the following code to the
NativeOnActivated()
. It will bind theGetBlockedPlayerList
function to theOnCachedBlockedPlayersDataUpdated
, updating the displayed list as soon as the actual list changes.void UBlockedPlayersWidget_Starter::NativeOnActivated()
{
Super::NativeOnActivated();
Btn_Back->OnClicked().AddUObject(this, &ThisClass::DeactivateWidget);
// Reset widgets.
Ws_BlockedPlayers->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Empty);
Lv_BlockedPlayers->ClearListItems();
ManagingFriendsSubsystem->BindOnCachedBlockedPlayersDataUpdated(GetOwningPlayer(), FOnGetCacheBlockedPlayersDataUpdated::CreateUObject(this, &ThisClass::GetBlockedPlayerList));
GetBlockedPlayerList();
}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()
{
Btn_Back->OnClicked().Clear();
ManagingFriendsSubsystem->UnbindOnCachedBlockedPlayersDataUpdated(GetOwningPlayer());
Super::NativeOnDeactivated();
}
Connect the UI to unfriend, block, and unblock players
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);
}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);
}Open the
BlockedPlayerWidgetEntry_Starter
class CPP file. Replace the existing implementation forOnUnblockButtonClicked
with the following to unblock a player:void UBlockedPlayerWidgetEntry_Starter::OnUnblockButtonClicked()
{
ensure(CachedBlockedPlayerData);
ensure(ManagingFriendsSubsystem);
ManagingFriendsSubsystem->UnblockPlayer(GetOwningPlayer(), CachedBlockedPlayerData->UserId);
}
Resources
- The files used in this tutorial section are available in the Unreal Byte Wars GitHub repository.
- AccelByteWars/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/UI/BlockedPlayersWidget_Starter.h
- AccelByteWars/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/UI/BlockedPlayersWidget_Starter.cpp
- AccelByteWars/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/UI/BlockedPlayerWidgetEntry_Starter.h
- AccelByteWars/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/UI/BlockedPlayerWidgetEntry_Starter.cpp
- AccelByteWars/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/ManagingFriendsSubsystem_Starter.cpp