Add ability to goto pagenum from pagenum button

This commit is contained in:
Jean-Patrick Guerrero 2022-08-14 19:18:29 +02:00
parent 7b31c998de
commit 0c4b4e6c4f
5 changed files with 33 additions and 5 deletions

View File

@ -595,6 +595,7 @@ local function reset_data(data)
data.scrbar_usg = 1 data.scrbar_usg = 1
data.query_item = nil data.query_item = nil
data.enable_search = nil data.enable_search = nil
data.goto_page = nil
data.recipes = nil data.recipes = nil
data.usages = nil data.usages = nil
data.export_rcp = nil data.export_rcp = nil

View File

@ -1,7 +1,7 @@
local set_fs = i3.set_fs local set_fs = i3.set_fs
IMPORT("vec_eq", "vec_round")
IMPORT("reg_items", "reg_aliases") IMPORT("reg_items", "reg_aliases")
IMPORT("min", "max", "vec_eq", "vec_round")
IMPORT("S", "random", "translate", "ItemStack") IMPORT("S", "random", "translate", "ItemStack")
IMPORT("sort", "copy", "insert", "remove", "indexof") IMPORT("sort", "copy", "insert", "remove", "indexof")
IMPORT("fmt", "find", "match", "sub", "lower", "split", "toupper") IMPORT("fmt", "find", "match", "sub", "lower", "split", "toupper")
@ -89,6 +89,7 @@ local function inv_fields(player, data, fields)
data.show_settings = nil data.show_settings = nil
data.waypoint_see = nil data.waypoint_see = nil
data.bag_rename = nil data.bag_rename = nil
data.goto_page = nil
if data.filter == "" then if data.filter == "" then
data.enable_search = nil data.enable_search = nil
@ -342,6 +343,14 @@ local function rcp_fields(player, data, fields)
sort_by_category(data) sort_by_category(data)
end end
elseif fields.pagenum then
data.goto_page = not data.goto_page
elseif fields.goto_page then
local pagenum = tonumber(fields.goto_page)
data.pagenum = max(1, min(data.pagemax, pagenum or data.pagenum))
data.goto_page = nil
elseif fields.prev_page or fields.next_page then elseif fields.prev_page or fields.next_page then
if data.pagemax == 1 then return end if data.pagemax == 1 then return end
data.pagenum -= (fields.prev_page and 1 or -1) data.pagenum -= (fields.prev_page and 1 or -1)
@ -428,9 +437,8 @@ core.register_on_player_receive_fields(function(player, formname, fields)
end end
-- No-op buttons -- No-op buttons
if fields.player_name or fields.awards or fields.home_pos or fields.pagenum or if fields.player_name or fields.awards or fields.home_pos or fields.no_item or
fields.no_item or fields.no_rcp or fields.select_sorting or fields.sort_method or fields.no_rcp or fields.select_sorting or fields.sort_method or fields.bg_content then
fields.bg_content then
return false return false
end end

View File

@ -1374,7 +1374,11 @@ local function get_items_fs(fs, data, player, full_height)
data.pagemax = max(1, ceil(#items / ipp)) data.pagemax = max(1, ceil(#items / ipp))
button(data.inv_width + 5.6, 0.14, 1.88, 0.7, "pagenum",
fs(fmt("style[pagenum;bgimg=%s;bgimg_hovered=%s;bgimg_middle=9;padding=-9]",
data.goto_page and PNG.pagenum_hover or "", PNG.pagenum_hover))
button(data.inv_width + 5.8, 0.14, 1.48, 0.7, "pagenum",
fmt("%s / %u", clr(colors.yellow, data.pagenum), data.pagemax)) fmt("%s / %u", clr(colors.yellow, data.pagenum), data.pagemax))
if #items == 0 then if #items == 0 then
@ -1417,6 +1421,19 @@ local function get_items_fs(fs, data, player, full_height)
end end
end end
if data.goto_page then
image(data.inv_width + 4.8, 0.85, 2.9, 0.8, PNG.bg_goto)
fs"style_type[label;font_size=16;textcolor=#ddd]"
label(data.inv_width + 5, 1.25, ES"Go to page" .. ":")
box(data.inv_width + 6.5, 1, 1, 0.45, "#bababa10")
fs(fmt("style[goto_page;font=mono,bold;font_size=16;textcolor=%s]", colors.yellow),
fmt("field[%f,%f;1,0.45;goto_page;;%s]", data.inv_width + 6.55, 1.05, data.pagenum),
"field_close_on_enter[goto_page;false]")
fs"style_type[label;font_size=16;textcolor=#fff]"
end
local _tabs = {"All", "Nodes", "Items"} local _tabs = {"All", "Nodes", "Items"}
local tab_len, tab_hgh = 1.8, 0.5 local tab_len, tab_hgh = 1.8, 0.5

View File

@ -4,6 +4,7 @@ local PNG = {
blank = "i3_blank.png", blank = "i3_blank.png",
bg = "i3_bg.png", bg = "i3_bg.png",
bg_full = "i3_bg_full.png", bg_full = "i3_bg_full.png",
bg_goto = "i3_bg_goto.png",
bg_content = "i3_bg_content.png", bg_content = "i3_bg_content.png",
bar = "i3_bar.png", bar = "i3_bar.png",
hotbar = "i3_hotbar.png", hotbar = "i3_hotbar.png",
@ -26,6 +27,7 @@ local PNG = {
cancel = "i3_cancel.png", cancel = "i3_cancel.png",
export = "i3_export.png", export = "i3_export.png",
slot = "i3_slot.png^\\[resize:128x128", slot = "i3_slot.png^\\[resize:128x128",
pagenum_hover = "i3_slot.png^\\[resize:128x128^\\[opacity:130",
tab = "i3_tab.png", tab = "i3_tab.png",
tab_small = "i3_tab_small.png", tab_small = "i3_tab_small.png",
tab_top = "i3_tab.png^\\[transformFY", tab_top = "i3_tab.png^\\[transformFY",

BIN
textures/i3_bg_goto.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB