ブロックしたプレイヤーメニューとプレイヤーアクションメニューを追加する - フレンドを管理する - (Unreal Engine モジュール)
注釈:本資料はAI技術を用いて翻訳されています。
メニューの内容
このセクションでは、ブロックしたプレイヤーを表示するために使用するウィジェットと、フレンド解除、ブロック、ブロック解除を行うアクションボタンを準備する方法を学びます。ウィジェットはリソースセクションで入手でき、以下のクラスで定義されています:
BlockedPlayersWidget_Starter: ブロックしたプレイヤーを表示する関数を呼び出すために使用するC++クラスです。- ヘッダーファイル:
/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/UI/BlockedPlayersWidget_Starter.h - CPPファイル:
/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/UI/BlockedPlayersWidget_Starter.cpp - Blueprintウィジェット:
/Content/TutorialModules/Social/ManagingFriends/UI/W_BlockedPlayers_Starter.uasset
- ヘッダーファイル:
BlockedPlayerWidgetEntry_Starter: ブロックしたプレイヤーの表示名やアバターなどの情報を表示するために使用するC++クラスです。- ヘッダーファイル:
/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/UI/BlockedPlayerWidgetEntry_Starter.h - CPPファイル:
/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/UI/BlockedPlayerWidgetEntry_Starter.cpp - Blueprintウィジェット:
/Content/TutorialModules/Social/ManagingFriends/UI/W_BlockedPlayerEntry_Starter.uasset
- ヘッダーファイル:
これらのウィジェットがどのように構築されているかの詳細を見ていきましょう。
Blocked Playersウィジェット
Blocked Playersウィジェットには、リクエストステータスの各状態を表すいくつかの状態があります:空、読み込み中、エラー、空でない(ブロックしたプレイヤーリストを表示)。これらの状態は、カスタムWidget Switcher: UAccelByteWarsWidgetSwitcherを使用して実現されています。リスト自体は、エントリーウィジェットクラスを受け取り、エントリーを動的に生成するList Viewを使用して作成されています。以下はW_BlockedPlayers_Starter Blueprintウィジェットのプレビューです:

ブロックしたプレイヤーを表示するリストは、BlockedPlayersWidget_Starterクラスのヘッダーファイルで定義されています。
protected:
// ...
UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional, BlueprintProtected = true, AllowPrivateAccess = true))
UAccelByteWarsWidgetSwitcher* Ws_BlockedPlayers;
UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional, BlueprintProtected = true, AllowPrivateAccess = true))
UListView* Lv_BlockedPlayers;
このウィジェットの状態を変更するには、Ws_BlockedPlayers->SetWidgetState()を呼び出します。
Blocked Player Entryウィジェット
以下はW_BlockedPlayerEntry_Starter Blueprintウィジェットのプレビューです。このウィジェットは、表示名、アバター、ブロック解除ボタンなど、ブロックしたプレイヤーの情報を表示します。

