feat: add Hpbar, add RoundProgress
Hpbar - not working
This commit is contained in:
parent
672b19326b
commit
54396bc42c
Binary file not shown.
BIN
Content/Material/M_RoundProgressbar.uasset
Normal file
BIN
Content/Material/M_RoundProgressbar.uasset
Normal file
Binary file not shown.
BIN
Content/Material/M_RoundProgressbar_Inst.uasset
Normal file
BIN
Content/Material/M_RoundProgressbar_Inst.uasset
Normal file
Binary file not shown.
BIN
Content/Widget/WBP_HpBar.uasset
Normal file
BIN
Content/Widget/WBP_HpBar.uasset
Normal file
Binary file not shown.
BIN
Content/Widget/WBP_RoundProgressBar.uasset
Normal file
BIN
Content/Widget/WBP_RoundProgressBar.uasset
Normal file
Binary file not shown.
|
|
@ -9,7 +9,10 @@
|
|||
"Type": "Runtime",
|
||||
"LoadingPhase": "Default",
|
||||
"AdditionalDependencies": [
|
||||
"Engine"
|
||||
"Engine",
|
||||
"UMG",
|
||||
"Slate",
|
||||
"SlateCore"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
|
||||
#include "Characters/ExoPlayerCharacter.h"
|
||||
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "Characters/Components/ShootingComponent.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
#include "Items/AmmoBoxBase.h"
|
||||
|
|
@ -32,6 +34,20 @@ void AExoPlayerCharacter::BeginPlay()
|
|||
Super::BeginPlay();
|
||||
|
||||
GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &AExoPlayerCharacter::OnActorBeginOverlap);
|
||||
|
||||
|
||||
|
||||
if (PlayerHudClass)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1,5.0f,FColor::Green,TEXT("Jest klasa hudu playera"));
|
||||
PlayerHud = CreateWidget<UUserWidget>(GetWorld(),PlayerHudClass);
|
||||
if (PlayerHud)
|
||||
{
|
||||
PlayerHud->AddToViewport();
|
||||
PlayerHud->AddToPlayerScreen();
|
||||
GEngine->AddOnScreenDebugMessage(-1,5.0f,FColor::Green,TEXT("Dodaje to Viewportu"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AExoPlayerCharacter::OnActorBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
||||
|
|
|
|||
14
Source/Exo/Private/Widget/UWBP_HpBar.cpp
Normal file
14
Source/Exo/Private/Widget/UWBP_HpBar.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Widget/UWBP_HpBar.h"
|
||||
|
||||
#include "Components/ProgressBar.h"
|
||||
#include "Widget/UWBP_RoundProgressBar.h"
|
||||
|
||||
void UWBP_HpBar::SetHp(float hp, float hpMax)
|
||||
{
|
||||
if (!HPBar)
|
||||
return;
|
||||
HPBar->SetPercent(hp/hpMax);
|
||||
}
|
||||
35
Source/Exo/Private/Widget/UWBP_RoundProgressBar.cpp
Normal file
35
Source/Exo/Private/Widget/UWBP_RoundProgressBar.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Widget/UWBP_RoundProgressBar.h"
|
||||
#include "Components/Image.h"
|
||||
#include "Styling/SlateBrush.h"
|
||||
|
||||
|
||||
void UUWBP_RoundProgressBar::BeginDestroy()
|
||||
{
|
||||
Super::BeginDestroy();
|
||||
|
||||
}
|
||||
|
||||
void UUWBP_RoundProgressBar::SetPercent(float percent)
|
||||
{
|
||||
if (!DynamicMaterial)
|
||||
{
|
||||
if (!ImageBar)
|
||||
return;
|
||||
FSlateBrush brush= ImageBar->Brush;
|
||||
UMaterialInterface* material=Cast<UMaterialInterface>(brush.GetResourceObject());
|
||||
if (!material)
|
||||
return;
|
||||
DynamicMaterial = UMaterialInstanceDynamic::Create(material, this);
|
||||
if (DynamicMaterial)
|
||||
{
|
||||
FSlateBrush newBrush= brush;
|
||||
newBrush.SetResourceObject(DynamicMaterial);
|
||||
ImageBar->Brush = newBrush;
|
||||
}
|
||||
}
|
||||
if (DynamicMaterial)
|
||||
DynamicMaterial->SetScalarParameterValue("Percent",percent);
|
||||
}
|
||||
|
|
@ -54,6 +54,9 @@ public:
|
|||
UPROPERTY(EditAnywhere, Category = "Health")
|
||||
float CurrentHealth = 50.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UI")
|
||||
TSubclassOf<UUserWidget> PlayerHudClass;
|
||||
|
||||
UFUNCTION()
|
||||
void OnActorBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
||||
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult
|
||||
|
|
@ -66,4 +69,6 @@ protected:
|
|||
virtual void BeginPlay() override;
|
||||
|
||||
float MaxHealth = 100.0f;
|
||||
|
||||
UUserWidget* PlayerHud;
|
||||
};
|
||||
|
|
|
|||
22
Source/Exo/Public/Widget/UWBP_HpBar.h
Normal file
22
Source/Exo/Public/Widget/UWBP_HpBar.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "UWBP_HpBar.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class UWBP_HpBar : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
|
||||
void SetHp(float hp,float hpMax);
|
||||
|
||||
UPROPERTY(EditAnywhere, meta = (BindWidget))
|
||||
class UUWBP_RoundProgressBar* HPBar;
|
||||
};
|
||||
26
Source/Exo/Public/Widget/UWBP_RoundProgressBar.h
Normal file
26
Source/Exo/Public/Widget/UWBP_RoundProgressBar.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "UWBP_RoundProgressBar.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class EXO_API UUWBP_RoundProgressBar : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UMaterialInstanceDynamic* DynamicMaterial = nullptr;
|
||||
public:
|
||||
virtual void BeginDestroy() override;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SetPercent(float percent);
|
||||
|
||||
UPROPERTY(EditAnywhere, meta = (BindWidget))
|
||||
class UImage* ImageBar;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user