2020-09-09 16:48:43 +02:00
|
|
|
package de.ellpeck.actuallyadditions.booklet.page;
|
2016-11-10 21:07:15 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
import java.awt.Desktop;
|
|
|
|
import java.net.URI;
|
|
|
|
|
2016-11-12 00:29:01 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.internal.GuiBookletBase;
|
2020-09-09 16:48:43 +02:00
|
|
|
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
|
|
|
|
import de.ellpeck.actuallyadditions.common.util.StringUtil;
|
2016-11-12 00:29:01 +01:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2017-02-18 00:54:58 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
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
|
2017-02-18 00:54:58 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public void initGui(GuiBookletBase gui, int startX, int startY) {
|
2016-11-12 00:29:01 +01:00
|
|
|
super.initGui(gui, startX, startY);
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
gui.getButtonList().add(new GuiButton(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
|
2017-02-18 00:54:58 +01:00
|
|
|
@SideOnly(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-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
|
2017-02-18 00:54:58 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public void actionPerformed(GuiBookletBase gui, GuiButton button) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|