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

191 lines
5.6 KiB
Java
Raw Normal View History

package de.ellpeck.actuallyadditions.booklet.page;
2016-01-05 14:57:50 +01:00
2019-05-02 09:10:29 +02:00
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.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;
2020-09-21 19:59:08 +02:00
import net.minecraftforge.fml.relauncher.OnlyIn;
2016-01-05 14:57:50 +01:00
2019-05-02 09:10:29 +02:00
public class BookletPage implements IBookletPage {
2019-02-27 19:53:05 +01:00
protected final HashMap<String, String> textReplacements = new HashMap<>();
protected final int localizationKey;
2016-11-22 22:54:35 +01:00
private final int priority;
2019-02-27 19:53:05 +01:00
private final List<ItemStack> itemsForPage = new ArrayList<>();
private final List<FluidStack> fluidsForPage = new ArrayList<>();
protected IBookletChapter chapter;
protected boolean hasNoText;
2019-05-02 09:10:29 +02:00
public BookletPage(int localizationKey) {
2016-11-22 22:54:35 +01:00
this(localizationKey, 0);
}
2019-05-02 09:10:29 +02:00
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
2019-05-02 09:10:29 +02:00
public void getItemStacksForPage(List<ItemStack> list) {
2016-11-11 18:55:32 +01:00
list.addAll(this.itemsForPage);
}
@Override
2019-05-02 09:10:29 +02:00
public void getFluidStacksForPage(List<FluidStack> list) {
2016-11-11 18:55:32 +01:00
list.addAll(this.fluidsForPage);
2016-01-05 14:57:50 +01:00
}
@Override
2019-05-02 09:10:29 +02:00
public IBookletChapter getChapter() {
return this.chapter;
}
@Override
2019-05-02 09:10:29 +02:00
public void setChapter(IBookletChapter chapter) {
this.chapter = chapter;
}
@Override
2020-09-21 19:59:08 +02:00
@OnlyIn(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public String getInfoText() {
if (this.hasNoText) { return null; }
2016-01-05 14:57:50 +01:00
2017-02-18 00:54:58 +01:00
String base = StringUtil.localize(this.getLocalizationKey());
2019-05-02 09:10:29 +02: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");
2019-05-02 09:10:29 +02: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
2019-05-02 09:10:29 +02:00
for (Map.Entry<String, String> entry : this.textReplacements.entrySet()) {
2016-08-02 01:06:21 +02:00
base = base.replaceAll(entry.getKey(), entry.getValue());
2016-01-05 14:57:50 +01:00
}
return base;
}
2020-09-21 19:59:08 +02:00
@OnlyIn(Side.CLIENT)
2019-05-02 09:10:29 +02:00
protected String getLocalizationKey() {
return "booklet." + ActuallyAdditions.MODID + ".chapter." + this.chapter.getIdentifier() + ".text." + this.localizationKey;
2017-02-18 00:54:58 +01:00
}
2016-11-10 21:07:15 +01:00
@Override
2020-09-21 19:59:08 +02:00
@OnlyIn(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public void mouseClicked(GuiBookletBase gui, int mouseX, int mouseY, int mouseButton) {
2016-11-10 21:07:15 +01:00
}
@Override
2020-09-21 19:59:08 +02:00
@OnlyIn(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public void mouseReleased(GuiBookletBase gui, int mouseX, int mouseY, int state) {
2016-11-10 21:07:15 +01:00
}
@Override
2020-09-21 19:59:08 +02:00
@OnlyIn(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public void mouseClickMove(GuiBookletBase gui, int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
2016-11-10 21:07:15 +01:00
}
@Override
2020-09-21 19:59:08 +02:00
@OnlyIn(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public void actionPerformed(GuiBookletBase gui, GuiButton button) {
2016-11-10 21:07:15 +01:00
}
@Override
2020-09-21 19:59:08 +02:00
@OnlyIn(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public void initGui(GuiBookletBase gui, int startX, int startY) {
2016-11-10 21:07:15 +01:00
}
@Override
2020-09-21 19:59:08 +02:00
@OnlyIn(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public void updateScreen(GuiBookletBase gui, int startX, int startY, int pageTimer) {
2016-11-10 21:07:15 +01:00
}
@Override
2020-09-21 19:59:08 +02:00
@OnlyIn(Side.CLIENT)
2019-05-02 09:10:29 +02:00
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
2020-09-21 19:59:08 +02:00
@OnlyIn(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public void drawScreenPost(GuiBookletBase gui, int startX, int startY, int mouseX, int mouseY, float partialTicks) {
2016-11-10 22:06:58 +01:00
}
@Override
2019-05-02 09:10:29 +02:00
public boolean shouldBeOnLeftSide() {
return (this.chapter.getPageIndex(this) + 1) % 2 != 0;
2016-11-10 22:06:58 +01:00
}
@Override
2019-05-02 09:10:29 +02:00
public String getIdentifier() {
return this.chapter.getIdentifier() + "." + this.chapter.getPageIndex(this);
}
@Override
2019-05-02 09:10:29 +02:00
public String getWebLink() {
return "http://ellpeck.de/actaddmanual#" + this.chapter.getIdentifier();
}
2019-05-02 09:10:29 +02:00
public BookletPage setNoText() {
2016-11-10 21:07:15 +01:00
this.hasNoText = true;
return this;
}
2019-05-02 09:10:29 +02:00
public BookletPage addFluidToPage(Fluid fluid) {
this.fluidsForPage.add(new FluidStack(fluid, 1));
return this;
2016-02-01 17:49:55 +01:00
}
2019-05-02 09:10:29 +02:00
public BookletPage addItemsToPage(Block... blocks) {
for (Block block : blocks) {
2017-02-14 20:48:01 +01:00
this.addItemsToPage(new ItemStack(block));
}
return this;
}
2019-05-02 09:10:29 +02:00
public BookletPage addItemsToPage(ItemStack... stacks) {
2017-02-14 20:48:01 +01:00
Collections.addAll(this.itemsForPage, stacks);
return this;
2016-02-01 17:49:55 +01:00
}
2016-11-10 21:07:15 +01:00
@Override
2019-05-02 09:10:29 +02:00
public BookletPage addTextReplacement(String key, String value) {
2016-11-10 21:07:15 +01:00
this.textReplacements.put(key, value);
return this;
}
@Override
2019-05-02 09:10:29 +02:00
public BookletPage addTextReplacement(String key, float value) {
2016-11-10 21:07:15 +01:00
return this.addTextReplacement(key, Float.toString(value));
}
@Override
2019-05-02 09:10:29 +02:00
public BookletPage addTextReplacement(String key, int value) {
return this.addTextReplacement(key, Integer.toString(value));
}
2016-11-22 22:54:35 +01:00
@Override
2019-05-02 09:10:29 +02:00
public int getSortingPriority() {
2016-11-22 22:54:35 +01:00
return this.priority;
}
}