UE4 Editor Plugin UI

UE4 Editor Plugin UI

key value
Module DesktopPlatform
Header /Engine/Source/Developer/DesktopPlatform/Public/IDesktopPlatform.h
Include #include "IDesktopPlatform.h"

Choose Local Folder to save

选择本地硬盘目录:

#include "IDesktopPlatform.h

IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
//默认路径
FString DefaultLocation(FEditorDirectories::Get().GetLastDirectory(ELastDirectory::GENERIC_IMPORT));
FString Path = DefaultLocation;
bool bOpened = false;
if (DesktopPlatform)
{
	bOpened = DesktopPlatform->OpenDirectoryDialog(
		FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
		TEXT("Choose folder to save"),
		DefaultLocation,
		Path
	);
	if (bOpened)
		Path += "/";
}

Choose Content Folder

选择 UE4 project content 目录:

UE4 Editor Plugin UI

static FString Path = "/Game/";
TSharedRef<SDlgPickPath> PickContentPathDlg =
					SNew(SDlgPickPath)
					.Title(LOCTEXT("ChooseImportRootContentPath", "Choose Location for importing the H3D content"))
					.DefaultPath(FText::FromString(Path));

if (PickContentPathDlg->ShowModal() == EAppReturnType::Cancel)
{
	return;
}

Path = PickContentPathDlg->GetPath().ToString() + "/";

Open & Save File Dialog

打开本地文件和保存为本地文件对话框。

#include "IDesktopPlatform.h"
namespace FileDialogHelpers
{
	/**
	 * @param Title                  The title of the dialog
	 * @param FileTypes              Filter for which file types are accepted and should be shown
	 * @param InOutLastPath          Keep track of the last location from which the user attempted an import
	 * @param DefaultFile            Default file name to use for saving.
	 * @param OutOpenFilenames       The list of filenames that the user attempted to open
	 *
	 * @return true if the dialog opened successfully and the user accepted; false otherwise.
	 */
	bool SaveFile(const FString& Title, const FString& FileTypes, FString& InOutLastPath, const FString& DefaultFile, FString& OutFilename)
	{
		OutFilename = FString();

		IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
		bool bFileChosen = false;
		TArray<FString> OutFilenames;
		if (DesktopPlatform)
		{
			bFileChosen = DesktopPlatform->SaveFileDialog(
				FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
				Title,
				InOutLastPath,
				DefaultFile,
				FileTypes,
				EFileDialogFlags::None,
				OutFilenames
			);
		}

		bFileChosen = (OutFilenames.Num() > 0);

		if (bFileChosen)
		{
			// User successfully chose a file; remember the path for the next time the dialog opens.
			InOutLastPath = OutFilenames[0];
			OutFilename = OutFilenames[0];
		}

		return bFileChosen;
	}

	/**
	 * @param Title                  The title of the dialog
	 * @param FileTypes              Filter for which file types are accepted and should be shown
	 * @param InOutLastPath			 Keep track of the last location from which the user attempted an import
	 * @param DialogMode             Multiple items vs single item.
	 * @param OutOpenFilenames       The list of filenames that the user attempted to open
	 *
	 * @return true if the dialog opened successfully and the user accepted; false otherwise.
	 */
	bool OpenFiles(const FString& Title, const FString& FileTypes, FString& InOutLastPath, EFileDialogFlags::Type DialogMode, TArray<FString>& OutOpenFilenames)
	{
		IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
		bool bOpened = false;
		if (DesktopPlatform)
		{
			bOpened = DesktopPlatform->OpenFileDialog(
				FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
				Title,
				InOutLastPath,
				TEXT(""),
				FileTypes,
				DialogMode,
				OutOpenFilenames
			);
		}

		bOpened = (OutOpenFilenames.Num() > 0);

		if (bOpened)
		{
			// User successfully chose a file; remember the path for the next time the dialog opens.
			InOutLastPath = OutOpenFilenames[0];
		}

		return bOpened;
	}
}

Message Dialog

UE4 Editor Plugin UI

#include "Misc/MessageDialog.h"

#define LOCTEXT_NAMESPACE "FH3DEditorModule"

FText DialogText = LOCTEXT("PluginDialogText", "Next please choose folder to save......");
FText DialogTitle = LOCTEXT("PluginDialogTitle", "Choose save folder");

FMessageDialog::Open(EAppMsgType::Ok, DialogText,&DialogTitle);

参考

  1. UE4 Editor Plugin UI
上一篇:IDEA自动生成作者信息


下一篇:【Android Studio】数据持久化(二)SharedPreferences