use of com.badlogic.gdx.scenes.scene2d.ui.Label in project AmazingMaze by TheVirtualMachine.
the class StoryScreen method setupUI.
/** Helper method to setup the UI. */
private void setupUI() {
stage = new Stage(new ScreenViewport(), game.batch);
table = new Table();
table.top().center();
table.setFillParent(true);
stage.addActor(table);
header = new Label("Story", game.assets.skin, Assets.SERIF_HEADER_STYLE);
table.add(header).padTop(Gdx.graphics.getHeight() / 25f);
storyLabel = new Label(readStory(), game.assets.skin, Assets.STORY_STYLE);
storyLabel.setWrap(true);
table.row();
table.add(storyLabel).maxWidth(Gdx.graphics.getWidth()).prefWidth(Gdx.graphics.getWidth() / 1.125f).pad(Gdx.graphics.getHeight() / 25f);
continueButton = new TextButton("Continue...", game.assets.skin);
continueButton.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
if (continueButton.isPressed()) {
game.setScreen(new MazeScreen(game, false));
}
}
});
table.row();
table.add(continueButton).width(Gdx.graphics.getWidth() / 4f).pad(Gdx.graphics.getHeight() / 25f).expandY().bottom().fillY();
}
use of com.badlogic.gdx.scenes.scene2d.ui.Label in project gdx-skineditor by cobolfoo.
the class PreviewPane method refresh.
/**
*
*/
public void refresh() {
Gdx.app.log("PreviewPane", "Refresh pane!");
clear();
ImageButton button = (ImageButton) game.screenMain.barWidgets.group.getChecked();
String widget = button.getUserObject().toString();
String widgetStyle = "com.badlogic.gdx.scenes.scene2d.ui." + widget + "$" + widget + "Style";
try {
Class<?> style = Class.forName(widgetStyle);
ObjectMap<String, ?> styles = game.skinProject.getAll(style);
if (styles == null) {
Label label = new Label("No styles defined for this widget type", game.skin, "error");
add(label).row().pad(10);
} else {
Keys<String> keys = styles.keys();
Array<String> sortedKeys = new Array<String>();
for (String key : keys) {
sortedKeys.add(key);
}
sortedKeys.sort();
for (String key : sortedKeys) {
// We render one per key
add(new Label(key, game.skin, "title")).left().pad(10).expandX().row();
try {
if (widget.equals("Label")) {
Label w = new Label("This is a Label widget", game.skinProject, key);
add(w).pad(10).padBottom(20).row();
} else if (widget.equals("Button")) {
// Button
Button w = new Button(game.skinProject, key);
add(w).width(120).height(32).pad(10).padBottom(20).row();
} else if (widget.equals("TextButton")) {
// TextButton
TextButton w = new TextButton("This is a TextButton widget", game.skinProject, key);
add(w).pad(10).padBottom(20).row();
} else if (widget.equals("ImageButton")) {
// ImageButton
ImageButton w = new ImageButton(game.skinProject, key);
add(w).pad(10).padBottom(20).row();
} else if (widget.equals("CheckBox")) {
// CheckBox
CheckBox w = new CheckBox("This is a CheckBox widget", game.skinProject, key);
w.setChecked(true);
add(w).pad(10).padBottom(20).row();
} else if (widget.equals("TextField")) {
// TextField
TextField w = new TextField("This is a TextField widget", game.skinProject, key);
if (w.getStyle().fontColor == null) {
throw new Exception("Textfield style requires a font color!");
}
w.addListener(stopTouchDown);
add(w).pad(10).width(220).padBottom(20).row();
} else if (widget.equals("List")) {
// List
List w = new List(game.skinProject, key);
Array<String> items = new Array<String>();
items.add("This is");
items.add("a");
items.add("List widget!");
w.setItems(items);
add(w).pad(10).width(220).height(120).padBottom(20).expandX().fillX().row();
} else if (widget.equals("SelectBox")) {
// SelectBox
SelectBox<String> w = new SelectBox<String>(game.skinProject, key);
Array<String> items = new Array<String>();
items.add("This is");
items.add("a");
items.add("SelectBox widget!");
w.setItems(items);
add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
} else if (widget.equals("ProgressBar")) {
// ProgressBar
ProgressBarStyle progressStyle = game.skinProject.get(key, ProgressBarStyle.class);
// Check for edge-case: fields knob and knobBefore are optional but at least one should be specified
if (progressStyle.knob == null && progressStyle.knobBefore == null) {
throw new IllegalArgumentException("Fields 'knob' and 'knobBefore' in ProgressBarStyle are both optional but at least one should be specified");
}
ProgressBar w = new ProgressBar(0, 100, 5, false, progressStyle);
w.setValue(50);
w.addListener(stopTouchDown);
add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
} else if (widget.equals("Slider")) {
// Slider
Slider w = new Slider(0, 100, 5, false, game.skinProject, key);
add(w).pad(10).width(220).padBottom(20).expandX().fillX().row();
w.addListener(stopTouchDown);
Slider w2 = new Slider(0, 100, 5, true, game.skinProject, key);
add(w2).pad(10).padBottom(20).expandX().fillX().row();
w2.addListener(stopTouchDown);
} else if (widget.equals("ScrollPane")) {
// ScrollPane
Table t = new Table(game.skin);
for (int i = 0; i < 20; i++) {
t.add("This is a ScrollPane Widget").padRight(10);
t.add("This is a ScrollPane Widget").padRight(10);
t.add("This is a ScrollPane Widget").row();
}
ScrollPane w = new ScrollPane(t, game.skinProject, key);
w.addListener(stopTouchDown);
w.setFlickScroll(true);
w.setScrollbarsOnTop(true);
w.setScrollBarPositions(true, true);
w.setFadeScrollBars(false);
add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
} else if (widget.equals("SplitPane")) {
for (int j = 0; j < 2; j++) {
Table t = new Table(game.skin);
t.setBackground(game.skin.getDrawable("default-rect"));
Table t2 = new Table(game.skin);
t2.setBackground(game.skin.getDrawable("default-rect"));
for (int i = 0; i < 20; i++) {
t.add("This is a SplitPane Widget").pad(10).row();
t2.add("This is a SplitPane Widget").pad(10).row();
}
SplitPane w = new SplitPane(t, t2, (j % 2 == 0), game.skinProject, key);
w.addListener(stopTouchDown);
add(w).pad(10).width(220).height(160).padBottom(20).expandX().fillX();
}
row();
} else if (widget.equals("Window")) {
// Window
Table t = new Table(game.skin);
for (int i = 0; i < 5; i++) {
t.add("This is a Window Widget").row();
}
Window w = new Window("This is a Window Widget", game.skinProject, key);
w.addListener(stopTouchDown);
w.add(t);
add(w).pad(10).width(420).height(240).padBottom(20).expandX().fillX().row();
} else if (widget.equals("Touchpad")) {
// Touchpad
Touchpad w = new Touchpad(0, game.skinProject, key);
w.addListener(stopTouchDown);
add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
} else if (widget.equals("Tree")) {
// Tree
Tree w = new Tree(game.skinProject, key);
Tree.Node node = new Tree.Node(new Label("This", game.skin));
Tree.Node node1 = new Tree.Node(new Label("is", game.skin));
Tree.Node node2 = new Tree.Node(new Label("a", game.skin));
Tree.Node node3 = new Tree.Node(new Label("Tree", game.skin));
Tree.Node node4 = new Tree.Node(new Label("Widget", game.skin));
node3.add(node4);
node2.add(node3);
node1.add(node2);
node.add(node1);
w.add(node);
w.expandAll();
add(w).pad(10).width(200).height(200).padBottom(20).expandX().fillX().row();
} else {
add(new Label("Unknown widget type!", game.skin, "error")).pad(10).padBottom(20).row();
}
} catch (Exception e) {
add(new Label("Please fill all required fields", game.skin, "error")).pad(10).padBottom(20).row();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.badlogic.gdx.scenes.scene2d.ui.Label in project gdx-skineditor by cobolfoo.
the class Tooltips method showTooltip.
public void showTooltip(Actor actor) {
Vector2 v = new Vector2();
actor.localToStageCoordinates(v);
if (tooltip == null) {
LabelStyle style = new LabelStyle();
style.font = tooltipStyle.font;
style.background = tooltipStyle.background;
style.fontColor = tooltipStyle.fontColor;
tooltip = new Label(tooltips.get(actor), style);
tooltip.setStyle(style);
tooltip.pack();
tooltip.setPosition(v.x + 7.5f, v.y - tooltip.getPrefHeight() - 15);
tooltip.setOriginY(tooltip.getPrefHeight());
tooltip.setColor(1, 1, 1, 0);
tooltip.setScale(1, 0);
tooltip.addAction(parallel(fadeIn(0.15f), scaleTo(1, 1, 0.15f)));
} else {
tooltip.setText(tooltips.get(actor));
tooltip.pack();
tooltip.setPosition(v.x + 7.5f, v.y - tooltip.getPrefHeight() - 15);
}
stage.addActor(tooltip);
}
use of com.badlogic.gdx.scenes.scene2d.ui.Label in project commons-gdx by gemserk.
the class Actors method twoOptionsDialog.
public static Actor twoOptionsDialog(String[] texts, final DialogListener dialogListener, String titleText, String firstOption, String secondOption, Skin skin) {
Window window = new Window(titleText, skin);
window.setMovable(false);
TextButton firstOptionButton = new TextButton(firstOption, skin);
TextButton secondOptionButton = new TextButton(secondOption, 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);
}
});
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();
window.add(firstOptionButton).align(Align.center).padLeft(20).padRight(20).expandX();
window.add(secondOptionButton).align(Align.center).padLeft(20).padRight(20).expandX();
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.Label in project libgdx by libgdx.
the class ProjectiveTextureTest method setupUI.
public void setupUI() {
ui = new Stage();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
TextButton reload = new TextButton("Reload Shaders", skin.get(TextButtonStyle.class));
camera = new SelectBox(skin.get(SelectBoxStyle.class));
camera.setItems("Camera", "Light");
fps = new Label("fps: ", skin.get(LabelStyle.class));
Table table = new Table();
table.setFillParent(true);
table.top().padTop(15);
table.add(reload).spaceRight(5);
table.add(camera).spaceRight(5);
table.add(fps);
ui.addActor(table);
reload.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
ShaderProgram prog = new ShaderProgram(Gdx.files.internal("data/shaders/projtex-vert.glsl").readString(), Gdx.files.internal("data/shaders/projtex-frag.glsl").readString());
if (prog.isCompiled() == false) {
Gdx.app.log("GLSL ERROR", "Couldn't reload shaders:\n" + prog.getLog());
} else {
projTexShader.dispose();
projTexShader = prog;
}
}
});
}
Aggregations