When an item that is used in a crafting recipe has its own page, clicking on the item will open that page

This commit is contained in:
Ellpeck 2015-08-29 17:32:39 +02:00
parent 6a2af50620
commit 4e4fc76f2c
7 changed files with 95 additions and 13 deletions

View file

@ -28,6 +28,7 @@ import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@SideOnly(Side.CLIENT)
public class GuiBooklet extends GuiScreen{
@ -72,7 +73,7 @@ public class GuiBooklet extends GuiScreen{
if(key != 1 && this.searchField.isFocused()){
this.searchField.textboxKeyTyped(theChar, key);
if(this.currentIndexEntry == InitBooklet.allAndSearch){
if(this.currentIndexEntry instanceof BookletEntryAllSearch){
BookletEntryAllSearch currentEntry = (BookletEntryAllSearch)this.currentIndexEntry;
if(this.searchField.getText() != null && !this.searchField.getText().isEmpty()){
currentEntry.chapters.clear();
@ -122,7 +123,6 @@ public class GuiBooklet extends GuiScreen{
this.searchField = new GuiTextField(this.unicodeRenderer, guiLeft+148, guiTop+162, 66, 10);
this.searchField.setMaxStringLength(30);
this.searchField.setEnableBackgroundDrawing(false);
this.searchField.setVisible(false);
this.currentPage = null;
this.currentChapter = null;
@ -140,13 +140,17 @@ public class GuiBooklet extends GuiScreen{
super.renderToolTip(stack, x, y);
}
public void drawHoveringText(List list, int x, int y){
super.func_146283_a(list, x, y);
}
@Override
public void drawScreen(int x, int y, float f){
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(resLoc);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
if(this.currentIndexEntry == InitBooklet.allAndSearch && this.currentChapter == null){
if(this.currentIndexEntry instanceof BookletEntryAllSearch && this.currentChapter == null){
this.drawTexturedModalRect(this.guiLeft+146, this.guiTop+160, 146, 80, 70, 14);
}
@ -254,7 +258,8 @@ public class GuiBooklet extends GuiScreen{
if(this.currentIndexEntry != null){
if(this.currentChapter == null){
if(actualButton < this.currentIndexEntry.chapters.size()){
this.openChapter(currentIndexEntry.chapters.get(actualButton+(12*this.pageOpenInIndex-12)));
BookletChapter chap = currentIndexEntry.chapters.get(actualButton+(12*this.pageOpenInIndex-12));
this.openChapter(chap, chap.pages[0]);
}
}
}
@ -278,10 +283,10 @@ public class GuiBooklet extends GuiScreen{
@SuppressWarnings("unchecked")
private void openIndexEntry(BookletIndexEntry entry, int page, boolean resetTextField){
if(resetTextField){
this.searchField.setVisible(entry == InitBooklet.allAndSearch);
this.searchField.setFocused(entry == InitBooklet.allAndSearch);
this.searchField.setVisible(entry instanceof BookletEntryAllSearch);
this.searchField.setFocused(entry instanceof BookletEntryAllSearch);
this.searchField.setText("");
if(entry == InitBooklet.allAndSearch){
if(entry instanceof BookletEntryAllSearch){
entry.chapters = (ArrayList<BookletChapter>)((BookletEntryAllSearch)entry).allChapters.clone();
}
}
@ -316,7 +321,7 @@ public class GuiBooklet extends GuiScreen{
}
}
private void openChapter(BookletChapter chapter){
public void openChapter(BookletChapter chapter, IBookletPage page){
if(chapter == null) return;
this.searchField.setVisible(false);
@ -324,9 +329,9 @@ public class GuiBooklet extends GuiScreen{
this.searchField.setText("");
this.currentChapter = chapter;
this.currentPage = currentChapter.pages[0];
this.currentPage = page != null && this.hasPage(chapter, page) ? page : chapter.pages[0];
this.getButton(BUTTON_FORWARD_ID).visible = this.getNextPage(chapter, currentPage) != null;
this.getButton(BUTTON_FORWARD_ID).visible = this.getNextPage(chapter, this.currentPage) != null;
this.getButton(BUTTON_BACK_ID).visible = false;
for(int i = 0; i < 12; i++){
@ -335,6 +340,15 @@ public class GuiBooklet extends GuiScreen{
}
}
private boolean hasPage(BookletChapter chapter, IBookletPage page){
for(IBookletPage aPage : chapter.pages){
if(aPage == page){
return true;
}
}
return false;
}
private static class IndexButton extends GuiButton{
private FontRenderer renderer;

View file

@ -10,15 +10,21 @@
package ellpeck.actuallyadditions.inventory.gui.booklet;
import net.minecraft.item.ItemStack;
public interface IBookletPage{
int getID();
void setChapter(BookletChapter chapter);
BookletChapter getChapter();
String getText();
void renderPre(GuiBooklet gui, int mouseX, int mouseY);
void render(GuiBooklet gui, int mouseX, int mouseY);
ItemStack getItemStackForPage();
}

View file

@ -22,6 +22,7 @@ import java.util.ArrayList;
public class InitBooklet{
public static ArrayList<BookletIndexEntry> entries = new ArrayList<BookletIndexEntry>();
public static ArrayList<IBookletPage> pagesWithItemStackData = new ArrayList<IBookletPage>();
public static BookletIndexEntry entryFunctionalNonRF = new BookletIndexEntry("functionalNoRF");
public static BookletIndexEntry entryMisc = new BookletIndexEntry("misc");

View file

@ -32,6 +32,12 @@ public class PageCrafting extends PageText{
public PageCrafting(int id, IRecipe recipe){
super(id);
this.recipe = recipe;
InitBooklet.pagesWithItemStackData.add(this);
}
@Override
public ItemStack getItemStackForPage(){
return this.recipe == null ? null : this.recipe.getRecipeOutput();
}
@Override
@ -109,7 +115,7 @@ public class PageCrafting extends PageText{
}
else{
if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){
gui.renderToolTip(stack, mouseX, mouseY);
this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, true);
}
}
}

View file

@ -24,6 +24,7 @@ public class PageCrusherRecipe extends PageText{
public PageCrusherRecipe(int id, ItemStack input){
super(id);
this.input = input;
InitBooklet.pagesWithItemStackData.add(this);
}
@Override
@ -34,6 +35,11 @@ public class PageCrusherRecipe extends PageText{
}
}
@Override
public ItemStack getItemStackForPage(){
return CrusherRecipeManualRegistry.getOutput(this.input, false);
}
@SuppressWarnings("unchecked")
@Override
public void render(GuiBooklet gui, int mouseX, int mouseY){
@ -66,7 +72,7 @@ public class PageCrusherRecipe extends PageText{
}
else{
if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){
gui.renderToolTip(stack, mouseX, mouseY);
this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, j == 0);
}
}
}

View file

@ -26,6 +26,12 @@ public class PageFurnace extends PageText{
public PageFurnace(int id, ItemStack result){
super(id);
this.result = result;
InitBooklet.pagesWithItemStackData.add(this);
}
@Override
public ItemStack getItemStackForPage(){
return this.result;
}
@Override
@ -61,7 +67,7 @@ public class PageFurnace extends PageText{
}
else{
if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){
gui.renderToolTip(stack, mouseX, mouseY);
this.renderTooltipAndTransfer(gui, stack, mouseX, mouseY, x == 0);
}
}
}

View file

@ -12,6 +12,10 @@ package ellpeck.actuallyadditions.inventory.gui.booklet;
import ellpeck.actuallyadditions.util.ModUtil;
import ellpeck.actuallyadditions.util.StringUtil;
import net.minecraft.item.ItemStack;
import org.lwjgl.input.Mouse;
import java.util.List;
public class PageText implements IBookletPage{
@ -32,6 +36,11 @@ public class PageText implements IBookletPage{
this.chapter = chapter;
}
@Override
public BookletChapter getChapter(){
return this.chapter;
}
@Override
public String getText(){
return StringUtil.localize("booklet."+ModUtil.MOD_ID_LOWER+".chapter."+this.chapter.getUnlocalizedName()+".text."+this.id);
@ -46,4 +55,38 @@ public class PageText implements IBookletPage{
public void render(GuiBooklet gui, int mouseX, int mouseY){
gui.unicodeRenderer.drawSplitString(gui.currentPage.getText(), gui.guiLeft+14, gui.guiTop+11, 115, 0);
}
@Override
public ItemStack getItemStackForPage(){
return null;
}
@SuppressWarnings("unchecked")
protected void renderTooltipAndTransfer(GuiBooklet gui, ItemStack stack, int x, int y, boolean checkAndTransfer){
List list = stack.getTooltip(gui.mc.thePlayer, gui.mc.gameSettings.advancedItemTooltips);
for(int k = 0; k < list.size(); ++k){
if(k == 0){
list.set(k, stack.getRarity().rarityColor+(String)list.get(k));
}
else{
list.set(k, StringUtil.GRAY+list.get(k));
}
}
if(checkAndTransfer){
for(IBookletPage page : InitBooklet.pagesWithItemStackData){
if(page.getItemStackForPage() != null && page.getItemStackForPage().isItemEqual(stack)){
list.add(StringUtil.ORANGE+"Click to see Recipe!");
if(Mouse.isButtonDown(0)){
gui.openChapter(page.getChapter(), page);
}
break;
}
}
}
gui.drawHoveringText(list, x, y);
}
}