I want to implement DragDrop inventory. I have
InventoryWidget
class that have 16
InventoryItemSlotWidget
representing slots in inventory. In InventoryItemSlotWidget I created 3 methods:
.h:
virtual FEventReply OnMouseButtonDown(FGeometry MyGeometry, const FPointerEvent& MouseEvent);
virtual void OnDragCancelled(const FPointerEvent& PointerEvent, UDragDropOperation* Operation);
void virtual NativeOnDragDetected(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent, UDragDropOperation*& OutOperation);
.cpp:
FEventReply UInventoryItemSlotWidget_Class::OnMouseButtonDown(FGeometry MyGeometry, const FPointerEvent& MouseEvent)
{
Super::OnMouseButtonDown(MyGeometry, MouseEvent);
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Green, TEXT("Drag: OnMouseButtonDown"));
return UWidgetBlueprintLibrary::DetectDragIfPressed(MouseEvent, this, OnMouseDownDetectKey);
}
void UInventoryItemSlotWidget_Class::OnDragCancelled(const FPointerEvent& PointerEvent, UDragDropOperation* Operation)
{
Super::OnDragCancelled(PointerEvent, Operation);
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Green, TEXT("Drag: OnDragCancelled"));
TArray<UUserWidget*> InventoryWidgets;
UWidgetBlueprintLibrary::GetAllWidgetsOfClass(GetWorld(), InventoryWidgets, UInventoryWidget_Class::StaticClass());
Cast<UInventoryWidget_Class>(InventoryWidgets[0])->SetGrid();
}
void UInventoryItemSlotWidget_Class::NativeOnDragDetected(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent, UDragDropOperation*& OutOperation)
{
Super::NativeOnDragDetected(InGeometry, InMouseEvent, OutOperation);
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Green, TEXT("Drag: NativeOnDragDetected"));
if (SlotData.Quantity > 0) {
ItemImage->SetBrushColor(FLinearColor::Transparent);
ItemQuantity->SetText(FText());
// ---
UInventoryItemSlotWidget_Class* TemporaryWidget = CreateWidget<UInventoryItemSlotWidget_Class>(GetWorld(), InventoryItemBlueprintClass);
TemporaryWidget->SlotData = SlotData;
TemporaryWidget->Index = Index;
UInventoryDragDropOperation_Class* DragDropOperation = Cast<UInventoryDragDropOperation_Class>(UWidgetBlueprintLibrary::CreateDragDropOperation(UInventoryDragDropOperation_Class::StaticClass()));
DragDropOperation->InventoryItem = SlotData;
DragDropOperation->Index = Index;
}
}
but when I try to drag slot nothing is happend. If it helps I follow tutorial https://youtu.be/HuR3xNmIkeY?si=7bR1C8_K7ygIfEt5 4:20