use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project libgdx by libgdx.
the class ViewportTest1 method create.
public void create() {
stage = new Stage();
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
label = new Label("", skin);
Table root = new Table(skin);
root.setFillParent(true);
root.setBackground(skin.getDrawable("default-pane"));
root.debug().defaults().space(6);
root.add(new TextButton("Button 1", skin));
root.add(new TextButton("Button 2", skin)).row();
root.add("Press spacebar to change the viewport:").colspan(2).row();
root.add(label).colspan(2);
stage.addActor(root);
viewports = getViewports(stage.getCamera());
names = getViewportNames();
stage.setViewport(viewports.first());
label.setText(names.first());
Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {
public boolean keyDown(int keycode) {
if (keycode == Input.Keys.SPACE) {
int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size;
label.setText(names.get(index));
Viewport viewport = viewports.get(index);
stage.setViewport(viewport);
resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
return false;
}
}, stage));
}
use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project libgdx by libgdx.
the class TextButtonTest method create.
@Override
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
for (int i = 0; i < 1; i++) {
TextButton t = new TextButton("Button" + i, skin);
t.setX(MathUtils.random(0, Gdx.graphics.getWidth()));
t.setY(MathUtils.random(0, Gdx.graphics.getHeight()));
t.setWidth(MathUtils.random(50, 200));
t.setHeight(MathUtils.random(0, 100));
stage.addActor(t);
}
}
use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project libgdx by libgdx.
the class SoundTest method create.
@Override
public void create() {
sound = Gdx.audio.newSound(Gdx.files.getFileHandle("data/shotgun.ogg", FileType.Internal));
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
ui = new Stage();
TextButton play = new TextButton("Play", skin);
TextButton stop = new TextButton("Stop", skin);
final Slider pitch = new Slider(0.1f, 4, 0.1f, false, skin);
pitch.setValue(1);
final Label pitchValue = new Label("1.0", skin);
final Slider volume = new Slider(0.1f, 1, 0.1f, false, skin);
volume.setValue(1);
final Label volumeValue = new Label("1.0", skin);
Table table = new Table();
final Slider pan = new Slider(-1f, 1f, 0.1f, false, skin);
pan.setValue(0);
final Label panValue = new Label("0.0", skin);
table.setFillParent(true);
table.align(Align.center | Align.top);
table.columnDefaults(0).expandX().right().uniformX();
table.columnDefaults(2).expandX().left().uniformX();
table.add(play);
table.add(stop).left();
table.row();
table.add(new Label("Pitch", skin));
table.add(pitch);
table.add(pitchValue);
table.row();
table.add(new Label("Volume", skin));
table.add(volume);
table.add(volumeValue);
table.row();
table.add(new Label("Pan", skin));
table.add(pan);
table.add(panValue);
ui.addActor(table);
play.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
soundId = sound.play(volume.getValue());
sound.setPitch(soundId, pitch.getValue());
sound.setPan(soundId, pan.getValue(), volume.getValue());
}
});
stop.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
sound.stop(soundId);
}
});
pitch.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
sound.setPitch(soundId, pitch.getValue());
pitchValue.setText("" + pitch.getValue());
}
});
volume.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
sound.setVolume(soundId, volume.getValue());
volumeValue.setText("" + volume.getValue());
}
});
pan.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
sound.setPan(soundId, pan.getValue(), volume.getValue());
panValue.setText("" + pan.getValue());
}
});
Gdx.input.setInputProcessor(ui);
}
use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project commons-gdx by gemserk.
the class Actors method threeOptionsDialog.
public static Actor threeOptionsDialog(String[] texts, final DialogListener dialogListener, String titleText, String firstOption, String secondOption, String thirdOption, Skin skin) {
Window window = new Window(titleText, skin);
window.setMovable(false);
TextButton firstOptionButton = new TextButton(firstOption, skin);
TextButton secondOptionButton = new TextButton(secondOption, skin);
TextButton thirdOptionButton = new TextButton(thirdOption, skin);
firstOptionButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
dialogListener.optionSelected(0);
}
});
secondOptionButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
dialogListener.optionSelected(1);
}
});
thirdOptionButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
dialogListener.optionSelected(2);
}
});
window.defaults().spaceBottom(10);
window.row().fill().expandX();
for (int i = 0; i < texts.length; i++) {
window.row().padLeft(20);
Label label = new Label(texts[i], skin);
label.setWrap(true);
window.add(label).align(Align.left).colspan(2).fillX();
}
window.row().fill().expandX().padTop(10);
window.add(firstOptionButton).align(Align.center).padLeft(30).padRight(30);
window.row().fill().expandX();
window.add(secondOptionButton).align(Align.center).padLeft(30).padRight(30);
window.row().fill().expandX();
window.add(thirdOptionButton).align(Align.center).padLeft(30).padRight(30);
ScrollPane scrollPane = new ScrollPane(window);
scrollPane.setWidth(Gdx.graphics.getWidth() * 0.95f);
scrollPane.setHeight(Gdx.graphics.getHeight() * 0.95f);
scrollPane.setX(Gdx.graphics.getWidth() * 0.5f - scrollPane.getWidth() * 0.5f);
scrollPane.setY(Gdx.graphics.getHeight() * 0.5f - scrollPane.getHeight() * 0.5f);
return scrollPane;
}
use of com.badlogic.gdx.scenes.scene2d.ui.TextButton in project AmazingMaze by TheVirtualMachine.
the class FishMiniGame method dialog.
/**
* Displays the results dialog.
*/
public void dialog() {
message = formatString(answerField.getText());
Label.LabelStyle labelStyle = new Label.LabelStyle(game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE);
final Dialog dialog = new Dialog("Results", game.assets.skin);
final TextButton okButton = new TextButton("OK", game.assets.skin);
dialog.getButtonTable().bottom();
if (checkAnswer() == -1) {
Label label = new Label("Invalid answer. Please try again.", labelStyle);
label.setScale(.5f);
label.setWrap(true);
label.setAlignment(Align.center);
dialog.add(label).width(500).pad(50);
dialog.add(okButton).bottom();
okButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (okButton.isPressed()) {
dialog.hide();
canvas.setColor(drawColor);
}
}
});
dialog.addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Keys.ENTER) {
dialog.hide();
return true;
}
return false;
}
});
} else {
Label label = new Label("Your answer was: " + message + ". " + "The correct answer was: " + answer + ". " + "You get " + checkAnswer() + " back!", labelStyle);
game.save.addScore(checkAnswer());
game.save.setLives(player.getLives());
label.setScale(.5f);
label.setWrap(true);
label.setAlignment(Align.center);
dialog.add(label).width(500).pad(50);
dialog.add(okButton).bottom();
okButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (okButton.isPressed()) {
dialog.cancel();
if ((game.save.getLevel() - 1) % 5 == 0) {
game.setScreen(new ContinueScreen(game, true));
} else {
game.setScreen(new MazeScreen(game, false));
}
}
}
});
dialog.addListener(new InputListener() {
@Override
public boolean keyDown(InputEvent event, int keycode) {
if (keycode == Keys.ENTER) {
if ((game.save.getLevel() - 1) % 5 == 0) {
game.setScreen(new ContinueScreen(game, true));
} else {
game.setScreen(new MazeScreen(game, false));
}
return true;
}
return false;
}
});
}
dialog.show(stage);
}
Aggregations