-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTMProAutoTagLoader.cs
183 lines (164 loc) · 7.89 KB
/
TMProAutoTagLoader.cs
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// This code is part of the Fungus library (/~https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (/~https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using TMPro;
using System;
public enum TMProTagLoaderList
{
None,
bold,
italic,
size,
flash,
verticalPunchScreen,
horizontalPunchScreen,
punchScreen,
replaceText
}
namespace Fungus
{
/// <summary>
/// Writes text in a dialog box.
/// </summary>
[CommandInfo("Narrative",
"TMPro Auto Tags Loader",
"Recursively add narrative tags to available Says. Can be combined with TMProAutoEffectLoader if placed after. Must be placed at the very first order in your block")]
[AddComponentMenu("")]
public class TMProAutoTagLoader : Command
{
[System.Serializable]
public class BulkTags
{
[SerializeField] public string wordList;
[SerializeField] public TMProTagLoaderList style;
[SerializeField] public float floatParamValue;
[SerializeField] public string stringParamValue;
}
[SerializeField] protected BulkTags[] tags = new BulkTags[1];
[SerializeField] protected Flowchart flowchart;
[SerializeField] protected float saveWait = 2f;
#region Public members
protected IEnumerator TMtagLoader()
{
Say[] says = flowchart.GetComponents<Say>();
for(int i = 0; i < tags.Length; i++)
{
var dWord = tags[i].wordList;
var dTag = tags[i];
if(!String.IsNullOrEmpty(dWord) && tags[i].style != TMProTagLoaderList.None )
{
for(int j = 0; j < says.Length; j++)
{
if (says[j] != null && !String.IsNullOrEmpty(says[j].storyText))
{
var c = says[j];
if(c.storyText != "")
{
//Text italic
string italics = "{i}";
string cItalics = "{/i}";
//Text bold
string bold = "{b}";
string cBold = "{/b}";
//Text size
string tSize = "{size=" + tags[i].floatParamValue.ToString() + "}";
string cTsize = "{/size}";
//Flash screen
string sFlash = "{flash=" + tags[i].floatParamValue.ToString() + "}";
//Punch screen
string sPunch = "{punch=10,0.5}";
//Horizontal punch screen
string hPunch = "{hpunch=10,0.5}";
//Vertical punch screen
string vPunch = "{vpunch=10,0.5}";
if(!String.IsNullOrEmpty(dWord))
{
if(dTag.style == TMProTagLoaderList.bold || dTag.style == TMProTagLoaderList.italic)
{
if(dTag.style == TMProTagLoaderList.bold)
{
string bqm = bold + dWord + cBold;
string a = c.storyText.Replace(dWord, bqm);
c.storyText = a;
}
else
{
string bqm = italics + dWord + cItalics;
string a = c.storyText.Replace(dWord, bqm);
c.storyText = a;
}
}
if(dTag.style == TMProTagLoaderList.size)
{
string bqm = tSize + dWord + cTsize;
string a = c.storyText.Replace(dWord, bqm);
c.storyText = a;
}
if(dTag.style == TMProTagLoaderList.flash)
{
string bqm = dWord + sFlash;
string a = c.storyText.Replace(dWord, bqm);
c.storyText = a;
}
if(dTag.style == TMProTagLoaderList.punchScreen)
{
string bqm = dWord + sPunch;
string a = c.storyText.Replace(dWord, bqm);
c.storyText = a;
}
if(dTag.style == TMProTagLoaderList.verticalPunchScreen)
{
string bqm = dWord + vPunch;
string a = c.storyText.Replace(dWord, bqm);
c.storyText = a;
}
if(dTag.style == TMProTagLoaderList.horizontalPunchScreen)
{
string bqm = dWord + hPunch;
string a = c.storyText.Replace(dWord, bqm);
c.storyText = a;
}
if(dTag.style == TMProTagLoaderList.replaceText)
{
string bqm = tags[i].stringParamValue;
string a = c.storyText.Replace(dWord, bqm);
c.storyText = a;
}
}
}
}
}
}
}
yield return new WaitForSeconds(saveWait);
Continue();
}
public override void OnEnter()
{
if(flowchart != null)
{
StartCoroutine(TMtagLoader());
}
else
{
Continue();
}
}
public override string GetSummary()
{
string nullFlowchart = "";
if (flowchart == null)
{
return nullFlowchart = "Error: No flowchart selected";
}
return nullFlowchart;
}
public override Color GetButtonColor()
{
return new Color32(184, 210, 235, 255);
}
#endregion
}
}