used fs_decorated in fs_talkdialog as well

This commit is contained in:
Sokomine 2022-04-12 01:53:08 +02:00
parent d466436c34
commit 52d04e36e8
3 changed files with 17 additions and 148 deletions

View File

@ -147,7 +147,8 @@ end
yl_speak_up.show_fs_decorated = function(pname, edit_mode, h,
alternate_text,
add_this_to_left_window,
add_this_to_bottom_window)
add_this_to_bottom_window,
active_dialog)
if(not(pname)) then
return ""
end

View File

@ -389,84 +389,11 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
yl_speak_up.speak_to[pname].allowed = allowed
local portrait = yl_speak_up.calculate_portrait(pname, n_id)
local formspec_v = minetest.get_player_information(pname).formspec_version
local protocol_v = minetest.get_player_information(pname).protocol_version
local formspec = {}
local h
-- show who owns the NPC (and is thus more or less responsible for what it says)
local owner_info = ""
if(yl_speak_up.npc_owner[ n_id ]) then
owner_info = "\n\n(owned by "..minetest.formspec_escape(yl_speak_up.npc_owner[ n_id ])..")"
end
local pname_for_old_fs = yl_speak_up.get_pname_for_old_fs(pname)
local fs_version = yl_speak_up.fs_version[pname]
if(not(fs_version)) then
if formspec_v >= 4 then
fs_version = 3
elseif formspec_v >= 2 then
fs_version = 2
else
fs_version = 1
end
-- store which formspec version the player has
yl_speak_up.fs_version[pname] = fs_version
end
formspec = {
"size[57,33]",
"position[0,0.45]",
"anchor[0,0.45]",
"no_prepend[]",
"bgcolor[#00000000;false]",
-- Container
"container[2,0.75]",
-- Background
"background[0,0;20,23;yl_speak_up_bg_dialog.png;false]",
"background[0,24;54.5,7.5;yl_speak_up_bg_dialog.png;false]",
-- Frame Dialog
"image[-0.25,-0.25;1,1;yl_speak_up_bg_dialog_tl.png]",
"image[-0.25,22.25;1,1;yl_speak_up_bg_dialog_bl.png]",
"image[19.25,-0.25;1,1;yl_speak_up_bg_dialog_tr.png]",
"image[19.25,22.25;1,1;yl_speak_up_bg_dialog_br.png]",
"image[-0.25,0.75;1,21.5;yl_speak_up_bg_dialog_hl.png]",
"image[19.25,0.75;1,21.5;yl_speak_up_bg_dialog_hr.png]",
"image[0.75,-0.25;18.5,1;yl_speak_up_bg_dialog_vt.png]",
"image[0.75,22.25;18.5,1;yl_speak_up_bg_dialog_vb.png]",
-- Frame Options
"image[-0.25,23.75;1,1;yl_speak_up_bg_dialog_tl.png]",
"image[-0.25,30.75;1,1;yl_speak_up_bg_dialog_bl.png]",
"image[53.75,23.75;1,1;yl_speak_up_bg_dialog_tr.png]",
"image[53.75,30.75;1,1;yl_speak_up_bg_dialog_br.png]",
"image[-0.25,24.75;1,6;yl_speak_up_bg_dialog_hl.png]",
"image[53.75,24.75;1,6;yl_speak_up_bg_dialog_hr.png]",
"image[0.75,23.75;53,1;yl_speak_up_bg_dialog_vt.png]",
"image[0.75,30.75;53,1;yl_speak_up_bg_dialog_vb.png]",
"label[0.3,0.6;",
minetest.formspec_escape(dialog.n_npc),
"]",
"label[0.3,1.8;",
minetest.formspec_escape(dialog.n_description)..owner_info,
"]",
"image[15.5,0.5;4,4;",
portrait,
"]",
}
-- add those things that only exist in formspec_v >= 4
if(fs_version > 2) then
table.insert(formspec, "style_type[button;bgcolor=#a37e45]")
table.insert(formspec, "style_type[button_exit;bgcolor=#a37e45]") -- Dialog
-- table.insert(formspec, "background[-1,-1;22,25;yl_speak_up_bg_dialog2.png;false]")
-- table.insert(formspec, "background[-1,23;58,10;yl_speak_up_bg_dialog2.png;false]")
-- table.insert(formspec, "style_type[button;bgcolor=#a37e45]")
end
formspec = {}
local h
-- this is used to build a list of all available dialogs for a dropdown menu in edit mode
-- (only relevant in edit mode)
@ -530,65 +457,13 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
table.insert(formspec, "textarea[0.2,5;19.6,17.8;d_text;;"..
minetest.formspec_escape(active_dialog.d_text)..
"]")
else
if(alternate_text) then
alternate_text = string.gsub(alternate_text, "%$TEXT%$", active_dialog.d_text)
end
-- replace $NPC_NAME$ etc.
local t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
(alternate_text or active_dialog.d_text), dialog, pname))
if(fs_version > 2) then
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"hypertext", "0.2,5;19.6,17.8", "d_text",
"<normal>"..t.."\n</normal>",
t:trim()..";#000000;#FFFFFF",
true)
else
yl_speak_up.add_formspec_element_with_tooltip_if(formspec,
"textarea", "0.2,5;19.6,17.8", "",
";"..t.."\n",
t:trim(),
true)
end
end
local pname_for_old_fs = nil
if(fs_version > 2) then
table.insert(formspec, "scrollbaroptions[min=0;max=14;smallstep=1;largestep=2;arrows=show]")
table.insert(formspec, "scrollbar[0.2,24.2;0.2,7;vertical;scr0;0]")
table.insert(formspec, "scroll_container[0,24;56,7;scr0;vertical;1]")
else
if(fs_version < 2) then
-- if the player has an older formspec version
minetest.log( "info",
"[MOD] yl_speak_up: User " .. pname .. " talked to NPC ID n_" .. n_id ..
" with an old formspec version!")
table.insert(formspec,
"box[0.3,20;19,2.6;red]"..
"label[0.7,20.3;"..yl_speak_up.text_version_warning.."]")
-- The up and down buttons are microscopic. Offer some (still small)
-- additional text buttons so that players have a chance to hit them.
table.insert(formspec, "button[49,23.1;6,0.9;button_down;^ Scroll Up ^]")
table.insert(formspec, "button[49,31.5;6,0.9;button_up;v Scroll Down v]")
table.insert(formspec, "button[1,23.1;6,0.9;button_down;^ Scroll Up ^]")
table.insert(formspec, "button[1,31.5;6,0.9;button_up;v Scroll Down v]")
end
-- old formspec versions need to remember somewhere extern how far the player scrolled
pname_for_old_fs = pname
yl_speak_up.speak_to[pname_for_old_fs].counter = 1
table.insert(formspec, "container[0,24]")
if(fs_version < 2) then
-- very small, ugly, and difficult to hit
table.insert(formspec, "button[0.1,0;1,0.9;button_down;^]")
table.insert(formspec, "button[0.1,7.0;1,0.9;button_up;v]")
else
-- somewhat larger and quite usable (v2 is pretty ok)
table.insert(formspec, "button[0.1,0;1,3;button_down;^\nU\np]")
table.insert(formspec, "button[0.1,3.2;1,4.5;button_up;D\no\nw\nn\nv]")
table.insert(formspec, "button[53.5,0;1,3;button_down;^\nU\np]")
table.insert(formspec, "button[53.5,3.2;1,4.5;button_up;D\no\nw\nn\nv]")
end
end
-- we are finished with adding buttons and text etc. to the left side of the formspec
local left_window_fs = table.concat(formspec, "\n")
-- empty formspec for the bottom part
formspec = {}
h = -0.8
-- allow to delete entries that have no options later on
@ -861,17 +736,10 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
(has_trades), nil, nil, pname_for_old_fs)
end
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
"button_exit",
yl_speak_up.message_button_option_exit,
yl_speak_up.message_button_option_exit,
true, nil, true, pname_for_old_fs) -- button_exit
-- we are finished with adding buttons to the bottom of the formspec
local bottom_window_fs = table.concat(formspec, "\n")
if(fs_version > 2) then
table.insert(formspec, "scroll_container_end[]")
else
table.insert(formspec, "container_end[]")
end
table.insert(formspec, "container_end[]")
return table.concat(formspec, "")
return yl_speak_up.show_fs_decorated(pname, edit_mode, h, alternate_text,
left_window_fs, bottom_window_fs,
active_dialog)
end

View File

@ -205,5 +205,5 @@ yl_speak_up.get_fs_trade_list = function(player, show_dialog_option_trades)
-- kein edit_mode beim trade-formspec da nicht sinnvoll
return yl_speak_up.show_fs_decorated(pname, nil, h, alternate_text, "",
table.concat(formspec, ""))
table.concat(formspec, ""), nil)
end