Improve Quick Crafting look a bit

This commit is contained in:
Jean-Patrick Guerrero 2022-08-14 20:12:28 +02:00
parent aeeac6ac1b
commit 0e2f233234
7 changed files with 46 additions and 37 deletions

View File

@ -217,7 +217,7 @@ local function init_data(player, info)
data.auto_sorting = false data.auto_sorting = false
data.reverse_sorting = false data.reverse_sorting = false
data.inv_compress = true data.inv_compress = true
data.export_counts = {} data.crafting_counts = {}
data.tab = 1 data.tab = 1
data.itab = 1 data.itab = 1
data.subcat = 1 data.subcat = 1

View File

@ -413,7 +413,7 @@ local function craft_stack(player, data, craft_rcp)
local stackname, stackcount, stackmax = output:get_name(), output:get_count(), output:get_stack_max() local stackname, stackcount, stackmax = output:get_name(), output:get_count(), output:get_stack_max()
local scrbar_val = data[fmt("scrbar_%s", craft_rcp and "rcp" or "usg")] or 1 local scrbar_val = data[fmt("scrbar_%s", craft_rcp and "rcp" or "usg")] or 1
for name, count in pairs(data.export_counts[rcp_usg].rcp) do for name, count in pairs(data.crafting_counts[rcp_usg].rcp) do
local items = {[name] = count} local items = {[name] = count}
if is_group(name) then if is_group(name) then
@ -424,7 +424,7 @@ local function craft_stack(player, data, craft_rcp)
local remaining = count local remaining = count
for _, item in ipairs(item_groups) do for _, item in ipairs(item_groups) do
for _name, _count in pairs(data.export_counts[rcp_usg].inv) do for _name, _count in pairs(data.crafting_counts[rcp_usg].inv) do
if item == _name and remaining > 0 then if item == _name and remaining > 0 then
local c = min(remaining, _count) local c = min(remaining, _count)
items[item] = c items[item] = c
@ -598,8 +598,8 @@ local function reset_data(data)
data.goto_page = nil data.goto_page = nil
data.recipes = nil data.recipes = nil
data.usages = nil data.usages = nil
data.export_rcp = nil data.crafting_rcp = nil
data.export_usg = nil data.crafting_usg = nil
data.alt_items = nil data.alt_items = nil
data.confirm_trash = nil data.confirm_trash = nil
data.show_settings = nil data.show_settings = nil

View File

