forked from nalc/areas
Use the HUD alignment field instead of manually calculating offset
This commit is contained in:
parent
3f777900d4
commit
0cda67f5c1
22
hud.lua
22
hud.lua
|
@ -1,10 +1,6 @@
|
||||||
-- This is inspired by the landrush mod by Bremaweb
|
-- This is inspired by the landrush mod by Bremaweb
|
||||||
|
|
||||||
areas.hud = {}
|
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)
|
minetest.register_globalstep(function(dtime)
|
||||||
for _, player in pairs(minetest.get_connected_players()) do
|
for _, player in pairs(minetest.get_connected_players()) do
|
||||||
|
@ -16,7 +12,11 @@ minetest.register_globalstep(function(dtime)
|
||||||
:format(area.name, id, area.owner,
|
:format(area.name, id, area.owner,
|
||||||
area.open and ":open" or ""))
|
area.open and ":open" or ""))
|
||||||
end
|
end
|
||||||
local areaString = table.concat(areaStrings, "\n")
|
local areaString = "Areas:"
|
||||||
|
if #areaStrings > 0 then
|
||||||
|
areaString = areaString.."\n"..
|
||||||
|
table.concat(areaStrings, "\n")
|
||||||
|
end
|
||||||
local hud = areas.hud[name]
|
local hud = areas.hud[name]
|
||||||
if not hud then
|
if not hud then
|
||||||
hud = {}
|
hud = {}
|
||||||
|
@ -26,19 +26,15 @@ minetest.register_globalstep(function(dtime)
|
||||||
name = "Areas",
|
name = "Areas",
|
||||||
number = 0xFFFFFF,
|
number = 0xFFFFFF,
|
||||||
position = {x=0, y=1},
|
position = {x=0, y=1},
|
||||||
offset = {x=xOffset, y=yOffset - ((#areaStrings + 1) * textHeight)},
|
offset = {x=8, y=-8},
|
||||||
direction = 0,
|
text = areaString,
|
||||||
text = "Areas:\n"..areaString,
|
|
||||||
scale = {x=200, y=60},
|
scale = {x=200, y=60},
|
||||||
alignment = {x=1, y=1},
|
alignment = {x=1, y=-1},
|
||||||
})
|
})
|
||||||
hud.oldAreas = areaString
|
hud.oldAreas = areaString
|
||||||
return
|
return
|
||||||
elseif hud.oldAreas ~= areaString then
|
elseif hud.oldAreas ~= areaString then
|
||||||
player:hud_change(hud.areasId, "offset",
|
player:hud_change(hud.areasId, "text", areaString)
|
||||||
{x=xOffset, y=yOffset - ((#areaStrings + 1) * textHeight)})
|
|
||||||
player:hud_change(hud.areasId, "text",
|
|
||||||
"Areas:\n"..areaString)
|
|
||||||
hud.oldAreas = areaString
|
hud.oldAreas = areaString
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user