Skip to content

Commit

Permalink
made it so the page counter would only appear when there are multiple…
Browse files Browse the repository at this point in the history
… pages, or the book explicitly says it has a title page
  • Loading branch information
chrisj42 committed Jun 16, 2018
1 parent 61ae648 commit a9e5a48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/minicraft/item/BookItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,29 @@ public class BookItem extends Item {
protected static ArrayList<Item> getAllInstances() {
ArrayList<Item> items = new ArrayList<Item>();
items.add(new BookItem("Book", Color.get(-1, 200, 531, 430), null));
items.add(new BookItem("Antidious", Color.get(-1, 100, 300, 500), BookData.antVenomBook));
items.add(new BookItem("Antidious", Color.get(-1, 100, 300, 500), BookData.antVenomBook, true));
return items;
}

protected String book; // TODO this is not saved yet; it could be, for editable books.
private final boolean hasTitlePage;

private BookItem(String title, int color, String book) {
private BookItem(String title, int color, String book) { this(title, color, book, false); }
private BookItem(String title, int color, String book, boolean hasTitlePage) {
super(title, new Sprite(14, 4, color));
this.book = book;
this.hasTitlePage = hasTitlePage;
}

public boolean interactOn(Tile tile, Level level, int xt, int yt, Player player, Direction attackDir) {
Game.setMenu(new BookDisplay(book));
Game.setMenu(new BookDisplay(book, hasTitlePage));
return true;
}

@Override
public boolean interactsWithWorld() { return false; }

public BookItem clone() {
return new BookItem(getName(), sprite.color, book);
return new BookItem(getName(), sprite.color, book, hasTitlePage);
}
}
12 changes: 6 additions & 6 deletions src/minicraft/screen/BookDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class BookDisplay extends Display {
private final boolean showPageCount;
private final int pageOffset;

public BookDisplay(String book) { this(book, true); }
public BookDisplay(String book, boolean hasTitle) { this(book, hasTitle, !hasTitle); }
public BookDisplay(String book, boolean hasTitle, boolean hideCountIfOnePage) {
public BookDisplay(String book) { this(book, false); }
public BookDisplay(String book, boolean hasTitle) {// this(book, hasTitle, !hasTitle); }
//public BookDisplay(String book, boolean hasTitle, boolean hideCountIfOnePage) {
page = 0;
if(book == null) {
book = defaultBook;
Expand All @@ -51,15 +51,15 @@ public BookDisplay(String book, boolean hasTitle, boolean hideCountIfOnePage) {

lines = pages.toArray(new String[pages.size()][]);

showPageCount = !hideCountIfOnePage || lines.length != 1;
showPageCount = hasTitle || lines.length != 1;
pageOffset = showPageCount ? 1 : 0;

Menu.Builder builder = new Menu.Builder(true, spacing, RelPos.CENTER)
.setFrame(554, 1, 554);

Menu pageCount = builder // the small rect for the title
.setPositioning(new Point(Screen.w/2, 0), RelPos.BOTTOM)
.setEntries(StringEntry.useLines(Color.BLACK, "Page", hasTitle?"Title":"1"))
.setEntries(StringEntry.useLines(Color.BLACK, "Page", hasTitle?"Title":"1/"+lines.length))
.setSelection(1)
.createMenu();

Expand All @@ -81,7 +81,7 @@ private void turnPage(int dir) {
if(page+dir >= 0 && page+dir < lines.length) {
menus[page+pageOffset].shouldRender = false;
page += dir;
if(showPageCount) menus[0].updateSelectedEntry(new StringEntry(page==0 && hasTitle?"Title":(page+1)+"", Color.BLACK));
if(showPageCount) menus[0].updateSelectedEntry(new StringEntry(page==0 && hasTitle?"Title":(page+1)+"/"+lines.length, Color.BLACK));
menus[page+pageOffset].shouldRender = true;
}
}
Expand Down

0 comments on commit a9e5a48

Please sign in to comment.