save some changes in the options edit menu

This commit is contained in:
Sokomine 2021-05-04 12:59:05 +02:00
parent 319f05edc5
commit 0d7ae95ab6

View File

@ -2144,6 +2144,64 @@ minetest.register_on_player_receive_fields(
return
end
-- this way we can store the actual changes and present them to the player for saving
if(not(yl_speak_up.npc_was_changed[ n_id ])) then
yl_speak_up.npc_was_changed[ n_id ] = {}
end
-- change text when preconditions are met
if(fields.option_text_met and d_option
and d_option.o_text_when_prerequisites_met ~= fields.option_text_met) then
-- add change to changelog
table.insert(yl_speak_up.npc_was_changed[ yl_speak_up.edit_mode[pname] ],
"Dialog "..d_id..": The text for option "..tostring(k).." was changed from \""..
tostring(d_option.o_text_when_prerequisites_met).."\" to \""..
tostring(fields.option_text_met).."\".")
-- actually change the text of the option
d_option.o_text_when_prerequisites_met = fields.option_text_met
end
-- change alternate text when preconditions are not met
if(fields.option_text_not_met and d_option
and d_option.o_text_when_prerequisites_not_met ~= fields.option_text_not_met) then
-- add change to changelog
table.insert(yl_speak_up.npc_was_changed[ n_id ],
"Dialog "..d_id..": The alternate text for option "..tostring(k).." was changed from \""..
tostring(d_option.o_text_when_prerequisites_not_met).."\" to \""..
tostring(fields.option_text_not_met).."\".")
-- actually change the text of the option
d_option.o_text_when_prerequisites_not_met = fields.option_text_not_met
end
-- handle hide/grey out/show alternate answer
if(fields.hide_or_grey_or_alternate_answer and d_option) then
if(fields.hide_or_grey_or_alternate_answer == "..hide this answer."
and d_option.o_hide_when_prerequisites_not_met ~= "true") then
d_option.o_hide_when_prerequisites_not_met = "true"
d_option.o_grey_when_prerequisites_not_met = "false"
table.insert(yl_speak_up.npc_was_changed[ n_id ],
"Dialog "..d_id..": If precondition for option "..tostring(k)..
"is not met, hide option/answer.")
elseif(fields.hide_or_grey_or_alternate_answer == "..grey out this answer."
and d_option.o_grey_when_prerequisites_not_met ~= "true") then
d_option.o_hide_when_prerequisites_not_met = "false"
d_option.o_grey_when_prerequisites_not_met = "true"
table.insert(yl_speak_up.npc_was_changed[ n_id ],
"Dialog "..d_id..": If precondition for option "..tostring(k)..
"is not met, grey out option/answer.")
elseif(fields.hide_or_grey_or_alternate_answer == "..display the following alternate answer:"
and (d_option.o_hide_when_prerequisites_not_met ~= "false"
or d_option.o_grey_when_prerequisites_not_met) ~= "false") then
d_option.o_hide_when_prerequisites_not_met = "false"
d_option.o_grey_when_prerequisites_not_met = "false"
table.insert(yl_speak_up.npc_was_changed[ n_id ],
"Dialog "..d_id..": If precondition for option "..tostring(k)..
"is not met, show alternate option/answer.")
end
end
-- TODO: change of o_sort, change of target_dialog, button delete, buton add, (button save?)
-- back to the main dialog window?
if(fields.show_current_dialog or fields.quit or fields.button_exit or not(d_option)) then
minetest.show_formspec(pname, "yl_speak_up:talk", get_fs_talkdialog(player, n_id, d_id))