Compare commits

..

13 Commits
1.7.3 ... 1.7.5

9 changed files with 65 additions and 49 deletions

View File

@ -20,14 +20,14 @@ local function lf(path)
end end
i3 = { i3 = {
version = 173, version = 175,
data = core.deserialize(storage:get_string"data") or {}, data = core.deserialize(storage:get_string"data") or {},
settings = { settings = {
debug_mode = false, debug_mode = false,
max_favs = 6, max_favs = 6,
max_waypoints = 30, max_waypoints = 30,
min_fs_version = 4, min_fs_version = 6,
item_btn_size = 1.1, item_btn_size = 1.1,
drop_bag_on_die = true, drop_bag_on_die = true,
save_interval = 600, -- Player data save interval (in seconds) save_interval = 600, -- Player data save interval (in seconds)

View File

@ -344,7 +344,7 @@ end
i3.add_sorting_method("alphabetical", { i3.add_sorting_method("alphabetical", {
description = S"Sort items by name (A-Z)", description = S"Sort items by name (A-Z)",
func = function(list, data) func = function(list, data)
sorter(list, data.reverse_sorting, 1) sorter(list, data, 1)
return list return list
end end
}) })
@ -352,7 +352,7 @@ i3.add_sorting_method("alphabetical", {
i3.add_sorting_method("numerical", { i3.add_sorting_method("numerical", {
description = S"Sort items by number of items per stack", description = S"Sort items by number of items per stack",
func = function(list, data) func = function(list, data)
sorter(list, data.reverse_sorting, 2) sorter(list, data, 2)
return list return list
end, end,
}) })

View File

@ -80,7 +80,7 @@ end
local function utf8_len(str) local function utf8_len(str)
local c = 0 local c = 0
for _ in str:gmatch"([%z\1-\127\194-\244][\128-\191]*)" do -- Arguably working duct-tape code for _ in str:gmatch"[%z\1-\127\194-\244][\128-\191]*" do -- Arguably working duct-tape code
c++ c++
end end
@ -482,15 +482,16 @@ local function get_sorting_idx(name)
return idx return idx
end end
local function sorter(inv, reverse, 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
a, b = a:get_name(), b:get_name() a = translate(data.lang_code, a:get_short_description())
b = translate(data.lang_code, b:get_short_description())
else else
a, b = a:get_count(), b:get_count() a, b = a:get_count(), b:get_count()
end end
if reverse then if data.reverse_sorting then
return a > b return a > b
end end

View File

@ -313,7 +313,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 data.filter == "" then if fields.filter and fields.filter == "" then
data.enable_search = nil data.enable_search = nil
end end

View File

@ -41,21 +41,21 @@ local function snip(str, limit)
return fmt("%s...", sub(str, 1, limit - 3)) return fmt("%s...", sub(str, 1, limit - 3))
end end
local function get_desc(item) local function get_desc(item, lang_code)
if sub(item, 1, 1) == "_" then if sub(item, 1, 1) == "_" then
item = sub(item, 2) item = sub(item, 2)
end end
local def = reg_items[item] local def = reg_items[item]
if not def then if not def then
return S("Unknown Item (@1)", item) return S("Unknown Item (@1)", item)
end end
local desc = def.description local desc = ItemStack(item):get_short_description()
desc = translate(lang_code, desc)
if true_str(desc) then if true_str(desc) then
desc = desc:trim():match("[^\n]*"):gsub("_", " ") desc = desc:trim():gsub("_", " ")
if not find(desc, "%u") then if not find(desc, "%u") then
desc = toupper(desc) desc = toupper(desc)
@ -670,7 +670,7 @@ local function get_inventory_fs(player, data, fs)
--fs("style[player_model;bgcolor=black]") --fs("style[player_model;bgcolor=black]")
model(0.2, 0.2, armor_skin and 4 or 3.4, ctn_hgt, model(0.2, 0.2, armor_skin and 4 or 3.4, ctn_hgt,
"player_model", props.mesh, textures, "0,-150", "false", "false", "player_model", props.mesh, textures, "0,-150", "false", "false",
fmt("%u,%u%s", anim.x, anim.y, data.fs_version >= 5 and ";30" or "")) fmt("%u,%u;30", anim.x, anim.y))
else else
local size = 2.5 local size = 2.5
image(0.7, 0.2, size, size * props.visual_size.y, props.textures[1]) image(0.7, 0.2, size, size * props.visual_size.y, props.textures[1])
@ -750,7 +750,7 @@ local function get_inventory_fs(player, data, fs)
show_popup(fs, data) show_popup(fs, data)
end end
local function get_tooltip(item, info, pos) local function get_tooltip(item, info, pos, lang_code)
local tooltip local tooltip
if info.groups then if info.groups then
@ -768,7 +768,7 @@ local function get_tooltip(item, info, pos)
tooltip = S("Any item belonging to the groups: @1", groupstr) tooltip = S("Any item belonging to the groups: @1", groupstr)
end end
else else
tooltip = info.meta_desc or get_desc(item) tooltip = info.meta_desc or get_desc(item, lang_code)
end end
local function add(str) local function add(str)
@ -786,7 +786,7 @@ local function get_tooltip(item, info, pos)
if info.replace then if info.replace then
for i = 1, #info.replace.items do for i = 1, #info.replace.items do
local rpl = ItemStack(info.replace.items[i]):get_name() local rpl = ItemStack(info.replace.items[i]):get_name()
local desc = clr("#ff0", get_desc(rpl)) local desc = clr("#ff0", get_desc(rpl, lang_code))
if info.replace.type == "cooking" then if info.replace.type == "cooking" then
tooltip = add(S("Replaced by @1 on smelting", desc)) tooltip = add(S("Replaced by @1 on smelting", desc))
@ -813,12 +813,13 @@ local function get_tooltip(item, info, pos)
if several then if several then
for i = 1, #info.tools do for i = 1, #info.tools do
names = fmt("%s\t\t- %s\n", names, clr("#ff0", get_desc(info.tools[i]))) names = fmt("%s\t\t- %s\n", names, clr("#ff0", get_desc(info.tools[i], lang_code)))
end end
tooltip = add(S("Only drop if using one of these tools: @1", sub(names, 1, -2))) tooltip = add(S("Only drop if using one of these tools: @1", sub(names, 1, -2)))
else else
tooltip = add(S("Only drop if using this tool: @1", clr("#ff0", get_desc(info.tools[1])))) tooltip = add(S("Only drop if using this tool: @1",
clr("#ff0", get_desc(info.tools[1], lang_code))))
end end
end end
@ -883,7 +884,6 @@ local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_siz
local name = item:get_name() local name = item:get_name()
local count = item:get_count() local count = item:get_count()
local wear = item:get_wear() local wear = item:get_wear()
local bt_s = BTN_SIZE * 1.2
local _name = fmt("_%s", name) local _name = fmt("_%s", name)
local pos local pos
@ -899,11 +899,11 @@ local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_siz
inv:set_stack("main", 1, item) inv:set_stack("main", 1, item)
pos = {x = X + 0.11, y = Y} pos = {x = X + 0.11, y = Y}
else else
image(X, Y - 0.11, bt_s, bt_s, PNG.slot) local size = BTN_SIZE * 1.2
item_image_button( slot(X, Y - 0.11, size, size)
X + 0.11, Y, BTN_SIZE, BTN_SIZE,
fmt("%s %u %u", name, count * (is_recipe and data.scrbar_rcp or data.scrbar_usg or 1), wear), count *= (is_recipe and data.scrbar_rcp or data.scrbar_usg or 1)
_name, "") item_image_button(X + 0.11, Y, BTN_SIZE, BTN_SIZE, fmt("%s %u %u", name, count, wear), _name, "")
end end
local def = reg_items[name] local def = reg_items[name]
@ -927,7 +927,7 @@ local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_siz
} }
if next(infos) then if next(infos) then
fs(get_tooltip(_name, infos, pos)) fs(get_tooltip(_name, infos, pos, data.lang_code))
end end
end end
@ -1026,11 +1026,11 @@ local function get_grid_fs(fs, data, rcp, is_recipe)
end end
if not large_recipe then if not large_recipe then
image(X, Y, btn_size, btn_size, PNG.slot) slot(X, Y, btn_size, btn_size)
end end
local btn_name = groups and fmt("group!%s!%s", groups[1], name) or name local btn_name = groups and fmt("group!%s!%s", groups[1], name) or name
local _count = count * (is_recipe and data.scrbar_rcp or data.scrbar_usg or 1) count *= (is_recipe and data.scrbar_rcp or data.scrbar_usg or 1)
if group_cache and group_cache.sprite and not large_recipe then if group_cache and group_cache.sprite and not large_recipe then
local sprite = ESC(group_cache.sprite) local sprite = ESC(group_cache.sprite)
@ -1040,11 +1040,11 @@ local function get_grid_fs(fs, data, rcp, is_recipe)
animated_image(X + 0.01, Y + 0.025, size, size, sprite, group_cache.count, 1500) animated_image(X + 0.01, Y + 0.025, size, size, sprite, group_cache.count, 1500)
label(X + 0.45, Y + 0.18, label) label(X + 0.45, Y + 0.18, label)
if _count > 1 then if count > 1 then
label(X + 0.8, Y + 0.9, _count) label(X + 0.8, Y + 0.9, count)
end end
else else
item_image_button(X, Y, btn_size, btn_size, fmt("%s %u", name, _count), btn_name, label) item_image_button(X, Y, btn_size, btn_size, fmt("%s %u", name, count), btn_name, label)
end end
local def = reg_items[name] local def = reg_items[name]
@ -1069,7 +1069,7 @@ local function get_grid_fs(fs, data, rcp, is_recipe)
} }
if next(infos) then if next(infos) then
fs(get_tooltip(btn_name, infos)) fs(get_tooltip(btn_name, infos, nil, data.lang_code))
end end
end end
@ -1182,7 +1182,7 @@ local function get_header(fs, data)
fs(fmt("tooltip[exit;%s]", ES"Back to item list")) fs(fmt("tooltip[exit;%s]", ES"Back to item list"))
local desc_lim, name_lim = 34, 35 local desc_lim, name_lim = 34, 35
local desc = translate(data.lang_code, get_desc(data.query_item)) local desc = get_desc(data.query_item, data.lang_code)
desc = ESC(desc) desc = ESC(desc)
local tech_name = data.query_item local tech_name = data.query_item
local X = data.inv_width + 0.95 local X = data.inv_width + 0.95
@ -1324,7 +1324,7 @@ local function get_items_fs(fs, data, player, full_height)
local ipp = rows * lines local ipp = rows * lines
local size = 0.85 local size = 0.85
bg9(data.inv_width + 0.1, 0, 7.9, full_height, PNG.bg_full, 10) bg9(data.inv_width + 0.1, 0, 7.9, full_height, PNG.bg_full)
if data.enable_search then if data.enable_search then
fs("set_focus[filter]", fs("set_focus[filter]",
@ -1334,7 +1334,7 @@ local function get_items_fs(fs, data, player, full_height)
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(data.inv_width + 0.9, 0.49, clr("#aaa", ES"Search..."))
button(data.inv_width + 0.8, 0.1, 4, 0.8, "enable_search", "") button(data.inv_width + 0.8, 0.12, 4, 0.8, "enable_search", "")
end end
image_button(data.inv_width + 0.35, 0.32, 0.35, 0.35, "", "search", "") image_button(data.inv_width + 0.35, 0.32, 0.35, 0.35, "", "search", "")
@ -1399,11 +1399,13 @@ local function get_items_fs(fs, data, player, full_height)
for i, title in ipairs(_tabs) do for i, title in ipairs(_tabs) do
local selected = i == data.itab local selected = i == data.itab
fs(fmt([[style_type[image_button;fgimg=%s;fgimg_hovered=%s;noclip=true; local hover_texture = selected and PNG.tab_small_hover or PNG.tab_small
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(fmt([[style_type[image_button;bgimg=%s;bgimg_hovered=%s;
bgimg_middle=14,0,-14,-14;padding=-14,0,14,14] ]], hover_texture, PNG.tab_small_hover))
fs(fmt("style_type[image_button;noclip=true;font_size=16;textcolor=%s;content_offset=0;sound=i3_tab]",
selected and "#fff" or "#ddd"))
fs"style_type[image_button:hovered;textcolor=#fff]" fs"style_type[image_button:hovered;textcolor=#fff]"
image_button((data.inv_width - 0.65) + (i * (tab_len + 0.1)), image_button((data.inv_width - 0.65) + (i * (tab_len + 0.1)),
full_height, tab_len, tab_hgh, "", fmt("itab_%u", i), title) full_height, tab_len, tab_hgh, "", fmt("itab_%u", i), title)
@ -1420,7 +1422,7 @@ local function get_favs(fs, data)
local Y = data.yoffset + 0.8 local Y = data.yoffset + 0.8
if data.query_item == item then if data.query_item == item then
image(X, Y, btn_size, btn_size, PNG.slot) slot(X, Y, btn_size, btn_size)
end end
item_image_button(X, Y, btn_size, btn_size, item, name, "") item_image_button(X, Y, btn_size, btn_size, item, name, "")
@ -1440,7 +1442,7 @@ local function get_panels(fs, data, player)
data.yoffset += panels[i - 1].height + 0.1 data.yoffset += panels[i - 1].height + 0.1
end end
bg9(data.inv_width + 0.1, data.yoffset, 7.9, panel.height, PNG.bg_full, 10) bg9(data.inv_width + 0.1, data.yoffset, 7.9, panel.height, PNG.bg_full)
local is_recipe, is_usage = panel.name == "recipes", panel.name == "usages" local is_recipe, is_usage = panel.name == "recipes", panel.name == "usages"
panel.func(fs, data, player, panel, is_recipe, is_usage) panel.func(fs, data, player, panel, is_recipe, is_usage)
@ -1472,11 +1474,18 @@ local function get_tabs_fs(fs, player, data, full_height)
end end
local selected = i == data.tab local selected = i == data.tab
local bgimg = selected and (btm and PNG.tab_hover or PNG.tab_hover_top) or
(btm and PNG.tab or PNG.tab_top)
local bgimg_hover = btm and PNG.tab_hover or PNG.tab_hover_top
fs(fmt([[style_type[image_button;fgimg=%s;fgimg_hovered=%s;noclip=true; local middle = btm and "16,0,-16,-16" or "16,0,-16,0"
font_size=16;textcolor=%s;content_offset=0;sound=i3_tab] ]], local padding = btm and "-16,0,16,16" or "-16,-16,16,16"
selected and (btm and PNG.tab_hover or PNG.tab_hover_top) or (btm and PNG.tab or PNG.tab_top),
btm and PNG.tab_hover or PNG.tab_hover_top, selected and "#fff" or "#ddd")) fs(fmt([[style_type[image_button;bgimg=%s;bgimg_hovered=%s;bgimg_middle=%s;padding=%s] ]],
bgimg, bgimg_hover, middle, padding))
fs(fmt("style_type[image_button;noclip=true;font_size=16;textcolor=%s;content_offset=0;sound=i3_tab]",
selected and "#fff" or "#ddd"))
local X = (data.inv_width / 2) + (c * (tab_len + 0.1)) - ((tab_len + 0.05) * (shift / 2)) local X = (data.inv_width / 2) + (c * (tab_len + 0.1)) - ((tab_len + 0.05) * (shift / 2))
local Y = btm and full_height or -tab_hgh local Y = btm and full_height or -tab_hgh
@ -1545,7 +1554,7 @@ local function make_fs(player, data)
fs(fmt("formspec_version[%u]size[%f,%f]no_prepend[]bgcolor[#0000]", fs(fmt("formspec_version[%u]size[%f,%f]no_prepend[]bgcolor[#0000]",
i3.settings.min_fs_version, data.inv_width + 8, full_height), styles) i3.settings.min_fs_version, data.inv_width + 8, full_height), styles)
bg9(0, 0, data.inv_width, full_height, PNG.bg_full, 10) bg9(0, 0, data.inv_width, full_height, PNG.bg_full)
local tab = i3.tabs[data.tab] local tab = i3.tabs[data.tab]

View File

@ -1,3 +1,5 @@
local fmt = string.format
local PNG = { local PNG = {
blank = "i3_blank.png", blank = "i3_blank.png",
bg = "i3_bg.png", bg = "i3_bg.png",
@ -23,7 +25,7 @@ local PNG = {
sign = "i3_sign.png", sign = "i3_sign.png",
cancel = "i3_cancel.png", cancel = "i3_cancel.png",
export = "i3_export.png", export = "i3_export.png",
slot = "i3_slot.png", slot = "i3_slot.png^\\[resize:128x128",
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",
@ -44,6 +46,7 @@ local PNG = {
edit = "i3_edit.png", edit = "i3_edit.png",
no_result = "i3_no_result.png", no_result = "i3_no_result.png",
find_more = "i3_find_more.png", find_more = "i3_find_more.png",
search_outline = "i3_search_outline.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,12 +77,13 @@ local styles = string.format([[
style_type[label,field;font_size=16] style_type[label,field;font_size=16]
style_type[button;border=false;content_offset=0] style_type[button;border=false;content_offset=0]
style_type[image_button,item_image_button,checkbox,dropdown;border=false;sound=i3_click] style_type[image_button,item_image_button,checkbox,dropdown;border=false;sound=i3_click]
style_type[item_image_button;bgimg_hovered=%s] style_type[item_image_button;bgimg_hovered=%s;bgimg_middle=9;padding=-9]
style[;sound=] style[;sound=]
style[nofav;sound=i3_cannot] style[nofav;sound=i3_cannot]
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[search;fgimg=%s;content_offset=0]
style[enable_search:hovered;bgimg=%s]
style[exit;fgimg=%s;fgimg_hovered=%s;content_offset=0] style[exit;fgimg=%s;fgimg_hovered=%s;content_offset=0]
style[cancel;fgimg=%s;fgimg_hovered=%s;content_offset=0] style[cancel;fgimg=%s;fgimg_hovered=%s;content_offset=0]
style[prev_page,prev_recipe,prev_usage,prev_sort,prev_skin;fgimg=%s;fgimg_hovered=%s] style[prev_page,prev_recipe,prev_usage,prev_sort,prev_skin;fgimg=%s;fgimg_hovered=%s]
@ -97,6 +101,7 @@ local styles = string.format([[
]], ]],
PNG.slot, PNG.slot,
PNG.search_hover, PNG.search_hover,
PNG.search_outline,
PNG.exit, PNG.exit_hover, PNG.exit, PNG.exit_hover,
PNG.cancel, PNG.cancel_hover, PNG.cancel, PNG.cancel_hover,
PNG.prev, PNG.prev_hover, PNG.prev, PNG.prev_hover,
@ -111,9 +116,10 @@ local fs_elements = {
tooltip = "tooltip[%f,%f;%f,%f;%s]", tooltip = "tooltip[%f,%f;%f,%f;%s]",
button = "button[%f,%f;%f,%f;%s;%s]", button = "button[%f,%f;%f,%f;%s;%s]",
checkbox = "checkbox[%f,%f;%s;%s;%s]", checkbox = "checkbox[%f,%f;%s;%s;%s]",
slot = "image[%f,%f;%f,%f;" .. fmt("%s;9]", PNG.slot),
item_image = "item_image[%f,%f;%f,%f;%s]", item_image = "item_image[%f,%f;%f,%f;%s]",
hypertext = "hypertext[%f,%f;%f,%f;%s;%s]", hypertext = "hypertext[%f,%f;%f,%f;%s;%s]",
bg9 = "background9[%f,%f;%f,%f;%s;false;%u]", bg9 = "background9[%f,%f;%f,%f;%s;false;12]",
scrollbar = "scrollbar[%f,%f;%f,%f;%s;%s;%u]", scrollbar = "scrollbar[%f,%f;%f,%f;%s;%s;%u]",
model = "model[%f,%f;%f,%f;%s;%s;%s;%s;%s;%s;%s]", model = "model[%f,%f;%f,%f;%s;%s;%s;%s;%s;%s;%s]",
image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]", image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB