You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.5 KiB
68 lines
1.5 KiB
10 years ago
|
package mightypork.rogue.screens.game;
|
||
10 years ago
|
|
||
|
|
||
|
import mightypork.gamecore.gui.AlignX;
|
||
|
import mightypork.gamecore.gui.components.VisualComponent;
|
||
|
import mightypork.gamecore.render.Render;
|
||
10 years ago
|
import mightypork.gamecore.resources.textures.TxQuad;
|
||
|
import mightypork.gamecore.util.math.constraints.num.Num;
|
||
|
import mightypork.gamecore.util.math.constraints.num.mutable.NumVar;
|
||
|
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||
10 years ago
|
|
||
|
|
||
|
public class HeartBar extends VisualComponent {
|
||
|
|
||
10 years ago
|
private final TxQuad img_on;
|
||
|
private final TxQuad img_off;
|
||
|
private final int total;
|
||
|
private final int active;
|
||
10 years ago
|
|
||
|
NumVar index = new NumVar(0);
|
||
|
Rect heart;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param total
|
||
|
* @param active
|
||
|
* @param img_on
|
||
|
* @param img_off
|
||
10 years ago
|
* @param align
|
||
10 years ago
|
*/
|
||
10 years ago
|
public HeartBar(int total, int active, TxQuad img_on, TxQuad img_off, AlignX align)
|
||
|
{
|
||
10 years ago
|
super();
|
||
|
this.total = total;
|
||
|
this.active = active;
|
||
|
this.img_on = img_on;
|
||
|
this.img_off = img_off;
|
||
|
|
||
10 years ago
|
final Num h = height();
|
||
|
final Num w = width();
|
||
10 years ago
|
|
||
|
switch (align) {
|
||
|
case LEFT:
|
||
|
heart = leftEdge().growRight(h).moveX(index.mul(h));
|
||
|
break;
|
||
|
case RIGHT:
|
||
10 years ago
|
heart = rightEdge().growLeft(h).moveX(h.mul(-total + 1).add(index.mul(h)));
|
||
10 years ago
|
break;
|
||
|
case CENTER:
|
||
10 years ago
|
heart = leftEdge().moveX(w.half().add(h.mul(-total / 2D))).growRight(h).moveX(index.mul(h));
|
||
10 years ago
|
break;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
protected void renderComponent()
|
||
|
{
|
||
|
for (int i = 0; i < total; i++) {
|
||
|
index.setTo(i);
|
||
|
|
||
|
Render.quadTextured(heart, (i < active ? img_on : img_off));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|