Improve teleport error feedback in GUI

master
rubenwardy 2019-01-14 21:09:32 +00:00
parent fea17dc317
commit f2d08c8ba7
2 changed files with 27 additions and 23 deletions

View File

@ -272,15 +272,12 @@ function land.can_teleport_to(area, pname)
local comp = company.get_active(pname)
local owner = comp and comp.name or pname
if area.owner ~= owner and not area.land_open then
return false, "Attempted to teleport to land (" ..
area.name .. " [" .. dump(area.id) .. "]), which is not " ..
"open and is owned by someone else (owner=" .. area.owner ..
", teleporter=" .. owner .. ")"
return false, "Not open and is owned by someone else (owner=" ..
area.owner .. ")"
end
if not area.spawn_point then
return false, "No spawn point for area: " ..
area.name .. " [" .. dump(area.id) .. "]"
return false, "No spawn point"
end
return true

View File

@ -233,7 +233,12 @@ sfinv.register_page("land:land", {
context.list = list
if not context.selected and #list > 0 then
context.selected = 1
for i=1, #list do
if list[i].owner == owner then
context.selected = i
break
end
end
elseif context.selected and context.selected > #list then
context.selected = #list
end
@ -272,25 +277,26 @@ sfinv.register_page("land:land", {
fs[#fs + 1] = "container[0,-0.2]"
if context.selected then
-- local area = list[context.selected]
fs[#fs + 1] = "button[6,0;2,1;teleport;Teleport]"
fs[#fs + 1] = "box[6,1;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,2;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,3;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,4;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,5;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,6;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,7;1.8,0.8;#222]"
local area = list[context.selected]
local suc, msg = land.can_teleport_to(area, pname)
if suc then
fs[#fs + 1] = "button[6,0;2,1;teleport;Teleport]"
else
fs[#fs + 1] = "textarea[6.3,0;2,1;;;"
fs[#fs + 1] = minetest.formspec_escape(msg)
fs[#fs + 1] = "]"
fs[#fs + 1] = "box[6,0;1.8,0.8;#222]"
end
else
fs[#fs + 1] = "box[6,0;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,1;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,2;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,3;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,4;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,5;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,6;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,7;1.8,0.8;#222]"
end
fs[#fs + 1] = "box[6,1;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,2;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,3;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,4;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,5;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,6;1.8,0.8;#222]"
fs[#fs + 1] = "box[6,7;1.8,0.8;#222]"
fs[#fs + 1] = "container_end[]"
return sfinv.make_formspec(player, context,
@ -306,6 +312,7 @@ sfinv.register_page("land:land", {
if fields.list_areas then
local evt = minetest.explode_table_event(fields.list_areas)
context.selected = evt.row
sfinv.set_page_and_show(player, "land:land")
return true
end