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

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

Introduction

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

Prototype

public ScrollPane(Actor widget, ScrollPaneStyle style) 

Source Link

Usage

From source file:com.strategames.ui.dialogs.WheelSpinnerDialog.java

License:Open Source License

public Dialog create() {
    setWidth(150);/*from ww w  . j  av  a 2s  .  c  om*/
    setHeight(200);

    if (this.title != null) {
        Label label = new Label(this.title, this.skin);
        add(label).top();
        row();
    }

    Table buttonTable = new Table(this.skin);
    for (int i = 0; i < items.length; i++) {
        final TextButton button = new TextButton(items[i], this.skin);
        button.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                selectedItem = Integer.parseInt(button.getText().toString());
                OnClickListener listener = getOnClickListener();
                if (listener != null) {
                    listener.onClick(WheelSpinnerDialog.this, ITEM_SELECTED);
                }
            }
        });
        buttonTable.add(button).width(50);
        buttonTable.row();
    }

    ScrollPane scrollPane = new ScrollPane(buttonTable, this.skin);
    add(scrollPane).maxHeight(150);
    row();

    setNegativeButton("Cancel");

    return super.create();
}

From source file:com.theosirian.ppioo.controllers.PlayerSelectionController.java

License:Open Source License

@Override
protected void createComponents() {
    percentFormatter = NumberFormat.getPercentInstance();
    percentFormatter.setMaximumFractionDigits(0);

    playerPlayerComp = new PlayerComp(Player.firstNameComparator, false);

    rootLayout = new Table();
    rootLayout.setFillParent(true);/*from ww  w  . j av a2s  . c  o m*/
    rootLayout.setBackground(game.skin.newDrawable("white", Color.DARK_GRAY));

    titleLabel = new Label("Please choose your players and positions:", game.skin, "big.white");
    titleLabel.setAlignment(2); // 2 == center

    randomizePlayersButton = new TextButton("Randomize Players", game.skin);
    randomizePlayersButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            Array<Player> copy = game.data.getOwnedPlayers();
            copy.shuffle();
            copy.truncate(game.data.getTeamSize());
            game.data.getTeam().clear();
            game.data.getTeam().addAll(copy);
            invalidate();
        }
    });
    randomizePositionsButton = new TextButton("Randomize Positions", game.skin);
    randomizePositionsButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            game.data.getTeam().shuffle();
            invalidate();
        }
    });
    playerSortButton = new TextButton("Sort Players", game.skin);
    playerSortButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            Dialog info = new PlayerSortDialog("Sort Players By:", game.skin, false) {
                @Override
                protected void result(Object object) {
                    if (object == null) {
                        return;
                    }
                    playerPlayerComp = (PlayerComp) object;
                    PlayerSelectionController.this.invalidate();
                }
            };
            info.show(game.stage);
            invalidate();
        }
    });
    positionSortButton = new TextButton("Sort Positions", game.skin);
    positionSortButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            Dialog info = new PlayerSortDialog("Sort Positions By:", game.skin, false) {
                @Override
                protected void result(Object object) {
                    if (object == null) {
                        return;
                    }
                    positionPlayerComp = (PlayerComp) object;
                    PlayerSelectionController.this.invalidate();
                }
            };
            info.show(game.stage);
            invalidate();
        }
    });
    clearButton = new TextButton("Clear", game.skin);
    clearButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            game.data.getTeam().clear();
            invalidate();
        }
    });

    backButton = new TextButton("Return", game.skin, "error");
    backButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            game.changeController = MenuController.class;
        }
    });
    helpButton = new TextButton("Help", game.skin);
    helpButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            Dialog info = new Dialog("Help!", game.skin);
            info.text(
                    "In this screen you are shown your players in the left and the current team setup in the right.\n"
                            + "To advance you need to select 6 players and their positions, one goalkeeper and five kickers.");
            info.button("Close", false);
            info.key(Input.Keys.ENTER, false);
            info.key(Keys.ESCAPE, false);
            info.show(game.stage);
        }
    });
    proceedButton = new TextButton("Proceed", game.skin, "success");
    proceedButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (game.data.getTeam().size == game.data.getTeamSize()) {
                game.getSoundController().soundPlay(1);
                game.changeController = GameController.class;
            } else {
                Dialog info = new Dialog("Team not selected!", game.skin);
                info.text("You haven't selected the right amount of players.\nPlease select "
                        + game.data.getTeamSize() + " players.");
                info.button("Close", false);
                info.key(Input.Keys.ENTER, false);
                info.key(Keys.ESCAPE, false);
                info.show(game.stage);
            }
        }
    });

    playersTable = new Table();
    positionsTable = new Table();
    playersPane = new ScrollPane(playersTable, game.skin);
    positionsPane = new ScrollPane(positionsTable, game.skin);
}

