更新容器添加可旋转的shape物品

This commit is contained in:
997146918 2025-10-17 18:59:12 +08:00
parent c340c59eab
commit ce4efe2972
13 changed files with 256 additions and 9 deletions

View File

@ -0,0 +1,104 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "ContainerInfo.h"
#include "Engine/AssetManager.h"
#include "Engine/StreamableManager.h"
void UContainerInfo::InitContainer(FPrimaryAssetId ContainerShapeId)
{
//加载形状资源
TSharedPtr<FStreamableHandle> LoadHandle = GEngine->AssetManager->LoadPrimaryAsset(ContainerShapeId);
if (LoadHandle.IsValid())
{
// 等待加载完成,这会阻塞线程
LoadHandle->WaitUntilComplete();
// 加载完成后,通过句柄获取资源
UObject* LoadedObject = LoadHandle->GetLoadedAsset();
if (LoadedObject)
{
ContainerShape = Cast<UShapeAsset>(LoadedObject);
for (int x = 0; x < ContainerShape->GetShapeWidth(); x++)
{
for (int y = 0; y < ContainerShape->GetShapeHeight(); y++)
{
SlotInUsing.Add(FIntPoint(x, y), false);
}
}
}
LoadHandle->ReleaseHandle();
}
}
bool UContainerInfo::AddContainerItem(FContainerItem Item, FIntPoint Position)
{
if (IsItemInContainerShape(Item, Position))
{
return false;
}
if (!IsItemOverlapOtherItem(Item, Position))
{
return false;
}
//设置容器指定位置的占用状态
for (int x = 0; x < Item.GetItemWIdth(); x++)
{
for (int y = 0; y < Item.GetItemHeight(); y++)
{
if (Item.IsSlotUsing(FIntPoint(x, y)))
{
SlotInUsing.Add(FIntPoint(x + Position.X, y + Position.Y), true);
}
}
}
return true;
}
bool UContainerInfo::IsItemOverlapOtherItem(FContainerItem NewItem, FIntPoint Position)
{
for (int x = 0; x < NewItem.GetItemWIdth(); x++)
{
for (int y = 0; y < NewItem.GetItemHeight(); y++)
{
if (NewItem.IsSlotUsing(Position))
{
if (!ContainerShape->IsSlotActive(Position.X + x, Position.Y + y) ||
SlotInUsing.Find(FIntPoint(x + Position.X, y + Position.Y)))
{
return false;
}
}
}
}
return true;
}
bool UContainerInfo::IsItemInContainerShape(FContainerItem NewItem, FIntPoint Position)
{
for (int x = 0; x < NewItem.GetItemWIdth(); x++)
{
for (int y = 0; y < NewItem.GetItemHeight(); y++)
{
if ( (x + Position.X) > 0 && (x + Position.X) < ContainerShape->GetShapeWidth() &&
(y + Position.Y) > 0 && (y + Position.Y) < ContainerShape->GetShapeHeight()
)
{
if (!ContainerShape->IsSlotActive(Position.X + x, Position.Y + y))
{
return false;
}
}
else
{
return false;
}
}
}
return true;
}

View File

@ -0,0 +1,106 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.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 FContainerItem
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
EItemDegreeType DegreeType;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UShapeAsset* ItemShape;
//旋转后的水平宽度
int32 GetItemWIdth()
{
return DegreeType == EItemDegreeType::Ninety || DegreeType == EItemDegreeType::TwentySeven? ItemShape->GetShapeHeight()
: ItemShape->GetShapeWidth();
}
//旋转后的垂直高度
int32 GetItemHeight()
{
return DegreeType == EItemDegreeType::Ninety || DegreeType == EItemDegreeType::TwentySeven? ItemShape->GetShapeWidth()
: ItemShape->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 ItemShape->IsSlotActive(BeforeRotationPos.X, BeforeRotationPos.Y);
}
};
/**
*
*/
UCLASS()
class PROJECTFISH_API UContainerInfo : public UObject
{
GENERATED_BODY()
public:
void InitContainer(FPrimaryAssetId ContainerShapeId);
UFUNCTION(BlueprintPure)
bool AddContainerItem(FContainerItem Item, FIntPoint Position);
private:
//要添加的物品是否会覆盖其他物品
bool IsItemOverlapOtherItem(FContainerItem Item, FIntPoint Position);
//要添加的物品是否在容器范围内
bool IsItemInContainerShape(FContainerItem Item, FIntPoint Position);
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TMap<int32, FContainerItem> Items;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UShapeAsset* ContainerShape;
private:
TMap<FIntPoint, bool> SlotInUsing;
};

