diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java index 093278530..444d40109 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java @@ -20,6 +20,8 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import android.content.Intent; import android.net.Uri; +import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; +import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton; import com.watabou.input.Touchscreen.Touch; import com.watabou.noosa.BitmapTextMultiline; import com.watabou.noosa.Camera; @@ -143,12 +145,16 @@ public class AboutScene extends PixelScene { Archs archs = new Archs(); archs.setSize( Camera.main.width, Camera.main.height ); addToBack( archs ); - + + ExitButton btnExit = new ExitButton(); + btnExit.setPos( Camera.main.width - btnExit.width(), 0 ); + add( btnExit ); + fadeIn(); } @Override protected void onBackPressed() { - Game.switchScene( TitleScene.class ); + ShatteredPixelDungeon.switchNoFade(TitleScene.class); } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/AmuletScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/AmuletScene.java index 9b199588a..a3ab9ab30 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/AmuletScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/AmuletScene.java @@ -23,6 +23,7 @@ import com.watabou.noosa.Game; import com.watabou.noosa.Image; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.ResultDescriptions; import com.shatteredpixel.shatteredpixeldungeon.effects.Flare; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; @@ -66,6 +67,7 @@ public class AmuletScene extends PixelScene { RedButton btnExit = new RedButton( TXT_EXIT ) { @Override protected void onClick() { + Dungeon.win( ResultDescriptions.WIN ); Dungeon.deleteGame( Dungeon.hero.heroClass, true ); Game.switchScene( noText ? TitleScene.class : RankingsScene.class ); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/BadgesScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/BadgesScene.java index e3006d72a..0108f516e 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/BadgesScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/BadgesScene.java @@ -19,14 +19,15 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import com.watabou.noosa.BitmapText; import com.watabou.noosa.Camera; -import com.watabou.noosa.Game; import com.watabou.noosa.NinePatch; 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; @@ -51,8 +52,8 @@ public class BadgesScene extends PixelScene { archs.setSize( w, h ); add( archs ); - int pw = Math.min( 160, w - 10 ); - int ph = h - 24; + int pw = Math.min( 160, w - 6 ); + int ph = h - 30; NinePatch panel = Chrome.get( Chrome.Type.WINDOW ); panel.size( pw, ph ); @@ -77,12 +78,16 @@ public class BadgesScene extends PixelScene { panel.y + panel.marginTop(), panel.innerWidth(), panel.innerHeight() ); + + ExitButton btnExit = new ExitButton(); + btnExit.setPos( Camera.main.width - btnExit.width(), 0 ); + add( btnExit ); fadeIn(); } @Override protected void onBackPressed() { - Game.switchScene( TitleScene.class ); + ShatteredPixelDungeon.switchNoFade(TitleScene.class); } } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index ed5a660f3..c40b30b70 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -600,9 +600,10 @@ public class GameScene extends PixelScene { private static final CellSelector.Listener defaultCellListener = new CellSelector.Listener() { @Override public void onSelect( Integer cell ) { - if (cell != -1) { - Dungeon.hero.handle( cell ); - } + if (Dungeon.hero.handle( cell )) { + // Actor.next(); + Dungeon.hero.next(); + } } @Override public String prompt() { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java index 97bfb265e..e51002abb 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/InterlevelScene.java @@ -238,6 +238,7 @@ public class InterlevelScene extends PixelScene { Game.switchScene( StartScene.class ); }; } ); + error = null; } break; } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java index 04e02237c..be2cc5dbf 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java @@ -238,10 +238,15 @@ public class PixelScene extends Scene { v.x = align( c, v.x ); v.y = align( c, v.y ); } - - protected void fadeIn() { - fadeIn( 0xFF000000, false ); - } + + public static boolean noFade = false; + protected void fadeIn() { + if (noFade) { + noFade = false; + } else { + fadeIn( 0xFF000000, false ); + } + } protected void fadeIn( int color, boolean light ) { add( new Fader( color, light ) ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/RankingsScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/RankingsScene.java index 1991b4441..d4ea1be1b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/RankingsScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/RankingsScene.java @@ -20,16 +20,17 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import com.watabou.noosa.BitmapText; import com.watabou.noosa.BitmapTextMultiline; 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.ui.Button; import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.Rankings; import com.shatteredpixel.shatteredpixeldungeon.effects.Flare; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet; import com.shatteredpixel.shatteredpixeldungeon.ui.Archs; +import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton; import com.shatteredpixel.shatteredpixeldungeon.ui.Icons; import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; @@ -109,13 +110,17 @@ public class RankingsScene extends PixelScene { add( title ); } + + ExitButton btnExit = new ExitButton(); + btnExit.setPos( Camera.main.width - btnExit.width(), 0 ); + add( btnExit ); fadeIn(); } @Override protected void onBackPressed() { - Game.switchScene( TitleScene.class ); + ShatteredPixelDungeon.switchNoFade(TitleScene.class); } public static class Record extends Button { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/StartScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/StartScene.java index 1471427d4..0c50548db 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/StartScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/StartScene.java @@ -19,488 +19,435 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import java.util.HashMap; -import com.shatteredpixel.shatteredpixeldungeon.*; -import com.watabou.input.Touchscreen; import com.watabou.noosa.BitmapText; import com.watabou.noosa.BitmapTextMultiline; import com.watabou.noosa.Camera; import com.watabou.noosa.Game; import com.watabou.noosa.Group; import com.watabou.noosa.Image; -import com.watabou.noosa.NinePatch; -import com.watabou.noosa.TextureFilm; -import com.watabou.noosa.TouchArea; import com.watabou.noosa.audio.Sample; import com.watabou.noosa.particles.Emitter; import com.watabou.noosa.ui.Button; +import com.shatteredpixel.shatteredpixeldungeon.Assets; +import com.shatteredpixel.shatteredpixeldungeon.Badges; +import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.GamesInProgress; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass; -import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass; +import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites; import com.shatteredpixel.shatteredpixeldungeon.effects.Speck; +import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites.Type; import com.shatteredpixel.shatteredpixeldungeon.ui.Archs; +import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton; import com.shatteredpixel.shatteredpixeldungeon.ui.Icons; import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton; -import com.shatteredpixel.shatteredpixeldungeon.ui.SimpleButton; -import com.shatteredpixel.shatteredpixeldungeon.ui.Window; import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; -import com.shatteredpixel.shatteredpixeldungeon.windows.WndList; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndChallenges; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndClass; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage; import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; -import com.shatteredpixel.shatteredpixeldungeon.windows.WndTitledMessage; public class StartScene extends PixelScene { - private static final float BUTTON_HEIGHT = 24; - private static final float GAP = 2; - - private static final String TXT_TITLE = "Select Your Hero"; - - private static final String TXT_LOAD = "Load Game"; - private static final String TXT_NEW = "New Game"; - - private static final String TXT_ERASE = "Erase current game"; - private static final String TXT_DPTH_LVL = "Depth: %d, level: %d"; - - private static final String TXT_REALLY = "Do you really want to start new game?"; - private static final String TXT_WARNING = "Your current game progress will be erased."; - private static final String TXT_YES = "Yes, start new game"; - private static final String TXT_NO = "No, return to main menu"; - - private static final String TXT_UNLOCK = "To unlock this character class, slay the 3rd boss with any other class"; - - private float width; - private float height; - private float top; - private float left; - - private static HashMap gems = new HashMap(); - - private Avatar avatar; - private NinePatch frame; - private BitmapText className; - - private SimpleButton btnMastery; - - private GameButton btnLoad; - private GameButton btnNewGame; - - private boolean huntressUnlocked; - private Group unlock; - - public static HeroClass curClass; - - @Override - public void create() { - - super.create(); - - Badges.loadGlobal(); - - uiCamera.visible = false; - - int w = Camera.main.width; - int h = Camera.main.height; - - width = 128; - height = 220; - left = (w - width) / 2; - top = (h - height) / 2; - - Archs archs = new Archs(); - archs.setSize( w, h ); - add( archs ); - - BitmapText title = PixelScene.createText( TXT_TITLE, 9 ); - title.hardlight( Window.TITLE_COLOR ); - title.measure(); - title.x = align( (w - title.width()) / 2 ); - title.y = align( top ); - add( title ); - - float pos = title.y + title.height() + GAP; - - GemButton btns[] = { - new GemButton( HeroClass.WARRIOR ), - new GemButton( HeroClass.MAGE ), - new GemButton( HeroClass.ROGUE ), - new GemButton( HeroClass.HUNTRESS ) }; - - float space = width; - for (GemButton btn : btns) { - space -= btn.width(); - } - - float p = 0; - for (GemButton btn : btns) { - add( btn ); - btn.setPos( align( left + p ), align( pos ) ); - p += btn.width() + space / 3; - } - - - frame = Chrome.get( Chrome.Type.TOAST_TR ); - add( frame ); - - btnNewGame = new GameButton( TXT_NEW ) { - @Override - protected void onClick() { - if (GamesInProgress.check( curClass ) != null) { - StartScene.this.add( new WndOptions( TXT_REALLY, TXT_WARNING, TXT_YES, TXT_NO ) { - @Override - protected void onSelect( int index ) { - if (index == 0) { - startNewGame(); - } - } - } ); - - } else { - startNewGame(); - } - } - }; - add( btnNewGame ); + private static final float BUTTON_HEIGHT = 24; + private static final float GAP = 2; - btnLoad = new GameButton( TXT_LOAD ) { - @Override - protected void onClick() { - InterlevelScene.mode = InterlevelScene.Mode.CONTINUE; - Game.switchScene( InterlevelScene.class ); - } - }; - add( btnLoad ); - - frame.size( width, BUTTON_HEIGHT + frame.marginVer() ); - frame.x = align( left ); - frame.y = align( h - top - frame.height() ); - - avatar = new Avatar(); - - NinePatch avFrame = Chrome.get( Chrome.Type.TOAST_TR ); - avFrame.size( avatar.width() * 1.6f, avatar.height() * 1.6f ); - avFrame.x = align( (w - avFrame.width()) / 2 ); - avFrame.y = align( (frame.y + btns[0].bottom() - avFrame.height()) / 2 ); - add( avFrame ); - - className = PixelScene.createText( "Placeholder", 9 ); - className.measure(); - className.y = align( avFrame.y + avFrame.innerBottom() - className.height() ); - add( className ); - - avatar.point( avFrame.center() ); - avatar.camera = Camera.main; - align( avatar ); - add( avatar ); - - Image iconInfo = Icons.INFO.get(); - iconInfo.x = avFrame.x + avFrame.innerRight() - iconInfo.width(); - iconInfo.y = avFrame.y + avFrame.marginTop(); - add( iconInfo ); - - add( new TouchArea( avFrame ) { - @Override - protected void onClick( Touchscreen.Touch touch ) { - add( new WndList( curClass.perks() ) ); - } - } ); - - btnMastery = new SimpleButton( Icons.MASTERY.get() ) { - @Override - protected void onClick() { - String text = null; - switch (curClass) { - case WARRIOR: - text = HeroSubClass.GLADIATOR.desc() + "\n\n" + HeroSubClass.BERSERKER.desc(); - break; - case MAGE: - text = HeroSubClass.BATTLEMAGE.desc() + "\n\n" + HeroSubClass.WARLOCK.desc(); - break; - case ROGUE: - text = HeroSubClass.FREERUNNER.desc() + "\n\n" + HeroSubClass.ASSASSIN.desc(); - break; - case HUNTRESS: - text = HeroSubClass.SNIPER.desc() + "\n\n" + HeroSubClass.WARDEN.desc(); - break; - } - StartScene.this.add( new WndTitledMessage( Icons.MASTERY.get(), "Mastery", text ) ); - } - }; - btnMastery.setPos( - avFrame.x + avFrame.innerRight() - btnMastery.width(), - avFrame.y + avFrame.innerBottom() - btnMastery.height() ); - add( btnMastery ); - - unlock = new Group(); - add( unlock ); - - if (!(huntressUnlocked = Badges.isUnlocked( Badges.Badge.BOSS_SLAIN_3 ))) { - - BitmapTextMultiline text = PixelScene.createMultiline( TXT_UNLOCK, 5 ); - text.maxWidth = (int)frame.innerWidth(); - text.measure(); - - pos = frame.center().y - text.height() / 2; - for (BitmapText line : text.new LineSplitter().split()) { - line.measure(); - line.hardlight( 0xFFFF00 ); - line.x = PixelScene.align( frame.center().x - line.width() / 2 ); - line.y = PixelScene.align( pos ); - unlock.add( line ); - - pos += line.height(); - } - } - - curClass = null; - updateClass( HeroClass.values()[ShatteredPixelDungeon.lastClass()] ); - - fadeIn(); - } - - private void updateClass( HeroClass cl ) { - - if (curClass == cl) { - return; - } - - if (curClass != null) { - gems.get( curClass ).highlight( false ); - } - - gems.get( curClass = cl ).highlight( true ); - - className.text( Utils.capitalize( cl.title() ) ); - className.measure(); - className.x = align( frame.center().x - className.width() / 2 ); - - if (cl != HeroClass.HUNTRESS || huntressUnlocked) { - - unlock.visible = false; - - float buttonPos = frame.y + frame.innerBottom() - BUTTON_HEIGHT; - - GamesInProgress.Info info = GamesInProgress.check( curClass ); - if (info != null) { - - btnLoad.visible = true; - btnLoad.secondary( Utils.format( TXT_DPTH_LVL, info.depth, info.level ) ); - btnNewGame.visible = true; - btnNewGame.secondary( TXT_ERASE ); - - float w = (frame.innerWidth() - GAP) / 2; - - btnLoad.setRect( - frame.x + frame.marginLeft(), buttonPos, w, BUTTON_HEIGHT ); - btnNewGame.setRect( - btnLoad.right() + GAP, buttonPos, w, BUTTON_HEIGHT ); - - } else { - btnLoad.visible = false; - - btnNewGame.visible = true; - btnNewGame.secondary( null ); - btnNewGame.setRect( - frame.x + frame.marginLeft(), buttonPos, frame.innerWidth(), BUTTON_HEIGHT ); - } - - Badges.Badge badgeToCheck = null; - switch (curClass) { - case WARRIOR: - badgeToCheck = Badges.Badge.MASTERY_WARRIOR; - break; - case MAGE: - badgeToCheck = Badges.Badge.MASTERY_MAGE; - break; - case ROGUE: - badgeToCheck = Badges.Badge.MASTERY_ROGUE; - break; - case HUNTRESS: - badgeToCheck = Badges.Badge.MASTERY_HUNTRESS; - break; - } - btnMastery.active = - btnMastery.visible = - Badges.isUnlocked( badgeToCheck ); - - } else { - - unlock.visible = true; - btnLoad.visible = false; - btnNewGame.visible = false; - btnMastery.active = btnMastery.visible = false; - - } - - avatar.selectClass( curClass ); - } - - private void startNewGame() { + private static final String TXT_LOAD = "Load Game"; + private static final String TXT_NEW = "New Game"; - Dungeon.hero = null; - InterlevelScene.mode = InterlevelScene.Mode.DESCEND; - - if (ShatteredPixelDungeon.intro()) { - ShatteredPixelDungeon.intro(false); - Game.switchScene( IntroScene.class ); - } else { - Game.switchScene( InterlevelScene.class ); - } - } - - @Override - protected void onBackPressed() { - Game.switchScene( TitleScene.class ); - } - - private static class Avatar extends Image { - - private static final int WIDTH = 24; - private static final int HEIGHT = 32; - private static final int SCALE = 2; - - private TextureFilm frames; - - private float brightness = 0; - - public Avatar() { - super( Assets.AVATARS ); - - frames = new TextureFilm( texture, WIDTH, HEIGHT ); - selectClass( HeroClass.WARRIOR ); - scale.set( SCALE ); - - origin.set( width() / 2, height() / 2 ); - } - - public void selectClass( HeroClass cl ) { - frame( frames.get( cl.ordinal() ) ); - } - - public void flash() { - brightness = 1f; - } - - @Override - public void update() { - super.update(); - - if (brightness > 0) { - ra = ga = ba = brightness; - brightness -= Game.elapsed * 4; - if (brightness < 0) { - resetColor(); - } - } - } - } - - private class GemButton extends Button { - - private NinePatch bg; - private Image icon; - - private HeroClass cl; - - public GemButton( HeroClass cl ) { - super(); - - this.cl = cl; - gems.put( cl, this ); - - icon.copy( Icons.get( cl ) ); - setSize( 32, 32 ); - - highlight( false ); - } - - @Override - protected void createChildren() { - super.createChildren(); - - bg = Chrome.get( Chrome.Type.GEM ); - add( bg ); - - icon = new Image(); - add( icon ); - } - - @Override - protected void layout() { - super.layout(); - - bg.x = x; - bg.y = y; - bg.size( width, height ); - - icon.x = x + (width - icon.width) / 2; - icon.y = y + (height - icon.height) / 2; - } - - @Override - protected void onTouchDown() { - Emitter emitter = (Emitter)recycle( Emitter.class ); - emitter.revive(); - emitter.pos( bg ); - emitter.burst( Speck.factory( Speck.LIGHT ), 3 ); - - updateClass( cl ); - avatar.flash(); - - Sample.INSTANCE.play( Assets.SND_CLICK, 1, 1, 1.2f ); - } - - public void highlight( boolean value ) { - if (value) { - bg.rm = 1.2f; - bg.gm = 1.2f; - bg.bm = 1.1f; - bg.am = 0.8f; - } else { - bg.rm = 1.0f; - bg.gm = 1.0f; - bg.bm = 1.0f; - bg.am = 0.6f; - } - } - } - - private static class GameButton extends RedButton { - - private static final int SECONDARY_COLOR = 0xCACFC2; - - private BitmapText secondary; - - public GameButton( String primary ) { - super( primary ); - - this.secondary.text( null ); - } - - @Override - protected void createChildren() { - super.createChildren(); - - secondary = createText( 6 ); - secondary.hardlight( SECONDARY_COLOR ); - add( secondary ); - } - - @Override - protected void layout() { - super.layout(); - - if (secondary.text().length() > 0) { - text.y = y + (height - text.height() - secondary.baseLine()) / 2; - - secondary.x = align( x + (width - secondary.width()) / 2 ); - secondary.y = align( text.y + text.height() ); - } else { - text.y = y + (height - text.baseLine()) / 2; - } - } - - public void secondary( String text ) { - secondary.text( text ); - secondary.measure(); - } - } -} + private static final String TXT_ERASE = "Erase current game"; + private static final String TXT_DPTH_LVL = "Depth: %d, level: %d"; + + private static final String TXT_REALLY = "Do you really want to start new game?"; + private static final String TXT_WARNING = "Your current game progress will be erased."; + private static final String TXT_YES = "Yes, start new game"; + private static final String TXT_NO = "No, return to main menu"; + + private static final String TXT_UNLOCK = "To unlock this character class, slay the 3rd boss with any other class"; + + private static final String TXT_WIN_THE_GAME = + "To unlock \"Challenges\", win the game with any character class."; + + private static final float WIDTH = 116; + private static final float HEIGHT = 220; + + private static HashMap shields = new HashMap(); + + private GameButton btnLoad; + private GameButton btnNewGame; + + private boolean huntressUnlocked; + private Group unlock; + + public static HeroClass curClass; + + @Override + public void create() { + + super.create(); + + Badges.loadGlobal(); + + uiCamera.visible = false; + + int w = Camera.main.width; + int h = Camera.main.height; + + float left = (w - WIDTH) / 2; + float top = (h - HEIGHT) / 2; + float bottom = h - top; + + Archs archs = new Archs(); + archs.setSize( w, h ); + add( archs ); + + Image title = BannerSprites.get( Type.SELECT_YOUR_HERO ); + title.x = align( (w - title.width()) / 2 ); + title.y = top; + add( title ); + + btnNewGame = new GameButton( TXT_NEW ) { + @Override + protected void onClick() { + if (GamesInProgress.check( curClass ) != null) { + StartScene.this.add( new WndOptions( TXT_REALLY, TXT_WARNING, TXT_YES, TXT_NO ) { + @Override + protected void onSelect( int index ) { + if (index == 0) { + startNewGame(); + } + } + } ); + + } else { + startNewGame(); + } + } + }; + add( btnNewGame ); + + btnLoad = new GameButton( TXT_LOAD ) { + @Override + protected void onClick() { + InterlevelScene.mode = InterlevelScene.Mode.CONTINUE; + Game.switchScene( InterlevelScene.class ); + } + }; + add( btnLoad ); + + HeroClass[] classes = { + HeroClass.WARRIOR, HeroClass.MAGE, HeroClass.ROGUE, HeroClass.HUNTRESS + }; + float shieldW = WIDTH / 2; + float shieldH = Math.min( (bottom - BUTTON_HEIGHT - title.y - title.height()) / 2, shieldW * 1.2f ); + top = (bottom - BUTTON_HEIGHT + title.y + title.height() - shieldH * 2) / 2; + for (int i=0; i < classes.length; i++) { + ClassShield shield = new ClassShield( classes[i] ); + shield.setRect( + left + (i % 2) * shieldW, + top + (i / 2) * shieldH, + shieldW, shieldH ); + add( shield ); + + shields.put( classes[i], shield ); + } + + unlock = new Group(); + add( unlock ); + + ChallengeButton challenge = new ChallengeButton(); + challenge.setPos( + w / 2 - challenge.width() / 2, + top + shieldH - challenge.height() / 2 ); + add( challenge ); + + if (!(huntressUnlocked = Badges.isUnlocked( Badges.Badge.BOSS_SLAIN_3 ))) { + + BitmapTextMultiline text = PixelScene.createMultiline( TXT_UNLOCK, 9 ); + text.maxWidth = (int)WIDTH; + text.measure(); + + float pos = (bottom - BUTTON_HEIGHT) + (BUTTON_HEIGHT - text.height()) / 2; + for (BitmapText line : text.new LineSplitter().split()) { + line.measure(); + line.hardlight( 0xFFFF00 ); + line.x = PixelScene.align( left + WIDTH / 2 - line.width() / 2 ); + line.y = PixelScene.align( pos ); + unlock.add( line ); + + pos += line.height(); + } + } + + ExitButton btnExit = new ExitButton(); + btnExit.setPos( Camera.main.width - btnExit.width(), 0 ); + add( btnExit ); + + curClass = null; + updateClass( HeroClass.values()[ShatteredPixelDungeon.lastClass()] ); + + fadeIn(); + } + + private void updateClass( HeroClass cl ) { + + if (curClass == cl) { + add( new WndClass( cl ) ); + return; + } + + if (curClass != null) { + shields.get( curClass ).highlight( false ); + } + shields.get( curClass = cl ).highlight( true ); + + if (cl != HeroClass.HUNTRESS || huntressUnlocked) { + + unlock.visible = false; + + float buttonPos = (Camera.main.height + HEIGHT) / 2 - BUTTON_HEIGHT; + + float left = (Camera.main.width - WIDTH) / 2; + + GamesInProgress.Info info = GamesInProgress.check( curClass ); + if (info != null) { + + btnLoad.visible = true; + btnLoad.secondary( Utils.format( TXT_DPTH_LVL, info.depth, info.level ) ); + btnNewGame.visible = true; + btnNewGame.secondary( TXT_ERASE ); + + float w = (WIDTH - GAP) / 2; + + btnLoad.setRect( + left, buttonPos, w, BUTTON_HEIGHT ); + btnNewGame.setRect( + btnLoad.right() + GAP, buttonPos, w, BUTTON_HEIGHT ); + + } else { + btnLoad.visible = false; + + btnNewGame.visible = true; + btnNewGame.secondary( null ); + btnNewGame.setRect( left, buttonPos, WIDTH, BUTTON_HEIGHT ); + } + + } else { + + unlock.visible = true; + btnLoad.visible = false; + btnNewGame.visible = false; + + } + } + + private void startNewGame() { + + Dungeon.hero = null; + InterlevelScene.mode = InterlevelScene.Mode.DESCEND; + + if (ShatteredPixelDungeon.intro()) { + ShatteredPixelDungeon.intro( false ); + Game.switchScene( IntroScene.class ); + } else { + Game.switchScene( InterlevelScene.class ); + } + } + + @Override + protected void onBackPressed() { + ShatteredPixelDungeon.switchNoFade( TitleScene.class ); + } + + private static class GameButton extends RedButton { + + private static final int SECONDARY_COLOR = 0xCACFC2; + + private BitmapText secondary; + + public GameButton( String primary ) { + super( primary ); + + this.secondary.text( null ); + } + + @Override + protected void createChildren() { + super.createChildren(); + + secondary = createText( 6 ); + secondary.hardlight( SECONDARY_COLOR ); + add( secondary ); + } + + @Override + protected void layout() { + super.layout(); + + if (secondary.text().length() > 0) { + text.y = align( y + (height - text.height() - secondary.baseLine()) / 2 ); + + secondary.x = align( x + (width - secondary.width()) / 2 ); + secondary.y = align( text.y + text.height() ); + } else { + text.y = align( y + (height - text.baseLine()) / 2 ); + } + } + + public void secondary( String text ) { + secondary.text( text ); + secondary.measure(); + } + } + + private class ClassShield extends Button { + + private static final float MIN_BRIGHTNESS = 0.6f; + + private static final int WIDTH = 24; + private static final int HEIGHT = 32; + private static final float SCALE = 1.75f; + + private HeroClass cl; + + private Image avatar; + private BitmapText name; + private Emitter emitter; + + private float brightness; + + public ClassShield( HeroClass cl ) { + super(); + + this.cl = cl; + + avatar.frame( cl.ordinal() * WIDTH, 0, WIDTH, HEIGHT ); + avatar.scale.set( SCALE ); + + name.text( cl.name() ); + name.measure(); + + brightness = MIN_BRIGHTNESS; + updateBrightness(); + } + + @Override + protected void createChildren() { + + super.createChildren(); + + avatar = new Image( Assets.AVATARS ); + add( avatar ); + + name = PixelScene.createText( 9 ); + add( name ); + + emitter = new Emitter(); + add( emitter ); + } + + @Override + protected void layout() { + + super.layout(); + + avatar.x = align( x + (width - avatar.width()) / 2 ); + avatar.y = align( y + (height - avatar.height() - name.height()) / 2 ); + + name.x = align( x + (width - name.width()) / 2 ); + name.y = avatar.y + avatar.height() + SCALE; + + emitter.pos( avatar.x, avatar.y, avatar.width(), avatar.height() ); + } + + @Override + protected void onTouchDown() { + + emitter.revive(); + emitter.start( Speck.factory( Speck.LIGHT ), 0.05f, 7 ); + + Sample.INSTANCE.play( Assets.SND_CLICK, 1, 1, 1.2f ); + updateClass( cl ); + } + + @Override + public void update() { + super.update(); + + if (brightness < 1.0f && brightness > MIN_BRIGHTNESS) { + if ((brightness -= Game.elapsed) <= MIN_BRIGHTNESS) { + brightness = MIN_BRIGHTNESS; + } + updateBrightness(); + } + } + + public void highlight( boolean value ) { + if (value) { + brightness = 1.0f; + name.hardlight( 0xCACFC2 ); + } else { + brightness = 0.999f; + name.hardlight( 0x444444 ); + } + + updateBrightness(); + } + + private void updateBrightness() { + avatar.gm = avatar.bm = avatar.rm = avatar.am = brightness; + } + } + + private class ChallengeButton extends Button { + + private Image image; + + public ChallengeButton() { + super(); + + width = image.width; + height = image.height; + + image.am = Badges.isUnlocked( Badges.Badge.VICTORY ) ? 1.0f : 0.5f; + } + + @Override + protected void createChildren() { + + super.createChildren(); + + image = Icons.get( ShatteredPixelDungeon.challenges() > 0 ? Icons.CHALLENGE_ON :Icons.CHALLENGE_OFF ); + add( image ); + } + + @Override + protected void layout() { + + super.layout(); + + image.x = align( x ); + image.y = align( y ); + } + + @Override + protected void onClick() { + if (Badges.isUnlocked( Badges.Badge.VICTORY )) { + add( new WndChallenges( ShatteredPixelDungeon.challenges(), true ) { + public void onBackPressed() { + super.onBackPressed(); + image.copy( Icons.get( ShatteredPixelDungeon.challenges() > 0 ? + Icons.CHALLENGE_ON :Icons.CHALLENGE_OFF ) ); + }; + } ); + } else { + add( new WndMessage( TXT_WIN_THE_GAME ) ); + } + } + + @Override + protected void onTouchDown() { + Sample.INSTANCE.play( Assets.SND_CLICK ); + } + } +} \ No newline at end of file diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java index 35e7bde83..e245c41f6 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java @@ -17,7 +17,6 @@ */ package com.shatteredpixel.shatteredpixeldungeon.scenes; -import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; import com.watabou.noosa.BitmapText; import com.watabou.noosa.Camera; import com.watabou.noosa.Game; @@ -26,9 +25,11 @@ 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.ShatteredPixelDungeon; import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites; import com.shatteredpixel.shatteredpixeldungeon.effects.Fireball; import com.shatteredpixel.shatteredpixeldungeon.ui.Archs; +import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton; import com.shatteredpixel.shatteredpixeldungeon.ui.PrefsButton; public class TitleScene extends PixelScene { @@ -80,7 +81,7 @@ public class TitleScene extends PixelScene { DashboardItem btnBadges = new DashboardItem( TXT_BADGES, 3 ) { @Override protected void onClick() { - Game.switchScene( BadgesScene.class ); + ShatteredPixelDungeon.switchNoFade( BadgesScene.class ); } }; btnBadges.setPos( w / 2 - btnBadges.width(), (h + height) / 2 - DashboardItem.SIZE ); @@ -89,7 +90,7 @@ public class TitleScene extends PixelScene { DashboardItem btnAbout = new DashboardItem( TXT_ABOUT, 1 ) { @Override protected void onClick() { - Game.switchScene( AboutScene.class ); + ShatteredPixelDungeon.switchNoFade( AboutScene.class ); } }; btnAbout.setPos( w / 2, (h + height) / 2 - DashboardItem.SIZE ); @@ -98,7 +99,7 @@ public class TitleScene extends PixelScene { DashboardItem btnPlay = new DashboardItem( TXT_PLAY, 0 ) { @Override protected void onClick() { - Game.switchScene( StartScene.class ); + ShatteredPixelDungeon.switchNoFade( StartScene.class ); } }; btnPlay.setPos( w / 2 - btnPlay.width(), btnAbout.top() - DashboardItem.SIZE ); @@ -107,7 +108,7 @@ public class TitleScene extends PixelScene { DashboardItem btnHighscores = new DashboardItem( TXT_HIGHSCORES, 2 ) { @Override protected void onClick() { - Game.switchScene( RankingsScene.class ); + ShatteredPixelDungeon.switchNoFade( RankingsScene.class ); } }; btnHighscores.setPos( w / 2, btnPlay.top() ); @@ -128,8 +129,12 @@ public class TitleScene extends PixelScene { add( version ); PrefsButton btnPrefs = new PrefsButton(); - btnPrefs.setPos( w - btnPrefs.width() - 1, 1 ); + btnPrefs.setPos( 0, 0 ); add( btnPrefs ); + + ExitButton btnExit = new ExitButton(); + btnExit.setPos( w - btnExit.width(), 0 ); + add( btnExit ); fadeIn(); } diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ui/ExitButton.java b/src/com/shatteredpixel/shatteredpixeldungeon/ui/ExitButton.java new file mode 100644 index 000000000..d55a1875e --- /dev/null +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ui/ExitButton.java @@ -0,0 +1,7 @@ +package com.shatteredpixel.shatteredpixeldungeon.ui; + +/** + * Created by Evan on 18/10/2014. + */ +public class ExitButton { +} diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndChallenges.java b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndChallenges.java new file mode 100644 index 000000000..fd9ed6599 --- /dev/null +++ b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndChallenges.java @@ -0,0 +1,7 @@ +package com.shatteredpixel.shatteredpixeldungeon.windows; + +/** + * Created by Evan on 18/10/2014. + */ +public class WndChallenges { +} diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndClass.java b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndClass.java new file mode 100644 index 000000000..054e08d01 --- /dev/null +++ b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndClass.java @@ -0,0 +1,7 @@ +package com.shatteredpixel.shatteredpixeldungeon.windows; + +/** + * Created by Evan on 18/10/2014. + */ +public class WndClass { +}