Search in sources :

Example 1 with RedButton

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

the class WndItem method layoutButtons.

// this method assumes a max of 3 buttons per line
// FIXME: this is really messy for just trying to make buttons fill the window. Gotta be a cleaner way.
private static void layoutButtons(ArrayList<RedButton> line, float extraWidth, float y) {
    if (line == null || line.size() == 0 || extraWidth == 0)
        return;
    if (line.size() == 1) {
        line.get(0).setSize(line.get(0).width() + extraWidth, BUTTON_HEIGHT);
        line.get(0).setPos(0, y);
        return;
    }
    ArrayList<RedButton> lineByWidths = new ArrayList<>(line);
    Collections.sort(lineByWidths, widthComparator);
    RedButton smallest, middle, largest;
    smallest = lineByWidths.get(0);
    middle = lineByWidths.get(1);
    largest = null;
    if (lineByWidths.size() == 3) {
        largest = lineByWidths.get(2);
    }
    float btnDiff = middle.width() - smallest.width();
    smallest.setSize(smallest.width() + Math.min(btnDiff, extraWidth), BUTTON_HEIGHT);
    extraWidth -= btnDiff;
    if (extraWidth > 0) {
        if (largest == null) {
            smallest.setSize(smallest.width() + extraWidth / 2, BUTTON_HEIGHT);
            middle.setSize(middle.width() + extraWidth / 2, BUTTON_HEIGHT);
        } else {
            btnDiff = largest.width() - smallest.width();
            smallest.setSize(smallest.width() + Math.min(btnDiff, extraWidth / 2), BUTTON_HEIGHT);
            middle.setSize(middle.width() + Math.min(btnDiff, extraWidth / 2), BUTTON_HEIGHT);
            extraWidth -= btnDiff * 2;
            if (extraWidth > 0) {
                smallest.setSize(smallest.width() + extraWidth / 3, BUTTON_HEIGHT);
                middle.setSize(middle.width() + extraWidth / 3, BUTTON_HEIGHT);
                largest.setSize(largest.width() + extraWidth / 3, BUTTON_HEIGHT);
            }
        }
    }
    float x = 0;
    for (RedButton btn : line) {
        btn.setPos(x, y);
        x += btn.width() + 1;
    }
}
Also used : ArrayList(java.util.ArrayList) RedButton(com.shatteredpixel.shatteredpixeldungeon.ui.RedButton)

Example 2 with RedButton

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

the class AmuletScene method create.

@Override
public void create() {
    super.create();
    RenderedTextMultiline text = null;
    if (!noText) {
        text = renderMultiline(Messages.get(this, "text"), 8);
        text.maxWidth(WIDTH);
        add(text);
    }
    amulet = new Image(Assets.AMULET);
    add(amulet);
    RedButton btnExit = new RedButton(Messages.get(this, "exit")) {

        @Override
        protected void onClick() {
            Dungeon.win(Amulet.class);
            Dungeon.deleteGame(GamesInProgress.curSlot, true);
            Game.switchScene(RankingsScene.class);
        }
    };
    btnExit.setSize(WIDTH, BTN_HEIGHT);
    add(btnExit);
    RedButton btnStay = new RedButton(Messages.get(this, "stay")) {

        @Override
        protected void onClick() {
            onBackPressed();
        }
    };
    btnStay.setSize(WIDTH, BTN_HEIGHT);
    add(btnStay);
    float height;
    if (noText) {
        height = amulet.height + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
        amulet.x = (Camera.main.width - amulet.width) / 2;
        amulet.y = (Camera.main.height - height) / 2;
        align(amulet);
        btnExit.setPos((Camera.main.width - btnExit.width()) / 2, amulet.y + amulet.height + LARGE_GAP);
        btnStay.setPos(btnExit.left(), btnExit.bottom() + SMALL_GAP);
    } else {
        height = amulet.height + LARGE_GAP + text.height() + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
        amulet.x = (Camera.main.width - amulet.width) / 2;
        amulet.y = (Camera.main.height - height) / 2;
        align(amulet);
        text.setPos((Camera.main.width - text.width()) / 2, amulet.y + amulet.height + LARGE_GAP);
        align(text);
        btnExit.setPos((Camera.main.width - btnExit.width()) / 2, text.top() + text.height() + LARGE_GAP);
        btnStay.setPos(btnExit.left(), btnExit.bottom() + SMALL_GAP);
    }
    new Flare(8, 48).color(0xFFDDBB, true).show(amulet, 0).angularSpeed = +30;
    fadeIn();
}
Also used : Flare(com.shatteredpixel.shatteredpixeldungeon.effects.Flare) RenderedTextMultiline(com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline) RedButton(com.shatteredpixel.shatteredpixeldungeon.ui.RedButton) Image(com.watabou.noosa.Image)

Example 3 with RedButton

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

the class SurfaceScene method create.

