diff --git a/fs_edit_general.lua b/fs_edit_general.lua index 0c82917..dd41af7 100644 --- a/fs_edit_general.lua +++ b/fs_edit_general.lua @@ -972,12 +972,18 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, local dialog = yl_speak_up.speak_to[pname].dialog local element = dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ][ x_id ] if(element and element[ id_prefix.."variable"]) then - -- TODO: actually implement/show usage of the variable as formspec + local effect_name = "(Ef)fect" + if(id_prefix == "p_") then + effect_name = "pre(C)ondition" + end yl_speak_up.show_fs(player, "msg", { input_to = "yl_speak_up:"..formspec_input_to, formspec = yl_speak_up.get_list_of_usage_of_variable( element[ id_prefix.."variable"], pname, true, - "back_from_show_var_usage") + "back_from_show_var_usage", + "Back to select "..effect_name.." "..tostring(x_id).. + " of option "..tostring(o_id).. + " of dialog "..tostring(d_id)) }) return end @@ -985,13 +991,23 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields, elseif(fields.show_var_usage_edit_element and x_id) then local dialog = yl_speak_up.speak_to[pname].dialog local element = dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ][ x_id ] + if(not(element) or data.variable_name) then + element = {} + element[ id_prefix.."variable"] = data.variable_name + end if(element and element[ id_prefix.."variable"]) then - -- TODO: actually implement/show usage of the variable as formspec + local effect_name = "(Ef)fect" + if(id_prefix == "p_") then + effect_name = "pre(C)ondition" + end yl_speak_up.show_fs(player, "msg", { input_to = "yl_speak_up:"..formspec_input_to, formspec = yl_speak_up.get_list_of_usage_of_variable( element[ id_prefix.."variable"], pname, true, - "back_from_error_msg") + "back_from_error_msg", + "Back to select "..effect_name.." "..tostring(x_id).. + " of option "..tostring(o_id).. + " of dialog "..tostring(d_id)) }) return end diff --git a/quest_api.lua b/quest_api.lua index 29194bb..b410849 100644 --- a/quest_api.lua +++ b/quest_api.lua @@ -387,7 +387,8 @@ end -- find out where this variable is used in NPCs -yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_preconditions, back_button_name) +yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_preconditions, + back_button_name, back_button_text) -- which NPC (might be several) is using this variable? local npc_list = yl_speak_up.get_npc_users_of_variable(var_name) -- list of all relevant preconditions, actions and effects @@ -401,6 +402,7 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec for o_id, o in pairs(d.d_options) do local p_text = "" local r_text = "" + local sort_value = 0 if(o and o.o_prerequisites and check_preconditions) then for p_id, p in pairs(o.o_prerequisites) do if(p and p.p_type and p.p_type == "state" @@ -411,6 +413,7 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec minetest.formspec_escape(p.p_type)..",#FFFF00,".. minetest.formspec_escape( yl_speak_up.show_precondition(p, pname)) + sort_value = (p.p_var_cmp_value or 0) end end end @@ -424,6 +427,9 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec minetest.formspec_escape(r.r_type)..",#55FF55,".. minetest.formspec_escape( yl_speak_up.show_effect(r, pname)) + -- values set in the results are more important than + -- those set in preconditions + sort_value = (r.r_var_cmp_value or 0) end end end @@ -444,7 +450,7 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec -- show newlines as <\n> in order to save space local d_text = string.gsub( dialog.n_dialogs[ d_id ].d_text or "?", - "\n", "<"..minetest.formspec_escape("\\").."n>") + "\n", minetest.formspec_escape("
")) -- break the text up into lines of length x local parts = minetest.wrap_text(d_text, 80, true) -- only show the first two lines (we don't have infinite room) @@ -465,7 +471,8 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec prefix..minetest.formspec_escape(parts[3]).. minetest.formspec_escape(" [...]") end - table.insert(res, + res[ tostring(n_id).." "..tostring(d_id).." "..tostring(o_id) ] = { + text = "#6666FF,".. tostring(n_id)..",#6666FF,NPC,#6666FF,named:,#6666FF,".. minetest.formspec_escape(dialog.n_npc or "?")..",".. @@ -476,7 +483,8 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec tostring(o_id)..",#FFFFFF,Option,#FFFFFF,A:,#FFFFFF,".. minetest.formspec_escape(tostring( o.o_text_when_prerequisites_met or "?")).. - p_text..r_text) + p_text..r_text, + sort_value = sort_value} end end end @@ -484,17 +492,24 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec end end + local sorted_list = yl_speak_up.get_sorted_options(res, "sort_value") + local sorted_res = {} + for i, k in pairs(sorted_list) do + table.insert(sorted_res, res[ k ].text) + end local formspec = { "formspec_version[3]", "size[57,33]", -- back to the list with that one precondition or effect - -- TODO: give this button a better description (back to where?) - "button[0.2,0.2;2,0.9;"..back_button_name..";Back]", + "button[0.2,0.2;56.6,1.2;"..back_button_name..";".. + minetest.formspec_escape(back_button_text).."]", + "button[0.2,31.6;56.6,1.2;"..back_button_name..";".. + minetest.formspec_escape(back_button_text).."]", -- type x_id color type text "tablecolumns[color,span=1;text;color,span=1;text;color,span=1;text;color,span=1;text]", - "table[1.2,1.2;55.0,30.0;table_of_variable_uses;" + "table[1.2,1.4;55.0,30.0;table_of_variable_uses;" } -- insert blank lines between lines belonging together - table.insert(formspec, table.concat(res, ",#FFFFFF,,#FFFFFF,,#FFFFFF,,#FFFFFF,,")) + table.insert(formspec, table.concat(sorted_res, ",#FFFFFF,,#FFFFFF,,#FFFFFF,,#FFFFFF,,")) return table.concat(formspec, "\n") end