Added a progressbar class
This commit is contained in:
parent
1ec72d47ba
commit
5ea0a854c8
3 changed files with 87 additions and 31 deletions
77
src/ei/engine/effects/ProgressBar.java
Normal file
77
src/ei/engine/effects/ProgressBar.java
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
package ei.engine.effects;
|
||||||
|
|
||||||
|
import ei.engine.math.Vector2f;
|
||||||
|
import ei.engine.math.Vector4f;
|
||||||
|
import ei.engine.scene.Box;
|
||||||
|
import ei.engine.scene.Node;
|
||||||
|
import ei.engine.scene.Sprite;
|
||||||
|
import ei.engine.texture.Texture;
|
||||||
|
|
||||||
|
public class ProgressBar{
|
||||||
|
private Node progressNode;
|
||||||
|
private Sprite value;
|
||||||
|
private Box bar;
|
||||||
|
private int max;
|
||||||
|
private float width;
|
||||||
|
private float height;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a selection box with health bar
|
||||||
|
*
|
||||||
|
* @param x The size of the progressbar
|
||||||
|
* @param y The size of the progressbar
|
||||||
|
* @param max The max health of the object
|
||||||
|
*/
|
||||||
|
public ProgressBar(String name, float x, float y, int max){
|
||||||
|
this.max = max;
|
||||||
|
this.width = x;
|
||||||
|
this.height = y;
|
||||||
|
progressNode = new Node(name+"Node");
|
||||||
|
|
||||||
|
Texture tex = new Texture();
|
||||||
|
tex.setColor(new Vector4f(0.5f, 1.0f, 0.5f,1));
|
||||||
|
|
||||||
|
Texture tex2 = new Texture();
|
||||||
|
tex2.setColor(new Vector4f(0.3f, 1.0f, 0.3f, 0.6f));
|
||||||
|
|
||||||
|
value = new Sprite(name+"_Value",tex2);
|
||||||
|
value.setSize(new Vector2f(width,height));
|
||||||
|
value.setLocation(new Vector2f(0,-50));
|
||||||
|
progressNode.add(value);
|
||||||
|
|
||||||
|
bar = new Box(name+"_Bar",tex);
|
||||||
|
bar.setSize(new Vector2f(width,height));
|
||||||
|
bar.setLocation(new Vector2f());
|
||||||
|
progressNode.add(bar);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBarColor(Vector4f c){
|
||||||
|
bar.getTexture().setColor(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Node getNode(){
|
||||||
|
return progressNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the value of the health bar
|
||||||
|
*
|
||||||
|
* @param v The value of the health bar
|
||||||
|
*/
|
||||||
|
public void setValue(int v){
|
||||||
|
value.setSize(new Vector2f(((float)v/max)*width,height));//(v/max)*width
|
||||||
|
value.setLocation(new Vector2f(-width/2+(((float)v/max)*width)/2,0));
|
||||||
|
|
||||||
|
if(((float)v/max) < 0.15f){
|
||||||
|
value.getTexture().setColor(new Vector4f(1.0f, 0f, 0f, 0.6f));
|
||||||
|
}
|
||||||
|
else if(((float)v/max) < 0.50f){
|
||||||
|
value.getTexture().setColor(new Vector4f(1.0f, .95f, 0, 0.6f));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
value.getTexture().setColor(new Vector4f(0.3f, 1.0f, 0.3f, 0.6f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,7 @@ package ei.game.gamestate;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
import ei.engine.effects.ProgressBar;
|
import ei.engine.effects.BitmapProgressBar;
|
||||||
import ei.engine.scene.Sprite;
|
import ei.engine.scene.Sprite;
|
||||||
import ei.engine.sound.SoundLoader;
|
import ei.engine.sound.SoundLoader;
|
||||||
import ei.engine.state.GameState;
|
import ei.engine.state.GameState;
|
||||||
|
|
@ -22,7 +22,7 @@ public class LoadingState extends GameState{
|
||||||
private Queue<String> loadSounds;
|
private Queue<String> loadSounds;
|
||||||
// The name of the next state to activate after loading
|
// The name of the next state to activate after loading
|
||||||
private String nextState;
|
private String nextState;
|
||||||
private ProgressBar progress;
|
private BitmapProgressBar progress;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -35,7 +35,7 @@ public class LoadingState extends GameState{
|
||||||
loadTextures = new LinkedList<String>();
|
loadTextures = new LinkedList<String>();
|
||||||
loadSounds = new LinkedList<String>();
|
loadSounds = new LinkedList<String>();
|
||||||
|
|
||||||
progress = new ProgressBar("Loading");
|
progress = new BitmapProgressBar("Loading");
|
||||||
progress.centerToScreen();
|
progress.centerToScreen();
|
||||||
progress.setBarTexture(new Sprite("ProgressBar","data/loadbar_front.png"));
|
progress.setBarTexture(new Sprite("ProgressBar","data/loadbar_front.png"));
|
||||||
progress.setProgressTexture(new Sprite("Progress","data/loadbar.png"));
|
progress.setProgressTexture(new Sprite("Progress","data/loadbar.png"));
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package ei.game.scene;
|
package ei.game.scene;
|
||||||
|
|
||||||
|
import ei.engine.effects.ProgressBar;
|
||||||
import ei.engine.math.Vector2f;
|
import ei.engine.math.Vector2f;
|
||||||
import ei.engine.math.Vector4f;
|
import ei.engine.math.Vector4f;
|
||||||
import ei.engine.scene.Box;
|
import ei.engine.scene.Box;
|
||||||
|
|
@ -10,7 +11,7 @@ import ei.engine.texture.Texture;
|
||||||
public class SelectBox {
|
public class SelectBox {
|
||||||
private Node selectNode;
|
private Node selectNode;
|
||||||
private Node mouseOverNode;
|
private Node mouseOverNode;
|
||||||
private Sprite value;
|
private ProgressBar bar;
|
||||||
private int max;
|
private int max;
|
||||||
private float width;
|
private float width;
|
||||||
private static final float height = 3;
|
private static final float height = 3;
|
||||||
|
|
@ -31,25 +32,14 @@ public class SelectBox {
|
||||||
Texture tex = new Texture();
|
Texture tex = new Texture();
|
||||||
tex.setColor(new Vector4f(0.5f, 1.0f, 0.5f,1));
|
tex.setColor(new Vector4f(0.5f, 1.0f, 0.5f,1));
|
||||||
|
|
||||||
Texture tex2 = new Texture();
|
bar = new ProgressBar("Health",width,height,max);
|
||||||
tex2.setColor(new Vector4f(0.3f, 1.0f, 0.3f, 0.6f));
|
bar.getNode().setLocation(new Vector2f(0,-x/2+height/2));
|
||||||
|
selectNode.add(bar.getNode());
|
||||||
value = new Sprite("Healthvalue",tex2);
|
mouseOverNode.add(bar.getNode());
|
||||||
value.setSize(new Vector2f(x,height));
|
|
||||||
value.setLocation(new Vector2f(0,-x/2+height/2));
|
|
||||||
selectNode.add(value);
|
|
||||||
mouseOverNode.add(value);
|
|
||||||
|
|
||||||
Box bar = new Box("bar",tex);
|
|
||||||
bar.setSize(new Vector2f(x,height));
|
|
||||||
bar.setLocation(new Vector2f(0,-x/2+height/2));
|
|
||||||
selectNode.add(bar);
|
|
||||||
mouseOverNode.add(bar);
|
|
||||||
|
|
||||||
Box select = new Box("select",tex);
|
Box select = new Box("select",tex);
|
||||||
select.setSize(new Vector2f(x,y));
|
select.setSize(new Vector2f(x,y));
|
||||||
selectNode.add(select);
|
selectNode.add(select);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,17 +68,6 @@ public class SelectBox {
|
||||||
* @param v The value of the health bar
|
* @param v The value of the health bar
|
||||||
*/
|
*/
|
||||||
public void setValue(int v){
|
public void setValue(int v){
|
||||||
value.setSize(new Vector2f(((float)v/max)*width,height));//(v/max)*width
|
bar.setValue(v);
|
||||||
value.setLocation(new Vector2f(-width/2+(((float)v/max)*width)/2,-width/2+height/2));
|
|
||||||
|
|
||||||
if(((float)v/max) < 0.15f){
|
|
||||||
value.getTexture().setColor(new Vector4f(1.0f, 0f, 0f, 0.6f));
|
|
||||||
}
|
|
||||||
else if(((float)v/max) < 0.50f){
|
|
||||||
value.getTexture().setColor(new Vector4f(1.0f, .95f, 0, 0.6f));
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
value.getTexture().setColor(new Vector4f(0.3f, 1.0f, 0.3f, 0.6f));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue