I’m using this to try hide/show my menu.
But it seems the is triggering input after the UI did (they both look for the same key) making the menu show up again…
If I change the UI key it will work fine, I can also hack it kindof by holding down the key for a bit.
This is the code I’m using atm, can someone tell me what I am doing wrong?
Thanks!
// IN UI
FReply UPlayerMenu::NativeOnKeyDown(const FGeometry & InGeometry, const FKeyEvent & InKeyEvent)
{
if (InKeyEvent.GetCharacter() == 'I')
{
printc("Close Menu", Blue);
ALPlayerController* PC = (ALPlayerController*)GetWorld()->GetFirstPlayerController();
PC->TogglePlayerMenu();
return FReply::Handled();
}
return FReply::Unhandled();
}
// IN PC
void ALPlayerController::TogglePlayerMenu()
{
APlayerHUD* PlayerHUD = (APlayerHUD*)GetHUD();
if (PlayerHUD->ActiveMenu == EActiveMenu::AE_None)
{
printc("Show menu", Cyan);
PlayerHUD->ShowInventory();
}
else
{
printc("Hide menu", Cyan);
PlayerHUD->HideInventory();
}
}
// IN PlayerHUD
void APlayerHUD::ShowInventory()
{
printc("Drawing PlayerUI", Green);
if (InventoryMenuClass)
{
printc("Show menu", Green);
VisibleUI->AddToViewport();
ActiveMenu = EActiveMenu::AE_Inventory;
FInputModeUIOnly Mode;
Mode.SetWidgetToFocus(VisibleUI->GetCachedWidget());
GetWorld()->GetFirstPlayerController()->SetInputMode(Mode);
GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true;
}
}
void APlayerHUD::HideInventory()
{
if (InventoryMenuClass)
{
VisibleUI->RemoveFromViewport();
ActiveMenu = EActiveMenu::AE_None;
FInputModeGameOnly GameMode;
GetWorld()->GetFirstPlayerController()->SetInputMode(GameMode);
GetWorld()->GetFirstPlayerController()->bShowMouseCursor = false;
}
}