Search in sources :

Example 11 with CheckBox

use of com.badlogic.gdx.scenes.scene2d.ui.CheckBox in project libgdx by libgdx.

the class UITest method create.

@Override
public void create() {
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    texture1 = new Texture(Gdx.files.internal("data/badlogicsmall.jpg"));
    texture2 = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    TextureRegion image = new TextureRegion(texture1);
    TextureRegion imageFlipped = new TextureRegion(image);
    imageFlipped.flip(true, true);
    TextureRegion image2 = new TextureRegion(texture2);
    // stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false, new PolygonSpriteBatch());
    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);
    // Group.debug = true;
    ImageButtonStyle style = new ImageButtonStyle(skin.get(ButtonStyle.class));
    style.imageUp = new TextureRegionDrawable(image);
    style.imageDown = new TextureRegionDrawable(imageFlipped);
    ImageButton iconButton = new ImageButton(style);
    Button buttonMulti = new TextButton("Multi\nLine\nToggle", skin, "toggle");
    Button imgButton = new Button(new Image(image), skin);
    Button imgToggleButton = new Button(new Image(image), skin, "toggle");
    Label myLabel = new Label("this is some text.", skin);
    myLabel.setWrap(true);
    Table t = new Table();
    t.row();
    t.add(myLabel);
    t.layout();
    final CheckBox checkBox = new CheckBox(" Continuous rendering", skin);
    checkBox.setChecked(true);
    final Slider slider = new Slider(0, 10, 1, false, skin);
    slider.setAnimateDuration(0.3f);
    TextField textfield = new TextField("", skin);
    textfield.setMessageText("Click here!");
    textfield.setAlignment(Align.center);
    final SelectBox selectBox = new SelectBox(skin);
    selectBox.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            System.out.println(selectBox.getSelected());
        }
    });
    selectBox.setItems("Android1", "Windows1 long text in item", "Linux1", "OSX1", "Android2", "Windows2", "Linux2", "OSX2", "Android3", "Windows3", "Linux3", "OSX3", "Android4", "Windows4", "Linux4", "OSX4", "Android5", "Windows5", "Linux5", "OSX5", "Android6", "Windows6", "Linux6", "OSX6", "Android7", "Windows7", "Linux7", "OSX7");
    selectBox.setSelected("Linux6");
    Image imageActor = new Image(image2);
    ScrollPane scrollPane = new ScrollPane(imageActor);
    List list = new List(skin);
    list.setItems(listEntries);
    list.getSelection().setMultiple(true);
    list.getSelection().setRequired(false);
    // list.getSelection().setToggle(true);
    ScrollPane scrollPane2 = new ScrollPane(list, skin);
    scrollPane2.setFlickScroll(false);
    SplitPane splitPane = new SplitPane(scrollPane, scrollPane2, false, skin, "default-horizontal");
    fpsLabel = new Label("fps:", skin);
    // configures an example of a TextField in password mode.
    final Label passwordLabel = new Label("Textfield in password mode: ", skin);
    final TextField passwordTextField = new TextField("", skin);
    passwordTextField.setMessageText("password");
    passwordTextField.setPasswordCharacter('*');
    passwordTextField.setPasswordMode(true);
    buttonMulti.addListener(new TextTooltip("This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip! This is a tooltip!", skin));
    Table tooltipTable = new Table(skin);
    tooltipTable.pad(10).background("default-round");
    tooltipTable.add(new TextButton("Fancy tooltip!", skin));
    imgButton.addListener(new Tooltip(tooltipTable));
    // window.debug();
    Window window = new Window("Dialog", skin);
    window.getTitleTable().add(new TextButton("X", skin)).height(window.getPadTop());
    window.setPosition(0, 0);
    window.defaults().spaceBottom(10);
    window.row().fill().expandX();
    window.add(iconButton);
    window.add(buttonMulti);
    window.add(imgButton);
    window.add(imgToggleButton);
    window.row();
    window.add(checkBox);
    window.add(slider).minWidth(100).fillX().colspan(3);
    window.row();
    window.add(selectBox).maxWidth(100);
    window.add(textfield).minWidth(100).expandX().fillX().colspan(3);
    window.row();
    window.add(splitPane).fill().expand().colspan(4).maxHeight(200);
    window.row();
    window.add(passwordLabel).colspan(2);
    window.add(passwordTextField).minWidth(100).expandX().fillX().colspan(2);
    window.row();
    window.add(fpsLabel).colspan(4);
    window.pack();
    // stage.addActor(new Button("Behind Window", skin));
    stage.addActor(window);
    textfield.setTextFieldListener(new TextFieldListener() {

        public void keyTyped(TextField textField, char key) {
            if (key == '\n')
                textField.getOnscreenKeyboard().show(false);
        }
    });
    slider.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            Gdx.app.log("UITest", "slider: " + slider.getValue());
        }
    });
    iconButton.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            new Dialog("Some Dialog", skin, "dialog") {

                protected void result(Object object) {
                    System.out.println("Chosen: " + object);
                }
            }.text("Are you enjoying this demo?").button("Yes", true).button("No", false).key(Keys.ENTER, true).key(Keys.ESCAPE, false).show(stage);
        }
    });
    checkBox.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            Gdx.graphics.setContinuousRendering(checkBox.isChecked());
        }
    });
}
Also used : Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) SplitPane(com.badlogic.gdx.scenes.scene2d.ui.SplitPane) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) List(com.badlogic.gdx.scenes.scene2d.ui.List) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) ButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) Tooltip(com.badlogic.gdx.scenes.scene2d.ui.Tooltip) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 12 with CheckBox

use of com.badlogic.gdx.scenes.scene2d.ui.CheckBox in project libgdx by libgdx.

the class TableTest method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    TextureRegion region = new TextureRegion(texture);
    NinePatch patch = skin.getPatch("default-round");
    Label label = new Label("This is some text.", skin);
    root = new Table() {

        public void draw(Batch batch, float parentAlpha) {
            super.draw(batch, parentAlpha);
        }
    };
    stage.addActor(root);
    // root.setTransform(true);
    Table table = new Table();
    table.setTransform(true);
    table.setPosition(100, 100);
    table.setOrigin(0, 0);
    table.setRotation(45);
    table.setScaleY(2);
    table.add(label);
    table.add(new TextButton("Text Button", skin));
    table.pack();
    // table.debug();
    table.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            System.out.println("click!");
        }
    });
    //		root.addActor(table);
    TextButton button = new TextButton("Text Button", skin);
    Table table2 = new Table();
    // table2.debug()
    table2.add(button);
    table2.setTransform(true);
    table2.setScaleX(1.5f);
    table2.setOrigin(table2.getPrefWidth() / 2, table2.getPrefHeight() / 2);
    // Test colspan with expandX.
    // root.setPosition(10, 10);
    root.debug();
    root.setFillParent(true);
    root.add(new Label("meow meow meow meow meow meow meow meow meow meow meow meow", skin)).colspan(3).expandX();
    root.add(new TextButton("Text Button", skin));
    root.row();
    root.add(new TextButton("Text Button", skin));
    root.add(new TextButton("Toggle Button", skin.get("toggle", TextButtonStyle.class)));
    root.add(new CheckBox("meow meow meow meow meow meow meow meow", skin));
// root.pack();
// root.add(new Button(new Image(region), skin));
// root.add(new LabelButton("Toggley", skin.getStyle("toggle", LabelButtonStyle.class)));
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Batch(com.badlogic.gdx.graphics.g2d.Batch) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 13 with CheckBox

use of com.badlogic.gdx.scenes.scene2d.ui.CheckBox in project ProjektGG by eskalon.

the class LobbyCreationScreen method initUI.

