From edfd3577ad35ca77bc0312849c6f4ccfe3394a5f Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 28 Jun 2017 19:08:05 +0200 Subject: [PATCH] More work on TUI (can now browse a text story) --- libs/jexer-0.0.4-sources.patch.jar | Bin 20542 -> 23536 bytes .../fanfix/reader/TuiReaderStoryWindow.java | 128 ++++++++++++++---- 2 files changed, 99 insertions(+), 29 deletions(-) diff --git a/libs/jexer-0.0.4-sources.patch.jar b/libs/jexer-0.0.4-sources.patch.jar index 85dc502747923c3b5f604ef8a2151c8e83dcc506..0816729da0f14e142a188189690ed56bd3010058 100644 GIT binary patch delta 3015 zcmV;&3pn(?paJl=0kAnYe^Hp+O7b3VX(9^%09_{l01yBG0BU7;WpXc6RAqQ{E^1+R zVeML9b0Rkke{Md7hM7)DLpOJQ=}gmfN&?r=6376#G}HEBVGZkMv8mS^l6LO9SJD~` z`v>l(FMTL;2WwmUNtR?;_U8P{6ZjH-5--BQSMXE#9KuArSh!EIf1{_YF!OLGPJqcK zv4Gp&1p0C&R4Sl}jZ-&vtyix`E@BJK>r?pp&D(F_XYni*^uwiAb^~!I%u=SQ)Cyz@ zu`pu#3JVh=Mbv`15d!oaW^rg1q6Jn%s9s?uOo|M8YD1}{T0lrpGn7cgHb$gW&+R%i z0_h_N(^Su7h>#HJe_6H^%7&Ii&SfG}Xj+^{W9&E@r!7PyQIQA}K#gg5GYV^IW1U$r zBDF@&2&RQZvm}d9lkIRKmogWEV2r@VNC`JfMT@m)qbR-aU?b zKi*8>X4vm^vGb~n`n9k6U6RJLyY9Dpw=L+jZ`(h1nQMqBG)ba#YQn=!mwHKR8~(zvmz%;r9Kw zyQfj7f7|XO;u!h&=r>OOAisMv$F}KI5 z?iL;OF;w@f<5VMBv&YE@YD4q~ZVo|a(ae3Rf1X6tm#IhagWT1qKJZ4PR~6zGdGz>e*>|VQ3u&_Dh$D~RbeXZS_lOqoW-yTO^Ef& zDy~Imt}*5yvg{?iEep6N4=X9uOu$muSVvSdL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j&gsly6>&$33f8j|a|s4CJaR zf2mY`=G!gyE*<$o_+#JEn~v}HuE44*Lk}L%n^G28iB@?Usz+=z3iK6IBhxHH>l(=O z`Bx1%<3AHv2;)x}h5Zvr8fgI@NyePy(3`8we?k88*nHDskF=b`AeY$O72L`%s#|sE zNNoyJCqO#Hm7G8Wbc`$37L}Ht(n;jw3gx>n;x%GKYV%8;X%ecZJR~aPjCJHND=Fh+ zt{KCb^n%+!AtKYxHFI`(>=sOB=@UB_ok7U8GbkD*Z=MTdB-wG#E_DQ1W9#R zP;JPh{0AGeSSFDXYJZmqb}f|KQfQ#S7nF)3kAuGWx#)--`(P%hEuud zh)>7tsKc1OPt}wE7~%k?)p&^iXt1t|4r1l+M9OfErMULAjfLUG08JZCLD*Sv3feD3 zzZiY&Z`G=LnegG{AG0qvp%@WSnA}S89&TwO3jhFJCjbBtli^PoD^z88bS`RPc3}zt zAOHXW000317ytmV4OTGl(g6Um4OTGl(g6Um4OTGllfq9d0)Il2@J~Pv1poyAtN{Q3 JE?NKp004``%Qyf4 delta 41 wcmeycopIj+#toL{n>(GROH6KxmYZxB%{_T_v^gIO0}F!}BLl-dKL#KG08W(*cK`qY diff --git a/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java b/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java index 9572566f..9613e632 100644 --- a/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java +++ b/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java @@ -1,5 +1,8 @@ package be.nikiroo.fanfix.reader; +import java.util.ArrayList; +import java.util.List; + import jexer.*; import jexer.event.TResizeEvent; import be.nikiroo.fanfix.Instance; @@ -12,47 +15,55 @@ public class TuiReaderStoryWindow extends TWindow { private MetaData meta; private Story story; private TText textField; + private int chapter = -2; + private List navigationButtons; + private TLabel chapterName; public TuiReaderStoryWindow(TApplication app, MetaData meta) { + this(app, meta, 0); + } + + public TuiReaderStoryWindow(TApplication app, MetaData meta, int chapter) { super(app, desc(meta), 0, 0, 60, 18, CENTERED | RESIZABLE); this.meta = meta; - // /TODO: status bar with info, buttons to change chapter << < Chapter 0 - // : xxx.. > >> (max size for name = getWith() - X) + // TODO: show all meta info before? - // TODO: show all meta info before - // TODO: text.append("Resume:\n\n "); -> to status bar - // -2 because 0-based, 2 for borders, -1 to hide the HScroll textField = addText("", 0, 0, getWidth() - 2, getHeight() - 2); - - Chapter resume = getStory().getMeta().getResume(); - if (resume != null) { - for (Paragraph para : resume) { - // TODO: This is not efficient, should be changed - for (String line : para.getContent().split("\n")) { - textField.addLine(line); - } - } - } - + statusBar = newStatusBar(desc(meta)); statusBar.addShortcutKeypress(TKeypress.kbF10, TCommand.cmExit, "Exit"); - + + navigationButtons = new ArrayList(4); + // -3 because 0-based and 2 for borders - TButton first = addButton("<<", 0, getHeight() - 3, - new TAction() { + int row = getHeight() - 3; + + navigationButtons.add(addButton("<<", 0, row, new TAction() { public void DO() { - // TODO + setChapter(0); } - } - ); - addButton("<", 3, getHeight() - 3, null); - addButton(">", 5, getHeight() - 3, null); - addButton(">>", 7, getHeight() - 3, null); - // TODO: pad with space up to end of window - // TODO: do not show "0/x: " for desc, only for other chapters - addLabel(String.format(" %d/%d: %s", resume.getNumber(), getStory().getChapters().size(), resume.getName()), 11, getHeight() - 3); + })); + navigationButtons.add(addButton("<", 3, row, new TAction() { + public void DO() { + setChapter(TuiReaderStoryWindow.this.chapter - 1); + } + })); + navigationButtons.add(addButton(">", 5, row, new TAction() { + public void DO() { + setChapter(TuiReaderStoryWindow.this.chapter + 1); + } + })); + navigationButtons.add(addButton(">>", 7, row, new TAction() { + public void DO() { + setChapter(getStory().getChapters().size()); + } + })); + + chapterName = addLabel("", 11, row); + chapterName.setWidth(getWidth() - 10); + setChapter(chapter); } @Override @@ -63,11 +74,70 @@ public class TuiReaderStoryWindow extends TWindow { textField.setWidth(resize.getWidth()); textField.setHeight(resize.getHeight() - 2); textField.reflow(); + + // -3 because 0-based and 2 for borders + int row = getHeight() - 3; + + String name = chapterName.getLabel(); + while (name.length() < resize.getWidth() - chapterName.getX()) { + name += " "; + } + chapterName.setLabel(name); + chapterName.setWidth(resize.getWidth() - 10); + chapterName.setY(row); + + for (TButton button : navigationButtons) { + button.setY(row); + } + } + + private void setChapter(int chapter) { + if (chapter < 0) { + chapter = 0; + } + + if (chapter > getStory().getChapters().size()) { + chapter = getStory().getChapters().size(); + } + + if (chapter != this.chapter) { + this.chapter = chapter; + Chapter chap; + String name; + if (chapter == 0) { + chap = getStory().getMeta().getResume(); + name = String.format(" %s", chap.getName()); + } else { + chap = getStory().getChapters().get(chapter - 1); + name = String.format(" %d/%d: %s", chapter, getStory() + .getChapters().size(), chap.getName()); + } + + while (name.length() < getWidth() - chapterName.getX()) { + name += " "; + } + + chapterName.setLabel(name); + + StringBuilder builder = new StringBuilder(); + // TODO: i18n + String c = String.format("Chapter %d: %s", chapter, chap.getName()); + builder.append(c).append("\n"); + for (int i = 0; i < c.length(); i++) { + builder.append("═"); + } + builder.append("\n\n"); + for (Paragraph para : chap) { + builder.append(para.getContent()).append("\n\n"); + } + textField.setText(builder.toString()); + textField.reflow(); + } } private Story getStory() { if (story == null) { - // TODO: progress bar + // TODO: progress bar? story = Instance.getLibrary().getStory(meta.getLuid(), null); } return story; -- 2.27.0