use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project libgdx by libgdx.
the class TableTest method create.
@Override
public void create() {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
TextureRegion region = new TextureRegion(texture);
NinePatch patch = skin.getPatch("default-round");
Label label = new Label("This is some text.", skin);
root = new Table() {
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
}
};
stage.addActor(root);
// root.setTransform(true);
Table table = new Table();
table.setTransform(true);
table.setPosition(100, 100);
table.setOrigin(0, 0);
table.setRotation(45);
table.setScaleY(2);
table.add(label);
table.add(new TextButton("Text Button", skin));
table.pack();
// table.debug();
table.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("click!");
}
});
// root.addActor(table);
TextButton button = new TextButton("Text Button", skin);
Table table2 = new Table();
// table2.debug()
table2.add(button);
table2.setTransform(true);
table2.setScaleX(1.5f);
table2.setOrigin(table2.getPrefWidth() / 2, table2.getPrefHeight() / 2);
// Test colspan with expandX.
// root.setPosition(10, 10);
root.debug();
root.setFillParent(true);
root.add(new Label("meow meow meow meow meow meow meow meow meow meow meow meow", skin)).colspan(3).expandX();
root.add(new TextButton("Text Button", skin));
root.row();
root.add(new TextButton("Text Button", skin));
root.add(new TextButton("Toggle Button", skin.get("toggle", TextButtonStyle.class)));
root.add(new CheckBox("meow meow meow meow meow meow meow meow", skin));
// root.pack();
// root.add(new Button(new Image(region), skin));
// root.add(new LabelButton("Toggley", skin.getStyle("toggle", LabelButtonStyle.class)));
}
use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project Entitas-Java by Rubentxu.
the class MenuState method init.
@Override
public void init() {
Gdx.app.log("Menu", "Init");
int pad = (int) (20 * SMGUIManager.ScaleUtil.getSizeRatio());
int pad2 = (int) (60 * SMGUIManager.ScaleUtil.getSizeRatio());
final TextButton btnStart = new TextButton("Comenzar", skin);
btnStart.pad(pad, pad2, pad, pad2);
final TextButton btnOptions = new TextButton("Opciones", skin);
btnOptions.pad(pad, pad2, pad, pad2);
final TextButton btnScores = new TextButton("Puntuaciones", skin);
btnScores.pad(pad, pad2, pad, pad2);
final TextButton button3 = new TextButton("Creditos", skin);
button3.pad(pad, pad2, pad, pad2);
button3.setChecked(false);
btnStart.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("Click Comenzar...");
}
});
btnOptions.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("Click optionScreen...");
SMGame.ebus.post((ChangeStateCommand<SMGame>) (nameState, game) -> game.changeState(game.getOptionState(), game.getFadeTransition()));
}
});
btnScores.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
System.out.println("Click highScoreScreen...");
SMGame.ebus.post((ChangeStateCommand<SMGame>) (nameState, game) -> game.changeState(game.getScoresState(), game.getSlideTransition()));
}
});
Label label = new Label("SUPER MARIANO", skin, "header", Color.CYAN);
label.setAlignment(Align.center, Align.center);
mainTable.defaults().padBottom(pad);
if (Gdx.graphics.getHeight() < 480)
mainTable.defaults().height(Gdx.graphics.getHeight() / 5f - pad);
mainTable.add(label);
mainTable.row();
mainTable.add(btnStart);
mainTable.row();
mainTable.add(btnOptions);
mainTable.row();
mainTable.add(btnScores);
mainTable.row();
mainTable.add(button3);
mainTable.row();
mainTable.setBackground(new SpriteDrawable(new Sprite((Texture) assetsManager.getTexture(SMGUIManager.MENU_BACKGROUND))));
mainTable.row();
}
use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project bladecoder-adventure-engine by bladecoder.
the class DialogUI method show.
private void show() {
choices = World.getInstance().getDialogOptions();
if (choices.size() == 0)
return;
else if (style.autoselect && choices.size() == 1) {
// If only has one option, autoselect it
select(0);
return;
}
panel.clear();
for (int i = 0; i < choices.size(); i++) {
String str = choices.get(i);
if (str.charAt(0) == I18N.PREFIX)
str = I18N.getString(str.substring(1));
TextButton ob = new TextButton(str, style.textButtonStyle);
ob.setUserObject(i);
panel.row();
panel.add(ob);
ob.getLabel().setWrap(true);
ob.getLabel().setAlignment(Align.left);
ob.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
int i = (Integer) event.getListenerActor().getUserObject();
select(i);
}
});
}
panel.pack();
setWidth(getStage().getViewport().getScreenWidth());
setHeight(Math.min(panel.getHeight(), getStage().getViewport().getScreenHeight() / 2));
float size = DPIUtils.getPrefButtonSize() * .8f;
float margin = DPIUtils.getSpacing();
getStage().addActor(up);
up.setSize(size, size);
up.setPosition(getX() + getWidth() - size - margin, getY() + getHeight() - margin - size);
up.setVisible(false);
getStage().addActor(down);
down.setSize(size, size);
down.setPosition(getX() + getWidth() - size - margin, getY() + margin);
down.setVisible(false);
}
use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project bladecoder-adventure-engine by bladecoder.
the class LoadSaveScreen method show.
@Override
public void show() {
float size = DPIUtils.getPrefButtonSize();
float pad = DPIUtils.getMarginSize();
final Skin skin = ui.getSkin();
final World world = World.getInstance();
// loadScreenMode = ui.getScreen(Screens.LOAD_GAME_SCREEN) == this;
loadScreenMode = world.getCurrentScene() == null;
stage = new Stage(new ScreenViewport());
slotWidth = (int) (stage.getViewport().getWorldWidth() / (ROW_SLOTS + 1) - 2 * pad);
slotHeight = (int) (slotWidth * stage.getViewport().getScreenHeight() / stage.getViewport().getScreenWidth());
LoadSaveScreenStyle style = skin.get(LoadSaveScreenStyle.class);
Drawable bg = style.background;
if (bg == null && style.bgFile != null) {
bgTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.bgFile));
bgTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear);
bg = new TextureRegionDrawable(new TextureRegion(bgTexFile));
}
Table table = new Table(skin);
table.setFillParent(true);
table.center();
table.pad(pad);
Label title = new Label(loadScreenMode ? I18N.getString("ui.load") : I18N.getString("ui.save"), skin, "title");
Button back = new Button(skin, "back");
back.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
ui.setCurrentScreen(Screens.MENU_SCREEN);
}
});
Table header = new Table();
// header.padBottom(pad);
Container<Button> cont = new Container<Button>(back);
cont.size(size);
header.add(cont);
header.add(title).fillX().expandX().left();
table.add(header).fillX().expandX().left();
if (bg != null)
table.setBackground(bg);
table.addListener(new InputListener() {
@Override
public boolean keyUp(InputEvent event, int keycode) {
if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK)
if (world.getCurrentScene() != null)
ui.setCurrentScreen(Screens.SCENE_SCREEN);
return true;
}
});
final PagedScrollPane scroll = new PagedScrollPane();
scroll.setFlingTime(0.1f);
scroll.setPageSpacing(0);
Table slots = new Table().pad(pad);
slots.defaults().pad(pad).size(slotWidth + pad, slotHeight + pad * 2).top();
int c = 0;
// Add "new slot" slot for save screen
if (!loadScreenMode) {
slots.add(getSlotButton(Long.toString(new Date().getTime()))).fill().expand();
c++;
}
final List<String> sl = getSlots();
Collections.sort(sl);
for (int j = sl.size() - 1; j >= 0; j--) {
String s = sl.get(j);
if (c % ROW_SLOTS == 0 && c % (ROW_SLOTS * COL_SLOTS) != 0)
slots.row();
if (c != 0 && c % (ROW_SLOTS * COL_SLOTS) == 0) {
scroll.addPage(slots);
slots = new Table().pad(pad);
slots.defaults().pad(pad).size(slotWidth + pad, slotHeight + pad * 2).top();
}
Button removeButton = new Button(skin, "delete_game");
removeButton.setName(s);
removeButton.addListener(removeClickListener);
Container<Button> container = new Container<Button>(removeButton);
container.size(DPIUtils.getPrefButtonSize() * .75f);
container.align(Align.topRight);
slots.stack(getSlotButton(s), container).fill().expand();
c++;
}
// Add last page
if (slots.getCells().size > 0)
scroll.addPage(slots);
table.row();
if (loadScreenMode && sl.size() == 0) {
Label lbl = new Label(I18N.getString("ui.noSavedGames"), skin, "title");
lbl.setAlignment(Align.center);
lbl.setWrap(true);
table.add(lbl).expand().fill();
} else {
table.add(scroll).expand().fill();
}
table.pack();
stage.setKeyboardFocus(table);
stage.addActor(table);
pointer = new Pointer(ui.getSkin());
stage.addActor(pointer);
Gdx.input.setInputProcessor(stage);
}
use of com.badlogic.gdx.scenes.scene2d.utils.ClickListener in project AnotherMonekyParadox by SantiagoMille.
the class PantallaJuego3 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_n3.png");
itemBosss = new Texture("Bosses/item_boss3.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() + 63);
listaBalas.add(nueva);
} else {
if (music) {
gunSound.play();
}
Bala nueva = new Bala(bananaDisparo, true);
nueva.set(personaje.getX(), personaje.getY() + 63);
listaBalas.add(nueva);
}
}
Bar.setValue(Bar.getValue() - 0.18f);
}
});
// 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 PantallaJuego3.EscenaPausa3(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);
}
Aggregations