added fs_edit_actions.lua and necessary sourroundings
This commit is contained in:
parent
62cfd61e8a
commit
5d82cbc32d
@ -32,6 +32,9 @@ yl_speak_up.trade_max_cols = 4
|
|||||||
|
|
||||||
-- how many prerequirements can the player define per dialog option?
|
-- how many prerequirements can the player define per dialog option?
|
||||||
yl_speak_up.max_prerequirements = 12
|
yl_speak_up.max_prerequirements = 12
|
||||||
|
-- how many actions can there be per dialog option?
|
||||||
|
-- for now, more than one doesn't make sense
|
||||||
|
yl_speak_up.max_actions = 1
|
||||||
-- how many effects can the player define per dialog option?
|
-- how many effects can the player define per dialog option?
|
||||||
yl_speak_up.max_result_effects = 6
|
yl_speak_up.max_result_effects = 6
|
||||||
|
|
||||||
|
95
fs_edit_actions.lua
Normal file
95
fs_edit_actions.lua
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
|
||||||
|
-- Which diffrent types of actions are available?
|
||||||
|
-- -> The following fields are part of an action:
|
||||||
|
-- a_id the ID/key of the action
|
||||||
|
-- a_type selected from values_what
|
||||||
|
-- a_value used to store the subtype of a_type
|
||||||
|
--
|
||||||
|
-- on_failure: TODO - does this make sense here?
|
||||||
|
-- r_value alternate target dialog if the previous *effect* failed
|
||||||
|
--
|
||||||
|
-- Note: Trades are not stored as actions - they are stored in
|
||||||
|
-- dialog.trades[ trade_id ] with <trade_id> == "<d_id> <o_id>"
|
||||||
|
--
|
||||||
|
|
||||||
|
-- some helper lists for creating the formspecs and evaulating
|
||||||
|
-- the player's answers:
|
||||||
|
|
||||||
|
-- general direction of what could make up an action
|
||||||
|
local check_what = {
|
||||||
|
"- please select -",
|
||||||
|
"No action (default).", -- 2
|
||||||
|
"Normal trade - one item(stack) for another item(stack).", -- 3
|
||||||
|
"The NPC gives something to the player (i.e. a quest item).", -- 4
|
||||||
|
"The player is expected to give something to the NPC (i.e. a quest item).", -- 5
|
||||||
|
"The player has to manually enter a password or passphrase or some other text.", -- 6
|
||||||
|
"The player has to move virtual items in a virtual inventory to the right position.", -- 7
|
||||||
|
"Call custom functions that are supposed to be overridden by the server.", -- 8
|
||||||
|
}
|
||||||
|
|
||||||
|
-- how to store these as a_type in the action:
|
||||||
|
local values_what = {"", "none", "trade", "npc_gives", "npc_wants", "text_input", "puzzle", "custom"}
|
||||||
|
|
||||||
|
|
||||||
|
-- returns a human-readable text as description of the action
|
||||||
|
-- (as shown in the edit options dialog and in the edit effect formspec)
|
||||||
|
yl_speak_up.show_action = function(a)
|
||||||
|
if(not(a.a_type) or a.a_type == "" or a.a_type == "none") then
|
||||||
|
return "(nothing): Nothing to do. No action."
|
||||||
|
elseif(a.a_type == "trade") then
|
||||||
|
return "trade:" -- TODO show ation text
|
||||||
|
elseif(a.a_type == "npc_gives") then
|
||||||
|
return "npc_gives:" -- TODO show ation text
|
||||||
|
elseif(a.a_type == "npc_wants") then
|
||||||
|
return "npc_wants:" -- TODO show ation text
|
||||||
|
elseif(a.a_type == "text_input") then
|
||||||
|
return "text_input:" -- TODO show ation text
|
||||||
|
elseif(a.a_type == "puzzle") then
|
||||||
|
return "puzzle:" -- TODO show ation text
|
||||||
|
elseif(a.a_type == "custom") then
|
||||||
|
return "custom:" -- TODO show ation text
|
||||||
|
end
|
||||||
|
-- fallback
|
||||||
|
return tostring(a.a_value)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
yl_speak_up.execute_all_actions = function(player, actions, o_id)
|
||||||
|
-- TODO: implement
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
yl_speak_up.execute_action = function(player, n_id, o_id, r)
|
||||||
|
-- TODO: implement. boils down to showing formspecs
|
||||||
|
-- fallback: unkown type
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- these are only wrapper functions for those in fs_edit_general.lua
|
||||||
|
|
||||||
|
yl_speak_up.input_fs_edit_actions = function(player, formname, fields)
|
||||||
|
return yl_speak_up.input_fs_edit_option_related(player, formname, fields,
|
||||||
|
"a_", "actions", yl_speak_up.max_actions,
|
||||||
|
"(A)ctions", "tmp_action",
|
||||||
|
nil, -- unused - no block operations
|
||||||
|
values_what, {}, {}, {}, {},
|
||||||
|
check_what, {}, {}, {}, {},
|
||||||
|
nil, -- no variables
|
||||||
|
"edit_actions"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
yl_speak_up.get_fs_edit_actions = function(player, table_click_result)
|
||||||
|
return yl_speak_up.get_fs_edit_option_related(player, table_click_result,
|
||||||
|
"a_", "actions", yl_speak_up.max_actions,
|
||||||
|
"(A)ctions", "tmp_action",
|
||||||
|
"What do you want to happen in this (A)ction?",
|
||||||
|
check_what, {}, {}, {}, {},
|
||||||
|
nil, -- no variables
|
||||||
|
yl_speak_up.show_action,
|
||||||
|
"table_of_elements",
|
||||||
|
nil, nil, nil, -- no variable handling here
|
||||||
|
nil -- nothing block-related to do here
|
||||||
|
)
|
||||||
|
end
|
@ -243,7 +243,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
|||||||
|
|
||||||
-- comparison value for a variable (same for both preconditions and effects)
|
-- comparison value for a variable (same for both preconditions and effects)
|
||||||
elseif(fields.var_cmp_value
|
elseif(fields.var_cmp_value
|
||||||
and data and data.what and data.what == 2) then
|
and data and data.what and data.what == 2 and id_prefix ~= "a_") then
|
||||||
data.var_cmp_value = fields.var_cmp_value
|
data.var_cmp_value = fields.var_cmp_value
|
||||||
|
|
||||||
-- text for a chat message
|
-- text for a chat message
|
||||||
@ -289,14 +289,14 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- "an internal state (i.e. of a quest)", -- 2
|
-- "an internal state (i.e. of a quest)", -- 2
|
||||||
if(data.what == 2) then
|
if(data.what == 2 and id_prefix ~= "a_") then
|
||||||
v[ id_prefix.."value" ] = "expression"
|
v[ id_prefix.."value" ] = "expression"
|
||||||
v[ id_prefix.."operator" ] = values_operator[ data.operator ]
|
v[ id_prefix.."operator" ] = values_operator[ data.operator ]
|
||||||
v[ id_prefix.."var_cmp_value" ] = (data.var_cmp_value or "")
|
v[ id_prefix.."var_cmp_value" ] = (data.var_cmp_value or "")
|
||||||
v[ id_prefix.."variable" ] = data.variable_name
|
v[ id_prefix.."variable" ] = data.variable_name
|
||||||
|
|
||||||
-- "a block somewhere", -- 3
|
-- "a block somewhere", -- 3
|
||||||
elseif(data.what == 3) then
|
elseif(data.what == 3 and id_prefix ~= "a_") then
|
||||||
v[ id_prefix.."value" ] = values_block[ data.block ]
|
v[ id_prefix.."value" ] = values_block[ data.block ]
|
||||||
if(not(data.block_pos) or not(data.node_data) or not(data.node_data.name)) then
|
if(not(data.block_pos) or not(data.node_data) or not(data.node_data.name)) then
|
||||||
yl_speak_up.show_fs(player, "msg", {
|
yl_speak_up.show_fs(player, "msg", {
|
||||||
@ -605,7 +605,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
|||||||
|
|
||||||
-- "an internal state (i.e. of a quest)", -- 2
|
-- "an internal state (i.e. of a quest)", -- 2
|
||||||
-- (state is the second offered option in both preconditions and effects list)
|
-- (state is the second offered option in both preconditions and effects list)
|
||||||
if(data.what and data.what == 2) then
|
if(data.what and data.what == 2 and id_prefix ~= "a_") then
|
||||||
if(not(data.variable) or data.variable == 1) then
|
if(not(data.variable) or data.variable == 1) then
|
||||||
data.variable = 1
|
data.variable = 1
|
||||||
-- not enough selected yet for saving
|
-- not enough selected yet for saving
|
||||||
@ -642,7 +642,7 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
|||||||
|
|
||||||
-- "a block somewhere", -- 3
|
-- "a block somewhere", -- 3
|
||||||
-- (block is the third offered option in both preconditions and effects list)
|
-- (block is the third offered option in both preconditions and effects list)
|
||||||
elseif(data.what and data.what == 3) then
|
elseif(data.what and data.what == 3 and id_prefix ~= "a_") then
|
||||||
local block_pos_str = "- none set -"
|
local block_pos_str = "- none set -"
|
||||||
local node = {name = "- unknown -", param2 = "- unkown -"}
|
local node = {name = "- unknown -", param2 = "- unkown -"}
|
||||||
if(not(block_pos) and data and data.block_pos) then
|
if(not(block_pos) and data and data.block_pos) then
|
||||||
|
@ -42,7 +42,7 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
|
|||||||
yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = d_id})
|
yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = d_id})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
--[[ -- TODO
|
||||||
-- for now, there's only trade as action
|
-- for now, there's only trade as action
|
||||||
if(fields.table_of_actions) then
|
if(fields.table_of_actions) then
|
||||||
local trade_id = tostring(d_id).." "..tostring(o_id)
|
local trade_id = tostring(d_id).." "..tostring(o_id)
|
||||||
@ -62,9 +62,9 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
|
|||||||
-- create a new trade for this dialog and option - with ID "<d_id> <o_id>"
|
-- create a new trade for this dialog and option - with ID "<d_id> <o_id>"
|
||||||
yl_speak_up.show_fs(player, "add_trade_simple", tostring(d_id).." "..tostring(o_id))
|
yl_speak_up.show_fs(player, "add_trade_simple", tostring(d_id).." "..tostring(o_id))
|
||||||
return
|
return
|
||||||
|
--]]
|
||||||
-- the player wants to see the previous option/answer
|
-- the player wants to see the previous option/answer
|
||||||
elseif(fields.edit_option_prev) then
|
if(fields.edit_option_prev) then
|
||||||
-- sort all options by o_sort
|
-- sort all options by o_sort
|
||||||
local sorted_list = yl_speak_up.get_sorted_options(n_dialog.d_options, "o_sort")
|
local sorted_list = yl_speak_up.get_sorted_options(n_dialog.d_options, "o_sort")
|
||||||
local o_found = o_id
|
local o_found = o_id
|
||||||
@ -93,6 +93,7 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
|
|||||||
{n_id = n_id, d_id = d_id, o_id = o_found, caller="next option"})
|
{n_id = n_id, d_id = d_id, o_id = o_found, caller="next option"})
|
||||||
return
|
return
|
||||||
|
|
||||||
|
--[[ TODO handle elsewhere
|
||||||
-- show the trade associated with this dialog and option
|
-- show the trade associated with this dialog and option
|
||||||
elseif(fields.effect_show_trade) then
|
elseif(fields.effect_show_trade) then
|
||||||
-- remember which option was selected
|
-- remember which option was selected
|
||||||
@ -102,6 +103,7 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
|
|||||||
-- show the trade with ID "<d_id> <o_id>"
|
-- show the trade with ID "<d_id> <o_id>"
|
||||||
yl_speak_up.show_fs(player, "trade_simple", tostring(d_id).." "..tostring(o_id))
|
yl_speak_up.show_fs(player, "trade_simple", tostring(d_id).." "..tostring(o_id))
|
||||||
return
|
return
|
||||||
|
--]]
|
||||||
|
|
||||||
-- the player clicked on a precondition
|
-- the player clicked on a precondition
|
||||||
elseif(fields.table_of_preconditions) then
|
elseif(fields.table_of_preconditions) then
|
||||||
@ -110,6 +112,13 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields)
|
|||||||
yl_speak_up.show_fs(player, "edit_preconditions", fields.table_of_preconditions)
|
yl_speak_up.show_fs(player, "edit_preconditions", fields.table_of_preconditions)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
-- the player clicked on an action
|
||||||
|
elseif(fields.table_of_actions) then
|
||||||
|
-- remember which option was selected
|
||||||
|
yl_speak_up.speak_to[pname].o_id = o_id
|
||||||
|
yl_speak_up.show_fs(player, "edit_actions", fields.table_of_actions)
|
||||||
|
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
|
-- remember which option was selected
|
||||||
@ -166,6 +175,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local list_of_actions = ""
|
local list_of_actions = ""
|
||||||
|
-- TODO: build the same way as list of preconditions and effects
|
||||||
if(dialog.trades and dialog.trades[ tostring(d_id).." "..tostring(o_id) ]) then
|
if(dialog.trades and dialog.trades[ tostring(d_id).." "..tostring(o_id) ]) then
|
||||||
local tr = dialog.trades[ tostring(d_id).." "..tostring(o_id)]
|
local tr = dialog.trades[ tostring(d_id).." "..tostring(o_id)]
|
||||||
-- show the trade in the result/effects list
|
-- show the trade in the result/effects list
|
||||||
|
2
init.lua
2
init.lua
@ -23,6 +23,8 @@ dofile(modpath .. "show_fs.lua")
|
|||||||
dofile(modpath .. "fs_edit_general.lua")
|
dofile(modpath .. "fs_edit_general.lua")
|
||||||
-- edit preconditions (can be reached through edit options dialog)
|
-- edit preconditions (can be reached through edit options dialog)
|
||||||
dofile(modpath .. "fs_edit_preconditions.lua")
|
dofile(modpath .. "fs_edit_preconditions.lua")
|
||||||
|
-- edit actions (can be reached through edit options dialog)
|
||||||
|
dofile(modpath .. "fs_edit_actions.lua")
|
||||||
-- edit effects (can be reached through edit options dialog)
|
-- edit effects (can be reached through edit options dialog)
|
||||||
dofile(modpath .. "fs_edit_effects.lua")
|
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)
|
||||||
|
@ -45,6 +45,10 @@ minetest.register_on_player_receive_fields( function(player, formname, fields)
|
|||||||
elseif formname == "yl_speak_up:edit_preconditions" then
|
elseif formname == "yl_speak_up:edit_preconditions" then
|
||||||
yl_speak_up.input_fs_edit_preconditions(player, formname, fields)
|
yl_speak_up.input_fs_edit_preconditions(player, formname, fields)
|
||||||
return true
|
return true
|
||||||
|
-- handled in fs_edit_actions.lua
|
||||||
|
elseif formname == "yl_speak_up:edit_actions" then
|
||||||
|
yl_speak_up.input_fs_edit_actions(player, formname, fields)
|
||||||
|
return true
|
||||||
-- handled in fs_edit_effects.lua
|
-- handled in fs_edit_effects.lua
|
||||||
elseif formname == "yl_speak_up:edit_effects" then
|
elseif formname == "yl_speak_up:edit_effects" then
|
||||||
yl_speak_up.input_fs_edit_effects(player, formname, fields)
|
yl_speak_up.input_fs_edit_effects(player, formname, fields)
|
||||||
@ -142,6 +146,10 @@ yl_speak_up.show_fs = function(player, fs_name, param)
|
|||||||
minetest.show_formspec(pname, "yl_speak_up:edit_preconditions",
|
minetest.show_formspec(pname, "yl_speak_up:edit_preconditions",
|
||||||
yl_speak_up.get_fs_edit_preconditions(player, param))
|
yl_speak_up.get_fs_edit_preconditions(player, param))
|
||||||
|
|
||||||
|
elseif(fs_name == "edit_actions") then
|
||||||
|
minetest.show_formspec(pname, "yl_speak_up:edit_actions",
|
||||||
|
yl_speak_up.get_fs_edit_actions(player, param))
|
||||||
|
|
||||||
elseif(fs_name == "edit_effects") then
|
elseif(fs_name == "edit_effects") then
|
||||||
minetest.show_formspec(pname, "yl_speak_up:edit_effects",
|
minetest.show_formspec(pname, "yl_speak_up:edit_effects",
|
||||||
yl_speak_up.get_fs_edit_effects(player, param))
|
yl_speak_up.get_fs_edit_effects(player, param))
|
||||||
|
Loading…
Reference in New Issue
Block a user