forked from nalc/areas
Make HUD area list multi-line
This commit is contained in:
parent
b3873fcfaf
commit
21c9e6a4c0
41
hud.lua
41
hud.lua
|
@ -1,42 +1,45 @@
|
||||||
-- 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
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local pos = vector.round(player:getpos())
|
local pos = vector.round(player:getpos())
|
||||||
local areaString = ""
|
local areaStrings = {}
|
||||||
local first = true
|
|
||||||
for id, area in pairs(areas:getAreasAtPos(pos)) do
|
for id, area in pairs(areas:getAreasAtPos(pos)) do
|
||||||
if not first then
|
table.insert(areaStrings, ("%s [%u] (%s%s)")
|
||||||
areaString = areaString..", "
|
|
||||||
else
|
|
||||||
first = false
|
|
||||||
end
|
|
||||||
areaString = areaString .. ("%s [%u] (%s%s)")
|
|
||||||
:format(area.name, id, area.owner,
|
:format(area.name, id, area.owner,
|
||||||
area.open and ":open" or "")
|
area.open and ":open" or ""))
|
||||||
end
|
end
|
||||||
if not areas.hud[name] then
|
local areaString = table.concat(areaStrings, "\n")
|
||||||
areas.hud[name] = {}
|
local hud = areas.hud[name]
|
||||||
areas.hud[name].areasId = player:hud_add({
|
if not hud then
|
||||||
|
hud = {}
|
||||||
|
areas.hud[name] = hud
|
||||||
|
hud.areasId = player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
name = "Areas",
|
name = "Areas",
|
||||||
number = 0xFFFFFF,
|
number = 0xFFFFFF,
|
||||||
position = {x=0, y=1},
|
position = {x=0, y=1},
|
||||||
offset = {x=5, y=-60},
|
offset = {x=xOffset, y=yOffset - ((#areaStrings + 1) * textHeight)},
|
||||||
direction = 0,
|
direction = 0,
|
||||||
text = "Areas: "..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},
|
||||||
})
|
})
|
||||||
areas.hud[name].oldAreas = areaString
|
hud.oldAreas = areaString
|
||||||
return
|
return
|
||||||
elseif areas.hud[name].oldAreas ~= areaString then
|
elseif hud.oldAreas ~= areaString then
|
||||||
player:hud_change(areas.hud[name].areasId, "text",
|
player:hud_change(hud.areasId, "offset",
|
||||||
"Areas: "..areaString)
|
{x=xOffset, y=yOffset - ((#areaStrings + 1) * textHeight)})
|
||||||
areas.hud[name].oldAreas = areaString
|
player:hud_change(hud.areasId, "text",
|
||||||
|
"Areas:\n"..areaString)
|
||||||
|
hud.oldAreas = areaString
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user