Compare commits

...

5 Commits

Author SHA1 Message Date
3a6b9042f1 更新船舱的保存功能 2025-10-21 09:17:17 +08:00
2c6e4f2a89 修改船舱的存档功能 2025-10-20 20:37:52 +08:00
4f33cfbd32 修复船舱添加bug 2025-10-20 20:16:33 +08:00
c00a1064b1 修改容器添加逻辑判断bug 2025-10-20 19:59:38 +08:00
680b6b3d87 修复船舱添加物品bug 2025-10-20 19:49:47 +08:00
19 changed files with 132 additions and 23 deletions

View File

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

View File

@ -12,6 +12,7 @@ FixedCameraDistance=1500.0
+PrimaryAssetTypesToScan=(PrimaryAssetType="Map",AssetBaseClass="/Script/Engine.World",bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game/Maps")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=Unknown))
+PrimaryAssetTypesToScan=(PrimaryAssetType="PrimaryAssetLabel",AssetBaseClass="/Script/Engine.PrimaryAssetLabel",bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=Unknown))
+PrimaryAssetTypesToScan=(PrimaryAssetType="FishingRewardDataAsset",AssetBaseClass="/Script/ProjectFish.FishingRewardDataAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/DataAssets/FishReward")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=AlwaysCook))
+PrimaryAssetTypesToScan=(PrimaryAssetType="ShapeAsset",AssetBaseClass="/Script/ProjectFish.ShapeAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/DataAssets")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=AlwaysCook))
bOnlyCookProductionAssets=False
bShouldManagerDetermineTypeAndName=False
bShouldGuessTypeAndNameInEditor=True

Binary file not shown.

View File

@ -2,6 +2,6 @@
"BuildId": "37670630",
"Modules":
{
"DeskMode": "UnrealEditor-DeskMode-0001.dll"
"DeskMode": "UnrealEditor-DeskMode.dll"
}
}

View File

@ -3,6 +3,7 @@
#include "ContainerInfo.h"
#include "PlayerInfoSaveGame.h"
#include "Engine/AssetManager.h"
#include "Engine/StreamableManager.h"
@ -80,16 +81,17 @@ bool UContainerInfo::IsItemOverlapOtherItem(FContainerItem NewItem, FIntPoint Po
{
if (NewItem.IsSlotUsing(Position))
{
if (!ContainerShape->IsSlotActive(Position.X + x, Position.Y + y) ||
SlotInUsing.Find(FIntPoint(x + Position.X, y + Position.Y)))
SlotInUsing[FIntPoint(x + Position.X, y + Position.Y)])
{
return false;
return true;
}
}
}
}
return true;
return false;
}
bool UContainerInfo::IsItemInContainerShape(FContainerItem NewItem, FIntPoint Position)
@ -115,3 +117,51 @@ bool UContainerInfo::IsItemInContainerShape(FContainerItem NewItem, FIntPoint Po
}
return true;
}
TArray<FContainerItemSaveData> UContainerInfo::GetSaveData() const
{
TArray<FContainerItemSaveData> SaveDataArray;
FPrimaryAssetId TestID = ContainerShape->GetPrimaryAssetId();
for (const auto& ItemPair : Items)
{
FContainerItemSaveData SaveData;
SaveData.PosX = ItemPair.Key.X;
SaveData.PosY = ItemPair.Key.Y;
SaveData.DegreeType = ItemPair.Value.DegreeType;
if (ItemPair.Value.RewardItem)
{
SaveData.RewardItemAssetId = ItemPair.Value.RewardItem->GetPrimaryAssetId();
}
SaveDataArray.Add(SaveData);
}
return SaveDataArray;
}
void UContainerInfo::LoadFromSaveData(UPlayerInfoSaveGame* SaveGameData)
{
// 清空当前数据
Items.Empty();
SlotInUsing.Empty();
//从存档中加载仓库形状
if (IsValid(SaveGameData))
{
FSoftObjectPath ShipShapePath = UAssetManager::Get().GetPrimaryAssetPath(SaveGameData->ShipContainerShapeID);
InitContainerByShape(Cast<UShapeAsset>(ShipShapePath.TryLoad()));
;}
// 获得仓库中的物品信息
TArray<FPrimaryAssetId> AssetsToLoad;
for (const FContainerItemSaveData& ItemData : SaveGameData->ShipContainerItems)
{
FContainerItem NewItem;
NewItem.DegreeType = ItemData.DegreeType;
//获得物品形状
FSoftObjectPath RewardItemPath = UAssetManager::Get().GetPrimaryAssetPath(ItemData.RewardItemAssetId);
NewItem.RewardItem = Cast<UFishingRewardDataAsset>(RewardItemPath.TryLoad());
//添加物品到容器中
FIntPoint Position(ItemData.PosX, ItemData.PosY);
AddContainerItem(NewItem, Position);
}
}

View File

