Completed phase 1
This commit is contained in:
@@ -1 +1,27 @@
|
||||
#include "ClothingItemInstance.h"
|
||||
|
||||
#include "ClothingItem.h"
|
||||
#include "NakedDesire/SaveGame/ItemSaveRecord.h"
|
||||
|
||||
void UClothingItemInstance::Init(UClothingItem* InClothingItem)
|
||||
{
|
||||
ClothingItem = InClothingItem;
|
||||
}
|
||||
|
||||
void UClothingItemInstance::Setup(UClothingItem* InClothingItem, const TArray<UItemInstance*>& InStoredItems,
|
||||
const float InCondition, const FGuid InInstanceId)
|
||||
{
|
||||
this->ClothingItem = InClothingItem;
|
||||
this->StoredItems = InStoredItems;
|
||||
this->Condition = InCondition;
|
||||
this->InstanceId = InInstanceId;
|
||||
}
|
||||
|
||||
UClothingItemInstance* UClothingItemInstance::CreateFromSave(UObject* Outer, const FItemSaveRecord& ItemSaveRecord)
|
||||
{
|
||||
UClothingItemInstance* NewItemInstance = NewObject<UClothingItemInstance>(Outer);
|
||||
|
||||
NewItemInstance->Setup(ItemSaveRecord.Definition.Get(), {}, ItemSaveRecord.Condition, ItemSaveRecord.InstanceId);
|
||||
|
||||
return NewItemInstance;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "NakedDesire/Items/ItemInstance.h"
|
||||
#include "ClothingItemInstance.generated.h"
|
||||
|
||||
struct FItemSaveRecord;
|
||||
class UClothingItem;
|
||||
|
||||
UCLASS(BlueprintType)
|
||||
@@ -17,6 +18,11 @@ public:
|
||||
|
||||
UClothingItem* GetClothingItem() const { return ClothingItem; }
|
||||
|
||||
void Init(UClothingItem* InClothingItem);
|
||||
void Setup(UClothingItem* InClothingItem, const TArray<UItemInstance*>& InStoredItems, float InCondition, FGuid InInstanceId);
|
||||
|
||||
static UClothingItemInstance* CreateFromSave(UObject* Outer, const FItemSaveRecord& ItemSaveRecord);
|
||||
|
||||
protected:
|
||||
UPROPERTY(BlueprintReadOnly, Category = "Clothing Item")
|
||||
TObjectPtr<UClothingItem> ClothingItem;
|
||||
|
||||
@@ -5,12 +5,23 @@
|
||||
#include "ClothingItem.h"
|
||||
#include "ClothingItemInstance.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "NakedDesire/SaveGame/GlobalSaveGameData.h"
|
||||
#include "NakedDesire/SaveGame/ItemSaveRecord.h"
|
||||
#include "NakedDesire/SaveGame/SaveSubsystem.h"
|
||||
|
||||
UClothingManager::UClothingManager()
|
||||
{
|
||||
PrimaryComponentTick.bCanEverTick = false;
|
||||
}
|
||||
|
||||
void UClothingManager::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
HydrateClothing();
|
||||
}
|
||||
|
||||
bool UClothingManager::IsBodyTypeExposed(const EBodyPart BodyPart)
|
||||
{
|
||||
for (const auto& ClothingSlot : ClothingSlots)
|
||||
@@ -63,13 +74,14 @@ TArray<UClothingItemInstance*> UClothingManager::GetEquippedClothing()
|
||||
return EquippedClothingItems;
|
||||
}
|
||||
|
||||
void UClothingManager::HydrateClothing(UGlobalSaveGameData* SaveGameData)
|
||||
void UClothingManager::HydrateClothing()
|
||||
{
|
||||
// for (const FClothingItemSaveData& ClothingItemSaveData : SaveGameData->PlayerClothing)
|
||||
// {
|
||||
// UClothingItemData* ClothingItemData = UClothingItemData::CreateFromSaveData(ClothingItemSaveData);
|
||||
// PutOnClothing(ClothingItemData);
|
||||
// }
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
for (const FItemSaveRecord& ItemSaveRecord : SaveSubsystem->GetCurrentSave()->EquippedItems)
|
||||
{
|
||||
UClothingItemInstance* ClothingItemInstance = UClothingItemInstance::CreateFromSave(this, ItemSaveRecord);
|
||||
PutOnClothing(ClothingItemInstance);
|
||||
}
|
||||
}
|
||||
|
||||
float UClothingManager::GetHeelHeight()
|
||||
@@ -109,6 +121,22 @@ void UClothingManager::PutOnClothing(UClothingItemInstance* ClothingItemInstance
|
||||
{
|
||||
ClothingSlotData.MeshComponent->SetLeaderPoseComponent(Cast<ACharacter>(GetOwner())->GetMesh());
|
||||
}
|
||||
|
||||
UClothingItem* ClothingItem = ClothingItemInstance->GetClothingItem();
|
||||
if (ClothingItem->SlotType == EClothingSlotType::Bodysuit)
|
||||
{
|
||||
DropClothing(EClothingSlotType::Top);
|
||||
DropClothing(EClothingSlotType::Bottom);
|
||||
DropClothing(EClothingSlotType::UnderwearTop);
|
||||
DropClothing(EClothingSlotType::UnderwearBottom);
|
||||
}
|
||||
else if (ClothingItem->SlotType == EClothingSlotType::Top ||
|
||||
ClothingItem->SlotType == EClothingSlotType::Bottom ||
|
||||
ClothingItem->SlotType == EClothingSlotType::UnderwearTop ||
|
||||
ClothingItem->SlotType == EClothingSlotType::UnderwearBottom)
|
||||
{
|
||||
DropClothing(EClothingSlotType::Bodysuit);
|
||||
}
|
||||
|
||||
OnClothingEquip.Broadcast(ClothingItemInstance);
|
||||
}
|
||||
@@ -125,6 +153,16 @@ void UClothingManager::TakeClothing(UClothingItemInstance* ClothingItemInstance)
|
||||
|
||||
ClothingSlotData.ClothingItemInstance = ClothingItemInstance;
|
||||
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
FItemSaveRecord ItemSaveRecord;
|
||||
ItemSaveRecord.Init(ClothingItemInstance);
|
||||
|
||||
SaveSubsystem->GetCurrentSave()->EquippedItems.Push(ItemSaveRecord);
|
||||
SaveSubsystem->GetCurrentSave()->DroppedItems.RemoveAll([ClothingItemInstance](const FItemSaveRecord& Item)
|
||||
{
|
||||
return Item.InstanceId == ClothingItemInstance->GetInstanceId();
|
||||
});
|
||||
|
||||
PutOnClothing(ClothingItemInstance);
|
||||
}
|
||||
|
||||
@@ -149,6 +187,12 @@ UClothingItemInstance* UClothingManager::RemoveClothing(const EClothingSlotType
|
||||
}
|
||||
|
||||
OnClothingUnequip.Broadcast(ClothingItemInstance);
|
||||
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
SaveSubsystem->GetCurrentSave()->EquippedItems.RemoveAll([ClothingItemInstance](const FItemSaveRecord& Item)
|
||||
{
|
||||
return Item.InstanceId == ClothingItemInstance->GetInstanceId();
|
||||
});
|
||||
|
||||
return ClothingItemInstance;
|
||||
}
|
||||
@@ -158,6 +202,11 @@ void UClothingManager::DropClothing(const EClothingSlotType ClothingType)
|
||||
const UClothingItemInstance* ClothingItemInstance = RemoveClothing(ClothingType);
|
||||
if (!ClothingItemInstance)
|
||||
return;
|
||||
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
FItemSaveRecord ItemSaveRecord;
|
||||
ItemSaveRecord.Init(ClothingItemInstance);
|
||||
SaveSubsystem->GetCurrentSave()->DroppedItems.Push(ItemSaveRecord);
|
||||
|
||||
OnClothingDropped.Broadcast(ClothingItemInstance);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ class NAKEDDESIRE_API UClothingManager : public UActorComponent
|
||||
|
||||
public:
|
||||
UClothingManager();
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "Clothing Manager|Clothing")
|
||||
USkeletalMeshComponent* RootMesh = nullptr;
|
||||
@@ -36,7 +38,6 @@ public:
|
||||
|
||||
UPROPERTY(BlueprintAssignable)
|
||||
FOnClothingChangeSignature OnClothingDropped;
|
||||
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void PutOnClothing(UClothingItemInstance* ClothingItemInstance);
|
||||
@@ -68,7 +69,7 @@ public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
TArray<UClothingItemInstance*> GetEquippedClothing();
|
||||
|
||||
void HydrateClothing(UGlobalSaveGameData* SaveGameData);
|
||||
void HydrateClothing();
|
||||
|
||||
UFUNCTION(BlueprintPure)
|
||||
float GetHeelHeight();
|
||||
|
||||
@@ -14,7 +14,7 @@ enum class EClothingSlotType : uint8
|
||||
Neck,
|
||||
Face,
|
||||
Eyes,
|
||||
BodySuit,
|
||||
Bodysuit,
|
||||
Top,
|
||||
Bottom,
|
||||
UnderwearTop,
|
||||
|
||||
Reference in New Issue
Block a user