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.
		
		
		
		
		
			
		
			
				
					
					
						
							67 lines
						
					
					
						
							1.4 KiB
						
					
					
				
			
		
		
	
	
							67 lines
						
					
					
						
							1.4 KiB
						
					
					
				| package mightypork.rogue.screens.ingame;
 | |
| 
 | |
| 
 | |
| import mightypork.gamecore.gui.AlignX;
 | |
| import mightypork.gamecore.gui.components.VisualComponent;
 | |
| import mightypork.gamecore.render.Render;
 | |
| import mightypork.gamecore.render.textures.TxQuad;
 | |
| import mightypork.util.constraints.num.Num;
 | |
| import mightypork.util.constraints.num.mutable.NumVar;
 | |
| import mightypork.util.constraints.rect.Rect;
 | |
| 
 | |
| 
 | |
| public class HeartBar extends VisualComponent {
 | |
| 	
 | |
| 	private final TxQuad img_on;
 | |
| 	private final TxQuad img_off;
 | |
| 	private final int total;
 | |
| 	private final int active;
 | |
| 	
 | |
| 	NumVar index = new NumVar(0);
 | |
| 	Rect heart;
 | |
| 	
 | |
| 	
 | |
| 	/**
 | |
| 	 * @param total
 | |
| 	 * @param active
 | |
| 	 * @param img_on
 | |
| 	 * @param img_off
 | |
| 	 * @param align
 | |
| 	 */
 | |
| 	public HeartBar(int total, int active, TxQuad img_on, TxQuad img_off, AlignX align)
 | |
| 	{
 | |
| 		super();
 | |
| 		this.total = total;
 | |
| 		this.active = active;
 | |
| 		this.img_on = img_on;
 | |
| 		this.img_off = img_off;
 | |
| 		
 | |
| 		final Num h = height();
 | |
| 		final Num w = width();
 | |
| 		
 | |
| 		switch (align) {
 | |
| 			case LEFT:
 | |
| 				heart = leftEdge().growRight(h).moveX(index.mul(h));
 | |
| 				break;
 | |
| 			case RIGHT:
 | |
| 				heart = rightEdge().growLeft(h).moveX(h.mul(-total + 1).add(index.mul(h)));
 | |
| 				break;
 | |
| 			case CENTER:
 | |
| 				heart = leftEdge().moveX(w.half().add(h.mul(-total / 2D))).growRight(h).moveX(index.mul(h));
 | |
| 				break;
 | |
| 		}
 | |
| 		
 | |
| 	}
 | |
| 	
 | |
| 	
 | |
| 	@Override
 | |
| 	protected void renderComponent()
 | |
| 	{
 | |
| 		for (int i = 0; i < total; i++) {
 | |
| 			index.setTo(i);
 | |
| 			
 | |
| 			Render.quadTextured(heart, (i < active ? img_on : img_off));
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| }
 | |
| 
 |