I have a simple inventory system which pops up from the side of the screen. I want the player to be able to drag items out of the inventory and drop them over other objects in the world. I also need a single click on the inventory items to start an item examination mode.
I’ve put my code for the mouse down and drag detected functions below. The DragDetected fires as expected but I don’t know the correct way to do something else (the PlayerCharacter-> line) if drag WASN’T detected. Can someone point me in the right direction please?
FReply UPGInventoryItemWidget::NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
// Check whether a drag action was initiated with any of our "Interact" action mappings.
auto InteractMappingDragged = GetPlayerContext().GetPlayerController()->PlayerInput->ActionMappings.FindByPredicate(
[InMouseEvent](auto& Mapping)
{
return Mapping.ActionName == FName("Interact")
&& Mapping.Key == InMouseEvent.GetEffectingButton();
});
if (InteractMappingDragged)
{
// Do this if dragged.
return UWidgetBlueprintLibrary::DetectDragIfPressed(InMouseEvent, this, InMouseEvent.GetEffectingButton()).NativeReply;
}
else
{
// Do this if just clicked but not dragged.
PlayerCharacter->ExamineActorFromInventory(InventoryItem->GetOwner());
return Super::NativeOnMouseButtonDown(InGeometry, InMouseEvent);
}
}
void UPGInventoryItemWidget::NativeOnDragDetected(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent,
UDragDropOperation*& OutOperation)
{
UE_LOG(LogPGUI, Warning, TEXT("Drag detected"));
Super::NativeOnDragDetected(InGeometry, InMouseEvent, OutOperation);
}