Add tabs to item list

This commit is contained in:
Jean-Patrick Guerrero 2021-06-26 04:40:57 +02:00
parent a1b2d03a71
commit b24411b189
4 changed files with 61 additions and 29 deletions

View File

@ -24,6 +24,7 @@ local PNG = {
export = "i3_export.png", export = "i3_export.png",
slot = "i3_slot.png", slot = "i3_slot.png",
tab = "i3_tab.png", tab = "i3_tab.png",
tab_small = "i3_tab_small.png",
tab_top = "i3_tab.png^\\[transformFY", tab_top = "i3_tab.png^\\[transformFY",
furnace_anim = "i3_furnace_anim.png", furnace_anim = "i3_furnace_anim.png",
bag = "i3_bag.png", bag = "i3_bag.png",
@ -48,6 +49,7 @@ local PNG = {
prev_hover = "i3_next_hover.png^\\[transformFX", prev_hover = "i3_next_hover.png^\\[transformFX",
next_hover = "i3_next_hover.png", next_hover = "i3_next_hover.png",
tab_hover = "i3_tab_hover.png", tab_hover = "i3_tab_hover.png",
tab_small_hover = "i3_tab_small_hover.png",
tab_hover_top = "i3_tab_hover.png^\\[transformFY", tab_hover_top = "i3_tab_hover.png^\\[transformFY",
bag_hover = "i3_bag_hover.png", bag_hover = "i3_bag_hover.png",
armor_hover = "i3_armor_hover.png", armor_hover = "i3_armor_hover.png",

View File

@ -7,7 +7,6 @@ local pdata = dslz(storage:get_string "pdata") or {}
-- Caches -- Caches
local init_items = {} local init_items = {}
local searches = {}
local recipes_cache = {} local recipes_cache = {}
local usages_cache = {} local usages_cache = {}
local fuel_cache = {} local fuel_cache = {}
@ -571,17 +570,15 @@ local function show_item(def)
def.description and def.description ~= "" def.description and def.description ~= ""
end end
local function search(data) local function reset_compression(data)
data.alt_items = nil data.alt_items = nil
data.expand = "" data.expand = ""
local filter = data.filter
if searches[filter] then
data.items = searches[filter]
return
end end
local function search(data)
reset_compression(data)
local filter = data.filter
local opt = "^(.-)%+([%w_]+)=([%w_,]+)" local opt = "^(.-)%+([%w_]+)=([%w_,]+)"
local search_filter = next(search_filters) and match(filter, opt) local search_filter = next(search_filters) and match(filter, opt)
local filters = {} local filters = {}
@ -629,16 +626,36 @@ local function search(data)
end end
end end
if not next(recipe_filters) then data.items = filtered_list
-- Cache the results only if searched 2 times end
if searches[filter] == nil then
searches[filter] = false local function sort_by_category(data)
else reset_compression(data)
searches[filter] = filtered_list local items = copy(data.items_raw)
if data.filter ~= "" then
search(data)
items = copy(data.items)
end
local new = {}
for i = 1, #items do
local item = items[i]
local to_add = true
if data.current_itab == 2 then
to_add = reg_nodes[item]
elseif data.current_itab == 3 then
to_add = reg_craftitems[item] or reg_tools[item]
end
if to_add then
new[#new + 1] = item
end end
end end
data.items = filtered_list data.items = new
end end
local function get_item_usages(item, recipe, added) local function get_item_usages(item, recipe, added)
@ -1661,7 +1678,7 @@ local function get_rcp_extra(player, fs, data, panel, is_recipe, is_usage)
fs("container_end[]") fs("container_end[]")
end end
local function get_items_fs(fs, data, extend) local function get_items_fs(fs, data, full_height)
if compression_active(data) then if compression_active(data) then
local new = {} local new = {}
@ -1676,8 +1693,7 @@ local function get_items_fs(fs, data, extend)
end end
local items = data.alt_items or data.items local items = data.alt_items or data.items
local rows = 8 local rows, lines = 8, 12
local lines = extend and 12 or 9
local ipp = rows * lines local ipp = rows * lines
local size = 0.85 local size = 0.85
@ -1718,7 +1734,7 @@ local function get_items_fs(fs, data, extend)
X = X - (X * 0.045) + data.inv_width + 0.28 X = X - (X * 0.045) + data.inv_width + 0.28
local Y = round((i % ipp - X) / rows + 1, 0) local Y = round((i % ipp - X) / rows + 1, 0)
Y = Y - (Y * (extend and 0.085 or 0.035)) + 0.95 Y = Y - (Y * 0.085) + 0.95
fs[#fs + 1] = fmt("item_image_button", X, Y, size, size, name, item, "") fs[#fs + 1] = fmt("item_image_button", X, Y, size, size, name, item, "")
@ -1732,6 +1748,22 @@ local function get_items_fs(fs, data, extend)
end end
end end
end end
local _tabs = {"All", "Nodes", "Items"}
local tab_len, tab_hgh = 1.8, 0.5
for i, title in ipairs(_tabs) do
local selected = i == data.current_itab
fs(fmt([[style_type[image_button;fgimg=%s;fgimg_hovered=%s;noclip=true;
font_size=16;textcolor=%s;content_offset=0;sound=i3_tab] ]],
selected and PNG.tab_small_hover or PNG.tab_small,
PNG.tab_small_hover, selected and "#fff" or "#ddd"))
fs("style_type[image_button:hovered;textcolor=#fff]")
fs("image_button", (data.inv_width - 0.65) + (i * (tab_len + 0.1)),
full_height, tab_len, tab_hgh, "", fmt("itab_%u", i), title)
end
end end
local function get_favs(fs, data) local function get_favs(fs, data)
@ -1753,21 +1785,15 @@ end
local function get_panels(player, data, fs, full_height) local function get_panels(player, data, fs, full_height)
local _title = {name = "title", height = 1.4} local _title = {name = "title", height = 1.4}
local _favs = {name = "favs", height = 2.23} local _favs = {name = "favs", height = 2.23}
local _items = {name = "items", height = 9.69} local _items = {name = "items", height = full_height}
local _recipes = {name = "recipes", rcp = data.recipes, height = 4.045} local _recipes = {name = "recipes", rcp = data.recipes, height = 4.045}
local _usages = {name = "usages", rcp = data.usages, height = 4.045} local _usages = {name = "usages", rcp = data.usages, height = 4.045}
local panels, extend local panels
if data.query_item then if data.query_item then
panels = {_title, _recipes, _usages, _favs} panels = {_title, _recipes, _usages, _favs}
else else
panels = {_items, _favs} panels = {_items}
if #data.favs == 0 then
extend = true
remove(panels, 2)
_items.height = full_height
end
end end
for idx = 1, #panels do for idx = 1, #panels do
@ -1787,7 +1813,7 @@ local function get_panels(player, data, fs, full_height)
if is_recipe or is_usage then if is_recipe or is_usage then
get_rcp_extra(player, fs, data, panel, is_recipe, is_usage) get_rcp_extra(player, fs, data, panel, is_recipe, is_usage)
elseif panel.name == "items" then elseif panel.name == "items" then
get_items_fs(fs, data, extend) get_items_fs(fs, data, full_height)
elseif panel.name == "title" then elseif panel.name == "title" then
get_header(fs, data) get_header(fs, data)
elseif panel.name == "favs" then elseif panel.name == "favs" then
@ -2251,6 +2277,7 @@ local function init_data(player, info)
data.favs = {} data.favs = {}
data.export_counts = {} data.export_counts = {}
data.current_tab = 1 data.current_tab = 1
data.current_itab = 1
data.subcat = 1 data.subcat = 1
data.scrbar_inv = 0 data.scrbar_inv = 0
data.lang_code = get_lang_code(info) data.lang_code = get_lang_code(info)
@ -3035,6 +3062,9 @@ core.register_on_player_receive_fields(function(player, formname, fields)
local tabname = sub(f, 5) local tabname = sub(f, 5)
set_tab(player, tabname) set_tab(player, tabname)
break break
elseif sub(f, 1, 5) == "itab_" then
data.current_itab = tonum(f:sub(-1))
sort_by_category(data)
end end
end end

BIN
textures/i3_tab_small.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB