Skip to content
This repository has been archived by the owner on Aug 20, 2020. It is now read-only.

Commit

Permalink
rewrite areas hud. issue #194
Browse files Browse the repository at this point in the history
  • Loading branch information
Crabman77 committed Mar 8, 2016
1 parent 8f74c9f commit 6c84995
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 21 deletions.
73 changes: 52 additions & 21 deletions mods/areas/hud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added mods/areas/textures/areas_0_0_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/areas/textures/areas_0_0_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/areas/textures/areas_0_1_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/areas/textures/areas_0_1_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/areas/textures/areas_0_1_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/areas/textures/areas_1_0_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/areas/textures/areas_1_0_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/areas/textures/areas_1_1_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/areas/textures/areas_1_1_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6c84995

Please sign in to comment.