forked from your-land-mirror/yl_speak_up
allow to toggle between trades attached to dialog options and those in the trade list
This commit is contained in:
parent
ae5107b1ea
commit
a62b898020
@ -1865,7 +1865,7 @@ yl_speak_up.show_fs = function(player, fs_name, param)
|
||||
|
||||
elseif(fs_name == "trade_list") then
|
||||
minetest.show_formspec(pname, "yl_speak_up:trade_list",
|
||||
yl_speak_up.get_fs_trade_list(player))
|
||||
yl_speak_up.get_fs_trade_list(player, param))
|
||||
|
||||
elseif(fs_name == "trade_simple") then
|
||||
-- the optional parameter param is the trade_id
|
||||
|
@ -19,6 +19,13 @@ yl_speak_up.input_trade_list = function(player, formname, fields)
|
||||
return
|
||||
end
|
||||
|
||||
-- toggle between view of dialog option trades and trade list trades
|
||||
if(fields.show_dialog_option_trades
|
||||
or fields.show_trade_list) then
|
||||
yl_speak_up.show_fs(player, "trade_list", fields.show_dialog_option_trades)
|
||||
return
|
||||
end
|
||||
|
||||
-- go back to the main dialog
|
||||
if(fields.finished_trading) then
|
||||
yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = d_id})
|
||||
@ -43,7 +50,9 @@ end
|
||||
|
||||
|
||||
-- show a list of all trades the NPC has to offer
|
||||
yl_speak_up.get_fs_trade_list = function(player)
|
||||
-- if show_dialog_option_trades is set: show only those trades that are attached to options of dialogs;
|
||||
-- otherwise show only those trades attached to the trade list
|
||||
yl_speak_up.get_fs_trade_list = function(player, show_dialog_option_trades)
|
||||
if(not(player)) then
|
||||
return ""
|
||||
end
|
||||
@ -68,6 +77,22 @@ yl_speak_up.get_fs_trade_list = function(player)
|
||||
local npc_inv = minetest.get_inventory({type="detached", name="yl_speak_up_npc_"..tostring(n_id)})
|
||||
|
||||
local formspec = {}
|
||||
|
||||
if(yl_speak_up.may_edit_npc(player, n_id)) then
|
||||
-- allow players with the right priv to switch view between dialog option trades
|
||||
-- and those normal ones in the trade list
|
||||
if(not(show_dialog_option_trades)) then
|
||||
table.insert(formspec, "button[3.0,-0.5;5.0,0.9;show_dialog_option_trades;"..
|
||||
"Show trades attached to dialog options]")
|
||||
else
|
||||
table.insert(formspec, "button[3.0,-0.5;5.0,0.9;show_trade_list;"..
|
||||
"Show trade list trades (player view)]")
|
||||
end
|
||||
else
|
||||
-- do not show trades attached to dialog options for players who cannot edit the NPC
|
||||
show_dialog_option_trades = false
|
||||
end
|
||||
|
||||
-- arrange the offers in yl_speak_up.trade_max_cols columns horizontally
|
||||
-- and yl_speak_up.trade_max_rows row vertically
|
||||
local row = 0
|
||||
@ -86,6 +111,9 @@ yl_speak_up.get_fs_trade_list = function(player)
|
||||
for i, k in ipairs(sorted_trades) do
|
||||
v = dialog.trades[ k ]
|
||||
if(col < yl_speak_up.trade_max_cols
|
||||
-- needs both to be negated because show_dialog_option_trades will most of the time be nil
|
||||
-- and the actual value of v.d_id isn't of intrest here either
|
||||
and (not(show_dialog_option_trades) == not(v.d_id))
|
||||
and v.pay and v.pay[1] and v.pay[1] ~= "" and v.buy and v.buy[1] and v.buy[1] ~= "") then
|
||||
local pay_stack = ItemStack(v.pay[1])
|
||||
local buy_stack = ItemStack(v.buy[1])
|
||||
|
Loading…
Reference in New Issue
Block a user