mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-08-29 23:36:23 +02:00
made dialog selection dropdown menu and prev/next dialog buttons work
This commit is contained in:
parent
e40c464af8
commit
a9259ed3ba
@ -1001,6 +1001,7 @@ local function get_fs_talkdialog(player, n_id, d_id)
|
|||||||
-- TODO: make name and description likewise editable?
|
-- TODO: make name and description likewise editable?
|
||||||
if(edit_mode) then
|
if(edit_mode) then
|
||||||
|
|
||||||
|
-- TODO: sort by name?
|
||||||
-- build the list of available dialogs for the dropdown list(s)
|
-- build the list of available dialogs for the dropdown list(s)
|
||||||
-- if there are dialogs defined
|
-- if there are dialogs defined
|
||||||
if(dialog and dialog.n_dialogs) then
|
if(dialog and dialog.n_dialogs) then
|
||||||
@ -1022,15 +1023,18 @@ local function get_fs_talkdialog(player, n_id, d_id)
|
|||||||
-- this is just an alternate way of walking through the dialogs
|
-- this is just an alternate way of walking through the dialogs
|
||||||
for k,v in pairs(d_id_to_dropdown_index) do
|
for k,v in pairs(d_id_to_dropdown_index) do
|
||||||
if( v == i-1) then
|
if( v == i-1) then
|
||||||
table.insert(formspec, "button[8.5,4.0;2,0.9;dialog_"..k..";<]")
|
table.insert(formspec, "button[8.5,4.0;2,0.9;prev_dialog_"..k..";<]")
|
||||||
-- add a tooltip
|
-- add a tooltip
|
||||||
table.insert(formspec, "tooltip[dialog_" .. k .. ";Go to previous dialog "..k..".]")
|
table.insert(formspec, "tooltip[prev_dialog_" .. k .. ";Go to previous dialog "..k..".]")
|
||||||
elseif(v == i+1) then
|
elseif(v == i+1) then
|
||||||
table.insert(formspec, "button[11,4.0;2,0.9;dialog_"..k..";>]")
|
table.insert(formspec, "button[11,4.0;2,0.9;next_dialog_"..k..";>]")
|
||||||
-- add a tooltip
|
-- add a tooltip
|
||||||
table.insert(formspec, "tooltip[dialog_" .. k .. ";Go to next dialog "..k..".]")
|
table.insert(formspec, "tooltip[next_dialog_" .. k .. ";Go to next dialog "..k..".]")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- add a "+" button for creating a new dialog
|
||||||
|
table.insert(formspec, "button[13.9,4.0;1,0.9;show_new_dialog;+]")
|
||||||
|
table.insert(formspec, "tooltip[show_new_dialog;Create a new dialog.]")
|
||||||
|
|
||||||
|
|
||||||
table.insert(formspec, "textarea[0.2,5;19.6,17.8;d_text;;")
|
table.insert(formspec, "textarea[0.2,5;19.6,17.8;d_text;;")
|
||||||
@ -1730,13 +1734,13 @@ minetest.register_on_player_receive_fields(
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if o == "" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Is the player working on this particular npc?
|
-- Is the player working on this particular npc?
|
||||||
local edit_mode = (yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id)
|
local edit_mode = (yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id)
|
||||||
|
|
||||||
|
if not(edit_mode) and o == "" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Let's check if the button was among the "allowed buttons". Only those may be executed
|
-- Let's check if the button was among the "allowed buttons". Only those may be executed
|
||||||
if not(edit_mode) and (yl_speak_up.speak_to[pname].allowed and yl_speak_up.speak_to[pname].allowed[o] == false) then
|
if not(edit_mode) and (yl_speak_up.speak_to[pname].allowed and yl_speak_up.speak_to[pname].allowed[o] == false) then
|
||||||
return
|
return
|
||||||
@ -1748,6 +1752,32 @@ minetest.register_on_player_receive_fields(
|
|||||||
|
|
||||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||||
|
|
||||||
|
-- in edit mode: another dialog was selected
|
||||||
|
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
|
||||||
|
show_dialog = fields.d_id
|
||||||
|
-- in edit mode: prev_dialog_../next_dialog_.. was selected
|
||||||
|
else
|
||||||
|
for k,v in pairs(dialog.n_dialogs) do
|
||||||
|
if(fields["prev_dialog_"..k]) then
|
||||||
|
show_dialog = k
|
||||||
|
elseif(fields["next_dialog_"..k]) then
|
||||||
|
show_dialog = k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
yl_speak_up.speak_to[pname].d_id = show_dialog
|
||||||
|
minetest.show_formspec(pname, "yl_speak_up:talk", get_fs_talkdialog(player, yl_speak_up.speak_to[pname].n_id, show_dialog))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local n_dialog = dialog.n_dialogs[d_id]
|
local n_dialog = dialog.n_dialogs[d_id]
|
||||||
|
|
||||||
local d_option = n_dialog.d_options[o]
|
local d_option = n_dialog.d_options[o]
|
||||||
|
Loading…
Reference in New Issue
Block a user