basic setup of a character sheet - needs some more work
Wiring up character interviewed Added property for bulletized text - ready to add when we have some
This commit is contained in:
48
Assets/Scripts/DialogueSystem/CharacterSheetController.cs
Normal file
48
Assets/Scripts/DialogueSystem/CharacterSheetController.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class CharacterSheetController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text m_characterNameText;
|
||||
[SerializeField] private TMP_Text m_line;
|
||||
[SerializeField] private Transform m_lineHolder;
|
||||
|
||||
private Dictionary<string, GameObject> m_lines = new Dictionary<string, GameObject>();
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
foreach(var line in m_lines)
|
||||
{
|
||||
Destroy(line.Value);
|
||||
}
|
||||
|
||||
m_lines.Clear();
|
||||
}
|
||||
|
||||
public void SetName(string name)
|
||||
{
|
||||
m_characterNameText.text = name;
|
||||
}
|
||||
|
||||
// Adds a line to the character sheet.
|
||||
public void AddLine(string lineText)
|
||||
{
|
||||
if (LineExists(lineText))
|
||||
return;
|
||||
|
||||
var line = Instantiate(m_line, m_lineHolder);
|
||||
line.text = lineText;
|
||||
|
||||
line.gameObject.SetActive(true);
|
||||
|
||||
m_lines.Add(lineText, line.gameObject);
|
||||
}
|
||||
|
||||
// Returns if the line has already been added.
|
||||
private bool LineExists(string lineText)
|
||||
{
|
||||
return m_lines.ContainsKey(lineText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 113c9cdbaeba15f47a35e92d7d13c848
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,6 +3,7 @@
|
||||
public class Dialogue
|
||||
{
|
||||
public string text;
|
||||
public string bulletizedText;
|
||||
}
|
||||
|
||||
public class QuestionData
|
||||
|
||||
@@ -1,19 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DialogueController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private DialoguePanel m_dialoguePanel;
|
||||
[SerializeField] private List<CharacterData> m_characterDatas;
|
||||
|
||||
// DEBUG - Will need replacing with the character you selected.
|
||||
private void Start()
|
||||
{
|
||||
DisplayCharacterText(m_characterDatas[0]);
|
||||
DisplayCharacterText(CharacterManager.Instance.CharacterDatas[0]);
|
||||
|
||||
m_dialoguePanel.OnQuestionsFinished += OnQuestionsFinished;
|
||||
}
|
||||
|
||||
public void DisplayCharacterText(CharacterData character)
|
||||
{
|
||||
m_dialoguePanel.Setup(character);
|
||||
}
|
||||
|
||||
public void OnQuestionsFinished(string characterName)
|
||||
{
|
||||
Debug.Log($"DialogueController: Character {characterName} finished interviewing");
|
||||
|
||||
CharacterManager.Instance.SetInterviewed(characterName);
|
||||
|
||||
// TODO: stop the dialogue and return to gameplay...
|
||||
// TODO: we could probably show a "Quit" button highlighted.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -5,17 +6,25 @@ using UnityEngine.UI;
|
||||
|
||||
public class DialoguePanel : MonoBehaviour
|
||||
{
|
||||
public Action<string> OnQuestionsFinished;
|
||||
|
||||
[SerializeField] private Transform m_questionHolder;
|
||||
[SerializeField] private Button m_questionButton;
|
||||
|
||||
[SerializeField] private TMP_Text m_characterNameText;
|
||||
[SerializeField] private TMP_Text m_characterText;
|
||||
[SerializeField] private CharacterSheetController m_characterSheetController;
|
||||
|
||||
private const float TypingSpeed = 0.03f;
|
||||
|
||||
private CharacterData m_currentCharacter;
|
||||
private bool m_skipped = false;
|
||||
|
||||
private int m_questionCount = QuestionData.Questions.Length;
|
||||
private int m_questionsAsked = 0;
|
||||
|
||||
private bool QuestionsFinished => m_questionsAsked >= m_questionCount;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
PopulateQuestionButtons();
|
||||
@@ -27,6 +36,9 @@ public class DialoguePanel : MonoBehaviour
|
||||
{
|
||||
Cleanup();
|
||||
|
||||
m_characterSheetController.Cleanup();
|
||||
m_characterSheetController.SetName(characterData.name);
|
||||
|
||||
m_currentCharacter = characterData;
|
||||
m_characterNameText.text = characterData.name;
|
||||
|
||||
@@ -84,6 +96,13 @@ public class DialoguePanel : MonoBehaviour
|
||||
m_skipped = true;
|
||||
m_characterText.text = text;
|
||||
|
||||
// If we've asked all the questions we should mark this character as interviewed and continue.
|
||||
if (QuestionsFinished)
|
||||
{
|
||||
OnQuestionsFinished?.Invoke(m_currentCharacter.name);
|
||||
yield break;
|
||||
}
|
||||
|
||||
// Re-enable the questions.
|
||||
m_questionHolder.gameObject.SetActive(true);
|
||||
}
|
||||
@@ -91,14 +110,16 @@ public class DialoguePanel : MonoBehaviour
|
||||
// Handles displaying the correct dialogue for the question.
|
||||
private void OnQuestionButtonClicked(int index)
|
||||
{
|
||||
//Debug.Log("Player picked option " + index);
|
||||
|
||||
Cleanup();
|
||||
|
||||
var dialogueOption = m_currentCharacter.m_dialogueOptions[index];
|
||||
StartCoroutine(DisplayText(dialogueOption.text));
|
||||
|
||||
// TODO: we should update the sheet with this information.
|
||||
m_characterSheetController.AddLine(dialogueOption.text);
|
||||
|
||||
// Increment questions asked.
|
||||
m_questionsAsked++;
|
||||
}
|
||||
|
||||
// Callback from Unity on the skip button.
|
||||
|
||||
Reference in New Issue
Block a user