Made this while working on something. I don't have any need for it what so ever. Its not exactly the best written thing I have ever done was mostly to test out what I could do so I'd suggest you edit it to your liking.
The big benefit of this is that it allows unlimited pages to be used within the book.
Firstly make a new class inside the players package. Name it BookCreation and paste this code inside
Code:
import java.util.ArrayList;
public class BookCreation {
//Page number and max pages
private int page = 0;
private int page_max = 0;
//Client Object
private Client c = null;
//Page title and more
private String[] CONTENT_PAGE_TITLE = {
"",//title
"Previous",//left corner
"Next",//right corner
};
//Holds the books content
ArrayList<String> CONTENT_PAGE = new ArrayList<String>();
//Constructor
public BookCreation(Client c){
this.c = c;
//this.CONTENT_PAGE_TITLE[0] = title; //Old idea
}
/* Sends interface */
public void openBook() {
page = 1;
updatePage();
c.getPlayerAssistant().showInterface(837);
}
/*adds the content to the book */
public void addContent(String str){
CONTENT_PAGE.add(str);
page_max = (int) Math.ceil((double) CONTENT_PAGE.size()/22);
}
/*adds the content to the book */
public void addContent(String[] str){
for(int i = 0; i < str.length; i++){
CONTENT_PAGE.add(str[i]);
}
page_max = (int) Math.ceil((double) CONTENT_PAGE.size()/22);
}
/*Title setter*/
public void setTitle(String str){
CONTENT_PAGE_TITLE[0] = str;
}
/*Title setter*/
public void setLeft(String str){
CONTENT_PAGE_TITLE[1] = str;
}
/*Title setter*/
public void setRight(String str){
CONTENT_PAGE_TITLE[2] = str;
}
/* page forward */
public void increasePage() {
if (page == page_max) {
//nothing here
} else {
page++;
updatePage();
}
}
/* page back */
public void decreasePage() {
if (page == 1) {
//nothing here
} else {
page--;
updatePage();
}
}
/* Updates the strings on the interface to the correct page text */
private void updatePage() {
//Clears book before each update
for(int i = 0, id = 843;i < 22; i++, id++){
c.getPlayerAssistant().sendFrame126("", id);
}
//Sets the title etc
c.getPlayerAssistant().sendFrame126(CONTENT_PAGE_TITLE[0], 903); /* Title of the book */
c.getPlayerAssistant().sendFrame126(CONTENT_PAGE_TITLE[1], 14165); /* Bottom left corner */
c.getPlayerAssistant().sendFrame126(CONTENT_PAGE_TITLE[2], 14166); /* Bottom right corner */
int i = 22 * (page - 1); //Set i to first entry for the page from array. i = 0 on page 1 then 22 page 2, 44 page 3, 66 etc
for(int id_num = 843;i < (22*page); i++, id_num++){//Simply loop over all items in the array for the page (Each page has 22 items 22 * page)
if(i >= CONTENT_PAGE.size()){ //Prevents trying to print non existent lines
return;
}
c.getPlayerAssistant().sendFrame126(CONTENT_PAGE.get(i), id_num); //Send the frame
}
}
}
Next find your ClickingButtons and at the bottom of all the cases add this
Code:
case 3073:
player.getBook().increasePage();
break;
case 3071:
player.getBook().decreasePage();
break;
case 39178:
player.getPlayerAssistant().closeAllWindows();
break;
Finally in client add these in. (Whilst it doesn't matter where you put these I suggest placing them where other similar methods have been placed)
Code:
private BookCreation Book = new BookCreation(this);
public BookCreation getBook() {
return Book;
}
Now to use it you just fill it with content, set a title and open it like so. This can be used from within ClickItem for a specific item, from a command or anything else. My aweful example below from my testing.
Code:
String[] str = {
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",//etc
};
player.getBook().addContent(str);
player.getBook().setTitle("Test Book");
player.getBook().openBook();
Remember made this while testing not the best but is at least functional.