ExoWest/Source/Exo/Private/Widget/WBP_PlayerUI.cpp

69 lines
1.7 KiB
C++
Raw Normal View History

2025-05-08 17:46:09 +02:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "Widget/WBP_PlayerUI.h"
2025-05-22 17:21:59 +02:00
#include "UWBP_Debuf.h"
#include "Blueprint/WidgetTree.h"
#include "Components/CanvasPanel.h"
#include "Components/CanvasPanelSlot.h"
#include "Components/Image.h"
2025-05-08 17:46:09 +02:00
#include "Components/TextBlock.h"
2025-05-22 17:21:59 +02:00
#include "Widget/UWBP_RoundProgressBar.h"
2025-05-08 17:46:09 +02:00
void UWBP_PlayerUI::SetHp(float hp, float hpMax)
{
2025-05-22 17:21:59 +02:00
if (!HPBar)
return;
HPBar->SetPercent(hp/hpMax);
2025-05-08 17:46:09 +02:00
}
2025-05-22 17:21:59 +02:00
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)
2025-05-08 17:46:09 +02:00
{
if (AmmoText)
AmmoText->SetText(FText::AsNumber(ammo));
}
2025-05-22 17:21:59 +02:00
void UWBP_PlayerUI::AddDebuf(UTexture2D* texture, float procent)
{
if (!DebufClass)
return;
if (!DebufPanel)
return;
UUWBP_Debuf* NewDebuf = WidgetTree->ConstructWidget<UUWBP_Debuf>(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<UCanvasPanelSlot>(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);
}