Bugfix Focus Issues in Inventory & Able to Open Inventory in Shop

Able to consistently open & close the inventory without losing focus on root widget
This commit is contained in:
Philip W 2023-05-21 15:19:18 +01:00
parent 89282de97c
commit 14f4ff4d35
16 changed files with 42 additions and 77 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/Levels/Build.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -24,11 +24,13 @@ void UEatableItems::Use(ATempCharacter* Character)
{ {
Character->Health = FMath::Clamp(Character->Health + 20, 0, 100); Character->Health = FMath::Clamp(Character->Health + 20, 0, 100);
Character->Inventory->RemoveItem(this); Character->Inventory->RemoveItem(this);
return;
} }
else if (Character->Health >= 100) else if (Character->Health >= 100)
{ {
UE_LOG(LogTemp, Display, TEXT("Health is full")); UE_LOG(LogTemp, Display, TEXT("Health is full"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Health is full")); GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Health is full"));
return;
} }
} }
@ -38,6 +40,7 @@ void UEatableItems::Use(ATempCharacter* Character)
StatusSystem->AddStatusEffect(NewObject<UStatusEffect>(Character, StrengthBuffStatusEffect)); StatusSystem->AddStatusEffect(NewObject<UStatusEffect>(Character, StrengthBuffStatusEffect));
UE_LOG(LogTemp, Display, TEXT("Damage Buffed")); UE_LOG(LogTemp, Display, TEXT("Damage Buffed"));
Character->Inventory->RemoveItem(this); Character->Inventory->RemoveItem(this);
return;
} }
if (isProbertiumType) if (isProbertiumType)
@ -49,6 +52,7 @@ void UEatableItems::Use(ATempCharacter* Character)
TurnBaseCombat->ProbertiumResource = FMath::Clamp(TurnBaseCombat->ProbertiumResource + 2, 0, 20); TurnBaseCombat->ProbertiumResource = FMath::Clamp(TurnBaseCombat->ProbertiumResource + 2, 0, 20);
Character->Inventory->RemoveItem(this); Character->Inventory->RemoveItem(this);
} }
return;
} }
if (isEisType) if (isEisType)
@ -60,6 +64,7 @@ void UEatableItems::Use(ATempCharacter* Character)
TurnBaseCombat->EisResource = FMath::Clamp(TurnBaseCombat->EisResource + 2, 0, 20); TurnBaseCombat->EisResource = FMath::Clamp(TurnBaseCombat->EisResource + 2, 0, 20);
Character->Inventory->RemoveItem(this); Character->Inventory->RemoveItem(this);
} }
return;
} }
if (isAzosType) if (isAzosType)
@ -71,6 +76,7 @@ void UEatableItems::Use(ATempCharacter* Character)
TurnBaseCombat->AzosResource = FMath::Clamp(TurnBaseCombat->AzosResource + 2, 0, 20); TurnBaseCombat->AzosResource = FMath::Clamp(TurnBaseCombat->AzosResource + 2, 0, 20);
Character->Inventory->RemoveItem(this); Character->Inventory->RemoveItem(this);
} }
return;
} }
if (isIroquoidType) if (isIroquoidType)

View File

@ -90,18 +90,9 @@ void AInteraction::RemoveWidget()
//Character & Camera refs //Character & Camera refs
TempCharacterRef = Cast<ATempCharacter>(GetWorld()->GetFirstPlayerController()->GetCharacter()); TempCharacterRef = Cast<ATempCharacter>(GetWorld()->GetFirstPlayerController()->GetCharacter());
MainCamera = Cast<UCameraComponent>(TempCharacterRef->FindComponentByClass<UCameraComponent>()); MainCamera = Cast<UCameraComponent>(TempCharacterRef->FindComponentByClass<UCameraComponent>());
TempCharacterRef->bShopKeeperText = true;
bDisableShopDialMove = true; bDisableShopDialMove = true;
bisDisabled = true; bisDisabled = true;
//Setting ShopWidgetText back to hidden
// ShopDialogWidget->SetVisibility(ESlateVisibility::Hidden);
// if (ShopDialogWidget->IsVisible())
// {
// return;
// }
// else
// {
// UE_LOG(LogTemp, Display, TEXT("You cant open this widget when this widget is open"));
// }
UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true")); UE_LOG(LogTemp, Display, TEXT("setting isDisabled to true"));
Cast<UQuestSystem>(GetWorld()->GetFirstPlayerController()->GetCharacter()->GetComponentByClass(UQuestSystem::StaticClass()))->QuestWidgetInstance->SetVisibility(ESlateVisibility::Hidden); Cast<UQuestSystem>(GetWorld()->GetFirstPlayerController()->GetCharacter()->GetComponentByClass(UQuestSystem::StaticClass()))->QuestWidgetInstance->SetVisibility(ESlateVisibility::Hidden);
if (Property == nullptr) if (Property == nullptr)
@ -208,9 +199,10 @@ void AInteraction::ExitScreen()
} }
else else
{ {
TempCharacterRef->InputEnabler();
ItemSelectorWidget->SetVisibility(ESlateVisibility::Hidden); ItemSelectorWidget->SetVisibility(ESlateVisibility::Hidden);
Cast<UQuestSystem>(GetWorld()->GetFirstPlayerController()->GetCharacter()->GetComponentByClass(UQuestSystem::StaticClass()))->QuestWidgetInstance->SetVisibility(ESlateVisibility::HitTestInvisible); Cast<UQuestSystem>(GetWorld()->GetFirstPlayerController()->GetCharacter()->GetComponentByClass(UQuestSystem::StaticClass()))->QuestWidgetInstance->SetVisibility(ESlateVisibility::HitTestInvisible);
TempCharacterRef->bShopKeeperText = false;
TempCharacterRef->InputEnabler();
} }
} }