@ -304,8 +304,8 @@ local function select_item(player, data, fields)
data.unum = 1 data.unum = 1
data.scrbar_rcp = 1 data.scrbar_rcp = 1
data.scrbar_usg = 1 data.scrbar_usg = 1
data.export_rcp = nil data.crafting_rcp = nil
data.export_usg = nil data.crafting_usg = nil
end end
end end
@ -374,13 +374,13 @@ local function rcp_fields(player, data, fields)
elseif fields.prev_recipe or fields.next_recipe then elseif fields.prev_recipe or fields.next_recipe then
local num = data.rnum + (fields.prev_recipe and -1 or 1) local num = data.rnum + (fields.prev_recipe and -1 or 1)
data.rnum = data.recipes[num] and num or (fields.prev_recipe and #data.recipes or 1) data.rnum = data.recipes[num] and num or (fields.prev_recipe and #data.recipes or 1)
data.export_rcp = nil data.crafting_rcp = nil
data.scrbar_rcp = 1 data.scrbar_rcp = 1
elseif fields.prev_usage or fields.next_usage then elseif fields.prev_usage or fields.next_usage then
local num = data.unum + (fields.prev_usage and -1 or 1) local num = data.unum + (fields.prev_usage and -1 or 1)
data.unum = data.usages[num] and num or (fields.prev_usage and #data.usages or 1) data.unum = data.usages[num] and num or (fields.prev_usage and #data.usages or 1)
data.export_usg = nil data.crafting_usg = nil
data.scrbar_usg = 1 data.scrbar_usg = 1
elseif fields.fav then elseif fields.fav then
@ -392,17 +392,17 @@ local function rcp_fields(player, data, fields)
remove(data.favs, fav) remove(data.favs, fav)
end end
elseif fields.export_rcp or fields.export_usg then elseif fields.crafting_rcp or fields.crafting_usg then
if fields.export_rcp then if fields.crafting_rcp then
data.export_rcp = not data.export_rcp data.crafting_rcp = not data.crafting_rcp
if not data.export_rcp then if not data.crafting_rcp then
data.scrbar_rcp = 1 data.scrbar_rcp = 1
end end
else else
data.export_usg = not data.export_usg data.crafting_usg = not data.crafting_usg
if not data.export_usg then if not data.crafting_usg then
data.scrbar_usg = 1 data.scrbar_usg = 1
end end
end end
@ -415,10 +415,10 @@ local function rcp_fields(player, data, fields)
craft_stack(player, data, fields.craft_rcp) craft_stack(player, data, fields.craft_rcp)
if fields.craft_rcp then if fields.craft_rcp then
data.export_rcp = nil data.crafting_rcp = nil
data.scrbar_rcp = 1 data.scrbar_rcp = 1
else else
data.export_usg = nil data.crafting_usg = nil
data.scrbar_usg = 1 data.scrbar_usg = 1
end end
else else

View File

@ -82,8 +82,8 @@ local function get_stack_max(inv, data, is_recipe, rcp)
counts_rcp[it] = (counts_rcp[it] or 0) + 1 counts_rcp[it] = (counts_rcp[it] or 0) + 1
end end
data.export_counts[rcp_usg] = {} data.crafting_counts[rcp_usg] = {}
data.export_counts[rcp_usg].rcp = counts_rcp data.crafting_counts[rcp_usg].rcp = counts_rcp
for i = 1, size do for i = 1, size do
local stack = list[i] local stack = list[i]
@ -111,7 +111,7 @@ local function get_stack_max(inv, data, is_recipe, rcp)
end end
end end
data.export_counts[rcp_usg].inv = counts_inv data.crafting_counts[rcp_usg].inv = counts_inv
for name in pairs(counts_rcp) do for name in pairs(counts_rcp) do
counts[name] = floor((counts_inv[name] or 0) / (counts_rcp[name] or 0)) counts[name] = floor((counts_inv[name] or 0) / (counts_rcp[name] or 0))
@ -365,7 +365,7 @@ local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
if waypoint_preview then if waypoint_preview then
image(0.25, y - 3.5, 5, 4, PNG.bg_content) image(0.25, y - 3.5, 5, 4, PNG.bg_content)
fs"style[area_preview;font_size=16]" fs"style[area_preview;font_size=16;textcolor=#ddd]"
button(0.25, y - 3.35, 5, 0.55, "area_preview", v.name) button(0.25, y - 3.35, 5, 0.55, "area_preview", v.name)
image_button(4.65, y - 3.25, 0.25, 0.25, PNG.cancel_hover .. "^\\[brighten", "close_preview", "") image_button(4.65, y - 3.25, 0.25, 0.25, PNG.cancel_hover .. "^\\[brighten", "close_preview", "")
@ -374,7 +374,7 @@ local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
end end
end end
fs"style_type[label;font=normal;font_size=16]" fs"style_type[label;font=normal;font_size=16;textcolor=#fff]"
end end
local function get_bag_fs(fs, data, name, esc_name, bag_size, yextra) local function get_bag_fs(fs, data, name, esc_name, bag_size, yextra)
@ -1236,16 +1236,16 @@ local function get_header(fs, data)
end end
end end
local function get_export_fs(fs, data, is_recipe, is_usage, max_stacks_rcp, max_stacks_usg) local function get_crafting_fs(fs, data, is_recipe, is_usage, max_stacks_rcp, max_stacks_usg)
local name = is_recipe and "rcp" or "usg" local name = is_recipe and "rcp" or "usg"
local show_export = (is_recipe and data.export_rcp) or (is_usage and data.export_usg) local show_crafting = (is_recipe and data.crafting_rcp) or (is_usage and data.crafting_usg)
fs(fmt("style[export_%s;fgimg=%s;fgimg_hovered=%s]", fs(fmt("style[crafting_%s;fgimg=%s;fgimg_hovered=%s;content_offset=0]",
name, fmt("%s", show_export and PNG.export_hover or PNG.export), PNG.export_hover)) name, fmt("%s", show_crafting and PNG.crafting_hover or PNG.crafting), PNG.crafting_hover))
image_button(data.inv_width + 7.35, data.yoffset + 0.2, 0.45, 0.45, "", fmt("export_%s", name), "") image_button(data.inv_width + 7.35, data.yoffset + 0.2, 0.45, 0.45, "", fmt("crafting_%s", name), "")
fs(fmt("tooltip[export_%s;%s]", name, ES"Quick crafting")) fs(fmt("tooltip[crafting_%s;%s]", name, ES"Quick crafting"))
if not show_export then return end if not show_crafting then return end
local craft_max = is_recipe and max_stacks_rcp or max_stacks_usg local craft_max = is_recipe and max_stacks_rcp or max_stacks_usg
local stack_fs = (is_recipe and data.scrbar_rcp) or (is_usage and data.scrbar_usg) or 1 local stack_fs = (is_recipe and data.scrbar_rcp) or (is_usage and data.scrbar_usg) or 1
@ -1260,12 +1260,21 @@ local function get_export_fs(fs, data, is_recipe, is_usage, max_stacks_rcp, max_
end end
end end
local x = data.inv_width + 6.8
fs"style_type[image,button,image_button;noclip=true]"
image(x, data.yoffset + 0.8, 3, 2, PNG.bg_content)
fs"style[quick_crafting;font_size=16;textcolor=#ddd]"
button(x, data.yoffset + 0.85, 3.05, 0.55, "quick_crafting", ES"Quick Crafting")
fs(fmt("style[scrbar_%s;noclip=true]", name), fs(fmt("style[scrbar_%s;noclip=true]", name),
fmt("scrollbaroptions[min=1;max=%u;smallstep=1]", craft_max)) fmt("scrollbaroptions[min=1;max=%u;smallstep=1]", craft_max))
local x = data.inv_width + 8.1 scrollbar(x + 0.2, data.yoffset + 1.45, 2.5, 0.35, "horizontal", fmt("scrbar_%s", name), stack_fs)
scrollbar(x, data.yoffset, 2.5, 0.35, "horizontal", fmt("scrbar_%s", name), stack_fs) button(x + 0.2, data.yoffset + 1.85, 2.5, 0.7, fmt("craft_%s", name), ES("Craft (×@1)", stack_fs))
button(x, data.yoffset + 0.4, 2.5, 0.7, fmt("craft_%s", name), ES("Craft (×@1)", stack_fs))
fs"style_type[label;font_size=16;textcolor=#fff]"
fs"style_type[image,button,image_button;noclip=false]"
end end
local function get_rcp_extra(fs, data, player, panel, is_recipe, is_usage) local function get_rcp_extra(fs, data, player, panel, is_recipe, is_usage)
@ -1287,15 +1296,15 @@ local function get_rcp_extra(fs, data, player, panel, is_recipe, is_usage)
end end
if is_recipe and max_stacks_rcp == 0 then if is_recipe and max_stacks_rcp == 0 then
data.export_rcp = nil data.crafting_rcp = nil
data.scrbar_rcp = 1 data.scrbar_rcp = 1
elseif is_usage and max_stacks_usg == 0 then elseif is_usage and max_stacks_usg == 0 then
data.export_usg = nil data.crafting_usg = nil
data.scrbar_usg = 1 data.scrbar_usg = 1
end end
if max_stacks_rcp > 0 or max_stacks_usg > 0 then if max_stacks_rcp > 0 or max_stacks_usg > 0 then
get_export_fs(fs, data, is_recipe, is_usage, max_stacks_rcp, max_stacks_usg) get_crafting_fs(fs, data, is_recipe, is_usage, max_stacks_rcp, max_stacks_usg)
end end
get_rcp_lbl(fs, data, panel, rn, is_recipe) get_rcp_lbl(fs, data, panel, rn, is_recipe)

View File

@ -26,7 +26,7 @@ local PNG = {
book = "i3_book.png", book = "i3_book.png",
sign = "i3_sign.png", sign = "i3_sign.png",
cancel = "i3_cancel.png", cancel = "i3_cancel.png",
export = "i3_export.png", crafting = "i3_crafting.png",
slot = "i3_slot.png^\\[resize:128x128", slot = "i3_slot.png^\\[resize:128x128",
pagenum_hover = "i3_slot.png^\\[resize:128x128^\\[opacity:130", pagenum_hover = "i3_slot.png^\\[resize:128x128^\\[opacity:130",
tab = "i3_tab.png", tab = "i3_tab.png",
@ -54,7 +54,7 @@ local PNG = {
cancel_hover = "i3_cancel.png^\\[brighten", cancel_hover = "i3_cancel.png^\\[brighten",
search_hover = "i3_search.png^\\[brighten", search_hover = "i3_search.png^\\[brighten",
export_hover = "i3_export.png^\\[brighten", crafting_hover = "i3_crafting.png^\\[brighten",
trash_hover = "i3_trash.png^\\[brighten^\\[colorize:#f00:100", trash_hover = "i3_trash.png^\\[brighten^\\[colorize:#f00:100",
compress_hover = "i3_compress.png^\\[brighten", compress_hover = "i3_compress.png^\\[brighten",
sort_hover = "i3_sort.png^\\[brighten", sort_hover = "i3_sort.png^\\[brighten",

BIN
textures/i3_crafting.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB