feat: change UI elements visibliti, changing vievFinder

This commit is contained in:
BambiTheLama 2025-06-04 00:28:56 +02:00
parent e2f70680d4
commit abc13be7d4
11 changed files with 149 additions and 36 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -76,7 +76,12 @@ void AExoPlayerCharacter::BeginPlay()
PlayerHud->SetAmmoNumber(10);
PlayerHud->SetAmmoType(EAmmoType::Revolver);
for (int i=0;i<4;i++)
PlayerHud->AddDebuf(NULL,0.25f*i);
PlayerHud->AddBuf(NULL,0.25f*i);
PlayerHud->SetVisibilityHP(false);
PlayerHud->SetVisibilityBuf(false);
PlayerHud->SetVisibilityAmmo(false);
PlayerHud->SetVisibilityViewFinder(false);
PlayerHud->SetShootingViewFinder(false);
}
}
}

View File

@ -1,12 +1,11 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Widget/UWBP_Debuf.h"
#include "Widget/UWBP_Buf.h"
#include "Components/Image.h"
#include "Widget/UWBP_RoundProgressBar.h"
void UUWBP_Debuf::SetTexture(UTexture2D* texture)
void UUWBP_Buf::SetTexture(UTexture2D* texture)
{
if (!DebufImage)
return;
@ -18,7 +17,7 @@ void UUWBP_Debuf::SetTexture(UTexture2D* texture)
DebufImage->SetBrush(NewBrush);
}
void UUWBP_Debuf::SetPrecent(float precent)
void UUWBP_Buf::SetPrecent(float precent)
{
if (ProgressBar)
ProgressBar->SetPercent(precent);

View File

@ -3,7 +3,7 @@
#include "Widget/WBP_PlayerUI.h"
#include "UWBP_Debuf.h"
#include "Widget/UWBP_Buf.h"
#include "Blueprint/WidgetTree.h"
#include "Components/CanvasPanel.h"
#include "Components/CanvasPanelSlot.h"
@ -39,30 +39,109 @@ void UWBP_PlayerUI::SetAmmoNumber(int ammo)
AmmoText->SetText(FText::AsNumber(ammo));
}
void UWBP_PlayerUI::AddDebuf(UTexture2D* texture, float procent)
UUWBP_Buf* UWBP_PlayerUI::AddBuf(UTexture2D* texture, float procent)
{
if (!DebufClass)
return;
if (!DebufPanel)
return;
if (!BufClass)
return NULL;
if (!BufPanel)
return NULL;
UUWBP_Debuf* NewDebuf = WidgetTree->ConstructWidget<UUWBP_Debuf>(DebufClass, FName(FString::Printf(TEXT("Debuff %d"), debufs.Num())));
if (!NewDebuf)
return;
float angle=debufs.Num()*DebufAngleDiff;
UUWBP_Buf* NewBuf = WidgetTree->ConstructWidget<UUWBP_Buf>(BufClass, FName(FString::Printf(TEXT("Buff %d"), bufsSlots.Num())));
if (!NewBuf)
return NULL;
float angle=bufsSlots.Num()*BufAngleDiff;
float radians= FMath::DegreesToRadians(angle);
debufs.Add(NewDebuf);
NewDebuf->SetTexture(texture);
NewDebuf->SetPrecent(procent);
UCanvasPanelSlot* CanvasSlot = Cast<UCanvasPanelSlot>(DebufPanel->AddChild(NewDebuf));
NewBuf->SetTexture(texture);
NewBuf->SetPrecent(procent);
UCanvasPanelSlot* CanvasSlot = Cast<UCanvasPanelSlot>(BufPanel->AddChild(NewBuf));
if (!CanvasSlot)
return;
return NULL;
bufsSlots.Add(CanvasSlot);
CanvasSlot->SetAnchors(FAnchors(0.5f, 0.5f));
CanvasSlot->SetAlignment(FVector2D(0.5f, 0.5f));
CanvasSlot->SetPosition(FVector2D(sin(radians)*DebufRange,-cos(radians)*DebufRange));
CanvasSlot->SetPosition(FVector2D(sin(radians)*BufRange,-cos(radians)*BufRange));
CanvasSlot->SetAutoSize(true);
updateBufPosition();
return NewBuf;
}
void UWBP_PlayerUI::SetVisibilityHP(bool visibility)
{
showHp=visibility;
}
void UWBP_PlayerUI::SetVisibilityBuf(bool visibility)
{
showBuf=visibility;
}
void UWBP_PlayerUI::SetVisibilityAmmo(bool visibility)
{
showAmmo=visibility;
}
void UWBP_PlayerUI::SetVisibilityViewFinder(bool visibility)
{
showViewFinder=visibility;
}
void UWBP_PlayerUI::SetShootingViewFinder(bool Shooting)
{
shootingViewFinder=Shooting;
}
void UWBP_PlayerUI::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
{
Super::NativeTick(MyGeometry, InDeltaTime);
float showSpeed=DisplaySpeed*InDeltaTime;
opacityHp = FMath::Clamp(opacityHp + showSpeed * (showHp?1:-1), 0.0f, 1.0f);
opacityViewFinder = FMath::Clamp(opacityViewFinder + showSpeed * (showViewFinder?1:-1), 0.0f, 1.0f);
opacityBuf = FMath::Clamp(opacityBuf + showSpeed * (showBuf?1:-1), 0.0f, 1.0f);
opacityAmmo = FMath::Clamp(opacityAmmo + showSpeed * (showAmmo?1:-1), 0.0f, 1.0f);
shootingViewFinderPercent=FMath::Clamp(shootingViewFinderPercent + showSpeed * (shootingViewFinder?1:-1), 0.0f, 1.0f);
if (HPBar)
HPBar->SetRenderOpacity(opacityHp);
if (ViewFinder)
ViewFinder->SetRenderOpacity(opacityViewFinder);
if (BufPanel)
BufPanel->SetRenderOpacity(opacityBuf);
if (AmmoImage)
AmmoPanel->SetRenderOpacity(opacityAmmo);
if (!DynamicViewFinderMaterial)
{
if (!ViewFinder)
return;
FSlateBrush brush= ViewFinder->Brush;
UMaterialInterface* material=Cast<UMaterialInterface>(brush.GetResourceObject());
if (!material)
return;
DynamicViewFinderMaterial = UMaterialInstanceDynamic::Create(material, this);
if (DynamicViewFinderMaterial)
{
FSlateBrush newBrush= brush;
newBrush.SetResourceObject(DynamicViewFinderMaterial);
ViewFinder->Brush = newBrush;
}
}
if (DynamicViewFinderMaterial)
{
DynamicViewFinderMaterial->SetScalarParameterValue("Percent",shootingViewFinderPercent);
ViewFinder->SetRenderScale(FVector2D(1.0f, 1.0f)*((1.0f-shootingViewFinderPercent)*3+1));
}
}
void UWBP_PlayerUI::updateBufPosition()
{
float startAngle =- (bufsSlots.Num() - 1) / 2.0f * BufAngleDiff;
for (int i=0;i<bufsSlots.Num();i++)
{
float radians = FMath::DegreesToRadians(startAngle+i*BufAngleDiff);
bufsSlots[i]->SetPosition(FVector2D(sin(radians)*BufRange,-cos(radians)*BufRange));
}
}

