HUD supports areas mod
This commit is contained in:
parent
9ebb7bc788
commit
d467d8cd61
@ -1,2 +1,3 @@
|
||||
towny
|
||||
towny_nations?
|
||||
areas?
|
||||
|
@ -4,23 +4,16 @@
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
-- This code is borrowed from [areas] by ShadowNinja
|
||||
-- TODO: Support areas (areas:getExternalHudEntries)
|
||||
|
||||
towny.hud = {}
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
local pos = vector.round(player:getpos())
|
||||
local areaStrings = {}
|
||||
|
||||
local function towns_at_pos(pos, areas)
|
||||
if not areas then areas = {} end
|
||||
local t,p,c = towny.regions.get_town_at(pos)
|
||||
|
||||
if t then
|
||||
if towny.nations then
|
||||
local n = towny.nations.get_town_nation(t)
|
||||
if n then
|
||||
table.insert(areaStrings, towny.nations.get_full_name(n))
|
||||
table.insert(areas, { name = towny.nations.get_full_name(n) })
|
||||
end
|
||||
end
|
||||
|
||||
@ -30,7 +23,7 @@ minetest.register_globalstep(function(dtime)
|
||||
if tdata.flags.greeting then
|
||||
greeting = "- "..tdata.flags.greeting
|
||||
end
|
||||
table.insert(areaStrings, ("%s %s"):format(town, greeting))
|
||||
table.insert(areas, { name = ("%s %s"):format(town, greeting) })
|
||||
|
||||
if p then
|
||||
local plot = tdata.plots[p]
|
||||
@ -40,6 +33,11 @@ minetest.register_globalstep(function(dtime)
|
||||
greeting = ("%s (%s)"):format(plot.flags['greeting'], plot.owner)
|
||||
end
|
||||
|
||||
-- Override unowned plot greeting
|
||||
if not plot.owner then
|
||||
greeting = "Unowned Plot"
|
||||
end
|
||||
|
||||
if plot.flags['claimable'] then
|
||||
if plot.flags['cost'] and plot.flags['cost'] > 0 then
|
||||
-- TODO: economy
|
||||
@ -47,10 +45,27 @@ minetest.register_globalstep(function(dtime)
|
||||
greeting = greeting .. " (For sale: FREE!)"
|
||||
end
|
||||
|
||||
table.insert(areaStrings, ("%s - %s"):format(town, greeting))
|
||||
table.insert(areas, { name = ("%s - %s"):format(town, greeting) })
|
||||
end
|
||||
end
|
||||
|
||||
return areas
|
||||
end
|
||||
|
||||
if minetest.get_modpath("areas") ~= nil then
|
||||
areas:registerHudHandler(towns_at_pos)
|
||||
else
|
||||
towny.hud = {}
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
local pos = vector.round(player:getpos())
|
||||
local areaStrings = {}
|
||||
|
||||
for i,town in pairs(towns_at_pos(pos)) do
|
||||
table.insert(areaStrings, town.name)
|
||||
end
|
||||
|
||||
local areaString = "Towns:"
|
||||
if #areaStrings > 0 then
|
||||
areaString = areaString.."\n"..
|
||||
@ -77,8 +92,9 @@ minetest.register_globalstep(function(dtime)
|
||||
hud.oldAreas = areaString
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
towny.hud[player:get_player_name()] = nil
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
name = towny_hud
|
||||
description = Heads Up Display information for towns
|
||||
depends = towny
|
||||
optional_depends = towny_nations
|
||||
optional_depends = towny_nations,areas
|
||||
|
Loading…
Reference in New Issue
Block a user