Search in sources :

Example 1 with Badges

use of com.watabou.pixeldungeon.Badges in project pixel-dungeon by watabou.

the class BadgesScene method create.

@Override
public void create() {
    super.create();
    Music.INSTANCE.play(Assets.THEME, true);
    Music.INSTANCE.volume(1f);
    uiCamera.visible = false;
    int w = Camera.main.width;
    int h = Camera.main.height;
    Archs archs = new Archs();
    archs.setSize(w, h);
    add(archs);
    int pw = (int) Math.min(w, (PixelDungeon.landscape() ? MIN_WIDTH_L : MIN_WIDTH_P) * 3) - 16;
    int ph = (int) Math.min(h, (PixelDungeon.landscape() ? MIN_HEIGHT_L : MIN_HEIGHT_P) * 3) - 32;
    float size = (float) Math.sqrt(pw * ph / 27f);
    int nCols = (int) Math.ceil(pw / size);
    int nRows = (int) Math.ceil(ph / size);
    size = Math.min(pw / nCols, ph / nRows);
    float left = (w - size * nCols) / 2;
    float top = (h - size * nRows) / 2;
    BitmapText title = PixelScene.createText(TXT_TITLE, 9);
    title.hardlight(Window.TITLE_COLOR);
    title.measure();
    title.x = align((w - title.width()) / 2);
    title.y = align((top - title.baseLine()) / 2);
    add(title);
    Badges.loadGlobal();
    List<Badges.Badge> badges = Badges.filtered(true);
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            int index = i * nCols + j;
            Badges.Badge b = index < badges.size() ? badges.get(index) : null;
            BadgeButton button = new BadgeButton(b);
            button.setPos(left + j * size + (size - button.width()) / 2, top + i * size + (size - button.height()) / 2);
            add(button);
        }
    }
    ExitButton btnExit = new ExitButton();
    btnExit.setPos(Camera.main.width - btnExit.width(), 0);
    add(btnExit);
    fadeIn();
    Badges.loadingListener = new Callback() {

        @Override
        public void call() {
            if (Game.scene() == BadgesScene.this) {
                PixelDungeon.switchNoFade(BadgesScene.class);
            }
        }
    };
}
Also used : ExitButton(com.watabou.pixeldungeon.ui.ExitButton) WndBadge(com.watabou.pixeldungeon.windows.WndBadge) Callback(com.watabou.utils.Callback) Archs(com.watabou.pixeldungeon.ui.Archs) BitmapText(com.watabou.noosa.BitmapText) Badges(com.watabou.pixeldungeon.Badges)

Aggregations

BitmapText (com.watabou.noosa.BitmapText)1 Badges (com.watabou.pixeldungeon.Badges)1 Archs (com.watabou.pixeldungeon.ui.Archs)1 ExitButton (com.watabou.pixeldungeon.ui.ExitButton)1 WndBadge (com.watabou.pixeldungeon.windows.WndBadge)1 Callback (com.watabou.utils.Callback)1