diff --git a/HarmonySrc/NecroTome.cs b/HarmonySrc/NecroTome.cs index d5ca80c..7d50a40 100644 --- a/HarmonySrc/NecroTome.cs +++ b/HarmonySrc/NecroTome.cs @@ -143,7 +143,9 @@ namespace NecromancerTome [Preserve] public class XUiC_NecroTome : XUiController { - const int MaxButtons = 10; // было 8; девятая - кровавый прилив (10.10), кнопки btnCh1..10 в windows.xml + /// Кнопок глав на странице оглавления (btnCh1..10 в windows.xml). Глав будет много (указание 10.10) - + /// оглавление листается теми же «Назад/Далее», что и главы. + const int MaxButtons = 10; XUiV_Label _title, _text, _page; XUiV_Texture _img; @@ -160,6 +162,9 @@ namespace NecromancerTome /// Глава по кнопке оглавления (только открытые главы, по порядку). readonly int[] _buttonChapter = new int[MaxButtons]; int _chapter = -1, _pageIndex; + /// Страница оглавления; «Оглавление» из главы возвращает на неё. + int _tocPage; + readonly List _open = new List(); public override void Init() { @@ -173,7 +178,7 @@ namespace NecromancerTome _prev = GetChildById("btnPrev") as XUiC_SimpleButton; _next = GetChildById("btnNext") as XUiC_SimpleButton; _close = GetChildById("btnClose") as XUiC_SimpleButton; - if (_toc != null) _toc.OnPressed += (_s, _m) => ShowToc(); + if (_toc != null) _toc.OnPressed += (_s, _m) => ShowToc(_tocPage); if (_prev != null) _prev.OnPressed += (_s, _m) => Turn(-1); if (_next != null) _next.OnPressed += (_s, _m) => Turn(1); if (_close != null) _close.OnPressed += (_s, _m) => xui.playerUI.windowManager.Close(NecroTomeBook.WindowGroup); @@ -191,25 +196,33 @@ namespace NecromancerTome public override void OnOpen() { base.OnOpen(); - ShowToc(); + ShowToc(0); } - void ShowToc() + void ShowToc(int _p) { _chapter = -1; SetLabel(_title, Localization.Get("necroTomeToc")); SetLabel(_text, ""); - SetLabel(_page, ""); SetMedia(null, null); EntityPlayerLocal player = xui.playerUI.entityPlayer; - int b = 0; - for (int c = 0; c < NecroTomeBook.Chapters.Count && b < MaxButtons; c++) + // Открытые главы по порядку; на странице - MaxButtons из них. + _open.Clear(); + for (int c = 0; c < NecroTomeBook.Chapters.Count; c++) { NecroTomeBook.Chapter ch = NecroTomeBook.Chapters[c]; - if (ch.Unlocked != null && !ch.Unlocked(player)) + if (ch.Unlocked == null || ch.Unlocked(player)) { - continue; + _open.Add(c); } + } + int pages = Mathf.Max(1, (_open.Count + MaxButtons - 1) / MaxButtons); + _tocPage = Mathf.Clamp(_p, 0, pages - 1); + int b = 0; + for (int i = _tocPage * MaxButtons; i < _open.Count && b < MaxButtons; i++) + { + int c = _open[i]; + NecroTomeBook.Chapter ch = NecroTomeBook.Chapters[c]; _buttonChapter[b] = c; if (_chapterButtons[b] != null) { @@ -226,8 +239,13 @@ namespace NecromancerTome } } SetVisible(_toc, false); - SetVisible(_prev, false); - SetVisible(_next, false); + // Листать оглавление - только если страниц больше одной. + bool many = pages > 1; + SetLabel(_page, many ? (_tocPage + 1) + " / " + pages : ""); + SetVisible(_prev, many); + SetVisible(_next, many); + if (_prev != null) _prev.Enabled = _tocPage > 0; + if (_next != null) _next.Enabled = _tocPage < pages - 1; } void ShowChapter(int _c, int _p) @@ -316,6 +334,10 @@ namespace NecromancerTome { ShowChapter(_chapter, _pageIndex + _d); } + else + { + ShowToc(_tocPage + _d); + } } static void SetLabel(XUiV_Label _l, string _s) diff --git a/NecromancerHarmony.dll b/NecromancerHarmony.dll index f3e769e..6724657 100644 Binary files a/NecromancerHarmony.dll and b/NecromancerHarmony.dll differ diff --git a/NecromancerHarmony.pdb b/NecromancerHarmony.pdb index 020ac59..04bdbcb 100644 Binary files a/NecromancerHarmony.pdb and b/NecromancerHarmony.pdb differ diff --git a/Textures/necroTomeTide.png b/Textures/necroTomeTide.png index 6651f85..dd11437 100644 Binary files a/Textures/necroTomeTide.png and b/Textures/necroTomeTide.png differ