138 lines
4.5 KiB
C++
138 lines
4.5 KiB
C++
// Copyright 2016 Mookie. All Rights Reserved.
|
|
|
|
#include "EBBarrelComponentFactory.h"
|
|
#include "EBBarrel.h"
|
|
#include "EBGun.h"
|
|
#include "Engine/Selection.h"
|
|
#include "Components/SceneComponent.h"
|
|
#include "DrawDebugHelpers.h"
|
|
|
|
#define LOCTEXT_NAMESPACE "EBBarrelComponentFactory"
|
|
|
|
void FEBBarrelComponentVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI)
|
|
{
|
|
const UEBBarrel* BarrelComponent = Cast<const UEBBarrel>(Component);
|
|
if (!BarrelComponent)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Get the component's transform
|
|
FTransform ComponentTransform = BarrelComponent->GetComponentTransform();
|
|
FVector Location = ComponentTransform.GetLocation();
|
|
FVector Forward = ComponentTransform.GetUnitAxis(EAxis::X);
|
|
FVector Right = ComponentTransform.GetUnitAxis(EAxis::Y);
|
|
FVector Up = ComponentTransform.GetUnitAxis(EAxis::Z);
|
|
|
|
// Draw barrel representation
|
|
FColor BarrelColor = FColor::Blue;
|
|
|
|
const AEBGun* ParentGun = BarrelComponent->GetParentGun();
|
|
if (ParentGun)
|
|
{
|
|
if (ParentGun->bChamberedRound)
|
|
{
|
|
BarrelColor = FColor::Green; // Loaded
|
|
}
|
|
else if (ParentGun->CurrentGunState == EGunState::GS_Firing)
|
|
{
|
|
BarrelColor = FColor::Red; // Firing
|
|
}
|
|
}
|
|
|
|
|
|
// Draw barrel cylinder
|
|
float BarrelLength = FMath::Max(BarrelComponent->BarrelLength, 10.0f); // Minimum visual length
|
|
float BarrelRadius = 2.0f;
|
|
FVector BarrelEnd = Location + (Forward * BarrelLength);
|
|
|
|
// Draw barrel outline
|
|
DrawWireCylinder(PDI, Location, Forward, Right, Up, BarrelColor, BarrelRadius, BarrelLength, 12, SDPG_Foreground);
|
|
|
|
// Draw muzzle
|
|
FVector MuzzleLocation = BarrelEnd;
|
|
DrawWireBox(PDI, FBox(MuzzleLocation - FVector(2, 2, 2), MuzzleLocation + FVector(2, 2, 2)), FColor::Orange, SDPG_Foreground);
|
|
|
|
// Draw firing direction indicator
|
|
if (ParentGun && ParentGun->CurrentGunState == EGunState::GS_Firing)
|
|
{
|
|
FVector FireDirection = BarrelEnd + (Forward * 20.0f);
|
|
PDI->DrawLine(BarrelEnd, FireDirection, FColor::Red, SDPG_Foreground, 2.0f);
|
|
}
|
|
|
|
// Draw spread cone when aiming
|
|
if (BarrelComponent->Spread > 0.0f)
|
|
{
|
|
float SpreadAngle = BarrelComponent->Spread;
|
|
float ConeLength = 50.0f;
|
|
FVector ConeEnd = BarrelEnd + (Forward * ConeLength);
|
|
float ConeRadius = FMath::Tan(SpreadAngle) * ConeLength;
|
|
|
|
// Draw spread cone outline (temporarily commented out due to function signature issues)
|
|
// FQuat ConeRotation = FQuat::FindBetweenVectors(FVector::ForwardVector, Forward);
|
|
// DrawWireCone(PDI, FTransform(ConeRotation, BarrelEnd), ConeLength, ConeRadius, 8, FColor::Yellow);
|
|
|
|
// Alternative: Draw lines to represent the cone
|
|
int32 NumSides = 8;
|
|
for (int32 i = 0; i < NumSides; i++)
|
|
{
|
|
float Angle = (2.0f * PI * i) / NumSides;
|
|
FVector RadialDirection = Right * FMath::Cos(Angle) + Up * FMath::Sin(Angle);
|
|
FVector ConePoint = BarrelEnd + Forward * ConeLength + RadialDirection * ConeRadius;
|
|
PDI->DrawLine(BarrelEnd, ConePoint, FColor::Yellow, SDPG_Foreground);
|
|
}
|
|
}
|
|
|
|
// Draw ammo count indicator
|
|
if (ParentGun && ParentGun->GetRoundsInMagazine() > 0)
|
|
{
|
|
FVector AmmoIndicatorLocation = Location + (Right * 10.0f);
|
|
for (int32 i = 0; i < FMath::Min(ParentGun->GetRoundsInMagazine(), 10); i++)
|
|
{
|
|
FVector AmmoLocation = AmmoIndicatorLocation + (Up * i * 3.0f);
|
|
FVector BoxExtent = FVector(0.5f, 0.5f, 1.0f);
|
|
DrawWireBox(PDI, FBox(AmmoLocation - BoxExtent, AmmoLocation + BoxExtent), FColor::Cyan, SDPG_Foreground);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool FEBBarrelComponentVisualizer::VisProxyHandleClick(FEditorViewportClient* InViewportClient, HComponentVisProxy* VisProxy, const FViewportClick& Click)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool FEBBarrelComponentVisualizer::GetWidgetLocation(const FEditorViewportClient* ViewportClient, FVector& OutLocation) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool FEBBarrelComponentVisualizer::GetCustomInputCoordinateSystem(const FEditorViewportClient* ViewportClient, FMatrix& OutMatrix) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool FEBBarrelComponentVisualizer::HandleInputDelta(FEditorViewportClient* ViewportClient, FViewport* Viewport, FVector& DeltaTranslate, FRotator& DeltaRotate, FVector& DeltaScale)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool FEBBarrelComponentVisualizer::HandleInputKey(FEditorViewportClient* ViewportClient, FViewport* Viewport, FKey Key, EInputEvent Event)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
TSharedPtr<SWidget> FEBBarrelComponentVisualizer::GenerateContextMenu() const
|
|
{
|
|
return TSharedPtr<SWidget>();
|
|
}
|
|
|
|
bool FEBBarrelComponentVisualizer::IsVisualizationShown(const UActorComponent* Component) const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void FEBBarrelComponentVisualizer::EndEditing()
|
|
{
|
|
}
|
|
|
|
#undef LOCTEXT_NAMESPACE |