Add notes handling to TaskButtonManager for UDP commands

This commit is contained in:
tom.hempel
2025-11-06 13:18:12 +01:00
parent fb002a6096
commit e99159a368
2 changed files with 61 additions and 7 deletions

View File

@ -18,12 +18,17 @@ public class TaskButtonManager : MonoBehaviour
private string pendingTimerCommand = null; private string pendingTimerCommand = null;
private readonly object sceneLock = new object(); private readonly object sceneLock = new object();
private readonly object timerLock = new object(); private readonly object timerLock = new object();
private readonly object notesLock = new object();
private TaskTimer taskTimer; private TaskTimer taskTimer;
private NotesDisplay notesDisplay;
private string pendingNotesText = null;
private void Start() private void Start()
{ {
// Find TaskTimer in the scene // Find TaskTimer in the scene
taskTimer = FindObjectOfType<TaskTimer>(); taskTimer = FindObjectOfType<TaskTimer>();
// Find NotesDisplay in the scene
notesDisplay = FindObjectOfType<NotesDisplay>();
if (enableUDPControl) if (enableUDPControl)
{ {
@ -60,6 +65,23 @@ public class TaskButtonManager : MonoBehaviour
} }
} }
// Check for pending notes updates (must be done on main thread)
lock (notesLock)
{
if (!string.IsNullOrEmpty(pendingNotesText))
{
if (notesDisplay != null)
{
notesDisplay.SetNotes(pendingNotesText);
}
else
{
Debug.LogWarning("NotesDisplay not found in scene. Cannot display notes text.");
}
pendingNotesText = null;
}
}
// VR Tasks (Keys 1-4) // VR Tasks (Keys 1-4)
if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1)) if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1))
LoadSceneByName("VR-Task1"); LoadSceneByName("VR-Task1");
@ -131,12 +153,12 @@ public class TaskButtonManager : MonoBehaviour
if (string.IsNullOrEmpty(message)) if (string.IsNullOrEmpty(message))
return; return;
// Parse command format: COMMAND:Parameter // Parse command format: COMMAND:Parameter (Parameter may contain additional colons)
string[] parts = message.Split(':'); int separatorIndex = message.IndexOf(':');
if (parts.Length >= 2) if (separatorIndex > 0 && separatorIndex < message.Length - 1)
{ {
string commandType = parts[0].Trim().ToUpper(); string commandType = message.Substring(0, separatorIndex).Trim().ToUpper();
string parameter = parts[1].Trim(); string parameter = message.Substring(separatorIndex + 1); // keep raw to preserve spaces/colons
if (commandType == "SWITCH") if (commandType == "SWITCH")
{ {
@ -156,14 +178,23 @@ public class TaskButtonManager : MonoBehaviour
} }
Debug.Log($"Scheduled timer command: {parameter}"); Debug.Log($"Scheduled timer command: {parameter}");
} }
else if (commandType == "NOTES")
{
// Notes display command
lock (notesLock)
{
pendingNotesText = parameter;
}
Debug.Log($"Scheduled notes update: {parameter}");
}
else else
{ {
Debug.LogWarning($"Unknown UDP command type: {commandType}. Expected: SWITCH or TIMER"); Debug.LogWarning($"Unknown UDP command type: {commandType}. Expected: SWITCH, TIMER or NOTES");
} }
} }
else else
{ {
Debug.LogWarning($"Invalid UDP command format: {message}. Expected format: COMMAND:Parameter (e.g., SWITCH:SceneName or TIMER:START)"); Debug.LogWarning($"Invalid UDP command format: {message}. Expected format: COMMAND:Parameter (e.g., SWITCH:SceneName, TIMER:START or NOTES:Your text)");
} }
} }

View File

@ -0,0 +1,23 @@
using UnityEngine;
using TMPro;
public class NotesDisplay : MonoBehaviour
{
[Header("Notes UI")]
[Tooltip("TextMeshProUGUI field where received notes will be displayed")]
public TextMeshProUGUI notesText;
public void SetNotes(string text)
{
if (notesText != null)
{
notesText.text = text;
}
else
{
Debug.LogWarning("NotesDisplay: notesText is not assigned in the inspector.");
}
}
}