|
| 1 | +/* |
| 2 | + * Copyright © 2024 moehreag <[email protected]> & Contributors |
| 3 | + * |
| 4 | + * This file is part of AxolotlClient. |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU Lesser General Public |
| 8 | + * License as published by the Free Software Foundation; either |
| 9 | + * version 3 of the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public License |
| 17 | + * along with this program; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + * |
| 20 | + * For more information, see the LICENSE file. |
| 21 | + */ |
| 22 | + |
| 23 | +package io.github.axolotlclient.modules.screenshotUtils; |
| 24 | + |
| 25 | +import net.minecraft.client.gui.screen.Screen; |
| 26 | +import net.minecraft.client.gui.screen.ScreenTexts; |
| 27 | +import net.minecraft.client.gui.widget.ButtonWidget; |
| 28 | +import net.minecraft.client.gui.widget.TextFieldWidget; |
| 29 | +import net.minecraft.client.resource.language.I18n; |
| 30 | +import net.minecraft.client.util.math.MatrixStack; |
| 31 | +import net.minecraft.text.LiteralText; |
| 32 | +import net.minecraft.text.Text; |
| 33 | +import net.minecraft.text.TranslatableText; |
| 34 | +import net.minecraft.util.Identifier; |
| 35 | + |
| 36 | +public class DownloadImageScreen extends Screen { |
| 37 | + private static final Identifier SPRITE = new Identifier("axolotlclient", "textures/gui/sprites/go.png"); |
| 38 | + |
| 39 | + private final Screen parent; |
| 40 | + |
| 41 | + public DownloadImageScreen(Screen parent) { |
| 42 | + super(new TranslatableText("viewScreenshot")); |
| 43 | + this.parent = parent; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void render(MatrixStack graphics, int mouseX, int mouseY, float delta) { |
| 48 | + renderBackground(graphics); |
| 49 | + super.render(graphics, mouseX, mouseY, delta); |
| 50 | + drawCenteredText(graphics, textRenderer, getTitle(), width / 2, 33 / 2 - textRenderer.fontHeight / 2, -1); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + protected void init() { |
| 55 | + var urlBox = new TextFieldWidget(textRenderer, width / 2 - 100, height / 2 - 10, 200, 20, new TranslatableText("urlBox")); |
| 56 | + urlBox.setSuggestion(I18n.translate("pasteURL")); |
| 57 | + urlBox.setChangedListener(s -> { |
| 58 | + if (s.isEmpty()) { |
| 59 | + urlBox.setSuggestion(I18n.translate("pasteURL")); |
| 60 | + } else { |
| 61 | + urlBox.setSuggestion(""); |
| 62 | + } |
| 63 | + }); |
| 64 | + urlBox.setMaxLength(52); |
| 65 | + addButton(urlBox); |
| 66 | + addButton(new ButtonWidget(width / 2 + 100 + 4, height / 2 - 10, 20, 20, new TranslatableText("download"), b -> { |
| 67 | + String url = urlBox.getText().trim(); |
| 68 | + if (url.isEmpty()) { |
| 69 | + return; |
| 70 | + } |
| 71 | + client.openScreen(ImageScreen.create(this, ImageShare.getInstance().downloadImage(url), true)); |
| 72 | + }) { |
| 73 | + @Override |
| 74 | + public void renderButton(MatrixStack graphics, int mouseX, int mouseY, float delta) { |
| 75 | + Text message = getMessage(); |
| 76 | + setMessage(LiteralText.EMPTY); |
| 77 | + super.renderButton(graphics, mouseX, mouseY, delta); |
| 78 | + setMessage(message); |
| 79 | + client.getTextureManager().bindTexture(SPRITE); |
| 80 | + drawTexture(graphics, x, y, 0, 0, getWidth(), getHeight(), getWidth(), getHeight()); |
| 81 | + } |
| 82 | + }); |
| 83 | + |
| 84 | + addButton(new ButtonWidget(width / 2 - 75, height - 33 / 2, 150, 20, ScreenTexts.BACK, b -> onClose())); |
| 85 | + |
| 86 | + |
| 87 | + setInitialFocus(urlBox); |
| 88 | + } |
| 89 | + |
| 90 | + @Override |
| 91 | + public void onClose() { |
| 92 | + client.openScreen(parent); |
| 93 | + } |
| 94 | +} |
0 commit comments