Example usage for com.badlogic.gdx.scenes.scene2d.ui ImageTextButton ImageTextButton

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui ImageTextButton ImageTextButton

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui ImageTextButton ImageTextButton.

Prototype

public ImageTextButton(String text, ImageTextButtonStyle style) 

Source Link

Usage

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createScoreLayer() {
    Stage stage = new Stage();
    Table table = new Table();
    BitmapFont font = new BitmapFont();
    font.scale(2);/*w  w w  . j a  va  2  s.com*/
    Button button;

    Skin skin = new Skin();
    skin.add("bluebox", new Texture("textures/bluebox.jpg"));
    skin.add("greenbox", new Texture("textures/greenbox.jpg"));
    skin.add("redbox", new Texture("textures/redbox2.jpg"));

    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("redbox"),
            skin.getDrawable("greenbox"), skin.getDrawable("bluebox"), font);

    button = new ImageTextButton("0", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    table.add(button).pad(5).center();

    table.pack();
    table.setPosition(Gdx.graphics.getWidth() / 2 - table.getWidth() / 2,
            Gdx.graphics.getHeight() - table.getHeight());
    stage.addActor(table);

    Global.scoreButton = button;
    return new Layer("scoreLayer", stage);
}

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createFireLayer() {
    Stage stage = new Stage(new StretchViewport(640, 480));
    Table table = new Table();
    BitmapFont font = new BitmapFont();
    Button button;//from w ww .ja  v  a  2 s  .  c om

    Skin skin = new Skin();
    skin.add("bluebox", new Texture("textures/bluebox.jpg"));
    skin.add("greenbox", new Texture("textures/greenbox.jpg"));
    skin.add("redbox", new Texture("textures/redbox.jpg"));

    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("redbox"),
            skin.getDrawable("greenbox"), skin.getDrawable("bluebox"), font);

    button = new ImageTextButton("Fire", style);
    button.setHeight(50);
    button.setWidth(50);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new InputListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            Gdx.input.getInputProcessor().keyDown(Keys.SPACE);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            Gdx.input.getInputProcessor().keyUp(Keys.SPACE);
        }

    });
    table.add(button).pad(50).center();

    table.pack();
    table.setPosition(640 - table.getWidth(), 0);
    stage.addActor(table);

    Engine.inputManager.add(stage);
    return new Layer("fireLayer", stage);
}

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createJoystickLayer() {
    Stage stage = new Stage(new StretchViewport(1280, 720));
    Table table = new Table();
    MyListener listener = new MyListener();
    BitmapFont font = new BitmapFont();
    Button button;/*from  w  w w  .j ava2s  .c o  m*/

    Skin skin = new Skin();
    skin.add("cirlce", new Texture("textures/circle.png"));
    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("cirlce"),
            skin.getDrawable("cirlce"), skin.getDrawable("cirlce"), font);

    button = new ImageTextButton("Move", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new MoveListener());
    table.add(button).pad(50).expandX().left();

    button = new ImageTextButton("Fire", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(listener);
    table.add(button).pad(50).bottom().right();

    table.setDebug(true);
    table.setFillParent(true);
    table.bottom().left();
    stage.addActor(table);

    Engine.inputManager.add(stage);
    return new Layer("joystickLayer", stage);
}

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createJoystickControlLayer() {
    Stage stage = new Stage(new StretchViewport(1280, 720));
    Table table = new Table();
    BitmapFont font = new BitmapFont();
    Button button;//from   w w  w  .ja va  2  s  .  c  o  m

    Skin skin = new Skin();
    skin.add("cirlce", new Texture("textures/circle.png"));
    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("cirlce"),
            skin.getDrawable("cirlce"), skin.getDrawable("cirlce"), font);

    button = new ImageTextButton("Debug Options", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            Engine.game.setScreen(Engine.screens.get("debug"));
            return false;
        }
    });
    table.add(button).pad(50).padLeft(100).expandX().left();
    table.row();

    button = new ImageTextButton("L Boost", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(true, false, true));
    table.add(button).pad(50).padLeft(100).expandX().left();

    button = new ImageTextButton("R Boost", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(false, true, true));
    table.add(button).pad(50).padRight(100).bottom().right();
    table.row();

    button = new ImageTextButton("Left", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(true, false, false));
    table.add(button).pad(50).padLeft(100).expandX().left();

    button = new ImageTextButton("Right", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(false, true, false));
    table.add(button).pad(50).padRight(100).bottom().right();

    //        table.setDebug(true);
    table.setFillParent(true);
    table.bottom().left();
    stage.addActor(table);

    if (Engine.systemManager.has(OrbitCameraSystem.class)
            && Engine.systemManager.get(OrbitCameraSystem.class).mouseListener) {
        InputProcessor tmp = Engine.systemManager.get(OrbitCameraSystem.class).orbitCameraController;
        Engine.inputManager.remove(tmp);
        Engine.inputManager.add(stage);
        Engine.inputManager.add(tmp);
    } else {
        Engine.inputManager.add(stage);
    }

    return new Layer("controlLayer", stage);
}

From source file:com.blastedstudios.gdxworld.util.ui.Scene2DUtils.java

License:Apache License

/** creates a {@link Button} according to the given {@link ButtonStyle} instance that may be {@link ButtonStyle}, {@link TextButtonStyle}, {@link ImageButtonStyle} or {@link ImageTextButtonStyle} */
public static Button newButton(ButtonStyle style, String textIfAny) {
    if (style instanceof ImageTextButtonStyle)
        return new ImageTextButton(textIfAny, (ImageTextButtonStyle) style);
    if (style instanceof TextButtonStyle)
        return new TextButton(textIfAny, (TextButtonStyle) style);
    if (style instanceof ImageButtonStyle)
        return new ImageButton((ImageButtonStyle) style);
    return new Button(style);
}

From source file:com.eightpuzzle.game.EightPuzzle.java

License:Apache License

@Override
public void create() {
    gameFont = new BitmapFont();
    solvedFont = new BitmapFont();
    batch = new SpriteBatch();
    aspectRatio = (float) Gdx.graphics.getHeight() / (float) Gdx.graphics.getWidth();
    OrthographicCamera camera = new OrthographicCamera(GAME_WIDTH * aspectRatio, GAME_HEIGHT * aspectRatio);
    //camera.position.set(GAME_WIDTH/2, GAME_HEIGHT/2, 0)
    camera.setToOrtho(false, GAME_WIDTH * aspectRatio, GAME_HEIGHT * aspectRatio);
    //camera.setToOrtho(false,GAME_WIDTH,GAME_HEIGHT);
    stage = new Stage(new ExtendViewport(GAME_WIDTH * aspectRatio, GAME_HEIGHT * aspectRatio, camera));//Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera));
    Gdx.input.setInputProcessor(stage);// w  w  w .j av  a2 s .  c o m

    // A skin can be loaded via JSON or defined programmatically, either is fine. Using a skin is optional but strongly
    // recommended solely for the convenience of getting a texture, region, etc as a drawable, tinted drawable, etc.
    skin = new Skin();

    // Generate a 1x1 white texture and store it in the skin named "white".
    Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
    pixmap.setColor(Color.WHITE);
    pixmap.fill();
    skin.add("white", new Texture(pixmap));

    // Store the default libgdx font under the name "default".
    skin.add("default", new BitmapFont());

    // Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this doesn't overwrite the font.
    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
    //textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
    textButtonStyle.font = skin.getFont("default");
    skin.add("default", textButtonStyle);

    Label.LabelStyle labelSty = new Label.LabelStyle();
    labelSty.font = skin.getFont("default");
    //labelSty.fontColor = Color.GREEN;
    skin.add("default", labelSty);

    WindowStyle ws = new Window.WindowStyle();
    ws.titleFont = new BitmapFont();
    ws.background = skin.newDrawable("white", Color.BLACK);
    skin.add("default", ws);

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Zig.ttf"));

    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 25;
    gameFont = generator.generateFont(parameter);

    FreeTypeFontParameter parameter2 = new FreeTypeFontParameter();
    parameter2.size = 100;
    parameter2.color = Color.GREEN;
    solvedFont = generator.generateFont(parameter2);
    generator.dispose();

    FileHandle blue, n1, n2, n3, n4, n5, n6, n7, n8, solveUp, solveDown;
    if (Gdx.app.getType() == ApplicationType.Desktop) {
        blue = Gdx.files.internal("icons64px/blue-square.png");
        n1 = Gdx.files.internal("icons64px/Number-1-icon.png");
        n2 = Gdx.files.internal("icons64px/Number-2-icon.png");
        n3 = Gdx.files.internal("icons64px/Number-3-icon.png");
        n4 = Gdx.files.internal("icons64px/Number-4-icon.png");
        n5 = Gdx.files.internal("icons64px/Number-5-icon.png");
        n6 = Gdx.files.internal("icons64px/Number-6-icon.png");
        n7 = Gdx.files.internal("icons64px/Number-7-icon.png");
        n8 = Gdx.files.internal("icons64px/Number-8-icon.png");
        solveUp = blue;
        solveDown = blue;
    } else {
        blue = Gdx.files.internal("icons256px/blue-circle.png");
        n1 = Gdx.files.internal("icons256px/Number-1-icon.png");
        n2 = Gdx.files.internal("icons256px/Number-2-icon.png");
        n3 = Gdx.files.internal("icons256px/Number-3-icon.png");
        n4 = Gdx.files.internal("icons256px/Number-4-icon.png");
        n5 = Gdx.files.internal("icons256px/Number-5-icon.png");
        n6 = Gdx.files.internal("icons256px/Number-6-icon.png");
        n7 = Gdx.files.internal("icons256px/Number-7-icon.png");
        n8 = Gdx.files.internal("icons256px/Number-8-icon.png");
        solveUp = Gdx.files.internal("icons256px/Box_Green.png");
        solveDown = Gdx.files.internal("icons256px/rectangle_green.png");
    }
    Texture bSquare = new Texture(blue);
    Texture n1T = new Texture(n1);
    Texture n2T = new Texture(n2);
    Texture n3T = new Texture(n3);
    Texture n4T = new Texture(n4);
    Texture n5T = new Texture(n5);
    Texture n6T = new Texture(n6);
    Texture n7T = new Texture(n7);
    Texture n8T = new Texture(n8);

    TextureRegion bSquareReg = new TextureRegion(bSquare);
    TextureRegion n1Reg = new TextureRegion(n1T);
    TextureRegion n2Reg = new TextureRegion(n2T);
    TextureRegion n3Reg = new TextureRegion(n3T);
    TextureRegion n4Reg = new TextureRegion(n4T);
    TextureRegion n5Reg = new TextureRegion(n5T);
    TextureRegion n6Reg = new TextureRegion(n6T);
    TextureRegion n7Reg = new TextureRegion(n7T);
    TextureRegion n8Reg = new TextureRegion(n8T);

    TextureRegionDrawable solveDUp = new TextureRegionDrawable(new TextureRegion(new Texture(solveUp)));
    TextureRegionDrawable solveDDown = new TextureRegionDrawable(new TextureRegion(new Texture(solveDown)));
    ImageTextButton.ImageTextButtonStyle tbSty = new ImageTextButton.ImageTextButtonStyle(solveDUp, solveDDown,
            solveDUp, gameFont);
    skin.add("default", tbSty);

    ImageButtonStyle bSquareSty = new ImageButtonStyle();
    bSquareSty.imageUp = new TextureRegionDrawable(bSquareReg);
    bSquareSty.imageDown = new TextureRegionDrawable(bSquareReg);

    ImageButtonStyle n1Sty = new ImageButtonStyle();
    n1Sty.imageUp = new TextureRegionDrawable(n1Reg);
    n1Sty.imageDown = new TextureRegionDrawable(n1Reg);

    ImageButtonStyle n2Sty = new ImageButtonStyle();
    n2Sty.imageUp = new TextureRegionDrawable(n2Reg);
    n2Sty.imageDown = new TextureRegionDrawable(n2Reg);

    ImageButtonStyle n3Sty = new ImageButtonStyle();
    n3Sty.imageUp = new TextureRegionDrawable(n3Reg);
    n3Sty.imageDown = new TextureRegionDrawable(n3Reg);

    ImageButtonStyle n4Sty = new ImageButtonStyle();
    n4Sty.imageUp = new TextureRegionDrawable(n4Reg);
    n4Sty.imageDown = new TextureRegionDrawable(n4Reg);

    ImageButtonStyle n5Sty = new ImageButtonStyle();
    n5Sty.imageUp = new TextureRegionDrawable(n5Reg);
    n5Sty.imageDown = new TextureRegionDrawable(n5Reg);

    ImageButtonStyle n6Sty = new ImageButtonStyle();
    n6Sty.imageUp = new TextureRegionDrawable(n6Reg);
    n6Sty.imageDown = new TextureRegionDrawable(n6Reg);

    ImageButtonStyle n7Sty = new ImageButtonStyle();
    n7Sty.imageUp = new TextureRegionDrawable(n7Reg);
    n7Sty.imageDown = new TextureRegionDrawable(n7Reg);

    ImageButtonStyle n8Sty = new ImageButtonStyle();
    n8Sty.imageUp = new TextureRegionDrawable(n8Reg);
    n8Sty.imageDown = new TextureRegionDrawable(n8Reg);

    ImageButton b1 = new ImageButton(n1Sty);
    b1.addListener(new MyChangeListener(1));
    map.put(1, b1);

    ImageButton holeB = new ImageButton(bSquareSty);
    map.put(0, holeB);

    ImageButton ib = new ImageButton(n2Sty);
    ib.addListener(new MyChangeListener(2));
    map.put(2, ib);

    ImageButton b4 = new ImageButton(n3Sty);
    b4.addListener(new MyChangeListener(3));
    ImageButton b5 = new ImageButton(n4Sty);
    b5.addListener(new MyChangeListener(4));
    ImageButton b6 = new ImageButton(n5Sty);
    b6.addListener(new MyChangeListener(5));
    map.put(3, b4);
    map.put(4, b5);
    map.put(5, b6);

    ImageButton b7 = new ImageButton(n6Sty);
    b7.addListener(new MyChangeListener(6));
    ImageButton b8 = new ImageButton(n7Sty);
    b8.addListener(new MyChangeListener(7));
    ImageButton b9 = new ImageButton(n8Sty);
    b9.addListener(new MyChangeListener(8));
    map.put(6, b7);
    map.put(7, b8);
    map.put(8, b9);

    newGameB = new ImageTextButton("New Game", skin);
    newGameB.addListener(new NewGameListener());

    solveB = new ImageTextButton("Solve", skin);
    solveB.addListener(new MySolveListener());

    newGameBoard();

    //table.padTop(50);
    //table.padBottom(20);

    VerticalGroup vg = new VerticalGroup();
    //vg.padTop(50);
    vg.setFillParent(true);
    vg.addActor(newGameB);
    vg.addActor(table);
    vg.addActor(solveB);

    stage.addActor(vg);
}

