void AAbilitySystemDebugHUD::DrawWithBackground(UFont* InFont, const FString& Text, const FColor& TextColor, EAlignHorizontal::Type HAlign, float& OffsetX, EAlignVertical::Type VAlign, float& OffsetY, float Alpha)
{
	float SizeX, SizeY;
	Canvas->StrLen(InFont, Text, SizeX, SizeY);

	const float PosX = (HAlign == EAlignHorizontal::Center) ? OffsetX + (Canvas->ClipX - SizeX) * 0.5f :
		(HAlign == EAlignHorizontal::Left) ? Canvas->OrgX + OffsetX :
		Canvas->ClipX - SizeX - OffsetX;

	const float PosY = (VAlign == EAlignVertical::Center) ? OffsetY + (Canvas->ClipY - SizeY) * 0.5f :
		(VAlign == EAlignVertical::Top) ? Canvas->OrgY + OffsetY :
		Canvas->ClipY - SizeY - OffsetY;

	const float BoxPadding = 5.0f;

	const float X = PosX - BoxPadding;
	const float Y = PosY - BoxPadding;
	const float Z = 0.1f;
	FCanvasTileItem TileItem(FVector2D(X, Y), FVector2D(SizeX + BoxPadding * 2.0f, SizeY + BoxPadding * 2.0f), FLinearColor(0.75f, 0.75f, 0.75f, Alpha));
	Canvas->DrawItem(TileItem);

	FLinearColor TextCol(TextColor);
	TextCol.A = Alpha;
	FCanvasTextItem TextItem(FVector2D(PosX, PosY), FText::FromString(Text), GEngine->GetSmallFont(), TextCol);
	Canvas->DrawItem(TextItem);

	OffsetY += 25;
}
/** draws high score */
void APlatformerHUD::DrawHighscore()
{
	const FText Highscore = LOCTEXT("Highscore", "High score");
	const float SizeX = Canvas->ClipX * 0.4f;
	const float SizeY = 1000 * UIScale;
	const float DrawX = (Canvas->ClipX - SizeX) / 2.0f;
	const float DrawY = (Canvas->ClipY - SizeY) / 2.0f;

	DrawBorder(DrawX, DrawY,  SizeX, SizeY, 1.0f, BlueBorder);

	const float TextScale = 1.4f;
	const float TextMargin = 0.03f;
	float StrSizeX, StrSizeY;
	Canvas->StrLen(HUDFont, Highscore.ToString(), StrSizeX, StrSizeY);
	StrSizeX = StrSizeX * TextScale * UIScale;
	StrSizeY = StrSizeY * TextScale * UIScale;

	FCanvasTextItem TextItem( FVector2D( (Canvas->ClipX - StrSizeX) / 2.0f, DrawY + SizeY * TextMargin ), 
		Highscore, HUDFont, FLinearColor::White );
	TextItem.Scale = FVector2D( TextScale * UIScale, TextScale * UIScale );
	TextItem.EnableShadow( FLinearColor::Transparent );
	Canvas->DrawItem( TextItem );

	const float BorderSize = BlueBorder.LeftBorder->Resource->GetSizeX() * UIScale;
	FCanvasTileItem TileItem(FVector2D(  DrawX + BorderSize, DrawY + SizeY * TextMargin + StrSizeY ), BlueBorder.TopBorder->Resource, 
		FVector2D( SizeX - 2* BorderSize, BlueBorder.TopBorder->Resource->GetSizeY() * UIScale ),
		FVector2D(0,0),FVector2D((SizeX - 2* BorderSize) / BlueBorder.TopBorder->Resource->GetSizeX() * UIScale,1), FLinearColor::White);
	TileItem.BlendMode = SE_BLEND_Translucent;
	Canvas->DrawItem(TileItem);


	const float StartY = DrawY + SizeY * TextMargin*3 + StrSizeY * TextScale * UIScale;

	const float ColWidths[] = {70*UIScale, 340*UIScale, 200*UIScale};
	
	const float TotalWidth = ColWidths[0]+ColWidths[1]+ColWidths[2];

	for (int32 i=0; i < 10; i++ )
	{
		FText Texts[] = { FText::Format(FText::FromString("{0}."), FText::AsNumber(i+1)),
			FText::FromString(UPlatformerBlueprintLibrary::DescribeTime(HighscoreTimes[i], false)),
			FText::FromString(HighscoreNames[i]) };
		float Offset = 0;
		for (uint8 column=0; column < 3; column++)
		{
			TextItem.Text = Texts[column]; 
			Canvas->StrLen(HUDFont, TextItem.Text.ToString(), StrSizeX, StrSizeY);
			StrSizeX = StrSizeX * TextScale * UIScale;
			StrSizeY = StrSizeY * TextScale * UIScale;
			TextItem.Position = FVector2D((Canvas->ClipX - TotalWidth) / 2.0f + Offset + ColWidths[column] - StrSizeX, StartY + i * StrSizeY);
			Canvas->DrawItem( TextItem );
			Offset += ColWidths[column];
		}

	}

}
Ejemplo n.º 3
0
void UReporterGraph::DrawBackground(UCanvas* Canvas)
{
    FVector2D Min = FVector2D(GraphScreenSize.Min.X * Canvas->SizeX, Canvas->SizeY - GraphScreenSize.Min.Y * Canvas->SizeY);
    FVector2D Max = FVector2D(GraphScreenSize.Max.X * Canvas->SizeX, Canvas->SizeY - GraphScreenSize.Max.Y * Canvas->SizeY);

    FCanvasTileItem TileItem(Min, GWhiteTexture, Max-Min, BackgroundColor);
    TileItem.BlendMode = SE_BLEND_Translucent;
    Canvas->DrawItem(TileItem, Min);
}
Ejemplo n.º 4
0
void AHUD::DrawRect(FLinearColor Color, float ScreenX, float ScreenY, float Width, float Height)
{
	if (IsCanvasValid_WarnIfNot())	
	{
		FCanvasTileItem TileItem( FVector2D(ScreenX, ScreenY), GWhiteTexture, FVector2D( Width, Height ), Color );
		TileItem.BlendMode = SE_BLEND_Translucent;
		Canvas->DrawItem( TileItem );		
	}
}
Ejemplo n.º 5
0
void ATheHUD::DrawMaterial(UCanvas* Canvas, UMaterialInterface* Material, float ScreenX, float ScreenY, 
  float ScreenW, float ScreenH, float MaterialU, float MaterialV, float MaterialUWidth, float MaterialVHeight)
{
  FCanvasTileItem TileItem( FVector2D( ScreenX, ScreenY ), Material->GetRenderProxy(0), 
    FVector2D( ScreenW, ScreenH ) * 1.f, FVector2D( MaterialU, MaterialV ), 
    FVector2D( MaterialU + MaterialUWidth, MaterialV + MaterialVHeight ) );
	TileItem.Rotation = FRotator(0, 0, 0);
	TileItem.PivotPoint = FVector2D::ZeroVector;
	Canvas->DrawItem( TileItem );
}
Ejemplo n.º 6
0
void ATheHUD::DrawMaterial(UCanvas* Canvas, UMaterialInterface* Material, float ScreenX, float ScreenY, 
  float ScreenW, float ScreenH, float MaterialU, float MaterialV, float MaterialUWidth, float MaterialVHeight, 
  float Scale, bool bScalePosition, float Rotation, FVector2D RotPivot)
{
  FCanvasTileItem TileItem( FVector2D( ScreenX, ScreenY ), Material->GetRenderProxy(0), 
    FVector2D( ScreenW, ScreenH ) * Scale, FVector2D( MaterialU, MaterialV ), 
    FVector2D( MaterialU + MaterialUWidth, MaterialV + MaterialVHeight ) );
	TileItem.Rotation = FRotator(0, Rotation, 0);
	TileItem.PivotPoint = RotPivot;
	Canvas->DrawItem( TileItem );
}
Ejemplo n.º 7
0
void AHUD::DrawMaterialSimple(UMaterialInterface* Material, float ScreenX, float ScreenY, float ScreenW, float ScreenH, float Scale, bool bScalePosition)
{
	if (IsCanvasValid_WarnIfNot() && Material)
	{
		FCanvasTileItem TileItem( FVector2D( ScreenX, ScreenY ), Material->GetRenderProxy(0), FVector2D( ScreenW, ScreenH ) * Scale );
		if (bScalePosition)
		{
			TileItem.Position *= Scale;
		}
		Canvas->DrawItem( TileItem );
	}
}
Ejemplo n.º 8
0
void AGameHUD::DrawTexture(UTexture2D* Texture)
{
	float TextureWidth = Texture->GetSurfaceWidth();
	float TextureHeight = Texture->GetSurfaceHeight();

	const FVector2D CanvasCenter(Canvas->ClipX / 2, Canvas->ClipY / 2);
	const FVector2D DrawPosition(CanvasCenter.X - (TextureWidth / 2), CanvasCenter.Y - (TextureHeight / 2));

	FCanvasTileItem TileItem(DrawPosition, Texture->Resource, FLinearColor::White);
	TileItem.BlendMode = ESimpleElementBlendMode::SE_BLEND_Translucent;

	Canvas->DrawItem(TileItem);
}
Ejemplo n.º 9
0
void AHUD::DrawMaterial(UMaterialInterface* Material, float ScreenX, float ScreenY, float ScreenW, float ScreenH, float MaterialU, float MaterialV, float MaterialUWidth, float MaterialVHeight, float Scale, bool bScalePosition, float Rotation, FVector2D RotPivot)
{
	if (IsCanvasValid_WarnIfNot() && Material)
	{
		FCanvasTileItem TileItem( FVector2D( ScreenX, ScreenY ), Material->GetRenderProxy(0), FVector2D( ScreenW, ScreenH ) * Scale, FVector2D( MaterialU, MaterialV ), FVector2D( MaterialU+MaterialUWidth, MaterialV +MaterialVHeight) );
		TileItem.Rotation = FRotator(0, Rotation, 0);
		TileItem.PivotPoint = RotPivot;
		if (bScalePosition)
		{
			TileItem.Position *= Scale;
		}
		Canvas->DrawItem( TileItem );
	}
}
Ejemplo n.º 10
0
void AFPSHUD::DrawHUD()
{
	Super::DrawHUD();
	// Draw very simple crosshair
	// find center of the Canvas
	const FVector2D Center(Canvas->ClipX * 0.5f, Canvas->ClipY * 0.5f);
	// offset by half the texture's dimensions so that the center of the texture aligns with the center of the Canvas
	const FVector2D CrosshairDrawPosition((Center.X - (CrosshairTex->GetSurfaceWidth() * 0.5)),
		(Center.Y - (CrosshairTex->GetSurfaceHeight() * 0.5f)));
	// draw the crosshair
	FCanvasTileItem TileItem(CrosshairDrawPosition, CrosshairTex->Resource, FLinearColor::White);
	TileItem.BlendMode = SE_BLEND_Translucent;
	Canvas->DrawItem(TileItem);
}
Ejemplo n.º 11
0
void AStrategyHUD::DrawHealthBar(AActor* ForActor, float HealthPercentage, int32 BarHeight, int32 OffsetY) const
{
	FBox BB = ForActor->GetComponentsBoundingBox();
	FVector Center = BB.GetCenter();
	FVector Extent = BB.GetExtent();
	FVector2D Center2D = FVector2D(Canvas->Project(FVector(Center.X,Center.Y,Center.Z + Extent.Z)));
	float ActorExtent = 40;
	if (Cast<APawn>(ForActor) != NULL)
	{
		AStrategyChar* StrategyChar = Cast<AStrategyChar>(ForActor);
		if( ( StrategyChar != NULL ) && ( StrategyChar->GetCapsuleComponent() != NULL ) )
		{
			ActorExtent = StrategyChar->GetCapsuleComponent()->GetScaledCapsuleRadius();
		}
	}
	else if (Cast<AStrategyBuilding>(ForActor) != NULL)
	{
		Center2D = FVector2D(Canvas->Project(ForActor->GetActorLocation()));
		ActorExtent = 60;
	}

	FVector Pos1 = Canvas->Project(FVector(Center.X,Center.Y - ActorExtent*2, Center.Z + Extent.Z));
	FVector Pos2 = Canvas->Project(FVector(Center.X,Center.Y + ActorExtent*2, Center.Z + Extent.Z));
	float HealthBarLength = (Pos2-Pos1).Size2D();

	AStrategyPlayerController* MyPC = GetPlayerController();
	IStrategyTeamInterface* ActorTeam = Cast<IStrategyTeamInterface>(ForActor);
	UTexture2D* HealthBarTexture = EnemyTeamHPTexture;

	if (ActorTeam != NULL && MyPC != NULL && ActorTeam->GetTeamNum() == MyPC->GetTeamNum())
	{
		HealthBarTexture = PlayerTeamHPTexture;
	} 
	float X = Center2D.X - HealthBarLength/2;
	float Y = Center2D.Y + OffsetY;
	FCanvasTileItem TileItem( FVector2D( X, Y ), HealthBarTexture->Resource, FVector2D( HealthBarLength * HealthPercentage,  BarHeight ), FLinearColor::White );
	TileItem.BlendMode = SE_BLEND_Translucent;
	TileItem.UV1 = FVector2D(HealthPercentage, 1.0f);

	Canvas->DrawItem( TileItem );
	//Fill the rest of health with gray gradient texture
	X = Center2D.X-HealthBarLength/2 + HealthBarLength * HealthPercentage;
	Y = Center2D.Y + OffsetY;
	TileItem.Position = FVector2D( X, Y );
	TileItem.Texture = BarFillTexture->Resource;
	TileItem.UV1 = FVector2D(1.0f, 1.0f);
	TileItem.Size = FVector2D( HealthBarLength * (1.0f - HealthPercentage), BarHeight );
	TileItem.SetColor(FLinearColor(0.5f, 0.5f, 0.5f, 0.5f));
	Canvas->DrawItem( TileItem );	
}
Ejemplo n.º 12
0
void AHUD::DrawTextureSimple(UTexture* Texture, float ScreenX, float ScreenY, float Scale, bool bScalePosition)
{
	if (IsCanvasValid_WarnIfNot() && Texture)
	{
		FCanvasTileItem TileItem( FVector2D( ScreenX, ScreenY ), Texture->Resource, FLinearColor::White );
		if (bScalePosition)
		{
			TileItem.Position *= Scale;
		}
		// Apply the scale to the size (which will have been setup from the texture in the constructor).
		TileItem.Size *= Scale;
		TileItem.BlendMode = SE_BLEND_Translucent;
		Canvas->DrawItem( TileItem );
	}
}
Ejemplo n.º 13
0
void AHUD::DrawTexture(UTexture* Texture, float ScreenX, float ScreenY, float ScreenW, float ScreenH, float TextureU, float TextureV, float TextureUWidth, float TextureVHeight, FLinearColor Color, EBlendMode BlendMode, float Scale, bool bScalePosition, float Rotation, FVector2D RotPivot)
{
	if (IsCanvasValid_WarnIfNot() && Texture)
	{
		FCanvasTileItem TileItem( FVector2D( ScreenX, ScreenY ), Texture->Resource, FVector2D( ScreenW, ScreenH ) * Scale, FVector2D( TextureU, TextureV ), FVector2D( TextureU + TextureUWidth, TextureV + TextureVHeight ), Color );
		TileItem.Rotation = FRotator(0, Rotation, 0);
		TileItem.PivotPoint = RotPivot;
		if (bScalePosition)
		{
			TileItem.Position *= Scale;
		}
		TileItem.BlendMode = FCanvas::BlendToSimpleElementBlend( BlendMode );
		Canvas->DrawItem( TileItem );
	}
}
void UFontThumbnailRenderer::Draw(UObject* Object, int32 X, int32 Y, uint32 Width, uint32 Height, FRenderTarget*, FCanvas* Canvas)
{
    UFont* Font = Cast<UFont>(Object);
    if (Font != nullptr &&
            Font->Textures.Num() > 0 &&
            Font->Textures[0] != nullptr)
    {
        FCanvasTileItem TileItem( FVector2D( X, Y ), Font->Textures[0]->Resource, FLinearColor::White );
        TileItem.BlendMode = SE_BLEND_Translucent;
        if (Font->ImportOptions.bUseDistanceFieldAlpha)
        {
            TileItem .BlendMode = SE_BLEND_TranslucentDistanceField;
        }

        Canvas->DrawItem( TileItem );
    }
}
Ejemplo n.º 15
0
/**
 * This is the main drawing pump.  It will determine which hud we need to draw (Game or PostGame).  Any drawing that should occur
 * regardless of the game state should go here.
 */