ブロックしたプレイヤーの情報を表示する関数は、BlockedPlayerWidgetEntry_StarterクラスのCPPファイル、特に以下の関数で既に準備されています。
void UBlockedPlayerWidgetEntry_Starter::NativeOnListItemObjectSet(UObject* ListItemObject)
{
Super::NativeOnListItemObjectSet(ListItemObject);
CachedBlockedPlayerData = Cast<UFriendData>(ListItemObject);
// Display display name.
if (!CachedBlockedPlayerData->DisplayName.IsEmpty())
{
Tb_DisplayName->SetText(FText::FromString(CachedBlockedPlayerData->DisplayName));
}
else
{
Tb_DisplayName->SetText(FText::FromString(
UTutorialModuleOnlineUtility::GetUserDefaultDisplayName(CachedBlockedPlayerData->UserId.ToSharedRef().Get())));
}
// Display avatar image.
const FString AvatarURL = CachedBlockedPlayerData->AvatarURL;
Img_Avatar->LoadImage(AvatarURL);
OnListItemObjectSet.Broadcast();
}
以下は、このウィジェットで使用されるコンポーネントの宣言です。宣言はBlockedPlayerWidgetEntry_Starterクラスのヘッダーファイルにあります。
protected:
// ...
UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional, BlueprintProtected = true, AllowPrivateAccess = true))
UAccelByteWarsAsyncImageWidget* Img_Avatar;
UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional, BlueprintProtected = true, AllowPrivateAccess = true))
UTextBlock* Tb_DisplayName;
UPROPERTY(BlueprintReadOnly, meta = (BindWidgetOptional, BlueprintProtected = true, AllowPrivateAccess = true))
UCommonButtonBase* Btn_Unblock;
Player Actionメニュー
Friend listモジュールでは、Friend Detailsウィジェットについて説明しました。このウィジェットは、フレンドの詳細を表示するだけでなく、ブロックボタンとフレンド解除ボタンを表示するプレイヤーアクションメニューとしても機能します。これらのボタンは実行時に動的に生成されます。

これらのボタンがクリックされると、以下の対応する関数がトリガーされます。これらの関数は/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/ManagingFriendsSubsystem_Starter.cppファイルにあります。このファイルの詳細については後ほど説明します。
protected:
// ...
void OnUnfriendButtonClicked(const APlayerController* PC, const FUniqueNetIdRepl FriendUserId, const FOnUnfriendComplete& OnComplete = FOnUnfriendComplete());
protected:
// ...
void OnBlockButtonClicked(const APlayerController* PC, const FUniqueNetIdRepl BlockedPlayerUserId, const FOnBlockPlayerComplete& OnComplete = FOnBlockPlayerComplete());
UIの準備
このセクションでは、チュートリアルに沿って進められるようにウィジェットを準備する方法を学びます。
-
BlockedPlayerWidgetEntry_StarterクラスのCPPファイルを開くと、以下の関数があります。この関数は、ブロック解除ボタンがクリックされたときにトリガーされます。後ほど、この関数内でプレイヤーのブロックを解除する関数を呼び出します。void UBlockedPlayerWidgetEntry_Starter::OnUnblockButtonClicked()
{
// ...
} -
BlockedPlayersWidget_StarterクラスのCPPファイルを開きます。そこに以下の関数があります。後ほど、この関数内でブロックしたプレイヤーリストを取得して表示する関数を呼び出します。void UBlockedPlayersWidget_Starter::GetBlockedPlayerList()
{
// ...
} -
プロジェクトをビルドし、Unreal Engine Editorで開きます。Unreal Engine Editorで、
/Content/TutorialModules/Social/ManagingFriends/に移動します。そこにDA_ManagingFriendsというデータアセットがあります。それを開き、Is Starter Mode Activeを有効にします。次に、データアセットを保存します。これにより、ゲームをプレイするときにウィジェットを操作できるようになります。
-
Editorでゲームをプレイし、ログインして、以下の場所への移動をテストします:
- Social > Blocked Playersメニューに移動できること。
- Social > Friendsメニューに移動できること。フレンドエントリーをクリックすると、フレンド詳細メニューにBlock PlayerボタンとUnfriendボタンが表示されます。
リソース
- このチュートリアルセクションで使用されるファイルは、Unreal Byte Wars GitHubリポジトリで入手できます。
- AccelByteWars/Content/TutorialModules/Social/ManagingFriends/DA_ManagingFriends.uasset
- AccelByteWars/Content/TutorialModules/Social/ManagingFriends/UI/W_BlockedPlayers_Starter.uasset
- AccelByteWars/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/UI/BlockedPlayersWidget_Starter.h
- AccelByteWars/Source/AccelByteWars/TutorialModules/Social/ManagingFriends/UI/BlockedPlayersWidget_Starter.cpp
- AccelByteWars/Content/TutorialModules/Social/ManagingFriends/UI/W_BlockedPlayerEntry_Starter.uasset
- 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