Scriptum/Assets/Scripts/REFACTORING/Application/Dialogue/Model/DialogueStepModel.cs
2022-12-20 03:30:37 +01:00

79 lines
2.2 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
// change to "mission step" model in future
[Serializable]
public class DialogueStepModel
{
[SerializeField]
public string Header;
[SerializeField] // this flag tell whatewer dialoge ware already display to user
public bool WasDisplayed = false;
[SerializeField] // list to map to queue in DialogueController
public List<DialogueModel> ListOfSentences = new List<DialogueModel>();
[SerializeField]
public UnityEvent EndOfDialogueStepAction = new UnityEvent();
// for displaying set of sentences in one display
public DialogueController DialogueController { get; protected set; }
public DialogueStepModel()
{
// Add marked step as displayed action as first!
EndOfDialogueStepAction.AddListener(() => { MarkAsDisplayed(); });
}
public DialogueStepModel(DialogueController _dialogueController)
{
// Add marked step as displayed action as first!
EndOfDialogueStepAction.AddListener(() => { MarkAsDisplayed(); });
DialogueController = _dialogueController;
}
/// <summary>
/// Just convert list to queue structure :D
/// </summary>
public virtual void Build()
{
// 1. Clear previous setups
// 2. Map first structur into second
DialogueController = new DialogueController();
foreach (DialogueModel DialogueModel in ListOfSentences)
{
// Pass data to builded panel (name, sentence, buttons)
DialogueModel.Header = Header; // set header
DialogueController.AddSentence(DialogueModel);
}
// 3 Bind ending actions
DialogueController.SetActionAfterDialogueEnds(EndOfDialogueStepAction);
}
public void SetActionAfterDialogueStep(UnityEvent _endOfDialogueStepAction)
{
EndOfDialogueStepAction = _endOfDialogueStepAction;
}
public void SetActionAfterDialogueStep(Action _finishDialogueAction)
{
EndOfDialogueStepAction.AddListener(new UnityAction(_finishDialogueAction));
}
public void MarkAsDisplayed()
{
WasDisplayed = true;
}
}