feat: change UI elements visibliti, changing vievFinder
This commit is contained in:
parent
e2f70680d4
commit
abc13be7d4
Binary file not shown.
BIN
Content/Material/M_Blend.uasset
Normal file
BIN
Content/Material/M_Blend.uasset
Normal file
Binary file not shown.
Binary file not shown.
BIN
Content/Material/frame-icon.uasset
Normal file
BIN
Content/Material/frame-icon.uasset
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -76,7 +76,12 @@ void AExoPlayerCharacter::BeginPlay()
|
||||||
PlayerHud->SetAmmoNumber(10);
|
PlayerHud->SetAmmoNumber(10);
|
||||||
PlayerHud->SetAmmoType(EAmmoType::Revolver);
|
PlayerHud->SetAmmoType(EAmmoType::Revolver);
|
||||||
for (int i=0;i<4;i++)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
// Fill out your copyright notice in the Description page of Project Settings.
|
// 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 "Components/Image.h"
|
||||||
#include "Widget/UWBP_RoundProgressBar.h"
|
#include "Widget/UWBP_RoundProgressBar.h"
|
||||||
|
|
||||||
void UUWBP_Debuf::SetTexture(UTexture2D* texture)
|
void UUWBP_Buf::SetTexture(UTexture2D* texture)
|
||||||
{
|
{
|
||||||
if (!DebufImage)
|
if (!DebufImage)
|
||||||
return;
|
return;
|
||||||
|
|
@ -18,7 +17,7 @@ void UUWBP_Debuf::SetTexture(UTexture2D* texture)
|
||||||
DebufImage->SetBrush(NewBrush);
|
DebufImage->SetBrush(NewBrush);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UUWBP_Debuf::SetPrecent(float precent)
|
void UUWBP_Buf::SetPrecent(float precent)
|
||||||
{
|
{
|
||||||
if (ProgressBar)
|
if (ProgressBar)
|
||||||
ProgressBar->SetPercent(precent);
|
ProgressBar->SetPercent(precent);
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "Widget/WBP_PlayerUI.h"
|
#include "Widget/WBP_PlayerUI.h"
|
||||||
|
|
||||||
#include "UWBP_Debuf.h"
|
#include "Widget/UWBP_Buf.h"
|
||||||
#include "Blueprint/WidgetTree.h"
|
#include "Blueprint/WidgetTree.h"
|
||||||
#include "Components/CanvasPanel.h"
|
#include "Components/CanvasPanel.h"
|
||||||
#include "Components/CanvasPanelSlot.h"
|
#include "Components/CanvasPanelSlot.h"
|
||||||
|
|
@ -39,30 +39,109 @@ void UWBP_PlayerUI::SetAmmoNumber(int ammo)
|
||||||
AmmoText->SetText(FText::AsNumber(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)
|
if (!BufClass)
|
||||||
return;
|
return NULL;
|
||||||
if (!DebufPanel)
|
if (!BufPanel)
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
UUWBP_Debuf* NewDebuf = WidgetTree->ConstructWidget<UUWBP_Debuf>(DebufClass, FName(FString::Printf(TEXT("Debuff %d"), debufs.Num())));
|
UUWBP_Buf* NewBuf = WidgetTree->ConstructWidget<UUWBP_Buf>(BufClass, FName(FString::Printf(TEXT("Buff %d"), bufsSlots.Num())));
|
||||||
if (!NewDebuf)
|
if (!NewBuf)
|
||||||
return;
|
return NULL;
|
||||||
float angle=debufs.Num()*DebufAngleDiff;
|
float angle=bufsSlots.Num()*BufAngleDiff;
|
||||||
float radians= FMath::DegreesToRadians(angle);
|
float radians= FMath::DegreesToRadians(angle);
|
||||||
debufs.Add(NewDebuf);
|
|
||||||
NewDebuf->SetTexture(texture);
|
NewBuf->SetTexture(texture);
|
||||||
NewDebuf->SetPrecent(procent);
|
NewBuf->SetPrecent(procent);
|
||||||
UCanvasPanelSlot* CanvasSlot = Cast<UCanvasPanelSlot>(DebufPanel->AddChild(NewDebuf));
|
UCanvasPanelSlot* CanvasSlot = Cast<UCanvasPanelSlot>(BufPanel->AddChild(NewBuf));
|
||||||
|
|
||||||
if (!CanvasSlot)
|
if (!CanvasSlot)
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
|
bufsSlots.Add(CanvasSlot);
|
||||||
CanvasSlot->SetAnchors(FAnchors(0.5f, 0.5f));
|
CanvasSlot->SetAnchors(FAnchors(0.5f, 0.5f));
|
||||||
CanvasSlot->SetAlignment(FVector2D(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);
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "UWBP_Debuf.generated.h"
|
#include "UWBP_Buf.generated.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class UUWBP_Debuf : public UUserWidget
|
class EXO_API UUWBP_Buf : public UUserWidget
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
public:
|
public:
|
||||||
|
|
@ -4,12 +4,13 @@
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
|
#include "Components/CanvasPanelSlot.h"
|
||||||
#include "WBP_PlayerUI.generated.h"
|
#include "WBP_PlayerUI.generated.h"
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
enum class EAmmoType: uint8;
|
enum class EAmmoType: uint8;
|
||||||
class UUWBP_Debuf;
|
class UUWBP_Buf;
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class UWBP_PlayerUI : public UUserWidget
|
class UWBP_PlayerUI : public UUserWidget
|
||||||
{
|
{
|
||||||
|
|
@ -21,7 +22,7 @@ public:
|
||||||
|
|
||||||
void SetAmmoNumber(int ammo);
|
void SetAmmoNumber(int ammo);
|
||||||
|
|
||||||
void AddDebuf(UTexture2D* texture,float procent);
|
UUWBP_Buf* AddBuf(UTexture2D* texture,float procent);
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, meta = (BindWidget))
|
UPROPERTY(EditAnywhere, meta = (BindWidget))
|
||||||
class UUWBP_RoundProgressBar* HPBar;
|
class UUWBP_RoundProgressBar* HPBar;
|
||||||
|
|
@ -33,20 +34,49 @@ public:
|
||||||
class UImage* AmmoImage;
|
class UImage* AmmoImage;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, meta = (BindWidget))
|
UPROPERTY(EditAnywhere, meta = (BindWidget))
|
||||||
class UCanvasPanel* DebufPanel;
|
class UImage* ViewFinder;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debuf")
|
UPROPERTY(EditAnywhere, meta = (BindWidget))
|
||||||
float DebufRange;
|
class UCanvasPanel* BufPanel;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debuf")
|
UPROPERTY(EditAnywhere, meta = (BindWidget))
|
||||||
float DebufAngleDiff;
|
class UCanvasPanel* AmmoPanel;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Debuf")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Buf")
|
||||||
TSubclassOf<UUserWidget> DebufClass;
|
float BufRange;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Buf")
|
||||||
|
float BufAngleDiff;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Buf")
|
||||||
|
TSubclassOf<UUserWidget> BufClass;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ammo")
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ammo")
|
||||||
TMap<EAmmoType, UTexture2D*> AmmoIconMap;
|
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:
|
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;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user