feat: UI ammo, UI sight
This commit is contained in:
parent
4b1bbda092
commit
acea2a0002
Binary file not shown.
Binary file not shown.
BIN
Content/Widget/WBP_PlayerUI.uasset
Normal file
BIN
Content/Widget/WBP_PlayerUI.uasset
Normal file
Binary file not shown.
|
|
@ -9,7 +9,8 @@
|
||||||
#include "Items/AmmoBoxBase.h"
|
#include "Items/AmmoBoxBase.h"
|
||||||
#include "Items/HealthBoxBase.h"
|
#include "Items/HealthBoxBase.h"
|
||||||
#include "Player/InteractionComponent.h"
|
#include "Player/InteractionComponent.h"
|
||||||
#include "Widget/UWBP_HpBar.h"
|
#include "Widget/WBP_PlayerUI.h"
|
||||||
|
|
||||||
|
|
||||||
AExoPlayerCharacter::AExoPlayerCharacter()
|
AExoPlayerCharacter::AExoPlayerCharacter()
|
||||||
{
|
{
|
||||||
|
|
@ -38,17 +39,16 @@ void AExoPlayerCharacter::BeginPlay()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (PlayerHudClass)
|
PlayerHud = CreateWidget<UWBP_PlayerUI>(GetWorld(),PlayerHudClass);
|
||||||
{
|
|
||||||
PlayerHud = CreateWidget<UUserWidget>(GetWorld(),PlayerHudClass);
|
|
||||||
if (PlayerHud)
|
if (PlayerHud)
|
||||||
{
|
{
|
||||||
PlayerHud->AddToViewport();
|
PlayerHud->AddToViewport();
|
||||||
PlayerHud->AddToPlayerScreen();
|
PlayerHud->AddToPlayerScreen();
|
||||||
UWBP_HpBar *HpBar=Cast<UWBP_HpBar>(PlayerHud);
|
|
||||||
if (HpBar)
|
|
||||||
HpBar->SetHp(CurrentHealth,MaxHealth);
|
|
||||||
|
|
||||||
|
if (PlayerHud)
|
||||||
|
{
|
||||||
|
PlayerHud->SetHp(CurrentHealth,MaxHealth);
|
||||||
|
PlayerHud->SetAmmo(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -91,4 +91,7 @@ void AExoPlayerCharacter::AddHealthPoints(float addValue)
|
||||||
|
|
||||||
if (CurrentHealth > MaxHealth)
|
if (CurrentHealth > MaxHealth)
|
||||||
CurrentHealth = MaxHealth;
|
CurrentHealth = MaxHealth;
|
||||||
|
|
||||||
|
if (PlayerHud)
|
||||||
|
PlayerHud->SetHp(CurrentHealth,MaxHealth);
|
||||||
}
|
}
|
||||||
20
Source/Exo/Private/Widget/WBP_PlayerUI.cpp
Normal file
20
Source/Exo/Private/Widget/WBP_PlayerUI.cpp
Normal 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));
|
||||||
|
}
|
||||||
|
|
||||||
30
Source/Exo/Private/Widget/WBP_PlayerUI.h
Normal file
30
Source/Exo/Private/Widget/WBP_PlayerUI.h
Normal 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;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
class UInteractionComponent;
|
class UInteractionComponent;
|
||||||
class UShootingComponent;
|
class UShootingComponent;
|
||||||
|
class UWBP_PlayerUI;
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class EXO_API AExoPlayerCharacter : public AExoCharacterBase
|
class EXO_API AExoPlayerCharacter : public AExoCharacterBase
|
||||||
|
|
@ -70,5 +71,5 @@ protected:
|
||||||
|
|
||||||
float MaxHealth = 100.0f;
|
float MaxHealth = 100.0f;
|
||||||
|
|
||||||
UUserWidget* PlayerHud;
|
UWBP_PlayerUI* PlayerHud;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user