package ch.asynk.tankontank.menu; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import ch.asynk.tankontank.ui.Label; import ch.asynk.tankontank.ui.Bg; import ch.asynk.tankontank.ui.Patch; import ch.asynk.tankontank.TankOnTank; import ch.asynk.tankontank.game.Battle; public class ScenariosMenu extends Patch { public static int PADDING = 40; public static int BTN_PADDING = 10; public static int TITLE_PADDING = 30; public static int VSPACING = 5; public static int HSPACING = 30; public static String CHECK = "#"; private final TankOnTank game; private final BitmapFont font; private float checkDy; private Label title; protected Bg okBtn; protected Bg cancelBtn; private Label [] battleLabels; public boolean launch; public ScenariosMenu(TankOnTank game, BitmapFont font, TextureAtlas atlas) { super(atlas.createPatch("typewriter")); this.game = game; this.font = font; this.okBtn = new Bg(atlas.findRegion("ok")); this.cancelBtn = new Bg(atlas.findRegion("cancel")); this.title = new Label(font); this.title.write("- Scenarios"); this.battleLabels = new Label[game.factory.battles.length]; for (int i = 0; i < battleLabels.length; i++) { Label l = new Label(font, 8f); l.write(game.factory.battles[i].getName()); battleLabels[i] = l; } checkDy = font.getMultiLineBounds(CHECK).height + 9; this.visible = false; this.launch = false; } public void setPosition() { float h = (title.getHeight() + TITLE_PADDING + ((battleLabels.length - 1) * VSPACING) + (2 * PADDING)); for (int i = 0; i < battleLabels.length; i++) h += battleLabels[i].getHeight(); float w = title.getWidth(); for (int i = 0; i < battleLabels.length; i++) { float t = battleLabels[i].getWidth(); if (t > w) w = t; } w += (2 * PADDING) + HSPACING; float x = position.getX(w); float y = position.getY(h); setPosition(x, y, w, h); okBtn.setPosition((x + w - okBtn.getWidth() + BTN_PADDING), (y - BTN_PADDING)); cancelBtn.setPosition((x - BTN_PADDING), okBtn.getY()); y += PADDING; x += PADDING + HSPACING; float dy = (VSPACING + battleLabels[0].getHeight()); for (int i = (battleLabels.length - 1); i > -1; i--) { battleLabels[i].setPosition(x, y); y += dy; } y += (TITLE_PADDING - VSPACING); title.setPosition(x, y); } @Override public boolean hit(float x, float y) { if (!visible) return false; if (okBtn.hit(x, y)) { this.launch = (game.config.battle != null); return true; } else if (cancelBtn.hit(x, y)) { this.launch = false; return true; } else { for (int i = 0; i