forked from your-land-mirror/yl_speak_up
added yl_speak_up.show_colored_dialog_text for edit menus
This commit is contained in:
parent
edee560b56
commit
ea5bbb0e7a
@ -1402,10 +1402,15 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
|
|||||||
local on_failure_dialog = ""
|
local on_failure_dialog = ""
|
||||||
if(dialog and dialog.n_dialogs and dialog.n_dialogs[ data.on_failure ]) then
|
if(dialog and dialog.n_dialogs and dialog.n_dialogs[ data.on_failure ]) then
|
||||||
on_failure_dialog =
|
on_failure_dialog =
|
||||||
"label[0.2,5.5;This will switch to dialog "..tostring(data.on_failure)..":]"..
|
"label[0.2,5.5;This will switch to dialog \""..
|
||||||
"hypertext[1.2,6.0;18.0,2.0;d_text;<global background=#776666><normal>"..
|
minetest.formspec_escape(tostring(data.on_failure)).."\""..
|
||||||
minetest.formspec_escape(dialog.n_dialogs[ data.on_failure ].d_text or "?")..
|
yl_speak_up.show_colored_dialog_text(
|
||||||
"\n</normal>]"
|
dialog,
|
||||||
|
data,
|
||||||
|
data.on_failure,
|
||||||
|
"1.2,5.8;18.0,2.0;d_text;",
|
||||||
|
", but with the following *modified* text",
|
||||||
|
":]")
|
||||||
end
|
end
|
||||||
formspec = formspec..
|
formspec = formspec..
|
||||||
"label[0.2,3.3;If the *previous* effect failed,]"..
|
"label[0.2,3.3;If the *previous* effect failed,]"..
|
||||||
@ -1633,18 +1638,68 @@ yl_speak_up.set_on_action_failure_dialog = function(pname, data, instruction)
|
|||||||
if(data and data.action_failure_dialog) then
|
if(data and data.action_failure_dialog) then
|
||||||
nr = data.action_failure_dialog + 1
|
nr = data.action_failure_dialog + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
|
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
|
||||||
local on_failure_dialog =
|
local on_failure_dialog =
|
||||||
"label[0.2,9.9;"..tostring(instruction).." If he doesn't, go to dialog:]"..
|
"label[0.2,9.9;"..tostring(instruction).." If he doesn't, go to dialog:]"..
|
||||||
"dropdown[11.0,9.6;2.8,0.6;select_on_action_failure;"..
|
"dropdown[11.0,9.6;2.7,0.6;select_on_action_failure;"..
|
||||||
"- current one -,"..
|
"- current one -,"..
|
||||||
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"
|
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"
|
||||||
if(nr and nr > 1) then
|
if(nr and nr > 1) then
|
||||||
local failure_d_id = sorted_dialog_list[ nr - 1]
|
return on_failure_dialog..
|
||||||
on_failure_dialog = on_failure_dialog..
|
yl_speak_up.show_colored_dialog_text(
|
||||||
"hypertext[1.2,10.2.0;18.0,1.8;d_text;<global background=#776666><normal>"..
|
dialog,
|
||||||
minetest.formspec_escape(dialog.n_dialogs[ failure_d_id ].d_text or "?")..
|
data,
|
||||||
"\n</normal>]"
|
sorted_dialog_list[ nr - 1],
|
||||||
|
"1.2,10.2.0;18.0,1.8;d_text",
|
||||||
|
"label[13.8,9.9;and show the following *modified* text:]",
|
||||||
|
"")
|
||||||
end
|
end
|
||||||
return on_failure_dialog
|
return on_failure_dialog
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
yl_speak_up.show_colored_dialog_text = function(dialog, data, d_id, hypertext_pos, alternate_text, postfix)
|
||||||
|
if(not(data)) then
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
-- if(math.random(1,2)==1) then data.alternate_text = "This is an alternate text.\n$TEXT$" end
|
||||||
|
-- slightly red in order to indicate that this is an on_failure dialog
|
||||||
|
local color = "776666"
|
||||||
|
-- ..except for normal redirecting to the next dialog with the dialog effect
|
||||||
|
-- (slightly yellow there)
|
||||||
|
if(data.r_id and data.r_type and data.r_type == "dialog") then
|
||||||
|
color = "777766"
|
||||||
|
end
|
||||||
|
local add_info_alternate_text = ""
|
||||||
|
local text = ""
|
||||||
|
if(dialog and dialog.n_dialogs and dialog.n_dialogs[ d_id ]) then
|
||||||
|
text = dialog.n_dialogs[ d_id ].d_text
|
||||||
|
end
|
||||||
|
if(data and data.alternate_text and data.alternate_text ~= "") then
|
||||||
|
add_info_alternate_text = alternate_text
|
||||||
|
-- replace $TEXT$ with the normal dialog text and make the new text yellow
|
||||||
|
text = "<style color=#FFFF00>"..
|
||||||
|
string.gsub(
|
||||||
|
data.alternate_text,
|
||||||
|
"%$TEXT%$",
|
||||||
|
"<style color=#FFFFFF>"..text.."</style>")..
|
||||||
|
"</style>"
|
||||||
|
-- slightly blue in order to indicate that this is a modified text
|
||||||
|
color = "333366"
|
||||||
|
end
|
||||||
|
-- display the variables in orange
|
||||||
|
text = yl_speak_up.replace_vars_in_text(text,
|
||||||
|
-- fake dialog; just adds the colors
|
||||||
|
-- also MY_NAME..but we can easily replace just one
|
||||||
|
{ n_npc = "<style color=#FF8800>$NPC_NAME$</style>",
|
||||||
|
npc_owner = "<style color=#FF8800>$OWNER_NAME$</style>"},
|
||||||
|
-- pname
|
||||||
|
"<style color=#FF8800>$PLAYER_NAME$</style>")
|
||||||
|
|
||||||
|
return add_info_alternate_text..
|
||||||
|
postfix..
|
||||||
|
"hypertext["..hypertext_pos..";<global background=#"..color.."><normal>"..
|
||||||
|
minetest.formspec_escape(text or "?")..
|
||||||
|
"\n</normal>]"
|
||||||
|
end
|
||||||
|
@ -186,6 +186,9 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
|
|||||||
|
|
||||||
-- find the right target dialog for this option (if it exists)
|
-- find the right target dialog for this option (if it exists)
|
||||||
local target_dialog = nil
|
local target_dialog = nil
|
||||||
|
-- which effect holds the information about the target dialog?
|
||||||
|
-- set this to a fallback for yl_speak_up.show_colored_dialog_text
|
||||||
|
local target_effect = {r_id = "-?-", r_type = "dialog"}
|
||||||
-- and build the list of effects
|
-- and build the list of effects
|
||||||
local list_of_effects = ""
|
local list_of_effects = ""
|
||||||
local results = d_option.o_results
|
local results = d_option.o_results
|
||||||
@ -202,6 +205,7 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
|
|||||||
yl_speak_up.show_effect(v))..","
|
yl_speak_up.show_effect(v))..","
|
||||||
-- there may be more than one in the data structure
|
-- there may be more than one in the data structure
|
||||||
target_dialog = v.r_value
|
target_dialog = v.r_value
|
||||||
|
target_effect = v
|
||||||
elseif v.r_type ~= "dialog" then
|
elseif v.r_type ~= "dialog" then
|
||||||
list_of_effects = list_of_effects..
|
list_of_effects = list_of_effects..
|
||||||
minetest.formspec_escape(v.r_id)..",#FFFF00,"..
|
minetest.formspec_escape(v.r_id)..",#FFFF00,"..
|
||||||
@ -227,11 +231,6 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- this is the text the NPC will say in reaction to this answer
|
|
||||||
local next_text = ""
|
|
||||||
if(target_dialog and dialog.n_dialogs[target_dialog]) then
|
|
||||||
next_text = dialog.n_dialogs[target_dialog].d_text
|
|
||||||
end
|
|
||||||
-- build the list of available dialogs for the dropdown list(s)
|
-- build the list of available dialogs for the dropdown list(s)
|
||||||
local dialog_list = yl_speak_up.text_new_dialog_id
|
local dialog_list = yl_speak_up.text_new_dialog_id
|
||||||
local dialog_selected = "1"
|
local dialog_selected = "1"
|
||||||
@ -312,14 +311,18 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
|
|||||||
and dialog.n_dialogs and dialog.n_dialogs[ action_data.a_on_failure]) then
|
and dialog.n_dialogs and dialog.n_dialogs[ action_data.a_on_failure]) then
|
||||||
action_text = action_text..
|
action_text = action_text..
|
||||||
-- ..and what the NPC will reply to that answer
|
-- ..and what the NPC will reply to that answer
|
||||||
|
"tooltip[1.2,15.5;19.6,2.5;This is what the NPC will say next when "..
|
||||||
|
"the player has failed to complete the action.]"..
|
||||||
"label[0.2,15.1;..the NPC will react to this failed action with the "..
|
"label[0.2,15.1;..the NPC will react to this failed action with the "..
|
||||||
"following dialog \""..tostring(action_data.a_on_failure).."\":]"..
|
"following dialog \""..tostring(action_data.a_on_failure)..
|
||||||
"hypertext[1.2,15.5;19.6,2.5;d_text_next;<global background=#776666>"..
|
"\""..
|
||||||
"<normal>"..minetest.formspec_escape(tostring(
|
yl_speak_up.show_colored_dialog_text(
|
||||||
dialog.n_dialogs[ action_data.a_on_failure ].d_text))..
|
dialog,
|
||||||
"\n</normal>]"..
|
action_data,
|
||||||
"tooltip[1.2,16.8;21.0,2.5;This is what the NPC will say next when "..
|
action_data.a_on_failure,
|
||||||
"the player has failed to complete the action.]"
|
"1.2,15.5;19.6,2.5;d_text_next",
|
||||||
|
"with the *modified* text",
|
||||||
|
":]")
|
||||||
else
|
else
|
||||||
action_text = action_text..
|
action_text = action_text..
|
||||||
"label[0.2,15.1;..go back to the initial dialog.]"
|
"label[0.2,15.1;..go back to the initial dialog.]"
|
||||||
@ -338,17 +341,24 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
|
|||||||
"selected.\n"..
|
"selected.\n"..
|
||||||
"Please click on an (Ef)fect in order to edit or delete it!]"..
|
"Please click on an (Ef)fect in order to edit or delete it!]"..
|
||||||
-- allow to change the target dialog via a dropdown menu
|
-- allow to change the target dialog via a dropdown menu
|
||||||
"dropdown[12.5,14.7;7.5,0.7;d_id_"..minetest.formspec_escape(o_id)..";"..
|
"dropdown[12.3,14.7;2.8,0.7;d_id_"..minetest.formspec_escape(o_id)..";"..
|
||||||
dialog_list..";"..dialog_selected..",]"..
|
dialog_list..";"..dialog_selected..",]"..
|
||||||
"tooltip[12.5,14.7;7.5,0.7;Select the target dialog with which the NPC shall react "..
|
"tooltip[12.3,14.7;2.8,0.7;Select the target dialog with which the NPC shall react "..
|
||||||
"to this answer. Currently, dialog "..minetest.formspec_escape(target_dialog)..
|
"to this answer. Currently, dialog \""..minetest.formspec_escape(target_dialog)..
|
||||||
" is beeing displayed.;#FFFFFF;#000000]"..
|
"\" is beeing displayed.;#FFFFFF;#000000]"..
|
||||||
-- ..and what the NPC will reply to that answer
|
-- ..and what the NPC will reply to that answer
|
||||||
|
"tooltip[1.2,15.5;19.6,2.5;This is what the NPC will say next when the player has "..
|
||||||
|
"selected this answer here.]"..
|
||||||
"label[0.2,15.1;The NPC will react to this answer with the following dialog:]"..
|
"label[0.2,15.1;The NPC will react to this answer with the following dialog:]"..
|
||||||
"hypertext[1.2,15.5;19.6,2.5;d_text_next;<global background=#777766><normal>"..
|
yl_speak_up.show_colored_dialog_text(
|
||||||
minetest.formspec_escape(next_text) .. "\n</normal>]"..
|
dialog,
|
||||||
"tooltip[1.2,16.8;21.0,2.5;This is what the NPC will say next when the player has "..
|
-- this is either the "dialog" effect or an empty fallback
|
||||||
"selected this answer here.]"
|
target_effect,
|
||||||
|
-- this is the text the NPC will say in reaction to this answer
|
||||||
|
target_dialog,
|
||||||
|
"1.2,15.5;19.6,2.5;d_text",
|
||||||
|
"label[15.2,15.1;with the *modified* text:]",
|
||||||
|
"")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- build up the formspec
|
-- build up the formspec
|
||||||
@ -366,8 +376,13 @@ yl_speak_up.get_fs_edit_option_dialog = function(player, n_id, d_id, o_id, calle
|
|||||||
-- the text the NPC says
|
-- the text the NPC says
|
||||||
"label[0.2,0.6;NPC says "..
|
"label[0.2,0.6;NPC says "..
|
||||||
minetest.formspec_escape("[dialog \""..tostring(d_id).."\"]:").."]"..
|
minetest.formspec_escape("[dialog \""..tostring(d_id).."\"]:").."]"..
|
||||||
"hypertext[1.2,1.2;19.6,2.5;d_text;<global background=#777766><normal>"..
|
yl_speak_up.show_colored_dialog_text(
|
||||||
minetest.formspec_escape(n_dialog.d_text) .. "\n</normal>]"..
|
dialog,
|
||||||
|
target_effect,
|
||||||
|
d_id,
|
||||||
|
"1.2,1.2;19.6,2.5;d_text",
|
||||||
|
"", -- no modifications possible at this step
|
||||||
|
"")..
|
||||||
"tooltip[1.2,1.2;19.6,3.0;This is what the NPC says to the player.]"..
|
"tooltip[1.2,1.2;19.6,3.0;This is what the NPC says to the player.]"..
|
||||||
-- list the preconditions
|
-- list the preconditions
|
||||||
"label[0.2,4.2;If all of the following pre(C)onditions are fulfilled:]"..
|
"label[0.2,4.2;If all of the following pre(C)onditions are fulfilled:]"..
|
||||||
|
Loading…
Reference in New Issue
Block a user