Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
UIBook.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text.RegularExpressions;
5using UnityEngine;
6using UnityEngine.UI;
7
8public class UIBook : MonoBehaviour
9{
10 public enum Mode
11 {
12 Help,
14 Book,
16 Gallery,
17 About
18 }
19
20 public class Item
21 {
22 public string id;
23
24 public string idFile;
25
26 public string title;
27
28 public List<Item> items = new List<Item>();
29 }
30
31 public class Page
32 {
33 public UIBook book;
34
35 public int idx;
36
37 public List<string> lines = new List<string>();
38
39 public virtual void BuildNote(UINote n, string idTopic)
40 {
41 string text = "";
42 bool center = false;
43 bool hasSearchWord = !searchWord.IsEmpty();
44 bool skip = false;
45 UINote current = n;
46 ParseLines(lines, idTopic);
47 void Flush()
48 {
49 if (!text.IsEmpty())
50 {
51 UIItem uIItem = current.AddText(STR(text));
52 text = "";
53 if (center)
54 {
55 uIItem.text1.alignment = TextAnchor.UpperCenter;
56 }
57 LayoutElement component = uIItem.GetComponent<LayoutElement>();
58 if ((bool)component)
59 {
60 component.enabled = false;
61 }
62 }
63 }
64 void ParseLines(List<string> lines, string idTopic)
65 {
66 char c = 'a';
67 bool flag = false;
68 foreach (string line in lines)
69 {
70 string text2 = Lang.Parse(line, "test1", "test2");
71 if (text2.Length == 0)
72 {
73 if (!skip && (idTopic.IsEmpty() || flag))
74 {
75 text += Environment.NewLine;
76 }
77 }
78 else
79 {
80 c = text2[0];
81 if (!idTopic.IsEmpty())
82 {
83 if (c == '$')
84 {
85 if (flag)
86 {
87 break;
88 }
89 if (text2.Split('$')[1] == idTopic)
90 {
91 flag = true;
92 continue;
93 }
94 }
95 if (!flag)
96 {
97 continue;
98 }
99 }
100 if (book.mode == Mode.Announce)
101 {
102 switch (c)
103 {
104 case '■':
105 Flush();
106 current.AddHeader("HeaderPatch_header", line);
107 continue;
108 case '[':
109 text = text.TrimEnd(Environment.NewLine.ToCharArray());
110 Flush();
111 current.AddHeader("HeaderPatch_category", line);
112 continue;
113 case '*':
114 Flush();
115 text = line.TrimStart('*').TrimStart(' ').TrimEnd(Environment.NewLine.ToCharArray());
116 current.AddText("NoteText_list", text);
117 text = "";
118 continue;
119 }
120 }
121 if (c == '{')
122 {
123 Flush();
124 string[] array = text2.Split('}');
125 text = array[1];
126 string[] array2 = array[0].TrimStart('{').Split(array[0].Contains('|') ? '|' : ',');
127 if (!skip || !(array2[0] != "endif"))
128 {
129 switch (array2[0])
130 {
131 case "if":
132 {
133 string text5 = array2[1];
134 if (!(text5 == "cn"))
135 {
136 if (text5 == "!cn" && Lang.langCode == "CN")
137 {
138 skip = true;
139 }
140 }
141 else if (Lang.langCode != "CN")
142 {
143 skip = true;
144 }
145 break;
146 }
147 case "endif":
148 skip = false;
149 break;
150 case "include":
151 case "load":
152 {
153 string text3 = "";
154 string text4 = "";
155 if (array2[0] == "include")
156 {
157 text3 = array2[1];
158 text4 = "include";
159 }
160 else
161 {
162 text4 = array2[1];
163 text3 = array2[2];
164 }
165 text4 += ".txt";
166 string[] array3 = IO.LoadTextArray(CorePath.CorePackage.Help + text4);
167 if (array3.IsEmpty())
168 {
169 array3 = IO.LoadTextArray(CorePath.CorePackage.Text + text4);
170 }
171 if (array3.IsEmpty())
172 {
173 array3 = IO.LoadTextArray(CorePath.CorePackage.TextCommon + text4);
174 }
175 if (!array3.IsEmpty())
176 {
177 ParseLines(array3.ToList(), text3);
178 }
179 break;
180 }
181 case "center":
182 center = true;
183 break;
184 case "/center":
185 center = false;
186 break;
187 case "layout":
188 if (array2.Length == 1)
189 {
190 current = n;
191 }
192 else
193 {
194 current = n.AddNote(STR(array2[1]));
195 }
196 break;
197 case "nerun":
198 current.AddText("NoteText_nerun", STR(text));
199 break;
200 case "topic":
201 current.AddHeader("HeaderHelpTopic", array2[1]);
202 break;
203 case "Q":
204 current.AddText("NoteText_Q", STR(array2[1]));
205 break;
206 case "A":
207 current.AddText("NoteText_A", STR(array2[1]));
208 break;
209 case "pair":
210 current.AddTopic("TopicPair", STR(array2[1]), STR(array2[2]));
211 break;
212 case "image":
213 current.AddImage(array2[1]);
214 break;
215 case "link":
216 current.AddButtonLink(array2[1], array2[2]);
217 break;
218 case "button":
219 if (array2[1] == "close")
220 {
222 }
223 break;
224 }
225 text = "";
226 }
227 }
228 else if (!skip)
229 {
230 text = text + text2 + Environment.NewLine;
231 }
232 }
233 }
234 if (!text.IsEmpty())
235 {
236 text = text.Replace("#pc", str_pc);
237 UIItem uIItem2 = current.AddText("NoteText_help", STR(text));
238 if (center)
239 {
240 uIItem2.text1.alignment = TextAnchor.UpperCenter;
241 }
242 }
243 }
244 string STR(string s)
245 {
246 if (!hasSearchWord)
247 {
248 return s;
249 }
250 return Regex.Replace(s, searchWord, searchWord.TagColor(book.colorSearchHit), RegexOptions.IgnoreCase);
251 }
252 }
253 }
254
255 public static string str_pc;
256
257 public static string searchWord;
258
259 public static Dictionary<string, string> helpTitles = new Dictionary<string, string>();
260
261 public Mode mode;
262
263 [NonSerialized]
264 public int currentPage;
265
266 public List<Page> pages = new List<Page>();
267
268 public UINote note;
269
270 public UINote note2;
271
273
274 public UIList list;
275
277
279
281
283
284 [NonSerialized]
285 public string idFile;
286
287 [NonSerialized]
288 public string idTopic;
289
290 [NonSerialized]
291 public string idFirstFile;
292
293 [NonSerialized]
294 public string idFirstTopic;
295
297
298 public LayoutGroup layoutButton;
299
301
303
304 public Scrollbar scrollbar;
305
307
309
311
312 public InputField inputSearch;
313
315
317
318 public Transform transSearchResult;
319
320 public string lastSearch;
321
322 public bool showSearchResult;
323
324 public float searchResultHeight;
325
326 public float marginSearchResult;
327
329
331
332 private void Awake()
333 {
334 if (searchContext == null || Application.isEditor)
335 {
338 }
339 if ((bool)inputSearch)
340 {
341 inputSearch.onValueChanged.AddListener(Search);
342 inputSearch.onSubmit.AddListener(Search);
343 lastSearch = null;
344 }
345 }
346
347 private void Update()
348 {
349 if ((bool)inputSearch)
350 {
351 if (inputSearch.isFocused)
352 {
353 showSearchResult = true;
354 }
355 else if (Input.GetMouseButtonDown(0) && !InputModuleEX.IsPointerOver(scrollView) && !InputModuleEX.IsPointerOver(inputSearch))
356 {
357 showSearchResult = false;
358 }
359 buttonClear.SetActive(inputSearch.text != "");
360 transSearchResult.SetActive((inputSearch.isFocused || showSearchResult) && inputSearch.text != "");
361 if (Input.GetKeyDown(KeyCode.Escape) && inputSearch.text == "")
362 {
364 EInput.Consume(consumeAxis: false, 5);
365 }
366 }
367 }
368
369 public void Search(string s)
370 {
371 if (s == lastSearch)
372 {
373 return;
374 }
375 lastSearch = s;
376 if (s.IsEmpty())
377 {
378 return;
379 }
380 transSearchResult.SetActive(enable: true);
382 listSearchResult.callbacks = new UIList.Callback<SearchContext.Item, UIButton>
383 {
384 onClick = delegate(SearchContext.Item a, UIButton b)
385 {
386 if (!a.system)
387 {
388 SE.Play("click_recipe");
389 searchWord = s;
390 Show(a.idFile, a.idTopic);
391 }
392 },
393 onRedraw = delegate(SearchContext.Item a, UIButton b, int i)
394 {
395 if (a.system)
396 {
397 b.mainText.text = "";
398 b.subText.text = a.text;
399 }
400 else
401 {
402 string text = helpTitles.TryGetValue(a.idFile + "-") ?? "";
403 string text2 = helpTitles.TryGetValue(a.idFile + "-" + a.idTopic) ?? a.idTopic;
404 b.mainText.text = (text.IsEmpty() ? "" : (text + " - ")) + text2;
405 string text3 = a.text;
406 if (!text3.Contains("</color>"))
407 {
408 int num = a.textSearch.IndexOf(s.ToLower());
409 if (num != -1)
410 {
411 text3 = text3.Substring(0, num) + text3.Substring(num, s.Length).TagColor(colorSearchHit) + text3.Substring(num + s.Length);
412 }
413 }
414 b.subText.text = text3;
415 }
416 },
417 onList = delegate
418 {
420 {
422 }
423 },
424 onRefresh = null
425 };
427 scrollView.content.RebuildLayout(recursive: true);
428 RectTransform rectTransform = transSearchResult.Rect();
429 rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, Mathf.Min(searchResultHeight, scrollView.content.sizeDelta.y + marginSearchResult));
430 }
431
432 public void ClearSearch()
433 {
434 inputSearch.text = "";
435 lastSearch = null;
436 }
437
438 public void ModPage(int a)
439 {
440 SE.Play("read_paper");
441 if ((bool)note2)
442 {
443 a *= 2;
444 }
445 currentPage += a;
446 if (currentPage < 0)
447 {
448 currentPage = 0;
449 }
450 if (currentPage >= pages.Count)
451 {
452 currentPage = pages.Count - ((!note2) ? 1 : 2);
453 }
454 ShowPage(currentPage);
455 }
456
457 public void Show(string _idFile = null, string _idTopic = null, string title = null, BookList.Item _bookItem = null)
458 {
459 if (!title.IsEmpty() && (bool)window)
460 {
462 }
463 idFile = _idFile;
464 idTopic = _idTopic;
465 bookItem = _bookItem;
466 BuildPages();
467 Show();
468 }
469
470 public void Show()
471 {
472 note.Clear();
473 if ((bool)note2)
474 {
475 note2.Clear();
476 }
477 if ((bool)layoutButton)
478 {
479 moldButton = layoutButton.CreateMold<UIButton>();
480 }
481 if (mode == Mode.Help)
482 {
486 }
487 else
488 {
489 ShowPage(currentPage);
490 }
491 }
492
493 public void BuildPages()
494 {
495 pages.Clear();
496 string[] array = IO.LoadTextArray(CorePath.CorePackage.Help + idFile);
497 if (idFile == "version" && Lang.langCode == "CN")
498 {
499 array = IO.LoadTextArray(CorePath.CorePackage.TextEN + idFile);
500 }
501 if (array.IsEmpty())
502 {
503 array = IO.LoadTextArray(CorePath.CorePackage.Text + idFile);
504 }
505 if (array.IsEmpty())
506 {
507 array = IO.LoadTextArray(CorePath.CorePackage.TextCommon + idFile);
508 }
509 if (array.IsEmpty())
510 {
511 array = IO.LoadTextArray(CorePath.CorePackage.HelpEN + idFile);
512 }
513 if (array.IsEmpty())
514 {
515 array = IO.LoadTextArray(CorePath.CorePackage.TextEN + idFile);
516 }
517 Page page = new Page();
518 int num = 0;
519 string[] array2 = array;
520 foreach (string text in array2)
521 {
522 if (bookItem != null && num == 0)
523 {
524 num++;
525 continue;
526 }
527 if (text == "{p}")
528 {
529 AddPage(page);
530 page = new Page();
531 }
532 page.lines.Add(text);
533 num++;
534 }
535 AddPage(page);
536 }
537
538 public void AddPage(Page page)
539 {
540 page.idx = pages.Count;
541 pages.Add(page);
542 page.book = this;
543 }
544
545 public void RefreshTopics()
546 {
547 string[] array = IO.LoadTextArray(CorePath.CorePackage.Help + "_topics.txt");
548 List<UIList> lists = new List<UIList>();
549 lists.Add(list);
550 list.Clear();
551 list.callbacks = new UIList.Callback<Item, ButtonCategory>
552 {
553 onClick = delegate(Item a, ButtonCategory b)
554 {
555 if (a.items.Count > 0)
556 {
557 b.buttonFold.onClick.Invoke();
558 }
559 else
560 {
561 idFile = a.idFile;
562 idTopic = a.id;
564 BuildPages();
565 ShowPage();
566 }
567 },
568 onInstantiate = delegate(Item a, ButtonCategory b)
569 {
570 b.mainText.text = a.title;
571 bool flag = false;
572 if (a.items.Count > 0)
573 {
574 foreach (Item item4 in a.items)
575 {
576 if (item4.idFile == idFile && item4.id == idTopic)
577 {
578 flag = true;
579 }
580 }
581 }
582 b.SetFold(a.items.Count > 0, !flag, delegate(UIList l)
583 {
584 lists.Add(l);
585 foreach (Item item5 in a.items)
586 {
587 l.Add(item5);
588 }
589 });
590 },
591 onRefresh = null
592 };
593 string oldValue = '\t'.ToString();
594 Item item = null;
595 Item item2 = null;
596 helpTitles.Clear();
597 string[] array2 = array;
598 for (int i = 0; i < array2.Length; i++)
599 {
600 string[] array3 = array2[i].Replace(oldValue, "").Split(',');
601 string[] array4 = array3[0].Split('-');
602 Item item3 = new Item
603 {
604 idFile = array4[0],
605 id = array4[1],
606 title = array3[1]
607 };
608 helpTitles[array3[0]] = item3.title.Replace("$", "");
609 if (item3.title.StartsWith("$"))
610 {
611 item = item3;
612 item3.title = item3.title.TrimStart('$');
613 list.Add(item3);
614 }
615 else if (item != null)
617 item.items.Add(item3);
618 }
619 else
620 {
621 list.Add(item3);
622 }
623 if (item3.idFile == idFirstFile && item3.id == idFirstTopic)
624 {
625 item2 = item3;
626 idFirstFile = null;
628 }
629 list.Refresh();
630 if (item2 != null)
631 {
632 foreach (UIList item6 in lists)
634 item6.Select(item2, invoke: true);
635 }
636 }
637 else if (list.children.Count > 0)
638 {
639 list.children.FirstItem().Select(0, invoke: true);
640 }
641 else
642 {
643 list.Select(0, invoke: true);
644 }
645 SkinManager.tempSkin = null;
646 }
647
648 public void ShowPage(int idx = 0)
649 {
650 if ((bool)note2)
651 {
652 ShowPage(idx, note, textPage, buttonPrev);
653 ShowPage(idx + 1, note2, textPage2, buttonNext);
654 }
655 else
656 {
657 ShowPage(idx, note, textPage);
658 }
659 }
660
661 public void ShowPage(int idx, UINote n, UIText textPage = null, UIButton button = null)
662 {
663 if ((bool)transSearchResult)
664 {
665 transSearchResult.SetActive(enable: false);
666 showSearchResult = false;
667 }
668 bool flag = pages.Count > idx;
669 n.Clear();
670 if ((bool)textPage)
671 {
672 textPage.SetActive(flag);
673 }
674 if ((bool)button)
675 {
676 button.SetActive(flag);
677 }
678 if (flag)
679 {
680 idx = Mathf.Clamp(idx, 0, pages.Count - 1);
681 Page page = pages[idx];
682 if (page.idx == 0 && bookItem != null)
683 {
684 n.AddHeader("HeaderNoteBook", bookItem.title).text2.SetText(bookItem.author);
685 }
686 page.BuildNote(n, idTopic);
687 n.RebuildLayout(recursive: true);
688 n.Build();
689 n.RebuildLayoutTo<Layer>();
690 if ((bool)textPage)
691 {
692 textPage.SetText(page.idx + 1 + " / " + pages.Count);
693 }
694 LayoutGroup[] componentsInChildren = n.transform.parent.GetComponentsInChildren<LayoutGroup>();
695 foreach (LayoutGroup obj in componentsInChildren)
696 {
697 obj.CalculateLayoutInputHorizontal();
698 obj.CalculateLayoutInputVertical();
699 obj.SetLayoutHorizontal();
700 obj.SetLayoutVertical();
701 }
702 this.RebuildLayout(recursive: true);
703 if ((bool)layoutButton)
704 {
705 layoutButton.RebuildLayout(recursive: true);
706 }
707 if ((bool)scrollbar)
708 {
709 scrollbar.value = 1f;
710 }
711 searchWord = "";
712 }
713 }
714
715 public void AddButtonClose()
716 {
717 if ((bool)window)
718 {
719 AddButton("close", window.layer.Close);
720 }
721 }
722
723 public UIButton AddButton(string lang, Action action)
724 {
726 uIButton.mainText.SetText(lang.lang());
727 uIButton.onClick.AddListener(delegate
728 {
729 action();
730 });
731 return uIButton;
732 }
733}
item3. title
Definition: UIBook.cs:616
UIButton buttonFold
void SetFold(bool show, bool folded)
static string Help
Definition: CorePath.cs:75
static string TextEN
Definition: CorePath.cs:69
static string Text
Definition: CorePath.cs:67
static string HelpEN
Definition: CorePath.cs:77
static string TextCommon
Definition: CorePath.cs:65
Definition: EInput.cs:8
static void Consume(int _skipFrame)
Definition: EInput.cs:656
static bool IsPointerOver(Component c)
Definition: Lang.cs:6
static string langCode
Definition: Lang.cs:28
static string Parse(string idLang, string val1, string val2=null, string val3=null, string val4=null, string val5=null)
Definition: Lang.cs:147
Definition: Layer.cs:9
virtual void Close()
Definition: Layer.cs:463
List< Item > Search(string s)
string title
Definition: UIBook.cs:26
List< Item > items
Definition: UIBook.cs:28
string idFile
Definition: UIBook.cs:24
string id
Definition: UIBook.cs:22
UIBook book
Definition: UIBook.cs:33
int idx
Definition: UIBook.cs:35
List< string > lines
Definition: UIBook.cs:37
virtual void BuildNote(UINote n, string idTopic)
Definition: UIBook.cs:39
Definition: UIBook.cs:9
UIText textPage
Definition: UIBook.cs:280
UIList list
Definition: UIBook.cs:274
bool showSearchResult
Definition: UIBook.cs:322
UINote noteSearch
Definition: UIBook.cs:272
string lastSearch
Definition: UIBook.cs:320
UIText textPage2
Definition: UIBook.cs:282
Window window
Definition: UIBook.cs:306
string idFirstFile
Definition: UIBook.cs:291
int currentPage
Definition: UIBook.cs:264
static string searchWord
Definition: UIBook.cs:257
Mode
Definition: UIBook.cs:11
void Show()
Definition: UIBook.cs:470
void RefreshTopics()
Definition: UIBook.cs:545
string idTopic
Definition: UIBook.cs:288
Mode mode
Definition: UIBook.cs:261
UIText textTitle
Definition: UIBook.cs:278
UIButton buttonClear
Definition: UIBook.cs:314
LayoutGroup layoutButton
Definition: UIBook.cs:298
UIButton AddButton(string lang, Action action)
Definition: UIBook.cs:621
string idFirstTopic
Definition: UIBook.cs:294
void AddPage(Page page)
Definition: UIBook.cs:538
void AddButtonClose()
Definition: UIBook.cs:613
UIButton buttonNext
Definition: UIBook.cs:310
Scrollbar scrollbar
Definition: UIBook.cs:304
void ModPage(int a)
Definition: UIBook.cs:438
BookList.Item bookItem
Definition: UIBook.cs:302
UINote note2
Definition: UIBook.cs:270
void Show(string _idFile=null, string _idTopic=null, string title=null, BookList.Item _bookItem=null)
Definition: UIBook.cs:457
SkinRootStatic skin
Definition: UIBook.cs:296
UIDynamicList listSearchResult
Definition: UIBook.cs:276
List< Page > pages
Definition: UIBook.cs:266
static Dictionary< string, string > helpTitles
Definition: UIBook.cs:259
static string str_pc
Definition: UIBook.cs:255
void Search(string s)
Definition: UIBook.cs:369
float marginSearchResult
Definition: UIBook.cs:326
void Awake()
Definition: UIBook.cs:332
void Update()
Definition: UIBook.cs:347
void ClearSearch()
Definition: UIBook.cs:432
UIButton buttonPrev
Definition: UIBook.cs:308
UIScrollView scrollView
Definition: UIBook.cs:316
UIButton moldButton
Definition: UIBook.cs:300
float searchResultHeight
Definition: UIBook.cs:324
Color colorSearchHit
Definition: UIBook.cs:328
InputField inputSearch
Definition: UIBook.cs:312
static SearchContext searchContext
Definition: UIBook.cs:330
string idFile
Definition: UIBook.cs:285
UINote note
Definition: UIBook.cs:268
void BuildPages()
Definition: UIBook.cs:493
Transform transSearchResult
Definition: UIBook.cs:318
UIText mainText
Definition: UIButton.cs:102
override void List()
override void Add(object o)
override void Clear()
Definition: UIItem.cs:5
UIText text2
Definition: UIItem.cs:8
Definition: UIList.cs:9
override void Clear()
Definition: UIList.cs:349
Dictionary< UIButton, UIList > children
Definition: UIList.cs:263
void Select(int index=0, bool invoke=false)
Definition: UIList.cs:644
override void Add(object item)
Definition: UIList.cs:302
virtual void Refresh(bool highlightLast=false)
Definition: UIList.cs:424
Definition: UINote.cs:6
UIButton AddButtonLink(string text, string url)
Definition: UINote.cs:193
void Clear()
Definition: UINote.cs:35
UINote AddNote(string id)
Definition: UINote.cs:72
void AddImage(Sprite sprite)
Definition: UINote.cs:158
UIItem AddHeader(string text, Sprite sprite=null)
Definition: UINote.cs:79
UIItem AddTopic(string id, string text, string value=null)
Definition: UINote.cs:144
UIItem AddText(string text, FontColor color=FontColor.DontChange)
Definition: UINote.cs:113
void Build()
Definition: UINote.cs:49
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:159
Definition: Util.cs:10
static Transform Instantiate(string path, Component parent=null)
Definition: Util.cs:67
Definition: Window.cs:13
UIText textCaption
Definition: Window.cs:610
Layer layer
Definition: Window.cs:677