当前位置: 首页 > article >正文

Unreal Engine 5 C++: 插件编写03 | MessageDialog

在虚幻引擎编辑器中编写Warning弹窗

准备工作

FMessageDialog These functions open a message dialog and display the specified informations there.

EAppReturnType::TypeUnreal Engine 中用于表示应用程序对话框(如消息对话框)返回结果的枚举类型。具体来说,当你使用 FMessageDialog::Open 或类似函数显示一个对话框时,用户的选择(例如点击“确定”、“取消”、“是”、“否”等按钮)会以 EAppReturnType::Type 的形式返回。这使得开发者能够根据用户的选择执行相应的逻辑。

EAppReturnType 是一个枚举类,其定义可能类似于以下内容:

namespace EAppReturnType
{
    enum Type
    {
        No,
        Yes,
        YesAll,
        NoAll,
        Cancel,
        Ok,
        Retry,
        Continue
    };
}

示例代码1

if (NumOfDuplicates<=0) {

	//Print(TEXT("Pls enter a valid number"), FColor::Red);
	FText MsgTitle = FText::FromString(TEXT("Warning"));

	FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(TEXT("Please enter a valid number")), &MsgTitle);
	return;
}

插件效果1

插件效果2

——————————编辑器右下角slate notification的效果————————————

A list of non-intrusive messages about the status of currently active work.

non-intrusive messages

非侵入性的消息,意味着这些消息不会干扰用户的操作或体验,通常是轻量级的提示或通知。

准备工作:需要的header file

https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Slate/Framework/Notifications/FSlateNotificationManager?application_version=4.27

A class which manages a group of notification windows

https://dev.epicgames.com/documentation/en-us/unreal-engine/API/Runtime/Slate/Widgets/Notifications/SNotificationList?application_version=4.27

A list of non-intrusive messages about the status of currently active work.

示例代码2

#pragma once
#include "Misc/MessageDialog.h"
#include "Widgets/Notifications/SNotificationList.h"
#include "Framework/Notifications/NotificationManager.h"

void Print(const FString& Message, const FColor& Color)
{
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 8.f, Color, Message);
	}
}

void PrintLog(const FString& Message)
{
	UE_LOG(LogTemp, Warning, TEXT("%s"),*Message);
}

EAppReturnType::Type ShowMsgDialog(EAppMsgType::Type MsgType, const FString& Message, 
bool bShowMsgAsWarning = true) 
{
	if (bShowMsgAsWarning == true) 
	{
		FText MsgTitle = FText::FromString(TEXT("Warning"));

		return FMessageDialog::Open(MsgType, FText::FromString(Message), &MsgTitle);
	//return FMessageDialog::Open(MsgType, FText::FromString(TEXT("Warning: ") + Message));
	}

	else
	{
		return FMessageDialog::Open(MsgType, FText::FromString(Message));
	}
}

void ShowNotifyInfo(const FString& Message)
{
	FNotificationInfo NotifyInfo(FText::FromString(Message));
	NotifyInfo.bUseLargeFont = true;
	NotifyInfo.FadeOutDuration = 7.f;

	FSlateNotificationManager::Get().AddNotification(NotifyInfo);
}
	if (Counter > 0)
	{
		ShowNotifyInfo(TEXT("Successfully duplicated" + FString::FromInt(Counter) + "files"));
		//Print(TEXT("Successfully duplicated" + FString::FromInt(Counter) + "files"), FColor::Green);
	}


http://www.kler.cn/news/317016.html

相关文章:

  • 线上搭子小程序:随时随地找搭子!
  • 详解Linux中cat命令
  • 软件开发详解:通过源码搭建高效的食堂采购与供应链管理平台
  • VOC2007数据集
  • Linux高级I/O:多路转接模型
  • 计算机毕业设计 校园志愿者管理系统的设计与实现 Java实战项目 附源码+文档+视频讲解
  • Linux进程间通信——Socket套接字
  • 计算机毕业设计 | SSM 凌云招聘平台 求职问答审批系统(附源码)
  • 【智能制造-32】通信冗余
  • win10 win11 设置文件权限以解决Onedrive不能同步问题
  • [Linux]:信号(下)
  • 计算机毕业设计 玩具租赁系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试
  • Can‘t get Kerberos realm
  • 智能体趋势:未来科技的核心驱动力
  • 4款AI生成PPT工具推荐,提升工作效率
  • 6个Python小游戏项目源码【免费】
  • 前端常见面试-首页性能提升、项目优化
  • leetcode第二十六题:删去有序数组的重复项
  • JavaScript 中的日期与时间处理
  • 設置Android設備全局代理
  • Fastapi做成docker启动失败,需要启动线程。
  • vue3 快速入门系列 —— 基础
  • OpenHarmony(鸿蒙南向开发)——小型系统内核(LiteOS-A)【内核通信机制】上
  • 第一个Java程序(二)
  • c++类中的特殊函数
  • 一篇关于网络的文章
  • electron nsis打包windows应用程序
  • Java企业面试题5
  • 【网站架构部署与优化】源码编译安装LAMP
  • 博客摘录「 SpringBoot大文件(百M以上)的上传下载实现技术」2024年8月2日