diff --git a/Source/StudyFrameworkPlugin/Private/HUD/SFFadeHandler.cpp b/Source/StudyFrameworkPlugin/Private/HUD/SFFadeHandler.cpp index e4d4fb4aed3fa86c05d7dff1154b13550a05cbb4..6c37f4f9f643a32f39d11f5f206d0a6dd23cb5c1 100644 --- a/Source/StudyFrameworkPlugin/Private/HUD/SFFadeHandler.cpp +++ b/Source/StudyFrameworkPlugin/Private/HUD/SFFadeHandler.cpp @@ -93,7 +93,7 @@ void USFFadeHandler::Tick() } } -void USFFadeHandler::FadeToLevel(const FString& NextLevelName, bool bForceFade, const bool bStartFadeFadedOut) +void USFFadeHandler::FadeToLevel(const FString& NextLevelName, EFadeBetweenCondition ShouldFade, const bool bStartFadeFadedOut) { if (GetCameraManager() == nullptr) { @@ -113,6 +113,20 @@ void USFFadeHandler::FadeToLevel(const FString& NextLevelName, bool bForceFade, FSFLoggingUtils::Log( "[USFFadeHandler::FadeToLevel()]: Fading From level (" + CurrentLevelName + ") to level (" + NextLevelName + ")", false); + bool bShouldFade = true; + if(ShouldFade == EFadeBetweenCondition::AsDefault) + { + bShouldFade = !USFGameInstance::Get()->GetStudySetup()->bNoFadingOnSameMap; + } + else if (ShouldFade == EFadeBetweenCondition::ForceFade) + { + bShouldFade = true; + } + else if (ShouldFade == EFadeBetweenCondition::ForceNoFade) + { + bShouldFade = false; + } + if (bStartFadeFadedOut || bIsFadedOut) { //we only need to fade in @@ -123,9 +137,7 @@ void USFFadeHandler::FadeToLevel(const FString& NextLevelName, bool bForceFade, Fade(0.0f, true); FadeState = EFadeState::FadingOut; } - else if (USFGameInstance::Get()->GetStudySetup()->bNoFadingOnSameMap - && CurrentLevelName == FPackageName::GetShortName(NextLevelName) - && !bForceFade) + else if (!bShouldFade && CurrentLevelName == FPackageName::GetShortName(NextLevelName)) { //bNoFadingOnSameMap and fade to same map, so no fading, but pretend we "faded in" FadeState = EFadeState::FadingIn; @@ -158,7 +170,7 @@ void USFFadeHandler::FadeIn() void USFFadeHandler::FadeOut() { - FadeToLevel("", true); + FadeToLevel("", EFadeBetweenCondition::ForceFade); } diff --git a/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp b/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp index 02a8ef1040586efaa0f3cca9d4fea334d7f92fc7..3640139d793c39f1a9487b7c60ccd0a6adc82a84 100644 --- a/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp +++ b/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp @@ -412,7 +412,7 @@ void USFGameInstance::EndStudy() } -bool USFGameInstance::NextCondition(bool bForced /*=false*/, bool bForceFade /*= false*/) +bool USFGameInstance::NextCondition(bool bForced /*=false*/, EFadeBetweenCondition Fade /*= EFadeBetweenCondition::AsDefault*/) { // Check if is already fading if (FadeHandler->GetIsFading() && !FadeHandler->GetIsFadedOutWaitingForLevel()) @@ -428,10 +428,10 @@ bool USFGameInstance::NextCondition(bool bForced /*=false*/, bool bForceFade /*= EndStudy(); return false; } - return GoToCondition(NextCondition, bForced, bForceFade); + return GoToCondition(NextCondition, bForced, Fade); } -bool USFGameInstance::GoToCondition(const USFCondition* Condition, bool bForced /*=false*/, bool bForceFade /*= false*/) +bool USFGameInstance::GoToCondition(const USFCondition* Condition, bool bForced /*=false*/, EFadeBetweenCondition Fade /*= EFadeBetweenCondition::AsDefault*/) { // Check if is already fading if (FadeHandler->GetIsFading() && !FadeHandler->GetIsFadedOutWaitingForLevel()) @@ -445,16 +445,16 @@ bool USFGameInstance::GoToCondition(const USFCondition* Condition, bool bForced FSFLoggingUtils::Log("[USFGameInstance::GoToCondition()]: Could not load next condition.", true); return false; } - GoToConditionSynced(Condition->UniqueName, bForced, bForceFade); + GoToConditionSynced(Condition->UniqueName, bForced, Fade); return true; } -void USFGameInstance::GoToConditionSynced(FString ConditionName, bool bForced, bool bForceFade) +void USFGameInstance::GoToConditionSynced(FString ConditionName, bool bForced, EFadeBetweenCondition Fade) { const EDisplayClusterOperationMode OperationMode = IDisplayCluster::Get().GetOperationMode(); if (OperationMode != EDisplayClusterOperationMode::Cluster) { - HandleGoToConditionSynced(ConditionName, bForced, bForceFade); + HandleGoToConditionSynced(ConditionName, bForced, Fade); } else { @@ -467,7 +467,7 @@ void USFGameInstance::GoToConditionSynced(FString ConditionName, bool bForced, b TMap<FString, FString> Params; Params.Add("ConditionName", ConditionName); Params.Add("bForced", bForced ?"true":"false"); - Params.Add("bForceFade", bForceFade ? "true" : "false"); + Params.Add("Fade", (Fade == EFadeBetweenCondition::AsDefault ? "AsDefault" : (Fade == EFadeBetweenCondition::ForceNoFade ? "ForceNoFade" : "ForceFade"))); ClusterEvent.Parameters = Params; ClusterEvent.bShouldDiscardOnRepeat = true; @@ -480,13 +480,29 @@ void USFGameInstance::HandleClusterEvent(const FDisplayClusterClusterEventJson& //now we actually react on all cluster nodes: if(Event.Name == "GoToConditionSynced") { - HandleGoToConditionSynced(Event.Parameters["ConditionName"], Event.Parameters["bForced"] == "true", Event.Parameters["bForceFade"] == "true"); + EFadeBetweenCondition Fade = EFadeBetweenCondition::AsDefault; + if (Event.Parameters["Fade"] != "AsDefault") + { + if (Event.Parameters["Fade"] == "ForceNoFade") + { + Fade = EFadeBetweenCondition::ForceNoFade; + } + else if (Event.Parameters["Fade"] == "ForceFade") + { + Fade = EFadeBetweenCondition::ForceFade; + } + else + { + FSFLoggingUtils::Log("[USFGameInstance::HandleClusterEvent] Unknown Fade value: " + Event.Parameters["Fade"], true); + } + } + HandleGoToConditionSynced(Event.Parameters["ConditionName"], Event.Parameters["bForced"] == "true", Fade); } } } -void USFGameInstance::HandleGoToConditionSynced(FString ConditionName, bool bForced, bool bForceFade) +void USFGameInstance::HandleGoToConditionSynced(FString ConditionName, bool bForced, EFadeBetweenCondition Fade) { USFCondition* NextCondition = nullptr; for (USFCondition* Condition : Participant->GetAllConditions()) @@ -557,7 +573,7 @@ void USFGameInstance::HandleGoToConditionSynced(FString ConditionName, bool bFor } else { - FadeHandler->FadeToLevel(NextCondition->Map, bForceFade); + FadeHandler->FadeToLevel(NextCondition->Map, Fade); } UpdateHUD("Fading out"); } diff --git a/Source/StudyFrameworkPlugin/Public/HUD/SFFadeHandler.h b/Source/StudyFrameworkPlugin/Public/HUD/SFFadeHandler.h index 82f579f6962076d2b026f40b4729b78c9f821d81..961ba7fdebc3fc5371d5991709331cac2d1c1727 100644 --- a/Source/StudyFrameworkPlugin/Public/HUD/SFFadeHandler.h +++ b/Source/StudyFrameworkPlugin/Public/HUD/SFFadeHandler.h @@ -36,6 +36,14 @@ struct FFadeConfig void FromJson(TSharedPtr<FJsonObject> Json); }; +UENUM() +enum class EFadeBetweenCondition : uint8 +{ + AsDefault = 0, //set ASFStudySetup::bNoFadingOnSameMap + ForceNoFade = 1, //is it is possible (same map used on next condition) + ForceFade = 2 +}; + UCLASS() class STUDYFRAMEWORKPLUGIN_API USFFadeHandler : public UObject @@ -45,7 +53,7 @@ class STUDYFRAMEWORKPLUGIN_API USFFadeHandler : public UObject public: void Tick(); - void FadeToLevel(const FString& LevelName, bool bForceFade, bool bStartFadedOut = false); + void FadeToLevel(const FString& LevelName, EFadeBetweenCondition ShouldFade, bool bStartFadedOut = false); void FadeIn(); void FadeOut(); float FadeTimeRemaining() const; diff --git a/Source/StudyFrameworkPlugin/Public/SFGameInstance.h b/Source/StudyFrameworkPlugin/Public/SFGameInstance.h index cb6622b494e7e8d0f150d62ff26c4abf5c9f0783..5a1c98ce8be0371a56fb5beb4643379a3f9e8565 100644 --- a/Source/StudyFrameworkPlugin/Public/SFGameInstance.h +++ b/Source/StudyFrameworkPlugin/Public/SFGameInstance.h @@ -9,6 +9,7 @@ #include "SFStudySetup.h" #include "SFParticipant.h" #include "HUD/SFMasterHUD.h" +#include "HUD/SFFadeHandler.h" #include "GazeTracking/SFGazeTracker.h" #include "Cluster/IDisplayClusterClusterManager.h" @@ -18,7 +19,6 @@ #include "SFGameInstance.generated.h" -class USFFadeHandler; DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnFadedInDelegate); @@ -51,17 +51,19 @@ public: //Fade to the next condition (use this to proceed in the study once condition is done) //bForce also goes to the next condition if the current condition was not finished (not all required dependent variables gathered) - //bForceFade: unless specified differently in the StudySetup it is faded between every two conditions, if bNoFadingOnSameMap is set to false, - // bForceFade forces to fade anyways between two conditions on the same map and has not effect otherwise + //Fade: if set to AsDefault, the value specified in ASFStudySetup::bNoFadingOnSameMap considered to decide whether to fade btw 2 conditions on the same map + // if ForceNoFade: independently from ASFStudySetup::bNoFadingOnSameMap it is not faded btw conditions on the same map + // if ForceFade: independently from ASFStudySetup::bNoFadingOnSameMap it is always faded UFUNCTION(BlueprintCallable) - bool NextCondition(bool bForce = false, bool bForceFade = false); + bool NextCondition(bool bForce = false, EFadeBetweenCondition Fade = EFadeBetweenCondition::AsDefault); //This method can be used to jump to a specific condition (DO NOT USE during normal study run) //bForce also goes to the next condition if the current condition was not finished (not all required dependent variables gathered) - //bForceFade: unless specified differently in the StudySetup it is faded between every two conditions, if bNoFadingOnSameMap is set to false, - // bForceFade forces to fade anyways between two conditions on the same map and has not effect otherwise + //Fade: if set to AsDefault, the value specified in ASFStudySetup::bNoFadingOnSameMap considered to decide whether to fade btw 2 conditions on the same map + // if ForceNoFade: independently from ASFStudySetup::bNoFadingOnSameMap it is not faded btw conditions on the same map + // if ForceFade: independently from ASFStudySetup::bNoFadingOnSameMap it is always faded UFUNCTION(BlueprintCallable) - bool GoToCondition(const USFCondition* Condition, bool bForce = false, bool bForceFade = false); + bool GoToCondition(const USFCondition* Condition, bool bForce = false, EFadeBetweenCondition Fade = EFadeBetweenCondition::AsDefault); //Whether the study was started already UFUNCTION(BlueprintCallable) @@ -177,8 +179,8 @@ protected: void EndStudy(); //we use cluster events so GoToConditionSynced can not run out of sync when using nDisplay in cluster mode - void GoToConditionSynced(FString ConditionName, bool bForced, bool bForceFade); //send the cluster event - void HandleGoToConditionSynced(FString ConditionName, bool bForced, bool bForceFade); //process the cluter event + void GoToConditionSynced(FString ConditionName, bool bForced, EFadeBetweenCondition Fade); //send the cluster event + void HandleGoToConditionSynced(FString ConditionName, bool bForced, EFadeBetweenCondition Fade); //process the cluter event FOnClusterEventJsonListener ClusterEventListenerDelegate; void HandleClusterEvent(const FDisplayClusterClusterEventJson& Event);