More book convenience

This commit is contained in:
Bernhard Bonigl committed 2016-05-17 20:49:07 +02:00
1 parent 214328c239
commit 1bd2c73a09
3 files changed
+21 -4

No files matched your search

@@ -77,7 +77,7 @@ public class BookLoader implements IResourceManagerReloadListener {
// Register action protocols
StringActionProcessor.registerProtocol(new ProtocolGoToPage());
StringActionProcessor.registerProtocol(new ProtocolGoToPage(true, "-rtn"));
StringActionProcessor.registerProtocol(new ProtocolGoToPage(true, ProtocolGoToPage.GO_TO_RTN));
}
/**
@@ -17,6 +17,7 @@ public abstract class BookTransformer {
public static BookTransformer IndexTranformer() { return IndexTranformer.INSTANCE; }
public static BookTransformer contentTableTransformer() { return ContentTableTransformer.INSTANCE; }
public static BookTransformer contentTableTransformerForSection(String sectionName) { return new ContentTableTransformer(sectionName); }
/**
* Called when all the sections within the book are loaded.
@@ -72,6 +73,16 @@ public abstract class BookTransformer {
public static final ContentTableTransformer INSTANCE = new ContentTableTransformer();
private final String sectionToTransform;
public ContentTableTransformer(String sectionToTransform) {
this.sectionToTransform = sectionToTransform;
}
public ContentTableTransformer() {
this.sectionToTransform = null;
}
@Override
public void transform(BookData book) {
final int ENTRIES_PER_PAGE = 24;
@@ -80,6 +91,9 @@ public abstract class BookTransformer {
if(section.name.equals("index")) {
continue;
}
if(sectionToTransform != null && !section.name.equals(sectionToTransform)) {
continue;
}
int genPages = (int) Math.ceil(section.getPageCount() * 1.F / ENTRIES_PER_PAGE);
@@ -4,14 +4,17 @@ import slimeknights.mantle.client.gui.book.GuiBook;
public class ProtocolGoToPage extends ActionProtocol {
public static final String GO_TO = "go-to-page";
public static final String GO_TO_RTN = GO_TO + "-rtn";
private final boolean returner;
public ProtocolGoToPage() {
this(false, "");
this(false, GO_TO);
}
public ProtocolGoToPage(boolean returner, String suffix) {
super("go-to-page" + suffix);
public ProtocolGoToPage(boolean returner, String string) {
super(string);
this.returner = returner;
}