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

69 lines
2.3 KiB
Java
Raw Normal View History

2016-11-10 21:07:15 +01:00
/*
* This file ("PageLinkButton.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2016-11-10 21:07:15 +01:00
*/
package de.ellpeck.actuallyadditions.mod.booklet.page;
2016-11-12 00:29:01 +01:00
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
2018-05-10 11:38:58 +02:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
2016-11-12 00:29:01 +01:00
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
2021-02-27 22:59:18 +01:00
import net.minecraft.client.gui.widget.button.Button;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.awt.*;
import java.net.URI;
2016-11-12 00:29:01 +01:00
2019-05-02 09:10:29 +02:00
public class PageLinkButton extends BookletPage {
2016-11-10 21:07:15 +01:00
2017-02-18 00:54:58 +01:00
public static int nextButtonId = 23782;
2016-12-05 21:48:45 +01:00
private final int buttonId;
2016-11-12 00:29:01 +01:00
private final String link;
2019-05-02 09:10:29 +02:00
public PageLinkButton(int localizationKey, String link) {
2016-11-10 21:07:15 +01:00
super(localizationKey);
2016-11-12 00:29:01 +01:00
this.link = link;
2016-12-05 21:48:45 +01:00
this.buttonId = nextButtonId;
nextButtonId++;
2016-11-12 00:29:01 +01:00
}
@Override
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
2021-03-01 20:14:50 +01:00
public void init(GuiBookletBase gui, int startX, int startY) {
super.init(gui, startX, startY);
2016-11-12 00:29:01 +01:00
2021-02-27 22:59:18 +01:00
gui.getButtonList().add(new Button(this.buttonId, startX + 125 / 2 - 50, startY + 130, 100, 20, StringUtil.localize("booklet." + ActuallyAdditions.MODID + ".chapter." + this.chapter.getIdentifier() + ".button." + this.localizationKey)));
2016-11-12 00:29:01 +01:00
}
@Override
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.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-12 00:29:01 +01:00
super.drawScreenPre(gui, startX, startY, mouseX, mouseY, partialTicks);
2019-05-02 09:10:29 +02:00
PageTextOnly.renderTextToPage(gui, this, startX + 6, startY + 5);
2016-11-12 00:29:01 +01:00
}
@Override
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.CLIENT)
2021-02-27 22:59:18 +01:00
public void actionPerformed(GuiBookletBase gui, Button button) {
2019-05-02 09:10:29 +02:00
if (button.id == this.buttonId) {
if (Desktop.isDesktopSupported()) {
try {
2016-11-12 00:29:01 +01:00
Desktop.getDesktop().browse(new URI(this.link));
2019-05-02 09:10:29 +02:00
} catch (Exception e) {
2018-05-10 11:38:58 +02:00
ActuallyAdditions.LOGGER.error("Couldn't open website from Link Button page!", e);
2016-11-12 00:29:01 +01:00
}
}
2019-05-02 09:10:29 +02:00
} else {
2016-11-12 00:29:01 +01:00
super.actionPerformed(gui, button);
}
2016-11-10 21:07:15 +01:00
}
}