From source file:com.theosirian.ppioo.controllers.ShopController.java

License:Open Source License

@Override
protected void createComponents() {
    percentFormatter = NumberFormat.getPercentInstance();
    percentFormatter.setMaximumFractionDigits(0);

    playerComp = new PlayerComp(Player.firstNameComparator, false);
    fanComp = new FanComp(Fan.nameComparator, false);

    rootLayout = new Table();
    rootLayout.setFillParent(true);/*from  www  .  ja  va2 s . c om*/
    rootLayout.setBackground(game.skin.newDrawable("white", Color.DARK_GRAY));

    titleLabel = new Label("Shop", game.skin, "big.white");
    titleLabel.setAlignment(Align.left);

    moneyLabel = new Label("Money: $" + game.data.getMoney(), game.skin, "big.white");
    moneyLabel.setAlignment(Align.center);

    backButton = new TextButton("Return", game.skin);
    backButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            game.getSoundController().soundPlay(1);
            game.changeController = MenuController.class;
        }
    });

    playerSortButton = new TextButton("Sort Players", game.skin);
    playerSortButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            Dialog info = new PlayerSortDialog("Sort Players By:", game.skin, true) {
                @Override
                protected void result(Object object) {
                    if (object == null) {
                        return;
                    }
                    playerComp = (PlayerComp) object;
                    ShopController.this.invalidate();
                }
            };
            info.show(game.stage);
        }
    });

    fanSortButton = new TextButton("Sort Players", game.skin);
    fanSortButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.getSoundController().soundPlay(1);
            Dialog info = new FanSortDialog("Sort Players By:", game.skin, true) {
                @Override
                protected void result(Object object) {
                    if (object == null) {
                        return;
                    }
                    fanComp = (FanComp) object;
                    ShopController.this.invalidate();
                }
            };
            info.show(game.stage);
        }
    });

    buildPlayerList();

    playersTable = new Table();
    fansTable = new Table();
    playersPane = new ScrollPane(playersTable, game.skin);
    fansPane = new ScrollPane(fansTable, game.skin);
}

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

License:Apache License

public LicenseScreen(Game g) {
    game = g;//  ww w .  jav a  2s .  c  om
    stage = new Stage(new FitViewport(WIDTH, HEIGHT));
    skin = new Skin();
    assets = new Assets();
    assets.initMainMenu();
    Gdx.input.setInputProcessor(stage);

    FileHandle handle;
    handle = Gdx.files.internal(LICENSE_PATH);
    licenseString = handle.readString();

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

    skin.add("default", new BitmapFont(Gdx.files.internal(FONT_PATH)));

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

    ScrollPaneStyle scrollPaneStyle = new ScrollPaneStyle();
    skin.add("default", scrollPaneStyle);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.font = skin.getFont("default");
    textButtonStyle.up = new NinePatchDrawable(assets.getBoxPatch());
    skin.add("default", textButtonStyle);

    Label license = new Label(licenseString, skin);
    ScrollPane scrollPane = new ScrollPane(license, skin);
    scrollPane.setFlickScroll(true);
    table.add(scrollPane);
    table.row();

    TextButton backButton = new TextButton("Back", skin);
    table.add(backButton).padTop(TABLE_PAD);
    table.padTop(TABLE_PAD);
    table.padBottom(TABLE_PAD);
    table.row();

    backButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            dispose();
            game.setScreen(new MainMenuScreen(game));
        }
    });
}

From source file:com.tumblr.oddlydrawn.stupidworm.screens.LicenseScreen.java

License:Apache License

