Search in sources :

Example 1 with Slider

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

the class MusicTest method create.

@Override
public void create() {
    music = Gdx.audio.newMusic(Gdx.files.internal("data/8.12.mp3"));
    music.play();
    buttons = new TextureRegion(new Texture(Gdx.files.internal("data/playback.png")));
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    slider = new Slider(0, 100, 0.1f, false, skin);
    slider.setPosition(200, 20);
    slider.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (!sliderUpdating && slider.isDragging())
                music.setPosition((slider.getValue() / 100f) * songDuration);
        }
    });
    stage.addActor(slider);
    Gdx.input.setInputProcessor(stage);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 2 with Slider

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

the class SoundTest method create.

@Override
public void create() {
    sound = Gdx.audio.newSound(Gdx.files.getFileHandle("data/shotgun.ogg", FileType.Internal));
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    ui = new Stage();
    TextButton play = new TextButton("Play", skin);
    TextButton stop = new TextButton("Stop", skin);
    final Slider pitch = new Slider(0.1f, 4, 0.1f, false, skin);
    pitch.setValue(1);
    final Label pitchValue = new Label("1.0", skin);
    final Slider volume = new Slider(0.1f, 1, 0.1f, false, skin);
    volume.setValue(1);
    final Label volumeValue = new Label("1.0", skin);
    Table table = new Table();
    final Slider pan = new Slider(-1f, 1f, 0.1f, false, skin);
    pan.setValue(0);
    final Label panValue = new Label("0.0", skin);
    table.setFillParent(true);
    table.align(Align.center | Align.top);
    table.columnDefaults(0).expandX().right().uniformX();
    table.columnDefaults(2).expandX().left().uniformX();
    table.add(play);
    table.add(stop).left();
    table.row();
    table.add(new Label("Pitch", skin));
    table.add(pitch);
    table.add(pitchValue);
    table.row();
    table.add(new Label("Volume", skin));
    table.add(volume);
    table.add(volumeValue);
    table.row();
    table.add(new Label("Pan", skin));
    table.add(pan);
    table.add(panValue);
    ui.addActor(table);
    play.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            soundId = sound.play(volume.getValue());
            sound.setPitch(soundId, pitch.getValue());
            sound.setPan(soundId, pan.getValue(), volume.getValue());
        }
    });
    stop.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            sound.stop(soundId);
        }
    });
    pitch.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setPitch(soundId, pitch.getValue());
            pitchValue.setText("" + pitch.getValue());
        }
    });
    volume.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setVolume(soundId, volume.getValue());
            volumeValue.setText("" + volume.getValue());
        }
    });
    pan.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            sound.setPan(soundId, pan.getValue(), volume.getValue());
            panValue.setText("" + pan.getValue());
        }
    });
    Gdx.input.setInputProcessor(ui);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 3 with Slider

use of com.badlogic.gdx.scenes.scene2d.ui.Slider in project skin-composer by raeleus.

the class RootTable method refreshPreview.

