添加容器原本位置存在item 替换拖拽
This commit is contained in:
parent
f9674f5445
commit
f80c48465c
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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());
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user