2020-09-09 16:49:01 +02:00
|
|
|
package de.ellpeck.actuallyadditions.booklet.gui;
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-11-10 19:50:01 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
|
2016-11-11 16:37:45 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
|
2016-11-10 21:07:15 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
2020-09-09 16:49:01 +02:00
|
|
|
import de.ellpeck.actuallyadditions.booklet.button.EntryButton;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.entry.BookletEntryTrials;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.misc.BookletUtils;
|
2016-11-11 16:37:45 +01:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2016-11-10 19:50:01 +01:00
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2016-11-10 23:37:40 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-11-10 22:06:58 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2016-11-10 22:06:58 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public class GuiEntry extends GuiBooklet {
|
2016-11-10 19:50:01 +01:00
|
|
|
|
|
|
|
//The page in the entry. Say you have 2 more chapters than fit on one double page, then those 2 would be displayed on entryPage 1 instead.
|
|
|
|
private final int entryPage;
|
2016-11-12 15:48:24 +01:00
|
|
|
private final int pageAmount;
|
2016-11-10 19:50:01 +01:00
|
|
|
private final IBookletEntry entry;
|
2016-11-11 16:37:45 +01:00
|
|
|
private final List<IBookletChapter> chapters;
|
2016-11-12 12:26:36 +01:00
|
|
|
private final String searchText;
|
|
|
|
private final boolean focusSearch;
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public GuiEntry(GuiScreen previousScreen, GuiBookletBase parentPage, IBookletEntry entry, int entryPage, String search, boolean focusSearch) {
|
2016-11-10 21:07:15 +01:00
|
|
|
super(previousScreen, parentPage);
|
2016-11-10 19:50:01 +01:00
|
|
|
this.entryPage = entryPage;
|
2016-11-10 21:07:15 +01:00
|
|
|
this.entry = entry;
|
2016-11-12 12:26:36 +01:00
|
|
|
this.searchText = search;
|
|
|
|
this.focusSearch = focusSearch;
|
|
|
|
this.chapters = entry.getChaptersForDisplay(search);
|
2016-11-12 15:48:24 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!this.chapters.isEmpty()) {
|
|
|
|
IBookletChapter lastChap = this.chapters.get(this.chapters.size() - 1);
|
|
|
|
this.pageAmount = lastChap == null ? 1 : calcEntryPage(this.entry, lastChap, this.searchText) + 1;
|
|
|
|
} else {
|
2016-11-12 16:06:30 +01:00
|
|
|
this.pageAmount = 1;
|
|
|
|
}
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public GuiEntry(GuiScreen previousScreen, GuiBookletBase parentPage, IBookletEntry entry, IBookletChapter chapterForPageCalc, String search, boolean focusSearch) {
|
2016-11-12 12:26:36 +01:00
|
|
|
this(previousScreen, parentPage, entry, calcEntryPage(entry, chapterForPageCalc, search), search, focusSearch);
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
private static int calcEntryPage(IBookletEntry entry, IBookletChapter chapterForPageCalc, String search) {
|
2016-11-12 12:26:36 +01:00
|
|
|
int index = entry.getChaptersForDisplay(search).indexOf(chapterForPageCalc);
|
2019-05-02 09:10:29 +02:00
|
|
|
return index / (BUTTONS_PER_PAGE * 2);
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|
|
|
|
|
2016-11-12 15:48:24 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void drawScreenPre(int mouseX, int mouseY, float partialTicks) {
|
2016-11-12 15:48:24 +01:00
|
|
|
super.drawScreenPre(mouseX, mouseY, partialTicks);
|
|
|
|
|
|
|
|
String name = this.entry.getLocalizedName();
|
2019-05-02 09:10:29 +02:00
|
|
|
this.fontRenderer.drawString(name, this.guiLeft + this.xSize / 2 - this.fontRenderer.getStringWidth(name) / 2, this.guiTop - 1, 0xFFFFFF, true);
|
2016-11-12 15:48:24 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
String pageStrg = "Page " + (this.entryPage * 2 + i + 1) + "/" + this.pageAmount * 2;
|
|
|
|
this.renderScaledAsciiString(pageStrg, this.guiLeft + 25 + i * 136, this.guiTop + this.ySize - 7, 0xFFFFFF, false, this.getLargeFontSize());
|
2016-11-12 15:48:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-10 19:50:01 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void initGui() {
|
2016-11-10 21:07:15 +01:00
|
|
|
super.initGui();
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.hasSearchBar() && this.searchText != null) {
|
2016-11-12 12:26:36 +01:00
|
|
|
this.searchField.setText(this.searchText);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.focusSearch) {
|
2016-11-12 12:26:36 +01:00
|
|
|
this.searchField.setFocused(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
int idOffset = this.entryPage * BUTTONS_PER_PAGE * 2;
|
|
|
|
for (int x = 0; x < 2; x++) {
|
|
|
|
for (int y = 0; y < BUTTONS_PER_PAGE; y++) {
|
|
|
|
int id = y + x * BUTTONS_PER_PAGE;
|
|
|
|
if (this.chapters.size() > id + idOffset) {
|
|
|
|
IBookletChapter chapter = this.chapters.get(id + idOffset);
|
|
|
|
this.buttonList.add(new EntryButton(this, id, this.guiLeft + 14 + x * 142, this.guiTop + 11 + y * 13, 115, 10, chapter.getLocalizedNameWithFormatting(), chapter.getDisplayItemStack()));
|
|
|
|
} else {
|
2016-11-10 21:07:15 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|
2016-11-10 23:37:40 +01:00
|
|
|
|
2016-11-11 16:37:45 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
protected void actionPerformed(GuiButton button) throws IOException {
|
|
|
|
if (button instanceof EntryButton) {
|
|
|
|
int actualId = button.id + this.entryPage * BUTTONS_PER_PAGE * 2;
|
2016-11-11 16:37:45 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.chapters.size() > actualId) {
|
2016-11-11 16:37:45 +01:00
|
|
|
IBookletChapter chapter = this.chapters.get(actualId);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (chapter != null) {
|
2016-11-11 16:37:45 +01:00
|
|
|
IBookletPage[] pages = chapter.getAllPages();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (pages != null && pages.length > 0) {
|
2016-11-11 16:37:45 +01:00
|
|
|
this.mc.displayGuiScreen(BookletUtils.createPageGui(this.previousScreen, this, pages[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-11-11 16:37:45 +01:00
|
|
|
super.actionPerformed(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-10 23:37:40 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void addOrModifyItemRenderer(ItemStack renderedStack, int x, int y, float scale, boolean shouldTryTransfer) {
|
2016-11-10 23:37:40 +01:00
|
|
|
|
|
|
|
}
|
2016-11-11 18:55:32 +01:00
|
|
|
|
2016-11-11 21:07:18 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean hasPageLeftButton() {
|
2016-11-11 21:07:18 +01:00
|
|
|
return this.entryPage > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void onPageLeftButtonPressed() {
|
|
|
|
this.mc.displayGuiScreen(new GuiEntry(this.previousScreen, this.parentPage, this.entry, this.entryPage - 1, this.searchText, this.searchField.isFocused()));
|
2016-11-11 21:07:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean hasPageRightButton() {
|
|
|
|
return !this.chapters.isEmpty() && this.entryPage < this.pageAmount - 1;
|
2016-11-11 21:07:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void onPageRightButtonPressed() {
|
|
|
|
this.mc.displayGuiScreen(new GuiEntry(this.previousScreen, this.parentPage, this.entry, this.entryPage + 1, this.searchText, this.searchField.isFocused()));
|
2016-11-11 21:07:18 +01:00
|
|
|
}
|
|
|
|
|
2016-11-11 18:55:32 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean hasBackButton() {
|
2016-11-11 18:55:32 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void onBackButtonPressed() {
|
|
|
|
if (!isShiftKeyDown()) {
|
2016-11-12 15:09:30 +01:00
|
|
|
this.mc.displayGuiScreen(this.parentPage);
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-11-12 15:09:30 +01:00
|
|
|
super.onBackButtonPressed();
|
|
|
|
}
|
2016-11-11 18:55:32 +01:00
|
|
|
}
|
2017-02-18 00:54:58 +01:00
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean areTrialsOpened() {
|
2017-02-18 00:54:58 +01:00
|
|
|
return this.entry instanceof BookletEntryTrials;
|
|
|
|
}
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|