/* * Pixel Dungeon * Copyright (C) 2012-2014 Oleg Dolya * * 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 */ package com.shatteredpixel.shatteredpixeldungeon.scenes; import com.watabou.noosa.BitmapText; import com.watabou.noosa.Camera; import com.watabou.noosa.Game; import com.watabou.noosa.Image; import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Sample; import com.watabou.noosa.ui.Button; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites; import com.shatteredpixel.shatteredpixeldungeon.effects.Fireball; import com.shatteredpixel.shatteredpixeldungeon.ui.Archs; import com.shatteredpixel.shatteredpixeldungeon.ui.PrefsButton; public class TitleScene extends PixelScene { private static final String TXT_PLAY = "Play"; private static final String TXT_HIGHSCORES = "Rankings"; private static final String TXT_BADGES = "Badges"; private static final String TXT_ABOUT = "About"; @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; float height = 180; Archs archs = new Archs(); archs.setSize( w, h ); add( archs ); Image title = BannerSprites.get( BannerSprites.Type.PIXEL_DUNGEON ); add( title ); title.x = (w - title.width()) / 2; title.y = (h - height) / 2; placeTorch( title.x + 18, title.y + 20 ); placeTorch( title.x + title.width - 18, title.y + 20 ); DashboardItem btnBadges = new DashboardItem( TXT_BADGES, 3 ) { @Override protected void onClick() { Game.switchScene( BadgesScene.class ); } }; btnBadges.setPos( w / 2 - btnBadges.width(), (h + height) / 2 - DashboardItem.SIZE ); add( btnBadges ); DashboardItem btnAbout = new DashboardItem( TXT_ABOUT, 1 ) { @Override protected void onClick() { Game.switchScene( AboutScene.class ); } }; btnAbout.setPos( w / 2, (h + height) / 2 - DashboardItem.SIZE ); add( btnAbout ); DashboardItem btnPlay = new DashboardItem( TXT_PLAY, 0 ) { @Override protected void onClick() { Game.switchScene( StartScene.class ); } }; btnPlay.setPos( w / 2 - btnPlay.width(), btnAbout.top() - DashboardItem.SIZE ); add( btnPlay ); DashboardItem btnHighscores = new DashboardItem( TXT_HIGHSCORES, 2 ) { @Override protected void onClick() { Game.switchScene( RankingsScene.class ); } }; btnHighscores.setPos( w / 2, btnPlay.top() ); add( btnHighscores ); BitmapText source = new BitmapText( "PD source v 1.7.1c", font1x ); source.measure(); source.hardlight( 0x444444 ); source.x = w - source.width(); source.y = h - source.height(); add( source ); BitmapText version = new BitmapText( "v " + Game.version + " ", font1x ); version.measure(); version.hardlight( 0xCCCCCC ); version.x = w - version.width(); version.y = h - version.height() - source.height(); add( version ); PrefsButton btnPrefs = new PrefsButton(); btnPrefs.setPos( w - btnPrefs.width() - 1, 1 ); add( btnPrefs ); fadeIn(); } private void placeTorch( float x, float y ) { Fireball fb = new Fireball(); fb.setPos( x, y ); add( fb ); } private static class DashboardItem extends Button { public static final float SIZE = 48; private static final int IMAGE_SIZE = 32; private Image image; private BitmapText label; public DashboardItem( String text, int index ) { super(); image.frame( image.texture.uvRect( index * IMAGE_SIZE, 0, (index + 1) * IMAGE_SIZE, IMAGE_SIZE ) ); this.label.text( text ); this.label.measure(); setSize( SIZE, SIZE ); } @Override protected void createChildren() { super.createChildren(); image = new Image( Assets.DASHBOARD ); add( image ); label = createText( 9 ); add( label ); } @Override protected void layout() { super.layout(); image.x = align( x + (width - image.width()) / 2 ); image.y = align( y ); label.x = align( x + (width - label.width()) / 2 ); label.y = align( image.y + image.height() +2 ); } @Override protected void onTouchDown() { image.brightness( 1.5f ); Sample.INSTANCE.play( Assets.SND_CLICK, 1, 1, 0.8f ); } @Override protected void onTouchUp() { image.resetColor(); } } }