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.ui;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
import com.watabou.input.Touchscreen.Touch;
|
|
|
|
import com.watabou.noosa.BitmapText;
|
|
|
|
import com.watabou.noosa.Camera;
|
|
|
|
import com.watabou.noosa.Image;
|
|
|
|
import com.watabou.noosa.NinePatch;
|
|
|
|
import com.watabou.noosa.TouchArea;
|
2014-10-19 01:30:38 +00:00
|
|
|
import com.watabou.noosa.audio.Sample;
|
2014-07-27 13:39:07 +00:00
|
|
|
import com.watabou.noosa.particles.Emitter;
|
2014-10-19 01:30:38 +00:00
|
|
|
import com.watabou.noosa.ui.Button;
|
2014-07-27 13:39:07 +00:00
|
|
|
import com.watabou.noosa.ui.Component;
|
2014-08-03 18:46:22 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.BloodParticle;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.items.keys.IronKey;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
|
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
|
2014-10-19 01:30:38 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
|
2014-08-03 18:46:22 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
|
2014-07-27 13:39:07 +00:00
|
|
|
|
|
|
|
public class StatusPane extends Component {
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
private NinePatch shield;
|
|
|
|
private Image avatar;
|
|
|
|
private Emitter blood;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
private int lastTier = 0;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
private Image hp;
|
|
|
|
private Image exp;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
private int lastLvl = -1;
|
|
|
|
private int lastKeys = -1;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
private BitmapText level;
|
|
|
|
private BitmapText depth;
|
|
|
|
private BitmapText keys;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
private DangerIndicator danger;
|
|
|
|
private BuffIndicator buffs;
|
|
|
|
private Compass compass;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
private MenuButton btnMenu;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
@Override
|
|
|
|
protected void createChildren() {
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
shield = new NinePatch( Assets.STATUS, 80, 0, 30 + 18, 0 );
|
|
|
|
add( shield );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
add( new TouchArea( 0, 1, 31, 31 ) {
|
|
|
|
@Override
|
|
|
|
protected void onClick( Touch touch ) {
|
|
|
|
Image sprite = Dungeon.hero.sprite;
|
|
|
|
if (!sprite.isVisible()) {
|
|
|
|
Camera.main.focusOn( sprite );
|
|
|
|
}
|
|
|
|
GameScene.show( new WndHero() );
|
|
|
|
};
|
|
|
|
} );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
btnMenu = new MenuButton();
|
|
|
|
add( btnMenu );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
avatar = HeroSprite.avatar( Dungeon.hero.heroClass, lastTier );
|
|
|
|
add( avatar );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
blood = new Emitter();
|
|
|
|
blood.pos( avatar );
|
|
|
|
blood.pour( BloodParticle.FACTORY, 0.3f );
|
|
|
|
blood.autoKill = false;
|
|
|
|
blood.on = false;
|
|
|
|
add( blood );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
compass = new Compass( Dungeon.level.exit );
|
|
|
|
add( compass );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
hp = new Image( Assets.HP_BAR );
|
|
|
|
add( hp );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
exp = new Image( Assets.XP_BAR );
|
|
|
|
add( exp );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
level = new BitmapText( PixelScene.font1x );
|
|
|
|
level.hardlight( 0xFFEBA4 );
|
|
|
|
add( level );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
depth = new BitmapText( Integer.toString( Dungeon.depth ), PixelScene.font1x );
|
|
|
|
depth.hardlight( 0xCACFC2 );
|
|
|
|
depth.measure();
|
|
|
|
add( depth );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
Dungeon.hero.belongings.countIronKeys();
|
|
|
|
keys = new BitmapText( PixelScene.font1x );
|
|
|
|
keys.hardlight( 0xCACFC2 );
|
|
|
|
add( keys );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
danger = new DangerIndicator();
|
|
|
|
add( danger );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
buffs = new BuffIndicator( Dungeon.hero );
|
|
|
|
add( buffs );
|
|
|
|
}
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
@Override
|
|
|
|
protected void layout() {
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
height = 32;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
shield.size( width, shield.height );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
avatar.x = PixelScene.align( camera(), shield.x + 15 - avatar.width / 2 );
|
|
|
|
avatar.y = PixelScene.align( camera(), shield.y + 16 - avatar.height / 2 );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
compass.x = avatar.x + avatar.width / 2 - compass.origin.x;
|
|
|
|
compass.y = avatar.y + avatar.height / 2 - compass.origin.y;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
hp.x = 30;
|
|
|
|
hp.y = 3;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
depth.x = width - 24 - depth.width() - 18;
|
|
|
|
depth.y = 6;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
keys.y = 6;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
danger.setPos( width - danger.width(), 18 );
|
2015-01-22 03:54:58 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
buffs.setPos( 31, 9 );
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
btnMenu.setPos( width - btnMenu.width(), 1 );
|
|
|
|
}
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
@Override
|
|
|
|
public void update() {
|
|
|
|
super.update();
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
float health = (float)Dungeon.hero.HP / Dungeon.hero.HT;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
if (health == 0) {
|
|
|
|
avatar.tint( 0x000000, 0.6f );
|
|
|
|
blood.on = false;
|
|
|
|
} else if (health < 0.25f) {
|
|
|
|
avatar.tint( 0xcc0000, 0.4f );
|
|
|
|
blood.on = true;
|
|
|
|
} else {
|
|
|
|
avatar.resetColor();
|
|
|
|
blood.on = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hp.scale.x = health;
|
|
|
|
exp.scale.x = (width / exp.width) * Dungeon.hero.exp / Dungeon.hero.maxExp();
|
|
|
|
|
|
|
|
if (Dungeon.hero.lvl != lastLvl) {
|
|
|
|
|
|
|
|
if (lastLvl != -1) {
|
|
|
|
Emitter emitter = (Emitter)recycle( Emitter.class );
|
|
|
|
emitter.revive();
|
|
|
|
emitter.pos( 27, 27 );
|
|
|
|
emitter.burst( Speck.factory( Speck.STAR ), 12 );
|
|
|
|
}
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
lastLvl = Dungeon.hero.lvl;
|
|
|
|
level.text( Integer.toString( lastLvl ) );
|
|
|
|
level.measure();
|
|
|
|
level.x = PixelScene.align( 27.0f - level.width() / 2 );
|
|
|
|
level.y = PixelScene.align( 27.5f - level.baseLine() / 2 );
|
|
|
|
}
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
int k = IronKey.curDepthQuantity;
|
|
|
|
if (k != lastKeys) {
|
|
|
|
lastKeys = k;
|
|
|
|
keys.text( Integer.toString( lastKeys ) );
|
|
|
|
keys.measure();
|
|
|
|
keys.x = width - 8 - keys.width() - 18;
|
|
|
|
}
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
int tier = Dungeon.hero.tier();
|
|
|
|
if (tier != lastTier) {
|
|
|
|
lastTier = tier;
|
|
|
|
avatar.copy( HeroSprite.avatar( Dungeon.hero.heroClass, tier ) );
|
|
|
|
}
|
|
|
|
}
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
private static class MenuButton extends Button {
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
private Image image;
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
public MenuButton() {
|
|
|
|
super();
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
width = image.width + 4;
|
|
|
|
height = image.height + 4;
|
|
|
|
}
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
@Override
|
|
|
|
protected void createChildren() {
|
|
|
|
super.createChildren();
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
image = new Image( Assets.STATUS, 114, 3, 12, 11 );
|
|
|
|
add( image );
|
|
|
|
}
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
@Override
|
|
|
|
protected void layout() {
|
|
|
|
super.layout();
|
2014-10-19 01:30:38 +00:00
|
|
|
|
2015-06-12 20:22:26 +00:00
|
|
|
image.x = x + 2;
|
|
|
|
image.y = y + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onTouchDown() {
|
|
|
|
image.brightness( 1.5f );
|
|
|
|
Sample.INSTANCE.play( Assets.SND_CLICK );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onTouchUp() {
|
|
|
|
image.resetColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onClick() {
|
|
|
|
GameScene.show( new WndGame() );
|
|
|
|
}
|
|
|
|
}
|
2014-07-27 13:39:07 +00:00
|
|
|
}
|