use of com.ray3k.skincomposer.data.StyleData in project skin-composer by raeleus.
the class DialogDrawables method deleteDrawable.
private void deleteDrawable(DrawableData drawable) {
if (!drawable.customized && drawable.tint == null && drawable.tintName == null && checkDuplicateDrawables(drawable.file, 1)) {
showConfirmDeleteDialog(drawable);
} else {
main.getAtlasData().getDrawables().removeValue(drawable, true);
for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
for (StyleData data : datas) {
for (StyleProperty styleProperty : data.properties.values()) {
if (styleProperty != null && styleProperty.type.equals(Drawable.class) && styleProperty.value != null && styleProperty.value.equals(drawable.toString())) {
styleProperty.value = null;
}
}
}
}
main.getRootTable().refreshStyleProperties(true);
main.getRootTable().refreshPreview();
main.getUndoableManager().clearUndoables();
main.getProjectData().setChangesSaved(false);
gatherDrawables();
sortBySelectedMode();
}
}
use of com.ray3k.skincomposer.data.StyleData in project skin-composer by raeleus.
the class DialogDrawables method removeDuplicateDrawables.
/**
* Removes any duplicate drawables that share the same file name. This
* ignores the file extension and also deletes TintedDrawables from the
* same file.
* @param handle
*/
private void removeDuplicateDrawables(FileHandle handle) {
boolean refreshDrawables = false;
String name = DrawableData.proper(handle.name());
for (int i = 0; i < main.getAtlasData().getDrawables().size; i++) {
DrawableData data = main.getAtlasData().getDrawables().get(i);
if (name.equals(DrawableData.proper(data.file.name()))) {
main.getAtlasData().getDrawables().removeValue(data, true);
for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
for (StyleData tempData : datas) {
for (StyleProperty prop : tempData.properties.values()) {
if (prop != null && prop.type.equals(Drawable.class) && prop.value != null && prop.value.equals(data.toString())) {
prop.value = null;
}
}
}
}
refreshDrawables = true;
i--;
}
}
main.getRootTable().refreshStyleProperties(true);
main.getRootTable().refreshPreview();
if (refreshDrawables) {
gatherDrawables();
}
}
use of com.ray3k.skincomposer.data.StyleData in project skin-composer by raeleus.
the class DialogColors method refreshTable.
public void refreshTable() {
colorTable.clear();
if (colors.size > 0) {
colorTable.defaults().padTop(5.0f);
for (ColorData color : colors) {
Button button = new Button(getSkin(), "color-base");
button.addListener(main.getHandListener());
Label label = new Label(color.toString(), getSkin(), "white");
label.setTouchable(Touchable.disabled);
float brightness = Utils.brightness(color.color);
Color borderColor;
if (brightness > .35f) {
borderColor = Color.BLACK;
label.setColor(borderColor);
} else {
borderColor = Color.WHITE;
label.setColor(borderColor);
}
Color bgColor = new Color(color.color.r, color.color.g, color.color.b, 1.0f);
Table table = new Table(getSkin());
table.setBackground("white");
table.setColor(bgColor);
table.add(label).pad(3.0f);
if (styleProperty == null && customProperty == null && !selectingForTintedDrawable) {
table.addCaptureListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
event.setBubbles(false);
refreshTable();
}
});
table.addCaptureListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
event.setBubbles(false);
return true;
}
});
}
Table borderTable = new Table(getSkin());
borderTable.setBackground("white");
borderTable.setColor(borderColor);
borderTable.add(table).growX().pad(1.0f);
button.add(borderTable).growX();
// rename button
Button renameButton = new Button(getSkin(), "settings-small");
renameButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
renameDialog(color);
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(10.0f);
TextTooltip toolTip = new TextTooltip("Rename Color", main.getTooltipManager(), getSkin());
renameButton.addListener(toolTip);
// recolor button
Button recolorButton = new Button(getSkin(), "colorwheel");
recolorButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
recolorDialog(color);
event.setBubbles(false);
}
});
recolorButton.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
event.setBubbles(false);
return true;
}
});
button.add(recolorButton);
toolTip = new TextTooltip("Change Color", main.getTooltipManager(), getSkin());
recolorButton.addListener(toolTip);
label = new Label("(" + ((int) (color.color.r * 255)) + ", " + ((int) (color.color.g * 255)) + ", " + ((int) (color.color.b * 255)) + ", " + ((int) (color.color.a * 255)) + ")", getSkin());
label.setTouchable(Touchable.disabled);
label.setAlignment(Align.center);
if (styleProperty == null && customProperty == null && !selectingForTintedDrawable) {
label.addCaptureListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
event.setBubbles(false);
refreshTable();
}
});
label.addCaptureListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
event.setBubbles(false);
return true;
}
});
}
button.add(label).padLeft(5.0f).minWidth(160.0f);
// delete color button
Button closeButton = new Button(getSkin(), "delete-small");
final ColorData deleteColor = color;
closeButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
colors.removeValue(deleteColor, true);
main.getProjectData().setChangesSaved(false);
// clear style properties that use this color.
for (Array<StyleData> datas : main.getJsonData().getClassStyleMap().values()) {
for (StyleData data : datas) {
for (StyleProperty property : data.properties.values()) {
if (property != null && property.type.equals(Color.class) && property.value != null && property.value.equals(deleteColor.getName())) {
property.value = null;
}
}
}
}
// delete tinted drawables based on this color.
for (DrawableData drawableData : new Array<>(main.getProjectData().getAtlasData().getDrawables())) {
if (drawableData.tintName != null && drawableData.tintName.equals(deleteColor.getName())) {
main.getProjectData().getAtlasData().getDrawables().removeValue(drawableData, true);
// clear any style properties based on this tinted drawable.
for (Array<StyleData> styleDatas : main.getJsonData().getClassStyleMap().values()) {
for (StyleData styleData : styleDatas) {
for (StyleProperty styleProperty : styleData.properties.values()) {
if (styleProperty != null && styleProperty.type.equals(Drawable.class) && styleProperty.value != null && styleProperty.value.equals(drawableData.toString())) {
styleProperty.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;
}
});
toolTip = new TextTooltip("Delete Color", main.getTooltipManager(), getSkin());
closeButton.addListener(toolTip);
button.add(closeButton).padLeft(5.0f);
if (styleProperty == null && customProperty == null && !selectingForTintedDrawable) {
button.setTouchable(Touchable.childrenOnly);
} else {
setObject(button, color);
final ColorData result = color;
button.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
result(result);
hide();
}
});
}
colorTable.add(button).growX();
colorTable.row();
}
} else {
colorTable.add(new Label("No colors have been set!", getSkin(), "required"));
}
}
use of com.ray3k.skincomposer.data.StyleData in project skin-composer by raeleus.
the class DialogFactory method showNewStyleDialog.
public void showNewStyleDialog(Skin skin, Stage stage) {
Class selectedClass = main.getRootTable().getSelectedClass();
final TextField textField = new TextField("", skin);
Dialog dialog = new Dialog("New Style", skin, "bg") {
@Override
protected void result(Object object) {
if ((Boolean) object) {
main.getUndoableManager().addUndoable(new NewStyleUndoable(selectedClass, textField.getText(), main), true);
}
}
};
dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
dialog.button("OK", true).button("Cancel", false);
dialog.getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
final TextButton okButton = (TextButton) dialog.getButtonTable().getCells().get(0).getActor();
textField.setTextFieldListener((TextField textField1, char c) -> {
if (c == '\n') {
if (!okButton.isDisabled()) {
main.getUndoableManager().addUndoable(new NewStyleUndoable(selectedClass, textField1.getText(), main), true);
dialog.hide();
}
main.getStage().setKeyboardFocus(textField1);
}
});
textField.addListener(main.getIbeamListener());
dialog.getTitleLabel().setAlignment(Align.center);
dialog.getContentTable().defaults().padLeft(10.0f).padRight(10.0f);
dialog.text("What is the name of the new style?");
dialog.getContentTable().getCells().first().pad(10.0f);
dialog.getContentTable().row();
dialog.getContentTable().add(textField).growX();
okButton.setDisabled(true);
Array<StyleData> currentStyles = main.getProjectData().getJsonData().getClassStyleMap().get(selectedClass);
textField.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
boolean disable = !StyleData.validate(textField.getText());
if (!disable) {
for (StyleData data : currentStyles) {
if (data.name.equals(textField.getText())) {
disable = true;
break;
}
}
}
okButton.setDisabled(disable);
}
});
dialog.key(Input.Keys.ESCAPE, false);
dialog.show(stage);
stage.setKeyboardFocus(textField);
textField.setFocusTraversal(false);
}
use of com.ray3k.skincomposer.data.StyleData 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();
}
}
}
Aggregations