forked from your-land-mirror/yl_speak_up
show variable usage (nicely colored)
This commit is contained in:
parent
82e4d37436
commit
c2402ccaed
@ -975,10 +975,10 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
|||||||
-- TODO: actually implement/show usage of the variable as formspec
|
-- TODO: actually implement/show usage of the variable as formspec
|
||||||
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 = "size[9,2]"..
|
formspec = yl_speak_up.get_list_of_usage_of_variable(
|
||||||
"label[0.2,0.5;This ought to show usage of a variable.]"..
|
element[ id_prefix.."variable"], pname, true,
|
||||||
-- back to the list with that one precondition or effect
|
"back_from_show_var_usage")
|
||||||
"button[1.5,1.5;2,0.9;back_from_show_var_usage;Back]"})
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- show var usuage - but this time from the edit dialog for that precondition or effect
|
-- show var usuage - but this time from the edit dialog for that precondition or effect
|
||||||
@ -989,10 +989,10 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
|
|||||||
-- TODO: actually implement/show usage of the variable as formspec
|
-- TODO: actually implement/show usage of the variable as formspec
|
||||||
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 = "size[9,2]"..
|
formspec = yl_speak_up.get_list_of_usage_of_variable(
|
||||||
"label[0.2,0.5;This ought to show usage of a variable.]"..
|
element[ id_prefix.."variable"], pname, true,
|
||||||
-- back to editing that particular precondition or effect
|
"back_from_error_msg")
|
||||||
"button[1.5,1.5;2,0.9;back_from_error_msg;Back]"})
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
105
quest_api.lua
105
quest_api.lua
@ -387,7 +387,7 @@ 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)
|
yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_preconditions, back_button_name)
|
||||||
-- 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
|
||||||
@ -399,23 +399,18 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec
|
|||||||
for d_id, d in pairs(dialog.n_dialogs) do
|
for d_id, d in pairs(dialog.n_dialogs) do
|
||||||
if(d and d.d_options) then
|
if(d and d.d_options) then
|
||||||
for o_id, o in pairs(d.d_options) do
|
for o_id, o in pairs(d.d_options) do
|
||||||
-- if preconditions or effects apply: show the action as well
|
local p_text = ""
|
||||||
local show_action = false
|
local r_text = ""
|
||||||
local text = "\n"..
|
|
||||||
tostring(n_id)..":"..tostring(d_id)..":"..tostring(o_id)..":"..
|
|
||||||
"\tTo "..tostring(dialog.n_npc)..": "..
|
|
||||||
tostring(o.o_text_when_prerequisites_met)
|
|
||||||
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"
|
||||||
and p.p_variable and p.p_variable == var_name) then
|
and p.p_variable and p.p_variable == var_name) then
|
||||||
if(text) then
|
p_text = p_text..",#FFFF00,"..
|
||||||
table.insert(res, text)
|
minetest.formspec_escape(tostring(p_id))..
|
||||||
text = nil
|
",#FFFF00,pre(C)ondition,#FFFF00,"..
|
||||||
end
|
minetest.formspec_escape(p.p_type)..",#FFFF00,"..
|
||||||
table.insert(res, "\t\tC: "..tostring(p_id).." "..
|
minetest.formspec_escape(
|
||||||
yl_speak_up.show_precondition(p, pname))
|
yl_speak_up.show_precondition(p, pname))
|
||||||
show_action = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -423,29 +418,83 @@ yl_speak_up.get_list_of_usage_of_variable = function(var_name, pname, check_prec
|
|||||||
for r_id, r in pairs(o.o_results) do
|
for r_id, r in pairs(o.o_results) do
|
||||||
if(r and r.r_type and r.r_type == "state"
|
if(r and r.r_type and r.r_type == "state"
|
||||||
and r.r_variable and r.r_variable == var_name) then
|
and r.r_variable and r.r_variable == var_name) then
|
||||||
if(text) then
|
r_text = r_text..",#55FF55,"..
|
||||||
table.insert(res, text)
|
minetest.formspec_escape(tostring(r_id))..
|
||||||
text = nil
|
",#55FF55,(Ef)fect,#55FF55,"..
|
||||||
end
|
minetest.formspec_escape(r.r_type)..",#55FF55,"..
|
||||||
table.insert(res, "\t\tE: "..tostring(r_id).." "..
|
minetest.formspec_escape(
|
||||||
yl_speak_up.show_effect(r, pname))
|
yl_speak_up.show_effect(r, pname))
|
||||||
show_action = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if(o and o.actions and show_action) then
|
-- if preconditions or effects apply: show the action as well
|
||||||
|
if(o and o.actions and (p_text ~= "" or r_text ~= "")) then
|
||||||
for a_id, a in pairs(o.actions) do
|
for a_id, a in pairs(o.actions) do
|
||||||
table.insert(res, "\t\tA: "..tostring(a_id).." "..
|
-- no need to introduce an a_text; this will follow
|
||||||
yl_speak_up.show_action(a, pname))
|
-- directly after p_text, and p_text is finished
|
||||||
|
p_text = p_text..",FF9900,"..
|
||||||
|
minetest.formspec_escape(tostring(a_id))..
|
||||||
|
",#FF9900,(A)ction,#FF9900,"..
|
||||||
|
minetest.formspec_escape(a.a_type)..",#FF9900,"..
|
||||||
|
minetest.formspec_escape(
|
||||||
|
yl_speak_up.show_action(a, pname))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if(p_text ~= "" or r_text ~= "") then
|
||||||
|
-- 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>")
|
||||||
|
-- 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)
|
||||||
|
local prefix = ",#FFFFFF,,#FFFFFF,,#FFFFFF,,#BBBBFF,"
|
||||||
|
if(#parts < 2) then
|
||||||
|
d_text = minetest.formspec_escape(parts[1])
|
||||||
|
elseif(#parts == 2) then
|
||||||
|
d_text = minetest.formspec_escape(parts[1])..
|
||||||
|
prefix..minetest.formspec_escape(parts[2])
|
||||||
|
elseif(#parts == 3) then
|
||||||
|
d_text = minetest.formspec_escape(parts[1])..
|
||||||
|
prefix..minetest.formspec_escape(parts[2])..
|
||||||
|
prefix..minetest.formspec_escape(parts[3])
|
||||||
|
else
|
||||||
|
-- indicate that there is more
|
||||||
|
d_text = minetest.formspec_escape(parts[1])..
|
||||||
|
prefix..minetest.formspec_escape(parts[2])..
|
||||||
|
prefix..minetest.formspec_escape(parts[3])..
|
||||||
|
minetest.formspec_escape(" [...]")
|
||||||
|
end
|
||||||
|
table.insert(res,
|
||||||
|
"#6666FF,"..
|
||||||
|
tostring(n_id)..",#6666FF,NPC,#6666FF,named:,#6666FF,"..
|
||||||
|
minetest.formspec_escape(dialog.n_npc or "?")..","..
|
||||||
|
"#BBBBFF,"..
|
||||||
|
tostring(d_id)..",#BBBBFF,Dialog,#BBBBFF,says:,#BBBBFF,"..
|
||||||
|
d_text..","..
|
||||||
|
"#FFFFFF,"..
|
||||||
|
tostring(o_id)..",#FFFFFF,Option,#FFFFFF,A:,#FFFFFF,"..
|
||||||
|
minetest.formspec_escape(tostring(
|
||||||
|
o.o_text_when_prerequisites_met or "?"))..
|
||||||
|
p_text..r_text)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i, line in ipairs(res) do
|
|
||||||
--minetest.chat_send_player("singleplayer", line)
|
local formspec = {
|
||||||
print(line) -- TODO
|
"formspec_version[3]",
|
||||||
end
|
"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]",
|
||||||
|
-- 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;"
|
||||||
|
}
|
||||||
|
-- insert blank lines between lines belonging together
|
||||||
|
table.insert(formspec, table.concat(res, ",#FFFFFF,,#FFFFFF,,#FFFFFF,,#FFFFFF,,"))
|
||||||
|
return table.concat(formspec, "\n")
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user