Added wardrobe
This commit is contained in:
@@ -2,38 +2,105 @@
|
||||
|
||||
|
||||
#include "Wardrobe.h"
|
||||
#include "Components/BoxComponent.h"
|
||||
#include "Components/WidgetComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "NakedDesire/Clothing/ClothingItemInstance.h"
|
||||
#include "NakedDesire/SaveGame/GlobalSaveGameData.h"
|
||||
#include "NakedDesire/SaveGame/ItemSaveRecord.h"
|
||||
#include "NakedDesire/SaveGame/SaveSubsystem.h"
|
||||
#include "NakedDesire/Global/NakedDesireHUD.h"
|
||||
#include "NakedDesire/Inventory/InventorySubsystem.h"
|
||||
#include "NakedDesire/Player/NakedDesireCharacter.h"
|
||||
#include "NakedDesire/UI/GameLayoutWidget.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "Wardrobe"
|
||||
|
||||
AWardrobe::AWardrobe()
|
||||
{
|
||||
ColliderComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("Collider"));
|
||||
SetRootComponent(ColliderComponent);
|
||||
// Trace-only: detected by the interaction LOS/focus line traces (ECC_Visibility),
|
||||
// transparent to movement and physics.
|
||||
ColliderComponent->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
||||
ColliderComponent->SetCollisionObjectType(ECC_WorldStatic);
|
||||
ColliderComponent->SetCollisionResponseToAllChannels(ECR_Ignore);
|
||||
ColliderComponent->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);
|
||||
|
||||
MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
|
||||
MeshComponent->SetupAttachment(RootComponent);
|
||||
// Movement blocker only: stops the character capsule (ECC_Pawn), but is invisible
|
||||
// to line traces so it never occludes the interaction LOS check.
|
||||
MeshComponent->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
||||
MeshComponent->SetCollisionObjectType(ECC_WorldStatic);
|
||||
MeshComponent->SetCollisionResponseToAllChannels(ECR_Ignore);
|
||||
MeshComponent->SetCollisionResponseToChannel(ECC_Pawn, ECR_Block);
|
||||
|
||||
InteractionHint = CreateDefaultSubobject<UWidgetComponent>(TEXT("Interaction Hint"));
|
||||
InteractionHint->SetupAttachment(RootComponent);
|
||||
}
|
||||
|
||||
void AWardrobe::Interact_Implementation(ANakedDesireCharacter* Player)
|
||||
{
|
||||
APlayerController* PC = Cast<APlayerController>(Player->GetController());
|
||||
if (!PC)
|
||||
return;
|
||||
|
||||
ANakedDesireHUD* HUD = Cast<ANakedDesireHUD>(PC->GetHUD());
|
||||
if (!HUD)
|
||||
return;
|
||||
|
||||
HUD->GetGameLayoutWidget()->OpenWardrobe();
|
||||
}
|
||||
|
||||
void AWardrobe::AddItem(UClothingItemInstance* ClothingItemInstance)
|
||||
{
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
SaveSubsystem->GetCurrentSave()->AddWardrobeItem(ClothingItemInstance);
|
||||
if (UInventorySubsystem* Inventory = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<UInventorySubsystem>())
|
||||
Inventory->AddToWardrobe(ClothingItemInstance);
|
||||
}
|
||||
|
||||
void AWardrobe::RemoveItem(UClothingItemInstance* ClothingItemInstance) const
|
||||
void AWardrobe::RemoveItem(UClothingItemInstance* ClothingItemInstance)
|
||||
{
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
|
||||
SaveSubsystem->GetCurrentSave()->RemoveWardrobeItem(ClothingItemInstance);
|
||||
if (UInventorySubsystem* Inventory = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<UInventorySubsystem>())
|
||||
Inventory->RemoveFromWardrobe(ClothingItemInstance);
|
||||
}
|
||||
|
||||
void AWardrobe::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
||||
UGlobalSaveGameData* SaveGame = SaveSubsystem->GetCurrentSave();
|
||||
|
||||
for (const FItemSaveRecord& ItemSaveRecord : SaveGame->GetWardrobeItems())
|
||||
{
|
||||
UClothingItemInstance* NewItemInstance = Cast<UClothingItemInstance>(UItemInstance::CreateFromRecord(this, ItemSaveRecord));
|
||||
if (!NewItemInstance)
|
||||
continue;
|
||||
|
||||
ClothingItems.Push(NewItemInstance);
|
||||
}
|
||||
InteractionHint->SetVisibility(false);
|
||||
}
|
||||
|
||||
bool AWardrobe::CanInteract_Implementation(ANakedDesireCharacter* Player) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
FText AWardrobe::GetInteractionPrompt_Implementation() const
|
||||
{
|
||||
return LOCTEXT("WardrobePrompt", "Open wardrobe");
|
||||
}
|
||||
|
||||
void AWardrobe::HideInteractionHint_Implementation()
|
||||
{
|
||||
ApplyOutline(false, 0);
|
||||
InteractionHint->SetVisibility(false);
|
||||
}
|
||||
|
||||
void AWardrobe::ShowInteractionFocusHint_Implementation()
|
||||
{
|
||||
ApplyOutline(true, 2);
|
||||
InteractionHint->SetVisibility(true);
|
||||
}
|
||||
|
||||
void AWardrobe::ShowInteractionProximityHint_Implementation()
|
||||
{
|
||||
ApplyOutline(true, 1);
|
||||
InteractionHint->SetVisibility(false);
|
||||
}
|
||||
|
||||
void AWardrobe::ApplyOutline(bool bEnabled, int32 StencilValue)
|
||||
{
|
||||
MeshComponent->SetRenderCustomDepth(bEnabled);
|
||||
MeshComponent->SetCustomDepthStencilValue(StencilValue);
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
Reference in New Issue
Block a user