From 846009470a875516292efa1c003425024c6275a1 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Tue, 4 May 2021 16:14:16 +0200 Subject: [PATCH] moved hide/grey out/alternate text and alternate text to yl_speak_up.edit_mode_apply_changes as well --- functions.lua | 122 +++++++++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 65 deletions(-) diff --git a/functions.lua b/functions.lua index d3c0868..55e8d09 100644 --- a/functions.lua +++ b/functions.lua @@ -864,8 +864,6 @@ local function get_fs_optiondialog(player, n_id, d_id, o_id, p_id, r_id) end --- TODO: actually add functionality for this formspec --- -- edit options (not via staff but via the "I am your owner" dialog) local function get_fs_edit_option_dialog(player, n_id, d_id, o_id) -- n_id, d_id and o_id have already been checked when this function is called @@ -940,9 +938,9 @@ local function get_fs_edit_option_dialog(player, n_id, d_id, o_id) -- offer the correct preselection for hidden/grey/show text local alternate_answer_option = "3" - if(d_option.o_hide_when_prerequisites_not_met) then + if(d_option.o_hide_when_prerequisites_not_met == "true") then alternate_answer_option = "1" - elseif(d_option.o_grey_when_prerequisites_not_met) then + elseif(d_option.o_grey_when_prerequisites_not_met == "true") then alternate_answer_option = "2" end @@ -2128,6 +2126,59 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields) fields["show_new_dialog"] = nil end + -- not in options edit menu? + local o_id = fields.o_id + if(not(o_id)) then + return result + end + + local d_option = dialog.n_dialogs[ d_id ].d_options[ o_id ] + -- change alternate text when preconditions are not met + -- (only happens in options edit menu) + 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(o_id).. + " 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 + -- (only happens in options edit menu) + 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(o_id).. + " is not met, hide option/answer.") + -- make sure we show this options update next + result["show_next_option"] = o_id + 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(o_id).. + " is not met, grey out option/answer.") + result["show_next_option"] = o_id + 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(o_id).. + " is not met, show alternate option/answer.") + result["show_next_option"] = o_id + end + end + -- currently only contains result["show_new_option"] (which is needed for options edit menu) return result end @@ -2154,7 +2205,7 @@ minetest.register_on_player_receive_fields( -- Is the player working on this particular npc? local edit_mode = (yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id) - if(not(edit_mode)) then + if(not(edit_mode) or not(fields.o_id)) then return end local n_id = yl_speak_up.speak_to[pname].n_id @@ -2172,71 +2223,12 @@ 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?) + -- TODO: allow change of o_sort, make button delete work, (add button save?) -- handles changes to o_text_when_prerequisites_met, target dialog, adding of a new dialog local result = yl_speak_up.edit_mode_apply_changes(pname, fields) -- if a new option was added or the target dialog of this one changed, display the right new option if(result and result["show_next_option"]) then - print("SHOWING "..tostring(result["show_next_option"])) -- TODO minetest.show_formspec(pname, "yl_speak_up:edit_option_dialog", get_fs_edit_option_dialog(player, n_id, d_id, result["show_next_option"])) return end