146 lines
3.6 KiB
C++
146 lines
3.6 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "ProjectFish/DataAsset/FishingRewardDataAsset.h"
|
|
#include "ProjectFish/DataAsset/ShapeAsset.h"
|
|
#include "UObject/Object.h"
|
|
#include "ContainerInfo.generated.h"
|
|
|
|
UENUM(BlueprintType)
|
|
enum class EItemDegreeType: uint8
|
|
{
|
|
Zero,
|
|
Ninety UMETA(DisplayName = "90度"),
|
|
OneEighty UMETA(DisplayName = "180度"),
|
|
TwentySeven UMETA(DisplayName = "270度"),
|
|
};
|
|
//仓库物品
|
|
|
|
class UShapeAsset;
|
|
|
|
// 可序列化的容器物品数据(仅用于存档)
|
|
USTRUCT(BlueprintType)
|
|
struct FContainerItemSaveData
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
UPROPERTY(SaveGame)
|
|
int32 PosX;
|
|
|
|
UPROPERTY(SaveGame)
|
|
int32 PosY;
|
|
|
|
UPROPERTY(SaveGame)
|
|
EItemDegreeType DegreeType;
|
|
|
|
UPROPERTY(SaveGame)
|
|
FPrimaryAssetId RewardItemAssetId;
|
|
};
|
|
|
|
USTRUCT(BlueprintType)
|
|
struct FContainerItem
|
|
{
|
|
GENERATED_BODY()
|
|
public:
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
|
FIntPoint ContainerStartPos;
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
|
EItemDegreeType DegreeType;
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
|
UFishingRewardDataAsset* RewardItem;
|
|
|
|
//旋转后的水平宽度
|
|
int32 GetItemWIdth()
|
|
{
|
|
return DegreeType == EItemDegreeType::Ninety || DegreeType == EItemDegreeType::TwentySeven? RewardItem->RewardShape->GetShapeHeight()
|
|
: RewardItem->RewardShape->GetShapeWidth();
|
|
}
|
|
//旋转后的垂直高度
|
|
int32 GetItemHeight()
|
|
{
|
|
return DegreeType == EItemDegreeType::Ninety || DegreeType == EItemDegreeType::TwentySeven? RewardItem->RewardShape->GetShapeWidth()
|
|
: RewardItem->RewardShape->GetShapeHeight();
|
|
}
|
|
|
|
bool IsSlotUsing(FIntPoint Position)
|
|
{
|
|
FIntPoint BeforeRotationPos;
|
|
switch (DegreeType)
|
|
{
|
|
case EItemDegreeType::Zero:
|
|
BeforeRotationPos = Position;
|
|
break;
|
|
case EItemDegreeType::Ninety:
|
|
{
|
|
BeforeRotationPos.X = Position.Y;
|
|
BeforeRotationPos.Y = GetItemWIdth() - Position.X - 1;
|
|
}
|
|
break;
|
|
case EItemDegreeType::OneEighty:
|
|
{
|
|
BeforeRotationPos.X = GetItemWIdth() - Position.X - 1;
|
|
BeforeRotationPos.Y = GetItemHeight() - Position.Y- 1;
|
|
}
|
|
break;
|
|
case EItemDegreeType::TwentySeven:
|
|
{
|
|
BeforeRotationPos.X = Position.X;
|
|
BeforeRotationPos.Y = GetItemHeight() - Position.Y- 1;
|
|
}
|
|
break;
|
|
}
|
|
|
|
return RewardItem->RewardShape->IsSlotActive(BeforeRotationPos.X, BeforeRotationPos.Y);
|
|
}
|
|
|
|
};
|
|
|
|
|
|
/**
|
|
* 仓库
|
|
*/
|
|
UCLASS(BlueprintType)
|
|
class PROJECTFISH_API UContainerInfo : public UObject
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "ContainerInfo")
|
|
void InitContainerByShape(UShapeAsset* InContainerShape);
|
|
|
|
UFUNCTION(BlueprintPure)
|
|
bool AddContainerItem(FContainerItem Item, int32& ItemID);
|
|
UFUNCTION(BlueprintPure)
|
|
bool RemoveContainerItem(const int32& ItemID);
|
|
|
|
// 获取存档数据
|
|
UFUNCTION(BlueprintCallable, Category = "ContainerInfo")
|
|
TArray<FContainerItemSaveData> GetSaveData() const;
|
|
|
|
// 从存档数据加载
|
|
// UFUNCTION(BlueprintCallable, Category = "ContainerInfo")
|
|
// bool LoadFromSaveData(UPlayerInfoSaveGame* SaveGameData);
|
|
|
|
UFUNCTION(BlueprintCallable, Category = "ContainerInfo")
|
|
bool LoadFromSaveData(FPrimaryAssetId ShapeID, const TArray<FContainerItemSaveData>& ContainerItems);
|
|
|
|
private:
|
|
//要添加的物品是否会覆盖其他物品
|
|
bool IsItemOverlapOtherItem(FContainerItem Item);
|
|
//要添加的物品是否在容器范围内
|
|
bool IsItemInContainerShape(FContainerItem Item);
|
|
|
|
public:
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
|
TMap<int32, FContainerItem> Items;
|
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
|
UShapeAsset* ContainerShape;
|
|
|
|
private:
|
|
int32 NextItemID = 0;
|
|
TMap<FIntPoint, bool> SlotInUsing;
|
|
};
|