2025-10-15 18:25:31 +08:00

40 lines
1.2 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "ProjectFish/DataAsset/ShapeAsset.h"
DECLARE_DELEGATE_TwoParams(FOnSlotClicked, int32, int32);
/**
*
*/
class SShapeGridWidget : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(SShapeGridWidget) {}
SLATE_ARGUMENT(UShapeAsset*, BagShapeAsset)
SLATE_EVENT(FOnSlotClicked, OnSlotClicked)
SLATE_END_ARGS()
void Construct(const FArguments& InArgs);
void UpdateBagShapeAsset(UShapeAsset* InBagShapeAsset);
// SWidget interface
virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
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;
private:
static const float CellSize;
static const float SeparatorWidth;
TWeakObjectPtr<UShapeAsset> BagShapeAsset;
FOnSlotClicked OnSlotClicked;
FVector2D GetGridCellFromPosition(const FVector2D& Position) const;
bool IsValidGridPosition(int32 X, int32 Y) const;
};