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
|
-- display the window with the text the NPC is saying
|
||||||
-- TODO: make name and description likewise editable?
|
-- TODO: make name and description likewise editable?
|
||||||
-- TODO: make name of dialog and sort option 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
|
if(edit_mode) then
|
||||||
|
|
||||||
-- TODO: sort by name?
|
-- TODO: sort by name?
|
||||||
@ -1681,13 +1682,14 @@ minetest.register_on_player_receive_fields(
|
|||||||
|
|
||||||
-- helper function
|
-- helper function
|
||||||
yl_speak_up.add_new_dialog = function(dialog, pname)
|
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
|
-- Initialize empty dialog
|
||||||
dialog.n_dialogs[future_d_id] = {
|
dialog.n_dialogs[future_d_id] = {
|
||||||
d_id = future_d_id,
|
d_id = future_d_id,
|
||||||
d_type = "text",
|
d_type = "text",
|
||||||
d_text = "",
|
d_text = "",
|
||||||
d_sort = -1 -- TODO
|
d_sort = next_id
|
||||||
}
|
}
|
||||||
-- 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[ yl_speak_up.edit_mode[pname] ],
|
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
|
end
|
||||||
|
|
||||||
-- changes to options are not possible if there are none
|
-- changes to options are not possible if there are none
|
||||||
-- TODO: handle adding of a new dialog
|
if(dialog.n_dialogs[ d_id ].d_options) then
|
||||||
if(not(dialog.n_dialogs[ d_id ].d_options)) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- detect changes to text_option_<o_id>: text for option <o_id>
|
-- 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
|
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 ]}
|
r_value = fields[ "d_id_"..k ]}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- add a new dialog; either via "+" button or "New dialog" in dialog dropdown menu
|
-- 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
|
-- this has to be done after all the other changes because those (text changes etc.) still
|
||||||
-- apply to the *old* dialog
|
-- apply to the *old* dialog
|
||||||
if(fields.show_new_dialog
|
if(fields.show_new_dialog
|
||||||
or(fields.d_id and fields.d_id == yl_speak_up.text_new_dialog_id)) then
|
or(fields["d_id"] and fields["d_id"] == yl_speak_up.text_new_dialog_id)) then
|
||||||
-- create the new dialog
|
-- create the new dialog and make sure it gets shown
|
||||||
d_id = yl_speak_up.add_new_dialog(dialog, pname)
|
local d_id = yl_speak_up.add_new_dialog(dialog, pname)
|
||||||
-- actually show the new dialog
|
-- actually show the new dialog
|
||||||
fields.d_id = d_id
|
fields["d_id"] = d_id
|
||||||
fields.show_new_dialog = nil
|
fields["show_new_dialog"] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO just for debugging
|
-- TODO just for debugging
|
||||||
@ -1930,11 +1930,9 @@ minetest.register_on_player_receive_fields(
|
|||||||
if ( o == "" and edit_mode) then
|
if ( o == "" and edit_mode) then
|
||||||
-- if nothing better can be found: keep the old dialog
|
-- if nothing better can be found: keep the old dialog
|
||||||
local show_dialog = d_id
|
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)
|
-- 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
|
show_dialog = fields.d_id
|
||||||
-- in edit mode: prev_dialog_../next_dialog_.. was selected
|
-- in edit mode: prev_dialog_../next_dialog_.. was selected
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user