// Fill out your copyright notice in the Description page of Project Settings. #include "BlasterHUD.h" #include "Announcement.h" #include "CharacterOverlay.h" #include "DebugWidget.h" #include "Blueprint/UserWidget.h" #include "Components/TextBlock.h" void ABlasterHUD::BeginPlay() { Super::BeginPlay(); } void ABlasterHUD::AddCharacterOverlay() { APlayerController* PlayerController = GetOwningPlayerController(); if (PlayerController && CharacterOverlayClass) { CharacterOverlay = CreateWidget(PlayerController, CharacterOverlayClass); CharacterOverlay->AddToViewport(); } } void ABlasterHUD::AddAnnouncement() { APlayerController* PlayerController = GetOwningPlayerController(); if (PlayerController && AnnouncementClass) { Announcement = CreateWidget(PlayerController, AnnouncementClass); Announcement->AddToViewport(); } } void ABlasterHUD::AddDebugWidget() { APlayerController* PlayerController = GetOwningPlayerController(); if (PlayerController && DebugWidgetClass) { DebugWidget = CreateWidget(PlayerController, DebugWidgetClass); DebugWidget->AddToViewport(); } } void ABlasterHUD::DrawHUD() { Super::DrawHUD(); if (GEngine) { FVector2D ViewportSize; GEngine->GameViewport->GetViewportSize(ViewportSize); const FVector2D ViewportCenter(ViewportSize.X / 2.f, ViewportSize.Y / 2.f); const float SpreadScaled = CrosshairSpreadMax * HUDPackage.CrosshairSpread; if (HUDPackage.CrosshairsCenter) { const FVector2D Spread(0.f, 0.f); DrawCrosshair(HUDPackage.CrosshairsCenter, ViewportCenter, Spread, HUDPackage.CrosshairsColor); } if (HUDPackage.CrosshairsLeft) { const FVector2D Spread(-SpreadScaled, 0.f); DrawCrosshair(HUDPackage.CrosshairsLeft, ViewportCenter, Spread, HUDPackage.CrosshairsColor); } if (HUDPackage.CrosshairsRight) { const FVector2D Spread(SpreadScaled, 0.f); DrawCrosshair(HUDPackage.CrosshairsRight, ViewportCenter, Spread, HUDPackage.CrosshairsColor); } if (HUDPackage.CrosshairsTop) { const FVector2D Spread(0.f, -SpreadScaled); DrawCrosshair(HUDPackage.CrosshairsTop, ViewportCenter, Spread, HUDPackage.CrosshairsColor); } if (HUDPackage.CrosshairsBottom) { const FVector2D Spread(0.f, SpreadScaled); DrawCrosshair(HUDPackage.CrosshairsBottom, ViewportCenter, Spread, HUDPackage.CrosshairsColor); } } } void ABlasterHUD::DrawCrosshair(UTexture2D* Texture, FVector2D ViewportCenter, FVector2D Spread, FLinearColor CrosshairColor) { const float TextureWidth = Texture->GetSizeX(); const float TextureHeight = Texture->GetSizeY(); const FVector2D TextureDrawPoint( ViewportCenter.X - (TextureWidth / 2.f) + Spread.X, ViewportCenter.Y - (TextureHeight / 2.f) + Spread.Y ); DrawTexture( Texture, TextureDrawPoint.X, TextureDrawPoint.Y, TextureWidth, TextureHeight, 0.f, 0.f, 1.f, 1.f, CrosshairColor ); }