Compare commits

..

2 Commits

7 changed files with 32 additions and 0 deletions

Binary file not shown.

View File

@ -43,6 +43,7 @@ int32 UContainerInfo::AddContainerItem(FContainerItem Item)
if (Item.IsSlotUsing(FIntPoint(x, y)))
{
SlotInUsing.Add(FIntPoint(x + Item.ContainerStartPos.X, y + Item.ContainerStartPos.Y), true);
SlotItems.Add(FIntPoint(x + Item.ContainerStartPos.X, y + Item.ContainerStartPos.Y), ItemID);
}
}
}
@ -61,6 +62,7 @@ bool UContainerInfo::RemoveContainerItem(const int32& ItemID)
if (Item.IsSlotUsing(FIntPoint(x, y )))
{
SlotInUsing[FIntPoint(x + Item.ContainerStartPos.X, y + Item.ContainerStartPos.Y)] = false;
SlotItems[FIntPoint(x + Item.ContainerStartPos.X, y + Item.ContainerStartPos.Y)] = -1;
}
}
}
@ -70,6 +72,32 @@ bool UContainerInfo::RemoveContainerItem(const int32& ItemID)
return false;
}
TSet<int32> UContainerInfo::GetOverlapOtherItem(FContainerItem Item)
{
TSet<int32> OverlapItems;
if (IsItemInContainerShape(Item))
{
for (int x = 0; x < Item.GetItemWIdth(); x++)
{
for (int y = 0; y < Item.GetItemHeight(); y++)
{
if (Item.IsSlotUsing(FIntPoint(x, y)))
{
if (ContainerShape->IsSlotActive(Item.ContainerStartPos.X + x, Item.ContainerStartPos.Y + y) &&
SlotItems[FIntPoint(x + Item.ContainerStartPos.X, y + Item.ContainerStartPos.Y)] != -1
)
{
OverlapItems.Add(SlotItems[FIntPoint(x + Item.ContainerStartPos.X, y + Item.ContainerStartPos.Y)] );
}
}
}
}
}
return OverlapItems;
}
bool UContainerInfo::IsItemOverlapOtherItem(FContainerItem NewItem)
{
@ -143,6 +171,7 @@ bool UContainerInfo::LoadFromSaveData(FPrimaryAssetId ShapeID, const TArray<FCon
// 清空当前数据
Items.Empty();
SlotInUsing.Empty();
SlotItems.Empty();
//从存档中加载仓库形状
FSoftObjectPath ShipShapePath = UAssetManager::Get().GetPrimaryAssetPath(ShapeID);
UShapeAsset* ShapeAsset = Cast<UShapeAsset>(ShipShapePath.TryLoad());

View File

@ -115,6 +115,8 @@ public:
int32 AddContainerItem(FContainerItem Item);
UFUNCTION(BlueprintPure)
bool RemoveContainerItem(const int32& ItemID);
UFUNCTION(BlueprintPure)
TSet<int32> GetOverlapOtherItem(FContainerItem Item);
// 获取存档数据
UFUNCTION(BlueprintCallable, Category = "ContainerInfo")
@ -142,4 +144,5 @@ public:
private:
int32 NextItemID = 0;
TMap<FIntPoint, bool> SlotInUsing;
TMap<FIntPoint, int32> SlotItems;
};