private void fillTable() { StyleHelper helper = StyleHelper.getInstance(); Table scrollTable = new Table(); ImageButton newProfile = new ImageButton( helper.getImageButtonStyle("widgets/icon-plus")); newProfile.addListener(new NewProfileClickListener()); scrollTable.defaults().width(500).height(100).space(10); scrollTable.padTop(30); for (Profile profile : profileController.getAllProfiles()) { TextButton profileButton = new TextButton(profile.getName(), helper.getTextButtonStyle()); scrollTable.add(profileButton); scrollTable.row(); profileButton.addListener(new ChangeProfileClickListener()); } scrollTable.add(newProfile); scrollTable.padBottom(15); ScrollPane scrollPane = new ScrollPane(scrollTable); table.add(scrollPane).expand().fill(); }
/** * Sets the background drawable and sets the table's padding to {@link Drawable#getBottomHeight()} * , {@link Drawable#getTopHeight()}, {@link Drawable#getLeftWidth()}, and {@link * Drawable#getRightWidth()}. * * @param background If null, the background will be cleared and all padding is removed. */ public void setBackground(Drawable background) { if (this.background == background) return; this.background = background; if (background == null) pad(null); else { padBottom(background.getBottomHeight()); padTop(background.getTopHeight()); padLeft(background.getLeftWidth()); padRight(background.getRightWidth()); invalidate(); } }
public void createWindow() { Skin skin = new Skin(Gdx.files.internal("data/uiskin.json")); TextButton closeButton = new TextButton("", skin, "close-toggle"); Random random = new Random(); dialog = new Window("Terminal", skin); dialog.setBounds(10 + random.nextInt(50), 100 + random.nextInt(50), 400, 200); dialog.setResizable(true); dialog.setKeepWithinStage(true); dialog .getTitleTable() .add(closeButton) .size(dialog.getPadTop() * 4 / 5, dialog.getPadTop() * 4 / 5) .padRight(dialog.getPadRight()); dialog.left().top(); dialog.setResizeBorder(5); dialog.padRight(0); dialog.padBottom(1); SimpleDateFormat simpleDateformat = new SimpleDateFormat("E"); String day = simpleDateformat.format(new Date()); String month = new SimpleDateFormat("MMM").format(Calendar.getInstance().getTime()); int date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); int min = Calendar.getInstance().get(Calendar.MINUTE); int sec = Calendar.getInstance().get(Calendar.SECOND); String textTest = "Last login: "******" " + month + " " + String.format("%02d", date) + " " + String.format("%02d", hour) + ":" + String.format("%02d", min) + ":" + String.format("%02d", sec); cld.textHistory = textTest; consoleDialog = new Label(cld.textHistory, skin); consoleDialog.setWrap(true); consoleDialog.setAlignment(Align.topLeft, Align.topLeft); consoleArrow = new Label(cld.parser.getInputPrefix(), new LabelStyle(skin.get(LabelStyle.class))); consoleField = new TextField("", skin); consoleField.setFocusTraversal(false); Color colour = Color.ORANGE; colour.a = 0.8f; consoleField.getStyle().cursor = skin.newDrawable("white", colour); consoleField.getStyle().cursor.setMinWidth(10); consoleField.setBlinkTime(0.6f); Table scrollTable = new Table(); scrollTable.top(); scrollTable.add(consoleDialog).colspan(2).growX().fill().left().top(); scrollTable.row(); scrollTable.add(consoleArrow).left().top(); scrollTable.add(consoleField).expand(true, false).fill().left().top(); scrollTable.padBottom(1); consoleScroll = new ScrollPane(scrollTable, skin); consoleScroll.setFadeScrollBars(false); consoleScroll.setVariableSizeKnobs(true); consoleScroll.setFlickScroll(false); dialog.add(consoleScroll).fill().expand(); this.stage.addActor(dialog); closeButton.addListener(new CLICloseButtonListener(this, dialog)); setKeyboardFocus(); }
@Override public void setUpInterface(Table table) { // Create the actors for this screen. timer = new TimerActor(Constants.SECONDS, game.getSkin()); score = new ScoreActor(game.getSkin()); board = new BoardActor(game.getBallAtlas(), game.getState().getBoard()); // Add the help button. ImageButton help = new ImageButton(game.getSkin(), "blueHelp"); help.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // Don't act if the game hasn't started yet. if (!timer.isRunning() || game.getState().isTimeout()) { event.cancel(); return; } // Don't do anything if there are less than 5 seconds. if (timer.getSeconds() <= 5 && game.getState().getWiggledBounds() == null) { game.player.playSound(SoundCode.FAIL); event.cancel(); return; } // Wiggle a valid combination. if (game.getState().getWiggledBounds() == null) { CombinationFinder finder = CombinationFinder.create(game.getState().getBoard()); game.getState() .setWiggledBounds( finder .getPossibleBounds() .get(MathUtils.random(finder.getPossibleBounds().size() - 1))); } board.addAction(board.shake(game.getState().getWiggledBounds(), 10, 5, 0.1f)); if (!game.getState().isCheatSeen()) { // Subtract some time. float subtractedTime = 5f; final float step = subtractedTime / 10; getStage() .addAction( Actions.repeat( 10, Actions.delay( 0.01f, Actions.run( new Runnable() { @Override public void run() { timer.setSeconds(timer.getSeconds() - step); } })))); game.getState().setCheatSeen(true); } event.cancel(); } }); // Add the pause button. ImageButton pause = new ImageButton(game.getSkin(), "blueCross"); pause.addListener( new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { game.player.playSound(SoundCode.FAIL); pauseGame(); event.cancel(); } }); // Disable game until countdown ends. timer.setRunning(false); board.setTouchable(Touchable.disabled); // Add subscribers. timer.addSubscriber(this); board.addSubscriber(this); score.setScoreListener(this); /* * Fill the HUD, which is the display that appears over the board with * all the information. The HUD is generated differently depending on * the aspect ratio of the device. If the device is 4:3, the HUD is * compressed to avoid making the board small. Otherwise, it's expanded * to the usual size. */ boolean landscape = Gdx.graphics.getWidth() > Gdx.graphics.getHeight(); float aspectRatio = landscape ? (float) Gdx.graphics.getWidth() / Gdx.graphics.getHeight() : (float) Gdx.graphics.getHeight() / Gdx.graphics.getWidth(); hud = new Table(); if (aspectRatio < 1.5f) { // Compact layout: buttons and score in the same line. hud.add(new BorderedContainer(game.getSkin(), help)).size(50).padBottom(10); hud.add(new BorderedContainer(game.getSkin(), score)) .height(50) .width(Constants.VIEWPORT_WIDTH / 2) .space(10) .expandX() .fillX(); hud.add(new BorderedContainer(game.getSkin(), pause)).size(50).padBottom(10).row(); hud.add(new BorderedContainer(game.getSkin(), timer)) .colspan(3) .fillX() .height(40) .padBottom(20) .row(); } else { // Large layout: buttons above timer, score below timer (classic). hud.add(new BorderedContainer(game.getSkin(), help)) .size(50) .spaceLeft(10) .padBottom(10) .align(Align.left); hud.add(new BorderedContainer(game.getSkin(), pause)) .size(50) .spaceRight(10) .padBottom(10) .align(Align.right) .row(); hud.add(new BorderedContainer(game.getSkin(), timer)) .colspan(2) .fillX() .expandX() .height(40) .padBottom(10) .row(); hud.add(new BorderedContainer(game.getSkin(), score)) .colspan(2) .height(60) .width(Constants.VIEWPORT_WIDTH / 2) .align(Align.center) .padBottom(10) .row(); } if (aspectRatio > 1.6) { hud.padBottom(20); } table.add(hud).fillX().expandY().align(Align.top).row(); table.add(board).fill().expand().row(); }