broke long formspec strings into table.concat lists

This commit is contained in:
Sokomine 2024-02-12 12:33:58 +01:00
parent 42c3751966
commit 35fa4e9774
6 changed files with 125 additions and 87 deletions

View File

@ -59,33 +59,35 @@ yl_speak_up.get_fs_action_npc_gives = function(player, param)
local dialog = yl_speak_up.speak_to[pname].dialog local dialog = yl_speak_up.speak_to[pname].dialog
-- it's not the fault of the player that the NPC doesn't have the item; -- it's not the fault of the player that the NPC doesn't have the item;
-- so tell him that (the action will still fail) -- so tell him that (the action will still fail)
return "size[7,2.0]".. return table.concat({"size[7,2.0]"..
"label[0.2,-0.2;".. "label[0.2,-0.2;",
minetest.formspec_escape(dialog.n_npc or "- ? -").. minetest.formspec_escape(dialog.n_npc or "- ? -"),
" is very sorry:\n".. " is very sorry:\n"..
"The item intended for you is currently unavailable.\n".. "The item intended for you is currently unavailable.\n"..
"Please come back later!]".. "Please come back later!]"..
"button[2,1.5;1.5,0.9;npc_does_not_have_item;Back]" "button[2,1.5;1.5,0.9;npc_does_not_have_item;Back]"}, "")
end end
end end
local pname = player:get_player_name() local pname = player:get_player_name()
local dialog = yl_speak_up.speak_to[pname].dialog local dialog = yl_speak_up.speak_to[pname].dialog
return "size[8.5,8]".. return table.concat({"size[8.5,8]",
"list[current_player;main;0.2,3.85;8,1;]".. "list[current_player;main;0.2,3.85;8,1;]",
"list[current_player;main;0.2,5.08;8,3;8]".. "list[current_player;main;0.2,5.08;8,3;8]",
"button[0.2,0.0;2.0,0.9;back_to_talk;Back to talk]".. "button[0.2,0.0;2.0,0.9;back_to_talk;Back to talk]",
"button[4.75,1.6;1.5,0.9;finished_action;Done]".. "button[4.75,1.6;1.5,0.9;finished_action;Done]",
"tooltip[back_to_talk;Click here if you don't want to (or can't)\n".. "tooltip[back_to_talk;Click here if you don't want to (or can't)\n",
"take the offered item.]".. "take the offered item.]",
"tooltip[finished_action;Click here once you have taken the item and\n".. "tooltip[finished_action;Click here once you have taken the item and\n",
"stored it in your inventory.]".. "stored it in your inventory.]",
"label[1.5,0.7;"..minetest.formspec_escape(dialog.n_npc or "- ? -").. "label[1.5,0.7;",
" offers to you:]".. minetest.formspec_escape(dialog.n_npc or "- ? -"),
" offers to you:]",
-- unlike the npc_gives slot - which is used for setting up the NPC - the -- unlike the npc_gives slot - which is used for setting up the NPC - the
-- npc_gives slot does not allow putting something in -- npc_gives slot does not allow putting something in
"list[detached:yl_speak_up_player_"..pname..";npc_gives;3.25,1.5;1,1;]" .. "list[detached:yl_speak_up_player_"..pname..";npc_gives;3.25,1.5;1,1;]" ,
"label[1.5,2.7;Take the offered item and click on \"Done\" to proceed.]" "label[1.5,2.7;Take the offered item and click on \"Done\" to proceed.]"
}, "")
end end

View File

