Add confirmation dialog on inventory clearing

This commit is contained in:
Jean-Patrick Guerrero 2021-07-05 23:38:43 +02:00
parent 1c4ae1df28
commit 5c96ede065
2 changed files with 40 additions and 17 deletions

View File

@ -84,6 +84,9 @@ local styles = fmt([[
style[craft_rcp,craft_usg;noclip=true;font_size=16;sound=i3_craft;
bgimg=i3_btn9.png;bgimg_hovered=i3_btn9_hovered.png;
bgimg_pressed=i3_btn9_pressed.png;bgimg_middle=4,6]
style[confirm_trash_yes,confirm_trash_no;noclip=true;font_size=16;
bgimg=i3_btn9.png;bgimg_hovered=i3_btn9_hovered.png;
bgimg_pressed=i3_btn9_pressed.png;bgimg_middle=4,6]
]],
PNG.slot,
PNG.exit, PNG.exit_hover,

View File

@ -2314,6 +2314,7 @@ local function reset_data(data)
data.export_rcp = nil
data.export_usg = nil
data.alt_items = nil
data.confirm_trash = nil
data.items = data.items_raw
if data.current_itab > 1 then
@ -2531,6 +2532,18 @@ local function get_inventory_fs(player, data, fs)
fs("image_button", i + 3.447 - (i * 0.4), 11.43, 0.35, 0.35, "", btn_name, "")
fs(fmt("tooltip[%s;%s]", btn_name, tooltip))
end
if data.confirm_trash then
fs("style_type[box;colors=#999,#999,#808080,#808080]")
for _ = 1, 3 do
fs("box", 2.95, 10.75, 4.35, 0.5, "")
end
fs("label", 3.1, 11, "Confirm trash?")
fs("image_button", 5.2, 10.75, 1, 0.5, "", "confirm_trash_yes", "Yes")
fs("image_button", 6.3, 10.75, 1, 0.5, "", "confirm_trash_no", "No")
end
end
i3.new_tab {
@ -2602,9 +2615,16 @@ i3.new_tab {
end
if fields.trash then
data.confirm_trash = true
elseif fields.confirm_trash_yes or fields.confirm_trash_no then
if fields.confirm_trash_yes then
local inv = player:get_inventory()
inv:set_list("main", {})
inv:set_list("craft", {})
end
data.confirm_trash = nil
elseif fields.compress then
compress_items(player)