package pl.shockah.ts.entities.hud;

import pl.shockah.glib.geom.Rectangle;
import pl.shockah.glib.geom.vector.Vector2i;
import pl.shockah.glib.gl.Graphics;
import pl.shockah.glib.gl.color.Color;
import pl.shockah.glib.gl.font.TextHelper;
import pl.shockah.glib.logic.standard.EntityRenderable;
import pl.shockah.glib.state.State;
import pl.shockah.ts.Assets;
import pl.shockah.ts.AtlasHelper;
import pl.shockah.ts.entities.EntityWallHint;

public class HudHintDisplay extends EntityRenderable {
	public HudHintDisplay() {
		baseDepth = -10000000;
	}
	
	protected void onRender(Graphics g) {
		if (EntityWallHint.alpha <= 0f || EntityWallHint.globalMessage == null) return;
		
		g.toggleAbsolute();
		
		Vector2i size = State.get().getDisplaySize();
		String wrapped = TextHelper.wordwrap(Assets.font24,EntityWallHint.globalMessage,size.x-40).toString();
		double strH = Math.max(Assets.font24.getHeight()*wrapped.split("\\r?\\n").length,Assets.aFrameText.getImage("topleft").getHeight()+Assets.aFrameText.getImage("bottomleft").getHeight()+4);
		
		g.setColor(Color.White.alpha(EntityWallHint.alpha));
		AtlasHelper.renderFrame(g,new Rectangle(12,12,size.x-24,strH+6),Assets.aFrameText);
		
		g.setColor(Color.White.alpha(EntityWallHint.alpha));
		TextHelper.drawWrapped(g,Assets.font24,20,21,wrapped,size.x-40);
		
		g.toggleAbsolute();
	}
}