更新 ui拖拽时 可以进行旋转
This commit is contained in:
parent
253df874a3
commit
cb74c13494
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,7 +2,7 @@
|
||||
"BuildId": "37670630",
|
||||
"Modules":
|
||||
{
|
||||
"ProjectFish": "UnrealEditor-ProjectFish-0027.dll",
|
||||
"ProjectFishEditor": "UnrealEditor-ProjectFishEditor-0027.dll"
|
||||
"ProjectFish": "UnrealEditor-ProjectFish.dll",
|
||||
"ProjectFishEditor": "UnrealEditor-ProjectFishEditor.dll"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
ProjectFish/Content/UI/TestUI/TestA.uasset
Normal file
BIN
ProjectFish/Content/UI/TestUI/TestA.uasset
Normal file
Binary file not shown.
BIN
ProjectFish/Content/UI/TestUI/TestB.uasset
Normal file
BIN
ProjectFish/Content/UI/TestUI/TestB.uasset
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,6 @@
|
||||
"BuildId": "37670630",
|
||||
"Modules":
|
||||
{
|
||||
"DeskMode": "UnrealEditor-DeskMode-0027.dll"
|
||||
"DeskMode": "UnrealEditor-DeskMode.dll"
|
||||
}
|
||||
}
|
||||
@ -3,14 +3,51 @@
|
||||
|
||||
#include "UIManagerSubsystem.h"
|
||||
#include "ProjectFish/Widget/DragableUserWidget.h"
|
||||
#include "Framework/Application/SlateApplication.h"
|
||||
#include "Components/CanvasPanelSlot.h"
|
||||
|
||||
|
||||
void UUIManagerSubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
||||
{
|
||||
Super::Initialize(Collection);
|
||||
FSlateApplication& SlateApp = FSlateApplication::Get();
|
||||
SlateApp.OnApplicationMousePreInputButtonDownListener().AddUObject(this, &UUIManagerSubsystem::OnMouseButtonDown);
|
||||
}
|
||||
|
||||
void UUIManagerSubsystem::AddDragWidget(UDragableUserWidget* UserWidget)
|
||||
{
|
||||
UserWidget->AddToViewport();
|
||||
UserWidget->SetVisibility(ESlateVisibility::HitTestInvisible);
|
||||
DragDropWidget = MakeWeakObjectPtr(UserWidget);
|
||||
}
|
||||
|
||||
void UUIManagerSubsystem::RemoveDragWidget()
|
||||
{
|
||||
if (DragDropWidget.IsValid())
|
||||
{
|
||||
DragDropWidget->RemoveFromViewport();
|
||||
}
|
||||
DragDropWidget.Reset();
|
||||
}
|
||||
|
||||
UDragableUserWidget* UUIManagerSubsystem::GetDragWidget()
|
||||
{
|
||||
if (DragDropWidget.IsValid())
|
||||
{
|
||||
return DragDropWidget.Get();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void UUIManagerSubsystem::OnMouseButtonDown(const FPointerEvent& PointerEvent)
|
||||
{
|
||||
if (DragDropWidget.IsValid())
|
||||
{
|
||||
if (PointerEvent.GetEffectingButton() == EKeys::RightMouseButton)
|
||||
{
|
||||
DragDropWidget->OnMouseButtonDownWhenDragging(PointerEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -16,11 +16,15 @@ class PROJECTFISH_API UUIManagerSubsystem : public UGameInstanceSubsystem
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
|
||||
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
|
||||
UFUNCTION(BlueprintCallable, Category = "UIManagerSubsystem")
|
||||
void AddDragWidget(class UDragableUserWidget* UserWidget);
|
||||
UFUNCTION(BlueprintCallable, Category = "UIManagerSubsystem")
|
||||
void RemoveDragWidget();
|
||||
UFUNCTION(BlueprintPure, Category = "UIManagerSubsystem")
|
||||
UDragableUserWidget* GetDragWidget();
|
||||
|
||||
void OnMouseButtonDown(const FPointerEvent& PointerEvent);
|
||||
|
||||
protected:
|
||||
TWeakObjectPtr<class UDragableUserWidget> DragDropWidget;
|
||||
|
||||
@ -15,9 +15,10 @@ void UDragableUserWidget::SetWidgetDragable(bool Dragable)
|
||||
void UDragableUserWidget::BeginDrag(const FGeometry& InGeometry)
|
||||
{
|
||||
bDraging = true;
|
||||
OriginWidgetScreenPos = InGeometry.GetAbsolutePosition();
|
||||
//OriginWidgetScreenPos = InGeometry.GetAbsolutePosition();
|
||||
UUIManagerSubsystem* UIManager = GetGameInstance()->GetSubsystem<UUIManagerSubsystem>();
|
||||
UIManager->AddDragWidget(this);
|
||||
|
||||
}
|
||||
|
||||
void UDragableUserWidget::EndDrag()
|
||||
@ -28,93 +29,88 @@ void UDragableUserWidget::EndDrag()
|
||||
UIManager->RemoveDragWidget();
|
||||
}
|
||||
|
||||
FReply UDragableUserWidget::NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
|
||||
{
|
||||
if (bDragable && InMouseEvent.GetEffectingButton() == EKeys::LeftMouseButton)
|
||||
{
|
||||
if (bDraging)
|
||||
{
|
||||
EndDrag();
|
||||
return FReply::Unhandled();
|
||||
}
|
||||
else
|
||||
{
|
||||
BeginDrag(InGeometry);
|
||||
return FReply::Handled();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Super::NativeOnMouseButtonDown(InGeometry, InMouseEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
FReply UDragableUserWidget::NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
|
||||
{
|
||||
return Super::NativeOnMouseButtonUp(InGeometry, InMouseEvent);
|
||||
}
|
||||
|
||||
FReply UDragableUserWidget::NativeOnMouseMove(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
|
||||
{
|
||||
if (bDraging)
|
||||
{
|
||||
Super::NativeOnMouseMove(InGeometry, InMouseEvent);
|
||||
|
||||
// 获取鼠标在屏幕空间的绝对坐标
|
||||
FVector2D MouseScreenPos = InMouseEvent.GetScreenSpacePosition();
|
||||
|
||||
// 获取Widget在屏幕上的实际渲染尺寸
|
||||
|
||||
FVector2D WidgetAbsoluteSize = InGeometry.GetDrawSize();
|
||||
|
||||
// 计算Widget中心点应对应的屏幕位置
|
||||
FVector2D DesiredCenter = MouseScreenPos;
|
||||
|
||||
// 计算新的左上角位置(让中心点对准鼠标)
|
||||
FVector2D NewTopLeft =FVector2D(DesiredCenter.X - WidgetAbsoluteSize.X * 0.5f, DesiredCenter.Y - WidgetAbsoluteSize.Y* 0.5f ); ;
|
||||
|
||||
// 边界检查
|
||||
FVector2D ViewportSize;
|
||||
if (GEngine && GEngine->GameViewport)
|
||||
{
|
||||
GEngine->GameViewport->GetViewportSize(ViewportSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewportSize = FVector2D(1920, 1080);
|
||||
}
|
||||
|
||||
// 确保Widget不会完全移出屏幕
|
||||
NewTopLeft.X = FMath::Clamp(NewTopLeft.X, 0.0f, ViewportSize.X - WidgetAbsoluteSize.X);
|
||||
NewTopLeft.Y = FMath::Clamp(NewTopLeft.Y, 0.0f, ViewportSize.Y - WidgetAbsoluteSize.Y);
|
||||
|
||||
// // 计算相对于原始位置的偏移量
|
||||
// FVector2D ParentAbsolutePosition = FVector2D::ZeroVector;
|
||||
// if (InGeometry.GetParentGeometry().IsValid())
|
||||
// {
|
||||
// ParentAbsolutePosition = InGeometry.GetParentGeometry().GetAbsolutePosition();
|
||||
// }
|
||||
//
|
||||
FVector2D LocalOffset = NewTopLeft - OriginWidgetScreenPos;
|
||||
|
||||
// 应用变换
|
||||
FWidgetTransform WidgetTransform = GetRenderTransform();
|
||||
WidgetTransform.Translation = LocalOffset/InGeometry.Scale;
|
||||
SetRenderTransform(WidgetTransform);
|
||||
|
||||
// FString Scale = FString::Printf(TEXT("%.0f"), InGeometry.Scale);
|
||||
// UE_LOG(LogTemp, Warning, TEXT("Mouse: %s, CurrentWidgetScreenPos: %s, WidgetAbsoluteSize: %s NewTopLeft : %s LocalOffset : %s Scale = %s"),
|
||||
// *MouseScreenPos.ToString(),
|
||||
// *OriginWidgetScreenPos.ToString(),
|
||||
// *WidgetAbsoluteSize.ToString(),
|
||||
// *NewTopLeft.ToString(),
|
||||
// *LocalOffset.ToString(),
|
||||
// *Scale
|
||||
// );
|
||||
|
||||
return FReply::Handled();
|
||||
}
|
||||
else
|
||||
return Super::NativeOnMouseMove(InGeometry, InMouseEvent);
|
||||
}
|
||||
// FReply UDragableUserWidget::NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
|
||||
// {
|
||||
// if (bDragable && InMouseEvent.GetEffectingButton() == EKeys::LeftMouseButton)
|
||||
// {
|
||||
// if (!bDraging)
|
||||
// {
|
||||
// BeginDrag(InGeometry);
|
||||
// return FReply::Unhandled();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// return Super::NativeOnMouseButtonDown(InGeometry, InMouseEvent);
|
||||
// }
|
||||
// return FReply::Unhandled();
|
||||
// }
|
||||
//
|
||||
// FReply UDragableUserWidget::NativeOnMouseButtonUp(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
|
||||
// {
|
||||
// return Super::NativeOnMouseButtonUp(InGeometry, InMouseEvent);
|
||||
// }
|
||||
//
|
||||
// FReply UDragableUserWidget::NativeOnMouseMove(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
|
||||
// {
|
||||
// if (bDraging)
|
||||
// {
|
||||
// Super::NativeOnMouseMove(InGeometry, InMouseEvent);
|
||||
//
|
||||
// // 获取鼠标在屏幕空间的绝对坐标
|
||||
// FVector2D MouseScreenPos = InMouseEvent.GetScreenSpacePosition();
|
||||
//
|
||||
// // 获取Widget在屏幕上的实际渲染尺寸
|
||||
//
|
||||
// FVector2D WidgetAbsoluteSize = InGeometry.GetDrawSize();
|
||||
//
|
||||
// // 计算Widget中心点应对应的屏幕位置
|
||||
// FVector2D DesiredCenter = MouseScreenPos;
|
||||
//
|
||||
// // 计算新的左上角位置(让中心点对准鼠标)
|
||||
// FVector2D NewTopLeft =FVector2D(DesiredCenter.X - WidgetAbsoluteSize.X * 0.5f, DesiredCenter.Y - WidgetAbsoluteSize.Y* 0.5f ); ;
|
||||
//
|
||||
// // 边界检查
|
||||
// FVector2D ViewportSize;
|
||||
// if (GEngine && GEngine->GameViewport)
|
||||
// {
|
||||
// GEngine->GameViewport->GetViewportSize(ViewportSize);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ViewportSize = FVector2D(1920, 1080);
|
||||
// }
|
||||
//
|
||||
// // 确保Widget不会完全移出屏幕
|
||||
// NewTopLeft.X = FMath::Clamp(NewTopLeft.X, 0.0f, ViewportSize.X - WidgetAbsoluteSize.X);
|
||||
// NewTopLeft.Y = FMath::Clamp(NewTopLeft.Y, 0.0f, ViewportSize.Y - WidgetAbsoluteSize.Y);
|
||||
//
|
||||
// // // 计算相对于原始位置的偏移量
|
||||
// // FVector2D ParentAbsolutePosition = FVector2D::ZeroVector;
|
||||
// // if (InGeometry.GetParentGeometry().IsValid())
|
||||
// // {
|
||||
// // ParentAbsolutePosition = InGeometry.GetParentGeometry().GetAbsolutePosition();
|
||||
// // }
|
||||
// //
|
||||
// FVector2D LocalOffset = NewTopLeft - OriginWidgetScreenPos;
|
||||
//
|
||||
// // 应用变换
|
||||
// FWidgetTransform WidgetTransform = GetRenderTransform();
|
||||
// WidgetTransform.Translation = LocalOffset/InGeometry.Scale;
|
||||
// SetRenderTransform(WidgetTransform);
|
||||
//
|
||||
// // FString Scale = FString::Printf(TEXT("%.0f"), InGeometry.Scale);
|
||||
// // UE_LOG(LogTemp, Warning, TEXT("Mouse: %s, CurrentWidgetScreenPos: %s, WidgetAbsoluteSize: %s NewTopLeft : %s LocalOffset : %s Scale = %s"),
|
||||
// // *MouseScreenPos.ToString(),
|
||||
// // *OriginWidgetScreenPos.ToString(),
|
||||
// // *WidgetAbsoluteSize.ToString(),
|
||||
// // *NewTopLeft.ToString(),
|
||||
// // *LocalOffset.ToString(),
|
||||
// // *Scale
|
||||
// // );
|
||||
//
|
||||
// return FReply::Unhandled();
|
||||
// }
|
||||
// else
|
||||
// return Super::NativeOnMouseMove(InGeometry, InMouseEvent);
|
||||
// }
|
||||
|
||||
@ -22,12 +22,14 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "Dragable Widget")
|
||||
void EndDrag();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, Category = "Dragable Widget")
|
||||
void OnMouseButtonDownWhenDragging(const FPointerEvent& PointerEvent);
|
||||
|
||||
virtual FReply NativeOnMouseButtonDown( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent ) override;
|
||||
virtual FReply NativeOnMouseButtonUp( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent ) override;
|
||||
virtual FReply NativeOnMouseMove( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent ) override;
|
||||
// virtual FReply NativeOnMouseButtonDown( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent ) override;
|
||||
// virtual FReply NativeOnMouseButtonUp( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent ) override;
|
||||
// virtual FReply NativeOnMouseMove( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent ) override;
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere)
|
||||
UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (ExposeOnSpawn = true))
|
||||
bool bDragable;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user