forked from your-land-mirror/yl_speak_up
make + button and New dialog option in dialog select dropdown work
This commit is contained in:
parent
20f3b3c831
commit
c34ef26c04
@ -1018,6 +1018,7 @@ local function get_fs_talkdialog(player, n_id, d_id)
|
||||
-- display the window with the text the NPC is saying
|
||||
-- TODO: make name and description likewise editable?
|
||||
-- TODO: make name of dialog and sort option editable?
|
||||
-- TODO: show who owns the npc/is responsible for its talks?
|
||||
if(edit_mode) then
|
||||
|
||||
-- TODO: sort by name?
|
||||
@ -1681,13 +1682,14 @@ minetest.register_on_player_receive_fields(
|
||||
|
||||
-- helper function
|
||||
yl_speak_up.add_new_dialog = function(dialog, pname)
|
||||
future_d_id = "d_" .. find_next_id(dialog.n_dialogs)
|
||||
next_id = find_next_id(dialog.n_dialogs)
|
||||
future_d_id = "d_" .. next_id
|
||||
-- Initialize empty dialog
|
||||
dialog.n_dialogs[future_d_id] = {
|
||||
d_id = future_d_id,
|
||||
d_type = "text",
|
||||
d_text = "",
|
||||
d_sort = -1 -- TODO
|
||||
d_sort = next_id
|
||||
}
|
||||
-- store that there have been changes to this npc
|
||||
table.insert(yl_speak_up.npc_was_changed[ yl_speak_up.edit_mode[pname] ],
|
||||
@ -1752,10 +1754,7 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
||||
end
|
||||
|
||||
-- changes to options are not possible if there are none
|
||||
-- TODO: handle adding of a new dialog
|
||||
if(not(dialog.n_dialogs[ d_id ].d_options)) then
|
||||
return
|
||||
end
|
||||
if(dialog.n_dialogs[ d_id ].d_options) then
|
||||
|
||||
-- detect changes to text_option_<o_id>: text for option <o_id>
|
||||
for k, v in pairs(dialog.n_dialogs[ d_id ].d_options) do
|
||||
@ -1804,17 +1803,18 @@ yl_speak_up.edit_mode_apply_changes = function(pname, fields)
|
||||
r_value = fields[ "d_id_"..k ]}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- add a new dialog; either via "+" button or "New dialog" in dialog dropdown menu
|
||||
-- this has to be done after all the other changes because those (text changes etc.) still
|
||||
-- apply to the *old* dialog
|
||||
if(fields.show_new_dialog
|
||||
or(fields.d_id and fields.d_id == yl_speak_up.text_new_dialog_id)) then
|
||||
-- create the new dialog
|
||||
d_id = yl_speak_up.add_new_dialog(dialog, pname)
|
||||
or(fields["d_id"] and fields["d_id"] == yl_speak_up.text_new_dialog_id)) then
|
||||
-- create the new dialog and make sure it gets shown
|
||||
local d_id = yl_speak_up.add_new_dialog(dialog, pname)
|
||||
-- actually show the new dialog
|
||||
fields.d_id = d_id
|
||||
fields.show_new_dialog = nil
|
||||
fields["d_id"] = d_id
|
||||
fields["show_new_dialog"] = nil
|
||||
end
|
||||
|
||||
-- TODO just for debugging
|
||||
@ -1930,11 +1930,9 @@ minetest.register_on_player_receive_fields(
|
||||
if ( o == "" and edit_mode) then
|
||||
-- if nothing better can be found: keep the old dialog
|
||||
local show_dialog = d_id
|
||||
-- "New dialog" button or option from dropdown menu was selected
|
||||
if(fields.show_new_dialog or (fields.d_id and fields.d_id == yl_speak_up.text_new_option_id)) then
|
||||
-- TODO
|
||||
-- dropdown menu was used; provided the dialog exists (and it's not the "New dialog" option)
|
||||
elseif(fields.d_id and fields.d_id ~= show_dialog and dialog.n_dialogs[fields.d_id]) then
|
||||
-- (if a new dialog was added using the "+" button, fields.d_id gets set accordingly)
|
||||
if(fields.d_id and fields.d_id ~= show_dialog and dialog.n_dialogs[fields.d_id]) then
|
||||
show_dialog = fields.d_id
|
||||
-- in edit mode: prev_dialog_../next_dialog_.. was selected
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user