use of com.badlogic.gdx.files.FileHandle in project skin-composer by raeleus.
the class Dialog9Patch method showLoadPatchesDialog.
private void showLoadPatchesDialog() {
Runnable runnable = () -> {
String defaultPath = projectData.getLastDrawablePath();
String[] filterPatterns = null;
if (!Utils.isMac()) {
filterPatterns = new String[] { "*.9.png;" };
}
File file = desktopWorker.openDialog("Load Patches from File...", defaultPath, filterPatterns, "Nine Patch files");
if (file != null) {
Gdx.app.postRunnable(() -> {
var fileHandle = new FileHandle(file);
loadPatches(fileHandle);
});
}
};
dialogFactory.showDialogLoading(runnable);
}
use of com.badlogic.gdx.files.FileHandle in project skin-composer by raeleus.
the class DialogDrawables method finalizeDrawables.
/**
* Adds the drawables to the project.
* @param backup If there is a failure, the drawable list will be rolled
* back to the provided backup.
* @param filesToProcess
*/
private void finalizeDrawables(Array<DrawableData> backup, Array<FileHandle> filesToProcess) {
for (FileHandle file : filesToProcess) {
DrawableData data = new DrawableData(file);
if (Utils.isNinePatch(file.name())) {
data.type = DrawableType.NINE_PATCH;
} else {
data.type = DrawableType.TEXTURE;
}
if (!checkIfNameExists(data.name)) {
atlasData.getDrawables().add(data);
}
}
gatherDrawables();
dialogFactory.showDialogLoading(() -> {
Gdx.app.postRunnable(() -> {
if (!atlasData.produceAtlas()) {
showDrawableError();
Gdx.app.log(getClass().getName(), "Attempting to reload drawables backup...");
atlasData.getDrawables().clear();
atlasData.getDrawables().addAll(backup);
gatherDrawables();
if (atlasData.produceAtlas()) {
Gdx.app.log(getClass().getName(), "Successfully rolled back changes to drawables");
} else {
Gdx.app.error(getClass().getName(), "Critical failure, could not roll back changes to drawables");
}
} else {
if (projectData.areResourcesRelative()) {
projectData.makeResourcesRelative();
}
projectData.setChangesSaved(false);
}
sortBySelectedMode();
});
});
}
use of com.badlogic.gdx.files.FileHandle in project skin-composer by raeleus.
the class DialogDrawables method drawablesSelected.
private void drawablesSelected(Array<FileHandle> files) {
atlasData.atlasCurrent = false;
Array<DrawableData> backup = new Array<>(atlasData.getDrawables());
Array<FileHandle> unhandledFiles = new Array<>();
Array<FileHandle> filesToProcess = new Array<>();
projectData.setLastDrawablePath(files.get(0).parent().path() + "/");
for (FileHandle fileHandle : files) {
var duplicateDrawable = checkDuplicateDrawables(DrawableData.proper(fileHandle.name()), 0);
var duplicateFontDrawable = checkDuplicateFontDrawables(DrawableData.proper(fileHandle.name()), 0);
if (duplicateDrawable || duplicateFontDrawable) {
unhandledFiles.add(fileHandle);
} else {
filesToProcess.add(fileHandle);
}
}
if (unhandledFiles.size > 0) {
showRemoveDuplicatesDialog(unhandledFiles, backup, filesToProcess);
} else {
finalizeDrawables(backup, filesToProcess);
}
}
use of com.badlogic.gdx.files.FileHandle in project skin-composer by raeleus.
the class DialogDrawables method initialize.
public void initialize(Main main, DialogDrawablesListener listener) {
Table table = new Table();
table.setFillParent(true);
table.setTouchable(Touchable.disabled);
addActor(table);
Label label = new Label("", getSkin(), "filter");
label.setName("filter-label");
label.setColor(1, 1, 1, 0);
table.add(label).bottom().right().expand().pad(50).padBottom(20);
filterInputListener = new FilterInputListener(this);
addListener(filterInputListener);
showing9patchButton = true;
showingOptions = true;
this.main = main;
instance = this;
this.listener = listener;
filesDroppedListener = (Array<FileHandle> files) -> {
Iterator<FileHandle> iter = files.iterator();
while (iter.hasNext()) {
FileHandle file = iter.next();
if (file.isDirectory()) {
files.addAll(file.list());
iter.remove();
} else if (!(file.name().toLowerCase().endsWith(".png") || file.name().toLowerCase().endsWith(".jpg") || file.name().toLowerCase().endsWith(".jpeg") || file.name().toLowerCase().endsWith(".bmp") || file.name().toLowerCase().endsWith(".gif"))) {
iter.remove();
}
}
var filesLimited = new Array<FileHandle>(files);
iter = filesLimited.iterator();
while (iter.hasNext()) {
var file = iter.next();
if (!file.name().toLowerCase(Locale.ROOT).endsWith(".9.png")) {
if (files.contains(file.sibling(file.nameWithoutExtension() + ".9.png"), false)) {
iter.remove();
}
}
}
if (filesLimited.size > 0) {
drawablesSelected(filesLimited);
}
};
desktopWorker.addFilesDroppedListener(filesDroppedListener);
gatherDrawables();
atlasData.produceAtlas();
populate();
}
use of com.badlogic.gdx.files.FileHandle in project skin-composer by raeleus.
the class DialogDrawables method drawablesSelected.
/**
* Called when a selection of drawables has been chosen from the
* newDrawablesDialog(). Adds the new drawables to the project.
* @param files
*/
private void drawablesSelected(List<File> files) {
Array<FileHandle> fileHandles = new Array<>();
files.forEach((file) -> {
fileHandles.add(new FileHandle(file));
});
drawablesSelected(fileHandles);
}
Aggregations