mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-07-09 23:38:54 +02:00
64 lines
2.1 KiB
Lua
64 lines
2.1 KiB
Lua
|
|
yl_speak_up.input_fs_edit_preconditions = function(player, formname, fields)
|
|
if(not(player)) then
|
|
return
|
|
end
|
|
local pname = player:get_player_name()
|
|
-- what are we talking about?
|
|
local n_id = yl_speak_up.speak_to[pname].n_id
|
|
local d_id = yl_speak_up.speak_to[pname].d_id
|
|
local o_id = yl_speak_up.speak_to[pname].o_id
|
|
|
|
-- this only works in edit mode
|
|
if(not(n_id) or yl_speak_up.edit_mode[pname] ~= n_id) then
|
|
return
|
|
end
|
|
|
|
-- go back to the edit option dialog
|
|
yl_speak_up.show_fs(player, "edit_option_dialog",
|
|
{n_id = n_id, d_id = d_id, o_id = o_id, caller="edit_precondition"})
|
|
end
|
|
|
|
|
|
yl_speak_up.get_fs_edit_preconditions = function(player, table_click_result)
|
|
if(not(player) or not(table_click_result)) then
|
|
return ""
|
|
end
|
|
local pname = player:get_player_name()
|
|
-- what are we talking about?
|
|
local n_id = yl_speak_up.speak_to[pname].n_id
|
|
local d_id = yl_speak_up.speak_to[pname].d_id
|
|
local o_id = yl_speak_up.speak_to[pname].o_id
|
|
|
|
-- this only works in edit mode
|
|
if(not(n_id) or yl_speak_up.edit_mode[pname] ~= n_id) then
|
|
return "size[1,1]label[0,0;You cannot edit this NPC.]"
|
|
end
|
|
|
|
local dialog = yl_speak_up.speak_to[pname].dialog
|
|
if(not(dialog) or not(dialog.n_dialogs)
|
|
or not(dialog.n_dialogs[d_id])
|
|
or not(dialog.n_dialogs[d_id].d_options)
|
|
or not(dialog.n_dialogs[d_id].d_options[o_id])) then
|
|
return "size[4,1]label[0,0;Dialog option does not exist.]"
|
|
end
|
|
|
|
local prereq = dialog.n_dialogs[d_id].d_options[o_id].o_prerequisites
|
|
if(not(prereq)) then
|
|
prereq = {}
|
|
end
|
|
-- which precondition has the player selected?
|
|
local sorted_key_list = yl_speak_up.sort_keys(prereq)
|
|
local selected = minetest.explode_table_event(table_click_result)
|
|
-- use "new" if nothing fits
|
|
local p_id = "new"
|
|
if((selected.type == "CHG" or selected.type == "DLC")
|
|
and selected.row <= #sorted_key_list) then
|
|
p_id = sorted_key_list[ selected.row ]
|
|
end
|
|
|
|
minetest.chat_send_player("singleplayer","input: "..minetest.serialize(table_click_result))
|
|
return "size[4,1.5]label[0,0;Formspec: edit preconditions\n-> "..tostring(p_id).."]"..
|
|
"button[1,1.0;1,1.0;back;Back]"
|
|
end
|