From 4776027d184955458024fd4d27600448e34fac7c Mon Sep 17 00:00:00 2001
From: Wuzzy <almikes@aol.com>
Date: Wed, 4 Feb 2015 04:01:56 +0100
Subject: Add text to bars

---
 init.lua | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

(limited to 'init.lua')

diff --git a/init.lua b/init.lua
index 65b28cb..1b674a0 100644
--- a/init.lua
+++ b/init.lua
@@ -6,7 +6,9 @@ hud.air = {}
 
 -- HUD item ids
 local health_hud = {}
+local health_hud_text = {}
 local air_hud = {}
+local air_hud_text = {}
 
 -- default settings
 
@@ -67,6 +69,15 @@ local function custom_hud(player)
 		alignment = {x=-1,y=-1},
 		offset = HUD_HEALTH_OFFSET,
 	})
+	health_hud_text[name] = player:hud_add({
+		hud_elem_type = "text",
+		position = HUD_HEALTH_POS,
+		text = tostring(string.format("Health: %d/%d", player:get_hp(), 20)),
+		alignment = {x=1,y=1},
+		number = 0xFFFFFF,
+		direction = 0,
+		offset = { x = HUD_HEALTH_OFFSET.x + 2,  y = HUD_HEALTH_OFFSET.y },
+	})
 
  --air
 	player:hud_add({
@@ -85,6 +96,15 @@ local function custom_hud(player)
 		alignment = {x=-1,y=-1},
 		offset = HUD_AIR_OFFSET,
 	})
+	air_hud_text[name] = player:hud_add({
+		hud_elem_type = "text",
+		position = HUD_AIR_POS,
+		text = tostring(string.format("Breath: %d/%d", math.min(player:get_breath(), 10), 10)),
+		alignment = {x=1,y=1},
+		number = 0x000000,
+		direction = 0,
+		offset = { x = HUD_AIR_OFFSET.x + 2,  y = HUD_AIR_OFFSET.y },
+	})
 
  end
 end
@@ -99,6 +119,9 @@ local function update_hud(player)
 		air = player:get_breath()
 		hud.air[name] = air
 		player:hud_change(air_hud[name], "number", hud.value_to_barlength(math.min(air, 10), 10))
+		player:hud_change(air_hud_text[name], "text",
+			tostring(string.format("Breath: %d/%d", math.min(player:get_breath(), 10), 10))
+		)
 	end
  --health
 	local hp = tonumber(hud.health[name])
@@ -106,6 +129,9 @@ local function update_hud(player)
 		hp = player:get_hp()
 		hud.health[name] = hp
 		player:hud_change(health_hud[name], "number", hud.value_to_barlength(hp, 20))
+		player:hud_change(health_hud_text[name], "text",
+			tostring(string.format("Health: %d/%d", hp, 20))
+		)
 	end
 end
 
-- 
cgit v1.2.3