using System.Collections; using System.Collections.Generic; using UnityEngine; using InfallibleCode; using TMPro; public class CollectibleEntry : MonoBehaviour { [Header("Collectible Entry")] [Tooltip("This is a title, so the entry can be saved")] [SerializeField] string _entryName; [Tooltip("What is the number of this entry, goes according to date")] [SerializeField] int _entryID; [Tooltip("Whose entry is that?")] [SerializeField] string _entryType; //{Medea,Children,Daniel,Investigators} [Tooltip("How much space does this text take?")] [SerializeField] float diaryScrollViewContentNewHeight; [Tooltip("Entry Text")] [TextArea(3/*min lines*/, 15/*max lines*/)] [SerializeField] string _entryText; //here goes the text of the entry [Tooltip("Players thoughts about the entry")] [TextArea(3/*min lines*/, 5/*max lines*/)] [SerializeField] string _playerThoughtsText; void Start() { if (diaryScrollViewContentNewHeight < 1080) { diaryScrollViewContentNewHeight = 1080; //1080 is the default price of this in Unity } } // Update is called once per frame void Update() { } public void DisplayEntryText() { StartCoroutine(UpdateInput()); SaveDiary(); } public void SaveDiary() { // Load existing data GameSaveData existingData = SaveSlotManager.LoadPlayerData(SaveSlotManager.GetInstance().selectedSaveSlotID); // Assuming saveSlotID is 0 if (existingData != null) { //If the collectable entry doesn't exist: if (!existingData.collectablesData.medeaDiaryEntryName.Contains(_entryName)) { //Add the entryName to the list. existingData.collectablesData.medeaDiaryEntryName.Add(_entryName); SaveSlotManager.UpdateAndSaveData(existingData); print("Entry saved!"); //Show save icon HERE! } else { print("Entry already saved!"); } } } IEnumerator UpdateInput() { //Wait because it can probably catch the input from the examinable item. yield return new WaitForSecondsRealtime(0.1f); while (ExaminableItemData.GetInstance().IsExamining) { if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton0/*A Button*/)) { ExaminableItemData.GetInstance().diaryScrollView.SetActive(true); //ExaminableItemData.GetInstance(). ExaminableItemData.GetInstance().diaryText.text = _entryText; ExaminableItemData.GetInstance().sentencesText.text = _playerThoughtsText; ExaminableItemData.GetInstance().diaryScrollViewContent.sizeDelta = new Vector2(ExaminableItemData.GetInstance().diaryScrollViewContent.sizeDelta.x, diaryScrollViewContentNewHeight); } yield return null; } yield return null; StopDisplayingEntryText(); } public void StopDisplayingEntryText() { ExaminableItemData.GetInstance().diaryText.text = ""; ExaminableItemData.GetInstance().diaryScrollView.SetActive(false); } }