let yl_speak_up.edit_mode_apply_changes handle all changes done by either dialog or option edit menu
This commit is contained in:
parent
a0c3a4c890
commit
dd1dee0fdc
@ -992,7 +992,7 @@ local function get_fs_edit_option_dialog(player, n_id, d_id, o_id)
|
|||||||
-- answer of the player (the actual option)
|
-- answer of the player (the actual option)
|
||||||
"label[0.2,6.8;..the player may answer with this text:]"..
|
"label[0.2,6.8;..the player may answer with this text:]"..
|
||||||
"label[1.2,7.6;A:]"..
|
"label[1.2,7.6;A:]"..
|
||||||
"field[1.7,7.1;19.1,0.9;option_text_met;;"..
|
"field[1.7,7.1;19.1,0.9;text_option_"..minetest.formspec_escape(o_id)..";;"..
|
||||||
minetest.formspec_escape(d_option.o_text_when_prerequisites_met).."]"..
|
minetest.formspec_escape(d_option.o_text_when_prerequisites_met).."]"..
|
||||||
"tooltip[option_text_met;This is the answer the player may choose if the "..
|
"tooltip[option_text_met;This is the answer the player may choose if the "..
|
||||||
"preconditions are all fulfilled.]"..
|
"preconditions are all fulfilled.]"..
|
||||||
@ -1022,7 +1022,8 @@ local function get_fs_edit_option_dialog(player, n_id, d_id, o_id)
|
|||||||
"tooltip[1.2,14.2;19.6,2.5;This is what the NPC will say next when the player has "..
|
"tooltip[1.2,14.2;19.6,2.5;This is what the NPC will say next when the player has "..
|
||||||
"selected this answer here.]"..
|
"selected this answer here.]"..
|
||||||
-- allow to change the target dialog via a dropdown menu
|
-- allow to change the target dialog via a dropdown menu
|
||||||
"dropdown[14.8,13.2;5,0.9;target_dialog;"..dialog_list..";"..dialog_selected..",]"..
|
"dropdown[14.8,13.2;5,0.9;d_id_"..minetest.formspec_escape(o_id)..";"..
|
||||||
|
dialog_list..";"..dialog_selected..",]"..
|
||||||
"tooltip[14.8,13.2;5,0.9;Select the target dialog with which the NPC shall react "..
|
"tooltip[14.8,13.2;5,0.9;Select the target dialog with which the NPC shall react "..
|
||||||
"to this answer. Currently, dialog "..minetest.formspec_escape(target_dialog)..
|
"to this answer. Currently, dialog "..minetest.formspec_escape(target_dialog)..
|
||||||
" is beeing displayed.;#FFFFFF;#000000]"..
|
" is beeing displayed.;#FFFFFF;#000000]"..
|
||||||
@ -1030,7 +1031,7 @@ local function get_fs_edit_option_dialog(player, n_id, d_id, o_id)
|
|||||||
"button[0.2,17;2.0,0.9;edit_option_delete;Delete]"..
|
"button[0.2,17;2.0,0.9;edit_option_delete;Delete]"..
|
||||||
"tooltip[edit_option_delete;Delete this option/answer.]"..
|
"tooltip[edit_option_delete;Delete this option/answer.]"..
|
||||||
-- button: add new
|
-- button: add new
|
||||||
"button[2.4,17;2.0,0.9;edit_option_add;Add]"..
|
"button[2.4,17;2.0,0.9;add_option;Add]"..
|
||||||
"tooltip[edit_option_add;Add a new option/answer to this dialog.]"..
|
"tooltip[edit_option_add;Add a new option/answer to this dialog.]"..
|
||||||
-- button: prev/next
|
-- button: prev/next
|
||||||
button_prev..
|
button_prev..
|
||||||
@ -1980,12 +1981,16 @@ yl_speak_up.save_changes_and_switch_to_other_dialog = function(player, fields, t
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- helper function for formspec "yl_speak_up:talk" when a parameter was changed in edit mode;
|
-- helper function for formspec "yl_speak_up:talk" *and* formspec "yl_speak_up:edit_option_dialog"
|
||||||
|
-- when a parameter was changed in edit mode;
|
||||||
-- this is called when the player is in edit_mode (editing the NPC);
|
-- this is called when the player is in edit_mode (editing the NPC);
|
||||||
-- the function checks if the player has changed any parameters
|
-- the function checks if the player has changed any parameters
|
||||||
-- Parameters:
|
-- Parameters:
|
||||||
-- pname player name
|
-- pname player name
|
||||||
-- fields the fields returned from the formspec
|
-- fields the fields returned from the formspec
|
||||||
|
-- Returns:
|
||||||
|
-- result table with information about what was added
|
||||||
|
-- (for now, only result.show_next_option is of intrest in the option edit menu)
|
||||||
yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
||||||
local n_id = yl_speak_up.edit_mode[pname]
|
local n_id = yl_speak_up.edit_mode[pname]
|
||||||
local d_id = yl_speak_up.speak_to[pname].d_id
|
local d_id = yl_speak_up.speak_to[pname].d_id
|
||||||
@ -2002,7 +2007,11 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- new options etc. may be added; store these IDs so that we can switch to the right target
|
||||||
|
local result = {}
|
||||||
|
|
||||||
-- detect changes to d_text: text of the dialog (what the npc is saying)
|
-- detect changes to d_text: text of the dialog (what the npc is saying)
|
||||||
|
-- (only happens in dialog edit menu)
|
||||||
if(fields.d_text and dialog.n_dialogs[ d_id ].d_text ~= fields.d_text) then
|
if(fields.d_text and dialog.n_dialogs[ d_id ].d_text ~= fields.d_text) then
|
||||||
-- store that there have been changes to this npc
|
-- store that there have been changes to this npc
|
||||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||||
@ -2034,6 +2043,8 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
|||||||
dialog.n_dialogs[d_id].d_options[future_o_id].o_sort = s
|
dialog.n_dialogs[d_id].d_options[future_o_id].o_sort = s
|
||||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||||
"Dialog "..d_id..": Added new option/answer "..future_o_id..".")
|
"Dialog "..d_id..": Added new option/answer "..future_o_id..".")
|
||||||
|
-- if this is selected in the options edit menu, we want to move straight on to the new option
|
||||||
|
result["show_next_option"] = future_o_id
|
||||||
end
|
end
|
||||||
|
|
||||||
-- changes to options are not possible if there are none
|
-- changes to options are not possible if there are none
|
||||||
@ -2072,9 +2083,11 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
|||||||
" to "..tostring(fields[ "d_id_"..k])..".")
|
" to "..tostring(fields[ "d_id_"..k])..".")
|
||||||
-- actually change the target dialog
|
-- actually change the target dialog
|
||||||
vr.r_value = fields[ "d_id_"..k ]
|
vr.r_value = fields[ "d_id_"..k ]
|
||||||
|
-- in options edit menu: show this update
|
||||||
|
result["show_next_option"] = k
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- this might be the first option
|
-- this might be the first result
|
||||||
elseif( fields["d_id_"..k ]) then
|
elseif( fields["d_id_"..k ]) then
|
||||||
-- this may also point to a new dialog
|
-- this may also point to a new dialog
|
||||||
if(fields[ "d_id_"..k ] == yl_speak_up.text_new_dialog_id) then
|
if(fields[ "d_id_"..k ] == yl_speak_up.text_new_dialog_id) then
|
||||||
@ -2083,7 +2096,9 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
|||||||
end
|
end
|
||||||
-- store that a new option has been added to this dialog
|
-- store that a new option has been added to this dialog
|
||||||
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
table.insert(yl_speak_up.npc_was_changed[ n_id ],
|
||||||
"Dialog "..d_id..": The target dialog for option "..tostring(k).." was changed from -default- to "..tostring(fields[ "d_id_"..k])..".")
|
"Dialog "..d_id..": The target dialog for option "..
|
||||||
|
tostring(k).." was changed from -default- to "..
|
||||||
|
tostring(fields[ "d_id_"..k])..".")
|
||||||
|
|
||||||
-- create a new result (first the id, then the actual result)
|
-- create a new result (first the id, then the actual result)
|
||||||
local future_r_id = "r_" .. find_next_id(dialog.n_dialogs[d_id].d_options[k].o_results)
|
local future_r_id = "r_" .. find_next_id(dialog.n_dialogs[d_id].d_options[k].o_results)
|
||||||
@ -2095,6 +2110,8 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
|||||||
r_id = future_r_id,
|
r_id = future_r_id,
|
||||||
r_type = "dialog",
|
r_type = "dialog",
|
||||||
r_value = fields[ "d_id_"..k ]}
|
r_value = fields[ "d_id_"..k ]}
|
||||||
|
-- in options edit menu: show this update
|
||||||
|
result["show_next_option"] = k
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2110,6 +2127,9 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
|||||||
fields["d_id"] = d_id
|
fields["d_id"] = d_id
|
||||||
fields["show_new_dialog"] = nil
|
fields["show_new_dialog"] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- currently only contains result["show_new_option"] (which is needed for options edit menu)
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
-- end of yl_speak_up.edit_mode_apply_changes
|
-- end of yl_speak_up.edit_mode_apply_changes
|
||||||
|
|
||||||
@ -2157,6 +2177,7 @@ minetest.register_on_player_receive_fields(
|
|||||||
yl_speak_up.npc_was_changed[ n_id ] = {}
|
yl_speak_up.npc_was_changed[ n_id ] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
-- change text when preconditions are met
|
-- change text when preconditions are met
|
||||||
if(fields.option_text_met and d_option
|
if(fields.option_text_met and d_option
|
||||||
and d_option.o_text_when_prerequisites_met ~= fields.option_text_met) then
|
and d_option.o_text_when_prerequisites_met ~= fields.option_text_met) then
|
||||||
@ -2168,6 +2189,7 @@ minetest.register_on_player_receive_fields(
|
|||||||
-- actually change the text of the option
|
-- actually change the text of the option
|
||||||
d_option.o_text_when_prerequisites_met = fields.option_text_met
|
d_option.o_text_when_prerequisites_met = fields.option_text_met
|
||||||
end
|
end
|
||||||
|
--]]
|
||||||
|
|
||||||
-- change alternate text when preconditions are not met
|
-- change alternate text when preconditions are not met
|
||||||
if(fields.option_text_not_met and d_option
|
if(fields.option_text_not_met and d_option
|
||||||
@ -2209,7 +2231,15 @@ minetest.register_on_player_receive_fields(
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- TODO: change of o_sort, change of target_dialog, button delete, buton add, (button save?)
|
-- TODO: change of o_sort, change of target_dialog, button delete, buton add, (button save?)
|
||||||
--yl_speak_up.edit_mode_apply_changes(pname, fields)
|
|
||||||
|
-- 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
|
||||||
|
|
||||||
-- back to the main dialog window?
|
-- back to the main dialog window?
|
||||||
if(fields.show_current_dialog or fields.quit or fields.button_exit or not(d_option)) then
|
if(fields.show_current_dialog or fields.quit or fields.button_exit or not(d_option)) then
|
||||||
|
Loading…
Reference in New Issue
Block a user