DCDC/Assets/Scripts/PlantStats/NotesManager.cs

61 lines
2.0 KiB
C#

using System;
using Firebase;
using TMPro;
using UnityEngine;
namespace PlantStats
{
public class NotesManagerScript : MonoBehaviour
{
public GameObject addDialog;
public GameObject addDialogBackdrop;
public GameObject addNewNoteButton;
public TMP_InputField newNoteMessage;
public TextMeshProUGUI errorMessage;
private ApplicationManager _applicationManager;
private FirebaseNoteManager _firebaseNoteManager;
private void Awake()
{
_applicationManager = FindFirstObjectByType<ApplicationManager>();
if (_applicationManager == null) Debug.LogError("[DCDC] ApplicationManager component not found.");
_firebaseNoteManager = FindFirstObjectByType<FirebaseNoteManager>();
if (_firebaseNoteManager == null) Debug.LogError("[DCDC] FirebaseNoteManager component not found.");
}
private void FixedUpdate()
{
// only client (supervisor) can add notes
if (_applicationManager.InProgress || _applicationManager.IsHost == true) return;
if (!addNewNoteButton.activeSelf) addNewNoteButton.SetActive(true);
}
public void OpenAddNewNote()
{
addDialog.SetActive(true);
addDialogBackdrop.SetActive(true);
}
public void SaveAddNewNote()
{
if (newNoteMessage.text.Trim() == "")
{
Debug.LogError("[DCDC] Note message is empty. Not adding a new note.");
errorMessage.text = "Note message is empty. Please enter a message before saving.";
return;
}
_firebaseNoteManager.AddANewNote(newNoteMessage.text);
addDialog.SetActive(false);
addDialogBackdrop.SetActive(false);
}
public void CancelAddNewNote()
{
addDialog.SetActive(false);
addDialogBackdrop.SetActive(false);
}
}
}