/** * Delegate fired when the joining process for an online session has completed * * @param SessionName the name of the session this callback is for * @param bWasSuccessful true if the async action completed without error, false if there was an error */ void UOnlineSessionClient::OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result) { UE_LOG(LogOnline, Verbose, TEXT("OnJoinSessionComplete %s bSuccess: %d"), *SessionName.ToString(), static_cast<int32>(Result)); SessionInt->ClearOnJoinSessionCompleteDelegate(OnJoinSessionCompleteDelegate); if (Result == EOnJoinSessionCompleteResult::Success) { FString URL; if (SessionInt->GetResolvedConnectString(SessionName, URL)) { APlayerController* PC = GetPlayerController(); if (PC) { if (bIsFromInvite) { URL += TEXT("?bIsFromInvite"); bIsFromInvite = false; } PC->ClientTravel(URL, TRAVEL_Absolute); } } else { UE_LOG(LogOnline, Warning, TEXT("Failed to join session %s"), *SessionName.ToString()); } } }
/** * Join a session of a given name after potentially tearing down an existing one * * @param LocalUserNum local user id * @param SessionName name of session to join * @param SearchResult the session to join */ void UOnlineSessionClient::JoinSession(int32 LocalUserNum, FName SessionName, const FOnlineSessionSearchResult& SearchResult) { // Clean up existing sessions if applicable EOnlineSessionState::Type SessionState = SessionInt->GetSessionState(SessionName); if (SessionState != EOnlineSessionState::NoSession) { CachedSessionResult = SearchResult; EndExistingSession(SessionName, OnEndForJoinSessionCompleteDelegate); } else { UGameInstance * const GameInstance = GetPlayerController()->GetGameInstance(); GameInstance->JoinSession(static_cast<ULocalPlayer*>(GetPlayerController()->Player), SearchResult); /*SessionInt->AddOnJoinSessionCompleteDelegate(OnJoinSessionCompleteDelegate); SessionInt->JoinSession(LocalUserNum, SessionName, SearchResult);*/ } }
void UBerserkCameraComponent::GetCameraView(float deltaTime, FMinimalViewInfo& outDesiredView) { auto playerController = GetPlayerController(); if (playerController) { outDesiredView.FOV = 30.f; const float currentOffset = MinCameraOffset + ZoomAlpha * (MaxCameraOffset - MinCameraOffset); outDesiredView.Location = playerController->GetFocalLocation() - FixedCameraAngle.Vector() * currentOffset; outDesiredView.Rotation = FixedCameraAngle; } }
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 ); }
UMainMenuWidget* UMainMenuWidget::Create(UObject* worldContextObject) { auto widget = InstantiateWidget<UMainMenuWidget>(worldContextObject); if (!widget) return nullptr; widget->playButton = Cast<UButton>(widget->GetWidgetFromName(TEXT("PlayButton"))); widget->quitButton = Cast<UButton>(widget->GetWidgetFromName(TEXT("QuitButton"))); widget->playButton->OnClicked.AddDynamic(widget, &UMainMenuWidget::OnPlayButtonClicked); widget->quitButton->OnClicked.AddDynamic(widget, &UMainMenuWidget::OnQuitButtonClicked); GetPlayerController()->bShowMouseCursor = true; return widget; }
/** * Transition from destroying a session to returning to the main menu * * @param SessionName name of session recently destroyed * @param bWasSuccessful was the destroy attempt successful */ void UOnlineSessionClient::OnDestroyForMainMenuComplete(FName SessionName, bool bWasSuccessful) { UE_LOG(LogOnline, Verbose, TEXT("OnDestroyForMainMenuComplete %s bSuccess: %d"), *SessionName.ToString(), bWasSuccessful); if (SessionInt.IsValid()) { SessionInt->ClearOnDestroySessionCompleteDelegate(OnDestroyForMainMenuCompleteDelegate); } APlayerController* PC = GetPlayerController(); if (PC) { // Call disconnect to force us back to the menu level GEngine->HandleDisconnect(PC->GetWorld(), PC->GetWorld()->GetNetDriver()); } bHandlingDisconnect = false; }
TVerdict CTestStepUnitMMFVidClient::DoControllerCalled(TInt aFunction, const TDesC8& aText, TBool aExpected) { // Get the controller TInt err = KErrNone; RMMFController* controller = NULL; err = GetPlayerController(controller); if (err != KErrNone) { INFO_PRINTF2(_L("Error getting controller %d"), err); return EInconclusive; } // Check that the correct functions were called in the controller TBuf8<64> functionText; TUid uid = { KMmfVideoTestControllerUid }; TMMFMessageDestination handleInfo(uid); TMMFMessageDestinationPckg message(handleInfo); TBuf<64> functionText16; err = controller->CustomCommandSync(message, aFunction, KNullDesC8, KNullDesC8, functionText); if (err == KErrNone ) { functionText16.Copy(aText); if (aExpected) { INFO_PRINTF2(_L("Expect %S"), &functionText16); } else { INFO_PRINTF2(_L("Should not have %S"), &functionText16); } if ((functionText.Compare(aText) == 0 && aExpected) || (functionText.Compare(aText) != 0 && !aExpected)) { iTestStepResult = EPass; } else { iTestStepResult = EFail; return iTestStepResult; } } return iTestStepResult; }
bool UOnlineSessionClient::HandleDisconnectInternal(UWorld* World, UNetDriver* NetDriver) { APlayerController* PC = GetPlayerController(); if (PC) { // This was a disconnect for our active world, we will handle it if (PC->GetWorld() == World) { // Prevent multiple calls to this async flow if (!bHandlingDisconnect) { bHandlingDisconnect = true; DestroyExistingSession(GameSessionName, OnDestroyForMainMenuCompleteDelegate); } return true; } } return false; }
void UBerserkCameraComponent::UpdateCameraMovement(const APlayerController* playerController) { auto const* const localPlayer = Cast<ULocalPlayer>(playerController->Player); if (localPlayer && localPlayer->ViewportClient && localPlayer->ViewportClient->Viewport) { FVector2D mousePosition; if (localPlayer->ViewportClient->GetMousePosition(mousePosition) == false) return; auto viewport = localPlayer->ViewportClient->Viewport; const float scrollSpeed = 60.0f; const FIntPoint viewportSize = viewport->GetSizeXY(); const uint32 viewLeft = FMath::TruncToInt(localPlayer->Origin.X * viewportSize.X); const uint32 viewRight = viewLeft + FMath::TruncToInt(localPlayer->Size.X * viewportSize.X); const uint32 viewTop = FMath::TruncToInt(localPlayer->Origin.Y * viewportSize.Y); const uint32 viewBottom = viewTop + FMath::TruncToInt(localPlayer->Size.Y * viewportSize.Y); const float maxSpeed = CameraScrollSpeed * FMath::Clamp(ZoomAlpha, 0.3f, 1.0f); bool isNoScrollZone = false; const FVector mouseCoords(mousePosition, 0.0f); for (int iZone = 0; iZone < NoScrollZones.Num(); ++iZone) { const auto eachZone = NoScrollZones[iZone]; if (eachZone.IsInsideXY(mouseCoords) == true) isNoScrollZone = true; } const uint32 mouseX = mousePosition.X; const uint32 mouseY = mousePosition.Y; float spectatorCameraSpeed = maxSpeed; ASpectatorPawn* spectatorPawn = nullptr; if (GetPlayerController() != nullptr) { spectatorPawn = GetPlayerController()->GetSpectatorPawn(); if (spectatorPawn->GetMovementComponent() != nullptr) spectatorCameraSpeed = GetDefault<UBerserkSpectatorPawnMovement>(spectatorPawn->GetMovementComponent()->GetClass())->MaxSpeed; } if (!isNoScrollZone) { if (mouseX >= viewLeft && mouseX <= (viewLeft + CameraActiveBorder)) { const float delta = 1.0f - float(mouseX - viewLeft) / CameraActiveBorder; spectatorCameraSpeed = delta * maxSpeed; MoveRight(-scrollSpeed * delta); } else if (mouseX >= (viewRight - CameraActiveBorder) && mouseX <= viewRight) { const float delta = float(mouseX - viewRight + CameraActiveBorder) / CameraActiveBorder; spectatorCameraSpeed = delta * maxSpeed; MoveRight(scrollSpeed * delta); } if (mouseY >= viewTop && mouseY <= (viewTop + CameraActiveBorder)) { const float delta = 1.0f - float(mouseY - viewTop) / CameraActiveBorder; spectatorCameraSpeed = delta * maxSpeed; MoveForward(scrollSpeed * delta); } else if (mouseY >= (viewBottom - CameraActiveBorder) && mouseY <= viewBottom) { const float delta = float(mouseY - (viewBottom - CameraActiveBorder)) / CameraActiveBorder; spectatorCameraSpeed = delta * maxSpeed; MoveForward(-scrollSpeed * delta); } if (spectatorPawn != nullptr) { UFloatingPawnMovement* floatingMovementComponent = Cast<UFloatingPawnMovement>(spectatorPawn->GetMovementComponent()); if (floatingMovementComponent) floatingMovementComponent->MaxSpeed = spectatorCameraSpeed; } } } NoScrollZones.Empty(); }
void UBerserkCameraComponent::SetCameraTarget(const FVector& cameraTarget) { auto spectatorPawn = GetPlayerController()->GetSpectatorPawn(); if (spectatorPawn != nullptr) spectatorPawn->SetActorLocation(cameraTarget, false); }
void UMainMenuWidget::OnPlayButtonClicked() { GetPlayerController()->bShowMouseCursor = false; LoadLevel(TEXT("Island")); }
void UBerserkCameraComponent::MoveRight(float value) { auto ownerPawn = GetOwnerPawn(); if (ownerPawn != nullptr) { auto playerController = GetPlayerController(); if ((value != 0.f) && (playerController != nullptr)) { const FRotationMatrix cameraRotation(playerController->PlayerCameraManager->GetCameraRotation()); const FVector worldSpaceAccel = cameraRotation.GetScaledAxis(EAxis::Y) * 100.0f; // transform to world space and add it ownerPawn->AddMovementInput(worldSpaceAccel, value); } } }