86 lines
2.4 KiB
C++
86 lines
2.4 KiB
C++
// © 2025 Naked People Team. All Rights Reserved.
|
|
|
|
|
|
#include "ItemPickup.h"
|
|
#include "Components/BoxComponent.h"
|
|
#include "Components/WidgetComponent.h"
|
|
#include "Kismet/GameplayStatics.h"
|
|
#include "NakedDesire/Clothing/ClothingItem.h"
|
|
#include "NakedDesire/Clothing/ClothingItemInstance.h"
|
|
#include "NakedDesire/Clothing/ClothingManager.h"
|
|
#include "NakedDesire/Player/NakedDesireCharacter.h"
|
|
#include "NakedDesire/SaveGame/GlobalSaveGameData.h"
|
|
#include "NakedDesire/SaveGame/ItemSaveRecord.h"
|
|
#include "NakedDesire/SaveGame/SaveSubsystem.h"
|
|
|
|
AItemPickup::AItemPickup()
|
|
{
|
|
Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
|
|
SetRootComponent(Mesh);
|
|
Mesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
|
|
|
Collider = CreateDefaultSubobject<UBoxComponent>(TEXT("Collider"));
|
|
Collider->SetupAttachment(RootComponent);
|
|
Collider->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
|
|
|
|
InteractionHint = CreateDefaultSubobject<UWidgetComponent>(TEXT("Interaction Hint"));
|
|
InteractionHint->SetupAttachment(RootComponent);
|
|
}
|
|
|
|
void AItemPickup::Interact_Implementation(ANakedDesireCharacter* Player)
|
|
{
|
|
if (ClothingItemInstance)
|
|
{
|
|
USaveSubsystem* SaveSubsystem = UGameplayStatics::GetGameInstance(GetWorld())->GetSubsystem<USaveSubsystem>();
|
|
Player->ClothingManager->TakeClothing(ClothingItemInstance);
|
|
SaveSubsystem->GetCurrentSave()->WorldItems.RemoveAll([this](const FItemSaveRecord& Item)
|
|
{
|
|
return ClothingItemInstance->GetInstanceId() == Item.InstanceId;
|
|
});
|
|
Destroy();
|
|
}
|
|
}
|
|
|
|
bool AItemPickup::CanInteract_Implementation(ANakedDesireCharacter* Player) const
|
|
{
|
|
return ClothingItemInstance != nullptr;
|
|
}
|
|
|
|
void AItemPickup::HideInteractionHint_Implementation()
|
|
{
|
|
ApplyOutline(Mesh, false, 0);
|
|
InteractionHint->SetVisibility(false);
|
|
}
|
|
|
|
void AItemPickup::ShowInteractionFocusHint_Implementation()
|
|
{
|
|
ApplyOutline(Mesh, true, 2);
|
|
InteractionHint->SetVisibility(true);
|
|
}
|
|
|
|
void AItemPickup::ShowInteractionProximityHint_Implementation()
|
|
{
|
|
ApplyOutline(Mesh, true, 1);
|
|
InteractionHint->SetVisibility(false);
|
|
}
|
|
|
|
void AItemPickup::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
InteractionHint->SetVisibility(false);
|
|
}
|
|
|
|
void AItemPickup::SetItem(UClothingItemInstance* InItem)
|
|
{
|
|
ClothingItemInstance = InItem;
|
|
|
|
Mesh->SetStaticMesh(InItem->GetClothingItem()->StaticMesh);
|
|
}
|
|
|
|
void AItemPickup::ApplyOutline(UStaticMeshComponent* InMesh, bool bEnabled, int32 StencilValue)
|
|
{
|
|
InMesh->SetRenderCustomDepth(bEnabled);
|
|
InMesh->SetCustomDepthStencilValue(StencilValue);
|
|
}
|