From source file:com.forerunnergames.peril.client.ui.screens.menus.MenuScreenWidgetFactory.java

License:Open Source License

public ImageTextButton createMenuChoice(final String choiceText, final EventListener listener) {
    Arguments.checkIsNotNullOrEmptyOrBlank(choiceText, "choiceText");
    Arguments.checkIsNotNull(listener, "listener");

    final ImageTextButton menuChoiceButton = new ImageTextButton(choiceText, createMenuChoiceStyle());

    final Stack singlePlayerButtonStack = new Stack();
    singlePlayerButtonStack.add(new Container<>(menuChoiceButton.getLabel()).left().padLeft(60));
    singlePlayerButtonStack.add(menuChoiceButton.getImage());
    menuChoiceButton.clearChildren();/*  w  w  w. ja va 2  s.  c  om*/
    menuChoiceButton.add(singlePlayerButtonStack).fill().expand();
    menuChoiceButton.addListener(listener);

    return menuChoiceButton;
}

From source file:com.ray3k.libraryinvaders.states.MenuState.java

License:Open Source License

private void createMenu() {
    FileHandle fileHandle = Gdx.files.local(Core.DATA_PATH + "/data.json");
    JsonReader reader = new JsonReader();
    JsonValue val = reader.parse(fileHandle);

    root = new Table();
    root.setFillParent(true);//from ww  w  .  ja  v  a 2s . com
    stage.addActor(root);

    Label label = new Label(val.getString("title"), skin, "title");
    label.setAlignment(Align.center);
    root.add(label).padBottom(50.0f);

    root.row();
    Image image = new Image(getEnemy());
    image.setScaling(Scaling.fit);
    root.add(image).grow();

    root.defaults().space(30.0f).padLeft(25.0f);
    root.row();
    ImageTextButton imageTextButton = new ImageTextButton("Play", skin);
    root.add(imageTextButton).expandX().left();

    imageTextButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            getCore().getAssetManager().get(Core.DATA_PATH + "/sfx/menu.wav", Sound.class).play();
            showCharacterDialog();
        }
    });

    root.row();
    imageTextButton = new ImageTextButton("Quit", skin);
    root.add(imageTextButton).expandX().left().padBottom(50.0f);

    imageTextButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            getCore().getAssetManager().get(Core.DATA_PATH + "/sfx/menu.wav", Sound.class).play();
            Gdx.app.exit();
        }
    });
}

