• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

UE4 Editor Plugin UI - SCompoundWidget

武飞扬头像
wblong_cs
帮助1

UE4 Editor Plugin UI - SCompoundWidget

创建自定义Window

学新通

创建自定义类

学新通

示例Code

涉及的布局相关的类:SBoxSVerticalBoxSHorizontalBoxSUniformGridPanel
输入及 显示控件类:SButtonSTextBlockSNumericEntryBox

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Widgets/SCompoundWidget.h"
#include "Framework/Application/SlateApplication.h"
/**
 * 
 */
class SH3DOptionsWindow : public SCompoundWidget
{
public:
	SLATE_BEGIN_ARGS(SH3DOptionsWindow)
	{}
	SLATE_ARGUMENT(TSharedPtr<SWindow>, WidgetWindow)
	SLATE_END_ARGS()

	/** Constructs this widget with InArgs */
	void Construct(const FArguments& InArgs);

public:
	bool ShouldOK() const
	{
		return bShouldProceed;
	}
	FTransform GetTransform()const {
		return FTransform(Rotation.Quaternion(),Translation,Scale3D);
	}
private:

	TOptional<float> GetTranslationX() const{ return Translation.X;}
	TOptional<float> GetTranslationY() const { return Translation.Y;}
	TOptional<float> GetTranslationZ() const { return Translation.Z;}
	void SetTranslationX(float X) { Translation.X = X; }
	void SetTranslationY(float Y) { Translation.Y = Y; }
	void SetTranslationZ(float Z) { Translation.Z = Z; }


	TOptional<float> GetScale3DX()const { return Scale3D.X; }
	TOptional<float> GetScale3DY()const { return Scale3D.Y; }
	TOptional<float> GetScale3DZ()const { return Scale3D.Z; }
	void SetScale3DX(float X) { Scale3D.X = X; }
	void SetScale3DY(float Y) { Scale3D.Y = Y; }
	void SetScale3DZ(float Z) { Scale3D.Z = Z; }

	TOptional<float> GetRotationX()const { return Rotation.Roll; }
	TOptional<float> GetRotationY()const { return Rotation.Pitch; }
	TOptional<float> GetRotationZ()const { return Rotation.Yaw; }

	void SetRotationX(float X) { Rotation.Roll = X; }
	void SetRotationY(float Y) { Rotation.Pitch = Y; }
	void SetRotationZ(float Z) { Rotation.Yaw = Z; }

	
	FReply OnOK()
	{
		bShouldProceed = true;
		if (Window.IsValid())
		{
			Window.Pin()->RequestDestroyWindow();
		}
		return FReply::Handled();
	}

	FReply OnCancel()
	{
		bShouldProceed = false;
		if (Window.IsValid())
		{
			Window.Pin()->RequestDestroyWindow();
		}
		return FReply::Handled();
	}
private:
	TWeakPtr< SWindow > Window;
	//others 
	bool bShouldProceed;

	FVector Translation;
	FVector Scale3D;
	FRotator Rotation;
};

学新通
// Fill out your copyright notice in the Description page of Project Settings.


#include "UI/SH3DOptionsWindow.h"
#include "Widgets/Input/SButton.h"
#include "Widgets/Layout/SBox.h"
#include "Widgets/Layout/SUniformGridPanel.h"
#include "Widgets/Text/STextBlock.h"
#include "Widgets/Input/SNumericEntryBox.h"
#include "SlateOptMacros.h"

#define LOCTEXT_NAMESPACE "H3DOptionsWindow"


