forked from Sokomine/yl_speak_up
added fs_edit_preconditions.lua and fs_edit_effects.lua
This commit is contained in:
parent
a0f338c965
commit
d916178ca0
62
fs_edit_effects.lua
Normal file
62
fs_edit_effects.lua
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
|
||||||
|
yl_speak_up.input_fs_edit_effects = 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_effects"})
|
||||||
|
end
|
||||||
|
|
||||||
|
yl_speak_up.get_fs_edit_effects = 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 results = dialog.n_dialogs[d_id].d_options[o_id].o_results
|
||||||
|
if(not(results)) then
|
||||||
|
results = {}
|
||||||
|
end
|
||||||
|
-- which precondition has the player selected?
|
||||||
|
local sorted_key_list = yl_speak_up.sort_keys(results)
|
||||||
|
local selected = minetest.explode_table_event(table_click_result)
|
||||||
|
-- use "new" if nothing fits
|
||||||
|
local r_id = "new"
|
||||||
|
if((selected.type == "CHG" or selected.type == "DLC")
|
||||||
|
and selected.row <= #sorted_key_list) then
|
||||||
|
r_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 effect\n-> "..tostring(r_id).."]"..
|
||||||
|
"button[1,1.0;1,1.0;back;Back]"
|
||||||
|
end
|
@ -105,9 +105,17 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
|
|||||||
|
|
||||||
-- the player clicked on a precondition
|
-- the player clicked on a precondition
|
||||||
elseif(fields.table_of_preconditions) then
|
elseif(fields.table_of_preconditions) then
|
||||||
|
-- remember which option was selected
|
||||||
|
yl_speak_up.speak_to[pname].o_id = o_id
|
||||||
|
yl_speak_up.show_fs(player, "edit_preconditions", fields.table_of_preconditions)
|
||||||
|
return
|
||||||
|
|
||||||
-- the player clicked on an effect
|
-- the player clicked on an effect
|
||||||
elseif(fields.table_of_effects) then
|
elseif(fields.table_of_effects) then
|
||||||
|
-- remember which option was selected
|
||||||
|
yl_speak_up.speak_to[pname].o_id = o_id
|
||||||
|
yl_speak_up.show_fs(player, "edit_effects", fields.table_of_effects)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if ESC is pressed or anything else unpredicted happens: go back to the main dialog edit window
|
-- if ESC is pressed or anything else unpredicted happens: go back to the main dialog edit window
|
||||||
@ -172,6 +180,10 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id)
|
|||||||
for i, k in ipairs(sorted_key_list) do
|
for i, k in ipairs(sorted_key_list) do
|
||||||
local v = results[ k ]
|
local v = results[ k ]
|
||||||
if v.r_type == "dialog" and dialog.n_dialogs[v.r_value] ~= nil then
|
if v.r_type == "dialog" and dialog.n_dialogs[v.r_value] ~= nil then
|
||||||
|
list_of_effects = list_of_effects..
|
||||||
|
minetest.formspec_escape(v.r_id)..",#999999,"..
|
||||||
|
minetest.formspec_escape(v.r_type)..","..
|
||||||
|
minetest.formspec_escape(v.r_value)..","
|
||||||
-- there may be more than one in the data structure
|
-- there may be more than one in the data structure
|
||||||
target_dialog = v.r_value
|
target_dialog = v.r_value
|
||||||
elseif v.r_type ~= "dialog" then
|
elseif v.r_type ~= "dialog" then
|
||||||
@ -308,7 +320,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id)
|
|||||||
"apply the following (Ef)fects:]"..
|
"apply the following (Ef)fects:]"..
|
||||||
-- TODO: perhaps add tooltip for the type of the conditions
|
-- TODO: perhaps add tooltip for the type of the conditions
|
||||||
"tablecolumns[text;color,span=1;text;text]"..
|
"tablecolumns[text;color,span=1;text;text]"..
|
||||||
"table[1.2,12.3;21.0,2.0;table_of_effects;"..
|
"table[1.2,12.3;19.6,2.0;table_of_effects;"..
|
||||||
list_of_effects..";0]"..
|
list_of_effects..";0]"..
|
||||||
-- ..and what the NPC will reply to that answer
|
-- ..and what the NPC will reply to that answer
|
||||||
"label[0.2,15.1;The NPC will react to this answer with the following dialog:]"..
|
"label[0.2,15.1;The NPC will react to this answer with the following dialog:]"..
|
||||||
|
63
fs_edit_preconditions.lua
Normal file
63
fs_edit_preconditions.lua
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
|
||||||
|
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
|
4
init.lua
4
init.lua
@ -19,6 +19,10 @@ dofile(modpath .. "config.lua")
|
|||||||
dofile(modpath .. "privs.lua")
|
dofile(modpath .. "privs.lua")
|
||||||
-- handle on_player_receive_fields and showing of formspecs
|
-- handle on_player_receive_fields and showing of formspecs
|
||||||
dofile(modpath .. "show_fs.lua")
|
dofile(modpath .. "show_fs.lua")
|
||||||
|
-- edit preconditions (can be reached through edit options dialog)
|
||||||
|
dofile(modpath .. "fs_edit_preconditions.lua")
|
||||||
|
-- edit effects (can be reached through edit options dialog)
|
||||||
|
dofile(modpath .. "fs_edit_effects.lua")
|
||||||
-- edit options dialog (detailed configuration of options in edit mode)
|
-- edit options dialog (detailed configuration of options in edit mode)
|
||||||
dofile(modpath .. "fs_edit_options_dialog.lua")
|
dofile(modpath .. "fs_edit_options_dialog.lua")
|
||||||
-- set name, description and owner (owner only with npc_talk_master priv)
|
-- set name, description and owner (owner only with npc_talk_master priv)
|
||||||
|
16
show_fs.lua
16
show_fs.lua
@ -41,6 +41,14 @@ minetest.register_on_player_receive_fields( function(player, formname, fields)
|
|||||||
elseif formname == "yl_speak_up:initial_config" then
|
elseif formname == "yl_speak_up:initial_config" then
|
||||||
yl_speak_up.input_fs_initial_config(player, formname, fields)
|
yl_speak_up.input_fs_initial_config(player, formname, fields)
|
||||||
return true
|
return true
|
||||||
|
-- handled in fs_edit_preconditions.lua
|
||||||
|
elseif formname == "yl_speak_up:edit_preconditions" then
|
||||||
|
yl_speak_up.input_fs_edit_preconditions(player, formname, fields)
|
||||||
|
return true
|
||||||
|
-- handled in fs_edit_effects.lua
|
||||||
|
elseif formname == "yl_speak_up:edit_effects" then
|
||||||
|
yl_speak_up.input_fs_edit_effects(player, formname, fields)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -129,6 +137,14 @@ yl_speak_up.show_fs = function(player, fs_name, param)
|
|||||||
yl_speak_up.get_fs_initial_config(player, param.n_id, param.d_id,
|
yl_speak_up.get_fs_initial_config(player, param.n_id, param.d_id,
|
||||||
param.is_initial_config))
|
param.is_initial_config))
|
||||||
|
|
||||||
|
elseif(fs_name == "edit_preconditions") then
|
||||||
|
minetest.show_formspec(pname, "yl_speak_up:edit_preconditions",
|
||||||
|
yl_speak_up.get_fs_edit_preconditions(player, param))
|
||||||
|
|
||||||
|
elseif(fs_name == "edit_effects") then
|
||||||
|
minetest.show_formspec(pname, "yl_speak_up:edit_effects",
|
||||||
|
yl_speak_up.get_fs_edit_effects(player, param))
|
||||||
|
|
||||||
-- fallback in case of wrong call
|
-- fallback in case of wrong call
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(pname, "Error: Trying to show wrong "..
|
minetest.chat_send_player(pname, "Error: Trying to show wrong "..
|
||||||
|
Loading…
Reference in New Issue
Block a user