mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-06-17 14:18:05 +02:00
325 lines
12 KiB
Lua
325 lines
12 KiB
Lua
|
|
-- route player input to the right functions;
|
|
-- return true when the right function has been found
|
|
minetest.register_on_player_receive_fields( function(player, formname, fields)
|
|
if formname == "yl_speak_up:optiondialog" then
|
|
yl_speak_up.input_optiondialog(player, formname, fields)
|
|
return true
|
|
elseif formname == "yl_speak_up:setdialog" then
|
|
yl_speak_up.input_setdialog(player, formname, fields)
|
|
return true
|
|
-- handled in fs_save_or_discard_or_back.lua
|
|
elseif formname == "yl_speak_up:save_or_discard_changes" then
|
|
yl_speak_up.input_save_or_discard_changes(player, formname, fields)
|
|
return true
|
|
-- handled in fs_edit_options_dialog.lua
|
|
elseif formname == "yl_speak_up:edit_option_dialog" then
|
|
yl_speak_up.input_edit_option_dialog(player, formname, fields)
|
|
return true
|
|
elseif formname == "yl_speak_up:talk" then
|
|
yl_speak_up.input_talk(player, formname, fields)
|
|
return true
|
|
elseif formname == "yl_speak_up:fashion" then
|
|
yl_speak_up.input_fashion(player, formname, fields)
|
|
return true
|
|
-- handled in inventory.lua
|
|
elseif formname == "yl_speak_up:inventory" then
|
|
yl_speak_up.input_inventory(player, formname, fields)
|
|
return true
|
|
-- handled in trade_list.lua
|
|
elseif formname == "yl_speak_up:trade_list" then
|
|
yl_speak_up.input_trade_list(player, formname, fields)
|
|
return true
|
|
-- handled in fs_player_offers_item.lua
|
|
elseif formname == "yl_speak_up:player_offers_item" then
|
|
yl_speak_up.input_player_offers_item(player, formname, fields)
|
|
return true
|
|
-- handled in trade_simple.lua
|
|
elseif formname == "yl_speak_up:do_trade_simple" then
|
|
yl_speak_up.input_do_trade_simple(player, formname, fields)
|
|
return true
|
|
-- (as above - also handled in trade_simple.lua)
|
|
elseif formname == "yl_speak_up:add_trade_simple" then
|
|
yl_speak_up.input_add_trade_simple(player, formname, fields)
|
|
return true
|
|
-- handled in fs_initial_config.lua
|
|
elseif formname == "yl_speak_up:initial_config" then
|
|
yl_speak_up.input_fs_initial_config(player, formname, fields)
|
|
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_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_actions.lua
|
|
elseif formname == "yl_speak_up:action_npc_gives" then
|
|
yl_speak_up.input_fs_action_npc_gives(player, formname, fields)
|
|
return true
|
|
elseif formname == "yl_speak_up:action_npc_wants" then
|
|
yl_speak_up.input_fs_action_npc_wants(player, formname, fields)
|
|
return true
|
|
elseif formname == "yl_speak_up:action_text_input" then
|
|
yl_speak_up.input_fs_action_text_input(player, formname, fields)
|
|
return true
|
|
elseif formname == "yl_speak_up:action_custom" then
|
|
yl_speak_up.input_fs_action_custom(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
|
|
-- handled in quest_api.lua
|
|
elseif formname == "yl_speak_up:manage_variables" then
|
|
yl_speak_up.input_fs_manage_variables(player, formname, fields)
|
|
return true
|
|
-- handled in fs_alternate_text.lua
|
|
elseif formname == "yl_speak_up:show_what_points_to_this_dialog" then
|
|
yl_speak_up.input_fs_show_what_points_to_this_dialog(player, formname, fields)
|
|
return true
|
|
end
|
|
end)
|
|
|
|
|
|
-- show formspec with highest possible version information for the player
|
|
-- force_version: optional parameter
|
|
yl_speak_up.show_fs_ver = function(pname, formname, formspec, force_version)
|
|
local fs_ver = (yl_speak_up.fs_version[pname] or "2")
|
|
if(force_version) then
|
|
fs_ver = force_version
|
|
end
|
|
minetest.show_formspec(pname, formname,
|
|
"formspec_version["..tostring(fs_ver).."]"..
|
|
formspec)
|
|
end
|
|
|
|
|
|
-- call show_formspec with the right input_* function for the right formspec
|
|
-- (handles all show_formspec-calls)
|
|
yl_speak_up.show_fs = function(player, fs_name, param)
|
|
if(not(player)) then
|
|
return
|
|
end
|
|
local pname = player:get_player_name()
|
|
if(not(yl_speak_up.speak_to[pname])) then
|
|
return
|
|
end
|
|
|
|
local last_fs = yl_speak_up.speak_to[pname].last_fs
|
|
-- show the save or discard changes dialog
|
|
if(fs_name and fs_name == "save_or_discard_changes") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:save_or_discard_changes",
|
|
yl_speak_up.get_fs_save_or_discard_changes(player, param))
|
|
return
|
|
|
|
-- the player either saved or discarded; we may proceed now
|
|
elseif(fs_name and fs_name == "proceed_after_save") then
|
|
fs_name = yl_speak_up.speak_to[pname].next_fs
|
|
param = yl_speak_up.speak_to[pname].next_fs_param
|
|
yl_speak_up.speak_to[pname].next_fs = nil
|
|
yl_speak_up.speak_to[pname].next_fs_param = nil
|
|
yl_speak_up.speak_to[pname].last_fs = fs_name
|
|
yl_speak_up.speak_to[pname].last_fs_param = param
|
|
if(not(fs_name) or fs_name == "quit") then
|
|
yl_speak_up.reset_vars_for_player(pname, false)
|
|
return
|
|
end
|
|
|
|
-- the player clicked on "back" in the above dialog
|
|
elseif(fs_name and fs_name == "show_last_fs") then
|
|
-- call the last formspec again - and with the same parameters
|
|
fs_name = yl_speak_up.speak_to[pname].last_fs
|
|
param = yl_speak_up.speak_to[pname].last_fs_param
|
|
|
|
-- do we need to check if there is something that needs saving?
|
|
elseif(fs_name
|
|
-- msg is just a loop for displaying (mostly error) messages
|
|
and fs_name ~= "msg"
|
|
and fs_name ~= "player_offers_item"
|
|
-- is the player editing the NPC? that is: might there be any changes?
|
|
and (yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id)) then
|
|
local last_fs = yl_speak_up.speak_to[pname].last_fs
|
|
local d_id = yl_speak_up.speak_to[pname].d_id
|
|
local o_id = yl_speak_up.speak_to[pname].o_id
|
|
-- only these two formspecs need to ask specificly if the data ought to be saved
|
|
if(last_fs == "talk" or last_fs == "edit_option_dialog" or fs_name == "quit") then
|
|
local last_param = yl_speak_up.speak_to[pname].last_fs_param
|
|
local show_save_fs = false
|
|
if(not(param)) then
|
|
param = {}
|
|
end
|
|
-- set the target dialog
|
|
yl_speak_up.speak_to[pname].target_dialog = param.d_id
|
|
-- if we are switching from one dialog to another: is it the same?
|
|
if(last_fs == "talk" and fs_name == last_fs
|
|
and param and param.d_id and param.d_id ~= d_id) then
|
|
-- diffrent parameters: save (if needed)
|
|
show_save_fs = true
|
|
elseif(fs_name == "talk" and param and param.do_save) then
|
|
-- player clicked on save button
|
|
show_save_fs = true
|
|
-- leaving a dialog: save!
|
|
elseif(last_fs == "talk" and fs_name ~= last_fs) then
|
|
show_save_fs = true
|
|
-- clicking on "save" in an edit option dialog: save!
|
|
elseif(last_fs == "edit_option_dialog" and fs_name == last_fs
|
|
and param and param.caller and param.caller == "save_option") then
|
|
show_save_fs = true
|
|
-- leaving editing an option: save!
|
|
elseif(last_fs == "edit_option_dialog" and fs_name ~= last_fs) then
|
|
show_save_fs = true
|
|
-- quitting: save!
|
|
elseif(fs_name == "quit") then
|
|
yl_speak_up.speak_to[pname].target_dialog = nil
|
|
show_save_fs = true
|
|
end
|
|
-- show the save or discard dialog
|
|
if(show_save_fs) then
|
|
yl_speak_up.speak_to[pname].next_fs = fs_name
|
|
yl_speak_up.speak_to[pname].next_fs_param = param
|
|
-- check first if it's necessary to ask for save or discard
|
|
yl_speak_up.input_save_or_discard_changes(player, "", {})
|
|
return
|
|
end
|
|
end
|
|
-- store the new formspec
|
|
yl_speak_up.speak_to[pname].last_fs = fs_name
|
|
-- and its parameter
|
|
yl_speak_up.speak_to[pname].last_fs_param = param
|
|
end
|
|
|
|
-- this is here mostly to fascilitate debugging - so that really all calls to
|
|
-- minetest.show_formspec are routed through here
|
|
if(fs_name == "msg") then
|
|
if(not(param)) then
|
|
param = {}
|
|
end
|
|
yl_speak_up.show_fs_ver(pname, param.input_to, param.formspec)
|
|
|
|
|
|
elseif(fs_name == "quit") then
|
|
return
|
|
|
|
-- staff-based editing
|
|
elseif(fs_name == "optiondialog") then
|
|
if(not(param)) then
|
|
param = {}
|
|
end
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:optiondialog",
|
|
yl_speak_up.get_fs_optiondialog(player, param.n_id, param.d_id, param.o_id, param.p_id, param.r_id))
|
|
|
|
elseif(fs_name == "setdialog") then
|
|
if(not(param)) then
|
|
param = {}
|
|
end
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:setdialog",
|
|
yl_speak_up.get_fs_setdialog(player, param.n_id, param.d_id))
|
|
|
|
elseif(fs_name == "edit_option_dialog") then
|
|
-- the optional "caller" parameter can be used for debugging
|
|
if(not(param)) then
|
|
param = {}
|
|
end
|
|
yl_speak_up.speak_to[pname].o_id = param.o_id
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:edit_option_dialog",
|
|
yl_speak_up.get_fs_edit_option_dialog(player, param.n_id, param.d_id, param.o_id,
|
|
param.caller))
|
|
|
|
elseif(fs_name == "talk") then
|
|
if(not(param)) then
|
|
param = {}
|
|
end
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:talk",
|
|
-- recursion depth from autoanswer: 0 (the player selected manually)
|
|
yl_speak_up.get_fs_talkdialog(player, param.n_id, param.d_id, param.alternate_text,0))
|
|
|
|
elseif(fs_name == "fashion") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:fashion",
|
|
yl_speak_up.get_fs_fashion(pname))
|
|
|
|
elseif(fs_name == "inventory") then
|
|
-- this is a very classical formspec; it works far better with OLD fs;
|
|
-- force formspec version 1
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:inventory",
|
|
yl_speak_up.get_fs_inventory(player),
|
|
1)
|
|
|
|
elseif(fs_name == "trade_list") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:trade_list",
|
|
yl_speak_up.get_fs_trade_list(player, param))
|
|
|
|
elseif(fs_name == "player_offers_item") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:player_offers_item",
|
|
yl_speak_up.get_fs_player_offers_item(player, param))
|
|
|
|
elseif(fs_name == "trade_simple") then
|
|
-- the optional parameter param is the trade_id
|
|
if(not(param) and yl_speak_up.speak_to[pname]) then
|
|
param = yl_speak_up.speak_to[pname].trade_id
|
|
end
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:do_trade_simple",
|
|
yl_speak_up.get_fs_trade_simple(player, param), 1)
|
|
|
|
elseif(fs_name == "add_trade_simple") then
|
|
-- the optional parameter param is the trade_id
|
|
if(not(param) and yl_speak_up.speak_to[pname]) then
|
|
param = yl_speak_up.speak_to[pname].trade_id
|
|
end
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:add_trade_simple",
|
|
yl_speak_up.get_fs_add_trade_simple(player, param), 1)
|
|
|
|
elseif(fs_name == "initial_config") then
|
|
if(not(param)) then
|
|
param = {}
|
|
end
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:initial_config",
|
|
yl_speak_up.get_fs_initial_config(player, param.n_id, param.d_id,
|
|
param.is_initial_config))
|
|
|
|
elseif(fs_name == "edit_preconditions") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:edit_preconditions",
|
|
yl_speak_up.get_fs_edit_preconditions(player, param))
|
|
|
|
elseif(fs_name == "edit_actions") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:edit_actions",
|
|
yl_speak_up.get_fs_edit_actions(player, param))
|
|
|
|
elseif(fs_name == "edit_effects") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:edit_effects",
|
|
yl_speak_up.get_fs_edit_effects(player, param))
|
|
|
|
-- action related
|
|
elseif(fs_name == "action_npc_gives") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:action_npc_gives",
|
|
yl_speak_up.get_fs_action_npc_gives(player, param))
|
|
|
|
elseif(fs_name == "action_npc_wants") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:action_npc_wants",
|
|
yl_speak_up.get_fs_action_npc_wants(player, param))
|
|
|
|
elseif(fs_name == "action_text_input") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:action_text_input",
|
|
yl_speak_up.get_fs_action_text_input(player, param))
|
|
|
|
elseif(fs_name == "action_custom") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:action_custom",
|
|
yl_speak_up.get_fs_action_custom(player, param))
|
|
|
|
elseif(fs_name == "manage_variables") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:manage_variables",
|
|
yl_speak_up.get_fs_manage_variables(player, param))
|
|
|
|
elseif(fs_name == "show_what_points_to_this_dialog") then
|
|
yl_speak_up.show_fs_ver(pname, "yl_speak_up:show_what_points_to_this_dialog",
|
|
yl_speak_up.show_what_points_to_this_dialog(player, param))
|
|
|
|
-- fallback in case of wrong call
|
|
else
|
|
minetest.chat_send_player(pname, "Error: Trying to show wrong "..
|
|
"formspec: \""..tostring(fs_name).."\". Please notify "..
|
|
"an admin.")
|
|
end
|
|
end
|