void SH3DOptionsWindow::Construct(const FArguments& InArgs)
{
	Window = InArgs._WidgetWindow;
	bShouldProceed = false;
	Translation = FVector::ZeroVector;
	Rotation = FRotator::ZeroRotator;
	Scale3D = FVector::OneVector;
	
	ChildSlot
		[
			SNew(SVerticalBox)
			//第一行:
		  SVerticalBox::Slot()
		.AutoHeight()
		.Padding(0.0f, 3.0f, 0.0f, 3.0f)
		[
			SNew(SHorizontalBox)
			  SHorizontalBox::Slot()
		.AutoWidth()
		.Padding(3.0f, 3.0f, 10.0f, 3.0f)
		.VAlign(VAlign_Center)
		[
			SNew(STextBlock)
			.MinDesiredWidth(75)
		.Text(LOCTEXT("H3DOptionsWindow_Location", "Location:"))
		.ToolTipText(LOCTEXT("H3DOptionsWindow_LocationTooltip", "Location"))
		]

	  SHorizontalBox::Slot()
		.AutoWidth()
		.Padding(0.0f, 3.0f, 8.0f, 3.0f)
		[
			SNew(SNumericEntryBox<float>)
			.IsEnabled(true)
			.Value(this,&SH3DOptionsWindow::GetTranslationX)
			.OnValueChanged(this,&SH3DOptionsWindow::SetTranslationX)
		.AllowSpin(true)
		.MinDesiredValueWidth(75)
		.Label()
		[
			SNew(SBox)
			.VAlign(VAlign_Center)
		[
			SNew(STextBlock)
			.Text(LOCTEXT("H3DOptionsWindow_Location_X", "X:"))
		]
		]
		]

	  SHorizontalBox::Slot()
		.Padding(0.0f, 3.0f, 8.0f, 3.0f)
		.AutoWidth()
		[
			SNew(SNumericEntryBox<float>)
			.IsEnabled(true)
			.Value(this, &SH3DOptionsWindow::GetTranslationY)
			.OnValueChanged(this, &SH3DOptionsWindow::SetTranslationY)
		.AllowSpin(true)
		.MinDesiredValueWidth(75)
		.Label()
		[
			SNew(SBox)
			.VAlign(VAlign_Center)
		[
			SNew(STextBlock)
			.Text(LOCTEXT("H3DOptionsWindow_Location_Y", "Y:"))
		]
		]
		]

	  SHorizontalBox::Slot()
		.Padding(0.0f, 3.0f, 8.0f, 3.0f)
		.AutoWidth()
		[
			SNew(SNumericEntryBox<float>)
			.IsEnabled(true)
			.Value(this, &SH3DOptionsWindow::GetTranslationZ)
			.OnValueChanged(this, &SH3DOptionsWindow::SetTranslationZ)
		.AllowSpin(true)
		.MinDesiredValueWidth(75)
		.Label()
		[
			SNew(SBox)
			.VAlign(VAlign_Center)
		[
			SNew(STextBlock)
			.Text(LOCTEXT("H3DOptionsWindow_Location_Z", "Z:"))
		]
		]
		]
		]
			
			// 第二行
			  SVerticalBox::Slot()
				.AutoHeight()
				.Padding(0.0f, 3.0f, 0.0f, 3.0f)
				[
					SNew(SHorizontalBox)
					  SHorizontalBox::Slot()
				.AutoWidth()
				.Padding(3.0f, 3.0f, 10.0f, 3.0f)
				.VAlign(VAlign_Center)
				[
					SNew(STextBlock)
					.MinDesiredWidth(75)
				.Text(LOCTEXT("H3DOptionsWindow_Rotation", "Rotation:"))
				.ToolTipText(LOCTEXT("H3DOptionsWindow_RotationTooltip", "Rotation"))
				]
			  SHorizontalBox::Slot()
				.AutoWidth()
				.Padding(0.0f, 3.0f, 8.0f, 3.0f)
				[
					SNew(SNumericEntryBox<float>)
					.IsEnabled(true)
					.Value(this, &SH3DOptionsWindow::GetRotationX)
					.OnValueChanged(this, &SH3DOptionsWindow::SetRotationX)
				.AllowSpin(true)
				.MinDesiredValueWidth(75)
				.Label()
				[
					SNew(SBox)
					.VAlign(VAlign_Center)
				[
					SNew(STextBlock)
					.Text(LOCTEXT("H3DOptionsWindow_Rotation_X", "X:"))
				]
				]
				]
			  SHorizontalBox::Slot()
				.Padding(0.0f, 3.0f, 8.0f, 3.0f)
				.AutoWidth()
				[
					SNew(SNumericEntryBox<float>)
						.IsEnabled(true)
						.Value(this, &SH3DOptionsWindow::GetRotationY)
						.OnValueChanged(this, &SH3DOptionsWindow::SetRotationY)
				.AllowSpin(true)
				.MinDesiredValueWidth(75)
				.Label()
				[
					SNew(SBox)
					.VAlign(VAlign_Center)
				[
					SNew(STextBlock)
					.Text(LOCTEXT("H3DOptionsWindow_Rotation_Y", "Y:"))
				]
				]
				]
			  SHorizontalBox::Slot()
				.Padding(0.0f, 3.0f, 8.0f, 3.0f)
				.AutoWidth()
				[
					SNew(SNumericEntryBox<float>)
					.IsEnabled(true)
					.Value(this, &SH3DOptionsWindow::GetRotationZ)
					.OnValueChanged(this, &SH3DOptionsWindow::SetRotationZ)
				.AllowSpin(true)
				.MinDesiredValueWidth(75)
				.Label()
				[
					SNew(SBox)
					.VAlign(VAlign_Center)
				[
					SNew(STextBlock)
					.Text(LOCTEXT("H3DOptionsWindow_Rotation_Z", "Z:"))
				]
				]
				]
				]
			// 第三行
			  SVerticalBox::Slot()
				.AutoHeight()
				.Padding(0.0f, 3.0f, 0.0f, 3.0f)
				[
					SNew(SHorizontalBox)
					  SHorizontalBox::Slot()
				.AutoWidth()
				.Padding(3.0f, 3.0f, 10.0f, 3.0f)
				.VAlign(VAlign_Center)
				[
					SNew(STextBlock)
					.MinDesiredWidth(75)
				.Text(LOCTEXT("H3DOptionsWindow_Scale", "Scale:"))
				.ToolTipText(LOCTEXT("H3DOptionsWindow_ScaleTooltip", "Scale"))
				]
			  SHorizontalBox::Slot()
				.AutoWidth()
				.Padding(0.0f, 3.0f, 8.0f, 3.0f)
				[
					SNew(SNumericEntryBox<float>)
					.IsEnabled(true)
					.Value(this, &SH3DOptionsWindow::GetScale3DX)
					.OnValueChanged(this, &SH3DOptionsWindow::SetScale3DX)
				.AllowSpin(true)
				.MinDesiredValueWidth(75)
				.Label()
				[
					SNew(SBox)
					.VAlign(VAlign_Center)
				[
					SNew(STextBlock)
					.Text(LOCTEXT("H3DOptionsWindow_Scale_X", "X:"))
				]
				]
				]
			  SHorizontalBox::Slot()
				.Padding(0.0f, 3.0f, 8.0f, 3.0f)
				.AutoWidth()
				[
					SNew(SNumericEntryBox<float>)
					.IsEnabled(true)
					.Value(this, &SH3DOptionsWindow::GetScale3DY)
					.OnValueChanged(this, &SH3DOptionsWindow::SetScale3DY)
				.AllowSpin(true)
				.MinDesiredValueWidth(75)
				.Label()
				[
					SNew(SBox)
					.VAlign(VAlign_Center)
				[
					SNew(STextBlock)
					.Text(LOCTEXT("H3DOptionsWindow_Scale_Y", "Y:"))
				]
				]
				]
			  SHorizontalBox::Slot()
				.Padding(0.0f, 3.0f, 8.0f, 3.0f)
				.AutoWidth()
				[
					SNew(SNumericEntryBox<float>)
					.IsEnabled(true)
					.Value(this, &SH3DOptionsWindow::GetScale3DZ)
					.OnValueChanged(this, &SH3DOptionsWindow::SetScale3DZ)
				.AllowSpin(true)
				.MinDesiredValueWidth(75)
				.Label()
				[
					SNew(SBox)
					.VAlign(VAlign_Center)
				[
					SNew(STextBlock)
					.Text(LOCTEXT("H3DOptionsWindow_Scale_Z", "Z:"))
				]
				]
				]
				]
			//第四行 Button 按钮
			  SVerticalBox::Slot()
				.AutoHeight()
				.Padding(0.0f, 3.0f, 0.0f, 3.0f)
				[
					SNew(SUniformGridPanel)
					  SUniformGridPanel::Slot(1, 0)
				.HAlign(HAlign_Right)
				[
					SNew(SHorizontalBox)
					  SHorizontalBox::Slot()
				.Padding(5, 0)
				.AutoWidth()
				.HAlign(HAlign_Right)
				[
					SNew(SButton)
					.HAlign(HAlign_Center)
				.VAlign(VAlign_Center)
				.Text(LOCTEXT("H3DOptionsWindow_OK", "OK"))
				.ToolTipText(LOCTEXT("H3DOptionsWindow_OKTip", "OK"))
				.OnClicked(this, &SH3DOptionsWindow::OnOK)
				]
			  SHorizontalBox::Slot()
				.Padding(5, 0)
				.AutoWidth()
				.HAlign(HAlign_Right)
				[
					SNew(SButton)
					.HAlign(HAlign_Center)
				.VAlign(VAlign_Center)
				.Text(LOCTEXT("H3DOptionsWindow_Cancel", "Cancel"))
				.ToolTipText(LOCTEXT("H3DOptionsWindow_CancelTip", "Cancle"))
				.OnClicked(this, &SH3DOptionsWindow::OnCancel)
				]
				]
				]
		];

}


#undef LOCTEXT_NAMESPACE
学新通

参考

  1. UE4 Editor Plugin UI - 模态对话框

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhfkjfie
系列文章
更多 icon
同类精品
更多 icon
继续加载