setup equipment ui

This commit is contained in:
koritsa
2026-05-27 16:20:10 +03:00
committed by koritsa
parent b161d021c4
commit 23f709bd61
134 changed files with 464 additions and 354 deletions
@@ -2,34 +2,88 @@
#include "EquipmentSlotWidget.h"
#include "Kismet/GameplayStatics.h"
#include "NakedDesire/Clothing/ClothingItem.h"
#include "NakedDesire/Clothing/ClothingItemInstance.h"
#include "NakedDesire/Clothing/ClothingManager.h"
#include "NakedDesire/Clothing/ClothingSlotsData.h"
#include "NakedDesire/Player/NakedDesireCharacter.h"
void UEquipmentSlotWidget::SetItem(UClothingItemInstance* InItem)
{
ClothingItemInstance = InItem;
IconImage->SetBrushFromTexture(InItem->GetClothingItem()->Icon);
IconImage->SetVisibility(ESlateVisibility::SelfHitTestInvisible);
SetIsEnabled(true);
}
void UEquipmentSlotWidget::ClearItem()
{
ClothingItemInstance = nullptr;
IconImage->SetBrushFromTexture(nullptr);
IconImage->SetVisibility(ESlateVisibility::Hidden);
SetIsEnabled(false);
}
void UEquipmentSlotWidget::NativeOnClicked()
{
Super::NativeOnClicked();
OnEquipmentSlotClicked.ExecuteIfBound(this);
}
void UEquipmentSlotWidget::NativePreConstruct()
{
Super::NativePreConstruct();
// if (!ClothingSlotsData->Slots.Contains(SlotType))
// return;
// FClothingSlotData& SlotData = ClothingSlotsData->Slots[SlotType];
// PlaceholderImage->SetBrushFromTexture(&SlotData.Icon);
InitSlotVisuals();
}
void UEquipmentSlotWidget::OnClothingEquip(UClothingItemInstance* InClothingItemInstance)
{
if (InClothingItemInstance->GetClothingItem()->SlotType != SlotType)
return;
SetItem(InClothingItemInstance);
}
void UEquipmentSlotWidget::OnClothingUnequip(UClothingItemInstance* InClothingItemInstance)
{
if (InClothingItemInstance->GetClothingItem()->SlotType != SlotType)
return;
ClearItem();
}
void UEquipmentSlotWidget::InitSlotVisuals()
{
if (!ClothingSlotsData)
return;
const FClothingSlotData& SlotData = ClothingSlotsData->Slots[SlotType];
PlaceholderImage->SetBrushFromTexture(SlotData.Icon);
}
void UEquipmentSlotWidget::SetSlotType(const EClothingSlotType InSlotType)
{
SlotType = InSlotType;
InitSlotVisuals();
}
void UEquipmentSlotWidget::NativeConstruct()
{
Super::NativeConstruct();
const ANakedDesireCharacter* Player = Cast<ANakedDesireCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
Player->ClothingManager->OnClothingEquip.AddUniqueDynamic(this, &UEquipmentSlotWidget::OnClothingEquip);
Player->ClothingManager->OnClothingUnequip.AddUniqueDynamic(this, &UEquipmentSlotWidget::OnClothingUnequip);
if (UClothingItemInstance* Item = Player->ClothingManager->GetSlotClothing(SlotType))
SetItem(Item);
else
ClearItem();
}