public LicenseScreen(Game g) {
    game = g;/*  www . java  2 s . com*/
    stage = new Stage();
    skin = new Skin();
    batch = new SpriteBatch();
    FileHandle handle;
    handle = Gdx.files.internal(LICENSE_LOC);
    licenseString = handle.readString();

    atlas = new TextureAtlas(Gdx.files.internal(TEXTURE_ATLAS_LOC));

    NinePatch patchBox;
    patchBox = new NinePatch(atlas.createPatch(PATCH_BOX_REGION_STRING));

    Gdx.input.setInputProcessor(stage);
    stage.setViewport(new StretchViewport(WIDTH, HEIGHT));
    Table table = new Table();
    table.setFillParent(true);
    stage.addActor(table);

    Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
    pixmap.setColor(Color.LIGHT_GRAY);
    pixmap.fill();

    // The following defines the defaults for Scene2D's skin
    skin.add("grey", new Texture(pixmap));
    skin.add("default", new BitmapFont(Gdx.files.internal(FONT_LOC)));

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

    ScrollPaneStyle scrollPaneStyle = new ScrollPaneStyle();
    skin.add("default", scrollPaneStyle);

    ButtonStyle buttonStyle = new ButtonStyle();
    skin.add("default", buttonStyle);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.font = skin.getFont("default");
    textButtonStyle.up = new NinePatchDrawable(patchBox);
    skin.add("default", textButtonStyle);

    // Creates Actors (the entire LICENSE text file) for Scene2D
    Label license = new Label(licenseString, skin);
    ScrollPane scrollPane = new ScrollPane(license, skin);
    scrollPane.setFlickScroll(true);
    table.add(scrollPane);

    // Creates the padding between the text and the button.
    table.row();
    // Label padding = new Label(LABEL_PADDING, skin);
    // table.add(padding);

    // Creates the 'Okay' button
    table.row();
    TextButton okay = new TextButton("Okay", skin);
    table.add(okay);
    okay.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            dispose();
            game.setScreen(new MainMenuScreen(game));
        }
    });

    // Adds padding on top and on the bottom of the table.
    table.padTop(TABLE_PADDING);
    table.padBottom(TABLE_PADDING);
    table.pack();
}

From source file:com.uwsoft.editor.gdx.ui.AssetList.java

License:Apache License

public AssetList(final UIStage s, float width, float height) {
    this.setWidth(width);
    this.setHeight(height);
    final Table container = new Table();
    Table table = new Table();
    container.setX(0);//  w w  w .ja  v  a2s  .  c om
    container.setY(0);
    container.setWidth(getWidth() - 1);
    container.setHeight(getHeight() - 20);
    final ScrollPane scroll = new ScrollPane(table, s.textureManager.editorSkin);
    container.add(scroll).colspan(4).width(getWidth());
    container.row();
    scroll.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return true;
        }
    });
    scroll.setHeight(getHeight() - 20);
    scroll.setFlickScroll(false);
    TextureAtlas atlas = s.textureManager.getProjectAssetsList();

    HashMap<String, SpineAnimData> spineAnimations = s.textureManager.getProjectSpineAnimationsList();
    HashMap<String, TextureAtlas> spriteAnimations = s.textureManager.getProjectSpriteAnimationsList();
    HashMap<String, FileHandle> spriterAnimations = s.textureManager.getProjectSpriterAnimationsList();

    if (atlas == null)
        return;

    int itemIter = 0;
    for (int i = 0; i < atlas.getRegions().size; i++) {
        TextureAtlas.AtlasRegion atlasRegion = atlas.getRegions().get(i);
        boolean is9patch = atlasRegion.splits != null;
        final ImageThumbnailBox thumb = is9patch ? new Image9patchThumbnailBox(s, atlasRegion)
                : new ImageThumbnailBox(s, atlasRegion);

        table.add(thumb).pad(3);

        if ((itemIter - 7) % 4 == 0) {
            table.row();
        }
        itemIter++;
    }

    for (String animationName : spineAnimations.keySet()) {
        final SpineAnimationThumbnailBox thumb = new SpineAnimationThumbnailBox(s,
                spineAnimations.get(animationName));

        table.add(thumb).size(50, 50).pad(3);
        if ((itemIter - 7) % 4 == 0) {

            table.row();
        }
        itemIter++;
    }

    for (String animationName : spriteAnimations.keySet()) {
        final SpriteAnimationThumbnailBox thumb = new SpriteAnimationThumbnailBox(s, animationName);

        table.add(thumb).size(50, 50).pad(3);
        if ((itemIter - 7) % 4 == 0) {

            table.row();
        }
        itemIter++;
    }

    for (String animationName : spriterAnimations.keySet()) {
        final SpriterAnimationThumbnailBox thumb = new SpriterAnimationThumbnailBox(s, animationName);

        table.add(thumb).size(50, 50).pad(3);
        if ((itemIter - 7) % 4 == 0) {

            table.row();
        }
        itemIter++;
    }

    addActor(container);
}

