Scriptum/Assets/Scripts/REFACTORING/Application/Dialogue/Controller/DialogueController.cs

108 lines
2.9 KiB
C#
Raw Normal View History

2022-10-16 19:40:44 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
[Serializable]
public class DialogueController
{
public Queue<DialogueModel> listOfDialogue = new Queue<DialogueModel>();
private UnityEvent EndOfDialogueStepAction = new UnityEvent();
[SerializeField]
public GameObject CurrentPanel;
/// <summary>
/// Set panel info (panel, coords, text, buttons)
/// </summary>
/// <param name="dialogueModel"></param>
public void AddSentence(DialogueModel dialogueModel)
{
listOfDialogue.Enqueue(dialogueModel);
}
/*
* TODO add endpoints to setup button sctions via others scripyts ! ! !
public void AddButton(PanelButtonStepModel _buttonModel)
{
Buttons.Add(_buttonModel);
}
public void SetButtons(List<PanelButtonStepModel> _buttonsModelList)
{
Buttons = _buttonsModelList;
}
*/
public void SetActionAfterDialogueEnds(UnityEvent _endOfDialogueStepAction)
{
EndOfDialogueStepAction = _endOfDialogueStepAction;
}
public void SetActionAfterDialogueEnds(Action _finishDialogueAction)
{
EndOfDialogueStepAction.AddListener( new UnityAction( _finishDialogueAction));
}
public void Show(DialogueModel panelModel)
{
Panel panelDis = panelModel.Panel(panelModel.Header, panelModel);
2022-10-16 19:40:44 +02:00
panelDis.PanelInstance = panelDis.BuildPanel();
if(!(panelDis is QuestionPanel))
panelDis.SetContinueButtonAction(ShowNextPanel, this);
2022-10-16 19:40:44 +02:00
CurrentPanel = panelDis.PanelInstance;
}
/// <summary>
/// Return false if there was no more 'sentences' in current 'step'
/// </summary>
/// <param name="parentDialController"></param>
/// <returns></returns>
public bool ShowNextPanel(DialogueController parentDialController)
2022-10-16 19:40:44 +02:00
{
if (listOfDialogue.Count == 0)
{
CloseCurrentPanel(parentDialController);
2022-12-04 18:42:34 +01:00
FinishDialoguStep();
return false;
2022-10-16 19:40:44 +02:00
}
else
{
MonoBehaviour.Destroy(parentDialController.CurrentPanel);
DialogueModel nextPanel = parentDialController.listOfDialogue.Dequeue();
Show(nextPanel);
}
return true;
}
public void CloseCurrentPanel(DialogueController parentDialController)
{
MonoBehaviour.Destroy(parentDialController.CurrentPanel);
}
public void CloseCurrentPanel()
{
MonoBehaviour.Destroy(CurrentPanel);
2022-10-16 19:40:44 +02:00
}
// if palyer click last dialogue panel's "continue" button then ShowNextPanel
// function invoke this method whioch contain external action :D - MAGIC
2022-12-04 18:42:34 +01:00
public void FinishDialoguStep()
2022-10-16 19:40:44 +02:00
{
// set uoe everything whats is needed to change after finish dialogue
// eg.
// - add task to list
// - get reward
// - mark quest as completed :D
EndOfDialogueStepAction.Invoke();
}
}