@ -38,20 +38,24 @@ end
yl_speak_up.get_fs_action_npc_wants = function(player, param) yl_speak_up.get_fs_action_npc_wants = function(player, param)
local pname = player:get_player_name() local pname = player:get_player_name()
local dialog = yl_speak_up.speak_to[pname].dialog local dialog = yl_speak_up.speak_to[pname].dialog
return "size[8.5,8]".. return table.concat({"size[8.5,8]",
"list[current_player;main;0.2,3.85;8,1;]".. "list[current_player;main;0.2,3.85;8,1;]",
"list[current_player;main;0.2,5.08;8,3;8]".. "list[current_player;main;0.2,5.08;8,3;8]",
"button[0.2,0.0;2.0,0.9;back_to_talk;Back to talk]".. "button[0.2,0.0;2.0,0.9;back_to_talk;Back to talk]",
"button[4.75,1.6;1.5,0.9;finished_action;Done]".. "button[4.75,1.6;1.5,0.9;finished_action;Done]",
"tooltip[back_to_talk;Click here if you don't know what item the\n".. "tooltip[back_to_talk;Click here if you don't know what item the\n",
"NPC wants or don't have the desired item.]".. "NPC wants or don't have the desired item.]",
"tooltip[finished_action;Click here once you have placed the item in\n".. "tooltip[finished_action;Click here once you have placed the item in\n",
"the waiting slot.]".. "the waiting slot.]",
"label[1.5,0.7;"..minetest.formspec_escape(dialog.n_npc or "- ? -").. "label[1.5,0.7;",
" expects something from you:]".. minetest.formspec_escape(dialog.n_npc or "- ? -"),
"list[detached:yl_speak_up_player_"..pname..";npc_wants;3.25,1.5;1,1;]" .. " expects something from you:]",
"list[detached:yl_speak_up_player_",
pname,
";npc_wants;3.25,1.5;1,1;]",
"label[1.5,2.7;Insert the right item and click on \"Done\" to proceed.]" "label[1.5,2.7;Insert the right item and click on \"Done\" to proceed.]"
}, "")
end end

View File

