diff --git a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset index 031c2b8..bf75664 100644 Binary files a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset and b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset differ diff --git a/Content/Material/M_RoundProgressbar.uasset b/Content/Material/M_RoundProgressbar.uasset new file mode 100644 index 0000000..69fc3ae Binary files /dev/null and b/Content/Material/M_RoundProgressbar.uasset differ diff --git a/Content/Material/M_RoundProgressbar_Inst.uasset b/Content/Material/M_RoundProgressbar_Inst.uasset new file mode 100644 index 0000000..a6879e5 Binary files /dev/null and b/Content/Material/M_RoundProgressbar_Inst.uasset differ diff --git a/Content/Widget/WBP_HpBar.uasset b/Content/Widget/WBP_HpBar.uasset new file mode 100644 index 0000000..221b145 Binary files /dev/null and b/Content/Widget/WBP_HpBar.uasset differ diff --git a/Content/Widget/WBP_RoundProgressBar.uasset b/Content/Widget/WBP_RoundProgressBar.uasset new file mode 100644 index 0000000..7ac5cd2 Binary files /dev/null and b/Content/Widget/WBP_RoundProgressBar.uasset differ diff --git a/Exo.uproject b/Exo.uproject index 43682e8..da85ef5 100644 --- a/Exo.uproject +++ b/Exo.uproject @@ -9,7 +9,10 @@ "Type": "Runtime", "LoadingPhase": "Default", "AdditionalDependencies": [ - "Engine" + "Engine", + "UMG", + "Slate", + "SlateCore" ] } ], diff --git a/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp b/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp index 53999db..40468db 100644 --- a/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp +++ b/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp @@ -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(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, diff --git a/Source/Exo/Private/Widget/UWBP_HpBar.cpp b/Source/Exo/Private/Widget/UWBP_HpBar.cpp new file mode 100644 index 0000000..bf32830 --- /dev/null +++ b/Source/Exo/Private/Widget/UWBP_HpBar.cpp @@ -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); +} diff --git a/Source/Exo/Private/Widget/UWBP_RoundProgressBar.cpp b/Source/Exo/Private/Widget/UWBP_RoundProgressBar.cpp new file mode 100644 index 0000000..0404096 --- /dev/null +++ b/Source/Exo/Private/Widget/UWBP_RoundProgressBar.cpp @@ -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(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); +} diff --git a/Source/Exo/Public/Characters/ExoPlayerCharacter.h b/Source/Exo/Public/Characters/ExoPlayerCharacter.h index 52e5b70..5e2d756 100644 --- a/Source/Exo/Public/Characters/ExoPlayerCharacter.h +++ b/Source/Exo/Public/Characters/ExoPlayerCharacter.h @@ -54,6 +54,9 @@ public: UPROPERTY(EditAnywhere, Category = "Health") float CurrentHealth = 50.0f; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UI") + TSubclassOf 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; }; diff --git a/Source/Exo/Public/Widget/UWBP_HpBar.h b/Source/Exo/Public/Widget/UWBP_HpBar.h new file mode 100644 index 0000000..aa67363 --- /dev/null +++ b/Source/Exo/Public/Widget/UWBP_HpBar.h @@ -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; +}; diff --git a/Source/Exo/Public/Widget/UWBP_RoundProgressBar.h b/Source/Exo/Public/Widget/UWBP_RoundProgressBar.h new file mode 100644 index 0000000..8970d2d --- /dev/null +++ b/Source/Exo/Public/Widget/UWBP_RoundProgressBar.h @@ -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; +};