Search in sources :

Example 26 with ClickListener

use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project skin-composer by raeleus.

the class DialogDrawables method refreshDrawableDisplay.

private void refreshDrawableDisplay() {
    contentGroup.clear();
    if (drawables.size == 0) {
        Label label = new Label("No drawables have been added!", getSkin());
        contentGroup.addActor(label);
    }
    for (DrawableData drawable : drawables) {
        Button drawableButton;
        if (property != null || customProperty != null) {
            drawableButton = new Button(getSkin(), "color-base");
            drawableButton.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    result(drawable);
                    hide();
                }
            });
            drawableButton.addListener(main.getHandListener());
        } else {
            drawableButton = new Button(getSkin(), "color-base-static");
        }
        contentGroup.addActor(drawableButton);
        Table table = new Table();
        drawableButton.add(table).width(sizes[MathUtils.floor(zoomSlider.getValue())]).height(sizes[MathUtils.floor(zoomSlider.getValue())]);
        ClickListener fixDuplicateTouchListener = new ClickListener() {

            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                event.setBubbles(false);
                return super.touchDown(event, x, y, pointer, button);
            }
        };
        // color wheel
        if (!drawable.customized && !drawable.tiled) {
            Button button = new Button(getSkin(), "colorwheel");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    newTintedDrawable(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("New Tinted Drawable", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else {
            table.add();
        }
        // swatches
        if (!drawable.customized && !drawable.tiled) {
            Button button = new Button(getSkin(), "swatches");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    colorSwatchesDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("Tinted Drawable from Colors", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else {
            table.add();
        }
        // tiles button (NOT FOR TINTS OR CUSTOM DRAWABLES)
        if (!drawable.customized && drawable.tint == null && drawable.tintName == null) {
            ;
            Button button = new Button(getSkin(), "tiles");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    tiledDrawableDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("Tiled Drawable", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else {
            table.add();
        }
        // tiled settings
        if (drawable.tiled) {
            Button button = new Button(getSkin(), "settings-small");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    tiledDrawableSettingsDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("Tiled Drawable Settings", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else // rename (ONLY FOR TINTS)
        if (drawable.tint != null || drawable.tintName != null) {
            Button button = new Button(getSkin(), "settings-small");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    renameDrawableDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("Rename Tinted Drawable", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else // settings for custom drawables
        if (drawable.customized) {
            Button button = new Button(getSkin(), "settings-small");
            button.addListener(new ChangeListener() {

                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    renameCustomDrawableDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null && customProperty == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
            TextTooltip toolTip = new TextTooltip("Rename Custom Drawable", main.getTooltipManager(), getSkin());
            button.addListener(toolTip);
        } else {
            table.add();
        }
        // delete
        Button button = new Button(getSkin(), "delete-small");
        button.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                deleteDrawable(drawable);
                event.setBubbles(false);
            }
        });
        button.addListener(fixDuplicateTouchListener);
        if (property == null && customProperty == null) {
            button.addListener(main.getHandListener());
        }
        table.add(button).expandX().right();
        TextTooltip toolTip = new TextTooltip("Delete Drawable", main.getTooltipManager(), getSkin());
        button.addListener(toolTip);
        // preview
        table.row();
        Container bg = new Container();
        bg.setClip(true);
        bg.setBackground(getSkin().getDrawable("white"));
        bg.setColor(drawable.bgColor);
        Image image = new Image(drawablePairs.get(drawable));
        if (MathUtils.isZero(zoomSlider.getValue())) {
            image.setScaling(Scaling.fit);
            bg.fill(false);
        } else {
            image.setScaling(Scaling.stretch);
            bg.fill();
        }
        bg.setActor(image);
        table.add(bg).colspan(5).grow();
        // name
        table.row();
        Label label = new Label(drawable.name, getSkin());
        label.setEllipsis("...");
        label.setEllipsis(true);
        label.setAlignment(Align.center);
        table.add(label).colspan(5).growX().width(sizes[MathUtils.floor(zoomSlider.getValue())]);
        // Tooltip
        toolTip = new TextTooltip(drawable.name, main.getTooltipManager(), getSkin());
        label.addListener(toolTip);
    }
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) DrawableData(com.ray3k.skincomposer.data.DrawableData) Container(com.badlogic.gdx.scenes.scene2d.ui.Container) TextTooltip(com.badlogic.gdx.scenes.scene2d.ui.TextTooltip) Button(com.badlogic.gdx.scenes.scene2d.ui.Button) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 27 with ClickListener

use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project commons-gdx by gemserk.

the class Actors method threeOptionsDialog.

public static Actor threeOptionsDialog(String[] texts, final DialogListener dialogListener, String titleText, String firstOption, String secondOption, String thirdOption, Skin skin) {
    Window window = new Window(titleText, skin);
    window.setMovable(false);
    TextButton firstOptionButton = new TextButton(firstOption, skin);
    TextButton secondOptionButton = new TextButton(secondOption, skin);
    TextButton thirdOptionButton = new TextButton(thirdOption, skin);
    firstOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(0);
        }
    });
    secondOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(1);
        }
    });
    thirdOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(2);
        }
    });
    window.defaults().spaceBottom(10);
    window.row().fill().expandX();
    for (int i = 0; i < texts.length; i++) {
        window.row().padLeft(20);
        Label label = new Label(texts[i], skin);
        label.setWrap(true);
        window.add(label).align(Align.left).colspan(2).fillX();
    }
    window.row().fill().expandX().padTop(10);
    window.add(firstOptionButton).align(Align.center).padLeft(30).padRight(30);
    window.row().fill().expandX();
    window.add(secondOptionButton).align(Align.center).padLeft(30).padRight(30);
    window.row().fill().expandX();
    window.add(thirdOptionButton).align(Align.center).padLeft(30).padRight(30);
    ScrollPane scrollPane = new ScrollPane(window);
    scrollPane.setWidth(Gdx.graphics.getWidth() * 0.95f);
    scrollPane.setHeight(Gdx.graphics.getHeight() * 0.95f);
    scrollPane.setX(Gdx.graphics.getWidth() * 0.5f - scrollPane.getWidth() * 0.5f);
    scrollPane.setY(Gdx.graphics.getHeight() * 0.5f - scrollPane.getHeight() * 0.5f);
    return scrollPane;
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 28 with ClickListener

