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

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.lryc.cn/news/449953.html

相关文章:

  • 【前端面试题】Vue 3 生命周期钩子的执行顺序详解
  • Apache DolphinScheduler-1.3.9源码分析(一)
  • 高级java每日一道面试题-2024年9月29日-数据库篇-索引怎么定义,分哪几种?
  • 现代LLM基本技术整理
  • EasyX与少儿编程:轻松上手的编程启蒙工具
  • 【C语言指南】数据类型详解(上)——内置类型
  • 视频汇聚/视频存储/安防视频监控EasyCVR平台RTMP推流显示离线是什么原因?
  • 联想电脑怎么开启vt_联想电脑开启vt虚拟化教程(附intel和amd主板开启方法)
  • 手把手教你使用YOLOv11训练自己数据集(含环境搭建 、数据集查找、模型训练)
  • LabVIEW界面输入值设为默认值
  • 【Android 14源码分析】Activity启动流程-1
  • Java 中 synchronized 和 Thread 的使用场合介绍
  • 爬虫库是什么?是ip吗
  • 【MySQL】查询原理 —— B+树查询数据全过程
  • 系统设置 WIFI输入框被挡住解决方案
  • SpringCloud无法注册Nacos和配置中心
  • word2vector训练数据集整理(代码实现)
  • 无心上班,只想为祖国庆生?让ChatGPT帮你搞定工作!
  • 【Python】YOLO牛刀小试:快速实现视频物体检测
  • Vscode超好看的渐变主题插件
  • OceanBase技术解析:自适应分布式下压技术
  • Firebase和JavaScript创建Postback Link逻辑
  • docker配置daemon.json文件
  • 【08】纯血鸿蒙HarmonyOS NEXT星河版开发0基础学习笔记-Scroll容器与Tabs组件
  • 苏州 数字化科技展厅展馆-「世岩科技」一站式服务商
  • 音频搜索公司 DeepGram,定位语音搜索AI大脑,DeepGram想做“音频版”
  • 基于php的在线租房管理系统
  • 如何评价 Python 语言的运行速度
  • Tomcat系列漏洞复现
  • K8S拉取本地docker中registry的镜像报错:http: server gave HTTP response to HTTPS client