use of com.ray3k.skincomposer.dialog.DialogListener in project skin-composer by raeleus.
the class MainListener method openFile.
public void openFile() {
Runnable runnable = () -> {
String defaultPath = projectData.getLastOpenSavePath();
String[] filterPatterns = null;
if (!Utils.isMac()) {
filterPatterns = new String[] { "*.scmp" };
}
File file = desktopWorker.openDialog("Open Skin Composer file...", defaultPath, filterPatterns, "Skin Composer files");
if (file != null) {
Gdx.app.postRunnable(() -> {
FileHandle fileHandle = new FileHandle(file);
projectData.load(fileHandle);
Array<DrawableData> drawableErrors = projectData.verifyDrawablePaths();
Array<FontData> fontErrors = projectData.verifyFontPaths();
var freeTypeFontErrors = projectData.verifyFreeTypeFontPaths();
if (drawableErrors.size > 0 || fontErrors.size > 0 || freeTypeFontErrors.size > 0) {
dialogFactory.showDialogPathErrors(drawableErrors, fontErrors, freeTypeFontErrors);
}
if (projectData.checkForInvalidMinWidthHeight()) {
projectData.setLoadedVersion(Main.VERSION);
dialogFactory.yesNoDialog("Fix minWidth and minHeight errors?", "Old project (< v.30) detected.\nResolve minWidth and minHeight errors?", new DialogFactory.ConfirmationListener() {
@Override
public void selected(int selection) {
if (selection == 0) {
projectData.fixInvalidMinWidthHeight();
refreshTextureAtlas();
}
}
}, null);
}
projectData.setLastOpenSavePath(fileHandle.parent().path() + "/");
rootTable.populate();
rootTable.updateRecentFiles();
});
}
};
if (!projectData.areChangesSaved() && !projectData.isNewProject()) {
var dialog = dialogFactory.yesNoCancelDialog("Save Changes?", "Do you want to save changes to the existing project?" + "\nAll unsaved changes will be lost.", (int selection) -> {
if (selection == 0) {
saveFile(runnable);
} else if (selection == 1) {
dialogFactory.showDialogLoading(runnable);
}
}, dialogListener);
dialog.addListener(new DialogListener() {
@Override
public void opened() {
desktopWorker.removeFilesDroppedListener(rootTable.getFilesDroppedListener());
}
@Override
public void closed() {
desktopWorker.addFilesDroppedListener(rootTable.getFilesDroppedListener());
}
});
} else {
dialogFactory.showDialogLoading(runnable);
}
}
use of com.ray3k.skincomposer.dialog.DialogListener 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;
}
use of com.ray3k.skincomposer.dialog.DialogListener in project skin-composer by raeleus.
the class ImageButtonListeners method imageButtonColorListener.
public static EventListener imageButtonColorListener(final DialogSceneComposerEvents events, SimActor simActor) {
var simImageButton = (DialogSceneComposerModel.SimImageButton) simActor;
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("Color:", skin, "scene-label-colored");
popTable.add(label);
popTable.row();
var imageButton = new ImageButton(skin, "scene-color");
imageButton.getImage().setColor(simImageButton.color == null ? Color.WHITE : simImageButton.color.color);
popTable.add(imageButton).minWidth(100);
imageButton.addListener(handListener);
imageButton.addListener(new TextTooltip("Select the color of the button.", tooltipManager, skin, "scene"));
imageButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
popTable.hide();
dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
if (!pressedCancel) {
events.imageButtonColor(colorData);
}
}, new DialogListener() {
@Override
public void opened() {
}
@Override
public void closed() {
}
});
}
});
popTable.row();
label = new Label(simImageButton.color == null ? "white" : simImageButton.color.getName(), skin, "scene-label-colored");
popTable.add(label);
}
};
popTableClickListener.update();
return popTableClickListener;
}
use of com.ray3k.skincomposer.dialog.DialogListener in project skin-composer by raeleus.
the class DialogSceneComposer method rootBackgroundColorListener.
private EventListener rootBackgroundColorListener() {
var popTableClickListener = new PopTableClickListener(skin) {
@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("Color:", skin, "scene-label-colored");
popTable.add(label);
popTable.row();
var imageButton = new ImageButton(skin, "scene-color");
imageButton.getImage().setColor(rootActor.backgroundColor == null ? Color.WHITE : rootActor.backgroundColor.color);
popTable.add(imageButton).minWidth(100);
imageButton.addListener(handListener);
imageButton.addListener(new TextTooltip("Select the color of the background.", tooltipManager, skin, "scene"));
imageButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
popTable.hide();
dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
if (!pressedCancel) {
events.rootBackgroundColor(colorData);
}
}, new DialogListener() {
@Override
public void opened() {
}
@Override
public void closed() {
}
});
}
});
popTable.row();
label = new Label(rootActor.backgroundColor == null ? "white" : rootActor.backgroundColor.getName(), skin, "scene-label-colored");
popTable.add(label);
}
};
popTableClickListener.update();
return popTableClickListener;
}
use of com.ray3k.skincomposer.dialog.DialogListener in project skin-composer by raeleus.
the class LabelListeners method labelColorListener.
public static EventListener labelColorListener(final DialogSceneComposerEvents events, SimActor simActor) {
var simLabel = (DialogSceneComposerModel.SimLabel) simActor;
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("Color:", skin, "scene-label-colored");
popTable.add(label);
popTable.row();
var imageButton = new ImageButton(skin, "scene-color");
imageButton.getImage().setColor(simLabel.color == null ? Color.WHITE : simLabel.color.color);
popTable.add(imageButton).minWidth(100);
imageButton.addListener(handListener);
imageButton.addListener(new TextTooltip("Select the color of the Label.", tooltipManager, skin, "scene"));
imageButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
popTable.hide();
dialogFactory.showDialogColors(new StyleProperty(), (colorData, pressedCancel) -> {
if (!pressedCancel) {
events.labelColor(colorData);
}
}, new DialogListener() {
@Override
public void opened() {
}
@Override
public void closed() {
}
});
}
});
popTable.row();
label = new Label(simLabel.color == null ? "white" : simLabel.color.getName(), skin, "scene-label-colored");
popTable.add(label);
}
};
popTableClickListener.update();
return popTableClickListener;
}
Aggregations