forked from Sokomine/yl_speak_up
added yl_speak_up.custom_functions_p_ etc.
This commit is contained in:
parent
adb5c5573f
commit
722556b37f
@ -188,3 +188,72 @@ yl_speak_up.input_fs_action_custom = function(player, formname, fields)
|
||||
"button[2,0.5;1.5,0.9;back_from_error_msg;Back]"})
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Custom preconditions and effects (functions; they have the type "evaluate")
|
||||
-----------------------------------------------------------------------------
|
||||
-- each entry in the table has the following format:
|
||||
-- key: for display in edit options dialog and dropdown menu,
|
||||
-- function_name: name of the function that shall be called
|
||||
-- description: long description of what the function does,
|
||||
-- param1_text: label for the input field for param1 (if empty, no input field is offered)
|
||||
-- param1_desc: mouseover text for the input field for param1
|
||||
-- ...
|
||||
-- param9_text: label for the input field for param1
|
||||
-- param9_desc: mouseover text for the input field for param1
|
||||
--
|
||||
-- preconditions:
|
||||
yl_speak_up.custom_functions_p_ = {}
|
||||
-- actions: (not yet used)
|
||||
yl_speak_up.custom_functions_a_ = {}
|
||||
-- results:
|
||||
yl_speak_up.custom_functions_r_ = {}
|
||||
|
||||
-- example function for preconditions:
|
||||
yl_speak_up.custom_functions_p_[ "example func" ] = {
|
||||
function_call = "yl_speak_up.custom_example_function",
|
||||
description = "Describe here in short form what your function does.",
|
||||
param1_text = "1. Parameter:",
|
||||
param1_desc = "This is the value passed to the function as first parameter.",
|
||||
param2_text = "2. Parameter:",
|
||||
param2_desc = "This is the value passed to the function as second parameter.",
|
||||
param3_text = "3. Parameter:",
|
||||
param3_desc = "This is the value passed to the function as 3. parameter.",
|
||||
param4_text = "4. Parameter:",
|
||||
param4_desc = "This is the value passed to the function as 4. parameter.",
|
||||
param5_text = "5. Parameter:",
|
||||
param5_desc = "This is the value passed to the function as 5. parameter.",
|
||||
param6_text = "6. Parameter:",
|
||||
param6_desc = "This is the value passed to the function as 6. parameter.",
|
||||
param7_text = "7. Parameter:",
|
||||
param7_desc = "This is the value passed to the function as 7. parameter.",
|
||||
param8_text = "8. Parameter:",
|
||||
param8_desc = "This is the value passed to the function as 8. parameter.",
|
||||
param9_text = "9. Parameter:",
|
||||
param9_desc = "This is the value passed to the function as 9. parameter.",
|
||||
}
|
||||
|
||||
-- example function for results/effects:
|
||||
yl_speak_up.custom_functions_r_[ "example func" ] = {
|
||||
function_call = "yl_speak_up.custom_example_function",
|
||||
description = "Describe here in short form what your function does.",
|
||||
param1_text = "1. Parameter:",
|
||||
param1_desc = "This is the value passed to the function as first parameter.",
|
||||
param2_text = "2. Parameter:",
|
||||
param2_desc = "This is the value passed to the function as second parameter.",
|
||||
param3_text = "3. Parameter:",
|
||||
param3_desc = "This is the value passed to the function as 3. parameter.",
|
||||
param4_text = "4. Parameter:",
|
||||
param4_desc = "This is the value passed to the function as 4. parameter.",
|
||||
param5_text = "5. Parameter:",
|
||||
param5_desc = "This is the value passed to the function as 5. parameter.",
|
||||
param6_text = "6. Parameter:",
|
||||
param6_desc = "This is the value passed to the function as 6. parameter.",
|
||||
param7_text = "7. Parameter:",
|
||||
param7_desc = "This is the value passed to the function as 7. parameter.",
|
||||
param8_text = "8. Parameter:",
|
||||
param8_desc = "This is the value passed to the function as 8. parameter.",
|
||||
param9_text = "9. Parameter:",
|
||||
param9_desc = "This is the value passed to the function as 9. parameter.",
|
||||
}
|
||||
|
||||
|
||||
|
@ -1635,9 +1635,35 @@ end
|
||||
yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
|
||||
pname, dialog, formspec, data, id_prefix, save_button, e,
|
||||
text_select_operator, values_operator, check_operator)
|
||||
if(e) then
|
||||
data.function_name = e[ id_prefix.."value"]
|
||||
-- TODO: p_param1 .. p_param9
|
||||
local func_data = nil
|
||||
if(e or true) then
|
||||
--data.function_name = e[ id_prefix.."value"]
|
||||
data.function_name = "example func"
|
||||
-- TODO: create the dropdown
|
||||
func_data = yl_speak_up["custom_functions_"..id_prefix][data.function_name]
|
||||
-- add the fields for param1..param9:
|
||||
if(func_data) then
|
||||
local xoff = 0
|
||||
for i = 1, 9 do
|
||||
if(i > 5) then
|
||||
xoff = 10
|
||||
end
|
||||
local paramn = "param"..tostring(i)
|
||||
local s = func_data[paramn.."_text"]
|
||||
if(s) then
|
||||
formspec = formspec..
|
||||
"label["..(0.2 + xoff)..","..(6.05 + ((i-1)%5)*0.8)..";"..
|
||||
minetest.formspec_escape(s).."]"..
|
||||
"field["..(4.0 + xoff)..","..(5.8 + ((i-1)%5)*0.8)..
|
||||
";5.0,0.6;set_"..paramn..";;"..
|
||||
minetest.formspec_escape(
|
||||
data[paramn] or "- enter value -").."]"..
|
||||
"tooltip[set_"..paramn..";"..
|
||||
minetest.formspec_escape(
|
||||
func_data[paramn.."_desc"] or "?").."]"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local operator_list = {}
|
||||
for i, v in ipairs(check_operator) do
|
||||
@ -1660,11 +1686,11 @@ yl_speak_up.get_fs_edit_option_p_and_e_evaluate = function(
|
||||
text_operator_and_comparison..
|
||||
-- TODO: rather a dropdown...
|
||||
"field[1.0,4.8;5.0,0.6;property;;"..
|
||||
minetest.formspec_escape(data.property or "- enter name -").."]"..
|
||||
"hypertext[1.2,7.0;16.0,2.5;some_text;<normal>"..
|
||||
"<b>Note:</b> Functions are called with parameters which are passed on to them. "..
|
||||
"The function then calculates a result. This can be compared to a given value."..
|
||||
"</normal>]"
|
||||
minetest.formspec_escape(data.property or "- enter name -").."]"
|
||||
-- "hypertext[1.2,7.0;16.0,2.5;some_text;<normal>"..
|
||||
-- "<b>Note:</b> Functions are called with parameters which are passed on to them. "..
|
||||
-- "The function then calculates a result. This can be compared to a given value."..
|
||||
-- "</normal>]"
|
||||
end
|
||||
|
||||
|
||||
|
@ -247,7 +247,7 @@ yl_speak_up.show_precondition = function(p, pname)
|
||||
elseif(p.p_type == "evaluate") then
|
||||
local str = ""
|
||||
for i = 1, 9 do
|
||||
str = str..tostring(p["p_param" + str(i)])
|
||||
str = str..tostring(p["p_param" + tostring(i)])
|
||||
if(i < 9) then
|
||||
str = str..","
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user