Esempio n. 1
0
bool AOpenBarrierConsole::OnInteract()
{
	/*When the player interact with the console it activates the camera to enter in puzzle mode*/
	UWorld* World = GetWorld();
	if (World)
	{
		APlayerController* PlayerController = World->GetFirstPlayerController();
		if (PlayerController)
		{
			ATGCOPlayerState* PlayerState = Cast<ATGCOPlayerState>(PlayerController->PlayerState);
			if (PlayerState)
			{
				if (PlayerState->eCurrentState == EPlayerStatus::IN_GAME)
				{
					PlayerState->SwitchGamePuzzle(CameraPuzzle);
				}
				else
				{
					if (PlayerState->eCurrentState == EPlayerStatus::IN_PUZZLE_GAME)
					{
						PlayerState->SwitchGamePuzzle(PlayerController->GetCharacter());
					}
				}
			}
		}
	}
	return true;
}
Esempio n. 2
0
void AFunctionalTest::GoToObservationPoint()
{
	if (ObservationPoint == NULL)
	{
		return;
	}

	UWorld* World = GetWorld();
	if (World)
	{
		APlayerController* PC = World->GetFirstPlayerController();
		if (PC && PC->GetPawn())
		{
			PC->GetPawn()->TeleportTo(ObservationPoint->GetActorLocation(), ObservationPoint->GetActorRotation(), /*bIsATest=*/false, /*bNoCheck=*/true);
			PC->SetControlRotation(ObservationPoint->GetActorRotation());
		}
	}
}
Esempio n. 3
0
FReply FSceneViewport::OnMouseButtonDown( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent )
{
	// Start a new reply state
	// Prevent throttling when interacting with the viewport so we can move around in it
	CurrentReplyState = FReply::Handled().PreventThrottling();

	KeyStateMap.Add(InMouseEvent.GetEffectingButton(), true);
	UpdateModifierKeys( InMouseEvent );
	UpdateCachedMousePos( InGeometry, InMouseEvent );
	UpdateCachedGeometry(InGeometry);

	// Switch to the viewport clients world before processing input
	FScopedConditionalWorldSwitcher WorldSwitcher( ViewportClient );
	if( ViewportClient && GetSizeXY() != FIntPoint::ZeroValue )
	{
		// If we're obtaining focus, we have to copy the modifier key states prior to processing this mouse button event, as this is the only point at which the mouse down
		// event is processed when focus initially changes and the modifier keys need to be in-place to detect any unique drag-like events.
		if ( !HasFocus() )
		{
			FModifierKeysState KeysState = FSlateApplication::Get().GetModifierKeys();
			ApplyModifierKeys( KeysState );
		}

		// Process the mouse event
		if( !ViewportClient->InputKey( this, 0, InMouseEvent.GetEffectingButton(), IE_Pressed ) )
		{
			CurrentReplyState = FReply::Unhandled(); 
		}

		if (ViewportClient->CaptureMouseOnClick() != EMouseCaptureMode::NoCapture && !ViewportClient->IgnoreInput())
		{
			TSharedRef<SViewport> ViewportWidgetRef = ViewportWidget.Pin().ToSharedRef();

			// Mouse down should focus viewport for keyboard input
			CurrentReplyState.SetKeyboardFocus(ViewportWidgetRef, EKeyboardFocusCause::Mouse);
			
			UWorld* World = ViewportClient->GetWorld();
			if (World && World->IsGameWorld() && World->GetFirstPlayerController())
			{
				CurrentReplyState.CaptureMouse(ViewportWidgetRef);
				CurrentReplyState.LockMouseToWidget(ViewportWidgetRef);

				bool bShouldShowMouseCursor = World->GetFirstPlayerController()->ShouldShowMouseCursor();
				if (ViewportClient->HideCursorDuringCapture() && bShouldShowMouseCursor)
				{
					bCursorHiddenDueToCapture = true;
				}
				if (bCursorHiddenDueToCapture || !bShouldShowMouseCursor)
				{
					CurrentReplyState.UseHighPrecisionMouseMovement(ViewportWidgetRef);
				}
			}
			else
			{
				CurrentReplyState.UseHighPrecisionMouseMovement(ViewportWidgetRef);
			}
		}
	}
	
	// Re-set prevent throttling here as it can get reset when inside of InputKey()
	CurrentReplyState.PreventThrottling();

	return CurrentReplyState;
}
Esempio n. 4
0
FReply FSceneViewport::OnMouseButtonDown( const FGeometry& InGeometry, const FPointerEvent& InMouseEvent )
{
	// Start a new reply state
	// Prevent throttling when interacting with the viewport so we can move around in it
	CurrentReplyState = FReply::Handled().PreventThrottling();

	KeyStateMap.Add(InMouseEvent.GetEffectingButton(), true);
	UpdateModifierKeys( InMouseEvent );
	UpdateCachedMousePos( InGeometry, InMouseEvent );
	UpdateCachedGeometry(InGeometry);

	// Switch to the viewport clients world before processing input
	FScopedConditionalWorldSwitcher WorldSwitcher( ViewportClient );
	if( ViewportClient && GetSizeXY() != FIntPoint::ZeroValue )
	{
		// If we're obtaining focus, we have to copy the modifier key states prior to processing this mouse button event, as this is the only point at which the mouse down
		// event is processed when focus initially changes and the modifier keys need to be in-place to detect any unique drag-like events.
		if ( !HasFocus() )
		{
			FModifierKeysState KeysState = FSlateApplication::Get().GetModifierKeys();
			ApplyModifierKeys( KeysState );
		}

		const bool bAnyMenuWasVisible = FSlateApplication::Get().AnyMenusVisible();

		// Process the mouse event
		if (!ViewportClient->InputKey(this, InMouseEvent.GetUserIndex(), InMouseEvent.GetEffectingButton(), IE_Pressed))
		{
			CurrentReplyState = FReply::Unhandled(); 
		}

		// a new menu was opened if there was previously not a menu visible but now there is
		const bool bNewMenuWasOpened = !bAnyMenuWasVisible && FSlateApplication::Get().AnyMenusVisible();

		if (!ViewportClient->IgnoreInput() &&
			!bNewMenuWasOpened && // We should not focus the viewport if a menu was opened as it would close the menu
			( ViewportClient->CaptureMouseOnClick() == EMouseCaptureMode::CapturePermanently ||
			  ViewportClient->CaptureMouseOnClick() == EMouseCaptureMode::CaptureDuringMouseDown ||
			  ( ViewportClient->CaptureMouseOnClick() == EMouseCaptureMode::CaptureDuringRightMouseDown && InMouseEvent.GetEffectingButton() == EKeys::RightMouseButton ) ) )
		{
			TSharedRef<SViewport> ViewportWidgetRef = ViewportWidget.Pin().ToSharedRef();

			// Mouse down should focus viewport for user input
			CurrentReplyState.SetUserFocus(ViewportWidgetRef, EFocusCause::SetDirectly, true);
			
			UWorld* World = ViewportClient->GetWorld();
			if (World && World->IsGameWorld() && World->GetFirstPlayerController())
			{
				CurrentReplyState.CaptureMouse(ViewportWidgetRef);
				CurrentReplyState.LockMouseToWidget(ViewportWidgetRef);

				bool bShouldShowMouseCursor = World->GetFirstPlayerController()->ShouldShowMouseCursor();
				if (ViewportClient->HideCursorDuringCapture() && bShouldShowMouseCursor)
				{
					bCursorHiddenDueToCapture = true;
					MousePosBeforeHiddenDueToCapture = FIntPoint( InMouseEvent.GetScreenSpacePosition().X, InMouseEvent.GetScreenSpacePosition().Y );
				}
				if (bCursorHiddenDueToCapture || !bShouldShowMouseCursor)
				{
					CurrentReplyState.UseHighPrecisionMouseMovement(ViewportWidgetRef);
				}
			}
			else
			{
				CurrentReplyState.UseHighPrecisionMouseMovement(ViewportWidgetRef);
			}
		}
	}
	
	// Re-set prevent throttling here as it can get reset when inside of InputKey()
	CurrentReplyState.PreventThrottling();

	return CurrentReplyState;
}
void AInteractiveActor::OnEndCursorOverlap()
{
	UWorld* World = GetWorld();
	if (World)
	{
		AZombieShooterPlayerController*  PlayerController = Cast<AZombieShooterPlayerController>(World->GetFirstPlayerController());
		if (PlayerController)
		{
			if (PlayerController->ControlledPawn)
			{
				if (PlayerController->ControlledPawn->TargetedObject == this)
				{
					PlayerController->ControlledPawn->TargetedObject = NULL;
				}
				bTargetedByPlayer = false;
			}
		}
	}
}
// Thoughout the function we delete all in-world coordinates by 200.
// This is to make a cube in the real world be equal to a pixel from the map image.
void APDemo::Tick( float DeltaTime )
{	
	Super::Tick( DeltaTime );
	
	UWorld* World = GetWorld();
	APlayerCameraManager* PlayerCameraManager = World->GetFirstPlayerController()->PlayerCameraManager;
	FVector cam_position = PlayerCameraManager->GetCameraLocation();
	
	if (br != 0){ //go through brick_to... and remove the marked ones from bricks
		for (unsigned int i = 0; i < br; ++i){
			ABrick* Brick = bricks[bricks_to_be_removed[i]];
			bricks.erase(bricks_to_be_removed[i]);
			Brick->Destroy();
			bricks_to_be_removed[i] = "";
		}
		br = 0;
	}
	
	//now go through bricks and mark the new bricks to be removed next frame
	for (auto it = bricks.begin(); it != bricks.end(); ++it){
		FVector brick_loc = it->second->GetActorLocation();
		float distance = ( (brick_loc - cam_position).Size() )/200;
		if (distance >= despawn_dist){
			bricks_to_be_removed[br] = it->first;
			++br;
		}
	}

	//int spawn_height_sector = (int)floor(cam_position.Z / 200) / 80;
	//spawn_height = 160 * spawn_height_sector;

	//this magic tho
	int spawn_height_sector = (int)floor(cam_position.Z / 200);
	int sector_offset = spawn_height_sector == 0 ? 0 : (spawn_height_sector / abs(spawn_height_sector)) * 80;
	spawn_height_sector += sector_offset;
	spawn_height_sector = spawn_height_sector / 160;	
	spawn_height = 160 * spawn_height_sector;
	

	int distance_fwd = 60;
	int distance_left = 60;
	int start_i = (int)floor(cam_position.X / 200);
	int start_j = (int)floor(cam_position.Y / 200);
	for (int i = start_i - distance_fwd; i < start_i + distance_fwd; ++i) {     // y
		for (int j = start_j - distance_left; j < start_j + distance_left; ++j) {  // x
			double x = (double)(abs(j) % width) / ((double)width);// we use % to make sure we never go out of the defined map
			double y = (double)(abs(i) % height) / ((double)height);

			double n = pn.noise(10 * x, 10 * y, 0.8);
			n = n < noise_threshold ? 0 : n;//used to create a clear distinction between space and land
			FVector brick_position = FVector(i * 200, j * 200, spawn_height * 200);
			float distance = ((brick_position - cam_position).Size()) / 200;

			if (distance < despawn_dist){
				string key = to_string(i) + to_string(j);

				if (n > 0 && !bricks[key]){
					float brick_height = n;
					ABrick* Brick = World->SpawnActor<ABrick>(ABrick::StaticClass());
					Brick->SetPositionAndHeight(brick_position, brick_height, noise_threshold);
					bricks[key] = Brick;
				}
			}
		}
	}	
}
Esempio n. 7
-1
FVector2D AGameplayPawn::GetMouseWorldPosition()
{
	UWorld* TestWorld = GetWorld();
	if (TestWorld)
	{
		APlayerController* PlayerController = TestWorld->GetFirstPlayerController();
		FVector2D MousePos = FVector2D(0, 0);
		FVector WorldPos = FVector(MousePos.X, MousePos.Y, 0);
		FVector Dir = FVector(0, 0, 0);
		if (PlayerController != nullptr)
		{
			PlayerController->GetMousePosition(MousePos.X, MousePos.Y);
			PlayerController->DeprojectMousePositionToWorld(WorldPos, Dir);
		}
		return FVector2D((int)(WorldPos.X/SCALE_FACTOR), (int)(WorldPos.Y/SCALE_FACTOR));
	}
	return FVector2D::ZeroVector;
}