Use the HUD API directly
parent
f809000bde
commit
5d6efc741a
32
hud.lua
32
hud.lua
|
@ -7,16 +7,6 @@ areas.hud = {}
|
||||||
local vround = vector.round
|
local vround = vector.round
|
||||||
local tconcat = table.concat
|
local tconcat = table.concat
|
||||||
|
|
||||||
hud.register("areas", {
|
|
||||||
hud_elem_type = "text",
|
|
||||||
position = {x = 0, y = 1},
|
|
||||||
alignment = {x = 1, y = -1},
|
|
||||||
offset = {x = 8, y = -8},
|
|
||||||
scale = {x = 200, y = 60},
|
|
||||||
text = "",
|
|
||||||
number = 0xFFFFFF
|
|
||||||
})
|
|
||||||
|
|
||||||
local function update_hud(player, name, pos)
|
local function update_hud(player, name, pos)
|
||||||
local areaStrings = {
|
local areaStrings = {
|
||||||
S("Areas:")
|
S("Areas:")
|
||||||
|
@ -40,10 +30,24 @@ local function update_hud(player, name, pos)
|
||||||
-- "Areas:" text has index 1
|
-- "Areas:" text has index 1
|
||||||
local areaString = #areaStrings > 1 and tconcat(areaStrings, "\n") or ""
|
local areaString = #areaStrings > 1 and tconcat(areaStrings, "\n") or ""
|
||||||
|
|
||||||
local phud = areas.hud[name] or {}
|
local hud = areas.hud[name]
|
||||||
if not phud.oldAreas or phud.oldAreas ~= areaString then
|
if not hud then
|
||||||
hud.change_item(player, "areas", {text = areaString})
|
hud = {}
|
||||||
phud.oldAreas = areaString
|
areas.hud[name] = hud
|
||||||
|
hud.areasId = player:hud_add({
|
||||||
|
hud_elem_type = "text",
|
||||||
|
name = "Areas",
|
||||||
|
number = 0xFFFFFF,
|
||||||
|
position = {x = 0, y = 1},
|
||||||
|
offset = {x = 8, y = -8},
|
||||||
|
scale = {x = 200, y = 60},
|
||||||
|
alignment = {x = 1, y = -1},
|
||||||
|
text = areaString
|
||||||
|
})
|
||||||
|
hud.oldAreas = areaString
|
||||||
|
elseif hud.oldAreas ~= areaString then
|
||||||
|
player:hud_change(hud.areasId, "text", areaString)
|
||||||
|
hud.oldAreas = areaString
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue