summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/ChoiceManager.cs
blob: 6ab87f9c2c342ef64d7b2edddad226e04e74f685 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ChoiceManager : MonoBehaviour
{
	public static ChoiceManager instance;

	private bool choiceCoroutineRunning;

	private bool choiceCanceled;

	[HideInInspector]
	public List<Choice> availableChoices = new List<Choice>();

	[HideInInspector]
	public Choice choiceToReturn;

	[HideInInspector]
	public BuildSlot currentOriginBuildSlot;

	public bool ChoiceCoroutineWaiting
	{
		get
		{
			if (!choiceCanceled)
			{
				return choiceToReturn == null;
			}
			return false;
		}
	}

	public bool ChoiceCoroutineRunning => choiceCoroutineRunning;

	public void CancelChoice()
	{
		choiceCanceled = true;
	}

	private void Awake()
	{
		instance = this;
	}

	public void PresentChoices(List<Choice> _availableChoices, BuildSlot originBuildSlot, Action<Choice> _onCompleteFunction)
	{
		if (!choiceCoroutineRunning)
		{
			currentOriginBuildSlot = originBuildSlot;
			if (_availableChoices.Count == 0)
			{
				_onCompleteFunction(null);
				return;
			}
			if (_availableChoices.Count == 1)
			{
				_onCompleteFunction(_availableChoices[0]);
				return;
			}
			availableChoices = _availableChoices;
			UIFrameManager.instance.PresentChoiceFrame();
			StartCoroutine(Choice(_availableChoices, _onCompleteFunction));
		}
	}

	private IEnumerator Choice(List<Choice> _availableChoices, Action<Choice> _onCompleteFunction)
	{
		choiceToReturn = null;
		choiceCoroutineRunning = true;
		choiceCanceled = false;
		LocalGamestate.Instance.SetPlayerFreezeState(frozen: true);
		while (choiceToReturn == null && !choiceCanceled)
		{
			yield return null;
		}
		LocalGamestate.Instance.SetPlayerFreezeState(frozen: false);
		yield return null;
		_onCompleteFunction(choiceToReturn);
		choiceCoroutineRunning = false;
	}
}