Add checkbox to change the panel style (preview: https://i.imgur.com/gNPLf0B.png)

This commit is contained in:
Jean-Patrick Guerrero 2022-08-15 20:15:43 +02:00
parent e300539dd3
commit 52464d4486
10 changed files with 100 additions and 53 deletions

View File

@ -53,6 +53,7 @@ i3 = {
bag = true, bag = true,
home = true, home = true,
font_size = true, font_size = true,
hide_tabs = true,
waypoints = true, waypoints = true,
inv_items = true, inv_items = true,
known_recipes = true, known_recipes = true,

View File

@ -178,7 +178,7 @@ local function inv_fields(player, data, fields)
for _, v in ipairs(data.waypoints) do for _, v in ipairs(data.waypoints) do
if vec_eq(vec_round(pos), vec_round(str_to_pos(v.pos))) then if vec_eq(vec_round(pos), vec_round(str_to_pos(v.pos))) then
play_sound(name, "i3_cannot", 0.8) play_sound(name, "i3_cannot", 0.8)
return msg(name, S"You already set a waypoint at this position") return msg(name, S"You already have set a waypoint at this position")
end end
end end
@ -301,7 +301,7 @@ end
local function rcp_fields(player, data, fields) local function rcp_fields(player, data, fields)
local sb_rcp, sb_usg = fields.scrbar_rcp, fields.scrbar_usg local sb_rcp, sb_usg = fields.scrbar_rcp, fields.scrbar_usg
if fields.filter and fields.filter == "" then if not data.hide_tabs and fields.filter and fields.filter == "" then
data.enable_search = nil data.enable_search = nil
end end
@ -312,7 +312,11 @@ local function rcp_fields(player, data, fields)
data.query_item = nil data.query_item = nil
elseif fields.enable_search then elseif fields.enable_search then
if data.hide_tabs then
data.enable_search = not data.enable_search
else
data.enable_search = true data.enable_search = true
end
elseif fields.filter and (fields.key_enter_field == "filter" or fields.search) then elseif fields.filter and (fields.key_enter_field == "filter" or fields.search) then
if fields.filter == "" then if fields.filter == "" then

View File

@ -299,7 +299,7 @@ end
local function get_waypoint_fs(fs, data, player, yextra, ctn_len) local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
fs(fmt("box[0,%f;4.9,0.6;#bababa25]", yextra + 1.1)) fs(fmt("box[0,%f;4.9,0.6;#bababa25]", yextra + 1.1))
label(0, yextra + 0.85, ES"Waypoint name:") label(0, yextra + 0.85, ES"New waypoint" .. ":")
fs(fmt("field[0.1,%f;4.8,0.6;waypoint_name;;]", yextra + 1.1)) fs(fmt("field[0.1,%f;4.8,0.6;waypoint_name;;]", yextra + 1.1))
image_button(5.1, yextra + 1.15, 0.5, 0.5, "", "waypoint_add", "") image_button(5.1, yextra + 1.15, 0.5, 0.5, "", "waypoint_add", "")
fs(fmt("tooltip[waypoint_add;%s]", ES"Add waypoint")) fs(fmt("tooltip[waypoint_add;%s]", ES"Add waypoint"))
@ -574,10 +574,10 @@ end
local function show_settings(fs, data) local function show_settings(fs, data)
if data.confirm_trash then if data.confirm_trash then
image(2.9, 10.65, 4.6, 0.7, PNG.bg_goto) image(2.8, 10.65, 4.6, 0.7, PNG.bg_goto)
label(3.12, 11, "Confirm trash?") label(3.02, 11, "Confirm trash?")
image_button(5.17, 10.75, 1, 0.5, "", "confirm_trash_yes", "Yes") image_button(5.07, 10.75, 1, 0.5, "", "confirm_trash_yes", "Yes")
image_button(6.27, 10.75, 1, 0.5, "", "confirm_trash_no", "No") image_button(6.17, 10.75, 1, 0.5, "", "confirm_trash_no", "No")
elseif data.show_settings then elseif data.show_settings then
image(2.2, 9, 6, 2.35, PNG.bg_content) image(2.2, 9, 6, 2.35, PNG.bg_content)
@ -623,18 +623,20 @@ local function show_settings(fs, data)
image_button(4.2, 10.4, 1.8, 0.7, "", "set_home", "Set home") image_button(4.2, 10.4, 1.8, 0.7, "", "set_home", "Set home")
elseif show_style then elseif show_style then
checkbox(2.6, 9.95, "cb_hide_tabs", "Hide tabs", tostring(data.hide_tabs))
local sign = (data.font_size > 0 and "+") or (data.font_size > 0 and "-") or "" local sign = (data.font_size > 0 and "+") or (data.font_size > 0 and "-") or ""
label(2.6, 10.05, ES"Font size" .. fmt(": %s", sign .. data.font_size)) label(2.6, 10.45, ES"Font size" .. fmt(": %s", sign .. data.font_size))
local range = 5 local range = 5
fs(fmt("scrollbaroptions[min=-%u;max=%u;smallstep=1;largestep=1;thumbsize=2]", range, range)) fs(fmt("scrollbaroptions[min=-%u;max=%u;smallstep=1;largestep=1;thumbsize=2]", range, range))
fs(fmt("scrollbar[2.6,10.3;2.5,0.3;horizontal;sb_font_size;%d]", data.font_size)) fs(fmt("scrollbar[2.6,10.65;2.5,0.3;horizontal;sb_font_size;%d]", data.font_size))
elseif show_sorting then elseif show_sorting then
checkbox(2.6, 10.05, "cb_inv_compress", "Compression", tostring(data.inv_compress)) checkbox(2.6, 9.95, "cb_inv_compress", "Compression", tostring(data.inv_compress))
checkbox(2.6, 10.5, "cb_reverse_sorting", "Reverse mode", tostring(data.reverse_sorting)) checkbox(2.6, 10.4, "cb_reverse_sorting", "Reverse mode", tostring(data.reverse_sorting))
checkbox(2.6, 10.95, "cb_ignore_hotbar", "Ignore hotbar", tostring(data.ignore_hotbar)) checkbox(2.6, 10.85, "cb_ignore_hotbar", "Ignore hotbar", tostring(data.ignore_hotbar))
checkbox(5.5, 10.05, "cb_auto_sorting", "Automation", tostring(data.auto_sorting)) checkbox(5.5, 9.95, "cb_auto_sorting", "Automation", tostring(data.auto_sorting))
local methods = {} local methods = {}
@ -643,11 +645,9 @@ local function show_settings(fs, data)
insert(methods, name) insert(methods, name)
end end
fs"style_type[label;font_size=14]" label(5.5, 10.4, ES"Sorting method:")
label(5.5, 10.45, ES"Sorting method:")
fs(fmt("dropdown[%f,%f;2.3,0.5;dd_sorting_method;%s;%u;true]", fs(fmt("dropdown[%f,%f;2.3,0.5;dd_sorting_method;%s;%u;true]",
5.5, 10.6, concat(methods, ","), data.sort)) 5.5, 10.6, concat(methods, ","), data.sort))
fs"style_type[label;font_size=16]"
local desc = i3.sorting_methods[data.sort].description local desc = i3.sorting_methods[data.sort].description
if desc then if desc then
@ -1359,52 +1359,85 @@ local function hide_items(player, data)
end end
end end
local function get_header_items_fs(fs, data, full_height) local function get_header_items_fs(fs, data)
local X = data.inv_width
fs"set_focus[filter;true]"
if data.hide_tabs then
fs(fmt("style[enable_search;bgimg=%s;bgimg_hovered=%s;bgimg_pressed=%s]",
data.enable_search and PNG.search_hover or PNG.search, PNG.search_hover, PNG.search_hover))
image_button(X + 0.3, 0.2, 0.5, 0.5, "", "enable_search", "")
fs(fmt("tooltip[enable_search;%s]", ES"Search"))
if data.enable_search then if data.enable_search then
fs("set_focus[filter]", image(X + 0.4, 0.75, 3.4, 0.8, PNG.bg_goto)
"style[filter;font_size=18;textcolor=#ccc]",
fmt("field[%f,0.2;3.35,0.6;filter;;%s]", data.inv_width + 0.85, ESC(data.filter)), fs("style[filter;font_size=16]",
fmt("field[%f,%f;3,0.45;filter;;%s]", X + 0.6, 0.95, data.filter),
"field_close_on_enter[filter;false]")
end
box(X + 1, 0.2, 0.01, 0.5, "#bababa50")
local cat = {{"all", "all items"}, {"node", "nodes only"}, {"item", "items only"}}
for i, name in ipairs(cat) do
local name, desc = unpack(cat[i])
local active = PNG[name .. "_hover"]
fs(fmt("style[itab_%u;bgimg=%s;bgimg_hovered=%s;bgimg_pressed=%s;sound=i3_tab]",
i, data.itab == i and active or PNG[name], active, active))
image_button(X + 1.25 + ((i - 1) * 0.7), 0.2, 0.5, 0.5, "", fmt("itab_%s", i), "")
fs(fmt("tooltip[itab_%u;Show %s]", i, desc))
end
else
fs(fmt("style[search;bgimg=%s]", PNG.search_hover))
image_button(X + 0.35, 0.32, 0.35, 0.35, "", "search", "")
fs(fmt("tooltip[search;%s]", ES"Search"))
if data.enable_search then
fs("style[filter;font_size=18]",
fmt("field[%f,0.2;3.35,0.6;filter;;%s]", X + 0.85, ESC(data.filter)),
"field_close_on_enter[filter;false]") "field_close_on_enter[filter;false]")
image(data.inv_width + 0.85, 0.75, 4, 0.01, PNG.search_outline_trim .. "^[opacity:100") image(X + 0.85, 0.75, 4, 0.01, PNG.search_outline_trim .. "^[opacity:100")
else else
fs"style_type[label;font=italic;font_size=18]" fs"style_type[label;font=italic;font_size=18]"
label(data.inv_width + 0.9, 0.49, clr("#aaa", ES"Search...")) label(X + 0.9, 0.49, clr("#aaa", ES"Search..."))
button(data.inv_width + 0.8, 0.12, 4, 0.8, "enable_search", "") button(X + 0.8, 0.12, 4, 0.8, "enable_search", "")
fs"style_type[label;font=normal;font_size=16]" fs"style_type[label;font=normal;font_size=16]"
end end
image_button(data.inv_width + 0.35, 0.32, 0.35, 0.35, "", "search", "")
image_button(data.inv_width + 5.27, 0.3, 0.35, 0.35, "", "prev_page", "")
image_button(data.inv_width + 7.45, 0.3, 0.35, 0.35, "", "next_page", "")
fs(fmt("tooltip[search;%s]", ES"Search"))
if true_str(data.filter) then if true_str(data.filter) then
image_button(data.inv_width + 4.3, 0.4, 0.2, 0.2, "", "cancel", "") image_button(X + 4.3, 0.4, 0.2, 0.2, "", "cancel", "")
fs(fmt("tooltip[cancel;%s]", ES"Clear")) fs(fmt("tooltip[cancel;%s]", ES"Clear"))
box(data.inv_width + 0.85, 0.75, 3.74, 0.01, "#f9826c") box(X + 0.85, 0.75, 3.74, 0.01, "#f9826c")
end end
end
image_button(X + 5.27, 0.3, 0.35, 0.35, "", "prev_page", "")
image_button(X + 7.45, 0.3, 0.35, 0.35, "", "next_page", "")
fs(fmt("style[pagenum;bgimg=%s;bgimg_hovered=%s;bgimg_middle=9;padding=-9;sound=i3_click]", fs(fmt("style[pagenum;bgimg=%s;bgimg_hovered=%s;bgimg_middle=9;padding=-9;sound=i3_click]",
data.goto_page and PNG.pagenum_hover or "", PNG.pagenum_hover)) data.goto_page and PNG.pagenum_hover or "", PNG.pagenum_hover))
button(data.inv_width + 5.8, 0.14, 1.48, 0.7, "pagenum", button(X + 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 data.goto_page then if data.goto_page then
image(data.inv_width + 4.8, 0.85, 2.9, 0.8, PNG.bg_goto) image(X + 4.8, 0.85, 2.9, 0.8, PNG.bg_goto)
fs"style_type[label;font_size=16;textcolor=#ddd]" fs"style_type[label;font_size=16;textcolor=#ddd]"
label(data.inv_width + 5, 1.25, ES"Go to page" .. ":") label(X + 5, 1.25, ES"Go to page" .. ":")
box(data.inv_width + 6.5, 1, 1, 0.45, "#bababa10") box(X + 6.5, 1, 1, 0.45, "#bababa10")
fs(fmt("style[goto_page;font=mono,bold;font_size=16;textcolor=%s]", colors.yellow), 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), fmt("field[%f,%f;1,0.45;goto_page;;%s]", X + 6.55, 1.05, data.pagenum),
"field_close_on_enter[goto_page;false]") "field_close_on_enter[goto_page;false]")
fs"style_type[label;font_size=16;textcolor=#fff]" fs"style_type[label;font_size=16;textcolor=#fff]"
end end
end
local function get_minitabs(fs, data, full_height)
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
@ -1474,7 +1507,7 @@ local function get_items_fs(fs, data, player, full_height)
end end
end end
get_header_items_fs(fs, data, full_height) get_header_items_fs(fs, data)
end end
local function get_favs(fs, data) local function get_favs(fs, data)
@ -1633,6 +1666,10 @@ local function make_fs(player, data)
get_items_fs(fs, data, player, full_height) get_items_fs(fs, data, player, full_height)
end end
if not data.hide_tabs then
get_minitabs(fs, data, full_height)
end
local visible_tabs = #i3.tabs local visible_tabs = #i3.tabs
for _, def in ipairs(i3.tabs) do for _, def in ipairs(i3.tabs) do

View File

@ -51,6 +51,9 @@ local PNG = {
find_more = "i3_find_more.png", find_more = "i3_find_more.png",
search_outline = "i3_search_outline.png", search_outline = "i3_search_outline.png",
search_outline_trim = "i3_search_outline_trim.png", search_outline_trim = "i3_search_outline_trim.png",
all = "i3_all.png",
node = "i3_node.png",
item = "i3_item.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",
@ -74,6 +77,9 @@ local PNG = {
exit_hover = "i3_exit.png^\\[brighten", exit_hover = "i3_exit.png^\\[brighten",
home_hover = "i3_home.png^\\[brighten", home_hover = "i3_home.png^\\[brighten",
edit_hover = "i3_edit.png^\\[brighten", edit_hover = "i3_edit.png^\\[brighten",
all_hover = "i3_all_on.png^\\[brighten",
node_hover = "i3_node_on.png^\\[brighten",
item_hover = "i3_item_on.png^\\[brighten",
} }
local styles = string.format([[ local styles = string.format([[
@ -86,8 +92,8 @@ local styles = string.format([[
style[;sound=] style[;sound=]
style[nofav;sound=i3_cannot] style[nofav;sound=i3_cannot]
style[search;content_offset=0]
style[pagenum,no_item,no_rcp;font=bold;font_size=18] style[pagenum,no_item,no_rcp;font=bold;font_size=18]
style[search;fgimg=%s;content_offset=0]
style[enable_search:hovered;bgimg=%s] style[enable_search:hovered;bgimg=%s]
style[enable_search:pressed;bgimg=%s^[opacity:178] style[enable_search:pressed;bgimg=%s^[opacity:178]
style[exit;fgimg=%s;fgimg_hovered=%s;content_offset=0] style[exit;fgimg=%s;fgimg_hovered=%s;content_offset=0]
@ -106,7 +112,6 @@ local styles = string.format([[
style[confirm_trash_yes;sound=i3_trash] style[confirm_trash_yes;sound=i3_trash]
]], ]],
PNG.slot, PNG.slot,
PNG.search_hover,
PNG.search_outline, PNG.search_outline, PNG.search_outline, PNG.search_outline,
PNG.exit, PNG.exit_hover, PNG.exit, PNG.exit_hover,
PNG.cancel, PNG.cancel_hover, PNG.cancel, PNG.cancel_hover,

BIN
textures/i3_all.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
textures/i3_all_on.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
textures/i3_item.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
textures/i3_item_on.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
textures/i3_node.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
textures/i3_node_on.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB