2014-07-27 13:39:07 +00:00
|
|
|
/*
|
|
|
|
* Pixel Dungeon
|
2015-06-12 20:44:04 +00:00
|
|
|
* Copyright (C) 2012-2015 Oleg Dolya
|
|
|
|
*
|
|
|
|
* Shattered Pixel Dungeon
|
|
|
|
* Copyright (C) 2014-2015 Evan Debenham
|
2014-07-27 13:39:07 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
2014-08-03 18:46:22 +00:00
|
|
|
package com.shatteredpixel.shatteredpixeldungeon.scenes;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
2016-02-12 18:46:42 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Badges;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
|
2015-11-10 05:48:02 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
|
2015-12-31 07:23:01 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
2016-02-12 18:46:42 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
|
2015-11-10 05:48:02 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge;
|
2014-07-27 13:39:07 +00:00
|
|
|
import com.watabou.noosa.Camera;
|
2015-02-05 06:25:24 +00:00
|
|
|
import com.watabou.noosa.Game;
|
2015-11-10 05:48:02 +00:00
|
|
|
import com.watabou.noosa.Image;
|
2016-01-13 05:53:17 +00:00
|
|
|
import com.watabou.noosa.RenderedText;
|
2014-07-27 13:39:07 +00:00
|
|
|
import com.watabou.noosa.audio.Music;
|
2015-11-10 05:48:02 +00:00
|
|
|
import com.watabou.noosa.audio.Sample;
|
|
|
|
import com.watabou.noosa.ui.Button;
|
2015-02-05 06:25:24 +00:00
|
|
|
import com.watabou.utils.Callback;
|
2015-11-10 05:48:02 +00:00
|
|
|
import com.watabou.utils.Random;
|
|
|
|
|
|
|
|
import java.util.List;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
public class BadgesScene extends PixelScene {
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
@Override
|
|
|
|
public void create() {
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
super.create();
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
Music.INSTANCE.play( Assets.THEME, true );
|
2015-08-20 13:34:20 +00:00
|
|
|
Music.INSTANCE.volume( ShatteredPixelDungeon.musicVol() / 10f );
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
uiCamera.visible = false;
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
int w = Camera.main.width;
|
|
|
|
int h = Camera.main.height;
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
Archs archs = new Archs();
|
|
|
|
archs.setSize( w, h );
|
|
|
|
add( archs );
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2015-11-10 05:48:02 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
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 );
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2015-11-10 05:48:02 +00:00
|
|
|
float left = (w - size * nCols) / 2;
|
|
|
|
float top = (h - size * nRows) / 2;
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2016-01-13 05:53:17 +00:00
|
|
|
RenderedText title = PixelScene.renderText( Messages.get(this, "title"), 9 );
|
2015-11-10 05:48:02 +00:00
|
|
|
title.hardlight(Window.TITLE_COLOR);
|
|
|
|
title.x = (w - title.width()) / 2 ;
|
|
|
|
title.y = (top - title.baseLine()) / 2 ;
|
2016-02-12 18:46:42 +00:00
|
|
|
align(title);
|
2015-11-10 05:48:02 +00:00
|
|
|
add(title);
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
Badges.loadGlobal();
|
2015-02-05 06:25:24 +00:00
|
|
|
|
2015-11-10 05:48:02 +00:00
|
|
|
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);
|
2016-02-12 18:46:42 +00:00
|
|
|
align(button);
|
2015-11-10 05:48:02 +00:00
|
|
|
add( button );
|
|
|
|
}
|
|
|
|
}
|
2015-02-05 06:25:24 +00:00
|
|
|
|
|
|
|
ExitButton btnExit = new ExitButton();
|
|
|
|
btnExit.setPos( Camera.main.width - btnExit.width(), 0 );
|
|
|
|
add( btnExit );
|
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
fadeIn();
|
2015-02-05 06:25:24 +00:00
|
|
|
|
|
|
|
Badges.loadingListener = new Callback() {
|
|
|
|
@Override
|
|
|
|
public void call() {
|
|
|
|
if (Game.scene() == BadgesScene.this) {
|
|
|
|
ShatteredPixelDungeon.switchNoFade( BadgesScene.class );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
2015-02-05 06:25:24 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void destroy() {
|
|
|
|
|
|
|
|
Badges.saveGlobal();
|
|
|
|
Badges.loadingListener = null;
|
|
|
|
|
|
|
|
super.destroy();
|
|
|
|
}
|
|
|
|
|
2014-07-27 13:39:07 +00:00
|
|
|
@Override
|
|
|
|
protected void onBackPressed() {
|
2015-02-05 06:25:24 +00:00
|
|
|
ShatteredPixelDungeon.switchNoFade( TitleScene.class );
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|
2015-11-10 05:48:02 +00:00
|
|
|
|
|
|
|
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 ) );
|
|
|
|
}
|
|
|
|
}
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|