// Fill out your copyright notice in the Description page of Project Settings. #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_RoundProgressBar.h" void UWBP_PlayerUI::SetHp(float hp, float hpMax) { if (!HPBar) return; HPBar->SetPercent(hp/hpMax); } 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); }