public void refreshPreview() {
    if (previewTable != null) {
        previewTable.clear();
        previewTable.setBackground("white");
        previewTable.setColor((Color) previewProperties.get("bgcolor"));
        for (BitmapFont font : previewFonts) {
            font.dispose();
        }
        if (classSelectBox.getSelectedIndex() >= 0 && classSelectBox.getSelectedIndex() < Main.BASIC_CLASSES.length) {
            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());
                    ((SelectBox) widget).getList().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);
                    if (style.stageBackground != null) {
                        previewTable.setBackground(style.stageBackground);
                        previewTable.setColor(Color.WHITE);
                        style.stageBackground = null;
                    }
                    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;
                            TraversalTextField widthField = new TraversalTextField("", getSkin());
                            TraversalTextField heightField = new TraversalTextField("", getSkin());
                            widthField.setNextFocus(heightField);
                            heightField.setNextFocus(widthField);
                            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);
                            TextButton okButton = (TextButton) dialog.getButtonTable().getCells().first().getActor();
                            okButton.setDisabled(true);
                            okButton.addListener(main.getHandListener());
                            widthField.addListener(new ChangeListener() {

                                @Override
                                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                                    okButton.setDisabled(!widthField.getText().matches("^\\d+$") || !heightField.getText().matches("^\\d+$"));
                                }
                            });
                            heightField.addListener(new ChangeListener() {

                                @Override
                                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                                    okButton.setDisabled(!widthField.getText().matches("^\\d+$") || !heightField.getText().matches("^\\d+$"));
                                }
                            });
                            dialog.getButtonTable().getCells().get(1).getActor().addListener(main.getHandListener());
                            dialog.key(Input.Keys.ESCAPE, false);
                            dialog.show(stage);
                            stage.setKeyboardFocus(widthField);
                            break;
                        case (7):
                            previewTable.add(widget).size((int) previewProperties.get("sizeX"), (int) previewProperties.get("sizeY"));
                            break;
                    }
                }
            }
        } else {
            CustomStyle customStyle = (CustomStyle) styleSelectBox.getSelected();
            boolean showMessage = true;
            if (customStyle.getProperties().size == 0) {
                Label label = new Label("No style properties!\nEmpty classes are not exported\nAdd style properties in the menu to the left", getSkin());
                label.setAlignment(0);
                previewTable.add(label);
            } else {
                for (CustomProperty customProperty : customStyle.getProperties()) {
                    if (customProperty.getValue() != null && !(customProperty.getValue() instanceof String) || customProperty.getValue() != null && !((String) customProperty.getValue()).equals("")) {
                        showMessage = false;
                        break;
                    }
                }
                if (showMessage) {
                    Label label = new Label("All properties are empty!\nEmpty classes are not exported\nAdd style properties in the menu to the left", getSkin());
                    label.setAlignment(0);
                    previewTable.add(label);
                }
            }
            if (!showMessage) {
                HorizontalGroup horizontalGroup = new HorizontalGroup();
                horizontalGroup.wrap();
                // the following causes a crash. LibGDX bug.
                // horizontalGroup.space(10.0f);
                horizontalGroup.wrapSpace(10.0f);
                horizontalGroup.setTouchable(Touchable.disabled);
                previewTable.add(horizontalGroup).grow().pad(10.0f);
                for (CustomProperty customProperty : customStyle.getProperties()) {
                    if (customProperty.getValue() != null) {
                        Container container = new Container();
                        container.pad(5.0f);
                        horizontalGroup.addActor(container);
                        switch(customProperty.getType()) {
                            case TEXT:
                            case RAW_TEXT:
                                Label labelText = new Label((String) customProperty.getValue(), getSkin());
                                container.setActor(labelText);
                                break;
                            case NUMBER:
                                Label labelNumber = new Label(Double.toString((double) customProperty.getValue()), getSkin());
                                container.setActor(labelNumber);
                                break;
                            case BOOL:
                                Label labelBoolean = new Label(Boolean.toString((boolean) customProperty.getValue()), getSkin());
                                container.setActor(labelBoolean);
                                break;
                            case COLOR:
                                ColorData colorData = null;
                                String colorName = (String) customProperty.getValue();
                                for (ColorData cd : main.getJsonData().getColors()) {
                                    if (cd.getName().equals(colorName)) {
                                        colorData = cd;
                                        break;
                                    }
                                }
                                if (colorData != null) {
                                    Table colorTable = new Table(getSkin());
                                    colorTable.setBackground("white");
                                    colorTable.setColor(colorData.color);
                                    colorTable.add().size(25.0f);
                                    container.setActor(colorTable);
                                }
                                break;
                            case FONT:
                                BitmapFont font = null;
                                FontData fontData = null;
                                String fontName = (String) customProperty.getValue();
                                for (FontData fd : main.getJsonData().getFonts()) {
                                    if (fd.getName().equals(fontName)) {
                                        fontData = fd;
                                        font = new BitmapFont(fd.file);
                                        previewFonts.add(font);
                                        break;
                                    }
                                }
                                if (font != null) {
                                    Label labelFont = new Label(fontData.getName(), new LabelStyle(font, Color.WHITE));
                                    container.setActor(labelFont);
                                }
                                FreeTypeFontData freeTypeFontData = null;
                                for (FreeTypeFontData fd : main.getJsonData().getFreeTypeFonts()) {
                                    if (fd.name.equals(fontName)) {
                                        freeTypeFontData = fd;
                                        break;
                                    }
                                }
                                if (freeTypeFontData.bitmapFont != null) {
                                    Label labelFont = new Label(freeTypeFontData.name, new LabelStyle(freeTypeFontData.bitmapFont, Color.WHITE));
                                    container.setActor(labelFont);
                                }
                                break;
                            case DRAWABLE:
                                DrawableData drawable = null;
                                String drawableName = (String) customProperty.getValue();
                                for (DrawableData dd : main.getAtlasData().getDrawables()) {
                                    if (dd.name.equals(drawableName)) {
                                        drawable = dd;
                                        break;
                                    }
                                }
                                if (drawable != null) {
                                    Image image = new Image(drawablePairs.get(drawable.name));
                                    container.setActor(image);
                                }
                                break;
                        }
                    }
                }
            }
        }
    }
}
Also used : Label(com.badlogic.gdx.scenes.scene2d.ui.Label) SplitPane(com.badlogic.gdx.scenes.scene2d.ui.SplitPane) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Container(com.badlogic.gdx.scenes.scene2d.ui.Container) DrawableData(com.ray3k.skincomposer.data.DrawableData) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Tree(com.badlogic.gdx.scenes.scene2d.ui.Tree) List(com.badlogic.gdx.scenes.scene2d.ui.List) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) SelectBox(com.badlogic.gdx.scenes.scene2d.ui.SelectBox) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) FontData(com.ray3k.skincomposer.data.FontData) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) TooltipManager(com.badlogic.gdx.scenes.scene2d.ui.TooltipManager) ScrollPaneStyle(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane.ScrollPaneStyle) ListStyle(com.badlogic.gdx.scenes.scene2d.ui.List.ListStyle) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) TextButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) ProgressBar(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar) StyleData(com.ray3k.skincomposer.data.StyleData) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) TextFieldStyle(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldStyle) CustomStyle(com.ray3k.skincomposer.data.CustomStyle) Array(com.badlogic.gdx.utils.Array) ColorData(com.ray3k.skincomposer.data.ColorData) FreeTypeFontData(com.ray3k.skincomposer.data.FreeTypeFontData) CustomProperty(com.ray3k.skincomposer.data.CustomProperty)