From source file:com.ray3k.skincomposer.RootTable.java

License:Open Source License

public void refreshPreview() {
    if (previewTable != null) {
        previewTable.clear();// ww w  .java  2s. c  o  m
        previewTable.setColor((Color) previewProperties.get("bgcolor"));

        for (BitmapFont font : previewFonts) {
            font.dispose();
        }

        if (classSelectBox.getSelectedIndex() >= 0) {
            StyleData styleData = getSelectedStyle();
            Class clazz = Main.BASIC_CLASSES[classSelectBox.getSelectedIndex()];

            if (!styleData.hasMandatoryFields()) {
                Label label;
                if (clazz.equals(SelectBox.class)) {
                    label = new Label(
                            "Please fill all mandatory fields\n(Highlighted on the left)\n\nscrollStyle and listStyle\nmust already be defined",
                            getSkin());
                } else if (clazz.equals(TextTooltip.class)) {
                    label = new Label(
                            "Please fill all mandatory fields\n(Highlighted on the left)\n\nlabel must already be defined",
                            getSkin());
                } else {
                    label = new Label("Please fill all mandatory fields\n(Highlighted on the left)", getSkin());
                }
                label.setAlignment(Align.center);
                previewTable.add(label);
            } else if (styleData.hasAllNullFields()) {
                Label label;
                label = new Label(
                        "All fields are empty!\nEmpty classes are not exported\nAdd style properties in the menu to the left",
                        getSkin());
                label.setAlignment(Align.center);
                previewTable.add(label);
            } else {
                Actor widget = null;
                if (clazz.equals(Button.class)) {
                    Button.ButtonStyle style = createPreviewStyle(Button.ButtonStyle.class, styleData);
                    widget = new Button(style);
                    ((Button) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(CheckBox.class)) {
                    CheckBox.CheckBoxStyle style = createPreviewStyle(CheckBox.CheckBoxStyle.class, styleData);
                    widget = new CheckBox("", style);
                    ((CheckBox) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((CheckBox) widget).setText((String) previewProperties.get("text"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(ImageButton.class)) {
                    ImageButtonStyle style = createPreviewStyle(ImageButtonStyle.class, styleData);
                    widget = new ImageButton(style);
                    ((ImageButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(ImageTextButton.class)) {
                    ImageTextButton.ImageTextButtonStyle style = createPreviewStyle(
                            ImageTextButton.ImageTextButtonStyle.class, styleData);
                    widget = new ImageTextButton("", style);
                    ((ImageTextButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((ImageTextButton) widget).setText((String) previewProperties.get("text"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Label.class)) {
                    LabelStyle style = createPreviewStyle(LabelStyle.class, styleData);
                    widget = new Label("", style);
                    ((Label) widget).setText((String) previewProperties.get("text"));
                } else if (clazz.equals(List.class)) {
                    ListStyle style = createPreviewStyle(ListStyle.class, styleData);
                    widget = new List(style);
                    Array<String> items = new Array<>(((String) previewProperties.get("text")).split("\\n"));
                    ((List) widget).setItems(items);
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(ProgressBar.class)) {
                    ProgressBar.ProgressBarStyle style = createPreviewStyle(ProgressBar.ProgressBarStyle.class,
                            styleData);
                    widget = new ProgressBar((float) (double) previewProperties.get("minimum"),
                            (float) (double) previewProperties.get("maximum"),
                            (float) (double) previewProperties.get("increment"),
                            (boolean) previewProperties.get("orientation"), style);
                    ((ProgressBar) widget).setValue((float) (double) previewProperties.get("value"));
                    ((ProgressBar) widget).setDisabled((boolean) previewProperties.get("disabled"));
                } else if (clazz.equals(ScrollPane.class)) {
                    ScrollPaneStyle style = createPreviewStyle(ScrollPaneStyle.class, styleData);
                    Label label = new Label("", getSkin());
                    widget = new ScrollPane(label, style);
                    ((ScrollPane) widget)
                            .setScrollbarsOnTop((boolean) previewProperties.get("scrollbarsOnTop"));
                    ((ScrollPane) widget).setScrollBarPositions(
                            (boolean) previewProperties.get("hScrollBarPosition"),
                            (boolean) previewProperties.get("vScrollBarPosition"));
                    ((ScrollPane) widget).setScrollingDisabled(
                            (boolean) previewProperties.get("hScrollDisabled"),
                            (boolean) previewProperties.get("vScrollDisabled"));
                    ((ScrollPane) widget).setForceScroll((boolean) previewProperties.get("forceHscroll"),
                            (boolean) previewProperties.get("forceVscroll"));
                    ((ScrollPane) widget)
                            .setVariableSizeKnobs((boolean) previewProperties.get("variableSizeKnobs"));
                    ((ScrollPane) widget).setOverscroll((boolean) previewProperties.get("hOverscroll"),
                            (boolean) previewProperties.get("vOverscroll"));
                    ((ScrollPane) widget).setFadeScrollBars((boolean) previewProperties.get("fadeScroll"));
                    ((ScrollPane) widget).setSmoothScrolling((boolean) previewProperties.get("smoothScroll"));
                    ((ScrollPane) widget).setFlickScroll((boolean) previewProperties.get("flickScroll"));
                    ((ScrollPane) widget).setClamp((boolean) previewProperties.get("clamp"));
                    label.setText((String) previewProperties.get("text"));
                } else if (clazz.equals(SelectBox.class)) {
                    SelectBox.SelectBoxStyle style = createPreviewStyle(SelectBox.SelectBoxStyle.class,
                            styleData);
                    widget = new SelectBox(style);
                    ((SelectBox) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    Array<String> items = new Array<>(((String) previewProperties.get("text")).split("\\n"));
                    ((SelectBox) widget).setItems(items);
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Slider.class)) {
                    Slider.SliderStyle style = createPreviewStyle(Slider.SliderStyle.class, styleData);
                    widget = new Slider((float) (double) previewProperties.get("minimum"),
                            (float) (double) previewProperties.get("maximum"),
                            (float) (double) previewProperties.get("increment"),
                            (boolean) previewProperties.get("orientation"), style);
                    ((Slider) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(SplitPane.class)) {
                    SplitPane.SplitPaneStyle style = createPreviewStyle(SplitPane.SplitPaneStyle.class,
                            styleData);
                    Label label1 = new Label("", getSkin());
                    Label label2 = new Label("", getSkin());
                    widget = new SplitPane(label1, label2, (boolean) previewProperties.get("orientation"),
                            style);
                    label1.setText((String) previewProperties.get("text"));
                    label2.setText((String) previewProperties.get("text"));

                    if ((boolean) previewProperties.get("orientation")) {
                        widget.addListener(vSplitPaneDragListener);
                        widget.addListener(vSplitPaneInputListener);
                    } else {
                        widget.addListener(hSplitPaneDragListener);
                        widget.addListener(hSplitPaneInputListener);
                    }
                } else if (clazz.equals(TextButton.class)) {
                    TextButtonStyle style = createPreviewStyle(TextButtonStyle.class, styleData);
                    widget = new TextButton("", style);
                    ((TextButton) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((TextButton) widget).setText((String) previewProperties.get("text"));
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(TextField.class)) {
                    TextFieldStyle style = createPreviewStyle(TextFieldStyle.class, styleData);
                    widget = new TextField("", style);
                    ((TextField) widget).setFocusTraversal(false);
                    ((TextField) widget).setDisabled((boolean) previewProperties.get("disabled"));
                    ((TextField) widget).setPasswordMode((boolean) previewProperties.get("passwordMode"));
                    ((TextField) widget).setAlignment((int) previewProperties.get("alignment"));
                    ((TextField) widget).setText((String) previewProperties.get("text"));
                    ((TextField) widget).setMessageText((String) previewProperties.get("message"));
                    String string = (String) previewProperties.get("password");
                    if (string.length() > 0) {
                        ((TextField) widget).setPasswordCharacter(string.charAt(0));
                    }
                    widget.addListener(main.getIbeamListener());
                } else if (clazz.equals(TextTooltip.class)) {
                    TextTooltip.TextTooltipStyle style = createPreviewStyle(TextTooltip.TextTooltipStyle.class,
                            styleData);

                    TooltipManager manager = new TooltipManager();
                    manager.animations = false;
                    manager.initialTime = 0.0f;
                    manager.resetTime = 0.0f;
                    manager.subsequentTime = 0.0f;
                    manager.hideAll();
                    manager.instant();
                    TextTooltip toolTip = new TextTooltip((String) previewProperties.get("text"), manager,
                            style);

                    widget = new Label("Hover over me", getSkin());
                    widget.addListener(toolTip);
                } else if (clazz.equals(Touchpad.class)) {
                    Touchpad.TouchpadStyle style = createPreviewStyle(Touchpad.TouchpadStyle.class, styleData);
                    widget = new Touchpad(0, style);
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Tree.class)) {
                    Tree.TreeStyle style = createPreviewStyle(Tree.TreeStyle.class, styleData);
                    widget = new Tree(style);
                    String[] lines = { "this", "is", "a", "test" };
                    Tree.Node parentNode = null;
                    for (String line : lines) {
                        Label label = new Label(line, getSkin());
                        Tree.Node node = new Tree.Node(label);
                        if (parentNode == null) {
                            ((Tree) widget).add(node);
                        } else {
                            parentNode.add(node);
                        }
                        parentNode = node;
                    }
                    widget.addListener(main.getHandListener());
                } else if (clazz.equals(Window.class)) {
                    Window.WindowStyle style = createPreviewStyle(Window.WindowStyle.class, styleData);

                    Label sampleText = new Label("", getSkin());
                    sampleText.setText((String) previewProperties.get("text"));

                    widget = new Window((String) previewProperties.get("title"), style);
                    ((Window) widget).add(sampleText);
                }

                if (widget != null) {
                    switch ((int) previewProperties.get("size")) {
                    case (0):
                        previewTable.add(widget).size(10.0f);
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (1):
                        previewTable.add(widget);
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (2):
                        previewTable.add(widget).size(200.0f);
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (3):
                        previewTable.add(widget).growX();
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (4):
                        previewTable.add(widget).growY();
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (5):
                        previewTable.add(widget).grow();
                        previewSizeSelectBox.setItems(DEFAULT_SIZES);
                        break;
                    case (6):
                        Actor addWidget = widget;
                        TextField widthField = new TextField("", getSkin());
                        TextField heightField = new TextField("", getSkin());
                        System.out.println("trigger");
                        Dialog dialog = new Dialog("Enter dimensions...", getSkin()) {
                            @Override
                            protected void result(Object object) {
                                if ((boolean) object) {
                                    previewTable.add(addWidget).size(Integer.parseInt(widthField.getText()),
                                            Integer.parseInt(heightField.getText()));
                                    Array<String> items = new Array<>(DEFAULT_SIZES);
                                    items.add(widthField.getText() + "x" + heightField.getText());
                                    previewProperties.put("sizeX", Integer.parseInt(widthField.getText()));
                                    previewProperties.put("sizeY", Integer.parseInt(heightField.getText()));
                                    previewSizeSelectBox.setItems(items);
                                    previewSizeSelectBox.setSelectedIndex(7);
                                } else {
                                    previewSizeSelectBox.setSelectedIndex(1);
                                }
                            }
                        };
                        dialog.getTitleTable().getCells().first().padLeft(5.0f);
                        dialog.text("Enter the preview dimensions: ");
                        dialog.getContentTable().getCells().first().pad(10.0f);
                        dialog.getContentTable().row();
                        Table sizeTable = new Table();
                        sizeTable.add(widthField).padLeft(10.0f);
                        sizeTable.add(new Label(" x ", getSkin()));
                        sizeTable.add(heightField).padRight(10.0f);
                        dialog.getContentTable().add(sizeTable);
                        dialog.getButtonTable().defaults().padBottom(10.0f).minWidth(50.0f);
                        dialog.button("OK", true);
                        dialog.button("Cancel", false);
                        dialog.key(Input.Keys.ESCAPE, false);
                        dialog.key(Input.Keys.ENTER, true);
                        dialog.show(stage);
                        stage.setKeyboardFocus(widthField);
                        break;
                    case (7):
                        previewTable.add(widget).size((int) previewProperties.get("sizeX"),
                                (int) previewProperties.get("sizeY"));
                        break;
                    }
                }
            }
        }
    }
}

From source file:com.tumblr.oddlydrawn.nahlc.screens.SetupScreen.java

License:Apache License

public SetupScreen(Game g) {
    game = g;/*w  ww .  j a va  2  s  .c  o  m*/
    assets = new Assets();
    stage = new Stage(new ExtendViewport(Renderer.WIDTH, Renderer.HEIGHT));
    Gdx.input.setInputProcessor(stage);
    skin = new Skin();
    assets.initSetupScreen();

    table = new Table();
    table.setFillParent(true);
    table.align(Align.left);
    stage.addActor(table);

    // Add default font to skin.
    skin.add("default", new BitmapFont(Gdx.files.internal(FONT_PATH)));

    // Create style for the level select checked and unchecked buttons with text (0-9).
    ImageTextButtonStyle imageTextButtonStyle = new ImageTextButtonStyle();
    imageTextButtonStyle.checked = new TextureRegionDrawable(assets.getSelectedSprite());
    imageTextButtonStyle.up = new TextureRegionDrawable(assets.getUnselectedSprite());
    imageTextButtonStyle.font = skin.getFont("default");
    skin.add("default", imageTextButtonStyle);

    // Create style for checkboxes with text beside them.
    CheckBoxStyle checkBoxStyle = new CheckBoxStyle();
    checkBoxStyle.checkboxOff = new TextureRegionDrawable(assets.getUncheckedSprite());
    checkBoxStyle.checkboxOn = new TextureRegionDrawable(assets.getCheckedSprite());
    checkBoxStyle.font = skin.getFont("default");
    skin.add("default", checkBoxStyle);

    // Create style for 9patch image button with text ("Start" button).
    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.font = skin.getFont("default");
    textButtonStyle.up = new NinePatchDrawable(assets.getBoxPatch());
    skin.add("default", textButtonStyle);

    final CheckBox soundOnBox = new CheckBox(LABEL_SOUND, skin);
    table.add(soundOnBox);
    table.row();
    final CheckBox musicOnBox = new CheckBox(LABEL_MUSIC, skin);
    table.add(musicOnBox);
    table.row();
    final CheckBox upsideDownBox = new CheckBox(LABEL_UPSIDE, skin);
    table.add(upsideDownBox);
    table.row();

    // Create an embedded table to have its own cells and not mess up parent.
    Table buttonsTable = new Table();

    final ImageTextButton zero = new ImageTextButton("0", skin);
    buttonsTable.add(zero);
    final ImageTextButton one = new ImageTextButton("1", skin);
    buttonsTable.add(one);
    final ImageTextButton two = new ImageTextButton("2", skin);
    buttonsTable.add(two);
    final ImageTextButton three = new ImageTextButton("3", skin);
    buttonsTable.add(three);
    final ImageTextButton four = new ImageTextButton("4", skin);
    buttonsTable.add(four);
    buttonsTable.row();
    final ImageTextButton five = new ImageTextButton("5", skin);
    buttonsTable.add(five);
    final ImageTextButton six = new ImageTextButton("6", skin);
    buttonsTable.add(six);
    final ImageTextButton seven = new ImageTextButton("7", skin);
    buttonsTable.add(seven);
    final ImageTextButton eight = new ImageTextButton("8", skin);
    buttonsTable.add(eight);
    final ImageTextButton nine = new ImageTextButton("9", skin);
    buttonsTable.add(nine);

    ButtonGroup groupButtons = new ButtonGroup();
    groupButtons.add(zero);
    groupButtons.add(one);
    groupButtons.add(two);
    groupButtons.add(three);
    groupButtons.add(four);
    groupButtons.add(five);
    groupButtons.add(six);
    groupButtons.add(seven);
    groupButtons.add(eight);
    groupButtons.add(nine);
    groupButtons.setMaxCheckCount(1); // Awesome.
    groupButtons.uncheckAll();
    zero.setChecked(true);

    LabelStyle labelStyle = new LabelStyle();
    labelStyle.font = skin.getFont("default");
    skin.add("default", labelStyle);

    Label levelLabel = new Label(LABEL_LEVEL, skin);
    table.add(levelLabel).padTop(PAD).align(Align.left);
    table.row();

    table.add(buttonsTable).padBottom(PAD);
    table.row();

    Label bagSize = new Label(LABEL_BAG_SIZE, skin);
    table.add(bagSize).align(Align.left);
    table.row();

    // Create an embedded table to have its own cells and not mess up parent.
    Table bagTable = new Table();

    final ImageTextButton sizeRandom = new ImageTextButton("Rnd", skin);
    bagTable.add(sizeRandom);
    final ImageTextButton sizeSeven = new ImageTextButton("7", skin);
    bagTable.add(sizeSeven);
    final ImageTextButton sizeFourteen = new ImageTextButton("14", skin);
    bagTable.add(sizeFourteen);
    final ImageTextButton sizeTwentyOne = new ImageTextButton("21", skin);
    bagTable.add(sizeTwentyOne);
    table.add(bagTable);
    table.row();

    ButtonGroup bagButtons = new ButtonGroup();
    bagButtons.add(sizeRandom);
    bagButtons.add(sizeSeven);
    bagButtons.add(sizeFourteen);
    bagButtons.add(sizeTwentyOne);
    bagButtons.setMaxCheckCount(1);
    bagButtons.uncheckAll();
    sizeSeven.setChecked(true);

    TextButton startButton = new TextButton(LABEL_START, skin);
    table.add(startButton).padTop(PAD);
    table.debugTable();

    // Load preferences
    SavedStuff savedStuff = new SavedStuff();
    savedStuff.loadPreferences();
    soundOn = savedStuff.isSoundOn();
    musicOn = savedStuff.isMusicOn();
    upsideDown = savedStuff.isUpsideDown();

    // Set loaded preferences
    soundOnBox.setChecked(soundOn);
    musicOnBox.setChecked(musicOn);
    upsideDownBox.setChecked(upsideDown);

    startButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            boolean sound;
            boolean music;
            boolean upside;
            int bag = 0;
            int level = 0;

            // Get selected starting level.
            if (zero.isChecked()) {
                level = 0;
            } else if (one.isChecked()) {
                level = 1;
            } else if (two.isChecked()) {
                level = 2;
            } else if (three.isChecked()) {
                level = 3;
            } else if (four.isChecked()) {
                level = 4;
            } else if (five.isChecked()) {
                level = 5;
            } else if (six.isChecked()) {
                level = 6;
            } else if (seven.isChecked()) {
                level = 7;
            } else if (eight.isChecked()) {
                level = 8;
            } else if (nine.isChecked()) {
                level = 9;
            }

            // Get selected randomized shape bag size
            if (sizeRandom.isChecked()) {
                bag = 0;
            } else if (sizeSeven.isChecked()) {
                bag = 1;
            } else if (sizeFourteen.isChecked()) {
                bag = 2;
            } else if (sizeTwentyOne.isChecked()) {
                bag = 3;
            }

            sound = soundOnBox.isChecked();
            music = musicOnBox.isChecked();
            upside = upsideDownBox.isChecked();

            // Save preferences.
            SavedStuff stuff = new SavedStuff();
            stuff.saveAll(sound, music, upside, bag, level);

            dispose();
            game.setScreen(new GameScreen(game));
        }
    });
}