@Override
public void create() {
    super.create();
    Music.INSTANCE.play(Assets.HAPPY, true);
    uiCamera.visible = false;
    int w = Camera.main.width;
    int h = Camera.main.height;
    Archs archs = new Archs();
    archs.reversed = true;
    archs.setSize(w, h);
    add(archs);
    float vx = align((w - SKY_WIDTH) / 2f);
    float vy = align((h - SKY_HEIGHT - BUTTON_HEIGHT) / 2f);
    Point s = Camera.main.cameraToScreen(vx, vy);
    viewport = new Camera(s.x, s.y, SKY_WIDTH, SKY_HEIGHT, defaultZoom);
    Camera.add(viewport);
    Group window = new Group();
    window.camera = viewport;
    add(window);
    boolean dayTime = Calendar.getInstance().get(Calendar.HOUR_OF_DAY) >= 7;
    Sky sky = new Sky(dayTime);
    sky.scale.set(SKY_WIDTH, SKY_HEIGHT);
    window.add(sky);
    if (!dayTime) {
        for (int i = 0; i < NSTARS; i++) {
            float size = Random.Float();
            ColorBlock star = new ColorBlock(size, size, 0xFFFFFFFF);
            star.x = Random.Float(SKY_WIDTH) - size / 2;
            star.y = Random.Float(SKY_HEIGHT) - size / 2;
            star.am = size * (1 - star.y / SKY_HEIGHT);
            window.add(star);
        }
    }
    float range = SKY_HEIGHT * 2 / 3;
    for (int i = 0; i < NCLOUDS; i++) {
        Cloud cloud = new Cloud((NCLOUDS - 1 - i) * (range / NCLOUDS) + Random.Float(range / NCLOUDS), dayTime);
        window.add(cloud);
    }
    int nPatches = (int) (sky.width() / GrassPatch.WIDTH + 1);
    for (int i = 0; i < nPatches * 4; i++) {
        GrassPatch patch = new GrassPatch((i - 0.75f) * GrassPatch.WIDTH / 4, SKY_HEIGHT + 1, dayTime);
        patch.brightness(dayTime ? 0.7f : 0.4f);
        window.add(patch);
    }
    Avatar a = new Avatar(Dungeon.hero.heroClass);
    // Removing semitransparent contour
    a.am = 2;
    a.aa = -1;
    a.x = (SKY_WIDTH - a.width) / 2;
    a.y = SKY_HEIGHT - a.height;
    align(a);
    window.add(a);
    final Pet pet = new Pet();
    pet.rm = pet.gm = pet.bm = 1.2f;
    pet.x = SKY_WIDTH / 2 + 2;
    pet.y = SKY_HEIGHT - pet.height;
    align(pet);
    window.add(pet);
    window.add(new TouchArea(sky) {

        protected void onClick(NoosaInputProcessor.Touch touch) {
            pet.jump();
        }
    });
    for (int i = 0; i < nPatches; i++) {
        GrassPatch patch = new GrassPatch((i - 0.5f) * GrassPatch.WIDTH, SKY_HEIGHT, dayTime);
        patch.brightness(dayTime ? 1.0f : 0.8f);
        window.add(patch);
    }
    Image frame = new Image(Assets.SURFACE);
    frame.frame(0, 0, FRAME_WIDTH, FRAME_HEIGHT);
    frame.x = vx - FRAME_MARGIN_X;
    frame.y = vy - FRAME_MARGIN_TOP;
    add(frame);
    if (dayTime) {
        a.brightness(1.2f);
        pet.brightness(1.2f);
    } else {
        frame.hardlight(0xDDEEFF);
    }
    RedButton gameOver = new RedButton(Messages.get(this, "exit")) {

        protected void onClick() {
            Game.switchScene(RankingsScene.class);
        }
    };
    gameOver.setSize(SKY_WIDTH - FRAME_MARGIN_X * 2, BUTTON_HEIGHT);
    gameOver.setPos(frame.x + FRAME_MARGIN_X * 2, frame.y + frame.height + 4);
    add(gameOver);
    Badges.validateHappyEnd();
    fadeIn();
}
Also used : Group(com.watabou.noosa.Group) Point(com.watabou.utils.Point) Image(com.watabou.noosa.Image) Point(com.watabou.utils.Point) Archs(com.shatteredpixel.shatteredpixeldungeon.ui.Archs) TouchArea(com.watabou.noosa.TouchArea) NoosaInputProcessor(com.watabou.input.NoosaInputProcessor) Camera(com.watabou.noosa.Camera) RedButton(com.shatteredpixel.shatteredpixeldungeon.ui.RedButton) ColorBlock(com.watabou.noosa.ColorBlock)

Aggregations

RedButton (com.shatteredpixel.shatteredpixeldungeon.ui.RedButton)3 Image (com.watabou.noosa.Image)2 Flare (com.shatteredpixel.shatteredpixeldungeon.effects.Flare)1 Archs (com.shatteredpixel.shatteredpixeldungeon.ui.Archs)1 RenderedTextMultiline (com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextMultiline)1 NoosaInputProcessor (com.watabou.input.NoosaInputProcessor)1 Camera (com.watabou.noosa.Camera)1 ColorBlock (com.watabou.noosa.ColorBlock)1 Group (com.watabou.noosa.Group)1 TouchArea (com.watabou.noosa.TouchArea)1 Point (com.watabou.utils.Point)1 ArrayList (java.util.ArrayList)1