v1.3.0: fixed errors in badge display and allowed multiple at once
This commit is contained in:
@@ -32,6 +32,7 @@ import com.watabou.noosa.audio.Sample;
|
||||
import com.watabou.utils.Point;
|
||||
import com.watabou.utils.PointF;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class BadgeBanner extends Image {
|
||||
@@ -40,8 +41,9 @@ public class BadgeBanner extends Image {
|
||||
FADE_IN, STATIC, FADE_OUT
|
||||
}
|
||||
private State state;
|
||||
|
||||
private static final float DEFAULT_SCALE = 3;
|
||||
|
||||
public static final float DEFAULT_SCALE = 3;
|
||||
public static final int SIZE = 16;
|
||||
|
||||
private static final float FADE_IN_TIME = 0.25f;
|
||||
private static final float STATIC_TIME = 1f;
|
||||
@@ -52,14 +54,14 @@ public class BadgeBanner extends Image {
|
||||
|
||||
private static TextureFilm atlas;
|
||||
|
||||
private static BadgeBanner current;
|
||||
public static ArrayList<BadgeBanner> showing = new ArrayList<>();
|
||||
|
||||
private BadgeBanner( int index ) {
|
||||
|
||||
super( Assets.Interfaces.BADGES );
|
||||
|
||||
if (atlas == null) {
|
||||
atlas = new TextureFilm( texture, 16, 16 );
|
||||
atlas = new TextureFilm( texture, SIZE, SIZE );
|
||||
}
|
||||
|
||||
setup(index);
|
||||
@@ -124,12 +126,16 @@ public class BadgeBanner extends Image {
|
||||
|
||||
@Override
|
||||
public void kill() {
|
||||
if (current == this) {
|
||||
current = null;
|
||||
}
|
||||
showing.remove(this);
|
||||
super.kill();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
showing.remove(this);
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
//map to cache highlight positions so we don't have to keep looking at texture pixels
|
||||
private static HashMap<Integer, Point> highlightPositions = new HashMap<>();
|
||||
|
||||
@@ -192,12 +198,13 @@ public class BadgeBanner extends Image {
|
||||
}
|
||||
|
||||
public static BadgeBanner show( int image ) {
|
||||
if (current != null) {
|
||||
current.setup(image);
|
||||
} else {
|
||||
current = new BadgeBanner(image);
|
||||
}
|
||||
return current;
|
||||
BadgeBanner banner = new BadgeBanner(image);
|
||||
showing.add(banner);
|
||||
return banner;
|
||||
}
|
||||
|
||||
public static boolean isShowingBadges(){
|
||||
return !showing.isEmpty();
|
||||
}
|
||||
|
||||
public static Image image( int index ) {
|
||||
|
||||
@@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.GamesInProgress;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Amulet;
|
||||
@@ -33,6 +34,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
|
||||
import com.watabou.noosa.Camera;
|
||||
import com.watabou.noosa.Game;
|
||||
import com.watabou.noosa.Image;
|
||||
import com.watabou.noosa.tweeners.Delayer;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
public class AmuletScene extends PixelScene {
|
||||
@@ -49,6 +51,9 @@ public class AmuletScene extends PixelScene {
|
||||
{
|
||||
inGameScene = true;
|
||||
}
|
||||
|
||||
RedButton btnExit = null;
|
||||
RedButton btnStay = null;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
@@ -63,19 +68,36 @@ public class AmuletScene extends PixelScene {
|
||||
|
||||
amulet = new Image( Assets.Sprites.AMULET );
|
||||
add( amulet );
|
||||
|
||||
RedButton btnExit = new RedButton( Messages.get(this, "exit") ) {
|
||||
|
||||
btnExit = new RedButton( Messages.get(this, "exit") ) {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
Dungeon.win( Amulet.class );
|
||||
Dungeon.deleteGame( GamesInProgress.curSlot, true );
|
||||
Game.switchScene( RankingsScene.class );
|
||||
|
||||
add(new Delayer(0.1f){
|
||||
@Override
|
||||
protected void onComplete() {
|
||||
if (BadgeBanner.isShowingBadges()){
|
||||
btnExit.enable(false);
|
||||
btnStay.enable(false);
|
||||
AmuletScene.this.add(new Delayer(3f){
|
||||
@Override
|
||||
protected void onComplete() {
|
||||
Game.switchScene( RankingsScene.class );
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Game.switchScene( RankingsScene.class );
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
btnExit.setSize( WIDTH, BTN_HEIGHT );
|
||||
add( btnExit );
|
||||
|
||||
RedButton btnStay = new RedButton( Messages.get(this, "stay") ) {
|
||||
btnStay = new RedButton( Messages.get(this, "stay") ) {
|
||||
@Override
|
||||
protected void onClick() {
|
||||
onBackPressed();
|
||||
|
||||
@@ -293,13 +293,23 @@ public class PixelScene extends Scene {
|
||||
Game.runOnRenderThread(new Callback() {
|
||||
@Override
|
||||
public void call() {
|
||||
BadgeBanner banner = BadgeBanner.show( badge.image );
|
||||
banner.camera = uiCamera;
|
||||
float offset = Camera.main.centerOffset.y;
|
||||
banner.x = align( banner.camera, (banner.camera.width - banner.width) / 2 );
|
||||
banner.y = align( uiCamera, (uiCamera.height - banner.height) / 2 - banner.height/2 - 16 - offset );
|
||||
Scene s = Game.scene();
|
||||
if (s != null) s.add( banner );
|
||||
if (s != null) {
|
||||
BadgeBanner banner = BadgeBanner.show(badge.image);
|
||||
s.add(banner);
|
||||
float offset = Camera.main.centerOffset.y;
|
||||
|
||||
int left = uiCamera.width/2 - BadgeBanner.SIZE/2;
|
||||
left -= (BadgeBanner.SIZE * BadgeBanner.DEFAULT_SCALE * (BadgeBanner.showing.size()-1))/2;
|
||||
for (int i = 0; i < BadgeBanner.showing.size(); i++){
|
||||
banner = BadgeBanner.showing.get(i);
|
||||
banner.camera = uiCamera;
|
||||
banner.x = align(banner.camera, left);
|
||||
banner.y = align(uiCamera, (uiCamera.height - banner.height) / 2 - banner.height / 2 - 16 - offset);
|
||||
left += BadgeBanner.SIZE * BadgeBanner.DEFAULT_SCALE;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user