show background images when editing inventory-related actions

This commit is contained in:
Sokomine 2021-06-20 00:36:07 +02:00
parent a44cb0fbdd
commit c93012338d

View File

@ -526,6 +526,8 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
local meta = stack:get_meta()
-- what does the NPC want to give?
v[ "a_value" ] = stack:get_name().." "..stack:get_count()
-- for displaying as a background image
data.item_string = v[ "a_value" ]
if(data.what == 5) then
data.item_desc = meta:get_string("description")
end
@ -858,9 +860,9 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
data.inv_stack_name = e[ "p_itemstack" ]
-- crafting (effect)
elseif(data.what and id_prefix == "r_" and data.what == 4) then
-- TODO: there really can't be done much in that regard so far
-- v[ "r_value" ] = player_inv:get_stack("craftpreview", 1):to_string()
-- v[ "r_craft_grid"] = {} player_inv:get_stack("craft", i):to_string())
-- those items can at least be shown as background images
data.craftresult = e[ "r_value" ]
data.craft_grid = e[ "r_craft_grid"]
-- on failure (effect)
elseif(data.what and id_prefix == "r_" and data.what == 5) then
data.on_failure = e[ "r_value" ]
@ -869,20 +871,21 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
data.chat_msg_text = e[ "r_value" ]
-- normal trade (action)
elseif(data.what and id_prefix == "a_" and data.what == 3) then
-- TODO: there is no good way to show that in edit mode yet
data.trade_id = e[ "a_value" ]
-- v[ "a_pay" ] = dialog.trades[ data.trade_id ].pay
-- v[ "a_buy" ] = dialog.trades[ data.trade_id ].buy
-- use as background images
if(dialog and dialog.trades and dialog.trades[ data.trade_id ]) then
data.pay = dialog.trades[ data.trade_id ].pay[1]
data.buy = dialog.trades[ data.trade_id ].buy[1]
end
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
data.action_failure_dialog = math.max(1,
table.indexof(sorted_dialog_list, e[ "a_on_failure" ]))
-- npc_gives/npc_wants (action)
elseif(data.what and id_prefix == "a_" and (data.what == 4 or data.what == 5)) then
-- TODO: there is no good way to show that in edit mode yet
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
data.action_failure_dialog = math.max(1,
table.indexof(sorted_dialog_list, e[ "a_on_failure" ]))
-- TODO: data.item_string is not really used...
-- data.item_string is used to show a background image
data.item_string = e[ "a_value"] -- stack name and count (as string)
data.item_desc = e[ "a_item_desc" ]
data.item_quest_id = e[ "a_item_quest_id" ]
@ -1067,6 +1070,18 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
-- "NPC crafts soemthing", -- 4
-- (craft - only for effects - not for preconditions)
elseif(data.what and id_prefix == "r_" and data.what == 4) then
local bg_img = ""
if(data and data.craftresult and data.craft_grid) then
bg_img = "item_image[5.95,4.90;0.7,0.7;"..tostring(data.craftresult).."]"
for i, v in ipairs(data.craft_grid) do
if(v and v ~= "") then
bg_img = bg_img.."item_image["..
tostring(1.15 + ((i-1)%3)*1.25)..","..
tostring(3.65 + math.floor((i-1)/3)*1.30)..
";0.7,0.7;"..tostring(v).."]"
end
end
end
formspec = formspec..
"label[8,2.6;Your invnetory:]"..
"list[current_player;main;8,3;8,4;]"..
@ -1075,7 +1090,8 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"list[current_player;craftpreview;5.8,4.75;1,1;]"..
"image[4.6,4.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
"label[1,8.0;Use your craft grid to show your NPC what to craft "..
"and how. Click on \"Save\" to save.]"
"and how. Click on \"Save\" to save.]"..
bg_img
-- "go to other dialog if the *previous* effect failed", -- 5
-- (on_failure - only for effects - not for preconditions)
@ -1120,6 +1136,12 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
if(not(data.trade_id)) then
data.trade_id = tostring(d_id).." "..tostring(o_id)
end
-- show the player which trade is stored
local bg_img = ""
if(data and data.buy and data.pay) then
bg_img = "item_image[2.15,4.35;0.7,0.7;"..tostring(data.buy).."]"..
"item_image[5.15,4.35;0.7,0.7;"..tostring(data.pay).."]"
end
yl_speak_up.speak_to[pname].trade_id = data.trade_id
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
formspec = formspec..
@ -1137,7 +1159,8 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"If he doesn't, go to dialog:]"..
"dropdown[4.3,6.0;2.8,0.6;select_on_action_failure;"..
"- current one -,"..
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"
table.concat(sorted_dialog_list, ",")..";"..tostring(nr)..";]"..
bg_img
-- "The NPC gives something to the player (i.e. a quest item).", -- 4
-- (only for actions)
@ -1160,6 +1183,10 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
if(data and data.item_node_name) then
stack_name = data.item_node_name
end
local bg_img = ""
if(data and data.item_string) then
bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]"
end
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
formspec = formspec..
"label[8,2.6;Your invnetory:]"..
@ -1192,7 +1219,8 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
"Set this to a text that helps the *player* to remember what\n"..
"this special quest item is for (i.e. \"Letter from August to\n"..
"Frederike\" for a piece of paper).\n"..
"This description is shown in the inventory on mouseover.]"
"This description is shown in the inventory on mouseover.]"..
bg_img
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
@ -1216,6 +1244,10 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
if(data and data.item_node_name) then
stack_name = data.item_node_name
end
local bg_img = ""
if(data and data.item_string) then
bg_img = "item_image[2.15,3.65;0.7,0.7;"..tostring(data.item_string).."]"
end
local sorted_dialog_list = yl_speak_up.sort_keys(dialog.n_dialogs)
formspec = formspec..
"label[8,2.6;Your invnetory:]"..
@ -1236,7 +1268,8 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
minetest.formspec_escape(tostring(item_quest_id)).."]"..
"label[0.2,9.0;Expected description:]"..
"label[4.0,9.0;"..
minetest.formspec_escape(tostring(item_desc)).."]"
minetest.formspec_escape(tostring(item_desc)).."]"..
bg_img
-- "The player has to manually enter a password or passphrase or some other text.", -- 6
-- (only for actions)