2016-11-10 19:50:01 +01:00
|
|
|
/*
|
|
|
|
* This file ("GuiPage.java") is part of the Actually Additions mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
|
|
|
* © 2015-2016 Ellpeck
|
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.booklet.gui;
|
|
|
|
|
2016-11-11 18:55:32 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
|
2016-11-10 19:50:01 +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;
|
2016-11-11 18:55:32 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.booklet.misc.BookletUtils;
|
2016-11-10 23:37:40 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.booklet.page.ItemDisplay;
|
2016-11-10 21:07:15 +01:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2016-11-10 19:50:01 +01:00
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2016-11-11 16:37:45 +01:00
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
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 21:07:15 +01:00
|
|
|
import java.io.IOException;
|
2016-11-10 23:37:40 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2016-11-10 21:07:15 +01:00
|
|
|
|
2016-11-10 22:06:58 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2016-11-10 21:07:15 +01:00
|
|
|
public class GuiPage extends GuiBooklet{
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2016-11-11 18:55:32 +01:00
|
|
|
private int pageTimer;
|
2016-11-10 23:37:40 +01:00
|
|
|
private final List<ItemDisplay> itemDisplays = new ArrayList<ItemDisplay>();
|
|
|
|
public final IBookletPage[] pages = new IBookletPage[2];
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2016-11-10 22:06:58 +01:00
|
|
|
public GuiPage(GuiScreen previousScreen, GuiBookletBase parentPage, IBookletPage page1, IBookletPage page2){
|
2016-11-10 21:07:15 +01:00
|
|
|
super(previousScreen, parentPage);
|
2016-11-10 22:06:58 +01:00
|
|
|
|
|
|
|
this.pages[0] = page1;
|
|
|
|
this.pages[1] = page2;
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-10 21:07:15 +01:00
|
|
|
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{
|
2016-11-10 22:06:58 +01:00
|
|
|
super.mouseClicked(mouseX, mouseY, mouseButton);
|
|
|
|
|
2016-11-10 23:37:40 +01:00
|
|
|
for(ItemDisplay display : this.itemDisplays){
|
|
|
|
display.onMousePress(mouseButton, mouseX, mouseY);
|
|
|
|
}
|
|
|
|
|
2016-11-10 22:06:58 +01:00
|
|
|
for(IBookletPage page : this.pages){
|
|
|
|
if(page != null){
|
|
|
|
page.mouseClicked(this, mouseX, mouseY, mouseButton);
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 21:07:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseReleased(int mouseX, int mouseY, int state){
|
2016-11-10 22:06:58 +01:00
|
|
|
super.mouseReleased(mouseX, mouseY, state);
|
|
|
|
|
|
|
|
for(IBookletPage page : this.pages){
|
|
|
|
if(page != null){
|
|
|
|
page.mouseReleased(this, mouseX, mouseY, state);
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 21:07:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick){
|
2016-11-10 22:06:58 +01:00
|
|
|
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
|
|
|
|
|
|
|
for(IBookletPage page : this.pages){
|
|
|
|
if(page != null){
|
|
|
|
page.mouseClickMove(this, mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 21:07:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(GuiButton button) throws IOException{
|
2016-11-10 22:06:58 +01:00
|
|
|
super.actionPerformed(button);
|
|
|
|
|
|
|
|
for(IBookletPage page : this.pages){
|
|
|
|
if(page != null){
|
|
|
|
page.actionPerformed(this, button);
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 21:07:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initGui(){
|
2016-11-10 23:37:40 +01:00
|
|
|
this.itemDisplays.clear();
|
2016-11-11 18:55:32 +01:00
|
|
|
super.initGui();
|
2016-11-10 22:06:58 +01:00
|
|
|
|
2016-11-10 23:37:40 +01:00
|
|
|
for(int i = 0; i < this.pages.length; i++){
|
|
|
|
IBookletPage page = this.pages[i];
|
2016-11-10 22:06:58 +01:00
|
|
|
if(page != null){
|
2016-11-10 23:37:40 +01:00
|
|
|
page.initGui(this, this.guiLeft+6+i*142, this.guiTop+7);
|
2016-11-10 22:06:58 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-10 21:07:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateScreen(){
|
2016-11-10 22:06:58 +01:00
|
|
|
super.updateScreen();
|
|
|
|
|
2016-11-10 23:37:40 +01:00
|
|
|
for(int i = 0; i < this.pages.length; i++){
|
|
|
|
IBookletPage page = this.pages[i];
|
2016-11-10 22:06:58 +01:00
|
|
|
if(page != null){
|
2016-11-11 18:55:32 +01:00
|
|
|
page.updateScreen(this, this.guiLeft+6+i*142, this.guiTop+7, this.pageTimer);
|
2016-11-10 22:06:58 +01:00
|
|
|
}
|
|
|
|
}
|
2016-11-11 18:55:32 +01:00
|
|
|
|
|
|
|
this.pageTimer++;
|
2016-11-10 21:07:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-12 13:54:49 +01:00
|
|
|
public void drawScreenPre(int mouseX, int mouseY, float partialTicks){
|
|
|
|
super.drawScreenPre(mouseX, mouseY, partialTicks);
|
2016-11-10 23:37:40 +01:00
|
|
|
|
2016-11-12 15:48:24 +01:00
|
|
|
if(this.pages[0] != null){
|
|
|
|
IBookletChapter chapter = this.pages[0].getChapter();
|
|
|
|
String name = chapter.getLocalizedName();
|
|
|
|
this.fontRendererObj.drawString(name, this.guiLeft+this.xSize/2-this.fontRendererObj.getStringWidth(name)/2, this.guiTop-1, 0xFFFFFF, true);
|
|
|
|
}
|
|
|
|
|
2016-11-10 22:06:58 +01:00
|
|
|
for(int i = 0; i < this.pages.length; i++){
|
|
|
|
IBookletPage page = this.pages[i];
|
|
|
|
if(page != null){
|
2016-11-12 15:48:24 +01:00
|
|
|
IBookletChapter chapter = this.pages[i].getChapter();
|
|
|
|
String pageStrg = "Page "+(chapter.getPageIndex(this.pages[i])+1)+"/"+chapter.getAllPages().length;
|
|
|
|
this.renderScaledAsciiString(pageStrg, this.guiLeft+25+i*136, this.guiTop+this.ySize-7, 0xFFFFFF, false, 0.8F);
|
|
|
|
|
2016-11-11 16:37:45 +01:00
|
|
|
GlStateManager.color(1F, 1F, 1F);
|
2016-11-10 22:06:58 +01:00
|
|
|
page.drawScreenPre(this, this.guiLeft+6+i*142, this.guiTop+7, mouseX, mouseY, partialTicks);
|
|
|
|
}
|
|
|
|
}
|
2016-11-10 23:37:40 +01:00
|
|
|
for(ItemDisplay display : this.itemDisplays){
|
2016-11-11 16:37:45 +01:00
|
|
|
display.drawPre();
|
2016-11-10 23:37:40 +01:00
|
|
|
}
|
2016-11-12 13:54:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawScreenPost(int mouseX, int mouseY, float partialTicks){
|
|
|
|
super.drawScreenPost(mouseX, mouseY, partialTicks);
|
2016-11-10 23:37:40 +01:00
|
|
|
|
2016-11-10 22:06:58 +01:00
|
|
|
for(int i = 0; i < this.pages.length; i++){
|
|
|
|
IBookletPage page = this.pages[i];
|
|
|
|
if(page != null){
|
2016-11-11 16:37:45 +01:00
|
|
|
GlStateManager.color(1F, 1F, 1F);
|
2016-11-10 22:06:58 +01:00
|
|
|
page.drawScreenPost(this, this.guiLeft+6+i*142, this.guiTop+7, mouseX, mouseY, partialTicks);
|
|
|
|
}
|
|
|
|
}
|
2016-11-11 16:37:45 +01:00
|
|
|
for(ItemDisplay display : this.itemDisplays){
|
|
|
|
display.drawPost(mouseX, mouseY);
|
|
|
|
}
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|
2016-11-10 23:37:40 +01:00
|
|
|
|
|
|
|
@Override
|
2016-11-11 18:55:32 +01:00
|
|
|
public void addOrModifyItemRenderer(ItemStack renderedStack, int x, int y, float scale, boolean shouldTryTransfer){
|
|
|
|
for(ItemDisplay display : this.itemDisplays){
|
|
|
|
if(display.x == x && display.y == y && display.scale == scale){
|
|
|
|
display.stack = renderedStack;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-10 23:37:40 +01:00
|
|
|
this.itemDisplays.add(new ItemDisplay(this, x, y, scale, renderedStack, shouldTryTransfer));
|
|
|
|
}
|
2016-11-11 18:55:32 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPageLeftButton(){
|
|
|
|
IBookletPage page = this.pages[0];
|
|
|
|
if(page != null){
|
|
|
|
IBookletChapter chapter = page.getChapter();
|
|
|
|
if(chapter != null){
|
|
|
|
return chapter.getPageIndex(page) > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageLeftButtonPressed(){
|
|
|
|
IBookletPage page = this.pages[0];
|
|
|
|
if(page != null){
|
|
|
|
IBookletChapter chapter = page.getChapter();
|
|
|
|
if(chapter != null){
|
|
|
|
IBookletPage[] pages = chapter.getAllPages();
|
|
|
|
|
|
|
|
int pageNumToOpen = chapter.getPageIndex(page)-1;
|
|
|
|
if(pageNumToOpen >= 0 && pageNumToOpen < pages.length){
|
|
|
|
this.mc.displayGuiScreen(BookletUtils.createPageGui(this.previousScreen, this.parentPage, pages[pageNumToOpen]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasPageRightButton(){
|
|
|
|
IBookletPage page = this.pages[1];
|
|
|
|
if(page != null){
|
|
|
|
IBookletChapter chapter = page.getChapter();
|
|
|
|
if(chapter != null){
|
|
|
|
int pageIndex = chapter.getPageIndex(page);
|
|
|
|
int pageAmount = chapter.getAllPages().length;
|
2016-11-12 00:29:01 +01:00
|
|
|
return pageIndex+1 < pageAmount;
|
2016-11-11 18:55:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageRightButtonPressed(){
|
|
|
|
IBookletPage page = this.pages[1];
|
|
|
|
if(page != null){
|
|
|
|
IBookletChapter chapter = page.getChapter();
|
|
|
|
if(chapter != null){
|
|
|
|
IBookletPage[] pages = chapter.getAllPages();
|
|
|
|
|
|
|
|
int pageNumToOpen = chapter.getPageIndex(page)+1;
|
|
|
|
if(pageNumToOpen >= 0 && pageNumToOpen < pages.length){
|
|
|
|
this.mc.displayGuiScreen(BookletUtils.createPageGui(this.previousScreen, this.parentPage, pages[pageNumToOpen]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasBackButton(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackButtonPressed(){
|
2016-11-12 15:09:30 +01:00
|
|
|
if(!isShiftKeyDown()){
|
|
|
|
this.mc.displayGuiScreen(this.parentPage);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
super.onBackButtonPressed();
|
|
|
|
}
|
2016-11-11 18:55:32 +01:00
|
|
|
}
|
2016-11-10 19:50:01 +01:00
|
|
|
}
|