2using System.Collections.Generic;
4using System.Text.RegularExpressions;
8public class UIBook : MonoBehaviour
28 public List<Item>
items =
new List<Item>();
37 public List<string>
lines =
new List<string>();
55 uIItem.text1.alignment = TextAnchor.UpperCenter;
57 LayoutElement component = uIItem.GetComponent<LayoutElement>();
60 component.enabled =
false;
68 foreach (
string line
in lines)
70 string text2 =
Lang.
Parse(line,
"test1",
"test2");
71 if (text2.Length == 0)
73 if (!skip && (
idTopic.IsEmpty() || flag))
75 text += Environment.NewLine;
89 if (text2.Split(
'$')[1] ==
idTopic)
106 current.
AddHeader(
"HeaderPatch_header", line);
109 text = text.TrimEnd(Environment.NewLine.ToCharArray());
111 current.
AddHeader(
"HeaderPatch_category", line);
115 text = line.TrimStart(
'*').TrimStart(
' ').TrimEnd(Environment.NewLine.ToCharArray());
116 current.
AddText(
"NoteText_list", text);
124 string[] array = text2.Split(
'}');
126 string[] array2 = array[0].TrimStart(
'{').Split(array[0].Contains(
'|') ?
'|' :
',');
127 if (!skip || !(array2[0] !=
"endif"))
133 string text5 = array2[1];
134 if (!(text5 ==
"cn"))
155 if (array2[0] ==
"include")
167 if (array3.IsEmpty())
171 if (array3.IsEmpty())
175 if (!array3.IsEmpty())
177 ParseLines(array3.ToList(), text3);
188 if (array2.Length == 1)
194 current = n.
AddNote(STR(array2[1]));
198 current.
AddText(
"NoteText_nerun", STR(text));
201 current.
AddHeader(
"HeaderHelpTopic", array2[1]);
204 current.
AddText(
"NoteText_Q", STR(array2[1]));
207 current.
AddText(
"NoteText_A", STR(array2[1]));
210 current.
AddTopic(
"TopicPair", STR(array2[1]), STR(array2[2]));
219 if (array2[1] ==
"close")
230 text = text + text2 + Environment.NewLine;
236 text = text.Replace(
"#pc",
str_pc);
237 UIItem uIItem2 = current.
AddText(
"NoteText_help", STR(text));
240 uIItem2.text1.alignment = TextAnchor.UpperCenter;
259 public static Dictionary<string, string>
helpTitles =
new Dictionary<string, string>();
266 public List<Page>
pages =
new List<Page>();
332 public static List<Func<string[]>>
topicLoaders =
new List<Func<string[]>>();
363 if (Input.GetKeyDown(KeyCode.Escape) &&
inputSearch.text ==
"")
390 SE.Play(
"click_recipe");
392 Show(a.idFile, a.idTopic);
399 b.mainText.text =
"";
400 b.subText.text = a.text;
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>"))
410 int num = a.textSearch.IndexOf(s.ToLower());
413 text3 = text3.Substring(0, num) + text3.Substring(num, s.Length).TagColor(
colorSearchHit) + text3.Substring(num + s.Length);
416 b.subText.text = text3;
429 scrollView.content.RebuildLayout(recursive:
true);
436 inputSearch.text =
"";
442 SE.Play(
"read_paper");
459 public void Show(
string _idFile =
null,
string _idTopic =
null,
string title =
null,
BookList.
Item _bookItem =
null)
499 if (
bookItem?.path !=
null && array ==
null)
501 array = IO.LoadTextArray(
bookItem.path);
505 List<string>
list =
new List<string>
511 CorePath.CorePackage.TextEN
520 if (!array.IsEmpty())
528 array = Array.Empty<
string>();
532 string[] array2 = array;
533 foreach (
string text
in array2)
545 page.lines.Add(text);
553 page.idx =
pages.Count;
560 List<UIList> lists =
new List<UIList>();
561 lists.Add(this.list);
567 if (a.
items.Count > 0)
582 b.mainText.text = a.
title;
584 if (a.
items.Count > 0)
605 string oldValue =
'\t'.ToString();
609 List<string>
list =
new List<string>();
615 list.AddRange(topicLoader());
617 catch (Exception arg)
619 Debug.LogWarning(
$"#book external topic loader failed\n{arg}");
622 foreach (
string item6
in list)
624 string[] array = item6.Replace(oldValue,
"").Split(
',');
625 string[] array2 = array[0].Split(
'-');
633 if (item3.
title.StartsWith(
"$"))
636 item3.title = item3.
title.TrimStart(
'$');
637 this.list.Add(item3);
639 else if (
item !=
null)
641 item.items.Add(item3);
645 this.list.Add(item3);
656 foreach (
UIList item7
in lists)
658 item7.
Select(item2, invoke:
true);
661 else if (this.list.children.Count > 0)
663 this.list.children.FirstItem().Select(0, invoke:
true);
667 this.list.Select(0, invoke:
true);
669 SkinManager.tempSkin =
null;
677 public void ShowPage(
int idx = 0)
697 bool flag = pages.Count > idx;
705 button.SetActive(flag);
709 idx = Mathf.Clamp(idx, 0,
pages.Count - 1);
710 Page page =
pages[idx];
711 if (page.idx == 0 &&
bookItem !=
null)
716 n.RebuildLayout(recursive:
true);
718 n.RebuildLayoutTo<
Layer>();
723 LayoutGroup[] componentsInChildren = n.transform.parent.GetComponentsInChildren<LayoutGroup>();
724 foreach (LayoutGroup obj
in componentsInChildren)
726 obj.CalculateLayoutInputHorizontal();
727 obj.CalculateLayoutInputVertical();
728 obj.SetLayoutHorizontal();
729 obj.SetLayoutVertical();
731 this.RebuildLayout(recursive:
true);
738 scrollbar.value = 1f;
756 uIButton.onClick.AddListener(delegate
this[] LoadBuiltInTopics()
static string[] LoadTextArray(string _path)
static string Parse(string idLang, string val1, string val2=null, string val3=null, string val4=null, string val5=null)
List< Item > Search(string s)
virtual void BuildNote(UINote n, string idTopic)
UIButton AddButton(string lang, Action action)
void Show(string _idFile=null, string _idTopic=null, string title=null, BookList.Item _bookItem=null)
UIDynamicList listSearchResult
static List< Func< string[]> > topicLoaders
static Dictionary< string, string > helpTitles
static SearchContext searchContext
Transform transSearchResult
override void Add(object o)
void Select(int index=0, bool invoke=false)
UIButton AddButtonLink(string text, string url)
UINote AddNote(string id)
void AddImage(Sprite sprite)
UIItem AddHeader(string text, Sprite sprite=null)
UIItem AddTopic(string id, string text, string value=null)
UIItem AddText(string text, FontColor color=FontColor.DontChange)
static Transform Instantiate(string path, Component parent=null)