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; style[craft_rcp,craft_usg;noclip=true;font_size=16;sound=i3_craft;
bgimg=i3_btn9.png;bgimg_hovered=i3_btn9_hovered.png; bgimg=i3_btn9.png;bgimg_hovered=i3_btn9_hovered.png;
bgimg_pressed=i3_btn9_pressed.png;bgimg_middle=4,6] 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.slot,
PNG.exit, PNG.exit_hover, PNG.exit, PNG.exit_hover,

View File

@ -2301,20 +2301,21 @@ local function init_data(player, info)
end end
local function reset_data(data) local function reset_data(data)
data.filter = "" data.filter = ""
data.expand = "" data.expand = ""
data.pagenum = 1 data.pagenum = 1
data.rnum = 1 data.rnum = 1
data.unum = 1 data.unum = 1
data.scrbar_rcp = 1 data.scrbar_rcp = 1
data.scrbar_usg = 1 data.scrbar_usg = 1
data.query_item = nil data.query_item = nil
data.recipes = nil data.recipes = nil
data.usages = nil data.usages = nil
data.export_rcp = nil data.export_rcp = nil
data.export_usg = nil data.export_usg = nil
data.alt_items = nil data.alt_items = nil
data.items = data.items_raw data.confirm_trash = nil
data.items = data.items_raw
if data.current_itab > 1 then if data.current_itab > 1 then
sort_by_category(data) sort_by_category(data)
@ -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("image_button", i + 3.447 - (i * 0.4), 11.43, 0.35, 0.35, "", btn_name, "")
fs(fmt("tooltip[%s;%s]", btn_name, tooltip)) fs(fmt("tooltip[%s;%s]", btn_name, tooltip))
end 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 end
i3.new_tab { i3.new_tab {
@ -2602,9 +2615,16 @@ i3.new_tab {
end end
if fields.trash then if fields.trash then
local inv = player:get_inventory() data.confirm_trash = true
inv:set_list("main", {})
inv:set_list("craft", {}) 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 elseif fields.compress then
compress_items(player) compress_items(player)