Elin Decompiled Documentation EA 23.287 Stable Patch 3
Loading...
Searching...
No Matches
Dialog.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.UI;
5
6public class Dialog : ELayer
7{
8 public enum InputType
9 {
10 None,
11 Default,
13 Item,
15 Chat
16 }
17
18 public Text textConfetti;
19
20 public Image image;
21
23
24 public UINote note;
25
27
28 public LayoutGroup layout;
29
31
33
34 public Transform spacer;
35
36 public List<GridItem> gridItems = new List<GridItem>();
37
39
41
42 [NonSerialized]
44
45 [NonSerialized]
46 public bool isInputEnter;
47
48 public Action<bool, string> onEnterInput;
49
50 public static bool warned;
51
52 public override void OnAfterInit()
53 {
54 ELayer.ui.hud.textMouseHintRight.transform.parent.SetActive(enable: false);
55 textDetail.SetActive(!textDetail.text.IsEmpty());
56 listGrid.SetActive(gridItems.Count > 0);
57 if (gridItems.Count >= 8)
58 {
59 GridLayoutGroup obj = listGrid.layoutItems as GridLayoutGroup;
60 obj.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
61 obj.constraintCount = 8;
62 }
63 if (gridItems.Count > 0)
64 {
66 listGrid.callbacks = new UIList.Callback<GridItem, ButtonGrid>
67 {
68 onInstantiate = delegate(GridItem a, ButtonGrid b)
69 {
70 b.SetItem(a);
71 },
72 onClick = delegate(GridItem a, ButtonGrid b)
73 {
74 a.OnClick(b);
75 }
76 };
77 foreach (GridItem gridItem in gridItems)
78 {
79 listGrid.Add(gridItem);
80 }
82 }
83 list.Refresh();
84 this.RebuildLayout(recursive: true);
85 GraphicRaycaster g = windows[0].GetComponent<GraphicRaycaster>();
86 g.enabled = false;
87 TweenUtil.Delay(0.3f, delegate
88 {
89 if ((bool)g)
90 {
91 g.enabled = true;
92 }
93 });
94 if ((bool)input)
95 {
96 input.Focus();
97 }
99 }
100
101 public void AddButton(string text, Action onClick = null, bool close = true)
102 {
103 list.AddButton(null, text, delegate
104 {
105 if (onClick != null)
106 {
107 onClick();
108 }
109 if (close)
110 {
111 Close();
112 }
113 });
114 }
115
116 private void Update()
117 {
118 if ((bool)input && option.canClose && Input.GetKeyDown(KeyCode.Escape))
119 {
120 Close();
121 }
122 }
123
124 public override bool OnBack()
125 {
127 {
128 return false;
129 }
130 return base.OnBack();
131 }
132
133 public override void OnUpdateInput()
134 {
135 if ((bool)input && option.canClose && (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) && keymap == null)
136 {
137 isInputEnter = true;
138 Close();
139 return;
140 }
141 if (!input.gameObject.activeInHierarchy && this.list != null)
142 {
143 foreach (UIList.ButtonPair button in this.list.buttons)
144 {
145 UIButton uIButton = button.component as UIButton;
146 if ((bool)uIButton && uIButton.interactable && !EInput.waitReleaseAnyKey && (bool)uIButton.keyText && !uIButton.keyText.text.IsEmpty() && uIButton.keyText.text == Input.inputString)
147 {
148 uIButton.onClick.Invoke();
149 return;
150 }
151 }
152 }
153 if (keymap != null)
154 {
155 List<KeyCode> list = new List<KeyCode>
156 {
157 KeyCode.Mouse0,
158 KeyCode.Mouse1,
159 KeyCode.Mouse2,
160 KeyCode.Mouse3,
161 KeyCode.Mouse4,
162 KeyCode.Escape,
163 KeyCode.LeftShift,
164 KeyCode.Delete
165 };
166 if (Input.GetKeyDown(KeyCode.Delete))
167 {
168 if (keymap.required)
169 {
170 SE.Beep();
171 return;
172 }
173 SE.Tab();
174 keymap.key = KeyCode.None;
175 Close();
176 return;
177 }
178 foreach (KeyCode value in Enum.GetValues(typeof(KeyCode)))
179 {
180 if (list.Contains(value) || !Input.GetKey(value))
181 {
182 continue;
183 }
184 foreach (EInput.KeyMap item in ELayer.core.config.input.keys.List())
185 {
186 if (item.key == value && item.GetGroup() == keymap.GetGroup())
187 {
188 item.key = keymap.key;
189 }
190 }
191 keymap.key = value;
192 SE.Tab();
193 Close();
194 return;
195 }
196 }
197 base.OnUpdateInput();
198 }
199
200 public void OnEnterInput()
201 {
202 isInputEnter = true;
203 Close();
204 }
205
206 public override void OnKill()
207 {
208 ELayer.ui.hud.textMouseHintRight.transform.parent.SetActive(enable: true);
209 if ((bool)input && onEnterInput != null)
210 {
212 }
213 if ((bool)input)
214 {
215 input.field.DeactivateInputField();
216 }
218 }
219
220 public static Dialog CreateNarration(string idImage, string idText)
221 {
222 Dialog dialog = Layer.Create<Dialog>("DialogNarration");
223 dialog.image.SetActive(enable: true);
224 dialog.image.sprite = Resources.Load<Sprite>("Media/Graphics/Image/Dialog/" + idImage);
225 dialog.image.SetNativeSize();
226 dialog.textDetail.SetText(IO.LoadText(CorePath.CorePackage.TextNarration + idText + ".txt"));
227 return dialog;
228 }
229
230 public static Dialog Ok(string langDetail, Action action = null)
231 {
232 Dialog dialog = Layer.Create<Dialog>();
233 dialog.textDetail.SetText(langDetail.lang() + " ");
234 dialog.list.AddButton(null, Lang.Get("ok"), dialog.Close);
235 if (action != null)
236 {
237 dialog.SetOnKill(action);
238 }
239 ELayer.ui.AddLayer(dialog);
240 return dialog;
241 }
242
243 public static Dialog Choice(string langDetail, Action<Dialog> action)
244 {
245 Dialog dialog = Layer.Create<Dialog>();
246 dialog.textDetail.SetText(langDetail.lang() + " ");
247 action(dialog);
248 ELayer.ui.AddLayer(dialog);
249 return dialog;
250 }
251
252 public static Dialog YesNo(string langDetail, Action actionYes, Action actionNo = null, string langYes = "yes", string langNo = "no")
253 {
254 Dialog d = Layer.Create<Dialog>();
255 d.textDetail.SetText(langDetail.lang() + " ");
256 d.list.AddButton(null, Lang.Get(langYes), delegate
257 {
258 if (actionYes != null)
259 {
260 actionYes();
261 }
262 d.Close();
263 });
264 d.list.AddButton(null, Lang.Get(langNo), delegate
265 {
266 if (actionNo != null)
267 {
268 actionNo();
269 }
270 d.Close();
271 });
272 ELayer.ui.AddLayer(d);
273 return d;
274 }
275
276 public static Dialog List<TValue>(string langDetail, ICollection<TValue> items, Func<TValue, string> getString, Func<int, string, bool> onSelect, bool canCancel = false)
277 {
278 Dialog d = Layer.Create<Dialog>();
279 d.textDetail.SetText(langDetail.lang() + " ");
280 int num = 0;
281 foreach (TValue item in items)
282 {
283 int _i = num;
284 d.list.AddButton(null, getString(item).lang(), delegate
285 {
286 if (onSelect(_i, getString(item)))
287 {
288 d.Close();
289 }
290 });
291 num++;
292 }
293 d.option.canClose = canCancel;
294 ELayer.ui.AddLayer(d);
295 return d;
296 }
297
298 public static void TryWarn(string lang, Action action, bool yes = true, string text = null)
299 {
300 Dialog d = Layer.Create<Dialog>();
301 d.textDetail.SetText(text ?? (lang.lang() + " "));
302 d.SetOnKill(delegate
303 {
304 ELayer.core.actionsNextFrame.Add(delegate
305 {
306 ActPlan.warning = false;
307 });
308 });
309 d.list.AddButton(null, Lang.Get("yes"), delegate
310 {
311 d.Close();
312 Commit();
313 });
314 if (yes)
315 {
316 d.list.AddButton(null, Lang.Get("yes_dontask"), delegate
317 {
318 switch (lang)
319 {
320 case "warn_crime":
321 ELayer.core.config.game.ignoreWarnCrime = true;
322 break;
323 case "warn_mana":
324 ELayer.core.config.game.ignoreWarnMana = true;
325 break;
326 case "warn_disassemble":
327 ELayer.core.config.game.ignoreWarnDisassemble = true;
328 break;
329 case "warn_slaughter":
330 ELayer.core.config.game.ignoreWarnSlaughter = true;
331 break;
332 }
333 d.Close();
334 Commit();
335 });
336 }
337 d.list.AddButton(null, Lang.Get("no"), delegate
338 {
339 d.Close();
340 });
341 if (!yes)
342 {
343 d.list.AddButton(null, Lang.Get("no_dontask"), delegate
344 {
345 string text2 = lang;
346 if (!(text2 == "warn_parallels"))
347 {
348 if (text2 == "warn_linuxMod")
349 {
350 ELayer.core.config.ignoreLinuxModWarning = true;
351 }
352 }
353 else
354 {
355 ELayer.core.config.ignoreParallelsWarning = true;
356 }
357 d.Close();
358 });
359 }
360 ELayer.ui.AddLayer(d);
361 void Commit()
362 {
363 warned = true;
364 action();
365 warned = false;
366 }
367 }
368
369 public static void TryWarnSlaughter(Action action, Chara c)
370 {
372 {
373 warned = true;
374 action();
375 warned = false;
376 ActPlan.warning = false;
377 }
378 else
379 {
380 TryWarn("warn_slaughter", action, yes: true, "warn_slaughter".lang(c.Name));
381 }
382 }
383
384 public static void TryWarnCrime(Action action)
385 {
387 {
388 warned = true;
389 action();
390 warned = false;
391 ActPlan.warning = false;
392 }
393 else
394 {
395 TryWarn("warn_crime", action);
396 }
397 }
398
399 public static void TryWarnMana(Action action)
400 {
402 {
403 warned = true;
404 action();
405 warned = false;
406 ActPlan.warning = false;
407 }
408 else
409 {
410 TryWarn("warn_mana", action);
411 }
412 }
413
414 public static void TryWarnDisassemble(Action action)
415 {
417 {
418 warned = true;
419 action();
420 warned = false;
421 }
422 else
423 {
424 TryWarn("warn_disassemble", action);
425 }
426 }
427
428 public static Dialog Gift(string langHeader, bool autoAdd, params Card[] cards)
429 {
430 return Gift(langHeader, autoAdd, new List<Card>(cards));
431 }
432
433 public static Dialog Gift(string langHeader, bool autoAdd, List<Card> list)
434 {
435 List<GridItem> list2 = new List<GridItem>();
436 foreach (Card item in list)
437 {
438 list2.Add(new GridItemCard
439 {
440 c = item
441 });
442 }
443 return Gift(langHeader, autoAdd, list2);
444 }
445
446 public static Dialog Gift(string langHeader, bool autoAdd, List<GridItem> list)
447 {
448 Dialog d = Layer.Create<Dialog>();
449 d.spacer.SetActive(enable: false);
450 d.note.AddHeader(langHeader.IsEmpty("headerGift").lang());
451 d.list.AddButton(null, Lang.Get("ok"), delegate
452 {
453 if (autoAdd)
454 {
455 foreach (GridItem item in list)
456 {
457 item.AutoAdd();
458 }
459 }
460 d.Close();
461 });
462 d.option.soundActivate = null;
463 d.option.canClose = false;
464 d.gridItems = list;
465 ELayer.Sound.Play("good");
466 ELayer.ui.AddLayer(d);
467 return d;
468 }
469
470 public static Dialog Recipe(List<RecipeSource> list)
471 {
472 Dialog d = Layer.Create<Dialog>();
473 d.spacer.SetActive(enable: false);
474 d.note.AddHeader("giftRecipe".lang());
475 d.list.AddButton(null, Lang.Get("ok"), delegate
476 {
477 d.Close();
478 });
479 d.option.soundActivate = null;
480 for (int i = 0; i < list.Count; i++)
481 {
482 RecipeSource recipeSource = list[i];
483 List<Recipe.Ingredient> ingredients = recipeSource.GetIngredients();
484 if (ingredients.Count > 0 && ELayer.sources.cards.map.ContainsKey(ingredients[0].id))
485 {
486 ELayer.sources.cards.map[ingredients[0].id].GetName();
487 }
488 d.note.AddText("・" + recipeSource.Name.ToTitleCase());
489 if (i >= 9 && list.Count > 10)
490 {
491 d.note.Space(6);
492 d.note.AddText("moreRecipes".lang((list.Count - 10).ToString() ?? ""));
493 break;
494 }
495 }
496 d.SetOnKill(SE.Click);
497 ELayer.Sound.Play("idea");
498 ELayer.ui.AddLayer(d);
499 return d;
500 }
501
502 public static Dialog Confetti(string langTitle, string langDetail, string langConfetti = "Grats!")
503 {
504 ELayer.Sound.Play("confetti");
505 return _Confetti("DialogConfetti", langTitle, langDetail, langConfetti);
506 }
507
508 public static Dialog ConfettiSimple(string langTitle, string langDetail, string langConfetti = "Grats!")
509 {
510 ELayer.Sound.Play("confettiSimple");
511 return _Confetti("DialogConfettiSimple", langTitle, langDetail, langConfetti);
512 }
513
514 public static Dialog _Confetti(string idPrefab, string langTitle, string langDetail, string langConfetti = "Grats!")
515 {
516 Dialog d = Layer.Create(idPrefab) as Dialog;
517 d.textConfetti.text = langConfetti.lang();
518 d.textDetail.SetText(langDetail.lang());
519 d.list.AddButton(null, Lang.Get("ok"), delegate
520 {
521 d.Close();
522 });
523 ELayer.ui.AddLayer(d);
524 return d;
525 }
526
528 {
529 Dialog dialog = Layer.Create<Dialog>("DialogKeymap");
530 dialog.textDetail.SetText("dialog_keymap".lang(("key_" + keymap.action).lang()));
531 dialog.keymap = keymap;
532 ELayer.ui.AddLayer(dialog);
533 return dialog;
534 }
535
536 public static Dialog InputName(string langDetail, string text, Action<bool, string> onClose, InputType inputType = InputType.Default)
537 {
538 Dialog d = Layer.Create<Dialog>("DialogInput");
539 d.inputType = inputType;
540 d.langHint = langDetail;
541 d.note.AddText(langDetail.lang()).text1.alignment = TextAnchor.MiddleCenter;
542 switch (inputType)
543 {
544 case InputType.Chat:
545 d.input.field.characterLimit = 500;
546 break;
547 case InputType.DistributionFilter:
548 d.input.field.characterLimit = 100;
549 break;
550 case InputType.Item:
551 d.input.field.characterLimit = 30;
552 break;
553 case InputType.Password:
554 d.input.field.characterLimit = 8;
555 d.input.field.contentType = InputField.ContentType.Alphanumeric;
556 break;
557 }
558 d.input.Text = text;
559 d.onEnterInput = onClose;
560 d.list.AddButton(null, Lang.Get("ok"), delegate
561 {
562 onClose(arg1: false, d.input.Text);
563 d.Close();
564 });
565 d.list.AddButton(null, Lang.Get("cancel"), delegate
566 {
567 onClose(arg1: true, "");
568 d.Close();
569 });
570 ELayer.ui.AddLayer(d);
571 return d;
572 }
573}
List< Action > actionsNextFrame
Definition: BaseCore.cs:31
void SetItem(GridItem i)
Definition: ButtonGrid.cs:398
bool usedKey
Definition: ButtonState.cs:55
bool pressing
Definition: ButtonState.cs:35
Definition: Card.cs:11
string Name
Definition: Card.cs:2177
Definition: Chara.cs:10
EInput.KeyMapManager keys
Definition: CoreConfig.cs:260
new GameConfig game
Definition: CoreConfig.cs:609
InputSetting input
Definition: CoreConfig.cs:615
static string TextNarration
Definition: CorePath.cs:63
CoreConfig config
Definition: Core.cs:70
Definition: Dialog.cs:7
UINote note
Definition: Dialog.cs:24
static Dialog Keymap(EInput.KeyMap keymap)
Definition: Dialog.cs:527
void Update()
Definition: Dialog.cs:116
override void OnKill()
Definition: Dialog.cs:206
static bool warned
Definition: Dialog.cs:50
InputType inputType
Definition: Dialog.cs:40
void OnEnterInput()
Definition: Dialog.cs:200
Transform spacer
Definition: Dialog.cs:34
ScreenEffect effect
Definition: Dialog.cs:30
static Dialog List< TValue >(string langDetail, ICollection< TValue > items, Func< TValue, string > getString, Func< int, string, bool > onSelect, bool canCancel=false)
Definition: Dialog.cs:276
Action< bool, string > onEnterInput
Definition: Dialog.cs:48
Image image
Definition: Dialog.cs:20
void AddButton(string text, Action onClick=null, bool close=true)
Definition: Dialog.cs:101
override void OnAfterInit()
Definition: Dialog.cs:52
static Dialog YesNo(string langDetail, Action actionYes, Action actionNo=null, string langYes="yes", string langNo="no")
Definition: Dialog.cs:252
UIButtonList list
Definition: Dialog.cs:26
UIList listGrid
Definition: Dialog.cs:32
static void TryWarn(string lang, Action action, bool yes=true, string text=null)
Definition: Dialog.cs:298
static Dialog Choice(string langDetail, Action< Dialog > action)
Definition: Dialog.cs:243
override bool OnBack()
Definition: Dialog.cs:124
static Dialog Gift(string langHeader, bool autoAdd, List< Card > list)
Definition: Dialog.cs:433
static Dialog InputName(string langDetail, string text, Action< bool, string > onClose, InputType inputType=InputType.Default)
Definition: Dialog.cs:536
static void TryWarnDisassemble(Action action)
Definition: Dialog.cs:414
static Dialog Ok(string langDetail, Action action=null)
Definition: Dialog.cs:230
UIInputText input
Definition: Dialog.cs:38
static Dialog Gift(string langHeader, bool autoAdd, List< GridItem > list)
Definition: Dialog.cs:446
UIText textDetail
Definition: Dialog.cs:22
override void OnUpdateInput()
Definition: Dialog.cs:133
Text textConfetti
Definition: Dialog.cs:18
static Dialog ConfettiSimple(string langTitle, string langDetail, string langConfetti="Grats!")
Definition: Dialog.cs:508
static void TryWarnCrime(Action action)
Definition: Dialog.cs:384
static void TryWarnMana(Action action)
Definition: Dialog.cs:399
InputType
Definition: Dialog.cs:9
static Dialog CreateNarration(string idImage, string idText)
Definition: Dialog.cs:220
List< GridItem > gridItems
Definition: Dialog.cs:36
LayoutGroup layout
Definition: Dialog.cs:28
static void TryWarnSlaughter(Action action, Chara c)
Definition: Dialog.cs:369
static Dialog _Confetti(string idPrefab, string langTitle, string langDetail, string langConfetti="Grats!")
Definition: Dialog.cs:514
bool isInputEnter
Definition: Dialog.cs:46
static Dialog Confetti(string langTitle, string langDetail, string langConfetti="Grats!")
Definition: Dialog.cs:502
EInput.KeyMap keymap
Definition: Dialog.cs:43
static Dialog Gift(string langHeader, bool autoAdd, params Card[] cards)
Definition: Dialog.cs:428
static Dialog Recipe(List< RecipeSource > list)
Definition: Dialog.cs:470
Definition: EInput.cs:8
static void WaitReleaseKey()
Definition: EInput.cs:661
static ButtonState rightMouse
Definition: EInput.cs:362
static bool waitReleaseAnyKey
Definition: EInput.cs:328
static EAction action
Definition: EInput.cs:270
Definition: ELayer.cs:4
static Core core
Definition: ELayer.cs:7
static SourceManager sources
Definition: ELayer.cs:37
static UI ui
Definition: ELayer.cs:21
static SoundManager Sound
Definition: ELayer.cs:41
virtual void OnClick(ButtonGrid b)
Definition: GridItem.cs:8
Definition: Lang.cs:7
static string Get(string id)
Definition: Lang.cs:94
bool canClose
Definition: Layer.cs:29
Definition: Layer.cs:9
Option option
Definition: Layer.cs:84
List< Window > windows
Definition: Layer.cs:116
virtual void Close()
Definition: Layer.cs:463
static Layer Create(string path)
Definition: Layer.cs:299
Layer SetOnKill(Action action)
Definition: Layer.cs:579
List< Recipe.Ingredient > GetIngredients()
Definition: Recipe.cs:7
Dictionary< string, CardRow > map
Definition: SourceCard.cs:9
SourceCard cards
void AddButton(object obj, string text, Action onClick, Action< UIButton > onInstantiate=null)
Definition: UIButtonList.cs:11
UIText keyText
Definition: UIButton.cs:108
InputField field
Definition: UIInputText.cs:15
void Focus()
Definition: UIInputText.cs:130
string Text
Definition: UIInputText.cs:49
override void Refresh(bool highlightLast=false)
Definition: UIListEx.cs:17
Definition: UIList.cs:9
override void Clear()
Definition: UIList.cs:401
override void Add(object item)
Definition: UIList.cs:354
virtual void Refresh(bool highlightLast=false)
Definition: UIList.cs:476
Definition: UINote.cs:6
UIItem AddHeader(string text, Sprite sprite=null)
Definition: UINote.cs:79
UIItem AddText(string text, FontColor color=FontColor.DontChange)
Definition: UINote.cs:113
void Space(int sizeY=0, int sizeX=1)
Definition: UINote.cs:62
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:163