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