Skip to content
Snippets Groups Projects
Commit fdaa784c authored by Malte Christian Kögel's avatar Malte Christian Kögel
Browse files

Attempt to make interactive popup Windows ("Continue/Restart/Next...

Attempt to make interactive popup Windows ("Continue/Restart/Next Participant", Custom Participant ID, Indep Variables) cluster safe. This version runs on a normal machine, has not been tested on cluster yet
parent 5f48f168
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "HUD/SFGlobalFadeGameViewportClient.h" #include "HUD/SFGlobalFadeGameViewportClient.h"
#include "Help/SFUtils.h" #include "Help/SFUtils.h"
#include "Kismet/KismetStringLibrary.h"
#include "Logging/SFLoggingBPLibrary.h" #include "Logging/SFLoggingBPLibrary.h"
#include "Logging/SFLoggingUtils.h" #include "Logging/SFLoggingUtils.h"
...@@ -248,7 +249,34 @@ void USFGameInstance::PrepareWithStudySetup(ASFStudySetup* Setup) ...@@ -248,7 +249,34 @@ void USFGameInstance::PrepareWithStudySetup(ASFStudySetup* Setup)
"Next Participant", "Next Participant",
"Restart Study" "Restart Study"
}; };
int Answer = FSFUtils::OpenCustomDialog(MessageTitle, MessageText, Buttons); int Answer;
if(!FSFUtils::IsPrimary())
{
while (!bResultBufferSet)
{
//Wait for Dialog to be completed on primary node
};
Answer = ResultBuffer;
ResultBuffer = -1;
bResultBufferSet = false;
}
else
{
Answer = FSFUtils::OpenCustomDialog(MessageTitle, MessageText, Buttons);
// Broadcast result to secondary nodes
if (IDisplayCluster::Get().GetOperationMode() == EDisplayClusterOperationMode::Cluster)
{
IDisplayClusterClusterManager* const Manager = IDisplayCluster::Get().GetClusterMgr();
FDisplayClusterClusterEventJson Event;
TMap<FString, FString> Params;
Params.Add("Result", FString::FromInt(Answer));
Event.Type = "SFGameInstanceEvent";
Event.Name = "CustomDialogCompleted";
Event.Parameters = Params;
Manager->EmitClusterEventJson(Event, false);
}
}
switch (Answer) switch (Answer)
{ {
...@@ -289,7 +317,37 @@ void USFGameInstance::PrepareWithStudySetup(ASFStudySetup* Setup) ...@@ -289,7 +317,37 @@ void USFGameInstance::PrepareWithStudySetup(ASFStudySetup* Setup)
while(!bValidIDEntered) while(!bValidIDEntered)
{ {
FString IDGiven; FString IDGiven;
int Result = FSFUtils::OpenCustomDialogText("Participant ID", "Please type in your ID:", "", IDGiven); int Result;
if (!FSFUtils::IsPrimary())
{
while (!bResultBufferSet)
{
//Wait for Dialog to be completed on primary node
};
Result = ResultBuffer;
ResultBuffer = -1;
bResultBufferSet = false;
IDGiven = TextBuffer;
TextBuffer = "";
bTextBufferSet = false;
}
else
{
Result = FSFUtils::OpenCustomDialogText("Participant ID", "Please type in your ID:", "", IDGiven);
// Broadcast result to secondary nodes
if (IDisplayCluster::Get().GetOperationMode() == EDisplayClusterOperationMode::Cluster)
{
IDisplayClusterClusterManager* const Manager = IDisplayCluster::Get().GetClusterMgr();
FDisplayClusterClusterEventJson Event;
TMap<FString, FString> Params;
Params.Add("Result", FString::FromInt(Result));
Params.Add("Text", IDGiven);
Event.Type = "SFGameInstanceEvent";
Event.Name = "CustomDialogTextCompleted";
Event.Parameters = Params;
Manager->EmitClusterEventJson(Event, false);
}
}
if (Result < 0) { if (Result < 0) {
FSFLoggingUtils::Log("[USFGameInstance::PrepareWithStudySetup] The window for entering the participant ID was closed without giving an answer, repeat question!", false); FSFLoggingUtils::Log("[USFGameInstance::PrepareWithStudySetup] The window for entering the participant ID was closed without giving an answer, repeat question!", false);
continue; continue;
...@@ -526,6 +584,24 @@ void USFGameInstance::HandleClusterEvent(const FDisplayClusterClusterEventJson& ...@@ -526,6 +584,24 @@ void USFGameInstance::HandleClusterEvent(const FDisplayClusterClusterEventJson&
} }
HandleGoToConditionSynced(Event.Parameters["ConditionName"], Event.Parameters["bForced"] == "true", Fade); HandleGoToConditionSynced(Event.Parameters["ConditionName"], Event.Parameters["bForced"] == "true", Fade);
} }
else if (Event.Name == "CustomDialogCompleted")
{
if(!FSFUtils::IsPrimary())
{
ResultBuffer = UKismetStringLibrary::Conv_StringToInt(Event.Parameters["Result"]);
bResultBufferSet = true;
}
}
else if (Event.Name == "CustomDialogTextCompleted")
{
if (!FSFUtils::IsPrimary())
{
TextBuffer = Event.Parameters["Text"];
bTextBufferSet = true;
ResultBuffer = UKismetStringLibrary::Conv_StringToInt(Event.Parameters["Result"]);
bResultBufferSet = true;
}
}
} }
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "Logging/SFLoggingBPLibrary.h" #include "Logging/SFLoggingBPLibrary.h"
#include "Logging/SFLoggingUtils.h" #include "Logging/SFLoggingUtils.h"
#include "JsonUtilities.h" #include "JsonUtilities.h"
#include "Kismet/KismetStringLibrary.h"
USFParticipant::USFParticipant() USFParticipant::USFParticipant()
{ {
...@@ -27,12 +28,45 @@ bool USFParticipant::Initialize(int SequenceNumber, FString ID) ...@@ -27,12 +28,45 @@ bool USFParticipant::Initialize(int SequenceNumber, FString ID)
StartTime = FPlatformTime::Seconds(); StartTime = FPlatformTime::Seconds();
IDisplayClusterClusterManager* ClusterManager = IDisplayCluster::Get().GetClusterMgr();
if (ClusterManager && !ClusterEventListenerDelegate.IsBound())
{
ClusterEventListenerDelegate = FOnClusterEventJsonListener::CreateUObject(this, &USFParticipant::HandleClusterEvent);
ClusterManager->AddClusterEventJsonListener(ClusterEventListenerDelegate);
}
ParticipantLoggingInfix = "LogParticipant-" + ParticipantID + "_" + FDateTime::Now().ToString(); ParticipantLoggingInfix = "LogParticipant-" + ParticipantID + "_" + FDateTime::Now().ToString();
FSFLoggingUtils::SetupParticipantLoggingStream(ParticipantLoggingInfix); FSFLoggingUtils::SetupParticipantLoggingStream(ParticipantLoggingInfix);
return true; return true;
} }
void USFParticipant::HandleClusterEvent(const FDisplayClusterClusterEventJson & Event) {
if (Event.Type == "SFParticipantEvent") {
//now we actually react on all cluster nodes:
if (Event.Name == "CustomDialogCompleted")
{
if (!FSFUtils::IsPrimary())
{
ResultBuffer = UKismetStringLibrary::Conv_StringToInt(Event.Parameters["Result"]);
bResultBufferSet = true;
}
}
else if (Event.Name == "CustomDialogTextCompleted")
{
if (!FSFUtils::IsPrimary())
{
TextBuffer = Event.Parameters["Text"];
bTextBufferSet = true;
ResultBuffer = UKismetStringLibrary::Conv_StringToInt(Event.Parameters["Result"]);
bResultBufferSet = true;
}
}
}
}
void USFParticipant::SetStudyConditions(TArray<USFCondition*> NewConditions) void USFParticipant::SetStudyConditions(TArray<USFCondition*> NewConditions)
{ {
Conditions = NewConditions; Conditions = NewConditions;
...@@ -606,7 +640,37 @@ void USFParticipant::SetIndependentVariablesFromStudySetup(ASFStudySetup* Setup) ...@@ -606,7 +640,37 @@ void USFParticipant::SetIndependentVariablesFromStudySetup(ASFStudySetup* Setup)
case EValType::TEXT: case EValType::TEXT:
{ {
FString Answer; FString Answer;
int Result = FSFUtils::OpenCustomDialogText(Var->Name, Var->Prompt, "", Answer); int Result;
if (!FSFUtils::IsPrimary())
{
while (!bResultBufferSet)
{
//Wait for Dialog to be completed on primary node
};
Answer = TextBuffer;
TextBuffer = "";
bTextBufferSet = false;
Result = ResultBuffer;
ResultBuffer = -1;
bResultBufferSet = false;
}
else
{
Result = FSFUtils::OpenCustomDialogText(Var->Name, Var->Prompt, "", Answer);
// Broadcast result to secondary nodes
if (IDisplayCluster::Get().GetOperationMode() == EDisplayClusterOperationMode::Cluster)
{
IDisplayClusterClusterManager* const Manager = IDisplayCluster::Get().GetClusterMgr();
FDisplayClusterClusterEventJson Event;
TMap<FString, FString> Params;
Params.Add("Result", FString::FromInt(Result));
Params.Add("Text", Answer);
Event.Type = "SFParticipantEvent";
Event.Name = "CustomDialogTextCompleted";
Event.Parameters = Params;
Manager->EmitClusterEventJson(Event, false);
}
}
if (Result < 0) { if (Result < 0) {
FSFLoggingUtils::Log("[USFParticipant::SetIndependentVariablesFromStudySetup] The window for the variable was closed without giving an answer!", false); FSFLoggingUtils::Log("[USFParticipant::SetIndependentVariablesFromStudySetup] The window for the variable was closed without giving an answer!", false);
} }
...@@ -618,7 +682,33 @@ void USFParticipant::SetIndependentVariablesFromStudySetup(ASFStudySetup* Setup) ...@@ -618,7 +682,33 @@ void USFParticipant::SetIndependentVariablesFromStudySetup(ASFStudySetup* Setup)
case EValType::MULTIPLECHOICE: case EValType::MULTIPLECHOICE:
{ {
int Answer = FSFUtils::OpenCustomDialog(Var->Name, Var->Prompt, Var->Options); int Answer;
if (!FSFUtils::IsPrimary())
{
while (!bResultBufferSet)
{
//Wait for Dialog to be completed on primary node
};
Answer = ResultBuffer;
ResultBuffer = -1;
bResultBufferSet = false;
}
else
{
Answer = FSFUtils::OpenCustomDialog(Var->Name, Var->Prompt, Var->Options);
// Broadcast result to secondary nodes
if (IDisplayCluster::Get().GetOperationMode() == EDisplayClusterOperationMode::Cluster)
{
IDisplayClusterClusterManager* const Manager = IDisplayCluster::Get().GetClusterMgr();
FDisplayClusterClusterEventJson Event;
TMap<FString, FString> Params;
Params.Add("Result", FString::FromInt(Answer));
Event.Type = "SFParticipantEvent";
Event.Name = "CustomDialogCompleted";
Event.Parameters = Params;
Manager->EmitClusterEventJson(Event, false);
}
}
if (Answer < 0) { if (Answer < 0) {
FSFLoggingUtils::Log("[USFParticipant::SetIndependentVariablesFromStudySetup] The window for the variable was closed without selecting anything!", false); FSFLoggingUtils::Log("[USFParticipant::SetIndependentVariablesFromStudySetup] The window for the variable was closed without selecting anything!", false);
} }
......
...@@ -249,5 +249,17 @@ protected: ...@@ -249,5 +249,17 @@ protected:
//Controls central logging functionality, stores logging parameters //Controls central logging functionality, stores logging parameters
UPROPERTY() UPROPERTY()
USFLogObject* LogObject; USFLogObject* LogObject;
private:
//Use this to write result from primary node
UPROPERTY()
FString TextBuffer = "";
UPROPERTY()
bool bTextBufferSet = false;
UPROPERTY()
int ResultBuffer = -1;
UPROPERTY()
bool bResultBufferSet = false;
}; };
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
#include "SFCondition.h" #include "SFCondition.h"
#include "SFMultipleTrialDependentVariable.h" #include "SFMultipleTrialDependentVariable.h"
#include "Cluster/IDisplayClusterClusterManager.h"
#include "Cluster/DisplayClusterClusterEvent.h"
#include "SFParticipant.generated.h" #include "SFParticipant.generated.h"
...@@ -123,4 +126,18 @@ protected: ...@@ -123,4 +126,18 @@ protected:
double StartTime = 0.0; double StartTime = 0.0;
FString ParticipantLoggingInfix; FString ParticipantLoggingInfix;
FOnClusterEventJsonListener ClusterEventListenerDelegate;
void HandleClusterEvent(const FDisplayClusterClusterEventJson& Event);
private:
//Use this to write result from primary node
UPROPERTY()
FString TextBuffer = "";
UPROPERTY()
bool bTextBufferSet = false;
UPROPERTY()
int ResultBuffer = -1;
UPROPERTY()
bool bResultBufferSet = false;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment