ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/booklet/GuiBooklet.java

316 lines
12 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("GuiBooklet.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://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2015-11-02 20:55:19 +01:00
* © 2015 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2015-08-29 23:01:13 +02:00
package ellpeck.actuallyadditions.booklet;
2015-08-28 21:17:09 +02:00
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ellpeck.actuallyadditions.booklet.chapter.BookletChapter;
import ellpeck.actuallyadditions.booklet.entry.BookletEntry;
import ellpeck.actuallyadditions.booklet.entry.BookletEntryAllSearch;
import ellpeck.actuallyadditions.booklet.page.BookletPage;
2015-08-28 21:17:09 +02:00
import ellpeck.actuallyadditions.config.GuiConfiguration;
2015-10-18 19:56:18 +02:00
import ellpeck.actuallyadditions.proxy.ClientProxy;
import ellpeck.actuallyadditions.update.UpdateChecker;
import ellpeck.actuallyadditions.util.AssetUtil;
2015-09-30 06:56:33 +02:00
import ellpeck.actuallyadditions.util.playerdata.PersistentClientData;
import net.minecraft.client.gui.FontRenderer;
2015-08-28 21:17:09 +02:00
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
2015-08-29 15:40:12 +02:00
import net.minecraft.client.gui.GuiTextField;
2015-08-28 21:17:09 +02:00
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import java.util.List;
2015-08-28 21:17:09 +02:00
@SideOnly(Side.CLIENT)
public class GuiBooklet extends GuiScreen{
public static final ResourceLocation resLoc = AssetUtil.getBookletGuiLocation("guiBooklet");
public static final ResourceLocation resLocHalloween = AssetUtil.getBookletGuiLocation("guiBookletHalloween");
public static final ResourceLocation resLocChristmas = AssetUtil.getBookletGuiLocation("guiBookletChristmas");
public static final ResourceLocation resLocValentine = AssetUtil.getBookletGuiLocation("guiBookletValentinesDay");
2015-11-16 19:57:46 +01:00
2015-10-03 10:16:18 +02:00
public static final int CHAPTER_BUTTONS_AMOUNT = 13;
public static final int TOOLTIP_SPLIT_LENGTH = 200;
2015-11-16 19:57:46 +01:00
2015-08-28 21:17:09 +02:00
public int xSize;
public int ySize;
public int guiLeft;
public int guiTop;
2015-11-16 19:57:46 +01:00
public BookletPage currentPage;
2015-08-28 21:17:09 +02:00
public BookletChapter currentChapter;
public BookletEntry currentIndexEntry;
2015-11-16 19:57:46 +01:00
public int pageOpenInIndex;
public int indexPageAmount;
2015-11-16 19:57:46 +01:00
public GuiButton buttonForward;
public GuiButton buttonBackward;
public GuiButton buttonPreviousScreen;
public GuiButton buttonPreviouslyOpenedGui;
public GuiButton buttonUpdate;
public GuiButton buttonTwitter;
public GuiButton buttonForum;
public GuiButton buttonAchievements;
public GuiButton buttonConfig;
public GuiButton[] chapterButtons = new GuiButton[CHAPTER_BUTTONS_AMOUNT];
2015-11-16 19:57:46 +01:00
public GuiButton[] bookmarkButtons = new GuiButton[8];
public GuiTextField searchField;
2015-11-16 19:57:46 +01:00
private int ticksElapsed;
2015-10-04 13:21:07 +02:00
private boolean mousePressed;
public GuiScreen parentScreen;
2015-11-24 17:50:27 +01:00
private boolean tryOpenMainPage;
private boolean saveOnClose;
2015-11-24 17:50:27 +01:00
public GuiBooklet(GuiScreen parentScreen, boolean tryOpenMainPage, boolean saveOnClose){
2015-08-28 21:17:09 +02:00
this.xSize = 146;
this.ySize = 180;
this.parentScreen = parentScreen;
2015-11-24 17:50:27 +01:00
this.tryOpenMainPage = tryOpenMainPage;
this.saveOnClose = saveOnClose;
2015-08-28 21:17:09 +02:00
}
public void drawHoveringText(List list, int x, int y){
super.func_146283_a(list, x, y);
}
public FontRenderer getFontRenderer(){
return this.fontRendererObj;
}
2015-08-28 21:17:09 +02:00
@Override
public void drawScreen(int x, int y, float f){
//Fixes Unicode flag
boolean unicodeBefore = this.fontRendererObj.getUnicodeFlag();
this.fontRendererObj.setUnicodeFlag(true);
//Draws the Background
2015-08-28 21:17:09 +02:00
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(ClientProxy.jingleAllTheWay ? resLocChristmas : (ClientProxy.pumpkinBlurPumpkinBlur ? resLocHalloween : (ClientProxy.bulletForMyValentine ? resLocValentine : resLoc)));
2015-10-16 22:34:58 +02:00
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
2015-08-28 21:17:09 +02:00
//Draws the search bar
if(this.currentIndexEntry instanceof BookletEntryAllSearch && this.currentChapter == null){
this.mc.getTextureManager().bindTexture(resLoc);
2015-08-29 15:40:12 +02:00
this.drawTexturedModalRect(this.guiLeft+146, this.guiTop+160, 146, 80, 70, 14);
}
//Draws Achievement Info
BookletUtils.drawAchievementInfo(this, true, x, y);
//Draws the title
this.fontRendererObj.setUnicodeFlag(false);
BookletUtils.drawTitle(this);
this.fontRendererObj.setUnicodeFlag(true);
2015-08-28 21:17:09 +02:00
//Pre-Renders the current page's content etc.
BookletUtils.renderPre(this, x, y, this.ticksElapsed, this.mousePressed);
//Does vanilla drawing stuff
super.drawScreen(x, y, f);
2015-08-29 15:40:12 +02:00
this.searchField.drawTextBox();
//Draws hovering texts for buttons
this.fontRendererObj.setUnicodeFlag(false);
BookletUtils.doHoverTexts(this, x, y);
2015-11-13 21:40:38 +01:00
BookletUtils.drawAchievementInfo(this, false, x, y);
this.fontRendererObj.setUnicodeFlag(true);
//Renders the current page's content
if(this.currentIndexEntry != null && this.currentChapter != null && this.currentPage != null){
this.currentPage.render(this, x, y, this.ticksElapsed, this.mousePressed);
}
this.fontRendererObj.setUnicodeFlag(unicodeBefore);
2015-10-04 13:21:07 +02:00
//Resets mouse
2015-10-04 13:21:07 +02:00
if(this.mousePressed){
this.mousePressed = false;
}
2015-08-28 21:17:09 +02:00
}
2015-10-03 10:19:40 +02:00
@Override
public void keyTyped(char theChar, int key){
if(key != 1 && this.searchField.isFocused()){
this.searchField.textboxKeyTyped(theChar, key);
BookletUtils.updateSearchBar(this);
}
else{
super.keyTyped(theChar, key);
}
}
2015-08-31 06:15:06 +02:00
2015-10-03 10:19:40 +02:00
@Override
protected void mouseClicked(int par1, int par2, int par3){
this.searchField.mouseClicked(par1, par2, par3);
//Notifys the booklet of the mouse being pressed
if(par3 == 0 && this.currentChapter != null){
2015-10-04 13:21:07 +02:00
this.mousePressed = true;
}
2015-10-03 10:19:40 +02:00
super.mouseClicked(par1, par2, par3);
2015-08-28 21:17:09 +02:00
}
@Override
public void actionPerformed(GuiButton button){
//Handles going to the parent GUI
if(button == this.buttonPreviouslyOpenedGui){
if(this.parentScreen != null){
mc.displayGuiScreen(this.parentScreen);
}
}
//Handles update
else if(button == this.buttonUpdate){
if(UpdateChecker.needsUpdateNotify){
BookletUtils.openBrowser(UpdateChecker.CHANGELOG_LINK, UpdateChecker.DOWNLOAD_LINK);
}
}
//Handles Twitter
else if(button == this.buttonTwitter){
BookletUtils.openBrowser("http://twitter.com/ActAddMod");
}
//Handles forum
else if(button == this.buttonForum){
BookletUtils.openBrowser("http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2551118");
}
//Handles config
else if(button == this.buttonConfig){
2015-08-28 21:17:09 +02:00
mc.displayGuiScreen(new GuiConfiguration(this));
}
//Handles achievements
else if(button == this.buttonAchievements){
2015-08-28 21:17:09 +02:00
mc.displayGuiScreen(new GuiAAAchievements(this, mc.thePlayer.getStatFileWriter()));
}
else if(button == this.buttonForward){
BookletUtils.handleNextPage(this);
2015-08-28 21:17:09 +02:00
}
else if(button == this.buttonBackward){
BookletUtils.handlePreviousPage(this);
2015-08-28 21:17:09 +02:00
}
//Handles gonig from page to chapter or from chapter to index
else if(button == this.buttonPreviousScreen){
if(this.currentChapter != null){
BookletUtils.openIndexEntry(this, this.currentIndexEntry, this.pageOpenInIndex, true);
}
else{
BookletUtils.openIndexEntry(this, null, 1, true);
2015-08-28 21:17:09 +02:00
}
}
2015-11-16 19:57:46 +01:00
//Handles Bookmark button
else if(button instanceof BookletUtils.BookmarkButton){
((BookletUtils.BookmarkButton)button).onPressed();
}
else{
BookletUtils.handleChapterButtonClick(this, button);
2015-08-28 21:17:09 +02:00
}
}
2015-10-03 10:19:40 +02:00
@SuppressWarnings("unchecked")
@Override
public void initGui(){
this.guiLeft = (this.width-this.xSize)/2;
this.guiTop = (this.height-this.ySize)/2;
this.buttonForward = new BookletUtils.TexturedButton(0, this.guiLeft+this.xSize-26, this.guiTop+this.ySize+1, 164, 0, 18, 10);
2015-10-03 10:19:40 +02:00
this.buttonList.add(this.buttonForward);
this.buttonBackward = new BookletUtils.TexturedButton(1, this.guiLeft+8, this.guiTop+this.ySize+1, 146, 0, 18, 10);
2015-10-03 10:19:40 +02:00
this.buttonList.add(this.buttonBackward);
this.buttonPreviousScreen = new BookletUtils.TexturedButton(2, this.guiLeft+this.xSize/2-7, this.guiTop+this.ySize+1, 182, 0, 15, 10);
2015-10-03 10:19:40 +02:00
this.buttonList.add(this.buttonPreviousScreen);
this.buttonPreviouslyOpenedGui = new BookletUtils.TexturedButton(3, this.guiLeft-4, this.guiTop+this.ySize+15, 245, 44, 11, 15);
2015-10-03 10:19:40 +02:00
this.buttonList.add(this.buttonPreviouslyOpenedGui);
this.buttonUpdate = new BookletUtils.TexturedButton(4, this.guiLeft-11, this.guiTop-11, 245, 0, 11, 11);
this.buttonUpdate.visible = UpdateChecker.needsUpdateNotify;
2015-10-03 10:19:40 +02:00
this.buttonList.add(this.buttonUpdate);
this.buttonTwitter = new BookletUtils.TexturedButton(5, this.guiLeft, this.guiTop, 213, 0, 8, 8);
2015-10-03 10:19:40 +02:00
this.buttonList.add(this.buttonTwitter);
this.buttonForum = new BookletUtils.TexturedButton(6, this.guiLeft, this.guiTop+10, 221, 0, 8, 8);
2015-10-03 10:19:40 +02:00
this.buttonList.add(this.buttonForum);
this.buttonAchievements = new BookletUtils.TexturedButton(7, this.guiLeft+138, this.guiTop, 205, 0, 8, 8);
2015-10-03 10:19:40 +02:00
this.buttonList.add(this.buttonAchievements);
this.buttonConfig = new BookletUtils.TexturedButton(8, this.guiLeft+138, this.guiTop+10, 197, 0, 8, 8);
2015-10-03 10:19:40 +02:00
this.buttonList.add(this.buttonConfig);
for(int i = 0; i < this.chapterButtons.length; i++){
this.chapterButtons[i] = new BookletUtils.IndexButton(9+i, guiLeft+15, guiTop+10+(i*12), 115, 10, "", this);
2015-10-03 10:19:40 +02:00
this.buttonList.add(this.chapterButtons[i]);
}
2015-11-16 19:57:46 +01:00
for(int i = 0; i < this.bookmarkButtons.length; i++){
int x = this.guiLeft+xSize/2-(this.bookmarkButtons.length/2*16)+(i*16);
this.bookmarkButtons[i] = new BookletUtils.BookmarkButton(this.chapterButtons[this.chapterButtons.length-1].id+1+i, x, this.guiTop+this.ySize+13, this);
2015-11-16 19:57:46 +01:00
this.buttonList.add(this.bookmarkButtons[i]);
}
this.searchField = new GuiTextField(this.fontRendererObj, guiLeft+148, guiTop+162, 66, 10);
2015-10-03 10:19:40 +02:00
this.searchField.setMaxStringLength(30);
this.searchField.setEnableBackgroundDrawing(false);
this.searchField.setCanLoseFocus(false);
2015-10-03 10:19:40 +02:00
this.currentPage = null;
this.currentChapter = null;
this.currentIndexEntry = null;
2015-11-24 17:50:27 +01:00
if(this.tryOpenMainPage && !PersistentClientData.getBoolean("BookAlreadyOpened")){
BookletUtils.openIndexEntry(this, InitBooklet.chapterIntro.entry, 1, true);
BookletUtils.openChapter(this, InitBooklet.chapterIntro, null);
2015-10-03 10:19:40 +02:00
PersistentClientData.setBoolean("BookAlreadyOpened", true);
}
else{
PersistentClientData.openLastBookPage(this);
}
}
@Override
public void updateScreen(){
super.updateScreen();
this.searchField.updateCursorCounter();
if(this.currentIndexEntry != null && this.currentChapter != null && this.currentPage != null){
this.currentPage.updateScreen(this.ticksElapsed);
}
boolean buttonThere = UpdateChecker.needsUpdateNotify;
2015-10-03 10:19:40 +02:00
this.buttonUpdate.visible = buttonThere;
if(buttonThere){
if(this.ticksElapsed%8 == 0){
BookletUtils.TexturedButton button = (BookletUtils.TexturedButton)this.buttonUpdate;
2015-10-03 10:19:40 +02:00
button.setTexturePos(245, button.texturePosY == 0 ? 22 : 0);
}
}
this.ticksElapsed++;
}
@Override
public void onGuiClosed(){
2015-11-24 17:50:27 +01:00
if(this.saveOnClose){
PersistentClientData.saveBookPage(this);
}
2015-10-03 10:19:40 +02:00
}
@Override
public boolean doesGuiPauseGame(){
return false;
}
2015-08-28 21:17:09 +02:00
}