@Override
protected void initUI() {
    backgroundTexture = assetManager.get(BACKGROUND_IMAGE_PATH);
    Sound clickSound = assetManager.get(BUTTON_SOUND);
    Label nameLabel = new Label("Name: ", skin);
    Label portLabel = new Label("Port: ", skin);
    TextField nameField = new TextField("", skin);
    TextField portField = new TextField("55789", skin);
    portField.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
    Label difficultyLabel = new Label("Schwierigkeit: ", skin);
    CheckBox easyDifficultyCheckbox = new CheckBox("Einfach", skin);
    CheckBox normalDifficultyCheckbox = new CheckBox("Normal", skin);
    CheckBox hardDifficultyCheckbox = new CheckBox("Schwer", skin);
    ButtonGroup speedGroup = new ButtonGroup();
    speedGroup.add(easyDifficultyCheckbox);
    speedGroup.add(normalDifficultyCheckbox);
    speedGroup.add(hardDifficultyCheckbox);
    normalDifficultyCheckbox.setChecked(true);
    ImageTextButton backButton = new ImageTextButton("Zur�ck", skin);
    backButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            game.pushScreen("serverBrowser");
            clickSound.play(1F);
            return true;
        }
    });
    ImageTextButton createButton = new ImageTextButton("Erstellen", skin);
    createButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (!nameField.getText().isEmpty() && !portField.getText().isEmpty()) {
                clickSound.play(1F);
                GameDifficulty difficulty = GameDifficulty.NORMAL;
                if (speedGroup.getChecked().equals(easyDifficultyCheckbox)) {
                    difficulty = GameDifficulty.EASY;
                } else if (speedGroup.getChecked().equals(normalDifficultyCheckbox)) {
                    difficulty = GameDifficulty.NORMAL;
                } else if (speedGroup.getChecked().equals(hardDifficultyCheckbox)) {
                    difficulty = GameDifficulty.HARD;
                }
                // Sever & Client starten
                game.getNetworkHandler().setUpConnectionAsHost(Integer.valueOf(portField.getText()), new GameSessionSetup(difficulty, GameMap.getMaps().get("Bamberg"), System.currentTimeMillis()));
                connectingDialog = new Dialog("Starten...", skin);
                connectingDialog.text("Server startet...");
                connectingDialog.show(stage);
            } else {
                Dialog dialog = new Dialog("Felder unausgef�llt", skin);
                dialog.text("Zum Starten m�ssen alle Felder ausgef�llt sein");
                dialog.button("Ok", true);
                dialog.key(Keys.ENTER, true);
                dialog.show(stage);
            }
            return true;
        }
    });
    Table settingsTable = new Table();
    Table settings2ColTable = new Table();
    Table settings3ColTable = new Table();
    Table buttonTable = new Table();
    settings2ColTable.add(nameLabel).padBottom(30);
    settings2ColTable.add(nameField).padBottom(30).row();
    settings2ColTable.add(portLabel);
    settings2ColTable.add(portField).row();
    settings3ColTable.add(difficultyLabel).colspan(3).row();
    settings3ColTable.add(easyDifficultyCheckbox);
    settings3ColTable.add(normalDifficultyCheckbox);
    settings3ColTable.add(hardDifficultyCheckbox);
    settingsTable.left().top().add(settings2ColTable).padBottom(40).row();
    settingsTable.add(settings3ColTable).row();
    buttonTable.add(backButton);
    buttonTable.add(createButton).padLeft(65);
    mainTable.add(settingsTable).width(580).height(405);
    mainTable.row();
    mainTable.add(buttonTable).height(50).bottom();
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) GameDifficulty(de.gg.data.GameSessionSetup.GameDifficulty) Sound(com.badlogic.gdx.audio.Sound) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) ButtonGroup(com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup) GameSessionSetup(de.gg.data.GameSessionSetup) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Aggregations

CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)13 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)10 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)9 Stage (com.badlogic.gdx.scenes.scene2d.Stage)6 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)6 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)5 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)4 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)4 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)4 Texture (com.badlogic.gdx.graphics.Texture)3 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)3 ImageTextButton (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton)3 List (com.badlogic.gdx.scenes.scene2d.ui.List)3 Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)3 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)3 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)3 Batch (com.badlogic.gdx.graphics.g2d.Batch)2 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)2