use of com.ray3k.skincomposer.data.DrawableData in project skin-composer by raeleus.
the class DialogFactory method recentFiles.
public void recentFiles() {
SelectBox<RecentFile> selectBox = new SelectBox(main.getSkin());
Dialog dialog = new Dialog("Recent Files...", main.getSkin(), "bg") {
@Override
protected void result(Object object) {
super.result(object);
if ((boolean) object) {
if (selectBox.getSelected() != null) {
FileHandle file = selectBox.getSelected().getFileHandle();
if (file.exists()) {
main.getProjectData().load(file);
Array<DrawableData> drawableErrors = main.getProjectData().verifyDrawablePaths();
Array<FontData> fontErrors = main.getProjectData().verifyFontPaths();
if (drawableErrors.size > 0 || fontErrors.size > 0) {
main.getDialogFactory().showDialogPathErrors(drawableErrors, fontErrors);
}
}
}
}
}
};
dialog.getTitleTable().getCells().first().padLeft(5.0f);
Array<RecentFile> recentFiles = main.getProjectData().getRecentFiles();
recentFiles.reverse();
selectBox.setItems(recentFiles);
selectBox.addListener(main.getHandListener());
selectBox.getList().addListener(main.getHandListener());
dialog.text("Select a file to open");
dialog.getContentTable().row();
dialog.getContentTable().add(selectBox).padLeft(10.0f).padRight(10.0f).growX();
dialog.getContentTable().getCells().first().pad(10.0f);
dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
dialog.button("OK", true).key(Input.Keys.ENTER, true);
dialog.button("Cancel", false).key(Input.Keys.ESCAPE, false);
dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
dialog.show(main.getStage());
}
use of com.ray3k.skincomposer.data.DrawableData in project skin-composer by raeleus.
the class DialogFonts method refreshTable.
public void refreshTable() {
fontsTable.clear();
fontsTable.defaults().growX().pad(5.0f);
if (fonts.size == 0 && freeTypeFonts.size == 0) {
fontsTable.add(new Label("No fonts have been set!", getSkin()));
} else {
if (fonts.size > 0) {
Label label = new Label("Bitmap Fonts", getSkin(), "required");
label.setAlignment(Align.center);
fontsTable.add(label);
fontsTable.row();
}
for (FontData font : fonts) {
Button button = new Button(getSkin(), "color-base");
Label label = new Label(font.getName(), getSkin());
label.setTouchable(Touchable.disabled);
button.add(label).left();
button.addListener(main.getHandListener());
Button renameButton = new Button(getSkin(), "settings-small");
renameButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
renameDialog(font);
event.setBubbles(false);
}
});
renameButton.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
event.setBubbles(false);
return true;
}
});
button.add(renameButton).padLeft(15.0f);
TextTooltip toolTip = new TextTooltip("Rename Font", main.getTooltipManager(), getSkin());
renameButton.addListener(toolTip);
LabelStyle style = new LabelStyle();
style.font = fontMap.get(font);
style.fontColor = Color.WHITE;
label = new Label("Lorem Ipsum", style);
label.setAlignment(Align.center);
label.setTouchable(Touchable.disabled);
Table bg = new Table(getSkin());
bg.setBackground("white");
BitmapFontData bf = new BitmapFontData(font.file, false);
if (bf.imagePaths.length > 0) {
FileHandle file = new FileHandle(bf.imagePaths[0]);
if (!file.exists()) {
file = bf.fontFile.sibling(bf.fontFile.nameWithoutExtension() + ".png");
}
if (Utils.brightness(Utils.averageEdgeColor(file)) < .5f) {
bg.setColor(Color.WHITE);
} else {
bg.setColor(Color.BLACK);
}
}
bg.add(label).pad(5.0f).grow();
button.add(bg).padLeft(15).growX();
Button closeButton = new Button(getSkin(), "delete-small");
final FontData deleteFont = font;
closeButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
fonts.removeValue(deleteFont, true);
main.getProjectData().setChangesSaved(false);
BitmapFontData bitmapFontData = new BitmapFontData(deleteFont.file, false);
for (String path : bitmapFontData.imagePaths) {
FileHandle imagefile = new FileHandle(path);
drawables.removeValue(new DrawableData(imagefile), false);
}
for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
for (StyleData data : datas) {
for (StyleProperty property : data.properties.values()) {
if (property != null && property.type.equals(BitmapFont.class) && property.value != null && property.value.equals(deleteFont.getName())) {
property.value = null;
}
}
}
}
main.getUndoableManager().clearUndoables();
main.getRootTable().refreshStyleProperties(true);
main.getRootTable().refreshPreview();
event.setBubbles(false);
refreshTable();
}
});
closeButton.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
event.setBubbles(false);
return true;
}
});
button.add(closeButton).padLeft(5.0f).right();
toolTip = new TextTooltip("Delete Font", main.getTooltipManager(), getSkin());
closeButton.addListener(toolTip);
if (styleProperty == null && customProperty == null) {
button.setTouchable(Touchable.childrenOnly);
} else {
final FontData fontResult = font;
button.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
result(fontResult);
hide();
}
});
}
fontsTable.add(button);
fontsTable.row();
}
if (freeTypeFonts.size > 0) {
Label label = new Label("FreeType Fonts", getSkin(), "required");
label.setAlignment(Align.center);
fontsTable.add(label).spaceTop(20.0f);
fontsTable.row();
}
for (FreeTypeFontData font : freeTypeFonts) {
Button button = new Button(getSkin(), "color-base");
Label label = new Label(font.name, getSkin());
label.setTouchable(Touchable.disabled);
button.add(label).left();
button.addListener(main.getHandListener());
Button renameButton = new Button(getSkin(), "settings-small");
renameButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
freeTypeSettingsDialog(font);
event.setBubbles(false);
}
});
renameButton.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
event.setBubbles(false);
return true;
}
});
button.add(renameButton).padLeft(15.0f);
TextTooltip toolTip = new TextTooltip("Rename Font", main.getTooltipManager(), getSkin());
renameButton.addListener(toolTip);
LabelStyle style = new LabelStyle();
style.font = font.bitmapFont;
style.fontColor = Color.WHITE;
label = new Label("Lorem Ipsum", style);
label.setAlignment(Align.center);
label.setTouchable(Touchable.disabled);
Table bg = new Table(getSkin());
bg.setBackground("white");
bg.add(label).pad(5.0f).grow();
button.add(bg).padLeft(15).growX();
Button closeButton = new Button(getSkin(), "delete-small");
final FreeTypeFontData deleteFont = font;
closeButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
freeTypeFonts.removeValue(deleteFont, true);
main.getProjectData().setChangesSaved(false);
for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
for (StyleData data : datas) {
for (StyleProperty property : data.properties.values()) {
if (property != null && property.type.equals(BitmapFont.class) && property.value != null && property.value.equals(deleteFont.name)) {
property.value = null;
}
}
}
}
main.getUndoableManager().clearUndoables();
main.getRootTable().refreshStyleProperties(true);
main.getRootTable().refreshPreview();
event.setBubbles(false);
refreshTable();
}
});
closeButton.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
event.setBubbles(false);
return true;
}
});
button.add(closeButton).padLeft(5.0f).right();
toolTip = new TextTooltip("Delete Font", main.getTooltipManager(), getSkin());
closeButton.addListener(toolTip);
if (styleProperty == null && customProperty == null) {
button.setTouchable(Touchable.childrenOnly);
} else {
final FreeTypeFontData fontResult = font;
button.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
result(fontResult);
hide();
}
});
}
fontsTable.add(button);
fontsTable.row();
}
}
}
use of com.ray3k.skincomposer.data.DrawableData in project skin-composer by raeleus.
the class DialogFonts method addFont.
private boolean addFont(String name, FileHandle file) {
if (FontData.validate(name)) {
try {
main.getProjectData().setChangesSaved(false);
FontData font = new FontData(name, file);
// remove any existing FontData that shares the same name.
if (fonts.contains(font, false)) {
FontData deleteFont = fonts.get(fonts.indexOf(font, false));
BitmapFontData deleteFontData = new BitmapFontData(deleteFont.file, false);
for (String path : deleteFontData.imagePaths) {
FileHandle imagefile = new FileHandle(path);
drawables.removeValue(new DrawableData(imagefile), false);
}
fonts.removeValue(font, false);
}
BitmapFontData bitmapFontData = new BitmapFontData(file, false);
for (String path : bitmapFontData.imagePaths) {
DrawableData drawable = new DrawableData(new FileHandle(path));
drawable.visible = false;
if (!drawables.contains(drawable, false)) {
main.getAtlasData().atlasCurrent = false;
drawables.add(drawable);
}
}
produceAtlas();
fonts.add(font);
Array<TextureRegion> regions = new Array<>();
for (String path : bitmapFontData.imagePaths) {
FileHandle imageFile = new FileHandle(path);
regions.add(atlas.findRegion(imageFile.nameWithoutExtension()));
}
fontMap.put(font, new BitmapFont(bitmapFontData, regions, true));
sortBySelectedMode();
refreshTable();
} catch (Exception e) {
Gdx.app.error(getClass().getName(), "Error creating font from file", e);
main.getDialogFactory().showDialogError("Font Error...", "Error creating font from file. Check file paths.\n\nOpen log?");
}
return true;
} else {
return false;
}
}
use of com.ray3k.skincomposer.data.DrawableData in project skin-composer by raeleus.
the class DialogPathErrors method resolveAssetsFromFolder.
private void resolveAssetsFromFolder(FileHandle folder, Array<DrawableData> drawables, Array<FontData> fonts) {
if (folder.isDirectory()) {
for (DrawableData drawable : drawables) {
if (!foundDrawables.contains(drawable, true)) {
FileHandle file = folder.child(drawable.file.name());
if (file.exists()) {
drawable.file = file;
foundDrawables.add(drawable);
}
}
}
for (FontData font : fonts) {
if (!foundFonts.contains(font, true)) {
FileHandle file = folder.child(font.file.name());
if (file.exists()) {
font.file = file;
foundFonts.add(font);
}
}
}
}
applyButton.setDisabled(foundDrawables.size != drawables.size || foundFonts.size != fonts.size);
}
use of com.ray3k.skincomposer.data.DrawableData in project skin-composer by raeleus.
the class DialogPathErrors method resetDrawableTable.
private void resetDrawableTable(Main main, Skin skin, Array<DrawableData> drawables, Array<FontData> fonts) {
dataTable.clear();
if (drawables.size > 0) {
Label label = new Label("Drawable Name", skin, "black");
dataTable.add(label);
label = new Label("Path", skin, "black");
dataTable.add(label);
dataTable.add();
label = new Label("Found?", skin, "black");
dataTable.add(label);
dataTable.row();
Image image = new Image(skin, "welcome-separator");
dataTable.add(image).colspan(4).pad(5.0f).padLeft(0.0f).padRight(0.0f).growX();
for (DrawableData drawable : drawables) {
dataTable.row();
label = new Label(drawable.name, skin);
dataTable.add(label);
label = new Label(drawable.file.path(), skin);
label.setWrap(true);
label.setAlignment(Align.left);
dataTable.add(label).growX();
TextButton textButton = new TextButton("browse...", skin);
textButton.addListener(main.getHandListener());
dataTable.add(textButton).padLeft(10.0f);
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
DesktopWorker desktopWorker = main.getDesktopWorker();
String[] filterPatterns = null;
if (!Utils.isMac()) {
filterPatterns = new String[] { "*.png", "*.jpg", "*.jpeg", "*.bmp", "*.gif" };
}
File file = desktopWorker.openDialog("Locate " + drawable.file.name() + "...", drawable.file.path(), filterPatterns, "Image files");
if (file != null) {
FileHandle fileHandle = new FileHandle(file);
drawable.file = fileHandle;
if (!foundDrawables.contains(drawable, true)) {
foundDrawables.add(drawable);
}
resolveAssetsFromFolder(fileHandle.parent(), drawables, fonts);
resetDrawableTable(main, skin, drawables, fonts);
}
}
});
if (foundDrawables.contains(drawable, true)) {
label = new Label("YES", skin, "white");
label.setColor(Color.GREEN);
dataTable.add(label);
} else {
label = new Label("NO", skin, "white");
label.setColor(Color.RED);
dataTable.add(label);
}
dataTable.row();
image = new Image(skin, "welcome-separator");
dataTable.add(image).colspan(4).pad(5.0f).padLeft(0.0f).padRight(0.0f).growX();
}
}
if (fonts.size > 0) {
dataTable.row();
dataTable.defaults().padTop(20.0f);
Label label = new Label("Font Name", skin, "black");
dataTable.add(label);
label = new Label("Path", skin, "black");
dataTable.add(label);
dataTable.add();
label = new Label("Found?", skin, "black");
dataTable.add(label);
dataTable.defaults().reset();
dataTable.row();
Image image = new Image(skin, "welcome-separator");
dataTable.add(image).colspan(4).pad(5.0f).padLeft(0.0f).padRight(0.0f).growX();
for (FontData font : fonts) {
dataTable.row();
label = new Label(font.getName(), skin);
dataTable.add(label);
label = new Label(font.file.path(), skin);
label.setWrap(true);
label.setAlignment(Align.left);
dataTable.add(label).growX();
TextButton textButton = new TextButton("browse...", skin);
textButton.addListener(main.getHandListener());
dataTable.add(textButton);
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
DesktopWorker desktopWorker = main.getDesktopWorker();
String[] filterPatterns = null;
if (!Utils.isMac()) {
filterPatterns = new String[] { "*.fnt" };
}
File file = desktopWorker.openDialog("Locate " + font.file.name() + "...", font.file.path(), filterPatterns, "Font files");
if (file != null) {
FileHandle fileHandle = new FileHandle(file);
font.file = fileHandle;
if (!foundFonts.contains(font, true)) {
foundFonts.add(font);
}
resolveAssetsFromFolder(fileHandle.parent(), drawables, fonts);
resetDrawableTable(main, skin, drawables, fonts);
}
}
});
if (foundFonts.contains(font, true)) {
label = new Label("YES", skin, "white");
label.setColor(Color.GREEN);
dataTable.add(label);
} else {
label = new Label("NO", skin, "white");
label.setColor(Color.RED);
dataTable.add(label);
}
dataTable.row();
image = new Image(skin, "welcome-separator");
dataTable.add(image).colspan(4).pad(5.0f).padLeft(0.0f).padRight(0.0f).growX();
}
}
}
Aggregations