From source file:com.uwsoft.editor.gdx.ui.ComponentList.java

License:Apache License

public ComponentList(final UIStage s, float width, float height) {
    this.setWidth(width);
    this.setHeight(height);
    final Table container = new Table();
    Table table = new Table();
    Group listContainer = new Group();
    container.setX(0);//from w w  w  . j a  v a 2  s  .co m
    container.setY(0);
    container.setWidth(getWidth() - 1);
    container.setHeight(getHeight() - 20);
    listContainer.setWidth(getWidth() - 20);
    listContainer.setHeight(getHeight() - 25);
    final ScrollPane scroll = new ScrollPane(table, s.textureManager.editorSkin);
    container.add(scroll).colspan(4).width(getWidth());
    container.row();
    scroll.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return true;
        }
    });
    scroll.setHeight(getHeight() - 20);
    scroll.setY(0);
    scroll.setFlickScroll(false);

    HashMap<String, String> components = new HashMap<String, String>();

    components.put("Label", "Label");
    components.put("TextBoxItem", "Text Field");
    components.put("ButtonItem", "Text Button");
    components.put("CheckBox", "CheckBox");
    components.put("SelectBox", "SelectBox");

    Label dummyTst = new Label("dummy", s.textureManager.editorSkin);
    if (components.size() * dummyTst.getHeight() > listContainer.getHeight())
        listContainer.setHeight(components.size() * dummyTst.getHeight());
    dummyTst = null;

    int iter = 1;
    for (final Object value : components.values()) {

        ComponentThumbnailBox thumb = new ComponentThumbnailBox(s, getWidth(), (String) value);
        thumb.setX(0);
        thumb.setY(listContainer.getHeight() - thumb.getHeight() * iter);
        listContainer.addActor(thumb);
        iter++;
    }

    table.add(listContainer);
    table.row();

    addActor(container);
}

From source file:com.uwsoft.editor.gdx.ui.dialogs.CustomVariablesDialog.java

License:Apache License

public CustomVariablesDialog(UIStage s, final IBaseItem item) {
    super(s, 320, 310);

    this.uiStagel = s;
    setX(200);//  w w w .  j a  v  a2 s  . com
    setY(200);

    setTitle("Custom Variables Dialog");

    vars = item.getCustomVariables();
    this.item = item;

    topWrapper = new Group();
    topWrapper.setX(5);
    topWrapper.setY(getHeight() - maxHeight - 20);
    topWrapper.setHeight(maxHeight);
    topWrapper.setWidth(getWidth() - 10);

    listContainer = new Group();
    wrapper = new Group();

    renderMainList();
    scroll = new ScrollPane(wrapper, s.textureManager.editorSkin);

    scroll.setWidth(topWrapper.getWidth());
    scroll.setHeight(maxHeight);
    scroll.setFlickScroll(false);
    scroll.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return true;
        }
    });

    wrapper.addActor(listContainer);
    scroll.setName("scroll");
    topWrapper.addActor(scroll);
    addActor(topWrapper);

    final CompositeItem newRow = stage.sceneLoader.getLibraryAsActor("newKeyValuePair");
    addActor(newRow);
    newRow.setX(getWidth() / 2 - newRow.getWidth() / 2);
    newRow.setY(topWrapper.getY() - newRow.getHeight() - 2);

    TextButton addBtn = newRow.getTextButtonById("addBtn");

    addBtn.addListener(new ClickListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            return true;
        }

        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {

            String key = newRow.getTextBoxById("key").getText();
            String value = newRow.getTextBoxById("value").getText();

            key.replace(";", "");
            key.replace(":", "");

            if (key.length() > 0) {
                vars.setVariable(key, value);
                renderMainList();

                newRow.getTextBoxById("key").setText("");
                newRow.getTextBoxById("value").setText("");
            }
        }
    });

}

From source file:com.uwsoft.editor.gdx.ui.dialogs.CustomVariablesDialog.java

License:Apache License

