From b200393bcf5dbd4fc3fb023bb1614ad1976e34a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Malte=20K=C3=B6gel?= <koegel@vr.rwth-aachen.de>
Date: Thu, 5 Oct 2023 13:26:23 +0200
Subject: [PATCH] WIP: Attempted to display warning, that level was started in
 debug mode. Not functional yet

---
 .../Private/HUD/SFHUDWidget.cpp               | 19 +++++++++++++++++++
 .../Private/HUD/SFMasterHUD.cpp               |  9 +++++++++
 .../Private/SFGameInstance.cpp                |  2 +-
 .../Public/HUD/SFHUDWidget.h                  |  7 +++++++
 .../Public/HUD/SFMasterHUD.h                  |  5 +++++
 5 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/Source/StudyFrameworkPlugin/Private/HUD/SFHUDWidget.cpp b/Source/StudyFrameworkPlugin/Private/HUD/SFHUDWidget.cpp
index 703778d..59408cf 100644
--- a/Source/StudyFrameworkPlugin/Private/HUD/SFHUDWidget.cpp
+++ b/Source/StudyFrameworkPlugin/Private/HUD/SFHUDWidget.cpp
@@ -5,6 +5,7 @@
 
 #include "Help/SFUtils.h"
 #include "Logging/SFLoggingUtils.h"
+#include <Kismet/KismetMathLibrary.h>
 
 
 USFHUDWidget::USFHUDWidget(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
@@ -54,6 +55,20 @@ void USFHUDWidget::SetStatus(const FString& Text)
 	StatusTextBox->SetText(FText::FromString(FString(TEXT("Status: ")) + Text));
 }
 
