Skip to content

Commit

Permalink
omit private pads from lists
Browse files Browse the repository at this point in the history
  • Loading branch information
entuland committed Jun 27, 2018
1 parent ae58338 commit b4eac3b
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ end

function submit.teleport(form)
local selected_index = form.state:get("pads_listbox"):getSelected()
local pad = tpad.get_pad_by_index(form.ownername, selected_index)
local pad = tpad.get_pad_by_index(form.ownername, selected_index, form.is_global, form.omit_private_pads)
if not pad then
notify.err(form.playername, "Error! Missing pad data!")
return
Expand All @@ -236,7 +236,7 @@ end
function submit.delete(form)
minetest.after(0, function()
local pads_listbox = form.state:get("pads_listbox")
local delete_pad = tpad.get_pad_by_index(form.ownername, pads_listbox:getSelected())
local delete_pad = tpad.get_pad_by_index(form.ownername, pads_listbox:getSelected(), form.is_global, form.omit_private_pads)

if not delete_pad then
notify.warn(form.playername, "Please select a pad first")
Expand Down Expand Up @@ -293,9 +293,10 @@ function tpad.on_rightclick(clicked_pos, node, clicker)
form.ownername = ownername
form.clicked_pos = clicked_pos
form.node = node
form.omit_private_pads = false
form.is_global = false

last_clicked_pos[playername] = clicked_pos;

if ownername == playername or minetest.get_player_privs(playername).tpad_admin then
form.formname = "tpad.forms.main_owner"
form.state = tpad.forms.main_owner:show(playername)
Expand All @@ -310,12 +311,13 @@ function tpad.on_rightclick(clicked_pos, node, clicker)
notify.warn(playername, "This pad is private")
return
else
form.omit_private_pads = true
form.formname = "tpad.forms.main_visitor"
form.state = tpad.forms.main_visitor:show(playername)
form.state:get("visitor_label"):setText("Pad \"" .. pad.name .. "\", owned by " .. ownername)
end

local padlist = tpad.get_padlist(ownername)
local padlist = tpad.get_padlist(ownername, form.is_global, form.omit_private_pads)
local last_index = last_selected_index[playername .. ":" .. ownername]

local pads_listbox = form.state:get("pads_listbox")
Expand Down Expand Up @@ -417,25 +419,28 @@ local function decorate_pad_data(pos, pad, ownername)
end

-- prepare the list of pads to be shown in the main dialog
function tpad.get_padlist(ownername, isglobal)
function tpad.get_padlist(ownername, is_global, omit_private_pads)
local pads = tpad._get_stored_pads(ownername)
local result = {}
for strpos, pad in pairs(pads) do
pad = decorate_pad_data(strpos, pad, ownername)
if isglobal then
table.insert(result, pad.global_fullname)
else
table.insert(result, pad.local_fullname)
local skip = omit_private_pads and pad.type == PRIVATE_PAD
if not skip then
if is_global then
table.insert(result, pad.global_fullname)
else
table.insert(result, pad.local_fullname)
end
end
end
table.sort(result)
return result
end

-- used by the main dialog to pair up chosen pad with stored pads
function tpad.get_pad_by_index(ownername, index, isglobal)
function tpad.get_pad_by_index(ownername, index, is_global, omit_private_pads)
local pads = tpad._get_stored_pads(ownername)
local padlist = tpad.get_padlist(ownername, isglobal)
local padlist = tpad.get_padlist(ownername, is_global, omit_private_pads)
local chosen = padlist[index]
if not chosen then return end
for strpos, pad in pairs(pads) do
Expand Down

0 comments on commit b4eac3b

Please sign in to comment.