From 21c9e6a4c0958fc5e72bbc3be5283be62c669dbd Mon Sep 17 00:00:00 2001
From: ShadowNinja <shadowninja@minetest.net>
Date: Mon, 13 Oct 2014 20:32:02 -0400
Subject: Make HUD area list multi-line

---
 hud.lua | 41 ++++++++++++++++++++++-------------------
 1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/hud.lua b/hud.lua
index ee93b06..604f6f3 100644
--- a/hud.lua
+++ b/hud.lua
@@ -1,42 +1,45 @@
 -- This is inspired by the landrush mod by Bremaweb
 
 areas.hud = {}
+local xOffset = 8
+local yOffset = -16
+-- Approximate the text height
+local textHeight = (tonumber(minetest.setting_get("font_size")) or 13) * 1.16
 
 minetest.register_globalstep(function(dtime)
 	for _, player in pairs(minetest.get_connected_players()) do
 		local name = player:get_player_name()
 		local pos = vector.round(player:getpos())
-		local areaString = ""
-		local first = true
+		local areaStrings = {}
 		for id, area in pairs(areas:getAreasAtPos(pos)) do
-			if not first then
-				areaString = areaString..", "
-			else
-				first = false
-			end
-			areaString = areaString .. ("%s [%u] (%s%s)")
+			table.insert(areaStrings, ("%s [%u] (%s%s)")
 					:format(area.name, id, area.owner,
-					area.open and ":open" or "")
+					area.open and ":open" or ""))
 		end
-		if not areas.hud[name] then
-			areas.hud[name] = {}
-			areas.hud[name].areasId = player:hud_add({
+		local areaString = table.concat(areaStrings, "\n")
+		local hud = areas.hud[name]
+		if not hud then
+			hud = {}
+			areas.hud[name] = hud
+			hud.areasId = player:hud_add({
 				hud_elem_type = "text",
 				name = "Areas",
 				number = 0xFFFFFF,
 				position = {x=0, y=1},
-				offset = {x=5, y=-60},
+				offset = {x=xOffset, y=yOffset - ((#areaStrings + 1) * textHeight)},
 				direction = 0,
-				text = "Areas: "..areaString,
+				text = "Areas:\n"..areaString,
 				scale = {x=200, y=60},
 				alignment = {x=1, y=1},
 			})
-			areas.hud[name].oldAreas = areaString
+			hud.oldAreas = areaString
 			return
-		elseif areas.hud[name].oldAreas ~= areaString then
-			player:hud_change(areas.hud[name].areasId, "text",
-					"Areas: "..areaString)
-			areas.hud[name].oldAreas = areaString
+		elseif hud.oldAreas ~= areaString then
+			player:hud_change(hud.areasId, "offset",
+				{x=xOffset, y=yOffset - ((#areaStrings + 1) * textHeight)})
+			player:hud_change(hud.areasId, "text",
+					"Areas:\n"..areaString)
+			hud.oldAreas = areaString
 		end
 	end
 end)
-- 
cgit v1.2.3