+void USFHUDWidget::SetbInDebugMode(bool InDebugMode) {
+	bInDebugMode = InDebugMode;
+	if (bInDebugModeTextBox){
+		if (bInDebugMode) {
+			bInDebugModeTextBox->SetText(FText::FromString("DEBUG MODE ||"));
+			bInDebugModeTextBox->SetColorAndOpacity(UKismetMathLibrary::MakeColor(0, 0, 1, 1));
+			bInDebugModeTextBox->SetVisibility(ESlateVisibility::Visible);
+		}
+		else{
+			bInDebugModeTextBox->SetText(FText::FromString(""));
+		}
+	}
+}
+
 void USFHUDWidget::AddLogMessage(const FString& Text)
 {
 	if (!Text.IsEmpty())
@@ -74,6 +89,7 @@ void USFHUDWidget::AddLogMessage(const FString& Text)
 
 void USFHUDWidget::ClearWidget()
 {
+	//TODO Clear Debug as well? When is this called?
 	SetCondition({});
 	SetParticipant("???");
 	SetPhase("???");
@@ -83,6 +99,7 @@ void USFHUDWidget::ClearWidget()
 FHUDSavedData USFHUDWidget::GetData()
 {
 	FHUDSavedData Data;
+	Data.bInDebugMode = bInDebugMode; // TODO: Do we want to save, whether data has been collected in debug mode? Or should we treat it the same? What happens, if the first half is collected in debug mode, the second half in normal mode
 	Data.Status = StatusTextBox->GetText().ToString();
 	Data.Participant = ParticipantTextBox->GetText().ToString();
 	Data.Phase = PhaseTextBox->GetText().ToString();
@@ -93,6 +110,8 @@ FHUDSavedData USFHUDWidget::GetData()
 
 void USFHUDWidget::SetData(FHUDSavedData Data)
 {
+	//TODO Do we want this?
+	//SetbInDebugMode(bInDebugMode);
 	if (Data.Status.StartsWith("Status:"))
 		StatusTextBox->SetText(FText::FromString(Data.Status));
 	else
diff --git a/Source/StudyFrameworkPlugin/Private/HUD/SFMasterHUD.cpp b/Source/StudyFrameworkPlugin/Private/HUD/SFMasterHUD.cpp
index 621efd0..bc768fa 100644
--- a/Source/StudyFrameworkPlugin/Private/HUD/SFMasterHUD.cpp
+++ b/Source/StudyFrameworkPlugin/Private/HUD/SFMasterHUD.cpp
@@ -83,6 +83,7 @@ void ASFMasterHUD::BeginPlay()
 	FHUDSavedData& Data = USFGameInstance::Get()->HUDSavedData;
 
 	HUDWidget->SetData(Data);
+	HUDWidget->SetbInDebugMode(bInDebugMode);
 
 	if(UnForwardedParticipant)
 	{
@@ -197,6 +198,14 @@ void ASFMasterHUD::SetNextConditionButtonVisibility(ESlateVisibility Visibility)
 	HUDWidget->GetNextButton()->SetVisibility(Visibility);
 }
 
+void ASFMasterHUD::SetbInDebugMode(bool InDebugMode)
+{
+	bInDebugMode = InDebugMode;
+	if (HUDWidget) {
+		HUDWidget->SetbInDebugMode(InDebugMode);
+	}
+}
+
 void ASFMasterHUD::DrawBackground()
 {
 	FLinearColor BackgroundColor = FLinearColor::Black;
diff --git a/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp b/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp
index 86d6b01..43e201a 100644
--- a/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp
+++ b/Source/StudyFrameworkPlugin/Private/SFGameInstance.cpp
@@ -155,7 +155,7 @@ void USFGameInstance::RestoreLastParticipantForDebugStart(USFCondition* InStartC
 
 	Participant->Initialize(ParticipantSequenceNumber, ParticipantID);
 	Participant->LoadConditionsFromJson();
-
+	Cast<ASFMasterHUD>(GetWorld()->GetFirstPlayerController()->GetHUD())->SetbInDebugMode(true); //Display notification in HUD, that we are in debug mode
 	
 	InitFadeHandler(StudySetup->FadeConfig);
 
diff --git a/Source/StudyFrameworkPlugin/Public/HUD/SFHUDWidget.h b/Source/StudyFrameworkPlugin/Public/HUD/SFHUDWidget.h
index fb9d0c5..95b5830 100644
--- a/Source/StudyFrameworkPlugin/Public/HUD/SFHUDWidget.h
+++ b/Source/StudyFrameworkPlugin/Public/HUD/SFHUDWidget.h
@@ -17,6 +17,7 @@ USTRUCT()
 struct FHUDSavedData
 {
 	GENERATED_BODY()
+	bool bInDebugMode;
 	FString Status;
 	FString Participant;
 	FString Phase;
@@ -44,6 +45,8 @@ public:
 	void SetCondition(const TMap<FString, FString>& Texts);
 	void SetStatus(const FString& Text);
 
+	void SetbInDebugMode(bool InDebugMode);
+
 	void AddLogMessage(const FString& Text);
 
 	void ClearWidget();
@@ -60,6 +63,10 @@ public:
 
 private:
 
+	// Notiy user in HUD, if level is used in Debug-Mode
+	bool bInDebugMode = false;
+	UPROPERTY(EditAnywhere, meta = (BindWidget)) UTextBlock* bInDebugModeTextBox;
+
 	UPROPERTY(EditAnywhere, meta = (BindWidget)) UTextBlock* StatusTextBox;
 	UPROPERTY(EditAnywhere, meta = (BindWidget)) UTextBlock* ParticipantTextBox;
 	UPROPERTY(EditAnywhere, meta = (BindWidget)) UTextBlock* PhaseTextBox;
diff --git a/Source/StudyFrameworkPlugin/Public/HUD/SFMasterHUD.h b/Source/StudyFrameworkPlugin/Public/HUD/SFMasterHUD.h
index 23fdb72..619c1c6 100644
--- a/Source/StudyFrameworkPlugin/Public/HUD/SFMasterHUD.h
+++ b/Source/StudyFrameworkPlugin/Public/HUD/SFMasterHUD.h
@@ -49,6 +49,9 @@ public:
 	UFUNCTION()
 	void SetNextConditionButtonVisibility(ESlateVisibility Visibility);
 
+	UFUNCTION()
+		void SetbInDebugMode(bool InDebugMode);
+
 	UPROPERTY(EditDefaultsOnly, Category = "Interactive")
 	TSubclassOf<USFHUDWidget> SFWidgetClass;
 	UPROPERTY(EditDefaultsOnly, Category = "Interactive")
@@ -75,6 +78,8 @@ private:
 	void DrawBackground();
 	float BackgroundAlpha = 1.0f;
 
+	bool bInDebugMode=false;
+
 	ASFHMDSpectatorHUDHelp* HMDHUDHelper;
 	bool bHMDHUDHelperTextureSet= false;
 
-- 
GitLab