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
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2016-11-10 19:50:01 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
2018-05-10 11:38:58 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
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-17 17:36:00 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.inventory.gui.TexturedButton;
|
2017-02-14 21:50:03 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
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-17 17:36:00 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
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
|
|
|
|
2017-06-29 18:36:33 +02:00
|
|
|
import java.awt.*;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
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-10 23:37:40 +01:00
|
|
|
public final IBookletPage[] pages = new IBookletPage[2];
|
2016-11-16 20:31:16 +01:00
|
|
|
private final List<ItemDisplay> itemDisplays = new ArrayList<ItemDisplay>();
|
|
|
|
private int pageTimer;
|
2016-11-10 19:50:01 +01:00
|
|
|
|
2016-11-17 17:36:00 +01:00
|
|
|
private GuiButton buttonViewOnline;
|
|
|
|
|
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-17 17:36:00 +01:00
|
|
|
if(button == this.buttonViewOnline){
|
|
|
|
List<String> links = this.getWebLinks();
|
|
|
|
if(Desktop.isDesktopSupported()){
|
|
|
|
for(String link : links){
|
|
|
|
try{
|
|
|
|
Desktop.getDesktop().browse(new URI(link));
|
|
|
|
}
|
|
|
|
catch(Exception e){
|
2018-05-10 11:38:58 +02:00
|
|
|
ActuallyAdditions.LOGGER.error("Couldn't open website from Booklet page!", e);
|
2016-11-17 17:36:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
super.actionPerformed(button);
|
2016-11-10 22:06:58 +01:00
|
|
|
|
2016-11-17 17:36:00 +01:00
|
|
|
for(IBookletPage page : this.pages){
|
|
|
|
if(page != null){
|
|
|
|
page.actionPerformed(this, button);
|
|
|
|
}
|
2016-11-10 22:06:58 +01:00
|
|
|
}
|
|
|
|
}
|
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-17 17:36:00 +01:00
|
|
|
List<String> links = this.getWebLinks();
|
|
|
|
if(links != null && !links.isEmpty()){
|
2018-05-10 11:38:58 +02:00
|
|
|
this.buttonViewOnline = new TexturedButton(RES_LOC_GADGETS, -782822, this.guiLeft+this.xSize-24, this.guiTop+this.ySize-25, 0, 172, 16, 16, Collections.singletonList(TextFormatting.GOLD+StringUtil.localize("booklet."+ActuallyAdditions.MODID+".onlineButton.name")));
|
2016-11-17 17:36:00 +01:00
|
|
|
this.buttonList.add(this.buttonViewOnline);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-11-17 17:36:00 +01:00
|
|
|
private List<String> getWebLinks(){
|
|
|
|
List<String> links = new ArrayList<String>();
|
|
|
|
|
|
|
|
for(IBookletPage page : this.pages){
|
|
|
|
if(page != null){
|
|
|
|
String link = page.getWebLink();
|
|
|
|
if(link != null && !links.contains(link)){
|
|
|
|
links.add(link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return links;
|
|
|
|
}
|
|
|
|
|
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();
|
2017-06-29 18:30:02 +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
|
|
|
}
|
|
|
|
|
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;
|
2016-12-07 15:25:04 +01:00
|
|
|
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-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
|
|
|
}
|