B U T T O N S

This commit is contained in:
Ellpeck 2016-11-11 18:55:32 +01:00
parent 24e2a9e88d
commit 81584c2fb1
17 changed files with 234 additions and 48 deletions

View file

@ -26,5 +26,5 @@ public interface IBookletChapter{
String getIdentifier();
int getPageNum(IBookletPage page);
int getPageIndex(IBookletPage page);
}

View file

@ -21,9 +21,9 @@ import java.util.List;
public interface IBookletPage{
List<ItemStack> getItemStacksForPage();
void getItemStacksForPage(List<ItemStack> list);
List<FluidStack> getFluidStacksForPage();
void getFluidStacksForPage(List<FluidStack> list);
IBookletChapter getChapter();
@ -47,7 +47,7 @@ public interface IBookletPage{
void initGui(GuiBookletBase gui, int startX, int startY);
@SideOnly(Side.CLIENT)
void updateScreen(GuiBookletBase gui, int startX, int startY);
void updateScreen(GuiBookletBase gui, int startX, int startY, int pageTimer);
@SideOnly(Side.CLIENT)
void drawScreenPre(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks);

View file

@ -32,5 +32,5 @@ public abstract class GuiBookletBase extends GuiScreen{
public abstract int getSizeY();
public abstract void addItemRenderer(ItemStack renderedStack, int x, int y, float scale, boolean shouldTryTransfer);
public abstract void addOrModifyItemRenderer(ItemStack renderedStack, int x, int y, float scale, boolean shouldTryTransfer);
}

View file

@ -79,10 +79,12 @@ public final class InitBooklet{
for(IBookletPage page : chapter.getAllPages()){
pageCount++;
List<ItemStack> items = page.getItemStacksForPage();
List<FluidStack> fluids = page.getFluidStacksForPage();
List<ItemStack> items = new ArrayList<ItemStack>();
page.getItemStacksForPage(items);
List<FluidStack> fluids = new ArrayList<FluidStack>();
page.getFluidStacksForPage(fluids);
if((items != null && !items.isEmpty()) || (fluids != null && !items.isEmpty())){
if((items != null && !items.isEmpty()) || (fluids != null && !fluids.isEmpty())){
if(!ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA.contains(page)){
ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA.add(page);
infoCount++;

View file

@ -71,10 +71,10 @@ public class BookletChapter implements IBookletChapter{
}
@Override
public int getPageNum(IBookletPage page){
public int getPageIndex(IBookletPage page){
for(int i = 0; i < this.pages.length; i++){
if(this.pages[i] == page){
return i+1;
return i;
}
}
return -1;

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.booklet.gui;
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
import de.ellpeck.actuallyadditions.mod.inventory.gui.TexturedButton;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.client.gui.GuiButton;
@ -34,6 +35,10 @@ public abstract class GuiBooklet extends GuiBookletBase{
public GuiScreen previousScreen;
protected GuiBookletBase parentPage;
private GuiButton buttonLeft;
private GuiButton buttonRight;
private GuiButton buttonBack;
protected int xSize;
protected int ySize;
protected int guiLeft;
@ -53,6 +58,21 @@ public abstract class GuiBooklet extends GuiBookletBase{
this.guiLeft = (this.width-this.xSize)/2;
this.guiTop = (this.height-this.ySize)/2;
if(this.hasPageLeftButton()){
this.buttonLeft = new TexturedButton(RES_LOC_GADGETS, -2000, this.guiLeft-12, this.guiTop+this.ySize-8, 18, 54, 18, 10);
this.buttonList.add(this.buttonLeft);
}
if(this.hasPageRightButton()){
this.buttonRight = new TexturedButton(RES_LOC_GADGETS, -2001, this.guiLeft+this.xSize-6, this.guiTop+this.ySize-8, 0, 54, 18, 10);
this.buttonList.add(this.buttonRight);
}
if(this.hasBackButton()){
this.buttonBack = new TexturedButton(RES_LOC_GADGETS, -2002, this.guiLeft-12, this.guiTop-2, 36, 54, 18, 10);
this.buttonList.add(this.buttonBack);
}
}
@Override
@ -69,6 +89,46 @@ public abstract class GuiBooklet extends GuiBookletBase{
return false;
}
public boolean hasPageLeftButton(){
return false;
}
public void onPageLeftButtonPressed(){
}
public boolean hasPageRightButton(){
return false;
}
public void onPageRightButtonPressed(){
}
public boolean hasBackButton(){
return false;
}
public void onBackButtonPressed(){
}
@Override
protected void actionPerformed(GuiButton button) throws IOException{
if(this.hasPageLeftButton() && button == this.buttonLeft){
this.onPageLeftButtonPressed();
}
else if(this.hasPageRightButton() && button == this.buttonRight){
this.onPageRightButtonPressed();
}
else if(this.hasBackButton() && button == this.buttonBack){
this.onBackButtonPressed();
}
else{
super.actionPerformed(button);
}
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException{
if(this.previousScreen != null && keyCode == Keyboard.KEY_ESCAPE){

View file

@ -89,7 +89,17 @@ public class GuiEntry extends GuiBooklet{
}
@Override
public void addItemRenderer(ItemStack renderedStack, int x, int y, float scale, boolean shouldTryTransfer){
public void addOrModifyItemRenderer(ItemStack renderedStack, int x, int y, float scale, boolean shouldTryTransfer){
}
@Override
public boolean hasBackButton(){
return true;
}
@Override
public void onBackButtonPressed(){
this.mc.displayGuiScreen(this.parentPage);
}
}

View file

@ -62,7 +62,7 @@ public class GuiMainPage extends GuiBooklet{
}
@Override
public void addItemRenderer(ItemStack renderedStack, int x, int y, float scale, boolean shouldTryTransfer){
public void addOrModifyItemRenderer(ItemStack renderedStack, int x, int y, float scale, boolean shouldTryTransfer){
}
}

View file

@ -10,8 +10,10 @@
package de.ellpeck.actuallyadditions.mod.booklet.gui;
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.misc.BookletUtils;
import de.ellpeck.actuallyadditions.mod.booklet.page.ItemDisplay;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
@ -27,6 +29,7 @@ import java.util.List;
@SideOnly(Side.CLIENT)
public class GuiPage extends GuiBooklet{
private int pageTimer;
private final List<ItemDisplay> itemDisplays = new ArrayList<ItemDisplay>();
public final IBookletPage[] pages = new IBookletPage[2];
@ -87,8 +90,8 @@ public class GuiPage extends GuiBooklet{
@Override
public void initGui(){
super.initGui();
this.itemDisplays.clear();
super.initGui();
for(int i = 0; i < this.pages.length; i++){
IBookletPage page = this.pages[i];
@ -105,9 +108,11 @@ public class GuiPage extends GuiBooklet{
for(int i = 0; i < this.pages.length; i++){
IBookletPage page = this.pages[i];
if(page != null){
page.updateScreen(this, this.guiLeft+6+i*142, this.guiTop+7);
page.updateScreen(this, this.guiLeft+6+i*142, this.guiTop+7, this.pageTimer);
}
}
this.pageTimer++;
}
@Override
@ -138,7 +143,82 @@ public class GuiPage extends GuiBooklet{
}
@Override
public void addItemRenderer(ItemStack renderedStack, int x, int y, float scale, boolean shouldTryTransfer){
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;
}
}
this.itemDisplays.add(new ItemDisplay(this, x, y, scale, renderedStack, shouldTryTransfer));
}
@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;
return pageIndex+1 < pageAmount-1;
}
}
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(){
this.mc.displayGuiScreen(this.parentPage);
}
}

View file

@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.booklet.misc;
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;
@ -21,13 +22,15 @@ import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.List;
public final class BookletUtils{
public static IBookletPage findFirstPageForStack(ItemStack stack){
for(IBookletPage page : ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA){
List<ItemStack> stacks = page.getItemStacksForPage();
List<ItemStack> stacks = new ArrayList<ItemStack>();
page.getItemStacksForPage(stacks);
if(stacks != null && !stacks.isEmpty()){
for(ItemStack pageStack : stacks){
if(ItemUtil.areItemsEqual(pageStack, stack, true)){
@ -48,11 +51,11 @@ public final class BookletUtils{
return createPageGui(previousScreen, entry, page);
}
public static GuiPage createPageGui(GuiScreen previousScreen, GuiBooklet parentPage, IBookletPage page){
public static GuiPage createPageGui(GuiScreen previousScreen, GuiBookletBase parentPage, IBookletPage page){
IBookletChapter chapter = page.getChapter();
IBookletPage[] allPages = chapter.getAllPages();
int pageIndex = chapter.getPageNum(page)-1;
int pageIndex = chapter.getPageIndex(page);
IBookletPage page1;
IBookletPage page2;

View file

@ -32,8 +32,8 @@ public class BookletPage implements IBookletPage{
protected IBookletChapter chapter;
protected List<FluidStack> fluidsForPage = new ArrayList<FluidStack>();
protected List<ItemStack> itemsForPage = new ArrayList<ItemStack>();
private final List<ItemStack> itemsForPage = new ArrayList<ItemStack>();
private final List<FluidStack> fluidsForPage = new ArrayList<FluidStack>();
protected boolean hasNoText;
protected final HashMap<String, String> textReplacements = new HashMap<String, String>();
@ -44,13 +44,13 @@ public class BookletPage implements IBookletPage{
}
@Override
public List<ItemStack> getItemStacksForPage(){
return this.itemsForPage;
public void getItemStacksForPage(List<ItemStack> list){
list.addAll(this.itemsForPage);
}
@Override
public List<FluidStack> getFluidStacksForPage(){
return this.fluidsForPage;
public void getFluidStacksForPage(List<FluidStack> list){
list.addAll(this.fluidsForPage);
}
@Override
@ -115,7 +115,7 @@ public class BookletPage implements IBookletPage{
@Override
@SideOnly(Side.CLIENT)
public void updateScreen(GuiBookletBase gui, int startX, int startY){
public void updateScreen(GuiBookletBase gui, int startX, int startY, int pageTimer){
}
@ -133,7 +133,7 @@ public class BookletPage implements IBookletPage{
@Override
public boolean shouldBeOnLeftSide(){
return this.chapter.getPageNum(this)%2 != 0;
return (this.chapter.getPageIndex(this)+1)%2 != 0;
}
public BookletPage setNoText(){

View file

@ -24,17 +24,19 @@ import net.minecraft.init.SoundEvents;
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.List;
public class ItemDisplay{
private final GuiPage gui;
private final int x;
private final int y;
private final float scale;
public final int x;
public final int y;
public final float scale;
private final ItemStack stack;
public ItemStack stack;
private final IBookletPage page;
public ItemDisplay(GuiPage gui, int x, int y, float scale, ItemStack stack, boolean shouldTryTransfer){
@ -46,10 +48,12 @@ public class ItemDisplay{
this.page = shouldTryTransfer ? BookletUtils.findFirstPageForStack(stack) : null;
}
@SideOnly(Side.CLIENT)
public void drawPre(){
AssetUtil.renderStackToGui(this.stack, this.x, this.y, this.scale);
}
@SideOnly(Side.CLIENT)
public void drawPost(int mouseX, int mouseY){
if(this.isHovered(mouseX, mouseY)){
Minecraft mc = this.gui.mc;

View file

@ -32,6 +32,7 @@ import java.util.List;
public class PageCrafting extends BookletPage{
private int recipeAt;
private String recipeTypeLocKey;
private boolean isWildcard;
private final List<IRecipe> recipes;
@ -64,20 +65,38 @@ public class PageCrafting extends BookletPage{
}
@Override
public void initGui(GuiBookletBase gui, int startX, int startY){
super.initGui(gui, startX, startY);
@SideOnly(Side.CLIENT)
public void updateScreen(GuiBookletBase gui, int startX, int startY, int pageTimer){
super.updateScreen(gui, startX, startY, pageTimer);
if(pageTimer%20 == 0){
this.findRecipe(gui, startX, startY);
}
}
private void findRecipe(GuiBookletBase gui, int startX, int startY){
if(!this.recipes.isEmpty()){
IRecipe recipe = this.recipes.get(0);
IRecipe recipe = this.recipes.get(this.recipeAt);
if(recipe != null){
this.setupRecipe(gui, recipe, startX, startY);
}
this.recipeAt++;
if(this.recipeAt >= this.recipes.size()){
this.recipeAt = 0;
}
}
}
@Override
public List<ItemStack> getItemStacksForPage(){
List<ItemStack> stacks = super.getItemStacksForPage();
public void initGui(GuiBookletBase gui, int startX, int startY){
super.initGui(gui, startX, startY);
this.findRecipe(gui, startX, startY);
}
@Override
public void getItemStacksForPage(List<ItemStack> list){
super.getItemStacksForPage(list);
if(!this.recipes.isEmpty()){
for(IRecipe recipe : this.recipes){
@ -88,13 +107,11 @@ public class PageCrafting extends BookletPage{
if(this.isWildcard){
copy.setItemDamage(Util.WILDCARD);
}
stacks.add(copy);
list.add(copy);
}
}
}
}
return stacks;
}
private void setupRecipe(GuiBookletBase gui, IRecipe recipe, int startX, int startY){
@ -152,11 +169,11 @@ public class PageCrafting extends BookletPage{
copy.setItemDamage(0);
}
gui.addItemRenderer(copy, startX+6+x*18, startY+7+y*18, 1F, true);
gui.addOrModifyItemRenderer(copy, startX+6+x*18, startY+7+y*18, 1F, true);
}
}
}
gui.addItemRenderer(recipe.getRecipeOutput(), startX+100, startY+25, 1F, false);
gui.addOrModifyItemRenderer(recipe.getRecipeOutput(), startX+100, startY+25, 1F, false);
}
}

View file

@ -109,7 +109,7 @@ public class ItemBooklet extends ItemBase implements IHudDisplay{
IBookletPage page = BookletUtils.findFirstPageForStack(blockStack);
if(page != null){
String strg1 = page.getChapter().getLocalizedName();
String strg2 = "Page "+page.getChapter().getPageNum(page);
String strg2 = "Page "+(page.getChapter().getPageIndex(page)+1);
String strg3 = "Right-Click to open...";
AssetUtil.renderStackToGui(page.getChapter().getDisplayItemStack() != null ? page.getChapter().getDisplayItemStack() : new ItemStack(InitItems.itemBooklet), resolution.getScaledWidth()/2-10, height+41, 1F);

View file

@ -16,8 +16,11 @@ import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.BlankRecipeCategory;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class BookletRecipeCategory extends BlankRecipeCategory<BookletRecipeWrapper>{
@ -49,6 +52,9 @@ public class BookletRecipeCategory extends BlankRecipeCategory<BookletRecipeWrap
@Override
public void setRecipe(IRecipeLayout recipeLayout, BookletRecipeWrapper wrapper, IIngredients ingredients){
recipeLayout.getItemStacks().init(0, true, 70, -4);
recipeLayout.getItemStacks().set(0, wrapper.thePage.getItemStacksForPage());
List<ItemStack> list = new ArrayList<ItemStack>();
wrapper.thePage.getItemStacksForPage(list);
recipeLayout.getItemStacks().set(0, list);
}
}

View file

@ -21,7 +21,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fluids.FluidStack;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
public class BookletRecipeWrapper extends RecipeWrapperWithButton{
@ -34,11 +34,15 @@ public class BookletRecipeWrapper extends RecipeWrapperWithButton{
@Override
public void getIngredients(IIngredients ingredients){
ingredients.setInputs(ItemStack.class, this.thePage.getItemStacksForPage());
ingredients.setInputs(FluidStack.class, this.thePage.getFluidStacksForPage());
List<ItemStack> itemList = new ArrayList<ItemStack>();
this.thePage.getItemStacksForPage(itemList);
ingredients.setInputs(ItemStack.class, itemList);
ingredients.setOutputs(ItemStack.class, itemList);
ingredients.setOutputs(ItemStack.class, this.thePage.getItemStacksForPage());
ingredients.setOutputs(FluidStack.class, this.thePage.getFluidStacksForPage());
List<FluidStack> fluidList = new ArrayList<FluidStack>();
this.thePage.getFluidStacksForPage(fluidList);
ingredients.setInputs(FluidStack.class, fluidList);
ingredients.setOutputs(FluidStack.class, fluidList);
}
@Override
@ -56,7 +60,7 @@ public class BookletRecipeWrapper extends RecipeWrapperWithButton{
minecraft.fontRendererObj.drawString(text.get(i)+(i == maxLines-1 && text.size() > maxLines ? TextFormatting.RESET+""+TextFormatting.BLACK+"..." : ""), 0, 16+25+i*(minecraft.fontRendererObj.FONT_HEIGHT+1), 0, false);
}
minecraft.fontRendererObj.drawString(TextFormatting.ITALIC+chapter.getLocalizedName(), 25, 85, 0, false);
minecraft.fontRendererObj.drawString(TextFormatting.ITALIC+"Page "+chapter.getPageNum(this.thePage), 25, 95, 0, false);
minecraft.fontRendererObj.drawString(TextFormatting.ITALIC+"Page "+(chapter.getPageIndex(this.thePage)+1), 25, 95, 0, false);
super.drawInfo(minecraft, recipeWidth, recipeHeight, mouseX, mouseY);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB