| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import java.io.IOException;
|
| 4 | import net.minecraft.client.resources.I18n;
|
| 5 |
|
| 6 | public class GuiConfirmOpenLink extends GuiYesNo
|
| 7 | {
|
| 8 | /** Text to warn players from opening unsafe links. */
|
| 9 | private final String openLinkWarning;
|
| 10 |
|
| 11 | /** Label for the Copy to Clipboard button. */
|
| 12 | private final String copyLinkButtonText;
|
| 13 | private final String linkText;
|
| 14 | private boolean showSecurityWarning = true;
|
| 15 |
|
| 16 | public GuiConfirmOpenLink(GuiYesNoCallback p_i1084_1_, String linkTextIn, int p_i1084_3_, boolean p_i1084_4_)
|
| 17 | {
|
| 18 | super(p_i1084_1_, I18n.format(p_i1084_4_ ? "chat.link.confirmTrusted" : "chat.link.confirm", new Object[0]), linkTextIn, p_i1084_3_);
|
| 19 | this.confirmButtonText = I18n.format(p_i1084_4_ ? "chat.link.open" : "gui.yes", new Object[0]);
|
| 20 | this.cancelButtonText = I18n.format(p_i1084_4_ ? "gui.cancel" : "gui.no", new Object[0]);
|
| 21 | this.copyLinkButtonText = I18n.format("chat.copy", new Object[0]);
|
| 22 | this.openLinkWarning = I18n.format("chat.link.warning", new Object[0]);
|
| 23 | this.linkText = linkTextIn;
|
| 24 | }
|
| 25 |
|
| 26 | /**
|
| 27 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 28 | * window resizes, the buttonList is cleared beforehand.
|
| 29 | */
|
| 30 | public void initGui()
|
| 31 | {
|
| 32 | super.initGui();
|
| 33 | this.buttonList.clear();
|
| 34 | this.buttonList.add(new GuiButton(0, this.width / 2 - 50 - 105, this.height / 6 + 96, 100, 20, this.confirmButtonText));
|
| 35 | this.buttonList.add(new GuiButton(2, this.width / 2 - 50, this.height / 6 + 96, 100, 20, this.copyLinkButtonText));
|
| 36 | this.buttonList.add(new GuiButton(1, this.width / 2 - 50 + 105, this.height / 6 + 96, 100, 20, this.cancelButtonText));
|
| 37 | }
|
| 38 |
|
| 39 | /**
|
| 40 | * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
|
| 41 | */
|
| 42 | protected void actionPerformed(GuiButton button) throws IOException
|
| 43 | {
|
| 44 | if (button.id == 2)
|
| 45 | {
|
| 46 | this.copyLinkToClipboard();
|
| 47 | }
|
| 48 |
|
| 49 | this.parentScreen.confirmClicked(button.id == 0, this.parentButtonClickedId);
|
| 50 | }
|
| 51 |
|
| 52 | /**
|
| 53 | * Copies the link to the system clipboard.
|
| 54 | */
|
| 55 | public void copyLinkToClipboard()
|
| 56 | {
|
| 57 | setClipboardString(this.linkText);
|
| 58 | }
|
| 59 |
|
| 60 | /**
|
| 61 | * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
|
| 62 | */
|
| 63 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
| 64 | {
|
| 65 | super.drawScreen(mouseX, mouseY, partialTicks);
|
| 66 |
|
| 67 | if (this.showSecurityWarning)
|
| 68 | {
|
| 69 | this.drawCenteredString(this.fontRendererObj, this.openLinkWarning, this.width / 2, 110, 16764108);
|
| 70 | }
|
| 71 | }
|
| 72 |
|
| 73 | public void disableSecurityWarning()
|
| 74 | {
|
| 75 | this.showSecurityWarning = false;
|
| 76 | }
|
| 77 | }
|
| 78 |
|