forked from Sokomine/yl_speak_up
process input into field elements of fs_edit_preconditions.lua
This commit is contained in:
parent
91788f8713
commit
850343a30d
@ -105,6 +105,43 @@ yl_speak_up.input_fs_edit_preconditions = function(player, formname, fields)
|
||||
return
|
||||
end
|
||||
|
||||
-- field inputs: those do not trigger a sending of the formspec on their own
|
||||
|
||||
-- are we talking about an inventory?
|
||||
local data = yl_speak_up.speak_to[pname].tmp_prereq
|
||||
if(fields.inv_stack_name and fields.inv_stack_name ~= ""
|
||||
and data and data.what and data.what >= 5 and data.what <= 6) then
|
||||
local parts = fields.inv_stack_name:split(" ")
|
||||
local size = 1
|
||||
if(parts and #parts > 1) then
|
||||
size = tonumber(parts[2])
|
||||
if(not(size) or size < 1) then
|
||||
size = 1
|
||||
end
|
||||
end
|
||||
-- does the item exist?
|
||||
if(minetest.registered_items[ parts[1] ]) then
|
||||
data.inv_stack_name = parts[1].." "..parts[2]
|
||||
else
|
||||
-- show error message
|
||||
yl_speak_up.show_fs(player, "msg", {
|
||||
input_to = "yl_speak_up:edit_preconditions",
|
||||
formspec = "size[8,2]"..
|
||||
"label[0.2,0.5;Error: \""..
|
||||
minetest.formspec_escape(fields.inv_stack_name)..
|
||||
"\" is not a valid item(stack).]"..
|
||||
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
|
||||
return
|
||||
end
|
||||
|
||||
-- comparison value for a variable
|
||||
elseif(fields.var_cmp_value
|
||||
and data and data.what and data.what >= 5 and data.what <= 6) then
|
||||
data.var_cmp_value = fields.var_cmp_value
|
||||
end
|
||||
|
||||
-- selections in a dropdown menu (they trigger sending the formspec)
|
||||
|
||||
-- select a general direction/type first
|
||||
if(fields.select_what) then
|
||||
local nr = table.indexof(check_what, fields.select_what)
|
||||
@ -141,7 +178,8 @@ yl_speak_up.input_fs_edit_preconditions = function(player, formname, fields)
|
||||
if(not(fields.back)
|
||||
and (fields.change_prereq or fields.select_what or fields.select_trade
|
||||
or fields.select_inv or fields.select_block
|
||||
or fields.select_variable or fields.select_operator)) then
|
||||
or fields.select_variable or fields.select_operator
|
||||
or fields.back_from_error_msg)) then
|
||||
yl_speak_up.show_fs(player, "edit_preconditions")
|
||||
return
|
||||
end
|
||||
@ -246,7 +284,8 @@ yl_speak_up.get_fs_edit_preconditions = function(player, table_click_result)
|
||||
data.operator = 1
|
||||
save_button = ""
|
||||
end
|
||||
local field_for_value = "field[11.2,4.8;7.0,0.6;var_cmp_value;;]"
|
||||
local field_for_value = "field[11.2,4.8;7.0,0.6;var_cmp_value;;"..
|
||||
minetest.formspec_escape(data.var_cmp_value or "- enter value -").."]"
|
||||
-- do not show value input field for unary operators
|
||||
if(not(data.operator) or data.operator == 1 or data.operator >= 8) then
|
||||
field_for_value = "label[11.2,5.1;- not used for this operator -]"
|
||||
@ -293,7 +332,7 @@ yl_speak_up.get_fs_edit_preconditions = function(player, table_click_result)
|
||||
table.concat(check_inv, ",")..";"..
|
||||
tostring(data.inv)..";]"..
|
||||
"label[0.2,4.5;Name of the item(stack):]"..
|
||||
"field[4.0,4.3;16.0,0.6;inv_stack_name;;]"..
|
||||
"field[4.0,4.3;16.0,0.6;inv_stack_name;;"..(data.inv_stack_name or "").."]"..
|
||||
"tooltip[inv_stack_name;Enter name of the block and amount.\n"..
|
||||
"Example: \"default:apple 3\" for three apples,\n"..
|
||||
" \"farming:bread\" for a bread.]"
|
||||
|
Loading…
Reference in New Issue
Block a user