mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-26 14:27:59 +01:00
Speed up loading of save dialog.
Pick save location, then download. Also removes the callback because the button is updated in updateScreen
This commit is contained in:
parent
6ef13d9e9a
commit
58b0fd2630
2 changed files with 29 additions and 42 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue