Added ClothingItemInstance and cleanup the project
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
|
||||
#include "ClothingManager.h"
|
||||
#include "ClothingItemData.h"
|
||||
#include "ClothingItem.h"
|
||||
#include "ClothingItemInstance.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "NakedDesire/SaveGame/GlobalSaveGameData.h"
|
||||
|
||||
UClothingManager::UClothingManager()
|
||||
{
|
||||
@@ -15,7 +15,7 @@ bool UClothingManager::IsBodyTypeExposed(const EPrivateBodyPartType PrivateBodyP
|
||||
{
|
||||
for (const auto& ClothingSlot : ClothingSlots)
|
||||
{
|
||||
if (ClothingSlot.ClothingData && ClothingSlot.ClothingData->Info->CoveredBodyParts.Contains(PrivateBodyPartType))
|
||||
if (ClothingSlot.ClothingItemInstance && ClothingSlot.ClothingItemInstance->GetClothingItem()->CoveredBodyParts.Contains(PrivateBodyPartType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -37,26 +37,26 @@ bool UClothingManager::GetClothingSlotData(const EClothingSlotType ClothingSlotT
|
||||
|
||||
return false;
|
||||
}
|
||||
void UClothingManager::SetClothingSlotItem(const EClothingSlotType ClothingSlotType, UClothingItemData* ClothingItem)
|
||||
void UClothingManager::SetClothingSlotItem(const EClothingSlotType ClothingSlotType, UClothingItemInstance* ClothingItemInstance)
|
||||
{
|
||||
for (FClothingSlotData& ClothingSlot : ClothingSlots)
|
||||
{
|
||||
if (ClothingSlot.ClothingSlotType == ClothingSlotType)
|
||||
{
|
||||
ClothingSlot.ClothingData = ClothingItem;
|
||||
ClothingSlot.ClothingItemInstance = ClothingItemInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TArray<UClothingItemData*> UClothingManager::GetEquippedClothing()
|
||||
TArray<UClothingItemInstance*> UClothingManager::GetEquippedClothing()
|
||||
{
|
||||
TArray<UClothingItemData*> EquippedClothingItems;
|
||||
TArray<UClothingItemInstance*> EquippedClothingItems;
|
||||
|
||||
for (FClothingSlotData ClothingSlot : ClothingSlots)
|
||||
{
|
||||
if (ClothingSlot.ClothingData)
|
||||
if (ClothingSlot.ClothingItemInstance)
|
||||
{
|
||||
EquippedClothingItems.Add(ClothingSlot.ClothingData);
|
||||
EquippedClothingItems.Add(ClothingSlot.ClothingItemInstance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,110 +65,101 @@ TArray<UClothingItemData*> UClothingManager::GetEquippedClothing()
|
||||
|
||||
void UClothingManager::HydrateClothing(UGlobalSaveGameData* SaveGameData)
|
||||
{
|
||||
for (const FClothingItemSaveData& ClothingItemSaveData : SaveGameData->PlayerClothing)
|
||||
{
|
||||
UClothingItemData* ClothingItemData = UClothingItemData::CreateFromSaveData(ClothingItemSaveData);
|
||||
PutOnClothing(ClothingItemData);
|
||||
}
|
||||
// for (const FClothingItemSaveData& ClothingItemSaveData : SaveGameData->PlayerClothing)
|
||||
// {
|
||||
// UClothingItemData* ClothingItemData = UClothingItemData::CreateFromSaveData(ClothingItemSaveData);
|
||||
// PutOnClothing(ClothingItemData);
|
||||
// }
|
||||
}
|
||||
|
||||
float UClothingManager::GetHeelHeight()
|
||||
{
|
||||
if (FClothingSlotData ClothingSlotData; GetClothingSlotData(EClothingSlotType::Shoes, ClothingSlotData))
|
||||
{
|
||||
if (ClothingSlotData.ClothingData)
|
||||
if (ClothingSlotData.ClothingItemInstance)
|
||||
{
|
||||
return ClothingSlotData.ClothingData->Info->ShoesOffset;
|
||||
return ClothingSlotData.ClothingItemInstance->GetClothingItem()->ShoesOffset;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UClothingManager::PutOnClothing(UClothingItemData* ClothingData)
|
||||
void UClothingManager::PutOnClothing(UClothingItemInstance* ClothingItemInstance)
|
||||
{
|
||||
if (!ClothingData)
|
||||
{
|
||||
if (!ClothingItemInstance)
|
||||
return;
|
||||
}
|
||||
|
||||
const EClothingSlotType ClothingSlotType = ClothingData->Info->SlotType;
|
||||
const EClothingSlotType ClothingSlotType = ClothingItemInstance->GetClothingItem()->SlotType;
|
||||
|
||||
FClothingSlotData ClothingSlotData;
|
||||
GetClothingSlotData(ClothingSlotType, ClothingSlotData);
|
||||
|
||||
ClothingSlotData.MeshComponent->SetSkeletalMesh(ClothingData->Info->SkeletalMesh);
|
||||
if (!ClothingData->Info->Materials.IsEmpty())
|
||||
ClothingSlotData.MeshComponent->SetSkeletalMesh(ClothingItemInstance->GetClothingItem()->SkeletalMesh);
|
||||
if (!ClothingItemInstance->GetClothingItem()->Materials.IsEmpty())
|
||||
{
|
||||
for (const TPair<FName, UMaterialInstance*>& Material : ClothingData->Info->Materials)
|
||||
for (const TPair<FName, UMaterialInstance*>& Material : ClothingItemInstance->GetClothingItem()->Materials)
|
||||
{
|
||||
ClothingSlotData.MeshComponent->SetMaterialByName(Material.Key, Material.Value);
|
||||
}
|
||||
}
|
||||
|
||||
SetClothingSlotItem(ClothingSlotType, ClothingData);
|
||||
if (ClothingData->Info->UseLeaderPose)
|
||||
SetClothingSlotItem(ClothingSlotType, ClothingItemInstance);
|
||||
if (ClothingItemInstance->GetClothingItem()->UseLeaderPose)
|
||||
{
|
||||
ClothingSlotData.MeshComponent->SetLeaderPoseComponent(Cast<ACharacter>(GetOwner())->GetMesh());
|
||||
}
|
||||
|
||||
OnClothingEquip.Broadcast(ClothingData);
|
||||
OnClothingEquip.Broadcast(ClothingItemInstance);
|
||||
}
|
||||
|
||||
void UClothingManager::TakeClothing(UClothingItemData* ClothingData)
|
||||
void UClothingManager::TakeClothing(UClothingItemInstance* ClothingItemInstance)
|
||||
{
|
||||
if (!ClothingData->Info)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FClothingSlotData ClothingSlotData;
|
||||
GetClothingSlotData(ClothingData->Info->SlotType, ClothingSlotData);
|
||||
GetClothingSlotData(ClothingItemInstance->GetClothingItem()->SlotType, ClothingSlotData);
|
||||
|
||||
if (ClothingSlotData.ClothingData->Info)
|
||||
if (ClothingSlotData.ClothingItemInstance->GetClothingItem())
|
||||
{
|
||||
DropClothing(ClothingData->Info->SlotType);
|
||||
DropClothing(ClothingItemInstance->GetClothingItem()->SlotType);
|
||||
}
|
||||
|
||||
ClothingSlotData.ClothingData = ClothingData;
|
||||
ClothingSlotData.ClothingItemInstance = ClothingItemInstance;
|
||||
|
||||
PutOnClothing(ClothingData);
|
||||
PutOnClothing(ClothingItemInstance);
|
||||
}
|
||||
|
||||
UClothingItemData* UClothingManager::RemoveClothing(const EClothingSlotType ClothingSlotType)
|
||||
UClothingItemInstance* UClothingManager::RemoveClothing(const EClothingSlotType ClothingSlotType)
|
||||
{
|
||||
FClothingSlotData ClothingSlotData;
|
||||
if (!GetClothingSlotData(ClothingSlotType, ClothingSlotData) || !ClothingSlotData.ClothingData)
|
||||
if (!GetClothingSlotData(ClothingSlotType, ClothingSlotData) || !ClothingSlotData.ClothingItemInstance)
|
||||
{
|
||||
UE_LOG(LogTemp, Error, TEXT("Couldn't find clothing slot"));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UClothingItemData* ClothingData = ClothingSlotData.ClothingData;
|
||||
UClothingItemInstance* ClothingItemInstance = ClothingSlotData.ClothingItemInstance;
|
||||
SetClothingSlotItem(ClothingSlotType, nullptr);
|
||||
|
||||
USkeletalMeshComponent* MeshComponent = ClothingSlotData.MeshComponent;
|
||||
MeshComponent->SetSkeletalMesh(nullptr);
|
||||
|
||||
if (ClothingData->Info->UseLeaderPose)
|
||||
if (ClothingItemInstance->GetClothingItem()->UseLeaderPose)
|
||||
{
|
||||
ClothingSlotData.MeshComponent->SetLeaderPoseComponent(nullptr);
|
||||
}
|
||||
|
||||
OnClothingUnequip.Broadcast(ClothingData);
|
||||
OnClothingUnequip.Broadcast(ClothingItemInstance);
|
||||
|
||||
return ClothingData;
|
||||
return ClothingItemInstance;
|
||||
}
|
||||
|
||||
void UClothingManager::DropClothing(const EClothingSlotType ClothingType)
|
||||
{
|
||||
const UClothingItemData* ClothingData = RemoveClothing(ClothingType);
|
||||
if (!ClothingData)
|
||||
{
|
||||
const UClothingItemInstance* ClothingItemInstance = RemoveClothing(ClothingType);
|
||||
if (!ClothingItemInstance)
|
||||
return;
|
||||
}
|
||||
|
||||
OnClothingDropped.Broadcast(ClothingData);
|
||||
OnClothingDropped.Broadcast(ClothingItemInstance);
|
||||
}
|
||||
|
||||
bool UClothingManager::IsClothingTypeOn(const EClothingSlotType ClothingType)
|
||||
@@ -176,7 +167,7 @@ bool UClothingManager::IsClothingTypeOn(const EClothingSlotType ClothingType)
|
||||
FClothingSlotData ClothingSlotData;
|
||||
GetClothingSlotData(ClothingType, ClothingSlotData);
|
||||
|
||||
const bool IsTypeOn = ClothingSlotData.ClothingData != nullptr;
|
||||
const bool IsTypeOn = ClothingSlotData.ClothingItemInstance != nullptr;
|
||||
return IsTypeOn;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user