Merging 1.9.1 source: scene changes
This commit is contained in:
@@ -20,28 +20,30 @@
|
||||
*/
|
||||
package com.shatteredpixel.shatteredpixeldungeon.scenes;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge;
|
||||
import com.watabou.noosa.BitmapText;
|
||||
import com.watabou.noosa.Camera;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.NinePatch;
|
||||
import com.watabou.noosa.Image;
|
||||
import com.watabou.noosa.audio.Music;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Badges;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.BadgesList;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.ScrollPane;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
||||
import com.watabou.noosa.audio.Sample;
|
||||
import com.watabou.noosa.ui.Button;
|
||||
import com.watabou.utils.Callback;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BadgesScene extends PixelScene {
|
||||
|
||||
private static final String TXT_TITLE = "Your Badges";
|
||||
|
||||
private static final int MAX_PANE_WIDTH = 160;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
|
||||
@@ -59,32 +61,38 @@ public class BadgesScene extends PixelScene {
|
||||
archs.setSize( w, h );
|
||||
add( archs );
|
||||
|
||||
int pw = Math.min( MAX_PANE_WIDTH, w - 6 );
|
||||
int ph = h - 30;
|
||||
float pw = Math.min( w, (ShatteredPixelDungeon.landscape() ? MIN_WIDTH_L : MIN_WIDTH_P) * 3 ) - 16;
|
||||
float ph = Math.min( h, (ShatteredPixelDungeon.landscape() ? MIN_HEIGHT_L : MIN_HEIGHT_P) * 3 ) - 32;
|
||||
|
||||
NinePatch panel = Chrome.get( Chrome.Type.WINDOW );
|
||||
panel.size( pw, ph );
|
||||
panel.x = (w - pw) / 2;
|
||||
panel.y = (h - ph) / 2;
|
||||
add( panel );
|
||||
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.hardlight(Window.TITLE_COLOR);
|
||||
title.measure();
|
||||
title.x = (w - title.width()) / 2;
|
||||
title.y = (panel.y - title.baseLine()) / 2;
|
||||
add( title );
|
||||
title.x = (w - title.width()) / 2 ;
|
||||
title.y = (top - title.baseLine()) / 2 ;
|
||||
add(title);
|
||||
|
||||
Badges.loadGlobal();
|
||||
|
||||
ScrollPane list = new BadgesList( true );
|
||||
add( list );
|
||||
|
||||
list.setRect(
|
||||
panel.x + panel.marginLeft(),
|
||||
panel.y + panel.marginTop(),
|
||||
panel.innerWidth(),
|
||||
panel.innerHeight() );
|
||||
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 );
|
||||
@@ -115,4 +123,46 @@ public class BadgesScene extends PixelScene {
|
||||
protected void onBackPressed() {
|
||||
ShatteredPixelDungeon.switchNoFade( TitleScene.class );
|
||||
}
|
||||
|
||||
private static class BadgeButton extends Button {
|
||||
|
||||
private Badges.Badge badge;
|
||||
|
||||
private Image icon;
|
||||
|
||||
public BadgeButton( Badges.Badge badge ) {
|
||||
super();
|
||||
|
||||
this.badge = badge;
|
||||
active = (badge != null);
|
||||
|
||||
icon = active ? BadgeBanner.image(badge.image) : new Image( Assets.LOCKED );
|
||||
add(icon);
|
||||
|
||||
setSize( icon.width(), icon.height() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void layout() {
|
||||
super.layout();
|
||||
|
||||
icon.x = x + (width - icon.width()) / 2;
|
||||
icon.y = y + (height - icon.height()) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
|
||||
if (Random.Float() < Game.elapsed * 0.1) {
|
||||
BadgeBanner.highlight( icon, badge.image );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
|
||||
Game.scene().add( new WndBadge( badge ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user