forked from Sokomine/yl_speak_up
ask for save when selecting edit options dialog
This commit is contained in:
parent
4ab2ee03f1
commit
6ad92fb198
@ -1725,20 +1725,23 @@ end
|
||||
-- this is always called when switching to a new dialog; but only in edit_mode does
|
||||
-- it show a formspec asking for change/back/discard
|
||||
yl_speak_up.save_changes_and_switch_to_other_dialog = function(player, fields, target_dialog)
|
||||
|
||||
if(not(target_dialog)) then
|
||||
target_dialog = ""
|
||||
end
|
||||
|
||||
local pname = player:get_player_name()
|
||||
-- if the player is not even talking to this particular npc
|
||||
if(not(yl_speak_up.speak_to[pname])) then
|
||||
return
|
||||
end
|
||||
|
||||
if(not(target_dialog)) then
|
||||
target_dialog = yl_speak_up.speak_to[pname].target_dialog
|
||||
if(not(target_dialog)) then
|
||||
target_dialog = ""
|
||||
end
|
||||
end
|
||||
|
||||
local edit_mode = (yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id)
|
||||
local d_id = yl_speak_up.speak_to[pname].d_id
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
local o_id = yl_speak_up.speak_to[pname].o_id
|
||||
|
||||
-- the player decided to go back and continue editing the current dialog
|
||||
if(edit_mode and fields.back_to_dialog_changes) then
|
||||
@ -1798,8 +1801,14 @@ yl_speak_up.save_changes_and_switch_to_other_dialog = function(player, fields, t
|
||||
local target_name = "quit"
|
||||
if(target_dialog and target_dialog ~= "") then
|
||||
target_name = "go on to dialog "..minetest.formspec_escape(target_dialog)
|
||||
if(target_dialog == "edit_option_dialog") then
|
||||
target_name = "edit option \""..
|
||||
minetest.formspec_escape(tostring(o_id)).."\" of dialog \""..
|
||||
minetest.formspec_escape(tostring(d_id)).."\""
|
||||
end
|
||||
end
|
||||
|
||||
yl_speak_up.speak_to[pname].target_dialog = target_dialog
|
||||
local d_id = yl_speak_up.speak_to[pname].d_id
|
||||
-- reverse the order of the changes in the log so that newest are topmost
|
||||
local text = ""
|
||||
@ -1823,10 +1832,7 @@ yl_speak_up.save_changes_and_switch_to_other_dialog = function(player, fields, t
|
||||
"tooltip[save_dialog_changes;Save all changes to this dialog and "..target_name..".]"..
|
||||
"tooltip[discard_dialog_changes;Undo all changes and "..target_name..".]"..
|
||||
"tooltip[back_to_dialog_changes;Go back to dialog "..
|
||||
minetest.formspec_escape(d_id).." and continue editing it.]"..
|
||||
|
||||
-- hidden field telling about the target dialog
|
||||
"field[20,20;0.1,0.1;goto_target_dialog;target_dialog;"..minetest.formspec_escape(target_dialog).."]"
|
||||
minetest.formspec_escape(d_id).." and continue editing it.]"
|
||||
-- actaully show the formspec to the player
|
||||
yl_speak_up.show_fs(player, "msg", {input_to = "yl_speak_up:confirm_save",
|
||||
formspec = formspec})
|
||||
@ -1847,9 +1853,17 @@ yl_speak_up.save_changes_and_switch_to_other_dialog = function(player, fields, t
|
||||
|
||||
-- the trade list is not really a dialog...
|
||||
if(target_dialog == "trade_list") then
|
||||
yl_speak_up.speak_to[pname].target_dialog = nil
|
||||
yl_speak_up.show_fs(player, "trade_list")
|
||||
return
|
||||
-- edit an option
|
||||
elseif(target_dialog == "edit_option_dialog" and o_id and d_id) then
|
||||
yl_speak_up.speak_to[pname].target_dialog = nil
|
||||
yl_speak_up.show_fs(player, "edit_option_dialog",
|
||||
{n_id = n_id, d_id = d_id, o_id = o_id, caller= "confirm_save"})
|
||||
return
|
||||
end
|
||||
yl_speak_up.speak_to[pname].target_dialog = nil
|
||||
-- move on to the target dialog
|
||||
yl_speak_up.speak_to[pname].d_id = target_dialog
|
||||
yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = target_dialog})
|
||||
@ -2480,9 +2494,11 @@ yl_speak_up.input_talk = function(player, formname, fields)
|
||||
if( fields["edit_option_"..o_id]
|
||||
or fields["conditions_"..o_id]
|
||||
or fields["effects_"..o_id]) then
|
||||
yl_speak_up.show_fs(player, "edit_option_dialog",
|
||||
{n_id = yl_speak_up.speak_to[pname].n_id,
|
||||
d_id = d_id, o_id = o_id, caller="button"})
|
||||
-- store which option we want to edit
|
||||
yl_speak_up.speak_to[pname].o_id = o_id
|
||||
-- if something was changed: ask for confirmation
|
||||
yl_speak_up.save_changes_and_switch_to_other_dialog(
|
||||
player, fields, "edit_option_dialog")
|
||||
return
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user