forked from Sokomine/yl_speak_up
yl_speak_up.get_list_of_usage_of_variable is now sorted by the value the variable is set to
This commit is contained in:
parent
c2402ccaed
commit
85a9a50d38
@ -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 dialog = yl_speak_up.speak_to[pname].dialog
|
||||||
local element = dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ][ x_id ]
|
local element = dialog.n_dialogs[d_id].d_options[o_id][ element_list_name ][ x_id ]
|
||||||
if(element and element[ id_prefix.."variable"]) then
|
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", {
|
yl_speak_up.show_fs(player, "msg", {
|
||||||
input_to = "yl_speak_up:"..formspec_input_to,
|
input_to = "yl_speak_up:"..formspec_input_to,
|
||||||
formspec = yl_speak_up.get_list_of_usage_of_variable(
|
formspec = yl_speak_up.get_list_of_usage_of_variable(
|
||||||
element[ id_prefix.."variable"], pname, true,
|
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
|
return
|
||||||
end
|
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
|
elseif(fields.show_var_usage_edit_element and x_id) then
|
||||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
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 ]
|
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
|
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", {
|
yl_speak_up.show_fs(player, "msg", {
|
||||||
input_to = "yl_speak_up:"..formspec_input_to,
|
input_to = "yl_speak_up:"..formspec_input_to,
|
||||||
formspec = yl_speak_up.get_list_of_usage_of_variable(
|
formspec = yl_speak_up.get_list_of_usage_of_variable(
|
||||||
element[ id_prefix.."variable"], pname, true,
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@ -387,7 +387,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- find out where this variable is used in NPCs
|
-- 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?
|
-- which NPC (might be several) is using this variable?
|
||||||
local npc_list = yl_speak_up.get_npc_users_of_variable(var_name)
|
local npc_list = yl_speak_up.get_npc_users_of_variable(var_name)
|
||||||
-- list of all relevant preconditions, actions and effects
|
-- 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
|
for o_id, o in pairs(d.d_options) do
|
||||||
local p_text = ""
|
local p_text = ""
|
||||||
local r_text = ""
|
local r_text = ""
|
||||||
|
local sort_value = 0
|
||||||
if(o and o.o_prerequisites and check_preconditions) then
|
if(o and o.o_prerequisites and check_preconditions) then
|
||||||
for p_id, p in pairs(o.o_prerequisites) do
|
for p_id, p in pairs(o.o_prerequisites) do
|
||||||
if(p and p.p_type and p.p_type == "state"
|
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(p.p_type)..",#FFFF00,"..
|
||||||
minetest.formspec_escape(
|
minetest.formspec_escape(
|
||||||
yl_speak_up.show_precondition(p, pname))
|
yl_speak_up.show_precondition(p, pname))
|
||||||
|
sort_value = (p.p_var_cmp_value or 0)
|
||||||
end
|
end
|
||||||
end
|
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(r.r_type)..",#55FF55,"..
|
||||||
minetest.formspec_escape(
|
minetest.formspec_escape(
|
||||||
yl_speak_up.show_effect(r, pname))
|
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
|
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
|
-- show newlines as <\n> in order to save space
|
||||||
local d_text = string.gsub(
|
local d_text = string.gsub(
|
||||||
dialog.n_dialogs[ d_id ].d_text or "?",
|
dialog.n_dialogs[ d_id ].d_text or "?",
|
||||||
"\n", "<"..minetest.formspec_escape("\\").."n>")
|
"\n", minetest.formspec_escape("<br>"))
|
||||||
-- break the text up into lines of length x
|
-- break the text up into lines of length x
|
||||||
local parts = minetest.wrap_text(d_text, 80, true)
|
local parts = minetest.wrap_text(d_text, 80, true)
|
||||||
-- only show the first two lines (we don't have infinite room)
|
-- 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])..
|
prefix..minetest.formspec_escape(parts[3])..
|
||||||
minetest.formspec_escape(" [...]")
|
minetest.formspec_escape(" [...]")
|
||||||
end
|
end
|
||||||
table.insert(res,
|
res[ tostring(n_id).." "..tostring(d_id).." "..tostring(o_id) ] = {
|
||||||
|
text =
|
||||||
"#6666FF,"..
|
"#6666FF,"..
|
||||||
tostring(n_id)..",#6666FF,NPC,#6666FF,named:,#6666FF,"..
|
tostring(n_id)..",#6666FF,NPC,#6666FF,named:,#6666FF,"..
|
||||||
minetest.formspec_escape(dialog.n_npc or "?")..","..
|
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,"..
|
tostring(o_id)..",#FFFFFF,Option,#FFFFFF,A:,#FFFFFF,"..
|
||||||
minetest.formspec_escape(tostring(
|
minetest.formspec_escape(tostring(
|
||||||
o.o_text_when_prerequisites_met or "?"))..
|
o.o_text_when_prerequisites_met or "?"))..
|
||||||
p_text..r_text)
|
p_text..r_text,
|
||||||
|
sort_value = sort_value}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -484,17 +492,24 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec
|
|||||||
end
|
end
|
||||||
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 = {
|
local formspec = {
|
||||||
"formspec_version[3]",
|
"formspec_version[3]",
|
||||||
"size[57,33]",
|
"size[57,33]",
|
||||||
-- back to the list with that one precondition or effect
|
-- 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;56.6,1.2;"..back_button_name..";"..
|
||||||
"button[0.2,0.2;2,0.9;"..back_button_name..";Back]",
|
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
|
-- type x_id color type text
|
||||||
"tablecolumns[color,span=1;text;color,span=1;text;color,span=1;text;color,span=1;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
|
-- 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")
|
return table.concat(formspec, "\n")
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user