Elin Decompiled Documentation EA 23.307 Stable
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 public static List<Func<string[]>> topicLoaders = new List<Func<string[]>>();
333
334 private void Awake()
335 {
336 if (searchContext == null || Application.isEditor)
337 {
340 }
341 if ((bool)inputSearch)
342 {
343 inputSearch.onValueChanged.AddListener(Search);
344 inputSearch.onSubmit.AddListener(Search);
345 lastSearch = null;
346 }
347 }
348
349 private void Update()
350 {
351 if ((bool)inputSearch)
352 {
353 if (inputSearch.isFocused)
354 {
355 showSearchResult = true;
356 }
357 else if (Input.GetMouseButtonDown(0) && !InputModuleEX.IsPointerOver(scrollView) && !InputModuleEX.IsPointerOver(inputSearch))
358 {
359 showSearchResult = false;
360 }
361 buttonClear.SetActive(inputSearch.text != "");
362 transSearchResult.SetActive((inputSearch.isFocused || showSearchResult) && inputSearch.text != "");
363 if (Input.GetKeyDown(KeyCode.Escape) && inputSearch.text == "")
364 {
366 EInput.Consume(consumeAxis: false, 5);
367 }
368 }
369 }
370
371 public void Search(string s)
372 {
373 if (s == lastSearch)
374 {
375 return;
376 }
377 lastSearch = s;
378 if (s.IsEmpty())
379 {
380 return;
381 }
382 transSearchResult.SetActive(enable: true);
384 listSearchResult.callbacks = new UIList.Callback<SearchContext.Item, UIButton>
385 {
386 onClick = delegate(SearchContext.Item a, UIButton b)
387 {
388 if (!a.system)
389 {
390 SE.Play("click_recipe");
391 searchWord = s;
392 Show(a.idFile, a.idTopic);
393 }
394 },
395 onRedraw = delegate(SearchContext.Item a, UIButton b, int i)
396 {
397 if (a.system)
398 {
399 b.mainText.text = "";
400 b.subText.text = a.text;
401 }
402 else
403 {
404 string text = helpTitles.TryGetValue(a.idFile + "-") ?? "";
405 string text2 = helpTitles.TryGetValue(a.idFile + "-" + a.idTopic) ?? a.idTopic;
406 b.mainText.text = (text.IsEmpty() ? "" : (text + " - ")) + text2;
407 string text3 = a.text;
408 if (!text3.Contains("</color>"))
409 {
410 int num = a.textSearch.IndexOf(s.ToLower());
411 if (num != -1)
412 {
413 text3 = text3.Substring(0, num) + text3.Substring(num, s.Length).TagColor(colorSearchHit) + text3.Substring(num + s.Length);
414 }
415 }
416 b.subText.text = text3;
417 }
418 },
419 onList = delegate
420 {
422 {
424 }
425 },
426 onRefresh = null
427 };
429 scrollView.content.RebuildLayout(recursive: true);
430 RectTransform rectTransform = transSearchResult.Rect();
431 rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, Mathf.Min(searchResultHeight, scrollView.content.sizeDelta.y + marginSearchResult));
432 }
433
434 public void ClearSearch()
435 {
436 inputSearch.text = "";
437 lastSearch = null;
438 }
439
440 public void ModPage(int a)
441 {
442 SE.Play("read_paper");
443 if ((bool)note2)
444 {
445 a *= 2;
446 }
447 currentPage += a;
448 if (currentPage < 0)
449 {
450 currentPage = 0;
451 }
452 if (currentPage >= pages.Count)
453 {
454 currentPage = pages.Count - ((!note2) ? 1 : 2);
455 }
456 ShowPage(currentPage);
457 }
458
459 public void Show(string _idFile = null, string _idTopic = null, string title = null, BookList.Item _bookItem = null)
460 {
461 if (!title.IsEmpty() && (bool)window)
462 {
464 }
465 idFile = _idFile;
466 idTopic = _idTopic;
467 bookItem = _bookItem;
468 BuildPages();
469 Show();
470 }
471
472 public void Show()
473 {
474 note.Clear();
475 if ((bool)note2)
476 {
477 note2.Clear();
478 }
479 if ((bool)layoutButton)
480 {
481 moldButton = layoutButton.CreateMold<UIButton>();
482 }
483 if (mode == Mode.Help)
484 {
488 }
489 else
490 {
491 ShowPage(currentPage);
492 }
493 }
494
495 public void BuildPages()
496 {
497 pages.Clear();
498 string[] array = bookItem?.lines;
499 if (bookItem?.path != null && array == null)
500 {
501 array = IO.LoadTextArray(bookItem.path);
502 }
503 if (array.IsEmpty())
504 {
505 List<string> list = new List<string>
506 {
511 CorePath.CorePackage.TextEN
512 };
513 if (idFile == "version" && Lang.langCode == "CN")
514 {
515 list.Insert(1, CorePath.CorePackage.TextEN);
516 }
517 foreach (string item in list)
518 {
519 array = IO.LoadTextArray(item + idFile);
520 if (!array.IsEmpty())
521 {
522 break;
523 }
524 }
525 }
526 if (array == null)
527 {
528 array = Array.Empty<string>();
529 }
530 Page page = new Page();
531 int num = 0;
532 string[] array2 = array;
533 foreach (string text in array2)
534 {
535 if (bookItem != null && num == 0)
536 {
537 num++;
538 continue;
539 }
540 if (text == "{p}")
541 {
542 AddPage(page);
543 page = new Page();
544 }
545 page.lines.Add(text);
546 num++;
547 }
548 AddPage(page);
549 }
550
551 public void AddPage(Page page)
552 {
553 page.idx = pages.Count;
554 pages.Add(page);
555 page.book = this;
556 }
557
558 public void RefreshTopics()
559 {
560 List<UIList> lists = new List<UIList>();
561 lists.Add(this.list);
562 this.list.Clear();
563 this.list.callbacks = new UIList.Callback<Item, ButtonCategory>
564 {
565 onClick = delegate(Item a, ButtonCategory b)
566 {
567 if (a.items.Count > 0)
568 {
569 b.buttonFold.onClick.Invoke();
570 }
571 else
572 {
573 idFile = a.idFile;
574 idTopic = a.id;
576 BuildPages();
577 ShowPage();
578 }
579 },
580 onInstantiate = delegate(Item a, ButtonCategory b)
581 {
582 b.mainText.text = a.title;
583 bool flag = false;
584 if (a.items.Count > 0)
585 {
586 foreach (Item item4 in a.items)
587 {
588 if (item4.idFile == idFile && item4.id == idTopic)
589 {
590 flag = true;
591 }
592 }
593 }
594 b.SetFold(a.items.Count > 0, !flag, delegate(UIList l)
595 {
596 lists.Add(l);
597 foreach (Item item5 in a.items)
598 {
599 l.Add(item5);
600 }
601 });
602 },
603 onRefresh = null
604 };
605 string oldValue = '\t'.ToString();
606 Item item = null;
607 Item item2 = null;
608 helpTitles.Clear();
609 List<string> list = new List<string>();
610 list.AddRange(LoadBuiltInTopics());
611 foreach (Func<string[]> topicLoader in topicLoaders)
612 {
613 try
614 {
615 list.AddRange(topicLoader());
616 }
617 catch (Exception arg)
618 {
619 Debug.LogWarning($"#book external topic loader failed\n{arg}");
620 }
621 }
622 foreach (string item6 in list)
623 {
624 string[] array = item6.Replace(oldValue, "").Split(',');
625 string[] array2 = array[0].Split('-');
626 Item item3 = new Item
627 {
628 idFile = array2[0],
629 id = array2[1],
630 title = array[1]
631 };
632 helpTitles[array[0]] = item3.title.Replace("$", "");
633 if (item3.title.StartsWith("$"))
634 {
635 item = item3;
636 item3.title = item3.title.TrimStart('$');
637 this.list.Add(item3);
638 }
639 else if (item != null)
641 item.items.Add(item3);
642 }
643 else
644 {
645 this.list.Add(item3);
646 }
647 if (item3.idFile == idFirstFile && item3.id == idFirstTopic)
648 {
649 item2 = item3;
650 idFirstFile = null;
651 }
652 }
653 this.list.Refresh();
654 if (item2 != null)
655 {
656 foreach (UIList item7 in lists)
657 {
658 item7.Select(item2, invoke: true);
659 }
660 }
661 else if (this.list.children.Count > 0)
662 {
663 this.list.children.FirstItem().Select(0, invoke: true);
664 }
665 else
666 {
667 this.list.Select(0, invoke: true);
668 }
669 SkinManager.tempSkin = null;
670 }
671
672 public string[] LoadBuiltInTopics()
673 {
674 return IO.LoadTextArray(CorePath.CorePackage.Help + "_topics.txt");
675 }
677 public void ShowPage(int idx = 0)
678 {
679 if ((bool)note2)
680 {
681 ShowPage(idx, note, textPage, buttonPrev);
682 ShowPage(idx + 1, note2, textPage2, buttonNext);
683 }
684 else
685 {
686 ShowPage(idx, note, textPage);
687 }
688 }
689
690 public void ShowPage(int idx, UINote n, UIText textPage = null, UIButton button = null)
691 {
692 if ((bool)transSearchResult)
693 {
694 transSearchResult.SetActive(enable: false);
695 showSearchResult = false;
696 }
697 bool flag = pages.Count > idx;
698 n.Clear();
699 if ((bool)textPage)
700 {
701 textPage.SetActive(flag);
702 }
703 if ((bool)button)
704 {
705 button.SetActive(flag);
706 }
707 if (flag)
708 {
709 idx = Mathf.Clamp(idx, 0, pages.Count - 1);
710 Page page = pages[idx];
711 if (page.idx == 0 && bookItem != null)
712 {
713 n.AddHeader("HeaderNoteBook", bookItem.title).text2.SetText(bookItem.author);
714 }
715 page.BuildNote(n, idTopic);
716 n.RebuildLayout(recursive: true);
717 n.Build();
718 n.RebuildLayoutTo<Layer>();
719 if ((bool)textPage)
720 {
721 textPage.SetText(page.idx + 1 + " / " + pages.Count);
722 }
723 LayoutGroup[] componentsInChildren = n.transform.parent.GetComponentsInChildren<LayoutGroup>();
724 foreach (LayoutGroup obj in componentsInChildren)
725 {
726 obj.CalculateLayoutInputHorizontal();
727 obj.CalculateLayoutInputVertical();
728 obj.SetLayoutHorizontal();
729 obj.SetLayoutVertical();
730 }
731 this.RebuildLayout(recursive: true);
732 if ((bool)layoutButton)
733 {
734 layoutButton.RebuildLayout(recursive: true);
735 }
736 if ((bool)scrollbar)
737 {
738 scrollbar.value = 1f;
739 }
740 searchWord = "";
741 }
742 }
743
744 public void AddButtonClose()
745 {
746 if ((bool)window)
747 {
748 AddButton("close", window.layer.Close);
749 }
750 }
751
752 public UIButton AddButton(string lang, Action action)
753 {
755 uIButton.mainText.SetText(lang.lang());
756 uIButton.onClick.AddListener(delegate
757 {
758 action();
759 });
760 return uIButton;
761 }
762}
item3. title
Definition: UIBook.cs:640
$
Definition: UIBook.cs:638
this[] LoadBuiltInTopics()
Definition: UIBook.cs:676
UIButton buttonFold
void SetFold(bool show, bool folded)
static string Help
Definition: CorePath.cs:69
static string TextEN
Definition: CorePath.cs:61
static string Text
Definition: CorePath.cs:59
static string HelpEN
Definition: CorePath.cs:71
static string TextCommon
Definition: CorePath.cs:57
Definition: EInput.cs:8
static void Consume(int _skipFrame)
Definition: EInput.cs:667
Definition: IO.cs:11
static string[] LoadTextArray(string _path)
Definition: IO.cs:475
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:149
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:472
void RefreshTopics()
Definition: UIBook.cs:558
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:645
string idFirstTopic
Definition: UIBook.cs:294
void AddPage(Page page)
Definition: UIBook.cs:551
void AddButtonClose()
Definition: UIBook.cs:637
UIButton buttonNext
Definition: UIBook.cs:310
Scrollbar scrollbar
Definition: UIBook.cs:304
void ModPage(int a)
Definition: UIBook.cs:440
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:459
SkinRootStatic skin
Definition: UIBook.cs:296
UIDynamicList listSearchResult
Definition: UIBook.cs:276
static List< Func< string[]> > topicLoaders
Definition: UIBook.cs:332
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:371
float marginSearchResult
Definition: UIBook.cs:326
void Awake()
Definition: UIBook.cs:334
void Update()
Definition: UIBook.cs:349
void ClearSearch()
Definition: UIBook.cs:434
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:495
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:401
void Select(int index=0, bool invoke=false)
Definition: UIList.cs:696
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:163
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