Example 4 with Slider

use of com.badlogic.gdx.scenes.scene2d.ui.Slider 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();
    }
}
Also used : Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) Node(com.badlogic.gdx.graphics.g3d.model.Node) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) SplitPane(com.badlogic.gdx.scenes.scene2d.ui.SplitPane) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) ProgressBarStyle(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar.ProgressBarStyle) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) Tree(com.badlogic.gdx.scenes.scene2d.ui.Tree) List(com.badlogic.gdx.scenes.scene2d.ui.List) ProgressBar(com.badlogic.gdx.scenes.scene2d.ui.ProgressBar) 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) Array(com.badlogic.gdx.utils.Array) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)

Example 5 with Slider

use of com.badlogic.gdx.scenes.scene2d.ui.Slider in project AnotherMonekyParadox by SantiagoMille.

the class PantallaDeveloper method crearMenu.

private void crearMenu() {
    stageMenu = new Stage(vista);
    prefs = Gdx.app.getPreferences("AnotherMonkeyPreferenceStory");
    musicOn = prefs.getBoolean("music", true);
    dif = prefs.getFloat("Difficulty");
    sen = prefs.getFloat("Sensitivity");
    Skin skin = new Skin(Gdx.files.internal("skin/comic-ui.json"));
    imgBackground = new Texture("pantalla_config2.png");
    spriteBackground = new Sprite(imgBackground);
    spriteBackground.setAlpha(0.55f);
    // Boton Return
    TextureRegionDrawable trdReturn = new TextureRegionDrawable(new TextureRegion(new Texture("go-back.png")));
    ImageButton btnReturn = new ImageButton(trdReturn);
    btnReturn.setPosition(20, ALTO - 30 - btnReturn.getHeight());
    // Click en boton Return
    btnReturn.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            difficulty = sliderDif.getPercent();
            sensitivity = sliderSens.getPercent();
            prefs.putFloat("Difficulty", difficulty);
            prefs.putFloat("Sensitivity", sensitivity);
            prefs.flush();
            main.setScreen(new PantallaMenu(main));
        }
    });
    // Boton Play
    trdMusicPressed = new TextureRegionDrawable(new TextureRegion(new Texture("mute.png")));
    trdMusic = new TextureRegionDrawable(new TextureRegion(new Texture("audio.png")));
    btnPlay = new ImageButton(trdMusic);
    btnPlayPressed = new ImageButton(trdMusicPressed);
    if (musicOn) {
        btnPlayPressed.setVisible(false);
        btnPlay.setVisible(true);
    } else {
        btnPlayPressed.setVisible(true);
        btnPlay.setVisible(false);
    }
    btnPlay.setSize(100, 100);
    btnPlayPressed.setSize(100, 100);
    btnPlay.setPosition(ANCHO - btnPlay.getWidth() - 30, ALTO - btnPlay.getHeight() - 20);
    btnPlayPressed.setPosition(ANCHO - btnPlay.getWidth() - 30, ALTO - btnPlay.getHeight() - 20);
    // Click en boton Play
    btnPlay.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            musicOn = false;
            prefs.putBoolean("music", false);
            prefs.flush();
            btnPlayPressed.setVisible(true);
            btnPlay.setVisible(false);
        }
    });
    // Click en boton Play
    btnPlayPressed.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            musicOn = true;
            prefs.putBoolean("music", true);
            prefs.flush();
            btnPlayPressed.setVisible(false);
            btnPlay.setVisible(true);
        }
    });
    titulo = new Texto(1, 1, 1);
    Texture diff = new Texture("button_difficulty.png");
    diffi = new Sprite(diff);
    diffi.setPosition(ANCHO / 2 - 110 - diffi.getWidth(), ALTO / 2);
    sliderDif = new Slider(0, 100, 1, false, skin);
    sliderDif.setValue(dif * 100);
    sliderDif.setPosition(diffi.getX() + 100, ALTO / 3);
    sliderDif.setScale(2);
    Texture sens = new Texture("button_sensitivity.png");
    sensi = new Sprite(sens);
    sensi.setPosition(ANCHO / 2 + 110, ALTO / 2);
    sliderSens = new Slider(0, 100, 1, false, skin);
    sliderSens.setValue(sen * 100);
    sliderSens.setPosition(sensi.getX() + 100, ALTO / 3);
    sliderSens.setScale(2);
    TextureRegionDrawable creditsTRD = new TextureRegionDrawable(new TextureRegion(new Texture("button_credits.png")));
    ImageButton btnCreds = new ImageButton(creditsTRD);
    btnCreds.setPosition(ANCHO - 20 - btnCreds.getWidth(), 20);
    btnCreds.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            difficulty = sliderDif.getPercent();
            sensitivity = sliderSens.getPercent();
            prefs.putFloat("Difficulty", difficulty);
            prefs.putFloat("Sensitivity", sensitivity);
            prefs.flush();
            main.setScreen(new PantallaCredits(main));
        }
    });
    stageMenu.addActor(btnCreds);
    stageMenu.addActor(btnPlay);
    stageMenu.addActor(btnPlayPressed);
    stageMenu.addActor(sliderDif);
    stageMenu.addActor(sliderSens);
    stageMenu.addActor(btnReturn);
    Gdx.input.setInputProcessor(stageMenu);
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Slider(com.badlogic.gdx.scenes.scene2d.ui.Slider) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Texture(com.badlogic.gdx.graphics.Texture) Texto(mx.itesm.another_monkey_paradox.Utils.Texto) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

Slider (com.badlogic.gdx.scenes.scene2d.ui.Slider)10 Actor (com.badlogic.gdx.scenes.scene2d.Actor)9 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)9 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)8 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)8 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)7 Stage (com.badlogic.gdx.scenes.scene2d.Stage)6 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)6 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)6 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)5 SelectBox (com.badlogic.gdx.scenes.scene2d.ui.SelectBox)5 Texture (com.badlogic.gdx.graphics.Texture)4 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)4 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)4 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)4 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)4 List (com.badlogic.gdx.scenes.scene2d.ui.List)3 SplitPane (com.badlogic.gdx.scenes.scene2d.ui.SplitPane)3 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)3