use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project var3dframe by Var3D.

the class DialogTest method init.

@Override
public void init() {
    // 设置背景
    setBackground(new ActorGradient(400, 300, Color.CYAN, Color.CORAL));
    // 设置标题(对话框使用show方法的时候不能省略父对象参数)
    game.getLabel(R.strings.dialogTitle).touchOff().setPosition(getWidth() / 2, getHeight() - 20, Align.top).setColor(Color.RED).setStroke(Color.YELLOW).show(this);
    // 关闭按钮
    Button btn_close = game.getButton(R.image.pause_btn_bg).addClicAction().setPosition(getWidth() / 2, 50, Align.bottom).show(this);
    btn_close.add(game.getLabel("关闭").setColor(Color.RED).getActor());
    btn_close.addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            game.removeDialog(DialogTest.this);
        // or game.removeTopDialog();
        // or game.removeAllDialog();
        }
    });
}
Also used : Button(com.badlogic.gdx.scenes.scene2d.ui.Button) ActorGradient(var3d.net.center.ActorGradient) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 29 with ClickListener

use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project var3dframe by Var3D.

the class DialogMessge method init.

@Override
public void init() {
    setBackground(game.getUI(new Actor()).setSize(game.WIDTH, game.HEIGHT).getActor());
    img_bg = game.getImage(getWidth() / 2, 1).touchOff().show(this);
    lab_msg = game.getLabel("messge").setColor(Color.DARK_GRAY).touchOff().show(this);
    lab_msg.setWrap(true);
    lab_msg.setAlignment(Align.center);
    lab_msg.setWidth(getWidth() / 2 - game.getDefaultFontSize());
    lab_msg.setPosition(getWidth() / 2, getHeight() / 2, Align.center);
    addListener(new ClickListener() {

        public void clicked(InputEvent event, float x, float y) {
            game.removeDialog(DialogMessge.this);
        }
    });
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 30 with ClickListener

use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project AnotherMonekyParadox by SantiagoMille.

the class PantallaJuego4 method crearMapa.

private void crearMapa() {
    cargarTexturas();
    Gdx.input.setCatchBackKey(true);
    stageNivel = new Stage(vista);
    // para sacar número random donde se crean los powerups
    random = new Random();
    // Objeto que dibuja texto
    // font = new BitmapFont(Gdx.files.internal("tutorial.fnt"));
    // textoGly = new GlyphLayout(font,"Score");
    // textoGlyGran = new GlyphLayout(font,"Score");
    boss = new Texture("Bosses/jefe_n4.png");
    itemBosss = new Texture("item_boss.png");
    bossSprite = new Sprite(boss);
    bossSprite.setPosition(ANCHO, ALTO);
    itemBoss = new Sprite(itemBosss);
    itemBoss.setPosition(ANCHO * 3 / 4, ALTO / 4);
    for (int i = 0; i < 5; i++) {
        if (i < cuentaVidas) {
            vidas.add(new PowerUp(new Texture("vida.png"), camara.position.x + 10 - ANCHO / 2 + (75 * i), ALTO - 70, true));
        } else {
            vidas.add(new PowerUp(new Texture("vida.png"), camara.position.x + 10 - ANCHO / 2 + (75 * i), ALTO - 70, false));
        }
    }
    // Granadas Colisión
    // banana1 = new Bala(bananaDisparo,false);
    banana1.set(-100, -100);
    // banana2 = new Bala(bananaDisparo, false);
    banana2.set(-100, -100);
    // banana3 = new Bala(bananaDisparo, false);
    banana3.set(-100, -100);
    // banana4 = new Bala(bananaDisparo, true);
    banana4.set(-100, -100);
    // banana5 = new Bala(bananaDisparo, true);
    banana5.set(-100, -100);
    // banana6 = new Bala(bananaDisparo, true);
    banana6.set(-100, -100);
    randomX = random.nextDouble() * 4000;
    randomX22 = random.nextDouble() * 4000;
    randomX2 = random.nextDouble() * 4000;
    // Barra Bala
    Bar.setPosition(745, ALTO * 0.93f);
    barraBala.setPosition(740, (ALTO * 0.92f) + 3);
    bananaBarra.setPosition(700, (ALTO * 0.90f));
    granada.setPosition(ANCHO * 3 / 4 - granada.getWidth() / 2 + 25, ALTO / 4 - granada.getHeight() / 2 - 80);
    granadasNum.setPosition(ANCHO * 0.712f - granadasNum.getWidth() / 2, ALTO / 4 - granadasNum.getHeight() / 2 - 40);
    /*
        //boton disparo
        TextureRegionDrawable btnArma = new TextureRegionDrawable(new TextureRegion(botonDisparo));
        TextureRegionDrawable btnArmaPressed = new TextureRegionDrawable(new TextureRegion(botonDisparoPressed));
        arma = new ImageButton(btnArma, btnArmaPressed);
        */
    arma.setPosition(ANCHO * 3 / 4 - arma.getWidth() / 2 + arma.getWidth() + 55, ALTO / 4 - arma.getHeight() / 2 - 80);
    /*
        //boton pausa
        TextureRegionDrawable btnPausa = new TextureRegionDrawable(new TextureRegion(botonPausa));
        pausa = new ImageButton(btnPausa);
        */
    pausa.setSize(55, 55);
    pausa.setPosition(ANCHO / 2 - pausa.getWidth() / 2, 680 - pausa.getHeight() / 2);
    /*
        //boton continua
        TextureRegionDrawable btnContinua = new TextureRegionDrawable(new TextureRegion(botonContinua));
        continua = new ImageButton(btnContinua);
        */
    continua.setSize(55, 55);
    continua.setPosition(ANCHO / 2 - continua.getWidth() / 2, 680 - continua.getHeight() / 2);
    /*
        //boton Home
        TextureRegionDrawable btnHome = new TextureRegionDrawable(new TextureRegion(botonHome));
        home = new ImageButton(btnContinua);
        */
    home.setSize(55, 55);
    home.setPosition(ANCHO / 2 - continua.getWidth() / 2, 680 - continua.getHeight() / 2);
    // Texturas para el pad
    Skin skin = new Skin();
    skin.add("fondo", padBack);
    skin.add("boton", padKnob);
    Touchpad.TouchpadStyle estilo = new Touchpad.TouchpadStyle();
    estilo.background = skin.getDrawable("fondo");
    estilo.knob = skin.getDrawable("boton");
    // Crea el pad
    // Radio, estilo
    Touchpad pad = new Touchpad(64, estilo);
    // x,y - ancho,alto
    pad.setBounds(40, 30, 200, 200);
    // Comportamiento del pad
    pad.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            Touchpad pad = (Touchpad) actor;
            if (pad.getKnobPercentX() > 0.25) {
                // Más de 20% de desplazamiento DERECHA
                personaje.setRight(true);
                isMovingRight = true;
                isMovingLeft = false;
            } else if (pad.getKnobPercentX() < -0.25) {
                // Más de 20% IZQUIERDA
                personaje.setRight(false);
                isMovingLeft = true;
                isMovingRight = false;
            } else {
                isMovingLeft = false;
                isMovingRight = false;
            }
        }
    });
    // Transparente
    pad.setColor(1, 1, 1, 0.7f);
    // Comportamiento de Boton Granada
    granada.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            if (maxGrandas > 0) {
                if (!isFliped) {
                    Granada grana = new Granada(bananaGranada, false);
                    grana.set(personaje.getX() + 105, personaje.getY() + 68);
                    listaGranadas.add(grana);
                    maxGrandas--;
                } else {
                    Granada grana = new Granada(bananaGranada, true);
                    grana.set(personaje.getX(), personaje.getY() + 68);
                    listaGranadas.add(grana);
                    maxGrandas--;
                }
            }
        }
    });
    // Comportamiento de Boton Disparo
    arma.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            if (Bar.getValue() > 0.1) {
                if (music) {
                    gunSound.play();
                }
                if (!isFliped) {
                    Bala nueva = new Bala(bananaDisparo, false);
                    nueva.set(personaje.getX() + 105, personaje.getY() + 70);
                    listaBalas.add(nueva);
                } else {
                    if (music) {
                        gunSound.play();
                    }
                    Bala nueva = new Bala(bananaDisparo, true);
                    nueva.set(personaje.getX(), personaje.getY() + 70);
                    listaBalas.add(nueva);
                }
            }
            Bar.setValue(Bar.getValue() - 0.08f);
        }
    });
    // Comportamiento de Boton Pausa
    pausa.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            // Gdx.app.log("ClickListener","Si se clickeoooo");
            estado = PantallaJuego.EstadoJuego.PAUSADO;
            // main.setScreen((Screen) new EscenaPausa2(vista,batch));
            if (escenaPausa == null) {
                escenaPausa = new PantallaJuego4.EscenaPausa4(vista, batch);
            }
            Gdx.input.setInputProcessor(escenaPausa);
            pause();
        }
    });
    stageNivel.addActor(granada);
    stageNivel.addActor(arma);
    stageNivel.addActor(pausa);
    stageNivel.addActor(pad);
    stageNivel.addActor(Bar);
    Gdx.input.setInputProcessor(stageNivel);
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Granada(mx.itesm.another_monkey_paradox.Objetos.Granada) Bala(mx.itesm.another_monkey_paradox.Objetos.Bala) Texture(com.badlogic.gdx.graphics.Texture) Random(java.util.Random) Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) Actor(com.badlogic.gdx.scenes.scene2d.Actor) PowerUp(mx.itesm.another_monkey_paradox.Objetos.PowerUp) 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

ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)74 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)72 Stage (com.badlogic.gdx.scenes.scene2d.Stage)39 Texture (com.badlogic.gdx.graphics.Texture)26 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)26 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)24 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)23 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)23 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)23 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)22 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)21 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)18 Actor (com.badlogic.gdx.scenes.scene2d.Actor)17 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)12 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)7 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)7 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)6 Touchpad (com.badlogic.gdx.scenes.scene2d.ui.Touchpad)6 Texto (mx.itesm.another_monkey_paradox.Utils.Texto)6 Random (java.util.Random)5