feat: UI ammo, UI sight

This commit is contained in:
BambiTheLama 2025-05-08 17:46:09 +02:00
parent 4b1bbda092
commit acea2a0002
7 changed files with 66 additions and 12 deletions

Binary file not shown.

View File

@ -9,7 +9,8 @@
#include "Items/AmmoBoxBase.h"
#include "Items/HealthBoxBase.h"
#include "Player/InteractionComponent.h"
#include "Widget/UWBP_HpBar.h"
#include "Widget/WBP_PlayerUI.h"
AExoPlayerCharacter::AExoPlayerCharacter()
{
@ -38,18 +39,17 @@ void AExoPlayerCharacter::BeginPlay()
if (PlayerHudClass)
PlayerHud = CreateWidget<UWBP_PlayerUI>(GetWorld(),PlayerHudClass);
if (PlayerHud)
{
PlayerHud = CreateWidget<UUserWidget>(GetWorld(),PlayerHudClass);
PlayerHud->AddToViewport();
PlayerHud->AddToPlayerScreen();
if (PlayerHud)
{
PlayerHud->AddToViewport();
PlayerHud->AddToPlayerScreen();
UWBP_HpBar *HpBar=Cast<UWBP_HpBar>(PlayerHud);
if (HpBar)
HpBar->SetHp(CurrentHealth,MaxHealth);
}
PlayerHud->SetHp(CurrentHealth,MaxHealth);
PlayerHud->SetAmmo(10);
}
}
}
@ -91,4 +91,7 @@ void AExoPlayerCharacter::AddHealthPoints(float addValue)
if (CurrentHealth > MaxHealth)
CurrentHealth = MaxHealth;
if (PlayerHud)
PlayerHud->SetHp(CurrentHealth,MaxHealth);
}

View File

@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Widget/WBP_PlayerUI.h"
#include "Components/TextBlock.h"
#include "Widget/UWBP_HpBar.h"
void UWBP_PlayerUI::SetHp(float hp, float hpMax)
{
if (HPBar)
HPBar->SetHp(hp, hpMax);
}
void UWBP_PlayerUI::SetAmmo(int ammo)
{
if (AmmoText)
AmmoText->SetText(FText::AsNumber(ammo));
}

View File

@ -0,0 +1,30 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "WBP_PlayerUI.generated.h"
/**
*
*/
UCLASS()
class UWBP_PlayerUI : public UUserWidget
{
GENERATED_BODY()
public:
void SetHp(float hp,float hpMax);
void SetAmmo(int ammo);
UPROPERTY(EditAnywhere, meta = (BindWidget))
class UWBP_HpBar* HPBar;
UPROPERTY(EditAnywhere, meta = (BindWidget))
class UImage* AmmoImage;
UPROPERTY(EditAnywhere, meta = (BindWidget))
class UTextBlock* AmmoText;
};

View File

@ -9,6 +9,7 @@
class UInteractionComponent;
class UShootingComponent;
class UWBP_PlayerUI;
UCLASS()
class EXO_API AExoPlayerCharacter : public AExoCharacterBase
@ -56,7 +57,7 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UI")
TSubclassOf<UUserWidget> PlayerHudClass;
UFUNCTION()
void OnActorBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult
@ -70,5 +71,5 @@ protected:
float MaxHealth = 100.0f;
UUserWidget* PlayerHud;
UWBP_PlayerUI* PlayerHud;
};