diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/SkinChooser.java b/src/hdskins/java/com/voxelmodpack/hdskins/SkinChooser.java index 598c99f2..6aa90cb9 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/SkinChooser.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/SkinChooser.java @@ -1,23 +1,23 @@ package com.voxelmodpack.hdskins; -import net.minecraft.client.Minecraft; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; - +import com.voxelmodpack.hdskins.skins.MoreHttpResponses; import com.voxelmodpack.hdskins.upload.awt.ThreadOpenFile; import com.voxelmodpack.hdskins.upload.awt.ThreadOpenFileFolder; import com.voxelmodpack.hdskins.upload.awt.ThreadOpenFilePNG; - -import javax.annotation.Nullable; -import javax.imageio.ImageIO; -import javax.swing.UIManager; +import net.minecraft.client.Minecraft; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.util.concurrent.ExecutionException; +import javax.annotation.Nullable; +import javax.imageio.ImageIO; +import javax.swing.UIManager; public class SkinChooser { + public static final int MAX_SKIN_DIMENSION = 1024; public static final String ERR_UNREADABLE = "hdskins.error.unreadable"; @@ -59,40 +59,32 @@ public class SkinChooser { return status; } - public void openBrowsePNG(Minecraft mc, String title, Runnable callback) { + public void openBrowsePNG(Minecraft mc, String title) { openFileThread = new ThreadOpenFilePNG(mc, title, (fileDialog, dialogResult) -> { openFileThread = null; if (dialogResult == 0) { selectFile(fileDialog.getSelectedFile()); - callback.run(); - } else { - callback.run(); } }); openFileThread.start(); } - public void openSavePNG(Minecraft mc, String title, Runnable callback) { - uploader.downloadSkin().thenAccept(response -> { - if (response.ok()) { - openFileThread = new ThreadOpenFileFolder(mc, title, (fileDialog, dialogResult) -> { - openFileThread = null; - callback.run(); - if (dialogResult == 0) { - File out = fileDialog.getSelectedFile(); - - try { - out.createNewFile(); - - FileUtils.copyInputStreamToFile(response.getInputStream(), out); - } catch (IOException e) { - e.printStackTrace(); - } + public void openSavePNG(Minecraft mc, String title) { + openFileThread = new ThreadOpenFileFolder(mc, title, (fileDialog, dialogResult) -> { + if (dialogResult == 0) { + File out = fileDialog.getSelectedFile(); + try (MoreHttpResponses response = uploader.downloadSkin().get()) { + if (response.ok()) { + FileUtils.copyInputStreamToFile(response.getInputStream(), out); } - }); - openFileThread.start(); + } catch (IOException | InterruptedException | ExecutionException e) { + e.printStackTrace(); + } } + openFileThread = null; + }); + openFileThread.start(); } public void selectFile(File skinFile) { diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java index a159004b..b9b89d0a 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java @@ -38,6 +38,7 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler { private int updateCounter = 0; + private Button btnBrowse; private Button btnUpload; private Button btnDownload; private Button btnClear; @@ -116,12 +117,8 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler { addButton(new Label(34, 34, "hdskins.local", 0xffffff)); addButton(new Label(width / 2 + 34, 34, "hdskins.server", 0xffffff)); - addButton(new Button(width / 2 - 150, height - 27, 90, 20, "hdskins.options.browse", sender -> { - sender.enabled = false; - chooser.openBrowsePNG(mc, format("hdskins.open.title"), () -> { - sender.enabled = true; - updateButtons(); - }); + addButton(btnBrowse = new Button(width / 2 - 150, height - 27, 90, 20, "hdskins.options.browse", sender -> { + chooser.openBrowsePNG(mc, format("hdskins.open.title")); })).setEnabled(!mc.isFullScreen()); addButton(btnUpload = new Button(width / 2 - 24, height / 2 - 20, 48, 20, "hdskins.options.chevy", sender -> { @@ -132,10 +129,7 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler { addButton(btnDownload = new Button(width / 2 - 24, height / 2 + 20, 48, 20, "hdskins.options.download", sender -> { if (uploader.canClear()) { - sender.enabled = false; - chooser.openSavePNG(mc, format("hdskins.open.title"), () -> { - sender.enabled = true; - }); + chooser.openSavePNG(mc, format("hdskins.open.title")); } })).setEnabled(uploader.canClear()).setTooltip("hdskins.options.download.title"); @@ -430,6 +424,7 @@ public class GuiSkins extends GameGui implements ISkinUploadHandler { private void updateButtons() { btnClear.enabled = uploader.canClear(); btnUpload.enabled = uploader.canUpload(); - btnDownload.enabled = uploader.canClear(); + btnDownload.enabled = uploader.canClear() && !chooser.pickingInProgress(); + btnBrowse.enabled = !chooser.pickingInProgress(); } }