diff --git a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset index 2088f19..e401763 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/Levels/TestMap.umap b/Content/Levels/TestMap.umap index 17119ce..04c8b38 100644 Binary files a/Content/Levels/TestMap.umap and b/Content/Levels/TestMap.umap differ diff --git a/Content/Widget/WBP_Debuf.uasset b/Content/Widget/WBP_Debuf.uasset new file mode 100644 index 0000000..020ebda Binary files /dev/null and b/Content/Widget/WBP_Debuf.uasset differ diff --git a/Content/Widget/WBP_HpBar.uasset b/Content/Widget/WBP_HpBar.uasset deleted file mode 100644 index e769a46..0000000 Binary files a/Content/Widget/WBP_HpBar.uasset and /dev/null differ diff --git a/Content/Widget/WBP_PlayerUI.uasset b/Content/Widget/WBP_PlayerUI.uasset index 7a968b5..0389e30 100644 Binary files a/Content/Widget/WBP_PlayerUI.uasset and b/Content/Widget/WBP_PlayerUI.uasset differ diff --git a/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp b/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp index e60497c..6180334 100644 --- a/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp +++ b/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp @@ -48,7 +48,10 @@ void AExoPlayerCharacter::BeginPlay() if (PlayerHud) { PlayerHud->SetHp(CurrentHealth,MaxHealth); - PlayerHud->SetAmmo(10); + PlayerHud->SetAmmoNumber(10); + PlayerHud->SetAmmoType(EAmmoType::Revolver); + for (int i=0;i<4;i++) + PlayerHud->AddDebuf(NULL,0.25f*i); } } } diff --git a/Source/Exo/Private/Widget/UWBP_Debuf.cpp b/Source/Exo/Private/Widget/UWBP_Debuf.cpp new file mode 100644 index 0000000..8e3c578 --- /dev/null +++ b/Source/Exo/Private/Widget/UWBP_Debuf.cpp @@ -0,0 +1,25 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Widget/UWBP_Debuf.h" + +#include "Components/Image.h" +#include "Widget/UWBP_RoundProgressBar.h" + +void UUWBP_Debuf::SetTexture(UTexture2D* texture) +{ + if (!DebufImage) + return; + FSlateBrush NewBrush; + if (!texture) + return; + NewBrush.SetResourceObject(texture); + NewBrush.ImageSize = FVector2D(64, 64); + DebufImage->SetBrush(NewBrush); +} + +void UUWBP_Debuf::SetPrecent(float precent) +{ + if (ProgressBar) + ProgressBar->SetPercent(precent); +} diff --git a/Source/Exo/Private/Widget/WBP_PlayerUI.h b/Source/Exo/Private/Widget/UWBP_Debuf.h similarity index 52% rename from Source/Exo/Private/Widget/WBP_PlayerUI.h rename to Source/Exo/Private/Widget/UWBP_Debuf.h index dce0020..88d1597 100644 --- a/Source/Exo/Private/Widget/WBP_PlayerUI.h +++ b/Source/Exo/Private/Widget/UWBP_Debuf.h @@ -4,27 +4,23 @@ #include "CoreMinimal.h" #include "Blueprint/UserWidget.h" -#include "WBP_PlayerUI.generated.h" +#include "UWBP_Debuf.generated.h" /** * */ UCLASS() -class UWBP_PlayerUI : public UUserWidget +class UUWBP_Debuf : public UUserWidget { GENERATED_BODY() public: - void SetHp(float hp,float hpMax); - - void SetAmmo(int ammo); + UPROPERTY(EditAnywhere, meta = (BindWidget)) + class UUWBP_RoundProgressBar* ProgressBar; UPROPERTY(EditAnywhere, meta = (BindWidget)) - class UWBP_HpBar* HPBar; + class UImage* DebufImage; - UPROPERTY(EditAnywhere, meta = (BindWidget)) - class UImage* AmmoImage; + void SetTexture(UTexture2D* texture); - UPROPERTY(EditAnywhere, meta = (BindWidget)) - class UTextBlock* AmmoText; - + void SetPrecent(float precent); }; diff --git a/Source/Exo/Private/Widget/UWBP_HpBar.cpp b/Source/Exo/Private/Widget/UWBP_HpBar.cpp deleted file mode 100644 index bf32830..0000000 --- a/Source/Exo/Private/Widget/UWBP_HpBar.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// 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/WBP_PlayerUI.cpp b/Source/Exo/Private/Widget/WBP_PlayerUI.cpp index fbb26b5..78442fd 100644 --- a/Source/Exo/Private/Widget/WBP_PlayerUI.cpp +++ b/Source/Exo/Private/Widget/WBP_PlayerUI.cpp @@ -3,18 +3,66 @@ #include "Widget/WBP_PlayerUI.h" +#include "UWBP_Debuf.h" +#include "Blueprint/WidgetTree.h" +#include "Components/CanvasPanel.h" +#include "Components/CanvasPanelSlot.h" +#include "Components/Image.h" #include "Components/TextBlock.h" -#include "Widget/UWBP_HpBar.h" +#include "Widget/UWBP_RoundProgressBar.h" void UWBP_PlayerUI::SetHp(float hp, float hpMax) { - if (HPBar) - HPBar->SetHp(hp, hpMax); + if (!HPBar) + return; + HPBar->SetPercent(hp/hpMax); } -void UWBP_PlayerUI::SetAmmo(int ammo) +void UWBP_PlayerUI::SetAmmoType(EAmmoType ammoType) +{ + if (!AmmoImage) + return; + FSlateBrush NewBrush; + if (!AmmoIconMap.Contains(ammoType)) + return; + UTexture2D* IconTexture = AmmoIconMap[ammoType]; + if (!IconTexture) + return; + NewBrush.SetResourceObject(IconTexture); + NewBrush.ImageSize = FVector2D(64, 64); + AmmoImage->SetBrush(NewBrush); +} + +void UWBP_PlayerUI::SetAmmoNumber(int ammo) { if (AmmoText) AmmoText->SetText(FText::AsNumber(ammo)); } +void UWBP_PlayerUI::AddDebuf(UTexture2D* texture, float procent) +{ + if (!DebufClass) + return; + if (!DebufPanel) + return; + + UUWBP_Debuf* NewDebuf = WidgetTree->ConstructWidget(DebufClass, FName(FString::Printf(TEXT("Debuff %d"), debufs.Num()))); + if (!NewDebuf) + return; + float angle=debufs.Num()*DebufAngleDiff; + float radians= FMath::DegreesToRadians(angle); + debufs.Add(NewDebuf); + NewDebuf->SetTexture(texture); + NewDebuf->SetPrecent(procent); + UCanvasPanelSlot* CanvasSlot = Cast(DebufPanel->AddChild(NewDebuf)); + + if (!CanvasSlot) + return; + + CanvasSlot->SetAnchors(FAnchors(0.5f, 0.5f)); + CanvasSlot->SetAlignment(FVector2D(0.5f, 0.5f)); + CanvasSlot->SetPosition(FVector2D(sin(radians)*DebufRange,-cos(radians)*DebufRange)); + CanvasSlot->SetAutoSize(true); + +} + diff --git a/Source/Exo/Public/Widget/UWBP_HpBar.h b/Source/Exo/Public/Widget/UWBP_HpBar.h deleted file mode 100644 index aa67363..0000000 --- a/Source/Exo/Public/Widget/UWBP_HpBar.h +++ /dev/null @@ -1,22 +0,0 @@ -// 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/WBP_PlayerUI.h b/Source/Exo/Public/Widget/WBP_PlayerUI.h new file mode 100644 index 0000000..d845f52 --- /dev/null +++ b/Source/Exo/Public/Widget/WBP_PlayerUI.h @@ -0,0 +1,52 @@ +// 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" +/** + * + */ +enum class EAmmoType: uint8; +class UUWBP_Debuf; +UCLASS() +class UWBP_PlayerUI : public UUserWidget +{ + GENERATED_BODY() +public: + void SetHp(float hp,float hpMax); + + void SetAmmoType(EAmmoType ammoType); + + void SetAmmoNumber(int ammo); + + void AddDebuf(UTexture2D* texture,float procent); + + UPROPERTY(EditAnywhere, meta = (BindWidget)) + class UUWBP_RoundProgressBar* HPBar; + + UPROPERTY(EditAnywhere, meta = (BindWidget)) + class UTextBlock* AmmoText; + + UPROPERTY(EditAnywhere, meta = (BindWidget)) + class UImage* AmmoImage; + + UPROPERTY(EditAnywhere, meta = (BindWidget)) + class UCanvasPanel* DebufPanel; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debuf") + float DebufRange; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debuf") + float DebufAngleDiff; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debuf") + TSubclassOf DebufClass; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ammo") + TMap AmmoIconMap; + +private: + TArray debufs; +};