Search in sources :

Example 1 with Badges

use of com.shatteredpixel.shatteredpixeldungeon.Badges in project shattered-pixel-dungeon-gdx by 00-Evan.

the class BadgesScene method create.

@Override
public void create() {
    super.create();
    Music.INSTANCE.play(Assets.THEME, true);
    uiCamera.visible = false;
    int w = Camera.main.width;
    int h = Camera.main.height;
    Archs archs = new Archs();
    archs.setSize(w, h);
    add(archs);
    float left = 5;
    float top = 16;
    RenderedText title = PixelScene.renderText(Messages.get(this, "title"), 9);
    title.hardlight(Window.TITLE_COLOR);
    title.x = (w - title.width()) / 2f;
    title.y = (top - title.baseLine()) / 2f;
    align(title);
    add(title);
    Badges.loadGlobal();
    List<Badges.Badge> badges = Badges.filtered(true);
    int blankBadges = 34;
    blankBadges -= badges.size();
    if (badges.contains(Badges.Badge.ALL_ITEMS_IDENTIFIED))
        blankBadges -= 6;
    if (badges.contains(Badges.Badge.YASD))
        blankBadges -= 5;
    blankBadges = Math.max(0, blankBadges);
    // guarantees a max of 5 rows in landscape, and 8 in portrait, assuming a max of 40 buttons
    int nCols = SPDSettings.landscape() ? 7 : 4;
    if (badges.size() + blankBadges > 32 && !SPDSettings.landscape())
        nCols++;
    int nRows = 1 + (blankBadges + badges.size()) / nCols;
    float badgeWidth = (w - 2 * left) / nCols;
    float badgeHeight = (h - 2 * top) / nRows;
    for (int i = 0; i < badges.size() + blankBadges; i++) {
        int row = i / nCols;
        int col = i % nCols;
        Badges.Badge b = i < badges.size() ? badges.get(i) : null;
        BadgeButton button = new BadgeButton(b);
        button.setPos(left + col * badgeWidth + (badgeWidth - button.width()) / 2, top + row * badgeHeight + (badgeHeight - button.height()) / 2);
        align(button);
        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) {
                ShatteredPixelDungeon.switchNoFade(BadgesScene.class);
            }
        }
    };
}
Also used : ExitButton(com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton) RenderedText(com.watabou.noosa.RenderedText) WndBadge(com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge) Callback(com.watabou.utils.Callback) Archs(com.shatteredpixel.shatteredpixeldungeon.ui.Archs) Badges(com.shatteredpixel.shatteredpixeldungeon.Badges)

Aggregations

Badges (com.shatteredpixel.shatteredpixeldungeon.Badges)1 Archs (com.shatteredpixel.shatteredpixeldungeon.ui.Archs)1 ExitButton (com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton)1 WndBadge (com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge)1 RenderedText (com.watabou.noosa.RenderedText)1 Callback (com.watabou.utils.Callback)1