created yl_speak_up.delete_element_p_or_a_or_e
This commit is contained in:
parent
4d0e9ba116
commit
6e40dbc388
@ -144,6 +144,55 @@ yl_speak_up.eval_and_execute_function = function(player, x_v, id_prefix)
|
||||
end
|
||||
|
||||
|
||||
-- helper function for yl_speak_up.input_fs_edit_option_related
|
||||
yl_speak_up.delete_element_p_or_a_or_e = function(
|
||||
player, pname, n_id, d_id, o_id, x_id, id_prefix,
|
||||
element_list_name, element_desc, formspec_input_to)
|
||||
-- does the dialog we want to modify exist?
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
if(not(dialog and dialog.n_dialogs
|
||||
and x_id
|
||||
and dialog.n_dialogs[d_id]
|
||||
and dialog.n_dialogs[d_id].d_options
|
||||
and dialog.n_dialogs[d_id].d_options[o_id])) then
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = "size[9,2]"..
|
||||
"label[0.2,0.5;The dialog that is supposed to contain the\n"..
|
||||
"element that you want to delete does not exist.]"..
|
||||
"button[1.5,1.5;2,0.9;back_from_cannot_be_edited;Back]"})
|
||||
return
|
||||
end
|
||||
local old_elem = dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ][ x_id ]
|
||||
if(id_prefix == "r_" and old_elem and old_elem.r_type == "dialog") then
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = "size[9,2]"..
|
||||
"label[0.2,0.5;Effects of the type \"dialog\" cannot be deleted.\n"..
|
||||
"Use the edit options or dialog menu to change the target dialog.]"..
|
||||
"button[1.5,1.5;2,0.9;back_from_cannot_be_edited;Back]"})
|
||||
return
|
||||
end
|
||||
-- actually delete the element
|
||||
dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ][ x_id ] = nil
|
||||
-- record this as a change, but do not save do disk yet
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..tostring(d_id)..": "..element_desc.." "..tostring( x_id )..
|
||||
" deleted for option "..tostring(o_id)..".")
|
||||
-- TODO: when trying to save: save to disk as well?
|
||||
-- show the new/changed element
|
||||
-- go back to the edit option dialog (after all we just deleted the prerequirement)
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = "size[6,2]"..
|
||||
"label[0.2,0.5;"..element_desc.." \""..
|
||||
minetest.formspec_escape(tostring( x_id ))..
|
||||
"\" has been deleted.]"..
|
||||
"button[1.5,1.5;2,0.9;back_from_delete_element;Back]"})
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
-- These two functions
|
||||
-- * yl_speak_up.input_fs_edit_option_related and
|
||||
-- * yl_speak_up.get_fs_edit_option_related
|
||||
@ -180,42 +229,11 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
||||
return
|
||||
end
|
||||
|
||||
-- delete precondition
|
||||
-- delete precondition, action or effect
|
||||
if(fields.delete_element) then
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
if(dialog and dialog.n_dialogs
|
||||
and x_id
|
||||
and dialog.n_dialogs[d_id]
|
||||
and dialog.n_dialogs[d_id].d_options
|
||||
and dialog.n_dialogs[d_id].d_options[o_id]) then
|
||||
local old_elem = dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ][ x_id ]
|
||||
if(id_prefix == "r_" and old_elem.r_type == "dialog") then
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = "size[9,2]"..
|
||||
"label[0.2,0.5;Effects of the type \"dialog\" cannot be deleted.\n"..
|
||||
"Use the edit options or dialog menu to change the target dialog.]"..
|
||||
"button[1.5,1.5;2,0.9;back_from_cannot_be_edited;Back]"})
|
||||
return
|
||||
end
|
||||
-- actually delete the element
|
||||
dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ][ x_id ] = nil
|
||||
-- record this as a change, but do not save do disk yet
|
||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||
"Dialog "..tostring(d_id)..": "..element_desc.." "..tostring( x_id )..
|
||||
" deleted for option "..tostring(o_id)..".")
|
||||
-- TODO: when trying to save: save to disk as well?
|
||||
-- show the new/changed element
|
||||
-- go back to the edit option dialog (after all we just deleted the prerequirement)
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:"..formspec_input_to,
|
||||
formspec = "size[6,2]"..
|
||||
"label[0.2,0.5;"..element_desc.." \""..
|
||||
minetest.formspec_escape(tostring( x_id ))..
|
||||
"\" has been deleted.]"..
|
||||
"button[1.5,1.5;2,0.9;back_from_delete_element;Back]"})
|
||||
return
|
||||
end
|
||||
yl_speak_up.delete_element_p_or_a_or_e( player, pname, n_id, d_id, o_id, x_id, id_prefix,
|
||||
element_list_name, element_desc, formspec_input_to)
|
||||
return
|
||||
end
|
||||
|
||||
if(fields.select_block_pos) then
|
||||
|
Loading…
Reference in New Issue
Block a user