added Let's trade button

This commit is contained in:
Sokomine 2021-05-29 16:04:29 +02:00
parent d75b94c99d
commit 466a5e617f

View File

@ -1522,6 +1522,26 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id)
table.insert(formspec, "label[0.7,"..(h+0.45)..";I am your owner. I have new orders for you.]")
end
-- add a Let's trade button to the first dialog if the NPC has trades
if(active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) == 0
and dialog.trades) then
local has_trades = nil
for k, v in pairs(dialog.trades) do
-- has the NPC any *public* trades that are not effects/results?
if(not(v.hide) and not(v.d_id)) then
has_trades = true
break
end
end
if(has_trades) then
h = h + 1
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;show_trade_list;]")
table.insert(formspec, "tooltip[show_trade_list;Show a list of trades the NPC has to offer.]")
table.insert(formspec, "label[0.7,"..(h+0.45)..";Let's trade!]")
end
end
h = h + 1
table.insert(formspec, "button_exit[0.5," .. h .. ";53.8,0.9;button_exit;]")
table.insert(formspec, "tooltip[button_exit;" .. yl_speak_up.message_button_option_exit .. "]")
@ -2217,6 +2237,13 @@ yl_speak_up.save_changes_and_switch_to_other_dialog = function(player, fields, t
yl_speak_up.edit_mode[pname] = nil
target_dialog = nil
end
-- the trade list is not really a dialog...
if(target_dialog == "trade_list") then
minetest.show_formspec(pname, "yl_speak_up:trade_list",
yl_speak_up.get_fs_trade_list(player))
return
end
-- move on to the target dialog
yl_speak_up.speak_to[pname].d_id = target_dialog
minetest.show_formspec(pname, "yl_speak_up:talk",
@ -2971,6 +2998,17 @@ yl_speak_up.input_talk = function(player, formname, fields)
yl_speak_up.speak_to[pname].option_index = 1
end
-- the player wants to see the trade list
if(fields.show_trade_list) then
if(edit_mode) then
yl_speak_up.save_changes_and_switch_to_other_dialog(player, fields, "trade_list")
return
end
minetest.show_formspec(pname, "yl_speak_up:trade_list",
yl_speak_up.get_fs_trade_list(player))
return
end
for k, v in pairs(fields) do
local s = string.split(k, "_")