turn target dialog dropdown into buttons first

This commit is contained in:
Sokomine 2021-05-26 16:57:37 +02:00
parent f3082b7637
commit f7118f4343

View File

@ -1066,7 +1066,12 @@ end
-- talk
yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id)
-- show_dropdown_o_id: When set (and in edit mode):
-- Show a dropdown menu for o_id that allows to change the target dialog.
-- This two-step approach was introduced in order to avoid accidental
-- changes of the target dialog by scrolling with the mouse wheel
-- while at the wrong position.
yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, show_dropdown_o_id)
local pname = player:get_player_name()
local dialog = yl_speak_up.speak_to[pname].dialog
local context_d_id = yl_speak_up.speak_to[pname].d_id
@ -1316,10 +1321,24 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id)
-- selecting an option this way MUST NOT execute the pre(C)onditions or (Ef)fects!
end
if(not(show_dropdown_o_id) or show_dropdown_o_id ~= oid) then
table.insert(formspec, "button[3.9,"..h..";4.7,1;show_dropdown_o_id_"..oid..";"..
(target_dialog or "- none -").."]")
table.insert(formspec, "tooltip[show_dropdown_o_id_"..oid..";"..
"Click here to show a dropdown menu for changing\n"..
"the target dialog of option "..oid..".]")
else
-- allow to set a new target dialog
table.insert(formspec, "dropdown[3.9,"..h..";4.7,1;d_id_"..oid..";"..dialog_list..";"..minetest.formspec_escape(d_id_to_dropdown_index[target_dialog] or "0")..",]")
table.insert(formspec, "dropdown[3.9,"..h..";4.7,1;d_id_"..oid..";"..
dialog_list..";"..
minetest.formspec_escape(d_id_to_dropdown_index[target_dialog] or "0")..",]")
-- add a tooltip "Change target dialog"
table.insert(formspec, "tooltip[3.9,"..h..";4.7,1;Change target dialog for option "..oid..".;#FFFFFF;#000000]")
table.insert(formspec, "tooltip[3.9,"..h..";4.7,1;"..
"Change target dialog for option "..oid..".;#FFFFFF;#000000]")
table.insert(formspec, "field[80,80;0.1,0.1;keep_show_dropdown_o_id"..oid..";"..
oid..";"..oid.."]")
end
-- are there any prerequirements?
local prereq = active_dialog.d_options[sb_v.o_id].o_prerequisites
@ -2992,6 +3011,7 @@ yl_speak_up.input_talk = function(player, formname, fields)
-- all three buttons (pre(C)onditions, (Ef)fects, edit option) lead to the same new formspec
local show_dropdown_o_id = nil
if( edit_mode ) then
local n_dialog = dialog.n_dialogs[d_id]
@ -3005,9 +3025,17 @@ yl_speak_up.input_talk = function(player, formname, fields)
player, yl_speak_up.speak_to[pname].n_id, d_id, o_id))
return
end
-- show a dropdown menu for changing the target dialog *only* for this
-- option in order to avoid accidental, unnoticed changes
if( fields["show_dropdown_o_id_"..o_id]) then
show_dropdown_o_id = o_id
end
end
end
end
-- if no new o_id for editing the dropdown menu has been selected: keep the old one
if(not(show_dropdown_o_id) and fields.keep_show_dropdown_o_id) then
show_dropdown_o_id = fields.keep_show_dropdown_o_id
end
-- in edit mode: another dialog was selected
@ -3034,7 +3062,7 @@ yl_speak_up.input_talk = function(player, formname, fields)
-- show the same dialog again
else
minetest.show_formspec(pname, "yl_speak_up:talk",
yl_speak_up.get_fs_talkdialog(player, n_id, d_id))
yl_speak_up.get_fs_talkdialog(player, n_id, d_id, show_dropdown_o_id))
end
-- no option was selected - so we need to end this here
return