2025-08-31 15:36:48 +08:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
#include "ProjectFish/DataAsset/BagConfigAsset.h"
|
|
|
|
|
|
|
|
|
|
DECLARE_DELEGATE_TwoParams(FOnGridCellClicked, int32, int32);
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class PROJECTFISHEDITOR_API SBagConfigGridWidget : public SCompoundWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SLATE_BEGIN_ARGS(SBagConfigGridWidget) {}
|
|
|
|
|
SLATE_ARGUMENT(UBagConfigAsset*, BagConfig)
|
|
|
|
|
SLATE_EVENT(FOnGridCellClicked, OnGridCellClicked)
|
|
|
|
|
SLATE_END_ARGS()
|
|
|
|
|
|
|
|
|
|
void Construct(const FArguments& InArgs);
|
|
|
|
|
|
|
|
|
|
// // 设置背包类
|
|
|
|
|
// void UpdateBagConfig(UBagConfigAsset* InBagClass);
|
|
|
|
|
//
|
|
|
|
|
// // 设置预览技能(用于显示放置预览)
|
|
|
|
|
// void SetPreviewSkill(USkillAsset* InPreviewSkill, int32 PreviewX, int32 PreviewY);
|
|
|
|
|
//
|
|
|
|
|
// // 清除预览
|
|
|
|
|
// void ClearPreview();
|
|
|
|
|
//
|
|
|
|
|
// 刷新显示
|
|
|
|
|
void RefreshGrid();
|
|
|
|
|
|
|
|
|
|
protected:
|
2025-08-31 15:49:07 +08:00
|
|
|
// Slate重写函数
|
|
|
|
|
virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
|
|
|
|
virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
2025-09-16 13:04:32 +08:00
|
|
|
virtual void OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
|
|
|
|
|
virtual void OnMouseLeave(const FPointerEvent& MouseEvent) override;
|
2025-08-31 15:49:07 +08:00
|
|
|
virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect,
|
|
|
|
|
FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override;
|
|
|
|
|
|
|
|
|
|
virtual FVector2D ComputeDesiredSize(float) const override;
|
2025-08-31 15:36:48 +08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// 背包类引用
|
2025-08-31 15:49:07 +08:00
|
|
|
TWeakObjectPtr<UBagConfigAsset> BagConfig;
|
2025-08-31 15:36:48 +08:00
|
|
|
|
|
|
|
|
// 回调委托
|
|
|
|
|
FOnGridCellClicked OnGridCellClicked;
|
|
|
|
|
|
|
|
|
|
// 预览数据
|
|
|
|
|
TWeakObjectPtr<USkillAsset> PreviewSkill;
|
|
|
|
|
int32 PreviewX;
|
|
|
|
|
int32 PreviewY;
|
|
|
|
|
|
2025-09-16 13:04:32 +08:00
|
|
|
// 悬停状态
|
|
|
|
|
TSharedPtr<SWidget> HoveredSkillTooltip;
|
|
|
|
|
int32 HoveredSkillIndex;
|
|
|
|
|
|
2025-08-31 15:36:48 +08:00
|
|
|
// UI参数
|
|
|
|
|
static const float CellSize;
|
|
|
|
|
static const float CellSpacing;
|
|
|
|
|
|
2025-08-31 15:49:07 +08:00
|
|
|
// 工具函数
|
|
|
|
|
FVector2D GetCellPosition(int32 X, int32 Y) const;
|
|
|
|
|
FVector2D GetGridCellFromPosition(const FVector2D& Position) const;
|
|
|
|
|
bool IsValidGridPosition(int32 X, int32 Y) const;
|
|
|
|
|
FLinearColor GetCellColor(int32 X, int32 Y) const;
|
2025-09-16 13:04:32 +08:00
|
|
|
USkillAsset* GetSkillAtPosition(int32 X, int32 Y) const;
|
|
|
|
|
TSharedRef<SWidget> CreateSkillTooltip(USkillAsset* SkillAsset) const;
|
2025-08-31 15:59:08 +08:00
|
|
|
|
2025-08-31 15:36:48 +08:00
|
|
|
};
|
2025-08-31 15:49:07 +08:00
|
|
|
|
|
|
|
|
inline FVector2D SBagConfigGridWidget::GetCellPosition(int32 X, int32 Y) const
|
|
|
|
|
{
|
|
|
|
|
return FVector2D(
|
|
|
|
|
X * (CellSize + CellSpacing),
|
|
|
|
|
Y * (CellSize + CellSpacing)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|