124 lines
4.0 KiB
C#
124 lines
4.0 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.EventSystems;
|
||
|
|
using Michsky.MUIP;
|
||
|
|
using TMPro;
|
||
|
|
using Febucci.UI;
|
||
|
|
|
||
|
|
|
||
|
|
public class DialogueController : MonoBehaviour, IPointerClickHandler {
|
||
|
|
[SerializeField] TextMeshProUGUI textTMPro;
|
||
|
|
[SerializeField] TextMeshProUGUI nameTMPro;
|
||
|
|
[SerializeField] TextAnimatorPlayer typer;
|
||
|
|
[SerializeField] ButtonManager button;
|
||
|
|
[SerializeField] RectTransform optionMenu;
|
||
|
|
[SerializeField] bool clickAnywhere = false;
|
||
|
|
|
||
|
|
[SerializeField] VNController vn = null;
|
||
|
|
|
||
|
|
[HideInInspector] List<DialogueInteraction> interactions;
|
||
|
|
[HideInInspector] public int dialogueIndex = 0;
|
||
|
|
|
||
|
|
// Whether to use VNData.NextScene or to pick a random Manager scene.
|
||
|
|
[SerializeField] public bool chooseManagerScene = false;
|
||
|
|
|
||
|
|
private string Compile(string text) {
|
||
|
|
// TODO: Compile for all possible names, controllable via DialogueInteraction flags
|
||
|
|
return text.Replace("%Her%", GameData.GLOBAL.characterNames[Character.Her]);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void Interact() {
|
||
|
|
if (dialogueIndex >= interactions.Count && optionMenu != null) {
|
||
|
|
optionMenu.gameObject.SetActive(true);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (dialogueIndex >= interactions.Count) {
|
||
|
|
vn.Done();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
DialogueInteraction d = interactions[dialogueIndex];
|
||
|
|
if (vn != null) {
|
||
|
|
vn.Interact(d);
|
||
|
|
}
|
||
|
|
nameTMPro.SetText(GameData.GLOBAL.characterNames[d.character]);
|
||
|
|
string text = Compile(d.text);
|
||
|
|
textTMPro.SetText(text);
|
||
|
|
if (d.unlock != Unlockable.None) {
|
||
|
|
GameData.Unlock(d.unlock);
|
||
|
|
}
|
||
|
|
if (d.gameOver) {
|
||
|
|
vn.gameOverAfterDone = true;
|
||
|
|
}
|
||
|
|
dialogueIndex += 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void NextButtonPressed() {
|
||
|
|
if (typer.textAnimator.allLettersShown) {
|
||
|
|
if (button.enabled) {
|
||
|
|
button.enabled = false;
|
||
|
|
}
|
||
|
|
Interact();
|
||
|
|
} else {
|
||
|
|
typer.SkipTypewriter();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnPointerClick(PointerEventData eventData) {
|
||
|
|
if (clickAnywhere) {
|
||
|
|
NextButtonPressed();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Set up and start a dialogue interaction.
|
||
|
|
// "fresh" means it's the first scene on Start, which triggers an appropriate load of VN assets.
|
||
|
|
// In the manager, "fresh" also causes the background to be set based on the time of day.
|
||
|
|
// Turn "fresh" off when the same VNAsset pack is used for multiple Dialogue scenes
|
||
|
|
// i.e. in the Manager, Studio, or tutorial.
|
||
|
|
public void SetUp(bool fresh = true) {
|
||
|
|
dialogueIndex = 0;
|
||
|
|
if (clickAnywhere) {
|
||
|
|
button.gameObject.SetActive(false);
|
||
|
|
} else {
|
||
|
|
button.enabled = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (optionMenu != null) {
|
||
|
|
optionMenu.gameObject.SetActive(false);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (fresh && chooseManagerScene) {
|
||
|
|
if (GameData.GLOBAL.ranAway) {
|
||
|
|
VNData.NextScene = Dialogue.Manager_RanAway;
|
||
|
|
} else if (GameData.GLOBAL.status == Status.Farty) {
|
||
|
|
VNData.NextScene = VNData.fartyScenes[Random.Range(0, VNData.fartyScenes.Count)];
|
||
|
|
} else if (GameData.GLOBAL.hunger > 2 && Random.Range(0f, 1f) > 0.5f) {
|
||
|
|
VNData.NextScene = Dialogue.Manager_Hungry1;
|
||
|
|
} else if (GameData.GLOBAL.status == Status.Moody) {
|
||
|
|
VNData.NextScene = VNData.moodyScenes[Random.Range(0, VNData.moodyScenes.Count)];
|
||
|
|
} else {
|
||
|
|
VNData.NextScene = VNData.managerScenes[Random.Range(0, VNData.managerScenes.Count)];
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// The scene to play is pre-loaded here.
|
||
|
|
interactions = VNData.GLOBAL.DIALOGUE[VNData.NextScene];
|
||
|
|
GameData.GLOBAL.viewedScenes.Add(VNData.NextScene);
|
||
|
|
vn.SetUp(VNData.NextScene, chooseManagerScene, fresh);
|
||
|
|
Interact();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Start is called before the first frame update
|
||
|
|
void Start() {
|
||
|
|
SetUp();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update is called once per frame
|
||
|
|
void Update() {
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|