use of com.badlogic.gdx.scenes.scene2d.utils.FocusListener in project libgdx by libgdx.
the class Dialog method initialize.
private void initialize() {
setModal(true);
defaults().space(6);
add(contentTable = new Table(skin)).expand().fill();
row();
add(buttonTable = new Table(skin)).fillX();
contentTable.defaults().space(6);
buttonTable.defaults().space(6);
buttonTable.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
if (!values.containsKey(actor))
return;
while (actor.getParent() != buttonTable) actor = actor.getParent();
result(values.get(actor));
if (!cancelHide)
hide();
cancelHide = false;
}
});
focusListener = new FocusListener() {
public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
if (!focused)
focusChanged(event);
}
public void scrollFocusChanged(FocusEvent event, Actor actor, boolean focused) {
if (!focused)
focusChanged(event);
}
private void focusChanged(FocusEvent event) {
Stage stage = getStage();
if (isModal && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == Dialog.this) {
// Dialog is top most actor.
Actor newFocusedActor = event.getRelatedActor();
if (newFocusedActor != null && !newFocusedActor.isDescendantOf(Dialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus)))
event.cancel();
}
}
};
}
use of com.badlogic.gdx.scenes.scene2d.utils.FocusListener in project ultimate-java by pantinor.
the class TinkerDialog method initialize.
private void initialize() {
screen.gameTimer.active = false;
setModal(true);
internalTable = new Table(skin);
internalTable.defaults().pad(5);
defaults().space(10).pad(2);
add(internalTable).expand().fill();
row();
internalTable.add(new Label("Owned Items", skin)).align(Align.left);
internalTable.add();
internalTable.add(new Label("Tinkering Table", skin)).align(Align.left);
internalTable.row();
Array<String> tmp = new Array<>();
for (Constants.Item item : Constants.Item.values()) {
if ((party.getSaveGame().items & (1 << item.ordinal())) > 0 && item.isVisible()) {
tmp.add(item.getDesc());
}
}
ownedList = new List<>(skin);
ownedList.setItems(tmp);
tinkeringList = new List<>(skin);
tinkeringList.setItems(new Array<>());
buttonTable = new Table(skin);
buttonTable.defaults().padLeft(20).padRight(20).padTop(5);
add = new TextButton("Add", skin, "wood");
add.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
String sel = ownedList.getSelected();
if (sel == null) {
return;
}
tinkeringList.getItems().add(sel);
// tinkeringList.setItems(tmp);
}
});
buttonTable.add(add).expandX().left().width(100);
clear = new TextButton("Clear", skin, "wood");
clear.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
tinkeringList.clearItems();
}
});
buttonTable.row();
buttonTable.add(clear).expandX().left().width(100).padBottom(30);
mix = new TextButton("Tinker", skin, "wood");
mix.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
if (tinkeringList == null || tinkeringList.getItems() == null || tinkeringList.getItems().size == 0) {
Sounds.play(Sound.NEGATIVE_EFFECT);
animateText("Bah, that won't work!", Color.WHITE, 10, 180, 350, 180, 2f);
return;
}
if (500 > party.getSaveGame().gold) {
Sounds.play(Sound.NEGATIVE_EFFECT);
animateText("I fear you have not the funds, perhaps another time..", Color.WHITE, 10, 180, 200, 180, 2.5f);
return;
}
if (tinkeringList.getItems().contains(Constants.Item.IRON_ORE.getDesc(), false) && tinkeringList.getItems().contains(Constants.Item.RUNE_MOLD.getDesc(), false)) {
Sounds.play(Sound.POSITIVE_EFFECT);
animateText("Excellent! you have made the Iron Rune!", Color.GREEN, 10, 180, 250, 180, 2.5f);
party.adjustGold(-500);
party.getSaveGame().items = (party.getSaveGame().items & ~Constants.Item.IRON_ORE.getLoc());
party.getSaveGame().items = (party.getSaveGame().items & ~Constants.Item.RUNE_MOLD.getLoc());
party.getSaveGame().items |= Constants.Item.IRON_RUNE.getLoc();
party.getMember(0).awardXP(400);
party.adjustKarma(Constants.KarmaAction.FOUND_ITEM);
} else if (tinkeringList.getItems().contains(Constants.Item.IRON_RUNE.getDesc(), false) && tinkeringList.getItems().contains(Constants.Item.SONG_HUM.getDesc(), false) && tinkeringList.getItems().contains(Constants.Item.PARCH.getDesc(), false) && (party.getSaveGame().runes & Constants.Virtue.HUMILITY.getLoc()) == 0) {
Sounds.play(Sound.POSITIVE_EFFECT);
animateText("Congatulations! You now have the Rune of Humility!", Color.GREEN, 10, 180, 250, 180, 2.5f);
party.adjustGold(-500);
party.getSaveGame().items = (party.getSaveGame().items & ~Constants.Item.IRON_RUNE.getLoc());
party.getSaveGame().items = (party.getSaveGame().items & ~Constants.Item.SONG_HUM.getLoc());
party.getSaveGame().items = (party.getSaveGame().items & ~Constants.Item.PARCH.getLoc());
party.getSaveGame().runes |= Constants.Virtue.HUMILITY.getLoc();
party.adjustKarma(Constants.KarmaAction.FOUND_ITEM);
party.getMember(0).awardXP(500);
} else {
Sounds.play(Sound.NEGATIVE_EFFECT);
animateText("Oh I'm afraid t'is a messy failure we have heahh..", Color.RED, 10, 180, 250, 180, 2f);
}
tinkeringList.clearItems();
ownedList.clearItems();
Array<String> tmp = new Array<>();
for (Constants.Item item : Constants.Item.values()) {
if ((party.getSaveGame().items & (1 << item.ordinal())) > 0 && item.isVisible()) {
tmp.add(item.getDesc());
}
}
ownedList.setItems(tmp);
}
});
buttonTable.row();
buttonTable.add(mix).expandX().left().width(100);
exit = new TextButton("Quit", skin, "wood");
exit.addListener(new ChangeListener() {
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
hide();
}
});
buttonTable.row();
buttonTable.add(exit).expandX().left().width(100);
internalTable.add(ownedList).align(Align.top).minWidth(150).minHeight(150);
internalTable.add(buttonTable).align(Align.top);
internalTable.add(tinkeringList).align(Align.top).padRight(10).minWidth(150).minHeight(150);
internalTable.row();
focusListener = new FocusListener() {
@Override
public void keyboardFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
if (!focused) {
focusChanged(event);
}
}
@Override
public void scrollFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
if (!focused) {
focusChanged(event);
}
}
private void focusChanged(FocusListener.FocusEvent event) {
Stage stage = getStage();
if (isModal() && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == TinkerDialog.this) {
Actor newFocusedActor = event.getRelatedActor();
if (newFocusedActor != null && !newFocusedActor.isDescendantOf(TinkerDialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus))) {
event.cancel();
}
}
}
};
}
use of com.badlogic.gdx.scenes.scene2d.utils.FocusListener in project bladecoder-adventure-engine by bladecoder.
the class PropertyTable method addProperty.
public void addProperty(String name, String value, Types type) {
table.row();
table.add(new Label(name, skin)).expandX().left();
if (type == Types.BOOLEAN) {
SelectBox<String> sb = new SelectBox<String>(skin);
sb.setItems(BOOLEAN_VALUES);
if (value != null)
sb.setSelected(value);
sb.setName(name);
table.add(sb).expandX().left();
sb.addListener(new ChangeListener() {
@SuppressWarnings("unchecked")
@Override
public void changed(ChangeEvent event, Actor actor) {
updateModel(actor.getName(), ((SelectBox<String>) actor).getSelected());
}
});
} else {
TextField tf = new TextField(value == null ? "" : value, skin);
tf.setName(name);
table.add(tf).expandX().left();
if (type == Types.INTEGER)
tf.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
tf.setTextFieldListener(new TextFieldListener() {
@Override
public void keyTyped(TextField actor, char c) {
if (c == 13) {
// ENTER KEY
updateModel(actor.getName(), ((TextField) actor).getText());
EditorLogger.debug("Updating property: " + actor.getName());
}
}
});
tf.addListener(new FocusListener() {
@Override
public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) {
if (!focused) {
updateModel(actor.getName(), ((TextField) actor).getText());
EditorLogger.debug("Updating property: " + actor.getName());
}
}
});
}
}
use of com.badlogic.gdx.scenes.scene2d.utils.FocusListener in project skin-composer by raeleus.
the class DialogSettings method populate.
public void populate() {
Table t = getContentTable();
getButtonTable().padBottom(15.0f);
Label label = new Label("Settings", main.getSkin(), "title");
t.add(label).colspan(2);
t.row();
TextButton textButton = new TextButton("Open temp/log directory", main.getSkin());
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
try {
Utils.openFileExplorer(Gdx.files.local("temp/"));
} catch (Exception e) {
Gdx.app.error(getClass().getName(), "Error opening temp folder", e);
main.getDialogFactory().showDialogError("Folder Error...", "Error opening temp folder.\n\nOpen log?");
}
}
});
textButton.addListener(main.getHandListener());
t.add(textButton).colspan(2).padTop(15.0f);
t.row();
textButton = new TextButton("Open preferences directory", main.getSkin());
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
try {
Utils.openFileExplorer(Gdx.files.external(".prefs/"));
} catch (Exception e) {
Gdx.app.error(getClass().getName(), "Error opening preferences folder", e);
main.getDialogFactory().showDialogError("Folder Error...", "Error opening preferences folder.\n\nOpen log?");
}
}
});
textButton.addListener(main.getHandListener());
t.add(textButton).colspan(2);
if (main.getProjectData().areChangesSaved() && main.getProjectData().getSaveFile().exists()) {
t.row();
textButton = new TextButton("Open project/import directory", main.getSkin());
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
try {
Utils.openFileExplorer(main.getProjectData().getSaveFile().sibling(main.getProjectData().getSaveFile().nameWithoutExtension() + "_data"));
} catch (Exception e) {
Gdx.app.error(getClass().getName(), "Error opening project folder", e);
main.getDialogFactory().showDialogError("Folder Error...", "Error opening project folder\n\nOpen log?");
}
}
});
textButton.addListener(main.getHandListener());
t.add(textButton).colspan(2);
}
t.row();
textButton = new TextButton("Open texture packer settings file", main.getSkin());
textButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
try {
Utils.openFileExplorer(Gdx.files.local("texturepacker/defaults.json"));
} catch (Exception e) {
Gdx.app.error(getClass().getName(), "Error opening defaults.json", e);
main.getDialogFactory().showDialogError("File Error...", "Error opening defaults.json\n\nOpen log?");
}
}
});
textButton.addListener(main.getHandListener());
t.add(textButton).colspan(2);
t.row();
label = new Label("Max Number of Undos: ", main.getSkin());
t.add(label).right().padTop(10.0f);
Spinner spinner3 = new Spinner(main.getProjectData().getMaxUndos(), 1.0, true, Orientation.HORIZONTAL, getSkin());
spinner3.setMinimum(1.0);
spinner3.setMaximum(100.0);
spinner3.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
maxUndos = (int) spinner3.getValue();
}
});
spinner3.addListener(new FocusListener() {
@Override
public void keyboardFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
maxUndos = (int) spinner3.getValue();
}
});
spinner3.getTextField().addListener(main.getIbeamListener());
spinner3.getButtonMinus().addListener(main.getHandListener());
spinner3.getButtonPlus().addListener(main.getHandListener());
t.add(spinner3).minWidth(150.0f).left().padTop(10.0f);
t.row();
final ImageTextButton checkBox = new ImageTextButton("Keep resources relative?", getSkin(), "checkbox");
checkBox.setChecked(resourcesRelative);
checkBox.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
resourcesRelative = checkBox.isChecked();
}
});
t.add(checkBox).padTop(10.0f).colspan(2);
t.row();
final ImageTextButton welcomeCheckBox = new ImageTextButton("Show welcome screen?", getSkin(), "checkbox");
welcomeCheckBox.setChecked(allowingWelcome);
welcomeCheckBox.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
allowingWelcome = welcomeCheckBox.isChecked();
}
});
t.add(welcomeCheckBox).padTop(10.0f).colspan(2);
t.row();
label = new Label("Exported JSON Format:", getSkin());
t.add(label).right().padTop(10.0f);
final SelectBox<ExportFormat> exportFormatSelectBox = new SelectBox(getSkin());
exportFormatSelectBox.setItems(ExportFormat.MINIMAL, ExportFormat.JAVASCRIPT, ExportFormat.JSON);
exportFormatSelectBox.setSelected(exportFormat);
exportFormatSelectBox.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
exportFormat = exportFormatSelectBox.getSelected();
}
});
t.add(exportFormatSelectBox).left().padTop(10.0f);
;
button("OK", true);
button("Cancel", false);
getButtonTable().getCells().first().getActor().addListener(main.getHandListener());
getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
key(Keys.ESCAPE, false);
}
use of com.badlogic.gdx.scenes.scene2d.utils.FocusListener in project skin-composer by raeleus.
the class Spinner method addWidgets.
private void addWidgets() {
buttonMinus = new Button(style.buttonMinusStyle);
buttonPlus = new Button(style.buttonPlusStyle);
textField = new TextField("", style.textFieldStyle) {
@Override
public void next(boolean up) {
if (up) {
if (transversalPrevious != null) {
getStage().setKeyboardFocus(transversalPrevious);
if (transversalPrevious instanceof TextField) {
((TextField) transversalPrevious).selectAll();
}
} else {
super.next(up);
}
} else {
if (transversalNext != null) {
getStage().setKeyboardFocus(transversalNext);
if (transversalNext instanceof TextField) {
((TextField) transversalNext).selectAll();
}
} else {
super.next(up);
}
}
}
};
textField.setAlignment(Align.center);
textField.addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Keys.UP) {
addValue();
fire(new ChangeListener.ChangeEvent());
} else if (keycode == Keys.DOWN) {
subtractValue();
fire(new ChangeListener.ChangeEvent());
}
return false;
}
});
textField.setTextFieldFilter(new TextField.TextFieldFilter() {
@Override
public boolean acceptChar(TextField textField1, char c) {
boolean returnValue = false;
if ((c >= 48 && c <= 57) || c == 45 || (!rounding && c == 46)) {
String text = textField1.getText();
if (textField1.getCursorPosition() <= text.length()) {
text = text.substring(0, textField1.getCursorPosition());
text += c + textField1.getText().substring(textField1.getCursorPosition());
}
if (text.matches("-?\\d*\\.?\\d*")) {
returnValue = true;
}
}
return returnValue;
}
});
updateText();
if (null != orientation)
switch(orientation) {
case HORIZONTAL:
add(buttonMinus);
add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
add(buttonPlus);
break;
case HORIZONTAL_FLIPPED:
add(buttonPlus);
add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
add(buttonMinus);
break;
case VERTICAL:
add(buttonPlus);
row();
add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
row();
add(buttonMinus);
break;
case VERTICAL_FLIPPED:
add(buttonMinus);
row();
add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
row();
add(buttonPlus);
break;
case RIGHT_STACK:
{
add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
VerticalGroup group = new VerticalGroup();
add(group);
group.addActor(buttonPlus);
group.addActor(buttonMinus);
break;
}
case LEFT_STACK:
{
VerticalGroup group = new VerticalGroup();
add(group);
group.addActor(buttonPlus);
group.addActor(buttonMinus);
add(textField).prefWidth(35.0f).minWidth(35.0f).growX();
break;
}
default:
break;
}
buttonMinus.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
subtractValue();
}
});
buttonPlus.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
addValue();
}
});
textField.addListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
Spinner parent = (Spinner) actor;
String text = textField.getText();
if (text.matches("\\-?(\\d+\\.?\\d*)|(\\.\\d+)")) {
double value = Double.parseDouble(text);
if (usingMinimum && value < parent.minimum) {
value = parent.minimum;
} else if (usingMaximum && value > parent.maximum) {
value = parent.maximum;
}
parent.value = BigDecimal.valueOf(value);
} else {
parent.value = BigDecimal.valueOf(usingMinimum ? parent.minimum : 0);
}
}
});
textField.addListener(new FocusListener() {
@Override
public void keyboardFocusChanged(FocusListener.FocusEvent event, Actor actor, boolean focused) {
Spinner parent = (Spinner) textField.getParent();
if (usingMinimum && parent.value.doubleValue() < parent.minimum) {
parent.value = BigDecimal.valueOf(parent.minimum);
}
if (usingMaximum && parent.value.doubleValue() > parent.maximum) {
parent.value = BigDecimal.valueOf(parent.maximum);
}
parent.updateText();
}
});
final Spinner spinner = this;
addCaptureListener(new ChangeListener() {
@Override
public void changed(ChangeListener.ChangeEvent event, Actor actor) {
event.setTarget(spinner);
}
});
}
Aggregations