@ -44,31 +44,40 @@ yl_speak_up.get_fs_add_trade_simple = function(player, trade_id)
if(trade_id and trade_id == "new") then if(trade_id and trade_id == "new") then
delete_button = "" delete_button = ""
end end
return "size[8.5,9]".. return table.concat({"size[8.5,9]",
"label[4.35,0.8;"..minetest.formspec_escape(dialog.n_npc).." sells:]".. "label[4.35,0.8;",
"list[current_player;main;0.2,4.85;8,1;]".. minetest.formspec_escape(dialog.n_npc),
"list[current_player;main;0.2,6.08;8,3;8]".. " sells:]",
"list[current_player;main;0.2,4.85;8,1;]",
"list[current_player;main;0.2,6.08;8,3;8]",
-- show the second slot of the setup inventory in the detached player's inv -- show the second slot of the setup inventory in the detached player's inv
"list[detached:yl_speak_up_player_"..pname..";setup;2,1.5;1,1;]".. "list[detached:yl_speak_up_player_",
pname,
";setup;2,1.5;1,1;]",
-- show the second slot of said inventory -- show the second slot of said inventory
"list[detached:yl_speak_up_player_"..pname..";setup;5,1.5;1,1;1]".. "list[detached:yl_speak_up_player_",
"label[0.5,0.0;Configure trade with "..minetest.formspec_escape(dialog.n_npc)..":]".. pname,
"label[1.5,0.8;The customer pays:]".. ";setup;5,1.5;1,1;1]",
"label[1.5,3.8;Put items in the two slots and click on \"Store trade\".]".. "label[0.5,0.0;Configure trade with ",
"label[1.5,4.2;You will get your items back when storing the trade.]".. minetest.formspec_escape(dialog.n_npc),
":]",
"label[1.5,0.8;The customer pays:]",
"label[1.5,3.8;Put items in the two slots and click on \"Store trade\".]",
"label[1.5,4.2;You will get your items back when storing the trade.]",
-- annoyingly, the height value no longer works :-( -- annoyingly, the height value no longer works :-(
"label[0.2,2.5;Item\nname:]".. "label[0.2,2.5;Item\nname:]",
"field[1.5,3.2;3,0.2;item_name_price;;]".. "field[1.5,3.2;3,0.2;item_name_price;;]",
"label[4.35,2.5;If you don't have the item you\n".. "label[4.35,2.5;If you don't have the item you\n",
"want to buy, then enter its item\n".. "want to buy, then enter its item\n",
"name (i.e. default:diamond) here.]".. "name (i.e. default:diamond) here.]",
"button[0.2,1.6;1.0,0.9;abort_trade_simple;Abort]".. "button[0.2,1.6;1.0,0.9;abort_trade_simple;Abort]",
delete_button.. delete_button,
"button[6.2,1.6;2.0,0.9;store_trade_simple;Store trade]".. "button[6.2,1.6;2.0,0.9;store_trade_simple;Store trade]",
"tooltip[store_trade_simple;Click here to store this as a new trade. Your\n".. "tooltip[store_trade_simple;Click here to store this as a new trade. Your\n",
"items will be returned to you and the trade will\n".. "items will be returned to you and the trade will\n",
"will be shown the way the customer can see it.]".. "will be shown the way the customer can see it.]",
"tooltip[abort_trade_simple;Abort setting up this new trade.]" "tooltip[abort_trade_simple;Abort setting up this new trade.]"
}, "")
end end
-- the player wants to add a simple trade; handle formspec input -- the player wants to add a simple trade; handle formspec input

View File

@ -392,21 +392,36 @@ yl_speak_up.get_fs_do_trade_simple = function(player, trade_id)
trades_done = "Traded: "..tostring(yl_speak_up.trade[pname].trade_done).." time(s)" trades_done = "Traded: "..tostring(yl_speak_up.trade[pname].trade_done).." time(s)"
end end
return formspec.. return table.concat({formspec,
"label[2.5,0.0;Trading with "..minetest.formspec_escape(trade.npc_name).."]".. "label[2.5,0.0;Trading with ",
"label[1.5,0.7;You pay:]".. minetest.formspec_escape(trade.npc_name),
"]",
"label[1.5,0.7;You pay:]",
-- show images of price and what is sold so that the player knows what -- show images of price and what is sold so that the player knows what
-- it costs and what he will get even if the trade is not possible at -- it costs and what he will get even if the trade is not possible at
-- that moment -- that moment
"item_image[2.1,1.2;0.8,0.8;"..tostring(trade.player_gives).."]".. "item_image[2.1,1.2;0.8,0.8;",
"item_image[5.1,1.2;0.8,0.8;"..tostring(trade.npc_gives).."]".. tostring(trade.player_gives),
"image[3.5,2.0;1,1;gui_furnace_arrow_bg.png^[transformR270]".. "]",
"item_image[5.1,1.2;0.8,0.8;",
tostring(trade.npc_gives),
"]",
"image[3.5,2.0;1,1;gui_furnace_arrow_bg.png^[transformR270]",
-- show the pay slot from the detached player's trade inventory -- show the pay slot from the detached player's trade inventory
"list[detached:yl_speak_up_player_"..pname..";pay;2,2.0;1,1;]" .. "list[detached:yl_speak_up_player_",
pname,
";pay;2,2.0;1,1;]",
-- show the buy slot from the same inventory -- show the buy slot from the same inventory
"list[detached:yl_speak_up_player_"..pname..";buy;5,2.0;1,1;]" .. "list[detached:yl_speak_up_player_",
"label[1.5,3.0;"..trade_possible_msg.."]".. pname,
"label[6.0,1.5;"..trades_done.."]" ";buy;5,2.0;1,1;]",
"label[1.5,3.0;",
trade_possible_msg,
"]",
"label[6.0,1.5;",
trades_done,
"]"
}, "")
end end

View File

@ -45,16 +45,24 @@ yl_speak_up.get_fs_inventory = function(player)
"button_exit[2,1.5;1,0.9;exit;Exit]" "button_exit[2,1.5;1,0.9;exit;Exit]"
end end
return "size[12,11]" .. return table.concat({"size[12,11]",
"label[2,-0.2;Inventory of "..minetest.formspec_escape(dialog.n_npc).. "label[2,-0.2;Inventory of ",
" (ID: "..tostring(n_id).."):]".. minetest.formspec_escape(dialog.n_npc),
"list[detached:yl_speak_up_npc_"..tostring(n_id)..";npc_main;0,0.3;12,6;]" .. " (ID: ",
"list[current_player;main;2,7.05;8,1;]" .. tostring(n_id),
"list[current_player;main;2,8.28;8,3;8]" .. "):]",
"listring[detached:yl_speak_up_npc_"..tostring(n_id)..";npc_main]" .. "list[detached:yl_speak_up_npc_",
"listring[current_player;main]" .. tostring(n_id),
"button[3.5,6.35;5,0.6;inventory_show_tradelist;Show trade list trades (player view)]".. ";npc_main;0,0.3;12,6;]",
"list[current_player;main;2,7.05;8,1;]",
"list[current_player;main;2,8.28;8,3;8]",
"listring[detached:yl_speak_up_npc_",
tostring(n_id),
";npc_main]",
"listring[current_player;main]",
"button[3.5,6.35;5,0.6;inventory_show_tradelist;Show trade list trades (player view)]",
"button[10.0,10.4;2,0.9;back_from_inventory;Back]" "button[10.0,10.4;2,0.9;back_from_inventory;Back]"
}, "")
end end

View File

@ -76,29 +76,29 @@ yl_speak_up.get_fs_trade_limit = function(player, selected)
-- all items for which limitations might possibly be needed have been collected; -- all items for which limitations might possibly be needed have been collected;
-- now display them -- now display them
local formspec = {'size[18,12]'.. local formspec = {'size[18,12]',
'button[0.5,11.1;17,0.8;back;Back]'.. 'button[0.5,11.1;17,0.8;back;Back]',
'label[7.0,0.5;List of trade limits]'.. 'label[7.0,0.5;List of trade limits]',
'label[0.5,1.0;If you do not set any limits, your NPC will buy and sell as many '.. 'label[0.5,1.0;If you do not set any limits, your NPC will buy and sell as many '..
'items as his inventory allows.\n'.. 'items as his inventory allows.\n',
'If you set \'Will sell if more than this\', your NPC '.. 'If you set \'Will sell if more than this\', your NPC '..
'will only sell if he will have enough left after the trade,\n'.. 'will only sell if he will have enough left after the trade,\n',
'and if you set \'Will buy if less than this\', he will '.. 'and if you set \'Will buy if less than this\', he will '..
'only buy items as long as he will not end up with more than '.. 'only buy items as long as he will not end up with more than '..
'this.]'.. 'this.]',
'tablecolumns[' .. 'tablecolumns[',
'text,align=left;'.. 'text,align=left;',
'color;text,align=right;'.. 'color;text,align=right;',
'color;text,align=center;'.. 'color;text,align=center;',
'text,align=right;'.. 'text,align=right;',
'color;text,align=center;'.. 'color;text,align=center;',
'text,align=right;'.. 'text,align=right;',
'color;text,align=left]'.. 'color;text,align=left]',
'table[0.1,2.3;17.8,8.5;edit_trade_limit;'.. 'table[0.1,2.3;17.8,8.5;edit_trade_limit;',
'Description:,'.. 'Description:,',
'#FFFFFF,NPC has:,'.. '#FFFFFF,NPC has:,',
'#FFFFFF,Will sell if more than this:,,'.. '#FFFFFF,Will sell if more than this:,,',
'#FFFFFF,Will buy if less than this:,,'.. '#FFFFFF,Will buy if less than this:,,',
'#EEEEEE,Item string:,' '#EEEEEE,Item string:,'
} }