net.dreditor.choices 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/ChoiceManager.cs CHANGED
@@ -1,317 +1,317 @@
1
- //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
- using DREditor.Dialogues;
3
- using DREditor.Dialogues.Ending;
4
- using DREditor.Dialogues.Events;
5
- using DREditor.EventObjects;
6
- using DREditor.Progressing.Handling;
7
- using DREditor.Services;
8
- using DREditor.UI;
9
- using System;
10
- using System.Collections;
11
- using System.Collections.Generic;
12
- using UnityEngine;
13
- using UnityEngine.Events;
14
- using UnityEngine.EventSystems;
15
- using UnityEngine.InputSystem;
16
-
17
- namespace DREditor.Choices
18
- {
19
- /// <summary>
20
- ///
21
- /// </summary>
22
- [ClassHeader(nameof(ServiceHolder<IChoiceManager>) + " for type: " + nameof(IChoiceManager) +
23
- "\n\n")]
24
- public class ChoiceManager : ServiceHolder<IChoiceManager>, IChoiceManager, IDialogueInteruptable, IToTitleScreen
25
- {
26
- /// <summary>
27
- ///
28
- /// </summary>
29
- [Space]
30
- [Divider]
31
- [Space]
32
- [Tooltip("")]
33
- [SerializeField] protected InputActionReference submit = null;
34
-
35
- /// <summary>
36
- ///
37
- /// </summary>
38
- [Tooltip("")]
39
- [SerializeField] protected BoolWithEvent isLeaving = null;
40
-
41
- /// <summary>
42
- ///
43
- /// </summary>
44
- [Tooltip("")]
45
- [SerializeField] protected BoolWithEvent fastForwardModeWasEnabled = null;
46
-
47
-
48
- /// <summary>
49
- ///
50
- /// </summary>
51
- [Header("")]
52
- [Divider]
53
- [Tooltip("")]
54
- [SerializeField] protected MenuGroupBase ChoiceGroup = null;
55
-
56
- /// <summary>
57
- ///
58
- /// </summary>
59
- [Tooltip("")]
60
- [SerializeField] protected ChoiceSaveHandler choiceSaveHandler = null;
61
-
62
- /// <summary>
63
- ///
64
- /// </summary>
65
- [Tooltip("")]
66
- [SerializeField] protected float displayChoiceBufferTime = 0.3f;
67
-
68
- /// <summary>
69
- ///
70
- /// </summary>
71
- [Tooltip("")]
72
- [SerializeField] protected List<ChoiceOptionUI> choiceOptions = new();
73
-
74
-
75
- [Header("")]
76
- [SerializeField] protected UnityEvent OnChoiceStarted = null;
77
-
78
- [Header("")]
79
- [SerializeField] protected UnityEvent OnChoiceConfirmed = null;
80
-
81
-
82
- public event Action<DialogueCore[]> OnInteruptWithNewDialogue;
83
-
84
-
85
- /// <summary>
86
- ///
87
- /// </summary>
88
- protected List<Action> allChoiceActions = new();
89
-
90
- /// <summary>
91
- ///
92
- /// </summary>
93
- protected Dialogue currentDialogue;
94
-
95
- /// <summary>
96
- ///
97
- /// </summary>
98
- protected Action exitParentRoutine = null;
99
-
100
- /// <summary>
101
- ///
102
- /// </summary>
103
- protected int selectedChoiceIndex = -1;
104
-
105
-
106
- /// <inheritdoc/>
107
- protected override void Awake()
108
- {
109
- base.Awake();
110
-
111
- ClearChoiceText();
112
- }
113
-
114
- /// <inheritdoc/>
115
- public virtual IEnumerator ExecuteChoiceHandling(Dialogue currentDialogue, Action exitParentRoutine = null)
116
- {
117
- this.currentDialogue = currentDialogue;
118
-
119
- this.exitParentRoutine = exitParentRoutine;
120
-
121
- InitializeChoices();
122
-
123
- if (ChoiceGroup != null)
124
- {
125
- if (displayChoiceBufferTime > 0)
126
- yield return new WaitForSeconds(displayChoiceBufferTime);
127
-
128
- ChoiceGroup.Show();
129
-
130
- yield return ChoiceGroup.WaitForChangeToComplete();
131
- }
132
-
133
- OnChoiceStarted?.Invoke();
134
-
135
- EventSystem.current.SetSelectedGameObject(choiceOptions[0].gameObject);
136
-
137
- yield return WaitForPlayerClick();
138
-
139
- OnChoiceConfirmed?.Invoke();
140
-
141
- EvaluateSelectedChoice();
142
-
143
- EventSystem.current.SetSelectedGameObject(null);
144
-
145
- if (ChoiceGroup != null)
146
- {
147
- ChoiceGroup.Hide();
148
-
149
- yield return ChoiceGroup.WaitForChangeToComplete();
150
- }
151
-
152
- PlayChoiceDialogue();
153
-
154
- TriggerCustomChoiceDialogueEvent();
155
- }
156
-
157
- /// <summary>
158
- ///
159
- /// </summary>
160
- protected virtual void InitializeChoices()
161
- {
162
- for (int i = 0; i < currentDialogue.Choices.Count; i++)
163
- {
164
- if (currentDialogue.Choices[i].ChoiceText != "")
165
- {
166
- choiceOptions[i].gameObject.SetActive(true);
167
-
168
- choiceOptions[i].SetText(currentDialogue.Choices[i].ChoiceText);
169
- }
170
- else
171
- choiceOptions[i].gameObject.SetActive(false);
172
- }
173
- }
174
-
175
- /// <summary>
176
- ///
177
- /// </summary>
178
- /// <remarks></remarks>
179
- protected virtual IEnumerator WaitForPlayerClick()
180
- {
181
- GameObject lastSelectedGO = null;
182
-
183
- while (!submit.action.triggered)
184
- {
185
- if (EventSystem.current.currentSelectedGameObject == null)
186
- EventSystem.current.SetSelectedGameObject(lastSelectedGO);
187
- else
188
- lastSelectedGO = EventSystem.current.currentSelectedGameObject;
189
-
190
- if (submit.action.triggered)
191
- break;
192
-
193
- yield return null;
194
- }
195
- }
196
-
197
- /// <summary>
198
- ///
199
- /// </summary>
200
- protected virtual void EvaluateSelectedChoice()
201
- {
202
- var choice = EventSystem.current.currentSelectedGameObject;
203
-
204
- for (int i = 0; i < choiceOptions.Count; i++)
205
- if (choice == choiceOptions[i].gameObject)
206
- choiceOptions[i].InvokeChoice();
207
-
208
- selectedChoiceIndex = choiceOptions.IndexOf(choice.GetComponent<ChoiceOptionUI>());
209
-
210
- UnityEngine.Debug.Log(ToString() + ": Choice Chosen Index was: " + selectedChoiceIndex);
211
- }
212
-
213
- /// <summary>
214
- ///
215
- /// </summary>
216
- protected virtual void PlayChoiceDialogue()
217
- {
218
- if (!isLeaving.Value && currentDialogue.HasChoiceDialogueAtIndex(selectedChoiceIndex))
219
- {
220
- TriggerDialogueFlag();
221
-
222
- fastForwardModeWasEnabled.SetValue(true);
223
-
224
- Dialogue[] dialogues = { currentDialogue.Choices[selectedChoiceIndex].NextDialogue };
225
-
226
- choiceSaveHandler.AddChoice(selectedChoiceIndex);
227
-
228
- exitParentRoutine?.Invoke();
229
-
230
- DialogueInterruptedInvoke(dialogues);
231
- }
232
- }
233
-
234
- /// <summary>
235
- ///
236
- /// </summary>
237
- protected virtual void TriggerCustomChoiceDialogueEvent()
238
- {
239
- if (!isLeaving.Value && currentDialogue.Choices[selectedChoiceIndex].CustomCall != "")
240
- {
241
- TriggerDialogueFlag();
242
-
243
- DialogueEventSystem.TriggerEvent(currentDialogue.Choices[selectedChoiceIndex].CustomCall);
244
-
245
- if (currentDialogue.Choices[selectedChoiceIndex].CallBreak)
246
- exitParentRoutine?.Invoke();
247
- }
248
- }
249
-
250
- /// <summary>
251
- ///
252
- /// </summary>
253
- protected virtual void TriggerDialogueFlag()
254
- {
255
- if (currentDialogue.FlagTrigger.Enabled)
256
- ServiceLocator.GetService<FlagTriggerHandlerBase>().TriggerFlag(
257
- currentDialogue.FlagTrigger.Chapter,
258
- currentDialogue.FlagTrigger.Objective,
259
- currentDialogue.FlagTrigger.Flags);
260
- }
261
-
262
-
263
- /// <inheritdoc/>
264
- public virtual void SubscribeAllChoices(Action[] actionArray)
265
- {
266
- for (int i = 0; i < actionArray.Length; i++)
267
- SubscribeChoice(i, actionArray[i]);
268
- }
269
-
270
- /// <inheritdoc/>
271
- public virtual void SubscribeChoice(int index, Action action)
272
- {
273
- choiceOptions[index].SubscribeChoice(action);
274
-
275
- allChoiceActions.Add(action);
276
- }
277
-
278
- /// <inheritdoc/>
279
- public virtual void UnsubscribeChoice(int index, Action action)
280
- {
281
- choiceOptions[index].UnsubscribeChoice(action);
282
-
283
- allChoiceActions.Remove(action);
284
- }
285
-
286
- /// <inheritdoc/>
287
- public virtual void UnsubscribeAllChoices()
288
- {
289
- for (int i = 0; i < choiceOptions.Count; i++)
290
- for (int x = 0; x < allChoiceActions.Count; x++)
291
- UnsubscribeChoice(i, allChoiceActions[x]);
292
- }
293
-
294
- /// <inheritdoc/>
295
- public virtual void ClearChoiceText()
296
- {
297
- foreach (var choice in choiceOptions)
298
- if (choice != null)
299
- choice.Clear();
300
- }
301
-
302
-
303
- /// <inheritdoc/>
304
- public virtual void DialogueInterruptedInvoke(DialogueCore[] dialogues)
305
- {
306
- if (OnInteruptWithNewDialogue == null)
307
- UnityEngine.Debug.LogWarning("ALERT: Nothing has subscribed to intercept the chosen choices dialogue!" +
308
- $"\nSomething must subscribe to this {nameof(IDialogueInteruptable)}'s {nameof(OnInteruptWithNewDialogue)} event!");
309
-
310
- OnInteruptWithNewDialogue?.Invoke(dialogues);
311
- }
312
-
313
- //Testing /// <inheritdoc/>
314
- /// <inheritdoc/>
315
- public virtual void ToTitleScreen() => isLeaving.Value = false;
316
- }
1
+ //Author: Benjamin "Sweden" Jillson : Discord: sweden_gaming For Project Eden's Garden
2
+ using DREditor.Dialogues;
3
+ using DREditor.Dialogues.Ending;
4
+ using DREditor.Dialogues.Events;
5
+ using DREditor.EventObjects;
6
+ using DREditor.Progressing.Handling;
7
+ using DREditor.Services;
8
+ using DREditor.UI;
9
+ using System;
10
+ using System.Collections;
11
+ using System.Collections.Generic;
12
+ using UnityEngine;
13
+ using UnityEngine.Events;
14
+ using UnityEngine.EventSystems;
15
+ using UnityEngine.InputSystem;
16
+
17
+ namespace DREditor.Choices
18
+ {
19
+ /// <summary>
20
+ ///
21
+ /// </summary>
22
+ [ClassHeader(nameof(ServiceHolder<IChoiceManager>) + " for type: " + nameof(IChoiceManager) +
23
+ "\n\n")]
24
+ public class ChoiceManager : ServiceHolder<IChoiceManager>, IChoiceManager, IDialogueInteruptable, IToTitleScreen
25
+ {
26
+ /// <summary>
27
+ ///
28
+ /// </summary>
29
+ [Space]
30
+ [Divider]
31
+ [Space]
32
+ [Tooltip("")]
33
+ [SerializeField] protected InputActionReference submit = null;
34
+
35
+ /// <summary>
36
+ ///
37
+ /// </summary>
38
+ [Tooltip("")]
39
+ [SerializeField] protected BoolWithEvent isLeaving = null;
40
+
41
+ /// <summary>
42
+ ///
43
+ /// </summary>
44
+ [Tooltip("")]
45
+ [SerializeField] protected BoolWithEvent fastForwardModeWasEnabled = null;
46
+
47
+
48
+ /// <summary>
49
+ ///
50
+ /// </summary>
51
+ [Header("")]
52
+ [Divider]
53
+ [Tooltip("")]
54
+ [SerializeField] protected MenuGroupBase ChoiceGroup = null;
55
+
56
+ /// <summary>
57
+ ///
58
+ /// </summary>
59
+ [Tooltip("")]
60
+ [SerializeField] protected ChoiceSaveHandler choiceSaveHandler = null;
61
+
62
+ /// <summary>
63
+ ///
64
+ /// </summary>
65
+ [Tooltip("")]
66
+ [SerializeField] protected float displayChoiceBufferTime = 0.3f;
67
+
68
+ /// <summary>
69
+ ///
70
+ /// </summary>
71
+ [Tooltip("")]
72
+ [SerializeField] protected List<ChoiceOptionUI> choiceOptions = new();
73
+
74
+
75
+ [Header("")]
76
+ [SerializeField] protected UnityEvent OnChoiceStarted = null;
77
+
78
+ [Header("")]
79
+ [SerializeField] protected UnityEvent OnChoiceConfirmed = null;
80
+
81
+
82
+ public event Action<DialogueCore[]> OnInteruptWithNewDialogue;
83
+
84
+
85
+ /// <summary>
86
+ ///
87
+ /// </summary>
88
+ protected List<Action> allChoiceActions = new();
89
+
90
+ /// <summary>
91
+ ///
92
+ /// </summary>
93
+ protected Dialogue currentDialogue;
94
+
95
+ /// <summary>
96
+ ///
97
+ /// </summary>
98
+ protected Action exitParentRoutine = null;
99
+
100
+ /// <summary>
101
+ ///
102
+ /// </summary>
103
+ protected int selectedChoiceIndex = -1;
104
+
105
+
106
+ /// <inheritdoc/>
107
+ protected override void Awake()
108
+ {
109
+ base.Awake();
110
+
111
+ ClearChoiceText();
112
+ }
113
+
114
+ /// <inheritdoc/>
115
+ public virtual IEnumerator ExecuteChoiceHandling(Dialogue currentDialogue, Action exitParentRoutine = null)
116
+ {
117
+ this.currentDialogue = currentDialogue;
118
+
119
+ this.exitParentRoutine = exitParentRoutine;
120
+
121
+ InitializeChoices();
122
+
123
+ if (ChoiceGroup != null)
124
+ {
125
+ if (displayChoiceBufferTime > 0)
126
+ yield return new WaitForSeconds(displayChoiceBufferTime);
127
+
128
+ ChoiceGroup.Show();
129
+
130
+ yield return ChoiceGroup.WaitForChangeToComplete();
131
+ }
132
+
133
+ OnChoiceStarted?.Invoke();
134
+
135
+ EventSystem.current.SetSelectedGameObject(choiceOptions[0].gameObject);
136
+
137
+ yield return WaitForPlayerClick();
138
+
139
+ OnChoiceConfirmed?.Invoke();
140
+
141
+ EvaluateSelectedChoice();
142
+
143
+ EventSystem.current.SetSelectedGameObject(null);
144
+
145
+ if (ChoiceGroup != null)
146
+ {
147
+ ChoiceGroup.Hide();
148
+
149
+ yield return ChoiceGroup.WaitForChangeToComplete();
150
+ }
151
+
152
+ PlayChoiceDialogue();
153
+
154
+ TriggerCustomChoiceDialogueEvent();
155
+ }
156
+
157
+ /// <summary>
158
+ ///
159
+ /// </summary>
160
+ protected virtual void InitializeChoices()
161
+ {
162
+ for (int i = 0; i < currentDialogue.Choices.Count; i++)
163
+ {
164
+ if (currentDialogue.Choices[i].ChoiceText != "")
165
+ {
166
+ choiceOptions[i].gameObject.SetActive(true);
167
+
168
+ choiceOptions[i].SetText(currentDialogue.Choices[i].ChoiceText);
169
+ }
170
+ else
171
+ choiceOptions[i].gameObject.SetActive(false);
172
+ }
173
+ }
174
+
175
+ /// <summary>
176
+ ///
177
+ /// </summary>
178
+ /// <remarks></remarks>
179
+ protected virtual IEnumerator WaitForPlayerClick()
180
+ {
181
+ GameObject lastSelectedGO = null;
182
+
183
+ while (!submit.action.triggered)
184
+ {
185
+ if (EventSystem.current.currentSelectedGameObject == null)
186
+ EventSystem.current.SetSelectedGameObject(lastSelectedGO);
187
+ else
188
+ lastSelectedGO = EventSystem.current.currentSelectedGameObject;
189
+
190
+ if (submit.action.triggered)
191
+ break;
192
+
193
+ yield return null;
194
+ }
195
+ }
196
+
197
+ /// <summary>
198
+ ///
199
+ /// </summary>
200
+ protected virtual void EvaluateSelectedChoice()
201
+ {
202
+ var choice = EventSystem.current.currentSelectedGameObject;
203
+
204
+ for (int i = 0; i < choiceOptions.Count; i++)
205
+ if (choice == choiceOptions[i].gameObject)
206
+ choiceOptions[i].InvokeChoice();
207
+
208
+ selectedChoiceIndex = choiceOptions.IndexOf(choice.GetComponent<ChoiceOptionUI>());
209
+
210
+ UnityEngine.Debug.Log(ToString() + ": Choice Chosen Index was: " + selectedChoiceIndex);
211
+ }
212
+
213
+ /// <summary>
214
+ ///
215
+ /// </summary>
216
+ protected virtual void PlayChoiceDialogue()
217
+ {
218
+ if (!isLeaving.Value && currentDialogue.HasChoiceDialogueAtIndex(selectedChoiceIndex))
219
+ {
220
+ TriggerDialogueFlag();
221
+
222
+ fastForwardModeWasEnabled.SetValue(true);
223
+
224
+ Dialogue[] dialogues = { currentDialogue.Choices[selectedChoiceIndex].NextDialogue };
225
+
226
+ choiceSaveHandler.AddChoice(selectedChoiceIndex);
227
+
228
+ exitParentRoutine?.Invoke();
229
+
230
+ DialogueInterruptedInvoke(dialogues);
231
+ }
232
+ }
233
+
234
+ /// <summary>
235
+ ///
236
+ /// </summary>
237
+ protected virtual void TriggerCustomChoiceDialogueEvent()
238
+ {
239
+ if (!isLeaving.Value && currentDialogue.Choices[selectedChoiceIndex].CustomCall != "")
240
+ {
241
+ TriggerDialogueFlag();
242
+
243
+ DialogueEventSystem.TriggerEvent(currentDialogue.Choices[selectedChoiceIndex].CustomCall);
244
+
245
+ if (currentDialogue.Choices[selectedChoiceIndex].CallBreak)
246
+ exitParentRoutine?.Invoke();
247
+ }
248
+ }
249
+
250
+ /// <summary>
251
+ ///
252
+ /// </summary>
253
+ protected virtual void TriggerDialogueFlag()
254
+ {
255
+ if (currentDialogue.FlagTrigger.Enabled)
256
+ ServiceLocator.GetService<FlagTriggerHandlerBase>().TriggerFlag(
257
+ currentDialogue.FlagTrigger.Chapter,
258
+ currentDialogue.FlagTrigger.Objective,
259
+ currentDialogue.FlagTrigger.Flags);
260
+ }
261
+
262
+
263
+ /// <inheritdoc/>
264
+ public virtual void SubscribeAllChoices(Action[] actionArray)
265
+ {
266
+ for (int i = 0; i < actionArray.Length; i++)
267
+ SubscribeChoice(i, actionArray[i]);
268
+ }
269
+
270
+ /// <inheritdoc/>
271
+ public virtual void SubscribeChoice(int index, Action action)
272
+ {
273
+ choiceOptions[index].SubscribeChoice(action);
274
+
275
+ allChoiceActions.Add(action);
276
+ }
277
+
278
+ /// <inheritdoc/>
279
+ public virtual void UnsubscribeChoice(int index, Action action)
280
+ {
281
+ choiceOptions[index].UnsubscribeChoice(action);
282
+
283
+ allChoiceActions.Remove(action);
284
+ }
285
+
286
+ /// <inheritdoc/>
287
+ public virtual void UnsubscribeAllChoices()
288
+ {
289
+ for (int i = 0; i < choiceOptions.Count; i++)
290
+ for (int x = 0; x < allChoiceActions.Count; x++)
291
+ UnsubscribeChoice(i, allChoiceActions[x]);
292
+ }
293
+
294
+ /// <inheritdoc/>
295
+ public virtual void ClearChoiceText()
296
+ {
297
+ foreach (var choice in choiceOptions)
298
+ if (choice != null)
299
+ choice.Clear();
300
+ }
301
+
302
+
303
+ /// <inheritdoc/>
304
+ public virtual void DialogueInterruptedInvoke(DialogueCore[] dialogues)
305
+ {
306
+ if (OnInteruptWithNewDialogue == null)
307
+ UnityEngine.Debug.LogWarning("ALERT: Nothing has subscribed to intercept the chosen choices dialogue!" +
308
+ $"\nSomething must subscribe to this {nameof(IDialogueInteruptable)}'s {nameof(OnInteruptWithNewDialogue)} event!");
309
+
310
+ OnInteruptWithNewDialogue?.Invoke(dialogues);
311
+ }
312
+
313
+ //Testing /// <inheritdoc/>
314
+ /// <inheritdoc/>
315
+ public virtual void ToTitleScreen() => isLeaving.Value = false;
316
+ }
317
317
  }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: b4049c5600662904db0b5d7b474e7c1b
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: b4049c5600662904db0b5d7b474e7c1b
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: