ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/BookletPage.java

193 lines
5.6 KiB
Java
Raw Normal View History

2016-01-05 14:57:50 +01:00
/*
2017-01-01 16:23:26 +01:00
* This file ("BookletPage.java") is part of the Actually Additions mod for Minecraft.
2016-01-05 14:57:50 +01:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2016-01-05 14:57:50 +01:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2016-01-05 14:57:50 +01:00
*/
package de.ellpeck.actuallyadditions.mod.booklet.page;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
2016-11-10 21:07:15 +01:00
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
2016-01-05 14:57:50 +01:00
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
2017-02-14 20:48:01 +01:00
import net.minecraft.block.Block;
2016-11-10 21:07:15 +01:00
import net.minecraft.client.gui.GuiButton;
import net.minecraft.item.ItemStack;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
2016-11-10 22:06:58 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2016-01-05 14:57:50 +01:00
2017-02-14 20:48:01 +01:00
import java.util.*;
2016-01-05 14:57:50 +01:00
public class BookletPage implements IBookletPage{
protected final HashMap<String, String> textReplacements = new HashMap<String, String>();
protected final int localizationKey;
2016-11-22 22:54:35 +01:00
private final int priority;
2016-11-11 18:55:32 +01:00
private final List<ItemStack> itemsForPage = new ArrayList<ItemStack>();
private final List<FluidStack> fluidsForPage = new ArrayList<FluidStack>();
protected IBookletChapter chapter;
protected boolean hasNoText;
public BookletPage(int localizationKey){
2016-11-22 22:54:35 +01:00
this(localizationKey, 0);
}
public BookletPage(int localizationKey, int priority){
2016-01-05 14:57:50 +01:00
this.localizationKey = localizationKey;
2016-11-22 22:54:35 +01:00
this.priority = priority;
2016-01-05 14:57:50 +01:00
}
@Override
2016-11-11 18:55:32 +01:00
public void getItemStacksForPage(List<ItemStack> list){
list.addAll(this.itemsForPage);
}
@Override
2016-11-11 18:55:32 +01:00
public void getFluidStacksForPage(List<FluidStack> list){
list.addAll(this.fluidsForPage);
2016-01-05 14:57:50 +01:00
}
@Override
public IBookletChapter getChapter(){
return this.chapter;
}
@Override
public void setChapter(IBookletChapter chapter){
this.chapter = chapter;
}
@Override
public String getInfoText(){
2016-01-05 14:57:50 +01:00
if(this.hasNoText){
return null;
}
String base = StringUtil.localize("booklet."+ModUtil.MOD_ID+".chapter."+this.chapter.getIdentifier()+".text."+this.localizationKey);
2016-03-18 23:47:22 +01:00
base = base.replaceAll("<imp>", TextFormatting.DARK_GREEN+"");
base = base.replaceAll("<item>", TextFormatting.BLUE+"");
base = base.replaceAll("<r>", TextFormatting.BLACK+"");
2016-01-05 14:57:50 +01:00
base = base.replaceAll("<n>", "\n");
2016-03-18 23:47:22 +01:00
base = base.replaceAll("<i>", TextFormatting.ITALIC+"");
base = base.replaceAll("<tifisgrin>", TextFormatting.DARK_RED+""+TextFormatting.UNDERLINE); //This is fucking important so go read it now
2016-01-05 14:57:50 +01:00
2016-08-02 01:06:21 +02:00
for(Map.Entry<String, String> entry : this.textReplacements.entrySet()){
base = base.replaceAll(entry.getKey(), entry.getValue());
2016-01-05 14:57:50 +01:00
}
return base;
}
2016-11-10 21:07:15 +01:00
@Override
2016-11-10 22:06:58 +01:00
@SideOnly(Side.CLIENT)
2016-11-10 21:07:15 +01:00
public void mouseClicked(GuiBookletBase gui, int mouseX, int mouseY, int mouseButton){
}
@Override
2016-11-10 22:06:58 +01:00
@SideOnly(Side.CLIENT)
2016-11-10 21:07:15 +01:00
public void mouseReleased(GuiBookletBase gui, int mouseX, int mouseY, int state){
}
@Override
2016-11-10 22:06:58 +01:00
@SideOnly(Side.CLIENT)
2016-11-10 21:07:15 +01:00
public void mouseClickMove(GuiBookletBase gui, int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick){
}
@Override
2016-11-10 22:06:58 +01:00
@SideOnly(Side.CLIENT)
2016-11-10 21:07:15 +01:00
public void actionPerformed(GuiBookletBase gui, GuiButton button){
}
@Override
2016-11-10 22:06:58 +01:00
@SideOnly(Side.CLIENT)
public void initGui(GuiBookletBase gui, int startX, int startY){
2016-11-10 21:07:15 +01:00
}
@Override
2016-11-10 22:06:58 +01:00
@SideOnly(Side.CLIENT)
2016-11-11 18:55:32 +01:00
public void updateScreen(GuiBookletBase gui, int startX, int startY, int pageTimer){
2016-11-10 21:07:15 +01:00
}
@Override
2016-11-10 22:06:58 +01:00
@SideOnly(Side.CLIENT)
public void drawScreenPre(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks){
2016-11-10 21:07:15 +01:00
}
2016-11-10 22:06:58 +01:00
@Override
@SideOnly(Side.CLIENT)
public void drawScreenPost(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks){
}
@Override
public boolean shouldBeOnLeftSide(){
2016-11-11 18:55:32 +01:00
return (this.chapter.getPageIndex(this)+1)%2 != 0;
2016-11-10 22:06:58 +01:00
}
@Override
public String getIdentifier(){
return this.chapter.getIdentifier()+"."+this.chapter.getPageIndex(this);
}
@Override
public String getWebLink(){
return "http://ellpeck.de/actaddmanual#"+this.chapter.getIdentifier();
}
2016-11-10 21:07:15 +01:00
public BookletPage setNoText(){
this.hasNoText = true;
return this;
}
public BookletPage addFluidToPage(Fluid fluid){
this.fluidsForPage.add(new FluidStack(fluid, 1));
return this;
2016-02-01 17:49:55 +01:00
}
2017-02-14 20:48:01 +01:00
public BookletPage addItemsToPage(Block... blocks){
for(Block block : blocks){
this.addItemsToPage(new ItemStack(block));
}
return this;
}
public BookletPage addItemsToPage(ItemStack... stacks){
Collections.addAll(this.itemsForPage, stacks);
return this;
2016-02-01 17:49:55 +01:00
}
2016-11-10 21:07:15 +01:00
@Override
2016-11-10 21:07:15 +01:00
public BookletPage addTextReplacement(String key, String value){
this.textReplacements.put(key, value);
return this;
}
@Override
2016-11-10 21:07:15 +01:00
public BookletPage addTextReplacement(String key, float value){
return this.addTextReplacement(key, Float.toString(value));
}
@Override
public BookletPage addTextReplacement(String key, int value){
return this.addTextReplacement(key, Integer.toString(value));
}
2016-11-22 22:54:35 +01:00
@Override
public int getSortingPriority(){
return this.priority;
}
}