Redesign settings

This commit is contained in:
Jean-Patrick Guerrero 2022-08-15 17:42:11 +02:00
parent 8db3fb4a41
commit 2cdd03b127
4 changed files with 56 additions and 87 deletions

View File

@ -211,13 +211,13 @@ local function init_data(player, info)
data.items = i3.init_items data.items = i3.init_items
data.items_raw = i3.init_items data.items_raw = i3.init_items
data.favs = {} data.favs = {}
data.sort = "alphabetical"
data.show_setting = "home" data.show_setting = "home"
data.ignore_hotbar = false data.ignore_hotbar = false
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.crafting_counts = {} data.crafting_counts = {}
data.sort = 1
data.tab = 1 data.tab = 1
data.itab = 1 data.itab = 1
data.subcat = 1 data.subcat = 1

View File

@ -477,18 +477,6 @@ local function safe_teleport(player, pos)
player:set_pos(p) player:set_pos(p)
end end
local function get_sorting_idx(name)
local idx = 1
for i, def in ipairs(i3.sorting_methods) do
if name == def.name then
idx = i
end
end
return idx
end
local function sorter(inv, data, mode) local function sorter(inv, data, mode)
sort(inv, function(a, b) sort(inv, function(a, b)
if mode == 1 then if mode == 1 then
@ -577,8 +565,7 @@ local function sort_inventory(player, data)
list = pre_sorting(list, start_i) list = pre_sorting(list, start_i)
end end
local idx = get_sorting_idx(data.sort) local new_inv = i3.sorting_methods[data.sort].func(list, data)
local new_inv = i3.sorting_methods[idx].func(list, data)
if not new_inv then return end if not new_inv then return end
if not data.ignore_hotbar then if not data.ignore_hotbar then
@ -674,7 +661,6 @@ local _ = {
sorter = sorter, sorter = sorter,
get_recipes = get_recipes, get_recipes = get_recipes,
sort_inventory = sort_inventory, sort_inventory = sort_inventory,
get_sorting_idx = get_sorting_idx,
sort_by_category = sort_by_category, sort_by_category = sort_by_category,
apply_recipe_filters = apply_recipe_filters, apply_recipe_filters = apply_recipe_filters,

View File

@ -5,8 +5,8 @@ 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")
IMPORT("search", "sort_inventory", "sort_by_category", "get_recipes", "get_detached_inv")
IMPORT("msg", "is_fav", "pos_to_str", "str_to_pos", "add_hud_waypoint", "play_sound", "reset_data") IMPORT("msg", "is_fav", "pos_to_str", "str_to_pos", "add_hud_waypoint", "play_sound", "reset_data")
IMPORT("search", "get_sorting_idx", "sort_inventory", "sort_by_category", "get_recipes", "get_detached_inv")
IMPORT("valid_item", "get_stack", "craft_stack", "clean_name", "compressible", "check_privs", "safe_teleport") IMPORT("valid_item", "get_stack", "craft_stack", "clean_name", "compressible", "check_privs", "safe_teleport")
local function inv_fields(player, data, fields) local function inv_fields(player, data, fields)
@ -124,19 +124,8 @@ local function inv_fields(player, data, fields)
elseif fields.sort then elseif fields.sort then
sort_inventory(player, data) sort_inventory(player, data)
elseif fields.prev_sort or fields.next_sort then elseif fields.dd_sorting_method then
local idx = get_sorting_idx(data.sort) data.sort = tonumber(fields.dd_sorting_method)
local tot = #i3.sorting_methods
idx -= (fields.prev_sort and 1 or -1)
if idx > tot then
idx = 1
elseif idx == 0 then
idx = tot
end
data.sort = i3.sorting_methods[idx].name
elseif fields.home then elseif fields.home then
if not data.home then if not data.home then

View File

@ -11,10 +11,10 @@ local VoxelArea, VoxelManip = VoxelArea, VoxelManip
IMPORT("find", "match", "sub", "upper") IMPORT("find", "match", "sub", "upper")
IMPORT("vec_new", "vec_sub", "vec_round") IMPORT("vec_new", "vec_sub", "vec_round")
IMPORT("clr", "ESC", "msg", "check_privs") IMPORT("clr", "ESC", "msg", "check_privs")
IMPORT("compression_active", "compressible")
IMPORT("min", "max", "floor", "ceil", "round") IMPORT("min", "max", "floor", "ceil", "round")
IMPORT("reg_items", "reg_tools", "reg_entities") IMPORT("reg_items", "reg_tools", "reg_entities")
IMPORT("true_str", "is_fav", "is_num", "str_to_pos") IMPORT("true_str", "is_fav", "is_num", "str_to_pos")
IMPORT("get_sorting_idx", "compression_active", "compressible")
IMPORT("get_bag_description", "get_detached_inv", "get_recipes") IMPORT("get_bag_description", "get_detached_inv", "get_recipes")
IMPORT("S", "ES", "translate", "ItemStack", "toupper", "utf8_len") IMPORT("S", "ES", "translate", "ItemStack", "toupper", "utf8_len")
IMPORT("maxn", "sort", "concat", "copy", "insert", "remove", "unpack") IMPORT("maxn", "sort", "concat", "copy", "insert", "remove", "unpack")
@ -572,45 +572,37 @@ local function get_container(fs, data, player, yoffset, ctn_len, award_list, awa
end end
end end
local function show_popup(fs, data) local function show_settings(fs, data)
if data.confirm_trash then if data.confirm_trash then
fs"style_type[box;colors=#999,#999,#808080,#808080]" image(2.9, 10.65, 4.6, 0.7, PNG.bg_goto)
for _ = 1, 3 do
box(2.97, 10.75, 4.3, 0.5, "")
end
label(3.12, 11, "Confirm trash?") label(3.12, 11, "Confirm trash?")
image_button(5.17, 10.75, 1, 0.5, "", "confirm_trash_yes", "Yes") image_button(5.17, 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.27, 10.75, 1, 0.5, "", "confirm_trash_no", "No")
elseif data.show_settings then elseif data.show_settings then
fs"style_type[box;colors=#999,#999,#808080,#808080]" image(2.2, 9, 6, 2.35, PNG.bg_content)
for _ = 1, 3 do
box(2.1, 9.25, 6, 2, "")
end
for _ = 1, 3 do
box(2.1, 9.25, 6, 0.5, "#707070")
end
image_button(7.75, 9.35, 0.25, 0.25, PNG.cancel_hover .. "^\\[brighten", "close_settings", "")
local show_home = data.show_setting == "home" local show_home = data.show_setting == "home"
local show_style = data.show_setting == "style"
local show_sorting = data.show_setting == "sorting" local show_sorting = data.show_setting == "sorting"
local show_misc = data.show_setting == "misc"
fs(fmt("style[setting_home;textcolor=%s;font=bold;font_size=16;sound=i3_click]", fs"style[setting_home,setting_style,setting_sorting;font=bold;font_size=16;sound=i3_click]"
fs(fmt("style[setting_home;bgimg=%s;bgimg_hovered=%s;bgimg_middle=9;padding=-9;textcolor=%s]",
show_home and PNG.pagenum_hover or "", PNG.pagenum_hover,
show_home and colors.yellow or "#fff"), show_home and colors.yellow or "#fff"),
fmt("style[setting_sorting;textcolor=%s;font=bold;font_size=16;sound=i3_click]", fmt("style[setting_style;bgimg=%s;bgimg_hovered=%s;bgimg_middle=9;padding=-9;textcolor=%s]",
show_sorting and colors.yellow or "#fff"), show_style and PNG.pagenum_hover or "", PNG.pagenum_hover,
fmt("style[setting_misc;textcolor=%s;font=bold;font_size=16;sound=i3_click]", show_style and colors.yellow or "#fff"),
show_misc and colors.yellow or "#fff")) fmt("style[setting_sorting;bgimg=%s;bgimg_hovered=%s;bgimg_middle=9;padding=-9;textcolor=%s]",
show_sorting and PNG.pagenum_hover or "", PNG.pagenum_hover,
show_sorting and colors.yellow or "#fff"))
button(2.2, 9.25, 1.8, 0.55, "setting_home", "Home") local X = 2.5
button(4, 9.25, 1.8, 0.55, "setting_sorting", "Sorting") button(X, 9.1, 1.6, 0.55, "setting_home", "Home")
button(5.8, 9.25, 1.8, 0.55, "setting_misc", "Misc.") button(X + 1.6, 9.1, 1.6, 0.55, "setting_style", "Style")
button(X + 3.2, 9.1, 1.6, 0.55, "setting_sorting", "Sorting")
image_button(X + 5, 9.2, 0.25, 0.25, PNG.cancel_hover .. "^\\[brighten", "close_settings", "")
if show_home then if show_home then
local coords, c, str = {"X", "Y", "Z"}, 0, ES"No home set" local coords, c, str = {"X", "Y", "Z"}, 0, ES"No home set"
@ -620,41 +612,44 @@ local function show_popup(fs, data)
"(%-?%d+)", function(a) "(%-?%d+)", function(a)
c++ c++
return fmt("<b>%s: <style color=%s font=mono>%s</style></b>", return fmt("<b>%s: <style color=%s font=mono>%s</style></b>",
coords[c], colors.black, a) coords[c], colors.blue, a)
end) end)
end end
hypertext(2.1, 9.9, 6, 0.6, "home_pos", fmt("<global size=16><center>%s</center>", str)) hypertext(2.1, 9.9, 6, 0.6, "home_pos", fmt("<global size=16><center>%s</center>", str))
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_sorting then elseif show_style then
button(2.1, 9.7, 6, 0.8, "select_sorting", ES"Select the inventory sorting method:")
image_button(2.2, 10.6, 0.35, 0.35, "", "prev_sort", "")
image_button(7.65, 10.6, 0.35, 0.35, "", "next_sort", "")
fs"style[sort_method;font=bold;font_size=20]"
button(2.55, 10.36, 5.1, 0.8, "sort_method", toupper(data.sort))
local idx = get_sorting_idx(data.sort)
local desc = i3.sorting_methods[idx].description
if desc then
fs(fmt("tooltip[%s;%s]", "sort_method", desc))
end
elseif show_misc then
checkbox(2.4, 10.05, "cb_inv_compress", "Compression", tostring(data.inv_compress))
checkbox(2.4, 10.5, "cb_reverse_sorting", "Reverse mode", tostring(data.reverse_sorting))
checkbox(2.4, 10.95, "cb_ignore_hotbar", "Ignore hotbar", tostring(data.ignore_hotbar))
checkbox(5.4, 10.05, "cb_auto_sorting", "Automation", tostring(data.auto_sorting))
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(5.4, 10.55, ES"Font size" .. fmt(": %s", sign .. data.font_size)) label(2.6, 10.05, 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[5.4,10.8;2.5,0.25;horizontal;sb_font_size;%d]", data.font_size)) fs(fmt("scrollbar[2.6,10.3;2.5,0.3;horizontal;sb_font_size;%d]", data.font_size))
elseif show_sorting then
checkbox(2.6, 10.05, "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.95, "cb_ignore_hotbar", "Ignore hotbar", tostring(data.ignore_hotbar))
checkbox(5.5, 10.05, "cb_auto_sorting", "Automation", tostring(data.auto_sorting))
local methods = {}
for _, v in ipairs(i3.sorting_methods) do
local name = toupper(v.name)
insert(methods, name)
end
fs"style_type[label;font_size=14]"
label(5.5, 10.45, ES"Sorting method:")
fs(fmt("dropdown[%f,%f;2.3,0.5;dd_sorting_method;%s;%u;true]",
5.5, 10.6, concat(methods, ","), data.sort))
fs"style_type[label;font_size=16]"
local desc = i3.sorting_methods[data.sort].description
if desc then
tooltip(5.5, 10.6, 2.3, 0.5, ESC(desc))
end
fs(fmt("tooltip[cb_inv_compress;%s;#707070;#fff]", fs(fmt("tooltip[cb_inv_compress;%s;#707070;#fff]",
ES"Enable this option to compress your inventory"), ES"Enable this option to compress your inventory"),
@ -767,7 +762,7 @@ local function get_inventory_fs(player, data, fs)
fs(fmt("tooltip[%s;%s]", btn_name, tooltip)) fs(fmt("tooltip[%s;%s]", btn_name, tooltip))
end end
show_popup(fs, data) show_settings(fs, data)
end end
local function get_tooltip(item, info, pos, lang_code) local function get_tooltip(item, info, pos, lang_code)
@ -1398,7 +1393,6 @@ local function get_items_fs(fs, data, player, full_height)
data.pagemax = max(1, ceil(#items / ipp)) data.pagemax = max(1, ceil(#items / ipp))
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))