void AStrategyHUD::DrawHUD()
{
	if (bBlackScreenActive)
	{
		FCanvasTileItem TileItem( FVector2D( 0.0f, 0.0f ), FVector2D( Canvas->ClipX,Canvas->ClipY ), FLinearColor( 0.0f, 0.0f, 0.0f, 1.0f ) );
		TileItem.BlendMode = SE_BLEND_Translucent;
		Canvas->DrawItem( TileItem );
		return;
	}

	if ( GEngine && GEngine->GameViewport )
	{
		FVector2D ViewportSize;
		GEngine->GameViewport->GetViewportSize(ViewportSize);
		UIScale = ViewportSize.X / 2048.0f;
	}

	Super::DrawHUD();
	bool bConsoleOpen = false;

	AStrategyGameState const* const MyGameState = GetWorld()->GetGameState<AStrategyGameState>();
	if (MyGameState)
	{
		//Builds the widgets if they are not yet built
		BuildMenuWidgets();

		if (MyGameState->IsGameActive())
		{
			DrawActorsHealth();
		}
		DrawMiniMap();
		DrawLives();

		if (IsPauseMenuUp())
		{
			/*FCanvasTileItem TileItem( FVector2D( 0.0f, 0.0f ), FVector2D( Canvas->ClipX,Canvas->ClipY ), FLinearColor( 0.0f, 0.0f, 0.0f, 0.25f ) );
			TileItem.BlendMode = SE_BLEND_Translucent;
			Canvas->DrawItem( TileItem );*/
		}

		if (SelectedActor.IsValid())
		{
			ActionGridPos = FVector2D(Canvas->Project(SelectedActor->GetActorLocation())) / UIScale - (MyHUDMenuWidget->ActionButtonsWidget->GetDesiredSize())/2;
		}
	}
}
Ejemplo n.º 16
0
void AHUD::DrawSafeZoneOverlay()
{
	const int32 DebugSafeZoneMode = GSafeZoneVisualizationModeCVar.GetValueOnGameThread();

	if ((DebugSafeZoneMode > 0) && (DebugCanvas != nullptr))
	{
		FDisplayMetrics Metrics;
		FSlateApplication::Get().GetDisplayMetrics(Metrics);

		const FMargin SafeMargin = (DebugSafeZoneMode == 1) ?
			FMargin(Metrics.TitleSafePaddingSize.X, Metrics.TitleSafePaddingSize.Y) :
			FMargin(Metrics.ActionSafePaddingSize.X, Metrics.ActionSafePaddingSize.Y);

		const float UnsafeZoneAlpha = GSafeZoneVisualizationAlphaCVar.GetValueOnGameThread();
		const FLinearColor UnsafeZoneColor(1.0f, 0.5f, 0.5f, UnsafeZoneAlpha);

		const float Width = DebugCanvas->SizeX;
		const float Height = DebugCanvas->SizeY;

		const float HeightOfSides = Height - SafeMargin.GetTotalSpaceAlong<Orient_Vertical>();

		FCanvasTileItem TileItem(FVector2D::ZeroVector, GWhiteTexture, UnsafeZoneColor);
		TileItem.BlendMode = SE_BLEND_Translucent;

		// Top bar
		TileItem.Position = FVector2D::ZeroVector;
		TileItem.Size = FVector2D(Width, SafeMargin.Top);
		DebugCanvas->DrawItem(TileItem);

		// Bottom bar
		TileItem.Position = FVector2D(0.0f, Height - SafeMargin.Bottom);
		TileItem.Size = FVector2D(Width, SafeMargin.Bottom);
		DebugCanvas->DrawItem(TileItem);

		// Left bar
		TileItem.Position = FVector2D(0.0f, SafeMargin.Top);
		TileItem.Size = FVector2D(SafeMargin.Left, HeightOfSides);
		DebugCanvas->DrawItem(TileItem);

		// Right bar
		TileItem.Position = FVector2D(Width - SafeMargin.Right, SafeMargin.Top);
		TileItem.Size = FVector2D(SafeMargin.Right, HeightOfSides);
		DebugCanvas->DrawItem(TileItem);
	}
}
Ejemplo n.º 17
0
void AStrategyHUD::DrawLives() const
{
	AStrategyGameState const* const MyGameState = GetWorld()->GetGameState<AStrategyGameState>();
	AStrategyBuilding_Brewery const* const Brewery = MyGameState ? MyGameState->GetPlayerData(EStrategyTeam::Player)->Brewery.Get() : NULL;

	uint8 const Lives = Brewery ? Brewery->GetNumberOfLives() : 0;

	float const TextureDrawWidth = LivesTexture->GetSurfaceWidth() * UIScale;
	float const TextureDrawHeight =  LivesTexture->GetSurfaceHeight() * UIScale;

	FCanvasTileItem TileItem(FVector2D(0,0), LivesTexture->Resource, 
							 FVector2D(TextureDrawWidth, TextureDrawHeight), FLinearColor::White );
	TileItem.BlendMode = SE_BLEND_Translucent;
	for (int32 i=0; i < Lives; i++)
	{
		TileItem.Position = FVector2D(Canvas->ClipX - Lives*TextureDrawWidth + i*TextureDrawWidth, 0);
		Canvas->DrawItem(TileItem);
	}
}
Ejemplo n.º 18
0
void AFPS_MultiplayerHUD::DrawHUD()
{
	Super::DrawHUD();
    
    // Draw very simple crosshair
    
    // find center of the Canvas
    const FVector2D Center(Canvas->ClipX * 0.5f, Canvas->ClipY * 0.5f);
    
    // offset by half the texture's dimensions so that the center of the texture aligns with the center of the Canvas
    const FVector2D CrosshairDrawPosition( (Center.X - (CrosshairTex->GetSurfaceWidth() * 0.5) + 10),
                                          (Center.Y - (CrosshairTex->GetSurfaceHeight() * 0.5f) + 15) );
    
    // draw the crosshair
    FCanvasTileItem TileItem( CrosshairDrawPosition, CrosshairTex->Resource, FLinearColor::White);
    TileItem.BlendMode = SE_BLEND_Translucent;
    Canvas->DrawItem( TileItem );
    
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Test 1"));
    AFPS_MultiplayerGameMode* GameMode = Cast<AFPS_MultiplayerGameMode>(UGameplayStatics::GetGameMode(this));
    if(GameMode)
    {
        GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Test 2"));
        if(GameMode->LastManStanding == true)
        {
            GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Test 3"));

            FVector2D ScreenDimensions = FVector2D(Canvas->SizeX, Canvas->SizeY);
            FVector2D GameOverSize;
            GetTextSize(TEXT("GAME OVER"), GameOverSize.X, GameOverSize.Y, HUDFont);
            DrawText(TEXT("GAME OVER"), FColor::White, (ScreenDimensions.X - GameOverSize.X) / 2.0f, (ScreenDimensions.Y - GameOverSize.Y) / 2.0f, HUDFont);
        }
        
    }
    //DrawHUDServer();

}
void APlatformerHUD::DrawHighscoreEntryPrompt()
{
	const float SizeX = 90 * UIScale;
	const float SizeY = 90 * UIScale;
	const float DrawX = (Canvas->ClipX - SizeX*3) / 2.0f;
	const float DrawY = (Canvas->ClipY - SizeY) / 2.0f;

	const float UVL = 90.0f/128.0f;
	const float TextScale = 1.8f;

	FCanvasTileItem TileItem(FVector2D(DrawX+SizeX*CurrentLetter, DrawY), UpButtonTexture->Resource, 
		FVector2D( SizeX, SizeY ),
		FVector2D(0,0),FVector2D(UVL,UVL), FLinearColor::White);
	TileItem.BlendMode = SE_BLEND_Translucent;
	if (HighScoreName[CurrentLetter] < 'Z')
	{
		Canvas->DrawItem(TileItem);
		AddHitBox(TileItem.Position,TileItem.Size,"Up",true,255);
	}

	if (HighScoreName[CurrentLetter] > 'A')
	{
		TileItem.Position = FVector2D(DrawX+SizeX*CurrentLetter,DrawY+SizeY*2);
		TileItem.Texture = DownButtonTexture->Resource;

		AddHitBox(TileItem.Position,TileItem.Size,"Down",true,255);
		Canvas->DrawItem(TileItem);
	}

	FCanvasTextItem TextItem(FVector2D(DrawX, DrawY), FText(), HUDFont, FLinearColor::White);
	TextItem.Scale = FVector2D(TextScale * UIScale, TextScale * UIScale);
	TextItem.EnableShadow( FLinearColor::Transparent );


	float StrSizeX, StrSizeY;
	float Offset = 0;

	for (int32 i = 0; i < HighScoreName.Num(); i++)
	{
		TextItem.Text = FText::FromString(FString::Chr(HighScoreName[i]));
		Canvas->StrLen(HUDFont, TextItem.Text.ToString(), StrSizeX, StrSizeY);
		Canvas->StrLen(HUDFont, TextItem.Text.ToString(), StrSizeX, StrSizeY);
		Canvas->StrLen(HUDFont, TextItem.Text.ToString(), StrSizeX, StrSizeY);
		StrSizeX = StrSizeX * TextScale * UIScale;
		StrSizeY = StrSizeY * TextScale * UIScale;
		TextItem.Position = FVector2D(DrawX+Offset+(SizeX-StrSizeX)/2.0f, DrawY + SizeY);

		DrawBorder(DrawX + Offset, DrawY + SizeY,  SizeX, SizeY, 0.4f, CurrentLetter == i ? BlueBorder : RedBorder);
		AddHitBox(FVector2D(DrawX + Offset,DrawY + SizeY),TileItem.Size,FName(TEXT("Letter"),i),true,255);

		Canvas->DrawItem( TextItem );
		Offset += SizeX;
	}

	const float ButtonWidth = 200 * UIScale;
	TextItem.Text = LOCTEXT("OK", "OK");
	Canvas->StrLen(HUDFont, TextItem.Text.ToString(), StrSizeX, StrSizeY);
	StrSizeX = StrSizeX * TextScale * UIScale;
	StrSizeY = StrSizeY * TextScale * UIScale;
	TextItem.Position = FVector2D((Canvas->ClipX - StrSizeX) / 2.0f, DrawY + SizeY*4);

	DrawBorder((Canvas->ClipX - ButtonWidth) / 2.0f, DrawY + SizeY*4,  ButtonWidth, SizeY, 0.4f, BlueBorder);
	AddHitBox(FVector2D((Canvas->ClipX - ButtonWidth) / 2.0f,DrawY + SizeY*4),FVector2D(ButtonWidth,SizeY),FName("OK"),true,255);
	Canvas->DrawItem( TextItem );
}
Ejemplo n.º 20
0
void FCanvasItemTestbed::Draw( class FViewport* Viewport, class FCanvas* Canvas )
{
	bTestState = !bTestState;

	if( !bShowTestbed )
	{
		return;
	}

	
	// A little ott for a testbed - but I wanted to draw several lines to ensure it worked :)
	if( TestLine.bTestSet == false )
	{
		TestLine.bTestSet = true;
		TestLine.LineStart.X = FMath::FRandRange( 0.0f, Viewport->GetSizeXY().X );
		TestLine.LineStart.Y = FMath::FRandRange( 0.0f, Viewport->GetSizeXY().Y );
		TestLine.LineEnd.X = FMath::FRandRange( 0.0f, Viewport->GetSizeXY().X );
		TestLine.LineEnd.Y  = FMath::FRandRange( 0.0f, Viewport->GetSizeXY().Y );
		TestLine.LineMove.X = FMath::FRandRange( 0.0f, 32.0f );
		TestLine.LineMove.Y = FMath::FRandRange( 0.0f, 32.0f );
		TestLine.LineMove2.X = FMath::FRandRange( 0.0f, 32.0f );
		TestLine.LineMove2.Y = FMath::FRandRange( 0.0f, 32.0f );
	}
	else
	{
		TestLine.LineStart += TestLine.LineMove;
		TestLine.LineEnd += TestLine.LineMove2;
		if( TestLine.LineStart.X < 0 )
		{
			TestLine.LineMove.X = -TestLine.LineMove.X;
		}
		if( TestLine.LineStart.Y < 0 )
		{
			TestLine.LineMove.Y = -TestLine.LineMove.Y;
		}
		if( TestLine.LineEnd.X < 0 )
		{
			TestLine.LineMove2.X = -TestLine.LineMove2.X;
		}
		if( TestLine.LineEnd.Y < 0 )
		{
			TestLine.LineMove2.Y = -TestLine.LineMove2.Y;
		}
		if( TestLine.LineStart.X > Viewport->GetSizeXY().X )
		{
			TestLine.LineMove.X = -TestLine.LineMove.X;
		}
		if( TestLine.LineStart.Y > Viewport->GetSizeXY().Y )
		{
			TestLine.LineMove.Y = -TestLine.LineMove.Y;
		}
		if( TestLine.LineEnd.X > Viewport->GetSizeXY().X )
		{
			TestLine.LineMove2.X = -TestLine.LineMove2.X;
		}
		if( TestLine.LineEnd.Y > Viewport->GetSizeXY().Y )
		{
			TestLine.LineMove2.Y = -TestLine.LineMove2.Y;
		}
	}
	
	// Text
	float CenterX = 0.0f;
	float YTest = 16.0f;
	FCanvasTextItem TextItem( FVector2D( CenterX, YTest ), LOCTEXT( "stringhere", "String Here" ), GEngine->GetSmallFont(), FLinearColor::Red );	
	TextItem.Draw( Canvas );
	
	// Shadowed text
	TextItem.Position.Y += TextItem.DrawnSize.Y;
	TextItem.Scale.X = 2.0f;
	TextItem.EnableShadow( FLinearColor::Green, FVector2D( 2.0f, 2.0f ) );
	TextItem.Text = LOCTEXT( "Scaled String here", "Scaled String here" );
	TextItem.Draw( Canvas );
	TextItem.DisableShadow();

	TextItem.Position.Y += TextItem.DrawnSize.Y;;
	TextItem.Text = LOCTEXT( "CenterdStringhere", "CenterdStringhere" );
	TextItem.Scale.X = 1.0f;
	TextItem.bCentreX = true;
	TextItem.Draw( Canvas );

	// Outlined text
	TextItem.Position.Y += TextItem.DrawnSize.Y;
	TextItem.Text = LOCTEXT( "ScaledCentredStringhere", "Scaled Centred String here" );	
	TextItem.OutlineColor = FLinearColor::Black;
	TextItem.bOutlined = true;
	TextItem.Scale = FVector2D( 2.0f, 2.0f );
	TextItem.SetColor( FLinearColor::Green );
	TextItem.Text = LOCTEXT( "ScaledCentredOutlinedStringhere", "Scaled Centred Outlined String here" );	
	TextItem.Draw( Canvas );
	
	// a line
	FCanvasLineItem LineItem( TestLine.LineStart, TestLine.LineEnd );
	LineItem.Draw( Canvas );

	// some boxes
	FCanvasBoxItem BoxItem( FVector2D( 88.0f, 88.0f ), FVector2D( 188.0f, 188.0f ) );
	BoxItem.SetColor( FLinearColor::Yellow );
	BoxItem.Draw( Canvas );

	BoxItem.SetColor( FLinearColor::Red );
	BoxItem.Position = FVector2D( 256.0f, 256.0f );
	BoxItem.Draw( Canvas );

	BoxItem.SetColor( FLinearColor::Blue );
	BoxItem.Position = FVector2D( 6.0f, 6.0f );
	BoxItem.Size = FVector2D( 48.0f, 96.0f );
	BoxItem.Draw( Canvas );
	
	// Triangle
	FCanvasTriangleItem TriItem(  FVector2D( 48.0f, 48.0f ), FVector2D( 148.0f, 48.0f ), FVector2D( 48.0f, 148.0f ), GWhiteTexture );
	TriItem.Draw( Canvas );

	// Triangle list
	TArray< FCanvasUVTri >	TriangleList;
	FCanvasUVTri SingleTri;
	SingleTri.V0_Pos = FVector2D( 128.0f, 128.0f );
	SingleTri.V1_Pos = FVector2D( 248.0f, 108.0f );
	SingleTri.V2_Pos = FVector2D( 100.0f, 348.0f );
	SingleTri.V0_UV = FVector2D::ZeroVector;
	SingleTri.V1_UV = FVector2D::ZeroVector;
	SingleTri.V2_UV = FVector2D::ZeroVector;
	TriangleList.Add( SingleTri );
	SingleTri.V0_Pos = FVector2D( 348.0f, 128.0f );
	SingleTri.V1_Pos = FVector2D( 448.0f, 148.0f );
	SingleTri.V2_Pos = FVector2D( 438.0f, 308.0f );
	TriangleList.Add( SingleTri );

	FCanvasTriangleItem TriItemList( TriangleList, GWhiteTexture );
	TriItemList.SetColor( FLinearColor::Red );
	TriItemList.Draw( Canvas );
	
// 	FCanvasNGonItem NGon( FVector2D( 256.0f, 256.0f ), FVector2D( 256.0f, 256.0f ), 6, GWhiteTexture, FLinearColor::White );
// 	NGon.Draw( Canvas );
// 
// 	FCanvasNGonItem NGon2( FVector2D( 488, 666.0f ), FVector2D( 256.0f, 256.0f ), 16, GWhiteTexture, FLinearColor::Green );
// 	NGon2.Draw( Canvas );

	// Texture
	UTexture* SelectedTexture = GEditor->GetSelectedObjects()->GetTop<UTexture>();	
	if( SelectedTexture )
	{
		// Plain tex
		FCanvasTileItem TileItem( FVector2D( 128.0f,128.0f ), SelectedTexture->Resource, FLinearColor::White );
		TileItem.Draw( Canvas );
		TileItem.Size = FVector2D( 32.0f,32.0f );
		TileItem.Position = FVector2D( 16.0f,16.0f );
		TileItem.Draw( Canvas );

		// UV 
		TileItem.Size = FVector2D( 64.0f,64.0f );
		TileItem.UV0 = FVector2D( 0.0f, 0.0f );
		TileItem.UV1 = FVector2D( 1.0f, 1.0f );
		TileItem.Position = FVector2D( 256.0f,16.0f );
		TileItem.Draw( Canvas );

		// UV 
		TileItem.Size = FVector2D( 64.0f,64.0f );
		TileItem.UV0 = FVector2D( 0.0f, 0.0f );
		TileItem.UV1 = FVector2D( 1.0f, -1.0f );
		TileItem.Position = FVector2D( 356.0f,16.0f );
		TileItem.Draw( Canvas );

		// UV 
		TileItem.Size = FVector2D( 64.0f,64.0f );
		TileItem.UV0 = FVector2D( 0.0f, 0.0f );
		TileItem.UV1 = FVector2D( -1.0f, 1.0f );
		TileItem.Position = FVector2D( 456.0f,16.0f );
		TileItem.Draw( Canvas );

		// UV 
		TileItem.Size = FVector2D( 64.0f,64.0f );
		TileItem.UV0 = FVector2D( 0.0f, 0.0f );
		TileItem.UV1 = FVector2D( -1.0f, -1.0f );
		TileItem.Position = FVector2D( 556.0f,16.0f );
		TileItem.Draw( Canvas );

		// Rotate top/left pivot
		TileItem.Size = FVector2D( 96.0f,96.0f );
		TileItem.UV0 = FVector2D( 0.0f, 0.0f );
		TileItem.UV1 = FVector2D( 1.0f, 1.0f );
		TileItem.Position = FVector2D( 400.0f,264.0f );
		TileItem.Rotation.Yaw = TestLine.Testangle;
		TileItem.Draw( Canvas );

		// Rotate center pivot
		TileItem.Size = FVector2D( 128.0f, 128.0f );
		TileItem.UV0 = FVector2D( 0.0f, 0.0f );
		TileItem.UV1 = FVector2D( 1.0f, 1.0f );
		TileItem.Position = FVector2D( 600.0f,264.0f );
		TileItem.Rotation.Yaw = 360.0f - TestLine.Testangle;
		TileItem.PivotPoint = FVector2D( 0.5f, 0.5f );
		TileItem.Draw( Canvas );

		TestLine.Testangle = FMath::Fmod( TestLine.Testangle + 2.0f, 360.0f );

		// textured tri
		FCanvasTriangleItem TriItemTex(  FVector2D( 48.0f, 48.0f ), FVector2D( 148.0f, 48.0f ), FVector2D( 48.0f, 148.0f ), FVector2D( 0.0f, 0.0f ), FVector2D( 1.0f, 0.0f ), FVector2D( 0.0f, 1.0f ), SelectedTexture->Resource  );
		TriItem.Texture = GWhiteTexture;
		TriItemTex.Draw( Canvas );

		// moving tri (only 1 point moves !)
		TriItemTex.Position = TestLine.LineStart;
		TriItemTex.Draw( Canvas );
	}
}
Ejemplo n.º 21
0
void AStrategyHUD::DrawMiniMap()
{
	const AStrategyPlayerController* const PC = Cast<AStrategyPlayerController>(PlayerOwner);
	AStrategyGameState const* const MyGameState = GetWorld()->GetGameState<AStrategyGameState>();

	// @todo, clean this up
	if (PC && MyGameState && MyGameState->MiniMapCamera.IsValid())
	{
		const float BaseRotation = 270;
		UTexture* MiniMapTexture = Cast<UTexture>(MyGameState->MiniMapCamera->GetCaptureComponent2D()->TextureTarget);
		const float MapWidth = (MyGameState->MiniMapCamera->MiniMapWidth - MiniMapMargin) * UIScale;
		const float MapHeight = (MyGameState->MiniMapCamera->MiniMapHeight - MiniMapMargin) * UIScale;
		const FVector WorldCenter = MyGameState->WorldBounds.GetCenter();
		const FVector WorldExtent = MyGameState->WorldBounds.GetExtent();
		const FRotator RotOrg = MyGameState->MiniMapCamera->GetCaptureComponent2D()->GetComponentRotation();
		const FRotationMatrix RotationMatrix(FRotator(0,BaseRotation-RotOrg.Roll,0));
		const FVector2D Offset(MiniMapMargin * UIScale + (MapWidth/2.0f), Canvas->ClipY - (MapHeight/2.0f) - MiniMapMargin * UIScale );

		if (MiniMapTexture)
		{
			FCanvasTileItem MapTileItem( FVector2D( 0.0f, 0.0f), FVector2D( 0.0f, 0.0f ), FLinearColor::White );
			MapTileItem.Texture = MiniMapTexture->Resource;
			MapTileItem.Size = FVector2D( MapWidth, MapHeight );
			MapTileItem.BlendMode = SE_BLEND_Opaque;
			Canvas->DrawItem( MapTileItem, FVector2D( MiniMapMargin * UIScale, Canvas->ClipY - MapHeight - MiniMapMargin * UIScale ) );
		}
		FCanvasTileItem TileItem( FVector2D( 0.0f, 0.0f), FVector2D( 0.0f, 0.0f ), FLinearColor::White );
		TileItem.Size = FVector2D( 6 * UIScale, 6 * UIScale );
		for (FConstPawnIterator Iterator = GetWorld()->GetPawnIterator(); Iterator; ++Iterator)
		{
			AStrategyChar* TestChar = Cast<AStrategyChar>(*Iterator);
			if (TestChar != NULL && TestChar->GetHealth() > 0 )
			{
				AStrategyAIController* AIController = Cast<AStrategyAIController>(TestChar->Controller);
				if (AIController != NULL && AIController->IsLogicEnabled())
				{
					FLinearColor DrawColor;
					if (PC != NULL && TestChar->GetTeamNum() == PC->GetTeamNum())
					{
						DrawColor = FColor( 49, 137, 253, 255);
					} 
					else
					{
						DrawColor = FColor( 242, 114, 16, 255);
					}
					const FVector CenterRelativeLocation = RotationMatrix.TransformPosition(TestChar->GetActorLocation() - WorldCenter);
					const FVector2D MiniMapPoint = FVector2D(CenterRelativeLocation.X / WorldExtent.X, CenterRelativeLocation.Y / WorldExtent.Y);
					TileItem.SetColor( DrawColor );
					Canvas->DrawItem( TileItem, FVector2D( Offset.X + MiniMapPoint.X * (MapWidth/2.0f), Offset.Y + MiniMapPoint.Y * (MapHeight/2.0f) ) );
				}
			}
		}


		ULocalPlayer* MyPlayer =  Cast<ULocalPlayer>(PC->Player);
		FVector2D ScreenCorners[4] = { FVector2D(0, 0), FVector2D(Canvas->ClipX, 0), FVector2D(Canvas->ClipX, Canvas->ClipY), FVector2D(0, Canvas->ClipY) };
		const FPlane GroundPlane = FPlane(FVector(0, 0, MyGameState->WorldBounds.Max.Z), FVector::UpVector);
		for (int32 i = 0; i < 4; i++)
		{
			FVector RayOrigin, RayDirection;
			FStrategyHelpers::DeprojectScreenToWorld(ScreenCorners[i], MyPlayer, RayOrigin, RayDirection);
			const FVector GroundPoint = FStrategyHelpers::IntersectRayWithPlane(RayOrigin, RayDirection, GroundPlane);
			const FVector CenterRelativeLocation = RotationMatrix.TransformPosition(GroundPoint - WorldCenter);
			MiniMapPoints[i] = FVector2D(CenterRelativeLocation.X / WorldExtent.X, CenterRelativeLocation.Y / WorldExtent.Y);
		}
	} 
}
void AGameplayDebuggerReplicator::DrawMenu(UGameplayDebuggerBaseObject::FPrintContext& DefaultContext, UGameplayDebuggerBaseObject::FPrintContext& OverHeadContext)
{
#if ENABLED_GAMEPLAY_DEBUGGER
	const float OldX = DefaultContext.CursorX;
	const float OldY = DefaultContext.CursorY;

	const UGameplayDebuggerModuleSettings* GameplayDebuggerSettings = UGameplayDebuggerModuleSettings::StaticClass()->GetDefaultObject<UGameplayDebuggerModuleSettings>();
	const float MenuStartX = GameplayDebuggerSettings->MenuStart.X;
	const float MenuStartY = GameplayDebuggerSettings->MenuStart.Y;

	if (DefaultContext.Canvas != nullptr)
	{
		UFont* OldFont = DefaultContext.Font.Get();
		DefaultContext.Font = GEngine->GetMediumFont();

		TArray<float> CategoriesWidth;
		CategoriesWidth.AddZeroed(Categories.Num());

		APlayerController* const MyPC = Cast<APlayerController>(LocalPlayerOwner);

		FString KeyDesc = ActivationKeyName != ActivationKeyDisplayName ? FString::Printf(TEXT("(%s key)"), *ActivationKeyName) : TEXT("");
		FString HeaderDesc;
		if (UGameplayDebuggerModuleSettings::StaticClass()->GetDefaultObject<UGameplayDebuggerModuleSettings>()->UseAlternateKeys())
		{
			HeaderDesc = FString::Printf(TEXT("{LightBlue}Tap {white}%s %s {LightBlue}to close, {white}Alt + number {LightBlue}to toggle categories, use {white}+ {LightBlue}or {white}- {LightBlue}to select active line with categories"), *ActivationKeyDisplayName, *KeyDesc);
		}
		else
		{
			HeaderDesc = FString::Printf(TEXT("{LightBlue}Use {white}%s %s{LightBlue} to close, {white}Numpad numbers {LightBlue}to toggle categories or use {white}+ {LightBlue}and {white}- {LightBlue}to select active line with categories"), *ActivationKeyDisplayName, *KeyDesc);
		}

		FString DefaultMenu;
		{
			DefaultMenu += FString::Printf(TEXT(" {white}[Tab]: %s%s  "), DebugCameraController.IsValid() ? TEXT("{Green}") : TEXT("{LightBlue}"), TEXT("Debug Camera"));
		}
		{
			DefaultMenu += FString::Printf(TEXT(" {white}[Ctrl+Tab]: %s%s  "), GEngine && GEngine->bEnableOnScreenDebugMessages ? TEXT("{Green}") : TEXT("{LightBlue}"), TEXT("DebugMessages"));
		}
		{
			const AHUD* GameHUD = MyPC ? MyPC->GetHUD() : nullptr;
			DefaultMenu += FString::Printf(TEXT(" {white}[Ctrl+Tilde]: %s%s  "), GameHUD && GameHUD->bShowHUD ? TEXT("{Green}") : TEXT("{LightBlue}"), TEXT("GameHUD"));
		}
		{
			KeyDesc = UGameplayDebuggerModuleSettings::StaticClass()->GetDefaultObject<UGameplayDebuggerModuleSettings>()->GetInputConfiguration().SelectPlayer.Key.GetFName().ToString();
			const bool SelectedPlayer = MyPC && MyPC->GetPawnOrSpectator() && LastSelectedActorToDebug == MyPC->GetPawnOrSpectator();
			DefaultMenu += FString::Printf(TEXT(" {white}[%s]: %sPlayer  "), *KeyDesc, SelectedPlayer ? TEXT("{Green}") : TEXT("{LightBlue}"));
		}

		FString MenuString = HeaderDesc + TEXT("\n") + DefaultMenu + TEXT("\n");
		const int32 NumberOfLines = Categories.Num() / 10 + 1;
		for (int32 LineIndex = 0; LineIndex < NumberOfLines; ++LineIndex)
		{
			const int32 ItemsInLine = FMath::Clamp(Categories.Num() - LineIndex * 10, 0, 10);
			for (int32 MenuItemIndex = 0; MenuItemIndex < ItemsInLine; ++MenuItemIndex)
			{
				const int32 i = LineIndex * 10 + MenuItemIndex;

				const bool bIsActive = IsCategoryEnabled(Categories[i].CategoryName);
				const bool bIsDisabled = LastSelectedActorToDebug == nullptr;
				const FString CategoryColor = bIsDisabled ? (bIsActive ? TEXT("DarkGreen") : TEXT("LightGrey")) : (bIsActive ? TEXT("Green") : TEXT("LightBlue"));
				if (CurrentMenuLine == LineIndex)
				{
					MenuString += FString::Printf(TEXT("   {white}%d:{%s}%s "), MenuItemIndex, *CategoryColor, *Categories[i].CategoryName);
				}
				else
				{
					MenuString += FString::Printf(TEXT("   {%s}%s "), *CategoryColor, *Categories[i].CategoryName);
				}
			}
			MenuString += TEXT(" \n");
		}
		float MenuWidth, MenuHeight;
		UGameplayDebuggerBaseObject::CalulateStringSize(DefaultContext, nullptr, MenuString, MenuWidth, MenuHeight);
		MaxMenuWidth = FMath::Max(MaxMenuWidth, MenuWidth+4);
		MenuHeight += 4;

		FCanvasTileItem TileItem(FVector2D(0, 0), GWhiteTexture, FVector2D(MaxMenuWidth, MenuHeight), FColor(0, 0, 0, 30));
		TileItem.BlendMode = SE_BLEND_Translucent;
		UGameplayDebuggerBaseObject::DrawItem(DefaultContext, TileItem, MenuStartX, MenuStartY);

		float CharWidth, CharHeight;
		UGameplayDebuggerBaseObject::CalulateStringSize(DefaultContext, nullptr, TEXT("X"), CharWidth, CharHeight);
		TileItem = FCanvasTileItem(FVector2D(0, 0), GWhiteTexture, FVector2D(MaxMenuWidth, CharHeight), FColor(0, 0, 0, 50));
		TileItem.BlendMode = SE_BLEND_Translucent;
		UGameplayDebuggerBaseObject::DrawItem(DefaultContext, TileItem, MenuStartX, MenuStartY + 2 + (CurrentMenuLine+2) * CharHeight);
		UGameplayDebuggerBaseObject::PrintString(DefaultContext, MenuString, MenuStartX + 2, MenuStartY + 2);

		DefaultContext.Font = OldFont;
	}

	if (LastSelectedActorToDebug == nullptr)
	{
		UGameplayDebuggerBaseObject::PrintString(DefaultContext, "{red}No Pawn selected - waiting for data to replicate from server. {green}Press and hold ' to select Pawn \n");
	}

	if (DebugCameraController.IsValid())
	{
		ADebugCameraController* DebugCamController = DebugCameraController.Get();
		if (DebugCamController != nullptr)
		{
			FVector const CamLoc = DebugCamController->PlayerCameraManager->GetCameraLocation();
			FRotator const CamRot = DebugCamController->PlayerCameraManager->GetCameraRotation();

			FString HitString;
			FCollisionQueryParams TraceParams(NAME_None, true, this);
			FHitResult Hit;
			bool bHit = GetWorld()->LineTraceSingleByChannel(Hit, CamLoc, CamRot.Vector() * 100000.f + CamLoc, ECC_Pawn, TraceParams);
			if (bHit && Hit.GetActor() != nullptr)
			{
				HitString = FString::Printf(TEXT("{white}Under cursor: {yellow}'%s'"), *Hit.GetActor()->GetName());
				DrawDebugLine(GetWorld(), Hit.Location, Hit.Location + Hit.Normal*60.f, FColor::White, /*bPersistentLines =*/ false, /*LifeTime =*/ -1.f, /*DepthPriority =*/ 0, /*Thickness =*/ 3.f);
			}
			else
			{
				HitString = FString::Printf(TEXT("Not actor under cursor"));
			}

			UGameplayDebuggerBaseObject::PrintString(DefaultContext, FColor::White, HitString/*, MenuStartX, MenuStartY + 40*/);
		}
	}


	DefaultContext.CursorX = OldX;
	DefaultContext.CursorY = OldY;
#endif //ENABLED_GAMEPLAY_DEBUGGER
}
Ejemplo n.º 23
0
void FEdMode::DrawHUD(FEditorViewportClient* ViewportClient,FViewport* Viewport,const FSceneView* View,FCanvas* Canvas)
{
    // Render the drag tool.
    ViewportClient->RenderDragTool( View, Canvas );

    // Let the current mode tool draw a HUD if it wants to
    FModeTool* tool = GetCurrentTool();
    if( tool )
    {
        tool->DrawHUD( ViewportClient, Viewport, View, Canvas );
    }

    if (ViewportClient->IsPerspective() && GetDefault<ULevelEditorViewportSettings>()->bHighlightWithBrackets)
    {
        DrawBrackets( ViewportClient, Viewport, View, Canvas );
    }

    // If this viewport doesn't show mode widgets or the mode itself doesn't want them, leave.
    if( !(ViewportClient->EngineShowFlags.ModeWidgets) || !ShowModeWidgets() )
    {
        return;
    }

    // Clear Hit proxies
    const bool bIsHitTesting = Canvas->IsHitTesting();
    if ( !bIsHitTesting )
    {
        Canvas->SetHitProxy(NULL);
    }

    // Draw vertices for selected BSP brushes and static meshes if the large vertices show flag is set.
    if ( !ViewportClient->bDrawVertices )
    {
        return;
    }

    const bool bLargeVertices		= View->Family->EngineShowFlags.LargeVertices;
    const bool bShowBrushes			= View->Family->EngineShowFlags.Brushes;
    const bool bShowBSP				= View->Family->EngineShowFlags.BSP;
    const bool bShowBuilderBrush	= View->Family->EngineShowFlags.BuilderBrush != 0;

    UTexture2D* VertexTexture = GetVertexTexture();
    const float TextureSizeX		= VertexTexture->GetSizeX() * ( bLargeVertices ? 1.0f : 0.5f );
    const float TextureSizeY		= VertexTexture->GetSizeY() * ( bLargeVertices ? 1.0f : 0.5f );

    // Temporaries.
    TArray<FVector> Vertices;

    for ( FSelectionIterator It( *Owner->GetSelectedActors() ) ; It ; ++It )
    {
        AActor* SelectedActor = static_cast<AActor*>( *It );
        checkSlow( SelectedActor->IsA(AActor::StaticClass()) );

        if( bLargeVertices )
        {
            FCanvasItemTestbed::bTestState = !FCanvasItemTestbed::bTestState;

            // Static mesh vertices
            AStaticMeshActor* Actor = Cast<AStaticMeshActor>( SelectedActor );
            if( Actor && Actor->GetStaticMeshComponent() && Actor->GetStaticMeshComponent()->StaticMesh
                    && Actor->GetStaticMeshComponent()->StaticMesh->RenderData )
            {
                FTransform ActorToWorld = Actor->ActorToWorld();
                Vertices.Empty();
                const FPositionVertexBuffer& VertexBuffer = Actor->GetStaticMeshComponent()->StaticMesh->RenderData->LODResources[0].PositionVertexBuffer;
                for( uint32 i = 0 ; i < VertexBuffer.GetNumVertices() ; i++ )
                {
                    Vertices.AddUnique( ActorToWorld.TransformPosition( VertexBuffer.VertexPosition(i) ) );
                }

                FCanvasTileItem TileItem( FVector2D( 0.0f, 0.0f ), FVector2D( 0.0f, 0.0f ), FLinearColor::White );
                TileItem.BlendMode = SE_BLEND_Translucent;
                for( int32 VertexIndex = 0 ; VertexIndex < Vertices.Num() ; ++VertexIndex )
                {
                    const FVector& Vertex = Vertices[VertexIndex];
                    FVector2D PixelLocation;
                    if(View->ScreenToPixel(View->WorldToScreen(Vertex),PixelLocation))
                    {
                        const bool bOutside =
                            PixelLocation.X < 0.0f || PixelLocation.X > View->ViewRect.Width() ||
                            PixelLocation.Y < 0.0f || PixelLocation.Y > View->ViewRect.Height();
                        if( !bOutside )
                        {
                            const float X = PixelLocation.X - (TextureSizeX/2);
                            const float Y = PixelLocation.Y - (TextureSizeY/2);
                            if( bIsHitTesting )
                            {
                                Canvas->SetHitProxy( new HStaticMeshVert(Actor,Vertex) );
                            }
                            TileItem.Texture = VertexTexture->Resource;

                            TileItem.Size = FVector2D( TextureSizeX, TextureSizeY );
                            Canvas->DrawItem( TileItem, FVector2D( X, Y ) );
                            if( bIsHitTesting )
                            {
                                Canvas->SetHitProxy( NULL );
                            }
                        }
                    }
                }
            }
        }
    }

    if(UsesPropertyWidgets())
    {
        AActor* SelectedActor = GetFirstSelectedActorInstance();
        if (SelectedActor != NULL)
        {
            FEditorScriptExecutionGuard ScriptGuard;

            const int32 HalfX = 0.5f * Viewport->GetSizeXY().X;
            const int32 HalfY = 0.5f * Viewport->GetSizeXY().Y;

            UClass* Class = SelectedActor->GetClass();
            TArray<FPropertyWidgetInfo> WidgetInfos;
            GetPropertyWidgetInfos(Class, SelectedActor, WidgetInfos);
            for(int32 i=0; i<WidgetInfos.Num(); i++)
            {
                FString WidgetName = WidgetInfos[i].PropertyName;
                FName WidgetValidator = WidgetInfos[i].PropertyValidationName;
                int32 WidgetIndex = WidgetInfos[i].PropertyIndex;
                bool bIsTransform = WidgetInfos[i].bIsTransform;

                FVector LocalPos = FVector::ZeroVector;
                if(bIsTransform)
                {
                    FTransform LocalTM = GetPropertyValueByName<FTransform>(SelectedActor, WidgetName, WidgetIndex);
                    LocalPos = LocalTM.GetLocation();
                }
                else
                {
                    LocalPos = GetPropertyValueByName<FVector>(SelectedActor, WidgetName, WidgetIndex);
                }

                FTransform ActorToWorld = SelectedActor->ActorToWorld();
                FVector WorldPos = ActorToWorld.TransformPosition(LocalPos);

                UFunction* ValidateFunc = NULL;
                FString FinalString;
                if(WidgetValidator != NAME_None &&
                        (ValidateFunc = SelectedActor->FindFunction(WidgetValidator)) != NULL)
                {
                    SelectedActor->ProcessEvent(ValidateFunc, &FinalString);
                }

                const FPlane Proj = View->Project( WorldPos );

                //do some string fixing
                const uint32 VectorIndex = WidgetInfos[i].PropertyIndex;
                const FString WidgetDisplayName = WidgetInfos[i].DisplayName + ((VectorIndex != INDEX_NONE) ? FString::Printf(TEXT("[%d]"), VectorIndex) : TEXT(""));
                FinalString = FinalString.IsEmpty() ? WidgetDisplayName : FinalString;

                if(Proj.W > 0.f)
                {
                    const int32 XPos = HalfX + ( HalfX * Proj.X );
                    const int32 YPos = HalfY + ( HalfY * (Proj.Y * -1.f) );
                    FCanvasTextItem TextItem( FVector2D( XPos + 5, YPos), FText::FromString( FinalString ), GEngine->GetSmallFont(), FLinearColor::White );
                    Canvas->DrawItem( TextItem );
                }
            }
        }
    }
}
void FTextureEditorViewportClient::Draw(FViewport* Viewport, FCanvas* Canvas)
{
	if (!TextureEditorPtr.IsValid())
	{
		return;
	}
	
	UTexture* Texture = TextureEditorPtr.Pin()->GetTexture();
	FVector2D Ratio = FVector2D(GetViewportHorizontalScrollBarRatio(), GetViewportVerticalScrollBarRatio());
	FVector2D ViewportSize = FVector2D(TextureEditorViewportPtr.Pin()->GetViewport()->GetSizeXY().X, TextureEditorViewportPtr.Pin()->GetViewport()->GetSizeXY().Y);
	FVector2D ScrollBarPos = GetViewportScrollBarPositions();
	int32 YOffset = (Ratio.Y > 1.0f)? ((ViewportSize.Y - (ViewportSize.Y / Ratio.Y)) * 0.5f): 0;
	int32 YPos = YOffset - ScrollBarPos.Y;
	int32 XOffset = (Ratio.X > 1.0f)? ((ViewportSize.X - (ViewportSize.X / Ratio.X)) * 0.5f): 0;
	int32 XPos = XOffset - ScrollBarPos.X;
	
	UpdateScrollBars();

	const UTextureEditorSettings& Settings = *GetDefault<UTextureEditorSettings>();

	Canvas->Clear( Settings.BackgroundColor );

	TextureEditorPtr.Pin()->PopulateQuickInfo();
	
	// Get the rendering info for this object
	FThumbnailRenderingInfo* RenderInfo = GUnrealEd->GetThumbnailManager()->GetRenderingInfo(Texture);

	// If there is an object configured to handle it, draw the thumbnail
	if (RenderInfo != NULL && RenderInfo->Renderer != NULL)
	{
		UTexture2D* Texture2D = Cast<UTexture2D>(Texture);
		UTextureCube* TextureCube = Cast<UTextureCube>(Texture);
		UTextureRenderTarget2D* TextureRT2D = Cast<UTextureRenderTarget2D>(Texture);
		UTextureRenderTargetCube* RTTextureCube = Cast<UTextureRenderTargetCube>(Texture);

		// Fully stream in the texture before drawing it.
		if (Texture2D)
		{
			Texture2D->SetForceMipLevelsToBeResident(30.0f);
			Texture2D->WaitForStreaming();
		}

		// Figure out the size we need
		uint32 Width, Height;
		TextureEditorPtr.Pin()->CalculateTextureDimensions(Width, Height);

		TRefCountPtr<FBatchedElementParameters> BatchedElementParameters;

		if (GMaxRHIFeatureLevel >= ERHIFeatureLevel::SM4)
		{
			if (TextureCube || RTTextureCube)
			{
				BatchedElementParameters = new FMipLevelBatchedElementParameters((float)TextureEditorPtr.Pin()->GetMipLevel(), false);
			}
			else if (Texture2D)
			{
				float MipLevel = (float)TextureEditorPtr.Pin()->GetMipLevel();
				bool bIsNormalMap = Texture2D->IsNormalMap();
				bool bIsSingleChannel = Texture2D->CompressionSettings == TC_Grayscale || Texture2D->CompressionSettings == TC_Alpha;
				BatchedElementParameters = new FBatchedElementTexture2DPreviewParameters(MipLevel, bIsNormalMap, bIsSingleChannel);
			}
			else if (TextureRT2D)
			{
				float MipLevel = (float)TextureEditorPtr.Pin()->GetMipLevel();
				BatchedElementParameters = new FBatchedElementTexture2DPreviewParameters(MipLevel, false, false);
			}
			else
			{
				// Default to treating any UTexture derivative as a 2D texture resource
				float MipLevel = (float)TextureEditorPtr.Pin()->GetMipLevel();
				BatchedElementParameters = new FBatchedElementTexture2DPreviewParameters(MipLevel, false, false);
			}
		}

		// Draw the background checkerboard pattern in the same size/position as the render texture so it will show up anywhere
		// the texture has transparency
		if (Settings.Background == TextureEditorBackground_CheckeredFill)
		{
			Canvas->DrawTile( 0.0f, 0.0f, Viewport->GetSizeXY().X, Viewport->GetSizeXY().Y, 0.0f, 0.0f, (Viewport->GetSizeXY().X / CheckerboardTexture->GetSizeX()), (Viewport->GetSizeXY().Y / CheckerboardTexture->GetSizeY()), FLinearColor::White, CheckerboardTexture->Resource);
		}
		else if (Settings.Background == TextureEditorBackground_Checkered)
		{
			Canvas->DrawTile( XPos, YPos, Width, Height, 0.0f, 0.0f, (Width / CheckerboardTexture->GetSizeX()), (Height / CheckerboardTexture->GetSizeY()), FLinearColor::White, CheckerboardTexture->Resource);
		}

		float Exposure = FMath::Pow(2.0f, (float)TextureEditorViewportPtr.Pin()->GetExposureBias());

		FCanvasTileItem TileItem( FVector2D( XPos, YPos ), Texture->Resource, FVector2D( Width, Height ), FLinearColor(Exposure, Exposure, Exposure) );
		TileItem.BlendMode = TextureEditorPtr.Pin()->GetColourChannelBlendMode();
		TileItem.BatchedElementParameters = BatchedElementParameters;
		Canvas->DrawItem( TileItem );

		// Draw a white border around the texture to show its extents
		if (Settings.TextureBorderEnabled)
		{
			FCanvasBoxItem BoxItem( FVector2D(XPos, YPos), FVector2D(Width , Height ) );
			BoxItem.SetColor( Settings.TextureBorderColor );
			Canvas->DrawItem( BoxItem );
		}
	}
}
Ejemplo n.º 25
0
	/**
	* Helper function to create an unwrapped 2D image of the cube map ( longitude/latitude )
	* This version takes explicitly passed properties of the source object, as the sources have different APIs.
	* @param	TextureResource		Source FTextureResource object.
	* @param	AxisDimenion		axis length of the cube.
	* @param	SourcePixelFormat	pixel format of the source.
	* @param	BitsOUT				Raw bits of the 2D image bitmap.
	* @param	SizeXOUT			Filled with the X dimension of the output bitmap.
	* @param	SizeYOUT			Filled with the Y dimension of the output bitmap.
	* @return						true on success.
	* @param	FormatOUT			Filled with the pixel format of the output bitmap.
	*/
	bool GenerateLongLatUnwrap(const FTextureResource* TextureResource, const uint32 AxisDimenion, const EPixelFormat SourcePixelFormat, TArray<uint8>& BitsOUT, FIntPoint& SizeOUT, EPixelFormat& FormatOUT)
	{
		TRefCountPtr<FBatchedElementParameters> BatchedElementParameters;
		BatchedElementParameters = new FMipLevelBatchedElementParameters((float)0, true);
		const FIntPoint LongLatDimensions(AxisDimenion * 2, AxisDimenion);

		// If the source format is 8 bit per channel or less then select a LDR target format.
		const EPixelFormat TargetPixelFormat = CalculateImageBytes(1, 1, 0, SourcePixelFormat) <= 4 ? PF_B8G8R8A8 : PF_FloatRGBA;

		UTextureRenderTarget2D* RenderTargetLongLat = NewObject<UTextureRenderTarget2D>();
		check(RenderTargetLongLat);
		RenderTargetLongLat->AddToRoot();
		RenderTargetLongLat->ClearColor = FLinearColor(0.0f, 0.0f, 0.0f, 0.0f);
		RenderTargetLongLat->InitCustomFormat(LongLatDimensions.X, LongLatDimensions.Y, TargetPixelFormat, false);
		RenderTargetLongLat->TargetGamma = 0;
		FRenderTarget* RenderTarget = RenderTargetLongLat->GameThread_GetRenderTargetResource();

		FCanvas* Canvas = new FCanvas(RenderTarget, NULL, 0, 0, 0, GMaxRHIFeatureLevel);
		Canvas->SetRenderTarget_GameThread(RenderTarget);

		// Clear the render target to black
		Canvas->Clear(FLinearColor(0, 0, 0, 0));

		FCanvasTileItem TileItem(FVector2D(0.0f, 0.0f), TextureResource, FVector2D(LongLatDimensions.X, LongLatDimensions.Y), FLinearColor::White);
		TileItem.BatchedElementParameters = BatchedElementParameters;
		TileItem.BlendMode = SE_BLEND_Opaque;
		Canvas->DrawItem(TileItem);

		Canvas->Flush_GameThread();
		FlushRenderingCommands();
		Canvas->SetRenderTarget_GameThread(NULL);
		FlushRenderingCommands();
		
		int32 ImageBytes = CalculateImageBytes(LongLatDimensions.X, LongLatDimensions.Y, 0, TargetPixelFormat);

		BitsOUT.AddUninitialized(ImageBytes);

		bool bReadSuccess = false;
		switch (TargetPixelFormat)
		{
			case PF_B8G8R8A8:
				bReadSuccess = RenderTarget->ReadPixelsPtr((FColor*)BitsOUT.GetData());
			break;
			case PF_FloatRGBA:
				{
					TArray<FFloat16Color> FloatColors;
					bReadSuccess = RenderTarget->ReadFloat16Pixels(FloatColors);
					FMemory::Memcpy(BitsOUT.GetData(), FloatColors.GetData(), ImageBytes);
				}
			break;
		}
		// Clean up.
		RenderTargetLongLat->RemoveFromRoot();
		RenderTargetLongLat = NULL;
		delete Canvas;

		SizeOUT = LongLatDimensions;
		FormatOUT = TargetPixelFormat;
		if (bReadSuccess == false)
		{
			// Reading has failed clear output buffer.
			BitsOUT.Empty();
		}

		return bReadSuccess;
	}
