2020-09-09 16:49:01 +02:00
|
|
|
package de.ellpeck.actuallyadditions.booklet.button;
|
2016-11-12 13:54:49 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-11-12 13:54:49 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
|
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
|
2020-09-09 16:48:43 +02:00
|
|
|
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
2020-09-09 16:49:01 +02:00
|
|
|
import de.ellpeck.actuallyadditions.booklet.gui.GuiBooklet;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.gui.GuiPage;
|
|
|
|
import de.ellpeck.actuallyadditions.booklet.misc.BookletUtils;
|
2020-09-09 16:48:43 +02:00
|
|
|
import de.ellpeck.actuallyadditions.common.util.AssetUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.StackUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.StringUtil;
|
2016-11-12 13:54:49 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public class BookmarkButton extends GuiButton {
|
2016-11-12 13:54:49 +01:00
|
|
|
|
|
|
|
private final GuiBooklet booklet;
|
|
|
|
public IBookletPage assignedPage;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public BookmarkButton(int id, int x, int y, GuiBooklet booklet) {
|
2016-11-12 13:54:49 +01:00
|
|
|
super(id, x, y, 16, 16, "");
|
|
|
|
this.booklet = booklet;
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public void onPressed() {
|
|
|
|
if (this.assignedPage != null) {
|
|
|
|
if (GuiScreen.isShiftKeyDown()) {
|
2016-11-12 13:54:49 +01:00
|
|
|
this.assignedPage = null;
|
2019-05-02 09:10:29 +02:00
|
|
|
} else if (!(this.booklet instanceof GuiPage) || ((GuiPage) this.booklet).pages[0] != this.assignedPage) {
|
2016-11-12 13:54:49 +01:00
|
|
|
GuiPage gui = BookletUtils.createPageGui(this.booklet.previousScreen, this.booklet, this.assignedPage);
|
|
|
|
Minecraft.getMinecraft().displayGuiScreen(gui);
|
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
|
|
|
if (this.booklet instanceof GuiPage) {
|
|
|
|
this.assignedPage = ((GuiPage) this.booklet).pages[0];
|
2016-11-12 13:54:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void drawButton(Minecraft minecraft, int x, int y, float f) {
|
|
|
|
if (this.visible) {
|
2016-11-12 13:54:49 +01:00
|
|
|
minecraft.getTextureManager().bindTexture(GuiBooklet.RES_LOC_GADGETS);
|
|
|
|
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
2019-05-02 09:10:29 +02:00
|
|
|
this.hovered = x >= this.x && y >= this.y && x < this.x + this.width && y < this.y + this.height;
|
2016-11-12 13:54:49 +01:00
|
|
|
int k = this.getHoverState(this.hovered);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (k == 0) {
|
2016-11-12 13:54:49 +01:00
|
|
|
k = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
GlStateManager.enableBlend();
|
|
|
|
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
|
|
|
GlStateManager.blendFunc(770, 771);
|
|
|
|
int renderHeight = 25;
|
2019-05-02 09:10:29 +02:00
|
|
|
this.drawTexturedModalRect(this.x, this.y, 224 + (this.assignedPage == null ? 0 : 16), 14 - renderHeight + k * renderHeight, this.width, renderHeight);
|
2016-11-12 13:54:49 +01:00
|
|
|
this.mouseDragged(minecraft, x, y);
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.assignedPage != null) {
|
2016-11-12 13:54:49 +01:00
|
|
|
ItemStack display = this.assignedPage.getChapter().getDisplayItemStack();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(display)) {
|
2016-11-12 13:54:49 +01:00
|
|
|
GlStateManager.pushMatrix();
|
2019-05-02 09:10:29 +02:00
|
|
|
AssetUtil.renderStackToGui(display, this.x + 2, this.y + 1, 0.725F);
|
2016-11-12 13:54:49 +01:00
|
|
|
GlStateManager.popMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public void drawHover(int mouseX, int mouseY) {
|
|
|
|
if (this.isMouseOver()) {
|
2019-02-27 19:53:05 +01:00
|
|
|
List<String> list = new ArrayList<>();
|
2016-11-12 13:54:49 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.assignedPage != null) {
|
2016-11-12 13:54:49 +01:00
|
|
|
IBookletChapter chapter = this.assignedPage.getChapter();
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
list.add(TextFormatting.GOLD + chapter.getLocalizedName() + ", Page " + (chapter.getPageIndex(this.assignedPage) + 1));
|
|
|
|
list.add(StringUtil.localize("booklet." + ActuallyAdditions.MODID + ".bookmarkButton.bookmark.openDesc"));
|
|
|
|
list.add(TextFormatting.ITALIC + StringUtil.localize("booklet." + ActuallyAdditions.MODID + ".bookmarkButton.bookmark.removeDesc"));
|
|
|
|
} else {
|
|
|
|
list.add(TextFormatting.GOLD + StringUtil.localize("booklet." + ActuallyAdditions.MODID + ".bookmarkButton.noBookmark.name"));
|
2016-11-12 13:54:49 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.booklet instanceof GuiPage) {
|
|
|
|
list.add(StringUtil.localize("booklet." + ActuallyAdditions.MODID + ".bookmarkButton.noBookmark.pageDesc"));
|
|
|
|
} else {
|
|
|
|
list.add(StringUtil.localize("booklet." + ActuallyAdditions.MODID + ".bookmarkButton.noBookmark.notPageDesc"));
|
2016-11-12 13:54:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Minecraft mc = Minecraft.getMinecraft();
|
2017-06-29 18:30:02 +02:00
|
|
|
GuiUtils.drawHoveringText(list, mouseX, mouseY, mc.displayWidth, mc.displayHeight, -1, mc.fontRenderer);
|
2016-11-12 13:54:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|