evil-inside/src/ei/game/scene/SelectBox.java

95 lines
2.3 KiB
Java
Raw Normal View History

2007-04-17 12:51:26 +00:00
package ei.game.scene;
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 SelectBox {
private Node selectNode;
2007-04-18 16:06:44 +00:00
private Node mouseOverNode;
2007-04-17 12:51:26 +00:00
private Sprite value;
private int max;
2007-04-17 14:21:36 +00:00
private float width;
private static final float height = 3;
2007-04-17 12:51:26 +00:00
/**
* Creates a selection box with health bar
*
* @param x The size of the selection box
* @param y The size of the selection box
* @param max The max health of the object
*/
public SelectBox(float x, float y, int max){
this.max = max;
2007-04-17 14:21:36 +00:00
this.width = x;
2007-04-17 12:51:26 +00:00
selectNode = new Node("SelectionNode");
2007-04-18 16:06:44 +00:00
mouseOverNode = new Node("MouseOverNode");
2007-04-17 12:51:26 +00:00
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("Healthvalue",tex2);
2007-04-17 14:21:36 +00:00
value.setSize(new Vector2f(x,height));
value.setLocation(new Vector2f(0,-x/2+height/2));
2007-04-17 12:51:26 +00:00
selectNode.add(value);
2007-04-18 16:06:44 +00:00
mouseOverNode.add(value);
2007-04-17 12:51:26 +00:00
Box bar = new Box("bar",tex);
2007-04-17 14:21:36 +00:00
bar.setSize(new Vector2f(x,height));
bar.setLocation(new Vector2f(0,-x/2+height/2));
2007-04-17 12:51:26 +00:00
selectNode.add(bar);
2007-04-18 16:06:44 +00:00
mouseOverNode.add(bar);
2007-04-17 12:51:26 +00:00
Box select = new Box("select",tex);
select.setSize(new Vector2f(x,y));
selectNode.add(select);
}
/**
* Returns the node of the selection
*
* @return The node of the selection
*/
2007-04-18 16:06:44 +00:00
public Node getSelectNode(){
2007-04-17 12:51:26 +00:00
return selectNode;
}
2007-04-18 16:06:44 +00:00
/**
* Returns the node of the selection
*
* @return The node of the selection
*/
public Node getMouseOverNode(){
return mouseOverNode;
}
2007-04-17 12:51:26 +00:00
/**
* Sets the value of the health bar
*
* @param v The value of the health bar
*/
public void setValue(int v){
2007-04-17 15:55:22 +00:00
value.setSize(new Vector2f(((float)v/max)*width,height));//(v/max)*width
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));
}
2007-04-17 12:51:26 +00:00
}
}