void AGameplayDebuggingHUDComponent::DrawEQSData(APlayerController* PC, class UGameplayDebuggingComponent *DebugComponent)
{
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) && WITH_EQS
	PrintString(DefaultContext, TEXT("\n{green}EQS {white}[Use + key to switch query]\n"));

	if (DebugComponent->EQSLocalData.Num() == 0)
	{
		return;
	}

	const int32 EQSIndex = DebugComponent->EQSLocalData.Num() > 0 ? FMath::Clamp(DebugComponent->CurrentEQSIndex, 0, DebugComponent->EQSLocalData.Num() - 1) : INDEX_NONE;
	if (!DebugComponent->EQSLocalData.IsValidIndex(EQSIndex))
	{
		return;
	}

	{
		int32 Index = 0;
		PrintString(DefaultContext, TEXT("{white}Queries: "));
		for (auto CurrentQuery : DebugComponent->EQSLocalData)
		{
			if (EQSIndex == Index)
			{
				PrintString(DefaultContext, FString::Printf(TEXT("{green}%s, "), *CurrentQuery.Name));
			}
			else
			{
				PrintString(DefaultContext, FString::Printf(TEXT("{yellow}%s, "), *CurrentQuery.Name));
			}
			Index++;
		}
		PrintString(DefaultContext, TEXT("\n"));
	}

	auto& CurrentLocalData = DebugComponent->EQSLocalData[EQSIndex];

	/** find and draw item selection */
	int32 BestItemIndex = INDEX_NONE;
	{
		APlayerController* const MyPC = Cast<APlayerController>(PlayerOwner);
		FVector CamLocation;
		FVector FireDir;
		if (!MyPC->GetSpectatorPawn())
		{
			FRotator CamRotation;
			MyPC->GetPlayerViewPoint(CamLocation, CamRotation);
			FireDir = CamRotation.Vector();
		}
		else
		{
			FireDir = DefaultContext.Canvas->SceneView->GetViewDirection();
			CamLocation = DefaultContext.Canvas->SceneView->ViewMatrices.ViewOrigin;
		}

		float bestAim = 0;
		for (int32 Index = 0; Index < CurrentLocalData.RenderDebugHelpers.Num(); ++Index)
		{
			auto& CurrentItem = CurrentLocalData.RenderDebugHelpers[Index];

			const FVector AimDir = CurrentItem.Location - CamLocation;
			float FireDist = AimDir.SizeSquared();

			FireDist = FMath::Sqrt(FireDist);
			float newAim = FireDir | AimDir;
			newAim = newAim / FireDist;
			if (newAim > bestAim)
			{
				BestItemIndex = Index;
				bestAim = newAim;
			}
		}

		if (BestItemIndex != INDEX_NONE)
		{
			DrawDebugSphere(World, CurrentLocalData.RenderDebugHelpers[BestItemIndex].Location, CurrentLocalData.RenderDebugHelpers[BestItemIndex].Radius, 8, FColor::Red, false);
			int32 FailedTestIndex = CurrentLocalData.RenderDebugHelpers[BestItemIndex].FailedTestIndex;
			if (FailedTestIndex != INDEX_NONE)
			{
				PrintString(DefaultContext, FString::Printf(TEXT("{red}Selected item failed with test %d: {yellow}%s {LightBlue}(%s)\n")
					, FailedTestIndex
					, *CurrentLocalData.Tests[FailedTestIndex].ShortName
					, *CurrentLocalData.Tests[FailedTestIndex].Detailed
					));
				PrintString(DefaultContext, FString::Printf(TEXT("{white}'%s' with score %3.3f\n\n"), *CurrentLocalData.RenderDebugHelpers[BestItemIndex].AdditionalInformation, CurrentLocalData.RenderDebugHelpers[BestItemIndex].FailedScore));
			}
		}
	}

	PrintString(DefaultContext, FString::Printf(TEXT("{white}Timestamp: {yellow}%.3f (%.2fs ago)\n")
		, CurrentLocalData.Timestamp, PC->GetWorld()->GetTimeSeconds() - CurrentLocalData.Timestamp
		));
	PrintString(DefaultContext, FString::Printf(TEXT("{white}Query ID: {yellow}%d\n")
		, CurrentLocalData.Id
		));

	PrintString(DefaultContext, FString::Printf(TEXT("{white}Query contains %d options: "), CurrentLocalData.Options.Num()));
	for (int32 OptionIndex = 0; OptionIndex < CurrentLocalData.Options.Num(); ++OptionIndex)
	{
		if (OptionIndex == CurrentLocalData.UsedOption)
		{
			PrintString(DefaultContext, FString::Printf(TEXT("{green}%s, "), *CurrentLocalData.Options[OptionIndex]));
		}
		else
		{
			PrintString(DefaultContext, FString::Printf(TEXT("{yellow}%s, "), *CurrentLocalData.Options[OptionIndex]));
		}
	}
	PrintString(DefaultContext, TEXT("\n"));

	const float RowHeight = 20.0f;
	const int32 NumTests = CurrentLocalData.Tests.Num();
	if (CurrentLocalData.NumValidItems > 0 && GetDebuggingReplicator()->EnableEQSOnHUD )
	{
		// draw test weights for best X items
		const int32 NumItems = CurrentLocalData.Items.Num();

		FCanvasTileItem TileItem(FVector2D(0, 0), GWhiteTexture, FVector2D(Canvas->SizeX, RowHeight), FLinearColor::Black);
		FLinearColor ColorOdd(0, 0, 0, 0.6f);
		FLinearColor ColorEven(0, 0, 0.4f, 0.4f);
		TileItem.BlendMode = SE_BLEND_Translucent;

		// table header		
		{
			DefaultContext.CursorY += RowHeight;
			const float HeaderY = DefaultContext.CursorY + 3.0f;
			TileItem.SetColor(ColorOdd);
			DrawItem(DefaultContext, TileItem, 0, DefaultContext.CursorY);

			float HeaderX = DefaultContext.CursorX;
			PrintString(DefaultContext, FColor::Yellow, FString::Printf(TEXT("Num items: %d"), CurrentLocalData.NumValidItems), HeaderX, HeaderY);
			HeaderX += ItemDescriptionWidth;

			PrintString(DefaultContext, FColor::White, TEXT("Score"), HeaderX, HeaderY);
			HeaderX += ItemScoreWidth;

			for (int32 TestIdx = 0; TestIdx < NumTests; TestIdx++)
			{
				PrintString(DefaultContext, FColor::White, FString::Printf(TEXT("Test %d"), TestIdx), HeaderX, HeaderY);
				HeaderX += TestScoreWidth;
			}

			DefaultContext.CursorY += RowHeight;
		}

		// valid items
		for (int32 Idx = 0; Idx < NumItems; Idx++)
		{
			TileItem.SetColor((Idx % 2) ? ColorOdd : ColorEven);
			DrawItem(DefaultContext, TileItem, 0, DefaultContext.CursorY);

			DrawEQSItemDetails(Idx, DebugComponent);
			DefaultContext.CursorY += RowHeight;
		}
		DefaultContext.CursorY += RowHeight;
	}

	// test description
	PrintString(DefaultContext, TEXT("All tests from used option:\n"));
	for (int32 TestIdx = 0; TestIdx < NumTests; TestIdx++)
	{
		FString TestDesc = FString::Printf(TEXT("{white}Test %d = {yellow}%s {LightBlue}(%s)\n"), TestIdx,
			*CurrentLocalData.Tests[TestIdx].ShortName,
			*CurrentLocalData.Tests[TestIdx].Detailed);

		PrintString(DefaultContext, TestDesc);
	}

#endif //!(UE_BUILD_SHIPPING || UE_BUILD_TEST)
}
void AGameplayDebuggingHUDComponent::DrawMenu(const float X, const float Y, class UGameplayDebuggingComponent* DebugComponent)
{
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
	const float OldX = DefaultContext.CursorX;
	const float OldY = DefaultContext.CursorY;

	UGameplayDebuggingControllerComponent*  GDC = GetDebuggingReplicator()->FindComponentByClass<UGameplayDebuggingControllerComponent>();
	if (DefaultContext.Canvas != NULL)
	{
		TArray<FDebugCategoryView> Categories;
		GetKeyboardDesc(Categories);

		UFont* OldFont = DefaultContext.Font;
		DefaultContext.Font = GEngine->GetMediumFont();

		TArray<float> CategoriesWidth;
		CategoriesWidth.AddZeroed(Categories.Num());
		float TotalWidth = 0.0f, MaxHeight = 0.0f;

		FString ActivationKeyDisplayName = TEXT("'");
		FString ActivationKeyName = TEXT("Apostrophe");

		APlayerController* const MyPC = Cast<APlayerController>(PlayerOwner);
		if (GDC)
		{
			ActivationKeyDisplayName = GDC->GetActivationKey().Key.GetDisplayName().ToString();
			ActivationKeyName = GDC->GetActivationKey().Key.GetFName().ToString();
		}

		const FString KeyDesc = ActivationKeyName != ActivationKeyDisplayName ? FString::Printf(TEXT("(%s key)"), *ActivationKeyName) : TEXT("");
		FString HeaderDesc = FString::Printf(TEXT("Tap %s %s to close, use Numpad numbers to toggle categories"), *ActivationKeyDisplayName, *KeyDesc);

		float HeaderWidth = 0.0f;
		CalulateStringSize(DefaultContext, DefaultContext.Font, HeaderDesc, HeaderWidth, MaxHeight);

		for (int32 i = 0; i < Categories.Num(); i++)
		{
			Categories[i].Desc = FString::Printf(TEXT("%d:%s "), i, *Categories[i].Desc);

			float StrHeight = 0.0f;
			CalulateStringSize(DefaultContext, DefaultContext.Font, Categories[i].Desc, CategoriesWidth[i], StrHeight);
			TotalWidth += CategoriesWidth[i];
			MaxHeight = FMath::Max(MaxHeight, StrHeight);
		}

		{
			static FString KeyShortcut = GDC->DebugCameraBind.GetInputText().ToString();
			const int32 DebugCameraIndex = Categories.Add(FDebugCategoryView());
			CategoriesWidth.AddZeroed(1);
			Categories[DebugCameraIndex].Desc = FString::Printf(TEXT(" %s[%s]: %s  "), GDC && GDC->GetDebugCameraController().IsValid() ? TEXT("{Green}") : TEXT("{White}"), *KeyShortcut, TEXT("Debug Camera"));
			float StrHeight = 0.0f;
			CalulateStringSize(DefaultContext, DefaultContext.Font, Categories[DebugCameraIndex].Desc, CategoriesWidth[DebugCameraIndex], StrHeight);
			TotalWidth += CategoriesWidth[DebugCameraIndex];
			MaxHeight = FMath::Max(MaxHeight, StrHeight);
		}
		{
			static FString KeyShortcut = GDC->OnScreenDebugMessagesBind.GetInputText().ToString();
			const int32 DebugCameraIndex = Categories.Add(FDebugCategoryView());
			CategoriesWidth.AddZeroed(1);
			Categories[DebugCameraIndex].Desc = FString::Printf(TEXT(" %s[%s]: %s  "), GEngine && GEngine->bEnableOnScreenDebugMessages ? TEXT("{Green}") : TEXT("{White}"), *KeyShortcut, TEXT("DebugMessages"));
			float StrHeight = 0.0f;
			CalulateStringSize(DefaultContext, DefaultContext.Font, Categories[DebugCameraIndex].Desc, CategoriesWidth[DebugCameraIndex], StrHeight);
			TotalWidth += CategoriesWidth[DebugCameraIndex];
			MaxHeight = FMath::Max(MaxHeight, StrHeight);
		}
		{
			static FString KeyShortcut = GDC->GameHUDBind.GetInputText().ToString();
			const AHUD* GameHUD = MyPC ? MyPC->GetHUD() : NULL;
			const int32 DebugCameraIndex = Categories.Add(FDebugCategoryView());
			CategoriesWidth.AddZeroed(1);
			Categories[DebugCameraIndex].Desc = FString::Printf(TEXT(" %s[%s]: %s  "), GameHUD && GameHUD->bShowHUD ? TEXT("{Green}") : TEXT("{White}"), *KeyShortcut, TEXT("GameHUD"));
			float StrHeight = 0.0f;
			CalulateStringSize(DefaultContext, DefaultContext.Font, Categories[DebugCameraIndex].Desc, CategoriesWidth[DebugCameraIndex], StrHeight);
			TotalWidth += CategoriesWidth[DebugCameraIndex];
			MaxHeight = FMath::Max(MaxHeight, StrHeight);
		}


		TotalWidth = FMath::Max(TotalWidth, HeaderWidth);

		FCanvasTileItem TileItem(FVector2D(10, 10), GWhiteTexture, FVector2D(TotalWidth + 20, MaxHeight + 20), FColor(0, 0, 0, 20));
		TileItem.BlendMode = SE_BLEND_Translucent;
		DrawItem(DefaultContext, TileItem, MenuStartX, MenuStartY);

		PrintString(DefaultContext, FColorList::LightBlue, HeaderDesc, MenuStartX + 2.f, MenuStartY + 2.f);

		float XPos = MenuStartX + 20.f;
		for (int32 i = 0; i < Categories.Num(); i++)
		{
			const bool bIsActive = GameplayDebuggerSettings(GetDebuggingReplicator()).CheckFlag(Categories[i].View) ? true : false;
			const bool bIsDisabled = Categories[i].View == EAIDebugDrawDataView::NavMesh ? false : (DebugComponent && DebugComponent->GetSelectedActor() ? false: true);

			PrintString(DefaultContext, bIsDisabled ? (bIsActive ? FColorList::DarkGreen  : FColorList::LightGrey) : (bIsActive ? FColorList::Green : FColorList::White), Categories[i].Desc, XPos, MenuStartY + MaxHeight + 2.f);
			XPos += CategoriesWidth[i];
		}
		DefaultContext.Font = OldFont;
	}

	if ((!DebugComponent || !DebugComponent->GetSelectedActor()) && GetWorld()->GetNetMode() == NM_Client)
	{
		PrintString(DefaultContext, "\n{red}No Pawn selected - waiting for data to replicate from server. {green}Press and hold ' to select Pawn \n");
	}

	if (GDC && GDC->GetDebugCameraController().IsValid())
	{
		ADebugCameraController* DebugCamController = GDC->GetDebugCameraController().Get();
		if (DebugCamController != NULL)
		{
			FVector const CamLoc = DebugCamController->PlayerCameraManager->GetCameraLocation();
			FRotator const CamRot = DebugCamController->PlayerCameraManager->GetCameraRotation();

			FString HitString;
			FCollisionQueryParams TraceParams(NAME_None, true, this);
			FHitResult Hit;
			bool bHit = GetWorld()->LineTraceSingleByChannel(Hit, CamLoc, CamRot.Vector() * 100000.f + CamLoc, ECC_Pawn, TraceParams);
			if (bHit && Hit.GetActor() != nullptr)
			{
				HitString = FString::Printf(TEXT("{white}Under cursor: {yellow}'%s'"), *Hit.GetActor()->GetName());
				DrawDebugLine(GetWorld(), Hit.Location, Hit.Location + Hit.Normal*30.f, FColor::White);
			}
			else
			{
				HitString = FString::Printf(TEXT("Not actor under cursor"));
			}

			PrintString(DefaultContext, FColor::White, HitString, MenuStartX, MenuStartY + 40);
		}
	}


	DefaultContext.CursorX = OldX;
	DefaultContext.CursorY = OldY;
#endif //!(UE_BUILD_SHIPPING || UE_BUILD_TEST)
}