diff --git a/mods/areas/hud.lua b/mods/areas/hud.lua index e1f6c1fa..b87d6097 100755 --- a/mods/areas/hud.lua +++ b/mods/areas/hud.lua @@ -7,36 +7,67 @@ local function tick() for _, player in pairs(minetest.get_connected_players()) do local name = player:get_player_name() local pos = vector.round(player:getpos()) - local areaStrings = {} + local area_text = "no areas\n" + local area_owner_name = "" + local mod_owner = 0 + local mod_open = 0 + local mod_arming = 0 + + local nb_areas = 0 for id, area in pairs(areas:getAreasAtPos(pos)) do - table.insert(areaStrings, ("%s [%u] (%s%s)") - :format(area.name, id, area.owner, - area.open and ":open" or area.openfarming and ":open to farming" or "")) + nb_areas = nb_areas+1 + if areas:isAreaOwner(id, name) then + mod_owner = 1 + end + + if area.open then + mod_open = 1 + end + if area.openfarming then + mod_arming = 1 + end + + if not area.parent then + area_owner_name = area.owner + end end - local areaString = "Areas:" - if #areaStrings > 0 then - areaString = areaString.."\n".. - table.concat(areaStrings, "\n") + + local icon = "areas_1_0_1.png" + if nb_areas > 0 then + area_text = ("nb area:%u\nowner:%s"):format(nb_areas, area_owner_name) + icon = ("areas_%u_%u_%u.png"):format(mod_owner, mod_open, mod_arming) end - local hud = areas.hud[name] - if not hud then - hud = {} - areas.hud[name] = hud - hud.areasId = player:hud_add({ + if not areas.hud[name] then + areas.hud[name] = {} + areas.hud[name].icon = player:hud_add({ + hud_elem_type = "image", + position = {x=0,y=1}, + scale = {x=1,y=1}, + offset = {x=26,y=-60}, + text = icon, + }) + + areas.hud[name].areas_id = player:hud_add({ hud_elem_type = "text", name = "Areas", number = 0xFFFFFF, position = {x=0, y=1}, - offset = {x=8, y=-8}, - text = areaString, - scale = {x=200, y=60}, + offset = {x=48, y=-40}, + text = area_text, + scale = {x=1, y=1}, alignment = {x=1, y=-1}, }) - hud.oldAreas = areaString - return - elseif hud.oldAreas ~= areaString then - player:hud_change(hud.areasId, "text", areaString) - hud.oldAreas = areaString + areas.hud[name].old_area_text = area_text + areas.hud[name].old_icon = icon + else + if areas.hud[name].old_area_text ~= area_text then + player:hud_change(areas.hud[name].areas_id, "text", area_text) + areas.hud[name].old_area_text = area_text + end + if areas.hud[name].old_icon ~= icon then + player:hud_change(areas.hud[name].icon, "text", icon) + areas.hud[name].old_icon = icon + end end end end diff --git a/mods/areas/textures/areas_0_0_0.png b/mods/areas/textures/areas_0_0_0.png new file mode 100644 index 00000000..f75a131f Binary files /dev/null and b/mods/areas/textures/areas_0_0_0.png differ diff --git a/mods/areas/textures/areas_0_0_1.png b/mods/areas/textures/areas_0_0_1.png new file mode 100644 index 00000000..65468ad1 Binary files /dev/null and b/mods/areas/textures/areas_0_0_1.png differ diff --git a/mods/areas/textures/areas_0_1_0.png b/mods/areas/textures/areas_0_1_0.png new file mode 100644 index 00000000..603ad387 Binary files /dev/null and b/mods/areas/textures/areas_0_1_0.png differ diff --git a/mods/areas/textures/areas_0_1_04.png b/mods/areas/textures/areas_0_1_04.png new file mode 100644 index 00000000..5a70543b Binary files /dev/null and b/mods/areas/textures/areas_0_1_04.png differ diff --git a/mods/areas/textures/areas_0_1_1.png b/mods/areas/textures/areas_0_1_1.png new file mode 100644 index 00000000..603ad387 Binary files /dev/null and b/mods/areas/textures/areas_0_1_1.png differ diff --git a/mods/areas/textures/areas_1_0_0.png b/mods/areas/textures/areas_1_0_0.png new file mode 100644 index 00000000..6a75ada4 Binary files /dev/null and b/mods/areas/textures/areas_1_0_0.png differ diff --git a/mods/areas/textures/areas_1_0_1.png b/mods/areas/textures/areas_1_0_1.png new file mode 100644 index 00000000..bddccad6 Binary files /dev/null and b/mods/areas/textures/areas_1_0_1.png differ diff --git a/mods/areas/textures/areas_1_1_0.png b/mods/areas/textures/areas_1_1_0.png new file mode 100644 index 00000000..6d19b24d Binary files /dev/null and b/mods/areas/textures/areas_1_1_0.png differ diff --git a/mods/areas/textures/areas_1_1_1.png b/mods/areas/textures/areas_1_1_1.png new file mode 100644 index 00000000..4d2cd1b3 Binary files /dev/null and b/mods/areas/textures/areas_1_1_1.png differ