2015-01-30 19:05:10 +00:00
|
|
|
/*
|
|
|
|
* Pixel Dungeon
|
|
|
|
* Copyright (C) 2012-2015 Oleg Dolya
|
|
|
|
*
|
2015-06-12 20:44:04 +00:00
|
|
|
* Shattered Pixel Dungeon
|
2016-05-08 23:54:12 +00:00
|
|
|
* Copyright (C) 2014-2016 Evan Debenham
|
2015-06-12 20:44:04 +00:00
|
|
|
*
|
2015-01-30 19:05:10 +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/>
|
|
|
|
*/
|
|
|
|
package com.shatteredpixel.shatteredpixeldungeon.ui;
|
|
|
|
|
2016-03-05 07:43:52 +00:00
|
|
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
2015-01-30 19:05:10 +00:00
|
|
|
import com.watabou.noosa.ColorBlock;
|
|
|
|
import com.watabou.noosa.ui.Component;
|
|
|
|
|
|
|
|
public class HealthBar extends Component {
|
|
|
|
|
|
|
|
private static final int COLOR_BG = 0xFFCC0000;
|
2016-03-05 07:43:52 +00:00
|
|
|
private static final int COLOR_HP = 0xFF00EE00;
|
|
|
|
private static final int COLOR_SHLD = 0xFFBBEEBB;
|
2015-01-30 19:05:10 +00:00
|
|
|
|
|
|
|
private static final int HEIGHT = 2;
|
|
|
|
|
2016-03-05 07:43:52 +00:00
|
|
|
private ColorBlock Bg;
|
|
|
|
private ColorBlock Shld;
|
|
|
|
private ColorBlock Hp;
|
2015-01-30 19:05:10 +00:00
|
|
|
|
2016-03-05 07:43:52 +00:00
|
|
|
private float health;
|
|
|
|
private float shield;
|
2015-01-30 19:05:10 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void createChildren() {
|
2016-03-05 07:43:52 +00:00
|
|
|
Bg = new ColorBlock( 1, 1, COLOR_BG );
|
|
|
|
add( Bg );
|
|
|
|
|
|
|
|
Shld = new ColorBlock( 1, 1, COLOR_SHLD );
|
|
|
|
add( Shld );
|
2015-01-30 19:05:10 +00:00
|
|
|
|
2016-03-05 07:43:52 +00:00
|
|
|
Hp = new ColorBlock( 1, 1, COLOR_HP );
|
|
|
|
add( Hp );
|
2015-01-30 19:05:10 +00:00
|
|
|
|
|
|
|
height = HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void layout() {
|
|
|
|
|
2016-03-05 07:43:52 +00:00
|
|
|
Bg.x = Shld.x = Hp.x = x;
|
|
|
|
Bg.y = Shld.y = Hp.y = y;
|
2015-01-30 19:05:10 +00:00
|
|
|
|
2016-03-05 07:43:52 +00:00
|
|
|
Bg.size( width, HEIGHT );
|
|
|
|
Shld.size( width * shield, HEIGHT );
|
|
|
|
Hp.size( width * health, HEIGHT );
|
2015-01-30 19:05:10 +00:00
|
|
|
|
|
|
|
height = HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void level( float value ) {
|
2016-03-05 07:43:52 +00:00
|
|
|
level( value, 0f );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void level( float health, float shield ){
|
|
|
|
this.health = health;
|
|
|
|
this.shield = shield;
|
2015-01-30 19:05:10 +00:00
|
|
|
layout();
|
|
|
|
}
|
2016-03-05 07:43:52 +00:00
|
|
|
|
|
|
|
public void level(Char c){
|
|
|
|
float health = c.HP;
|
|
|
|
float shield = c.SHLD;
|
|
|
|
float max = Math.max(health+shield, c.HT);
|
|
|
|
|
|
|
|
level(health/max, (health+shield)/max);
|
|
|
|
}
|
2015-01-30 19:05:10 +00:00
|
|
|
}
|