Skip to content

Commit ec68648

Browse files
committed
Update TextBoxController with events
1 parent 72f986e commit ec68648

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

Assets/Controllers/TextBoxController.cs

+40-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using TMPro;
55
using System;
66

7-
public class TextBoxController : MonoBehaviour
7+
public class TextBoxController : MonoBehaviour, IListen<NPCController>
88
{
99
public List<DialogData> dialogData;
1010
public event Action<bool> OnShowTextBox;
@@ -127,4 +127,43 @@ private IEnumerator ShowBox()
127127
yield return new WaitForSecondsRealtime(0.5f);
128128
}
129129
}
130+
131+
public (List<int>, Action<dynamic>) HandleEvent(NPCController component, IEvent<NPCController> @event)
132+
{
133+
return @event switch
134+
{
135+
NPCController.Event_Say e => (
136+
new List<int>() { 100 },
137+
(payload) =>
138+
{
139+
string[] tokens = payload.Split(".");
140+
var character = tokens[1];
141+
var message = tokens[3];
142+
switch(message)
143+
{
144+
case "intro":
145+
{
146+
var id = tokens[4];
147+
SayIntroDialog(int.Parse(id));
148+
break;
149+
}
150+
case "valid_recipe":
151+
{
152+
var id = tokens[4];
153+
SayCorrectIngredientDialog(int.Parse(id));
154+
break;
155+
}
156+
case "invalid_recipe":
157+
{
158+
var id = tokens[4];
159+
SayWrongIngredientDialog(int.Parse(id));
160+
break;
161+
}
162+
}
163+
164+
}
165+
),
166+
_ => (null, null)
167+
};
168+
}
130169
}

0 commit comments

Comments
 (0)