LY2.Lyra-UIMessaging
大约 2 分钟
项目说明:
ExorcistUIMessaging
是一个用于在游戏中展示全局消息框(MessageBox)的子系统,支持错误、确认等提示信息。 它基于 MVC 设计模式实现,通过异步蓝图节点来展示消息,能够简化用户与系统之间的交互。
功能:
主要模块:
- UAsyncAction_ShowConfirmation:
UFUNCTION(BlueprintCallable, BlueprintCosmetic, meta = (BlueprintInternalUseOnly = "true", WorldContext = "InWorldContextObject"))
static UAsyncAction_ShowConfirmation* ShowConfirmationYesNo(
UObject* InWorldContextObject, FText Title, FText Message
);
- UCommonGameDialogDescriptor(Model层 - 实体类):
static UCommonGameDialogDescriptor* CreateConfirmationOk(const FText& Header, const FText& Body);
UCommonGameDialogDescriptor* UCommonGameDialogDescriptor::CreateConfirmationOk(const FText& Header, const FText& Body)
{
UCommonGameDialogDescriptor* Descriptor = NewObject<UCommonGameDialogDescriptor>();
Descriptor->Header = Header;
Descriptor->Body = Body;
FConfirmationDialogAction ConfirmAction;
ConfirmAction.Result = ECommonMessagingResult::Confirmed;
ConfirmAction.OptionalDisplayText = LOCTEXT("Ok", "Ok");
Descriptor->ButtonActions.Add(ConfirmAction);
return Descriptor;
}
CreateConfirmationOk
函数用于构建一个消息描述符,包含标题、内容以及“确认”按钮。
- UExorcistConfirmationScreen(View层):
继承自UCommonGameDialog
和UCommonActivatableWidget
,负责显示对话框内容。
virtual void SetupDialog(UCommonGameDialogDescriptor* Descriptor,
FCommonMessagingResultDelegate ResultCallback);
SetupDialog
方法用于将对话框的数据进行设置,并绑定用户交互的回调函数。
- UExorcistUIMessaging 子系统(Controller层):
virtual void ShowConfirmation(UCommonGameDialogDescriptor* DialogDescriptor,
FCommonMessagingResultDelegate ResultCallback = FCommonMessagingResultDelegate()) override;
void UExorcistUIMessaging::ShowConfirmation(UCommonGameDialogDescriptor* DialogDescriptor, FCommonMessagingResultDelegate ResultCallback)
{
if (UCommonLocalPlayer* LocalPlayer = GetLocalPlayer<UCommonLocalPlayer>())
{
if (UPrimaryGameLayout* RootLayout = LocalPlayer->GetRootUILayout())
{
RootLayout->PushWidgetToLayerStack<UCommonGameDialog>(TAG_UI_LAYER_MODAL, ConfirmationDialogClassPtr, [DialogDescriptor, ResultCallback](UCommonGameDialog& Dialog) {
Dialog.SetupDialog(DialogDescriptor, ResultCallback);
});
GEngine->AddOnScreenDebugMessage(0, 10.0f, FColor::Red, TEXT("ShowConfirmation"));
}
}
}
ShowConfirmation
函数负责将 DialogDescriptor
实例推送到 UI 栈中,展示对话框。