private void initialize() { setModal(true); defaults().space(6); add(contentTable = new Table(skin)).expand().fill(); row(); add(buttonTable = new Table(skin)); contentTable.defaults().space(6); buttonTable.defaults().space(6); buttonTable.addListener( new ChangeListener() { public void changed(ChangeEvent event, Actor actor) { if (!values.containsKey(actor)) return; while (actor.getParent() != buttonTable) actor = actor.getParent(); result(values.get(actor)); if (!cancelHide) hide(); cancelHide = false; } }); focusListener = new FocusListener() { public void keyboardFocusChanged(FocusEvent event, Actor actor, boolean focused) { if (!focused) focusChanged(event); } public void scrollFocusChanged(FocusEvent event, Actor actor, boolean focused) { if (!focused) focusChanged(event); } private void focusChanged(FocusEvent event) { Stage stage = getStage(); if (isModal && stage != null && stage.getRoot().getChildren().size > 0 && stage.getRoot().getChildren().peek() == Dialog.this) { // Dialog is top most actor. Actor newFocusedActor = event.getRelatedActor(); if (newFocusedActor != null && !newFocusedActor.isDescendantOf(Dialog.this) && !(newFocusedActor.equals(previousKeyboardFocus) || newFocusedActor.equals(previousScrollFocus))) event.cancel(); } } }; }
public void show() { stage = new Stage(); Gdx.input.setInputProcessor(stage); atlas = new TextureAtlas("ui/atlas.pack"); skin = new Skin(Gdx.files.internal("ui/menuSkin.json"), atlas); Texture chipBg = new Texture(Gdx.files.internal("img/chips.png")); stage.addActor(new Image(chipBg)); table = new Table(skin); table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); table.bottom().right(); backButton = new TextButton("BACK", skin); backButton.addListener( new ClickListener() { public void clicked(InputEvent event, float x, float y) { ((Game) Gdx.app.getApplicationListener()).setScreen(new PotatoMenu()); } }); backButton.pad(10); table.add(backButton).bottom().right(); ; stage.addActor(table); tweenManager = new TweenManager(); Tween.registerAccessor(Actor.class, new ActorAccessor()); tweenManager.update(Gdx.graphics.getDeltaTime()); stage.addAction(sequence(moveTo(0, stage.getHeight()), moveTo(0, 0, .5f))); }
/** * Adds the given button to the button table. * * @param object The object that will be passed to {@link #result(Object)} if this button is * clicked. May be null. */ public Dialog button(Button button, Object object) { buttonTable.add(button); setObject(button, object); return this; }
/** Adds the given Label to the content table */ public Dialog text(Label label) { contentTable.add(label); return this; }
public void resize(int width, int height) { stage.setViewport(width, height, true); table.invalidateHierarchy(); table.setSize(width, height); }