View File

@ -20,13 +20,13 @@ public:
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "船只等级"))
int32 ShipLevel;
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "船舱信息"))
FContainerInfo ShipContainer;
class UContainerInfo* ShipContainer;
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "仓库资源"))
FPrimaryAssetId PlayerContainerAssetID;
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "仓库等级"))
int32 PlayerContainerLevel;
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "玩家仓库信息"))
FContainerInfo PlayerContainer;
class UContainerInfo* PlayerContainer;
};

View File

@ -8,7 +8,7 @@
#include "FishInfoConfigAsset.generated.h"
/**
*
*
*/
UCLASS(BlueprintType)
class PROJECTFISH_API UFishInfoConfigAsset : public UDataAsset

View File

@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "ShapeAsset.h"
#include "Engine/DataAsset.h"
#include "FishingRewardDataAsset.generated.h"
@ -14,7 +15,7 @@ enum class ERewardRarityType: uint8
Rare UMETA(DisplayName = "稀有"),
};
/**
*
*
*/
UCLASS()
class PROJECTFISH_API UFishingRewardDataAsset : public UPrimaryDataAsset
@ -30,6 +31,9 @@ public:
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Fishing Reward Data" , meta = (ToolTip = "鱼获重量"))
float RewardWeight;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Fishing Reward Data" , meta = (ToolTip = "鱼获形状"))
class UShapeAsset* RewardShape;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Fishing Reward Data" , meta = (ToolTip = "鱼获稀有度"))
ERewardRarityType RewardRarityType;
};

View File

@ -15,7 +15,7 @@ struct FShapeSlot
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 Y;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ToolTip = "该槽位是否为激活状态"))
bool bIsActive;
FShapeSlot()
{
@ -28,6 +28,7 @@ struct FShapeSlot
X = InX;
Y = InY;
bIsActive = InIsActive;
}
};
/**

View File

@ -0,0 +1,4 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "ShipConfigAsset.h"

View File

@ -0,0 +1,23 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "ShapeAsset.h"
#include "Engine/DataAsset.h"
#include "ShipConfigAsset.generated.h"
/**
*
*/
UCLASS()
class PROJECTFISH_API UShipConfigAsset : public UPrimaryDataAsset
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Ship")
FText ShipName;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Ship", meta=(ToolTip = "等级对应的船舱形状"))
TArray<UShapeAsset*> Level_ShipShapes;
};

View File

@ -5,6 +5,7 @@
#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
#include "PawnWithSkill.h"
#include "DataAsset/ShapeAsset.h"
#include "UObject/Object.h"
#include "Definations.generated.h"
@ -460,3 +461,7 @@ struct FSimpleConnection
{
}
};

View File

@ -11,7 +11,7 @@
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Kismet/KismetMathLibrary.h"
#include "ProjectFish/Components/ShipSpringArmComponent.h"
#include "ProjectFish/Gameplay/Components/ShipSpringArmComponent.h"
#include "ProjectFish/Settings/GameConfigSettings.h"

View File

@ -3,7 +3,7 @@
#include "SkillEffect_EnhanceFishRod.h"
#include "ProjectFish/Components/FishingRodComponent.h"
#include "ProjectFish/Gameplay/Components/FishingRodComponent.h"
#include "ProjectFish/Skill/Skill.h"
void USkillEffect_EnhanceFishRod::Execute(const FSkillContext& context)