View File

@ -4,13 +4,13 @@
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "UWBP_Debuf.generated.h"
#include "UWBP_Buf.generated.h"
/**
*
*/
UCLASS()
class UUWBP_Debuf : public UUserWidget
class EXO_API UUWBP_Buf : public UUserWidget
{
GENERATED_BODY()
public:

View File

@ -4,12 +4,13 @@
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Components/CanvasPanelSlot.h"
#include "WBP_PlayerUI.generated.h"
/**
*
*/
enum class EAmmoType: uint8;
class UUWBP_Debuf;
class UUWBP_Buf;
UCLASS()
class UWBP_PlayerUI : public UUserWidget
{
@ -21,7 +22,7 @@ public:
void SetAmmoNumber(int ammo);
void AddDebuf(UTexture2D* texture,float procent);
UUWBP_Buf* AddBuf(UTexture2D* texture,float procent);
UPROPERTY(EditAnywhere, meta = (BindWidget))
class UUWBP_RoundProgressBar* HPBar;
@ -33,20 +34,49 @@ public:
class UImage* AmmoImage;
UPROPERTY(EditAnywhere, meta = (BindWidget))
class UCanvasPanel* DebufPanel;
class UImage* ViewFinder;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debuf")
float DebufRange;
UPROPERTY(EditAnywhere, meta = (BindWidget))
class UCanvasPanel* BufPanel;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debuf")
float DebufAngleDiff;
UPROPERTY(EditAnywhere, meta = (BindWidget))
class UCanvasPanel* AmmoPanel;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debuf")
TSubclassOf<UUserWidget> DebufClass;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Buf")
float BufRange;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Buf")
float BufAngleDiff;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Buf")
TSubclassOf<UUserWidget> BufClass;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ammo")
TMap<EAmmoType, UTexture2D*> AmmoIconMap;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Display")
float DisplaySpeed=1.0f;
void SetVisibilityHP(bool visibility);
void SetVisibilityBuf(bool visibility);
void SetVisibilityAmmo(bool visibility);
void SetVisibilityViewFinder(bool visibility);
void SetShootingViewFinder(bool Shooting);
protected:
void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override;
private:
TArray<UUWBP_Debuf*> debufs;
TArray<UCanvasPanelSlot*> bufsSlots;
void updateBufPosition();
bool showHp = true, showBuf = true, showAmmo = true, showViewFinder = true;
float opacityHp = 1.0f, opacityBuf = 1.0f, opacityAmmo = 1.0f, opacityViewFinder = 1.0f;
bool shootingViewFinder = false;
float shootingViewFinderPercent = 1.0f;
UMaterialInstanceDynamic* DynamicViewFinderMaterial = nullptr;
};