@ -20,6 +20,25 @@ enum class EItemDegreeType: uint8
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
{
@ -86,15 +105,21 @@ class PROJECTFISH_API UContainerInfo : public UObject
GENERATED_BODY()
public:
// UFUNCTION(BlueprintCallable, Category = "ContainerInfo")
// void InitContainer(FPrimaryAssetId ContainerShapeId);
UFUNCTION(BlueprintCallable, Category = "ContainerInfo")
void InitContainerByShape(UShapeAsset* InContainerShape);
UFUNCTION(BlueprintPure)
bool AddContainerItem(FContainerItem Item, FIntPoint Position);
// 获取存档数据
UFUNCTION(BlueprintCallable, Category = "ContainerInfo")
TArray<FContainerItemSaveData> GetSaveData() const;
// 从存档数据加载
UFUNCTION(BlueprintCallable, Category = "ContainerInfo")
void LoadFromSaveData(UPlayerInfoSaveGame* SaveGameData);
private:
//要添加的物品是否会覆盖其他物品
bool IsItemOverlapOtherItem(FContainerItem Item, FIntPoint Position);

View File

@ -3,30 +3,44 @@
#pragma once
#include "CoreMinimal.h"
#include "ContainerInfo.h"
#include "GameFramework/SaveGame.h"
#include "ProjectFish/Definations.h"
#include "PlayerInfoSaveGame.generated.h"
/**
*
*
*/
UCLASS()
class PROJECTFISH_API UPlayerInfoSaveGame : public USaveGame
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "船只资源"))
UPROPERTY(SaveGame, BlueprintReadWrite, meta = (ToolTip = "船只资源"))
FPrimaryAssetId ShipAssetID;
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "船只等级"))
int32 ShipLevel;
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "船舱信息"))
class UContainerInfo* ShipContainer;
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "仓库资源"))
UPROPERTY(SaveGame, BlueprintReadWrite, meta = (ToolTip = "船只等级"))
int32 ShipLevel;
// 船舱容器形状资源ID
UPROPERTY(SaveGame, BlueprintReadWrite, meta = (ToolTip = "船舱容器形状"))
FPrimaryAssetId ShipContainerShapeID;
// 船舱物品存档数据
UPROPERTY(SaveGame, BlueprintReadWrite, meta = (ToolTip = "船舱物品数据"))
TArray<FContainerItemSaveData> ShipContainerItems;
UPROPERTY(SaveGame, BlueprintReadWrite, meta = (ToolTip = "仓库资源"))
FPrimaryAssetId PlayerContainerAssetID;
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "仓库等级"))
UPROPERTY(SaveGame, BlueprintReadWrite, meta = (ToolTip = "仓库等级"))
int32 PlayerContainerLevel;
UPROPERTY(BlueprintReadWrite, meta = (ToolTip = "玩家仓库信息"))
class UContainerInfo* PlayerContainer;
// 玩家仓库容器形状资源ID
UPROPERTY(SaveGame, BlueprintReadWrite, meta = (ToolTip = "玩家仓库容器形状"))
FPrimaryAssetId PlayerContainerShapeID;
// 玩家仓库物品存档数据
UPROPERTY(SaveGame, BlueprintReadWrite, meta = (ToolTip = "玩家仓库物品数据"))
TArray<FContainerItemSaveData> PlayerContainerItems;
};

View File

@ -9,6 +9,11 @@ UShapeAsset::UShapeAsset()
InitializeShape();
}
FPrimaryAssetId UShapeAsset::GetPrimaryAssetId() const
{
return FPrimaryAssetId(TEXT("ShapeAsset"), GetFName());
}
void UShapeAsset::InitializeShape()
{
Slots.Empty();

View File

@ -41,6 +41,7 @@ class PROJECTFISH_API UShapeAsset : public UDataAsset
public:
UShapeAsset();
virtual FPrimaryAssetId GetPrimaryAssetId() const override;
UFUNCTION(BlueprintCallable, Category="Shape")
void InitializeShape();

View File

@ -39,6 +39,15 @@ bool UGameInfoManager::LoadGameInfo()
if (UGameplayStatics::DoesSaveGameExist(SaveGameSlotName, 0))
{
PlayerInfo = Cast<UPlayerInfoSaveGame>(UGameplayStatics::LoadGameFromSlot(SaveGameSlotName, 0));
return true;
}
return false;
}
void UGameInfoManager::CreateGameInfo(UContainerInfo* ShipContainer)
{
PlayerInfo = NewObject<UPlayerInfoSaveGame>(this);
PlayerInfo->ShipContainerItems = ShipContainer->GetSaveData();
PlayerInfo->ShipContainerShapeID = ShipContainer->ContainerShape->GetPrimaryAssetId();
SaveGameInfo();
}

View File

@ -17,11 +17,15 @@ class PROJECTFISH_API UGameInfoManager : public UGameInstanceSubsystem
public:
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
private:
protected:
UFUNCTION(BlueprintCallable)
void SaveGameInfo();
UFUNCTION(BlueprintCallable)
bool LoadGameInfo();
UFUNCTION(BlueprintCallable)
void CreateGameInfo(UContainerInfo* ShipContainer);
protected:
UPROPERTY(BlueprintReadOnly)
TSoftObjectPtr<class UPlayerInfoSaveGame> PlayerInfo;
TObjectPtr<class UPlayerInfoSaveGame> PlayerInfo;
static FString SaveGameSlotName;
};

View File

@ -23,5 +23,5 @@ int32 UFishFunctionLibrary::GetContainerItemWiidth(const UObject* WorldContextOb
int32 UFishFunctionLibrary::GetContainerItemHeight(const UObject* WorldContextObject, FContainerItem ContainerItem)
{
return ContainerItem.GetItemWIdth();
return ContainerItem.GetItemHeight();
}