public void renderMainList() {
    item.updateDataVO();//from  w w  w.j a v  a2  s. co  m
    listContainer.clear();

    float itmHeight = 25;
    int cnt = vars.getCount();

    wrapper.setHeight(itmHeight * cnt);
    scroll = new ScrollPane(wrapper, uiStagel.textureManager.editorSkin);
    scroll.setWidth(topWrapper.getWidth());
    scroll.setHeight(maxHeight);
    scroll.setFlickScroll(false);
    scroll.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return true;
        }
    });
    if (topWrapper.findActor("scroll") != null) {
        topWrapper.findActor("scroll").remove();
    }

    topWrapper.addActor(scroll);

    if (itmHeight * cnt < maxHeight - 10) {
        listContainer.setHeight(maxHeight - 10);
    } else {
        listContainer.setHeight(itmHeight * cnt);
    }

    int iterator = 0;
    for (Map.Entry<String, String> entry : vars.getHashMap().entrySet()) {
        final String key = entry.getKey();
        String value = entry.getValue();
        // ...
        final CompositeItem itm = stage.sceneLoader.getLibraryAsActor("KeyValuePairRow");

        itm.getLabelById("key").setAlignment(Align.left);

        itm.getLabelById("key").setText(key);
        itm.getTextBoxById("value").setText(value);

        listContainer.addActor(itm);
        itm.setX(2);
        itm.setY(listContainer.getHeight() - (itm.getHeight() + 3) * (iterator + 1));
        iterator++;

        itm.getTextButtonById("updateBtn").addListener(new ClickListener() {
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                return true;
            }

            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                vars.setVariable(key, itm.getTextBoxById("value").getText());
                renderMainList();
            }
        });

        itm.getTextButtonById("deleteBtn").addListener(new ClickListener() {
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                return true;
            }

            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                vars.removeVariable(key);
                renderMainList();
            }
        });
    }
}

From source file:com.uwsoft.editor.gdx.ui.dialogs.EditAnimationDialog.java

License:Apache License

public EditAnimationDialog(UIStage s, final SpriteAnimation item) {
    super(s, 320, 310);

    this.uiStage = s;
    setX(200);//from w  ww. ja va 2s .c  o  m
    setY(200);

    setTitle("Add animation");

    animations = item.getAnimations();
    this.item = item;

    topWrapper = new Group();
    topWrapper.setX(5);
    topWrapper.setY(getHeight() - maxHeight - 20);
    topWrapper.setHeight(maxHeight);
    topWrapper.setWidth(getWidth() - 10);

    listContainer = new Group();
    wrapper = new Group();

    renderMainList();
    scroll = new ScrollPane(wrapper, s.textureManager.editorSkin);

    scroll.setWidth(topWrapper.getWidth());
    scroll.setHeight(maxHeight);
    scroll.setFlickScroll(false);
    scroll.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            event.stop();
            return true;
        }
    });

    wrapper.addActor(listContainer);
    scroll.setName("scroll");
    topWrapper.addActor(scroll);
    addActor(topWrapper);

    final CompositeItem newAnimationControl = stage.sceneLoader.getLibraryAsActor("newAnimationControl");
    addActor(newAnimationControl);
    newAnimationControl.setX(getWidth() / 2 - newAnimationControl.getWidth() / 2);
    newAnimationControl.setY(topWrapper.getY() - newAnimationControl.getHeight() - 5);

    TextButton addBtn = newAnimationControl.getTextButtonById("addBtn");

    addBtn.addListener(new ClickListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            return true;
        }

        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            try {
                int fromValue = Integer.parseInt(newAnimationControl.getTextBoxById("fromValue").getText());
                int toValue = Integer.parseInt(newAnimationControl.getTextBoxById("toValue").getText());
                String name = newAnimationControl.getTextBoxById("animationName").getText();
                if (!(fromValue > toValue || fromValue < 0 || toValue < 0 || toValue > item.getFramesCount())) {
                    animations.put(name, new SpriteAnimation.Animation(fromValue, toValue, name));
                    renderMainList();
                }

            } catch (NumberFormatException ignored) {

            }
            newAnimationControl.getTextBoxById("fromValue").setText("");
            newAnimationControl.getTextBoxById("toValue").setText("");
            newAnimationControl.getTextBoxById("animationName").setText("");
        }
    });

}