Jump to content

[1.11.2] [UNSOLVED] Custom book create pages on fly


Bektor

Recommended Posts

Hi,

 

I'm currently working on a custom book and want to create new pages on fly for it.

I've got myself and index which includes all chapters the book has and instead of using a scrollbar when more than 10 chapters

exists for this book, I want to add a new page to show the rest of the chapters.

So each site on the index page shows only 10 chapters and when you've got 100 chapters the index part of the book will be 10 pages long.

 

Here is what I've currently got:

 

        if(!this.chapters.isEmpty()) {
            int buttons = this.buttonList.size() - 1;
            int y = (this.top + 20) / this.chapters.size() + 10;
            for(int i = 0; i < this.chapters.size(); i++) {
                y += 10;
                GuiButtonChapter button = new GuiButtonChapter(i + buttons, this.left + 20, y, 100, 10, this.chapters.get(i));
                button.displayString = I18n.format(this.chapters.get(i).getTitle());
                this.buttonList.add(button);
            }
        }

 

GuiButtonChapter is the button used to display the chapter and to actually choose to read it.

Chapters is a ArrayList which get's loaded in from my API as other mods might want to add chapters to the book. This happens when the Gui object is created.

The top and left variables are used to determine the start point of the GUI.

 

Thx in advance.

Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

Anyone got an idea as I'm stuck on this problem.

 

Just to mention, also tried this piece of code... well, it resulted in an index out of bounds exception

for(int z = 0; z < this.maxPages; z++) {
            for(int i = 0; i < this.chapters.size(); i++) {
                y += 10;
                if(!(this.chapters.size() > i + z)) {
                    System.out.println("max: " + maxPages);
                    System.out.println("chapters: " + chapters.size());
                    System.out.println("i: " + i);
                    System.out.println("z: " + z);
                    break;
                }
                GuiButtonChapter button = new GuiButtonChapter(i + buttons, this.left + 20, y, 100, 10, this.chapters.get(i + z));
                button.displayString = I18n.format(this.chapters.get(i).getTitle());
                this.buttonList.add(button);
            }
}

 

Quote

max: 2 // yeah, it should be 3 as chapters is 21 and only 10 per page...

chapters: 21

i: 20

z: 1

 

Also it does not work. Somehow it even seems to do some weird stuff when going a page back...

Edited by Bektor

Developer of Primeval Forest.

Link to comment
Share on other sites

Math.ceil(chapters.size()/10f) should return the required amount of pages for the chapters.
But without an Idea how the rest of your code looks and how you handle the pages we cannot tell you anything more.

Edited by JTK222
Link to comment
Share on other sites

4 minutes ago, JTK222 said:

Math.ceil(chapters.size()/10f) should return the required amount of pages for the chapters.
But without an Idea how the rest of your code looks and how you handle the pages we cannot tell you anything more.

Ah, ok. That works. (I guess my idea of fixing this would have been more resource intensive ^^)

 

I'm handling the pages by actually having an integer variable which counts on which page we are currenty.

Thats basically how I handle the pages.

    private int page = 0;
    private int maxPages = 0;
    private ArrayList<Chapter> chapters = new ArrayList<>(APIMod.chapters);

    protected void initGui() {
        if(!this.chapters.isEmpty()) {
            int buttons = this.buttonList.size() - 1;
            int y = (this.top + 20) / this.chapters.size() + 10;
            for(int i = 0; i < this.chapters.size(); i++) {
                y += 10;
                GuiButtonChapter button = new GuiButtonChapter(i + buttons, this.left + 20, y, 100, 10, this.chapters.get(i));
                button.displayString = I18n.format(this.chapters.get(i).getTitle());
                this.buttonList.add(button);
            }
        }
    }

public void drawScreen(int mouseX, int mouseY, float partialTicks) {
  super.drawScreen(mouseX, mouseY, partialTicks);
}

 

Developer of Primeval Forest.

Link to comment
Share on other sites

So I guess you use the pages only for this?
And not for the chapters themselves?

If yes you should create a list of 10 buttons. and add a method to them on to change for which chapter they are.
And as you switch pages you would have just to change the chapters for the buttons.

Link to comment
Share on other sites

17 hours ago, JTK222 said:

So I guess you use the pages only for this?
And not for the chapters themselves?

If yes you should create a list of 10 buttons. and add a method to them on to change for which chapter they are.
And as you switch pages you would have just to change the chapters for the buttons.

Yes, the chapters are a different GUI.

 

Hm... I'm just wondering if this is efficient to do it with a list as every button would require to update on the actionPerformed method:

  • displayString and translate it
  • the chapter from the list

 This would mean, on each click on the forward button or the backwards button the hole button and chapters list would have to be iterated over.

Developer of Primeval Forest.

Link to comment
Share on other sites

Yes, you would need to iterate trough the buttons, but let's be serious even in case your chapters lists gets a few hundred entries you wouldn't even notice it. (Using this system for a Crafting System I have done).
But you wouldn't have to iterate trough the chapters, chapters.get(10 * page + buttonOffset); should be enough, you would just have to set buttonOffset for each button (first button 0 and 10th button 9).
Maybe with a small if statement to prevent an IndexOutOfBounds exception and it would be done.

	button.chapter = chapters.size > 10 * page + buttonOffset ? chapters.get(10*page +buttonOffset) : null;
	

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.