use of com.ray3k.skincomposer.dialog.DialogDrawables in project skin-composer by raeleus.
the class GeneralListeners method selectDrawableListener.
public static EventListener selectDrawableListener(DrawableData originalDrawable, String toolTipText, DrawableSelected drawableSelected) {
var popTableClickListener = new PopTableClickListener(skin) {
{
getPopTable().key(Keys.ESCAPE, popTable::hide);
}
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
update();
}
public void update() {
var popTable = getPopTable();
popTable.clearChildren();
var label = new Label("Drawable:", skin, "scene-label-colored");
popTable.add(label);
popTable.row();
var stack = new Stack();
popTable.add(stack).minSize(100).maxSize(300).grow();
var background = new Image(skin, "scene-tile-ten");
stack.add(background);
Image image;
if (originalDrawable != null) {
image = new Image(atlasData.drawablePairs.get(originalDrawable));
} else {
image = new Image((Drawable) null);
}
stack.add(image);
popTable.row();
var textButton = new TextButton("Select Drawable", skin, "scene-small");
popTable.add(textButton).minWidth(100);
textButton.addListener(handListener);
textButton.addListener(new TextTooltip(toolTipText, tooltipManager, skin, "scene"));
textButton.addListener(new ChangeListener() {
boolean confirmed;
DrawableData drawableData;
@Override
public void changed(ChangeEvent event, Actor actor) {
popTable.hide();
dialogFactory.showDialogDrawables(true, new DialogDrawables.DialogDrawablesListener() {
@Override
public void confirmed(DrawableData drawable, DialogDrawables dialog) {
confirmed = true;
drawableData = drawable;
}
@Override
public void emptied(DialogDrawables dialog) {
confirmed = false;
}
@Override
public void cancelled(DialogDrawables dialog) {
}
}, new DialogListener() {
@Override
public void opened() {
}
@Override
public void closed() {
if (confirmed) {
drawableSelected.selected(drawableData);
image.setDrawable(atlasData.drawablePairs.get(drawableData));
} else {
drawableSelected.selected(null);
image.setDrawable(null);
}
}
});
}
});
}
};
popTableClickListener.update();
return popTableClickListener;
}
Aggregations