更新技能配置 效果显示UI

This commit is contained in:
997146918 2025-09-16 13:04:32 +08:00
parent 7f84d384b9
commit 812cc728af
10 changed files with 130 additions and 2 deletions

View File

@ -2,7 +2,7 @@
"BuildId": "37670630", "BuildId": "37670630",
"Modules": "Modules":
{ {
"ProjectFish": "UnrealEditor-ProjectFish-0001.dll", "ProjectFish": "UnrealEditor-ProjectFish.dll",
"ProjectFishEditor": "UnrealEditor-ProjectFishEditor-0001.dll" "ProjectFishEditor": "UnrealEditor-ProjectFishEditor.dll"
} }
} }

View File

@ -28,6 +28,9 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "技能名称")) UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "技能名称"))
FText SkillName; FText SkillName;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "技能描述"))
FText SkillDescription;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "技能分类Tag")) UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "技能分类Tag"))
TArray<ESkillType> SkillTypes; TArray<ESkillType> SkillTypes;

View File

@ -15,6 +15,7 @@ void SBagConfigGridWidget::Construct(const FArguments& InArgs)
PreviewSkill = nullptr; PreviewSkill = nullptr;
PreviewX = -1; PreviewX = -1;
PreviewY = -1; PreviewY = -1;
HoveredSkillIndex = -1;
ChildSlot ChildSlot
[ [
@ -50,9 +51,76 @@ FReply SBagConfigGridWidget::OnMouseButtonDown(const FGeometry& MyGeometry, cons
FReply SBagConfigGridWidget::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) FReply SBagConfigGridWidget::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{ {
if (BagConfig.IsValid())
{
FVector2D LocalPosition = MyGeometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition());
FVector2D GridCell = GetGridCellFromPosition(LocalPosition);
int32 GridX = FMath::FloorToInt(GridCell.X);
int32 GridY = FMath::FloorToInt(GridCell.Y);
if (IsValidGridPosition(GridX, GridY))
{
USkillAsset* HoveredSkill = GetSkillAtPosition(GridX, GridY);
if (HoveredSkill)
{
int32 NewHoveredIndex = BagConfig->GetSkillAtPosition(GridX, GridY);
if (NewHoveredIndex != HoveredSkillIndex)
{
HoveredSkillIndex = NewHoveredIndex;
HoveredSkillTooltip = CreateSkillTooltip(HoveredSkill);
if (HoveredSkillTooltip.IsValid())
{
FSlateApplication::Get().PushMenu(
AsShared(),
FWidgetPath(),
HoveredSkillTooltip.ToSharedRef(),
MouseEvent.GetScreenSpacePosition(),
FPopupTransitionEffect::None
);
}
}
return FReply::Handled();
}
}
// 清除悬停状态
if (HoveredSkillIndex != -1)
{
HoveredSkillIndex = -1;
if (HoveredSkillTooltip.IsValid())
{
FSlateApplication::Get().DismissAllMenus();
HoveredSkillTooltip.Reset();
}
}
}
return FReply::Unhandled(); return FReply::Unhandled();
} }
void SBagConfigGridWidget::OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
SCompoundWidget::OnMouseEnter(MyGeometry, MouseEvent);
}
void SBagConfigGridWidget::OnMouseLeave(const FPointerEvent& MouseEvent)
{
// 清除悬停状态
if (HoveredSkillIndex != -1)
{
HoveredSkillIndex = -1;
if (HoveredSkillTooltip.IsValid())
{
FSlateApplication::Get().DismissAllMenus();
HoveredSkillTooltip.Reset();
}
}
SCompoundWidget::OnMouseLeave(MouseEvent);
}
int32 SBagConfigGridWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, int32 SBagConfigGridWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry,
const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId,
const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
@ -232,3 +300,52 @@ FLinearColor SBagConfigGridWidget::GetCellColor(int32 X, int32 Y) const
// 空闲格子为浅灰色 // 空闲格子为浅灰色
return FLinearColor(0.7f, 0.7f, 0.7f, 1.0f); return FLinearColor(0.7f, 0.7f, 0.7f, 1.0f);
} }
USkillAsset* SBagConfigGridWidget::GetSkillAtPosition(int32 X, int32 Y) const
{
if (!BagConfig.IsValid())
{
return nullptr;
}
int32 SkillIndex = BagConfig->GetSkillAtPosition(X, Y);
if (SkillIndex >= 0 && SkillIndex < BagConfig->PlacedSkills.Num())
{
return BagConfig->PlacedSkills[SkillIndex].SkillAsset;
}
return nullptr;
}
TSharedRef<SWidget> SBagConfigGridWidget::CreateSkillTooltip(USkillAsset* SkillAsset) const
{
if (!SkillAsset)
{
return SNullWidget::NullWidget;
}
return SNew(SBorder)
.BorderImage(FCoreStyle::Get().GetBrush("ToolTip.Background"))
.Padding(FMargin(8.0f))
[
SNew(SVerticalBox)
+ SVerticalBox::Slot()
.AutoHeight()
[
SNew(STextBlock)
.Text(SkillAsset->SkillName)
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 12))
.ColorAndOpacity(FLinearColor::White)
]
+ SVerticalBox::Slot()
.AutoHeight()
.Padding(0, 4, 0, 0)
[
SNew(STextBlock)
.Text(SkillAsset->SkillDescription)
.Font(FCoreStyle::GetDefaultFontStyle("Regular", 10))
.ColorAndOpacity(FLinearColor(0.9f, 0.9f, 0.9f, 1.0f))
.WrapTextAt(250.0f)
]
];
}

View File

@ -35,6 +35,8 @@ protected:
// Slate重写函数 // Slate重写函数
virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
virtual void OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override;
virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect,
FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override; FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override;
@ -52,6 +54,10 @@ private:
int32 PreviewX; int32 PreviewX;
int32 PreviewY; int32 PreviewY;
// 悬停状态
TSharedPtr<SWidget> HoveredSkillTooltip;
int32 HoveredSkillIndex;
// UI参数 // UI参数
static const float CellSize; static const float CellSize;
static const float CellSpacing; static const float CellSpacing;
@ -61,6 +67,8 @@ private:
FVector2D GetGridCellFromPosition(const FVector2D& Position) const; FVector2D GetGridCellFromPosition(const FVector2D& Position) const;
bool IsValidGridPosition(int32 X, int32 Y) const; bool IsValidGridPosition(int32 X, int32 Y) const;
FLinearColor GetCellColor(int32 X, int32 Y) const; FLinearColor GetCellColor(int32 X, int32 Y) const;
USkillAsset* GetSkillAtPosition(int32 X, int32 Y) const;
TSharedRef<SWidget> CreateSkillTooltip(USkillAsset* SkillAsset) const;
}; };