mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Added bookmarks and store page and bookmarks on close
This commit is contained in:
parent
0327ee9a26
commit
19cfcfa1c1
9 changed files with 228 additions and 5 deletions
|
@ -56,4 +56,6 @@ public interface IBookletPage{
|
|||
void drawScreenPost(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks);
|
||||
|
||||
boolean shouldBeOnLeftSide();
|
||||
|
||||
String getIdentifier();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* This file ("BookmarkButton.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.button;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
|
||||
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiPage;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.misc.BookletUtils;
|
||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class BookmarkButton extends GuiButton{
|
||||
|
||||
private final GuiBooklet booklet;
|
||||
public IBookletPage assignedPage;
|
||||
|
||||
public BookmarkButton(int id, int x, int y, GuiBooklet booklet){
|
||||
super(id, x, y, 16, 16, "");
|
||||
this.booklet = booklet;
|
||||
}
|
||||
|
||||
public void onPressed(){
|
||||
if(this.assignedPage != null){
|
||||
if(GuiScreen.isShiftKeyDown()){
|
||||
this.assignedPage = null;
|
||||
}
|
||||
else{
|
||||
GuiPage gui = BookletUtils.createPageGui(this.booklet.previousScreen, this.booklet, this.assignedPage);
|
||||
Minecraft.getMinecraft().displayGuiScreen(gui);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(this.booklet instanceof GuiPage){
|
||||
this.assignedPage = ((GuiPage)this.booklet).pages[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft minecraft, int x, int y){
|
||||
if(this.visible){
|
||||
minecraft.getTextureManager().bindTexture(GuiBooklet.RES_LOC_GADGETS);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.hovered = x >= this.xPosition && y >= this.yPosition && x < this.xPosition+this.width && y < this.yPosition+this.height;
|
||||
int k = this.getHoverState(this.hovered);
|
||||
if(k == 0){
|
||||
k = 1;
|
||||
}
|
||||
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||
GlStateManager.blendFunc(770, 771);
|
||||
int renderHeight = 25;
|
||||
this.drawTexturedModalRect(this.xPosition, this.yPosition, 224+(this.assignedPage == null ? 0 : 16), 14-renderHeight+k*renderHeight, this.width, renderHeight);
|
||||
this.mouseDragged(minecraft, x, y);
|
||||
|
||||
if(this.assignedPage != null){
|
||||
ItemStack display = this.assignedPage.getChapter().getDisplayItemStack();
|
||||
if(display != null){
|
||||
GlStateManager.pushMatrix();
|
||||
AssetUtil.renderStackToGui(display, this.xPosition+2, this.yPosition+1, 0.725F);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHover(int mouseX, int mouseY){
|
||||
if(this.isMouseOver()){
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
if(this.assignedPage != null){
|
||||
IBookletChapter chapter = this.assignedPage.getChapter();
|
||||
|
||||
list.add(TextFormatting.GOLD+chapter.getLocalizedName()+", Page "+(chapter.getPageIndex(this.assignedPage)+1));
|
||||
list.add("Click to open");
|
||||
list.add(TextFormatting.ITALIC+"Shift-Click to remove");
|
||||
}
|
||||
else{
|
||||
list.add(TextFormatting.GOLD+"None");
|
||||
|
||||
if(this.booklet instanceof GuiPage){
|
||||
list.add("Click to save current page");
|
||||
}
|
||||
}
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
GuiUtils.drawHoveringText(list, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRendererObj);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,6 +12,9 @@ package de.ellpeck.actuallyadditions.mod.booklet.gui;
|
|||
|
||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.button.BookmarkButton;
|
||||
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
||||
import de.ellpeck.actuallyadditions.mod.data.PlayerData.PlayerSave;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.gui.TexturedButton;
|
||||
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
||||
|
@ -23,6 +26,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -41,6 +45,7 @@ public abstract class GuiBooklet extends GuiBookletBase{
|
|||
private GuiButton buttonLeft;
|
||||
private GuiButton buttonRight;
|
||||
private GuiButton buttonBack;
|
||||
private final BookmarkButton[] bookmarkButtons = new BookmarkButton[12];
|
||||
|
||||
public GuiTextField searchField;
|
||||
|
||||
|
@ -84,10 +89,41 @@ public abstract class GuiBooklet extends GuiBookletBase{
|
|||
this.searchField.setMaxStringLength(50);
|
||||
this.searchField.setEnableBackgroundDrawing(false);
|
||||
}
|
||||
|
||||
if(this.hasBookmarkButtons()){
|
||||
PlayerSave data = PlayerData.getDataFromPlayer(this.mc.thePlayer);
|
||||
for(int i = 0; i < this.bookmarkButtons.length; i++){
|
||||
this.bookmarkButtons[i] = new BookmarkButton(1337+i, this.guiLeft+12+i*16, this.guiTop+this.ySize, this);
|
||||
this.buttonList.add(this.bookmarkButtons[i]);
|
||||
|
||||
if(data.bookmarks[i] != null){
|
||||
this.bookmarkButtons[i].assignedPage = data.bookmarks[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed(){
|
||||
super.onGuiClosed();
|
||||
|
||||
PlayerSave data = PlayerData.getDataFromPlayer(this.mc.thePlayer);
|
||||
|
||||
for(int i = 0; i < this.bookmarkButtons.length; i++){
|
||||
data.bookmarks[i] = this.bookmarkButtons[i].assignedPage;
|
||||
}
|
||||
|
||||
data.lastOpenBooklet = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks){
|
||||
this.drawScreenPre(mouseX, mouseY, partialTicks);
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.drawScreenPost(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
public void drawScreenPre(int mouseX, int mouseY, float partialTicks){
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
this.mc.getTextureManager().bindTexture(RES_LOC_GUI);
|
||||
drawModalRectWithCustomSizedTexture(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize, 512, 512);
|
||||
|
@ -107,8 +143,14 @@ public abstract class GuiBooklet extends GuiBookletBase{
|
|||
|
||||
this.fontRendererObj.setUnicodeFlag(unicodeBefore);
|
||||
}
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
public void drawScreenPost(int mouseX, int mouseY, float partialTicks){
|
||||
if(this.hasBookmarkButtons()){
|
||||
for(BookmarkButton button : this.bookmarkButtons){
|
||||
button.drawHover(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -162,6 +204,10 @@ public abstract class GuiBooklet extends GuiBookletBase{
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean hasBookmarkButtons(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onSearchBarChanged(String searchBarText){
|
||||
GuiBookletBase parent = !(this instanceof GuiEntry) ? this : this.parentPage;
|
||||
this.mc.displayGuiScreen(new GuiEntry(this.previousScreen, parent, ActuallyAdditionsAPI.allAndSearch, 0, searchBarText, true));
|
||||
|
@ -178,6 +224,12 @@ public abstract class GuiBooklet extends GuiBookletBase{
|
|||
else if(this.hasBackButton() && button == this.buttonBack){
|
||||
this.onBackButtonPressed();
|
||||
}
|
||||
else if(this.hasBookmarkButtons() && button instanceof BookmarkButton){
|
||||
int index = ArrayUtils.indexOf(this.bookmarkButtons, button);
|
||||
if(index >= 0){
|
||||
this.bookmarkButtons[index].onPressed();
|
||||
}
|
||||
}
|
||||
else{
|
||||
super.actionPerformed(button);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.minecraft.client.gui.GuiButton;
|
|||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
@ -116,8 +117,8 @@ public class GuiPage extends GuiBooklet{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks){
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
public void drawScreenPre(int mouseX, int mouseY, float partialTicks){
|
||||
super.drawScreenPre(mouseX, mouseY, partialTicks);
|
||||
|
||||
for(int i = 0; i < this.pages.length; i++){
|
||||
IBookletPage page = this.pages[i];
|
||||
|
@ -129,6 +130,11 @@ public class GuiPage extends GuiBooklet{
|
|||
for(ItemDisplay display : this.itemDisplays){
|
||||
display.drawPre();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreenPost(int mouseX, int mouseY, float partialTicks){
|
||||
super.drawScreenPost(mouseX, mouseY, partialTicks);
|
||||
|
||||
for(int i = 0; i < this.pages.length; i++){
|
||||
IBookletPage page = this.pages[i];
|
||||
|
|
|
@ -14,7 +14,6 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|||
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
|
||||
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
|
||||
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiEntry;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiMainPage;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiPage;
|
||||
|
@ -70,4 +69,17 @@ public final class BookletUtils{
|
|||
|
||||
return new GuiPage(previousScreen, parentPage, page1, page2);
|
||||
}
|
||||
|
||||
public static IBookletPage getBookletPageById(String id){
|
||||
if(id != null){
|
||||
for(IBookletChapter chapter : ActuallyAdditionsAPI.ALL_CHAPTERS){
|
||||
for(IBookletPage page : chapter.getAllPages()){
|
||||
if(id.equals(page.getIdentifier())){
|
||||
return page;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,6 +136,11 @@ public class BookletPage implements IBookletPage{
|
|||
return (this.chapter.getPageIndex(this)+1)%2 != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier(){
|
||||
return this.chapter.getIdentifier()+"."+this.chapter.getPageIndex(this);
|
||||
}
|
||||
|
||||
public BookletPage setNoText(){
|
||||
this.hasNoText = true;
|
||||
return this;
|
||||
|
|
|
@ -10,8 +10,15 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.data;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.misc.BookletUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
@ -44,6 +51,11 @@ public final class PlayerData{
|
|||
public boolean displayTesla;
|
||||
public boolean bookGottenAlready;
|
||||
|
||||
public IBookletPage[] bookmarks = new IBookletPage[12];
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public GuiBooklet lastOpenBooklet;
|
||||
|
||||
public PlayerSave(UUID id){
|
||||
this.id = id;
|
||||
}
|
||||
|
@ -51,11 +63,26 @@ public final class PlayerData{
|
|||
public void readFromNBT(NBTTagCompound compound){
|
||||
this.displayTesla = compound.getBoolean("DisplayTesla");
|
||||
this.bookGottenAlready = compound.getBoolean("BookGotten");
|
||||
|
||||
NBTTagList bookmarks = compound.getTagList("Bookmarks", 8);
|
||||
for(int i = 0; i < bookmarks.tagCount(); i++){
|
||||
String strg = bookmarks.getStringTagAt(i);
|
||||
if(strg != null && !strg.isEmpty()){
|
||||
IBookletPage page = BookletUtils.getBookletPageById(strg);
|
||||
this.bookmarks[i] = page;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound){
|
||||
compound.setBoolean("DisplayTesla", this.displayTesla);
|
||||
compound.setBoolean("BookGotten", this.bookGottenAlready);
|
||||
|
||||
NBTTagList bookmarks = new NBTTagList();
|
||||
for(IBookletPage bookmark : this.bookmarks){
|
||||
bookmarks.appendTag(new NBTTagString(bookmark == null ? "" : bookmark.getIdentifier()));
|
||||
}
|
||||
compound.setTag("Bookmarks", bookmarks);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
|||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiMainPage;
|
||||
import de.ellpeck.actuallyadditions.mod.booklet.misc.BookletUtils;
|
||||
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.gui.*;
|
||||
import de.ellpeck.actuallyadditions.mod.items.ItemBooklet;
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
|
||||
|
@ -177,7 +178,13 @@ public class GuiHandler implements IGuiHandler{
|
|||
return gui;
|
||||
}
|
||||
else{
|
||||
return new GuiMainPage(null);
|
||||
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
|
||||
if(data.lastOpenBooklet != null){
|
||||
return data.lastOpenBooklet;
|
||||
}
|
||||
else{
|
||||
return new GuiMainPage(null);
|
||||
}
|
||||
}
|
||||
case DIRECTIONAL_BREAKER:
|
||||
return new GuiDirectionalBreaker(player.inventory, tile);
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 6.4 KiB |
Loading…
Reference in a new issue