forked from Sokomine/yl_speak_up
created fs_decorated.lua and make trade_list.lua use it
This commit is contained in:
parent
c5c7d3391c
commit
d466436c34
311
fs_decorated.lua
Normal file
311
fs_decorated.lua
Normal file
@ -0,0 +1,311 @@
|
||||
-- the formspec menu used for talking to the NPC can also used for
|
||||
-- the trading formspec and similar things
|
||||
|
||||
-- because the player may have wandered off from his NPC and get too many messages
|
||||
-- without a quick way to get rid of them otherwise
|
||||
minetest.register_chatcommand( 'npc_talk_style', {
|
||||
description = "This command sets your formspec version "..
|
||||
"for the yl_speak_up NPC to value <version>.\n"..
|
||||
" Version 1: For very old clients. Not recommended.\n"..
|
||||
" Version 2: Adds extra scroll buttons. Perhaps you like this more.\n"..
|
||||
" Version 3: Default version.",
|
||||
privs = {},
|
||||
func = function(pname, param)
|
||||
if(param and param == "1") then
|
||||
yl_speak_up.fs_version[pname] = 1
|
||||
elseif(param and param == "2") then
|
||||
yl_speak_up.fs_version[pname] = 2
|
||||
elseif(param and param == "3") then
|
||||
yl_speak_up.fs_version[pname] = 3
|
||||
else
|
||||
minetest.chat_send_player(pname, "This command sets your formspec version "..
|
||||
"for the yl_speak_up NPC to value <version>.\n"..
|
||||
" Version 1: For very old clients. Not recommended.\n"..
|
||||
" Version 2: Adds extra scroll buttons. Perhaps you like this more.\n"..
|
||||
" Version 3: Default version.")
|
||||
end
|
||||
minetest.chat_send_player(pname, "Your formspec version for the yl_speak_up NPC "..
|
||||
"has been set to version "..tostring(yl_speak_up.fs_version[pname])..
|
||||
" for this session.")
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- helper function for yl_speak_up.show_fs_decorated
|
||||
yl_speak_up.calculate_portrait = function(pname, n_id)
|
||||
local tex = yl_speak_up.speak_to[pname].textures
|
||||
|
||||
local head = ""
|
||||
|
||||
head = head .. "[combine:8x8:-8,-8=" .. tex[2] .. ":-40,-8=" .. tex[2]
|
||||
|
||||
return head
|
||||
end
|
||||
|
||||
|
||||
-- older formspecs (before v3) do not offer a scroll container and have to scroll manually;
|
||||
-- we maintain a player-name-based counter in order to see if this line ought to be shown
|
||||
yl_speak_up.old_fs_version_show_line = function(pname)
|
||||
-- the player is using a new enough version for scroll_container to work
|
||||
if(not(pname)) then
|
||||
return true
|
||||
end
|
||||
local max_number_of_buttons = yl_speak_up.max_number_of_buttons
|
||||
local start_index = yl_speak_up.speak_to[pname].option_index
|
||||
local counter = yl_speak_up.speak_to[pname].counter
|
||||
yl_speak_up.speak_to[pname].counter = counter + 1
|
||||
if counter < start_index or counter >= start_index + max_number_of_buttons then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
-- show an edit option in the main menu of the NPC;
|
||||
-- helper function for yl_speak_up.fs_talkdialog(..)
|
||||
-- and yl_speak_up.show_fs_decorated
|
||||
yl_speak_up.add_edit_button_fs_talkdialog = function(formspec, h, button_name, tooltip, label,
|
||||
show_main_not_alternate, alternate_label, is_exit_button,
|
||||
pname)
|
||||
-- do not show this button at all if there is no alternate text and the condition is false
|
||||
if(not(alternate_label) and not(show_main_not_alternate)) then
|
||||
return h
|
||||
end
|
||||
local button_dimensions = "0.5,"..(h+1)..";53.8,0.9;"
|
||||
local label_start_pos = "0.7"
|
||||
-- older formspecs (before v4) do not offer a scroll container and have to scroll manually
|
||||
if(pname) then
|
||||
if(not(yl_speak_up.old_fs_version_show_line(pname))) then
|
||||
return h
|
||||
end
|
||||
-- there has to be more room for the up and down arrows
|
||||
button_dimensions = "1.2,"..(h+1)..";52.3,0.9;"
|
||||
label_start_pos = "1.4"
|
||||
end
|
||||
h = h + 1
|
||||
if(show_main_not_alternate) then
|
||||
if(is_exit_button) then
|
||||
table.insert(formspec, "button_exit["..button_dimensions..tostring(button_name)..";]")
|
||||
else
|
||||
table.insert(formspec, "button["..button_dimensions..tostring(button_name)..";]")
|
||||
end
|
||||
table.insert(formspec, "tooltip["..tostring(button_name)..";"..tostring(tooltip).."]")
|
||||
table.insert(formspec, "label["..label_start_pos..","..(h+0.45)..";"..tostring(label).."]")
|
||||
else
|
||||
table.insert(formspec, "box["..button_dimensions.."#BBBBBB]")
|
||||
table.insert(formspec, "label["..label_start_pos..","..(h+0.45)..";"..
|
||||
tostring(alternate_label).."]")
|
||||
end
|
||||
return h
|
||||
end
|
||||
|
||||
|
||||
-- show a formspec element in the main menu of the NPC (with tooltip);
|
||||
-- helper function for yl_speak_up.fs_talkdialog(..)
|
||||
-- and yl_speak_up.show_fs_decorated
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if = function(formspec, element_type, position, element_name,
|
||||
element_text, tooltip, condition)
|
||||
if(not(condition)) then
|
||||
return
|
||||
end
|
||||
table.insert(formspec, element_type.."["..position..";"..element_name..";"..element_text.."]")
|
||||
table.insert(formspec, "tooltip["..tostring(element_name)..";"..tostring(tooltip).."]")
|
||||
end
|
||||
|
||||
|
||||
-- in formspec versions lower than 3, scrolling has to be handled diffrently;
|
||||
-- this updates:
|
||||
-- yl_speak_up.fs_version[pname]
|
||||
-- yl_speak_up.speak_to[pname].counter
|
||||
yl_speak_up.get_pname_for_old_fs = function(pname)
|
||||
-- depending on formspec version, diffrent formspec elements are available
|
||||
local fs_version = yl_speak_up.fs_version[pname]
|
||||
if(not(fs_version)) then
|
||||
local formspec_v = minetest.get_player_information(pname).formspec_version
|
||||
local protocol_v = minetest.get_player_information(pname).protocol_version
|
||||
|
||||
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
|
||||
if(fs_version <= 2) then
|
||||
-- old formspec versions need to remember somewhere extern how far the player scrolled
|
||||
yl_speak_up.speak_to[pname].counter = 1
|
||||
return pname
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
yl_speak_up.show_fs_decorated = function(pname, edit_mode, h,
|
||||
alternate_text,
|
||||
add_this_to_left_window,
|
||||
add_this_to_bottom_window)
|
||||
if(not(pname)) then
|
||||
return ""
|
||||
end
|
||||
-- which NPC is the player talking to?
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
-- do we have all the necessary data?
|
||||
if(not(n_id) or not(dialog) or not(dialog.n_npc)) then
|
||||
return "size[6,2]"..
|
||||
"label[0.2,0.5;Ups! This NPC lacks ID or name.]"..
|
||||
"button_exit[2,1.5;1,0.9;exit;Exit]"
|
||||
end
|
||||
|
||||
-- depending on formspec version, diffrent formspec elements are available
|
||||
local fs_version = yl_speak_up.fs_version[pname]
|
||||
|
||||
local portrait = yl_speak_up.calculate_portrait(pname, n_id)
|
||||
|
||||
local formspec = {}
|
||||
|
||||
-- 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
|
||||
|
||||
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
|
||||
|
||||
-- display the window with the text the NPC is saying
|
||||
-- Note: In edit mode, and if there is a dialog selected, the necessary
|
||||
-- elements for editing said text are done in the calling function.
|
||||
if(not(edit_mode) or not(dialog) or not(dialog.n_dialogs)) then
|
||||
if(alternate_text and active_dialog and active_dialog.d_text) then
|
||||
alternate_text = string.gsub(alternate_text, "%$TEXT%$", active_dialog.d_text)
|
||||
elseif(active_dialog and active_dialog.d_text) then
|
||||
alternate_text = active_dialog.d_text
|
||||
end
|
||||
-- replace $NPC_NAME$ etc.
|
||||
local t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
alternate_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
|
||||
|
||||
-- add custom things (mostly for editing a dialog) to the window shown left
|
||||
table.insert(formspec, add_this_to_left_window)
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
table.insert(formspec, add_this_to_bottom_window)
|
||||
|
||||
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
|
||||
|
||||
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, "")
|
||||
end
|
@ -1,18 +1,6 @@
|
||||
-- This is the main talkdialog the NPC shows when right-clicked.
|
||||
|
||||
|
||||
-- helper function for yl_speak_up.fs_talkdialog
|
||||
yl_speak_up.calculate_portrait = function(pname, n_id)
|
||||
local tex = yl_speak_up.speak_to[pname].textures
|
||||
|
||||
local head = ""
|
||||
|
||||
head = head .. "[combine:8x8:-8,-8=" .. tex[2] .. ":-40,-8=" .. tex[2]
|
||||
|
||||
return head
|
||||
end
|
||||
|
||||
|
||||
yl_speak_up.input_talk = function(player, formname, fields)
|
||||
if formname ~= "yl_speak_up:talk" then
|
||||
return
|
||||
@ -279,73 +267,6 @@ yl_speak_up.input_talk = function(player, formname, fields)
|
||||
end
|
||||
|
||||
|
||||
-- older formspecs (before v3) do not offer a scroll container and have to scroll manually;
|
||||
-- we maintain a player-name-based counter in order to see if this line ought to be shown
|
||||
yl_speak_up.old_fs_version_show_line = function(pname)
|
||||
-- the player is using a new enough version for scroll_container to work
|
||||
if(not(pname)) then
|
||||
return true
|
||||
end
|
||||
local max_number_of_buttons = yl_speak_up.max_number_of_buttons
|
||||
local start_index = yl_speak_up.speak_to[pname].option_index
|
||||
local counter = yl_speak_up.speak_to[pname].counter
|
||||
yl_speak_up.speak_to[pname].counter = counter + 1
|
||||
if counter < start_index or counter >= start_index + max_number_of_buttons then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
-- show an edit option in the main menu of the NPC;
|
||||
-- helper function for yl_speak_up.fs_talkdialog(..)
|
||||
yl_speak_up.add_edit_button_fs_talkdialog = function(formspec, h, button_name, tooltip, label,
|
||||
show_main_not_alternate, alternate_label, is_exit_button,
|
||||
pname)
|
||||
-- do not show this button at all if there is no alternate text and the condition is false
|
||||
if(not(alternate_label) and not(show_main_not_alternate)) then
|
||||
return h
|
||||
end
|
||||
local button_dimensions = "0.5,"..(h+1)..";53.8,0.9;"
|
||||
local label_start_pos = "0.7"
|
||||
-- older formspecs (before v4) do not offer a scroll container and have to scroll manually
|
||||
if(pname) then
|
||||
if(not(yl_speak_up.old_fs_version_show_line(pname))) then
|
||||
return h
|
||||
end
|
||||
-- there has to be more room for the up and down arrows
|
||||
button_dimensions = "1.2,"..(h+1)..";52.3,0.9;"
|
||||
label_start_pos = "1.4"
|
||||
end
|
||||
h = h + 1
|
||||
if(show_main_not_alternate) then
|
||||
if(is_exit_button) then
|
||||
table.insert(formspec, "button_exit["..button_dimensions..tostring(button_name)..";]")
|
||||
else
|
||||
table.insert(formspec, "button["..button_dimensions..tostring(button_name)..";]")
|
||||
end
|
||||
table.insert(formspec, "tooltip["..tostring(button_name)..";"..tostring(tooltip).."]")
|
||||
table.insert(formspec, "label["..label_start_pos..","..(h+0.45)..";"..tostring(label).."]")
|
||||
else
|
||||
table.insert(formspec, "box["..button_dimensions.."#BBBBBB]")
|
||||
table.insert(formspec, "label["..label_start_pos..","..(h+0.45)..";"..
|
||||
tostring(alternate_label).."]")
|
||||
end
|
||||
return h
|
||||
end
|
||||
|
||||
|
||||
-- show a formspec element in the main menu of the NPC (with tooltip);
|
||||
-- helper function for yl_speak_up.fs_talkdialog(..)
|
||||
yl_speak_up.add_formspec_element_with_tooltip_if = function(formspec, element_type, position, element_name,
|
||||
element_text, tooltip, condition)
|
||||
if(not(condition)) then
|
||||
return
|
||||
end
|
||||
table.insert(formspec, element_type.."["..position..";"..element_name..";"..element_text.."]")
|
||||
table.insert(formspec, "tooltip["..tostring(element_name)..";"..tostring(tooltip).."]")
|
||||
end
|
||||
|
||||
|
||||
-- recursion_depth is increased each time autoanswer is automaticly selected
|
||||
yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, recursion_depth)
|
||||
@ -954,33 +875,3 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
||||
table.insert(formspec, "container_end[]")
|
||||
return table.concat(formspec, "")
|
||||
end
|
||||
|
||||
-- a chat command for entering and leaving debug mode; needs to be a chat command
|
||||
-- because the player may have wandered off from his NPC and get too many messages
|
||||
-- without a quick way to get rid of them otherwise
|
||||
minetest.register_chatcommand( 'npc_talk_style', {
|
||||
description = "This command sets your formspec version "..
|
||||
"for the yl_speak_up NPC to value <version>.\n"..
|
||||
" Version 1: For very old clients. Not recommended.\n"..
|
||||
" Version 2: Adds extra scroll buttons. Perhaps you like this more.\n"..
|
||||
" Version 3: Default version.",
|
||||
privs = {},
|
||||
func = function(pname, param)
|
||||
if(param and param == "1") then
|
||||
yl_speak_up.fs_version[pname] = 1
|
||||
elseif(param and param == "2") then
|
||||
yl_speak_up.fs_version[pname] = 2
|
||||
elseif(param and param == "3") then
|
||||
yl_speak_up.fs_version[pname] = 3
|
||||
else
|
||||
minetest.chat_send_player(pname, "This command sets your formspec version "..
|
||||
"for the yl_speak_up NPC to value <version>.\n"..
|
||||
" Version 1: For very old clients. Not recommended.\n"..
|
||||
" Version 2: Adds extra scroll buttons. Perhaps you like this more.\n"..
|
||||
" Version 3: Default version.")
|
||||
end
|
||||
minetest.chat_send_player(pname, "Your formspec version for the yl_speak_up NPC "..
|
||||
"has been set to version "..tostring(yl_speak_up.fs_version[pname])..
|
||||
" for this session.")
|
||||
end
|
||||
})
|
||||
|
2
init.lua
2
init.lua
@ -32,6 +32,8 @@ dofile(modpath .. "privs.lua")
|
||||
dofile(modpath .. "interface_mobs_api.lua")
|
||||
-- handle on_player_receive_fields and showing of formspecs
|
||||
dofile(modpath .. "show_fs.lua")
|
||||
-- general decoration part for main formspec, trade window etc.
|
||||
dofile(modpath .. "fs_decorated.lua")
|
||||
-- the formspec and input handling for the main dialog
|
||||
dofile(modpath .. "fs_talkdialog.lua")
|
||||
-- ask if the player wants to save, discard or go back in edit mode
|
||||
|
157
trade_list.lua
157
trade_list.lua
@ -59,6 +59,7 @@ yl_speak_up.get_fs_trade_list = function(player, show_dialog_option_trades)
|
||||
return ""
|
||||
end
|
||||
local pname = player:get_player_name()
|
||||
|
||||
-- which NPC is the player talking to?
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
@ -67,9 +68,9 @@ yl_speak_up.get_fs_trade_list = function(player, show_dialog_option_trades)
|
||||
return "size[6,2]"..
|
||||
"label[0.2,0.5;Ups! This NPC lacks ID or name.]"..
|
||||
"button_exit[2,1.5;1,0.9;exit;Exit]"
|
||||
|
||||
end
|
||||
|
||||
|
||||
-- make sure the NPC has that table defined
|
||||
if(not(dialog.trades)) then
|
||||
dialog.trades = {}
|
||||
@ -78,154 +79,21 @@ yl_speak_up.get_fs_trade_list = function(player, show_dialog_option_trades)
|
||||
yl_speak_up.load_npc_inventory(n_id)
|
||||
local npc_inv = minetest.get_inventory({type="detached", name="yl_speak_up_npc_"..tostring(n_id)})
|
||||
|
||||
local formspec = {}
|
||||
|
||||
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
|
||||
-- do not show trades attached to dialog options for players who cannot edit the NPC
|
||||
show_dialog_option_trades = false
|
||||
end
|
||||
|
||||
|
||||
local dialog = yl_speak_up.speak_to[pname].dialog
|
||||
local portrait = yl_speak_up.calculate_portrait(pname, n_id)
|
||||
|
||||
-- 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 fs_version = yl_speak_up.fs_version[pname]
|
||||
|
||||
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
|
||||
|
||||
|
||||
local alternate_text = " I can offer you these trades.\n\n"..
|
||||
"Select one trade and then choose \"buy\" to actually buy something."..
|
||||
"\n\nThere may be more trades then those shown in the first row. Please "..
|
||||
"look at all my offers [that is, scroll down a bit]!"..
|
||||
"\n\n[$NPC_NAME$ looks expectantly at you.]"
|
||||
local active_dialog = {}
|
||||
active_dialog.d_text = ""
|
||||
|
||||
-- display the window with the text the NPC is saying
|
||||
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
|
||||
|
||||
|
||||
|
||||
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
|
||||
local pname_for_old_fs = yl_speak_up.get_pname_for_old_fs(pname)
|
||||
local formspec = {}
|
||||
h = -0.8
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- arrange the offers in yl_speak_up.trade_max_cols columns horizontally
|
||||
-- and yl_speak_up.trade_max_rows row vertically
|
||||
local row = 0
|
||||
@ -328,12 +196,6 @@ yl_speak_up.get_fs_trade_list = function(player, show_dialog_option_trades)
|
||||
text, text,
|
||||
true, nil, nil, pname_for_old_fs) -- button_exit
|
||||
|
||||
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
|
||||
|
||||
-- if there are no trades, at least print a hint that there could be some here
|
||||
-- (a mostly empty formspec looks too boring and could irritate players)
|
||||
if(anz_trades == 0) then
|
||||
@ -341,12 +203,7 @@ yl_speak_up.get_fs_trade_list = function(player, show_dialog_option_trades)
|
||||
"label[1,1;Sorry. There are currently no offers available.]")
|
||||
end
|
||||
|
||||
|
||||
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, "")
|
||||
-- kein edit_mode beim trade-formspec da nicht sinnvoll
|
||||
return yl_speak_up.show_fs_decorated(pname, nil, h, alternate_text, "",
|
||||
table.concat(formspec, ""))
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user