View File

@ -45,7 +45,7 @@ public:
UPROPERTY() UPROPERTY()
UUserWidget* ShopDialogWidget; UUserWidget* ShopDialogWidget;
UPROPERTY() UPROPERTY(BlueprintReadOnly)
UUserWidget* ItemSelectorWidget; UUserWidget* ItemSelectorWidget;
UPROPERTY() UPROPERTY()

View File

@ -147,12 +147,12 @@ void ATempCharacter::LineTraceLogic()
{ {
return; return;
} }
if(OutHit.GetActor()->ActorHasTag(TEXT("Probertium"))) if (OutHit.GetActor()->ActorHasTag(TEXT("Probertium")))
{ {
AddToInventory(); AddToInventory();
return; return;
} }
if(OutHit.GetActor()->ActorHasTag(TEXT("Iroquid"))) if (OutHit.GetActor()->ActorHasTag(TEXT("Iroquid")))
{ {
AddToInventory(); AddToInventory();
return; return;
@ -184,38 +184,12 @@ void ATempCharacter::LineTraceLogic()
} }
// if the actor hit has the interaction component/script then it will activate the code // if the actor hit has the interaction component/script then it will activate the code
if (AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor())) if (const AInteraction* MyInteractable = Cast<AInteraction>(OutHit.GetActor()))
{ {
if (MyInteractable->ShopDialogWidget->IsVisible()) if (MyInteractable->ShopDialogWidget->IsVisible())
{ {
UE_LOG(LogTemp, Display, TEXT("ShopKeeper text is visible")); UE_LOG(LogTemp, Display, TEXT("ShopKeeper text is visible"));
bShopKeeperText = true; bShopKeeperText = true;
return;
}
//if there is no text on screen this triggers
else
{
if (MyInteractable->ItemSelectorWidget->IsVisible())
{
return;
}
else
{
//DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
// MyInteractable->OnInteract();
// UE_LOG(LogTemp, Display, TEXT("OnInteract activated"));
// UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
//
// // While loop to check bisDisabled var until it changes to true
// while (MyInteractable->bisDisabled == false || MyInteractable->bDisableShopDialMove == false)
// {
// if (MyInteractable->bisDisabled == true || MyInteractable->bDisableShopDialMove == true)
// {
// InputDisabler();
// break;
// }
// }
}
} }
} }
} }
@ -243,19 +217,16 @@ void ATempCharacter::AddToInventory()
void ATempCharacter::InputDisabler() void ATempCharacter::InputDisabler()
{ {
//Disable Character Movement
if (ACharacter* PlayerCharacter = Cast<ACharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
{
PlayerCharacter->DisableInput(GetWorld()->GetFirstPlayerController());
}
//TURNING OFF CROSSHAIR //TURNING OFF CROSSHAIR
CrossHairWidget->SetVisibility(ESlateVisibility::Hidden); CrossHairWidget->SetVisibility(ESlateVisibility::Hidden);
//Set to UI Mode Only //Set to UI Mode Only
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController(); APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->SetInputMode(FInputModeUIOnly()); PlayerController->SetInputMode(FInputModeGameAndUI());
PlayerController->bShowMouseCursor = true; PlayerController->bShowMouseCursor = true;
PlayerController->SetIgnoreMoveInput(true);
PlayerController->SetIgnoreLookInput(true);
disableTab = true; disableTab = true;
if (ThisCamera != nullptr) if (ThisCamera != nullptr)
@ -269,18 +240,20 @@ void ATempCharacter::InputDisabler()
void ATempCharacter::InputEnabler() void ATempCharacter::InputEnabler()
{ {
//Enable Character Movement
if (ACharacter* PlayerCharacter = Cast<ACharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
{
PlayerCharacter->EnableInput(GetWorld()->GetFirstPlayerController());
}
//Reset UI Mode //Reset UI Mode
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController(); APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerController->SetInputMode(FInputModeGameOnly()); PlayerController->SetInputMode(FInputModeGameOnly());
PlayerController->bShowMouseCursor = false; PlayerController->bShowMouseCursor = false;
PlayerController->SetIgnoreMoveInput(false); PlayerController->SetIgnoreMoveInput(false);
PlayerController->SetIgnoreLookInput(false); PlayerController->SetIgnoreLookInput(false);
CrossHairWidget->SetVisibility(ESlateVisibility::HitTestInvisible);
//Enable Character Movement
if (ACharacter* PlayerCharacter = Cast<ACharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
{
PlayerCharacter->EnableInput(GetWorld()->GetFirstPlayerController());
}
UE_LOG(LogTemp, Display, TEXT("Enabling Inputs")); UE_LOG(LogTemp, Display, TEXT("Enabling Inputs"));
disableTab = true; disableTab = true;
TraceDistance = 300; TraceDistance = 300;
@ -326,5 +299,4 @@ void ATempCharacter::BuyItem(AActor* Item)
TraceDistance = 1000; TraceDistance = 1000;
LineTraceLogic(); LineTraceLogic();
} }
} }

View File

@ -94,6 +94,7 @@ public:
UFUNCTION(BlueprintCallable, Category= "Items") UFUNCTION(BlueprintCallable, Category= "Items")
void BuyItem(AActor* Item); void BuyItem(AActor* Item);
UPROPERTY(BlueprintReadOnly)
bool bShopKeeperText = false; bool bShopKeeperText = false;
UPROPERTY(BlueprintReadWrite) UPROPERTY(BlueprintReadWrite)