void AAmbitionOfNobunagaPlayerController::OnMouseLButtonPressed1()
{
	if (Hud)
	{
		Hud->OnLMousePressed1(GetMouseScreenPosition());
	}
}
void AAmbitionOfNobunagaPlayerController::OnMouseLButtonReleased()
{
    bMouseLButton = false;
    if(Hud)
    {
        Hud->OnLMouseReleased(GetMouseScreenPosition());
    }
}
void AAmbitionOfNobunagaPlayerController::OnMouseRButtonPressed2()
{
    bMouseRButton = true;
    if(Hud)
    {
        Hud->OnRMousePressed2(GetMouseScreenPosition());
    }
}
void UVaQuoleHUDComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
	// Update mouse position
	FVector2D MousePosition = FVector2D::ZeroVector;
	if (GetMouseScreenPosition(MousePosition))
	{
		float ScreenX = (MousePosition.X - ScreenPosition.X) * (Width / ScreenSize.X);
		float ScreenY = (MousePosition.Y - ScreenPosition.Y) * (Height / ScreenSize.Y);

		SetMousePosition(ScreenX, ScreenY);
	}

	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
void AAmbitionOfNobunagaPlayerController::PlayerTick(float DeltaTime)
{
    Super::PlayerTick(DeltaTime);

    if(Hud)
    {
        CurrentMouseXY = GetMouseScreenPosition();
        FHitResult Hit;
        bool res = GetHitResultAtScreenPosition(CurrentMouseXY, ECC_Visibility, false, Hit);
//      if (Hit.Actor.IsValid())
//      {
//          Hit.Actor->AddActorWorldOffset(FVector(0, 0, 100));
//      }
        Hud->OnMouseMove(CurrentMouseXY, Hit.ImpactPoint);
    }
    ServerUpdateMove();
}
void AAmbitionOfNobunagaPlayerController::PlayerTick(float DeltaTime)
{
	Super::PlayerTick(DeltaTime);

	if(Hud)
	{
		CurrentMouseXY = GetMouseScreenPosition();
		TArray<FHitResult> Hits;
		bool res;
		FVector WorldOrigin;
		FVector WorldDirection;
		FCollisionObjectQueryParams CollisionQuery;
		CollisionQuery.AddObjectTypesToQuery(ECC_WorldStatic);
		if (UGameplayStatics::DeprojectScreenToWorld(this, CurrentMouseXY, WorldOrigin, WorldDirection) == true)
		{
			res = GetWorld()->LineTraceMultiByObjectType(Hits, WorldOrigin, WorldOrigin + WorldDirection * HitResultTraceDistance,
			        CollisionQuery);
		}
		// 只trace 地板的actor
		// 地板名可以自定義
		FVector HitPoint(0, 0, 0);
		if (Hits.Num() > 0)
		{
			for (FHitResult Hit : Hits)
			{
				if (Hit.Actor.IsValid() && Hit.Actor->GetFName().GetPlainNameString() == FloorActorName)
				{
					HitPoint = Hit.ImpactPoint;
				}
				// all landscape can click
				if (Hit.Actor.IsValid())
				{
					FString ResStr;
					Hit.Actor->GetClass()->GetName(ResStr);
					if (ResStr == "Landscape")
					{
						HitPoint = Hit.ImpactPoint;
					}
				}
			}
		}
		Hud->OnMouseMove(CurrentMouseXY, HitPoint);
	}
}