2023-03-31 18:47:36 +03:00
|
|
|
-- translation
|
2024-09-01 17:13:13 +03:00
|
|
|
local S = mail.S
|
2023-03-31 18:47:36 +03:00
|
|
|
|
2023-03-29 18:25:01 +03:00
|
|
|
local FORMNAME = "mail:editcontact"
|
|
|
|
|
|
|
|
function mail.show_edit_contact(name, contact_name, note, illegal_name_hint)
|
|
|
|
local formspec = [[
|
|
|
|
size[6,7]
|
2023-03-29 20:23:16 +03:00
|
|
|
button[4,6.25;2,0.5;back;]] .. S("Back") .. [[]
|
|
|
|
field[0.25,0.5;4,1;name;]] .. S("Player name") .. [[:;%s]
|
|
|
|
textarea[0.25,1.6;4,6.25;note;]] .. S("Note") .. [[:;%s]
|
|
|
|
button[4,0.10;2,1;save;]] .. S("Save") .. [[]
|
2023-03-29 18:25:01 +03:00
|
|
|
]]
|
|
|
|
if illegal_name_hint == "collision" then
|
|
|
|
formspec = formspec .. [[
|
2023-05-05 14:13:09 +03:00
|
|
|
textarea[4.25,1;2.5,6;;;]] ..
|
|
|
|
S("That name is already in your contacts") .. [[]
|
2023-03-29 18:25:01 +03:00
|
|
|
]]
|
|
|
|
elseif illegal_name_hint == "empty" then
|
|
|
|
formspec = formspec .. [[
|
2023-05-05 14:13:09 +03:00
|
|
|
textarea[4.25,1;2.5,6;;;]] ..
|
|
|
|
S("The contact name cannot be empty.") .. [[]
|
2023-03-29 18:25:01 +03:00
|
|
|
]]
|
|
|
|
end
|
|
|
|
formspec = formspec .. mail.theme
|
|
|
|
formspec = string.format(formspec,
|
|
|
|
minetest.formspec_escape(contact_name or ""),
|
|
|
|
minetest.formspec_escape(note or ""))
|
|
|
|
minetest.show_formspec(name, FORMNAME, formspec)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
|
|
if formname ~= FORMNAME then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local contacts = mail.get_contacts(name)
|
|
|
|
|
|
|
|
if fields.save then
|
2023-05-05 14:13:09 +03:00
|
|
|
if mail.selected_idxs.contacts[name] then
|
|
|
|
local contact = contacts[mail.selected_idxs.contacts[name]] or {name = ""}
|
|
|
|
if contact.name ~= fields.name or fields.name == "" then
|
2023-03-29 18:25:01 +03:00
|
|
|
-- name changed!
|
|
|
|
if #fields.name == 0 then
|
|
|
|
mail.show_edit_contact(name, contact.name, fields.note, "empty")
|
|
|
|
return true
|
|
|
|
|
2023-05-05 14:13:09 +03:00
|
|
|
elseif mail.get_contact(name, fields.name) then
|
2023-03-29 18:25:01 +03:00
|
|
|
mail.show_edit_contact(name, contact.name, fields.note, "collision")
|
|
|
|
return true
|
|
|
|
|
|
|
|
else
|
2023-05-05 14:13:09 +03:00
|
|
|
contact.name = fields.name
|
|
|
|
contact.note = fields.note
|
2023-03-29 18:25:01 +03:00
|
|
|
mail.update_contact(name, contact)
|
|
|
|
contacts[mail.selected_idxs.contacts[name]] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
contact.name = fields.name
|
|
|
|
contact.note = fields.note
|
|
|
|
mail.update_contact(name, contact)
|
|
|
|
|
|
|
|
else
|
|
|
|
mail.update_contact(name, {
|
|
|
|
name = fields.name,
|
|
|
|
note = fields.note,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
mail.show_contacts(name)
|
|
|
|
|
|
|
|
elseif fields.back then
|
|
|
|
mail.show_contacts(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
2023-03-29 20:23:16 +03:00
|
|
|
end)
|