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