mirror of
https://github.com/minetest-mods/i3.git
synced 2025-07-03 00:50:22 +02:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
1389027a22 | |||
629676a975 | |||
20b8110375 | |||
a3fea93a09 | |||
326ee3e098 | |||
60bdfa34fb | |||
9971b8c3e6 | |||
5a14116b69 | |||
222e04d2c4 | |||
8f4c9f28f1 | |||
37e0c21ca3 |
4
init.lua
4
init.lua
@ -20,14 +20,14 @@ local function lf(path)
|
||||
end
|
||||
|
||||
i3 = {
|
||||
version = 174,
|
||||
version = 175,
|
||||
data = core.deserialize(storage:get_string"data") or {},
|
||||
|
||||
settings = {
|
||||
debug_mode = false,
|
||||
max_favs = 6,
|
||||
max_waypoints = 30,
|
||||
min_fs_version = 4,
|
||||
min_fs_version = 6,
|
||||
item_btn_size = 1.1,
|
||||
drop_bag_on_die = true,
|
||||
save_interval = 600, -- Player data save interval (in seconds)
|
||||
|
@ -344,7 +344,7 @@ end
|
||||
i3.add_sorting_method("alphabetical", {
|
||||
description = S"Sort items by name (A-Z)",
|
||||
func = function(list, data)
|
||||
sorter(list, data.reverse_sorting, 1)
|
||||
sorter(list, data, 1)
|
||||
return list
|
||||
end
|
||||
})
|
||||
@ -352,7 +352,7 @@ i3.add_sorting_method("alphabetical", {
|
||||
i3.add_sorting_method("numerical", {
|
||||
description = S"Sort items by number of items per stack",
|
||||
func = function(list, data)
|
||||
sorter(list, data.reverse_sorting, 2)
|
||||
sorter(list, data, 2)
|
||||
return list
|
||||
end,
|
||||
})
|
||||
|
@ -80,7 +80,7 @@ end
|
||||
local function utf8_len(str)
|
||||
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++
|
||||
end
|
||||
|
||||
@ -482,15 +482,16 @@ local function get_sorting_idx(name)
|
||||
return idx
|
||||
end
|
||||
|
||||
local function sorter(inv, reverse, mode)
|
||||
local function sorter(inv, data, mode)
|
||||
sort(inv, function(a, b)
|
||||
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
|
||||
a, b = a:get_count(), b:get_count()
|
||||
end
|
||||
|
||||
if reverse then
|
||||
if data.reverse_sorting then
|
||||
return a > b
|
||||
end
|
||||
|
||||
|
83
src/gui.lua
83
src/gui.lua
@ -41,21 +41,21 @@ local function snip(str, limit)
|
||||
return fmt("%s...", sub(str, 1, limit - 3))
|
||||
end
|
||||
|
||||
local function get_desc(item)
|
||||
local function get_desc(item, lang_code)
|
||||
if sub(item, 1, 1) == "_" then
|
||||
item = sub(item, 2)
|
||||
end
|
||||
|
||||
local def = reg_items[item]
|
||||
|
||||
if not def then
|
||||
return S("Unknown Item (@1)", item)
|
||||
end
|
||||
|
||||
local desc = def.description
|
||||
local desc = ItemStack(item):get_short_description()
|
||||
desc = translate(lang_code, desc)
|
||||
|
||||
if true_str(desc) then
|
||||
desc = desc:trim():match("[^\n]*"):gsub("_", " ")
|
||||
desc = desc:trim():gsub("_", " ")
|
||||
|
||||
if not find(desc, "%u") then
|
||||
desc = toupper(desc)
|
||||
@ -670,7 +670,7 @@ local function get_inventory_fs(player, data, fs)
|
||||
--fs("style[player_model;bgcolor=black]")
|
||||
model(0.2, 0.2, armor_skin and 4 or 3.4, ctn_hgt,
|
||||
"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
|
||||
local size = 2.5
|
||||
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)
|
||||
end
|
||||
|
||||
local function get_tooltip(item, info, pos)
|
||||
local function get_tooltip(item, info, pos, lang_code)
|
||||
local tooltip
|
||||
|
||||
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)
|
||||
end
|
||||
else
|
||||
tooltip = info.meta_desc or get_desc(item)
|
||||
tooltip = info.meta_desc or get_desc(item, lang_code)
|
||||
end
|
||||
|
||||
local function add(str)
|
||||
@ -786,7 +786,7 @@ local function get_tooltip(item, info, pos)
|
||||
if info.replace then
|
||||
for i = 1, #info.replace.items do
|
||||
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
|
||||
tooltip = add(S("Replaced by @1 on smelting", desc))
|
||||
@ -813,12 +813,13 @@ local function get_tooltip(item, info, pos)
|
||||
|
||||
if several then
|
||||
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
|
||||
|
||||
tooltip = add(S("Only drop if using one of these tools: @1", sub(names, 1, -2)))
|
||||
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
|
||||
|
||||
@ -883,7 +884,6 @@ local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_siz
|
||||
local name = item:get_name()
|
||||
local count = item:get_count()
|
||||
local wear = item:get_wear()
|
||||
local bt_s = BTN_SIZE * 1.2
|
||||
local _name = fmt("_%s", name)
|
||||
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)
|
||||
pos = {x = X + 0.11, y = Y}
|
||||
else
|
||||
image(X, Y - 0.11, bt_s, bt_s, PNG.slot)
|
||||
item_image_button(
|
||||
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),
|
||||
_name, "")
|
||||
local size = BTN_SIZE * 1.2
|
||||
slot(X, Y - 0.11, size, size)
|
||||
|
||||
count *= (is_recipe and data.scrbar_rcp or data.scrbar_usg or 1)
|
||||
item_image_button(X + 0.11, Y, BTN_SIZE, BTN_SIZE, fmt("%s %u %u", name, count, wear), _name, "")
|
||||
end
|
||||
|
||||
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
|
||||
fs(get_tooltip(_name, infos, pos))
|
||||
fs(get_tooltip(_name, infos, pos, data.lang_code))
|
||||
end
|
||||
end
|
||||
|
||||
@ -1026,11 +1026,11 @@ local function get_grid_fs(fs, data, rcp, is_recipe)
|
||||
end
|
||||
|
||||
if not large_recipe then
|
||||
image(X, Y, btn_size, btn_size, PNG.slot)
|
||||
slot(X, Y, btn_size, btn_size)
|
||||
end
|
||||
|
||||
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
|
||||
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)
|
||||
label(X + 0.45, Y + 0.18, label)
|
||||
|
||||
if _count > 1 then
|
||||
label(X + 0.8, Y + 0.9, _count)
|
||||
if count > 1 then
|
||||
label(X + 0.8, Y + 0.9, count)
|
||||
end
|
||||
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
|
||||
|
||||
local def = reg_items[name]
|
||||
@ -1069,7 +1069,7 @@ local function get_grid_fs(fs, data, rcp, is_recipe)
|
||||
}
|
||||
|
||||
if next(infos) then
|
||||
fs(get_tooltip(btn_name, infos))
|
||||
fs(get_tooltip(btn_name, infos, nil, data.lang_code))
|
||||
end
|
||||
end
|
||||
|
||||
@ -1182,7 +1182,7 @@ local function get_header(fs, data)
|
||||
fs(fmt("tooltip[exit;%s]", ES"Back to item list"))
|
||||
|
||||
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)
|
||||
local tech_name = data.query_item
|
||||
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 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
|
||||
fs("set_focus[filter]",
|
||||
@ -1334,7 +1334,7 @@ local function get_items_fs(fs, data, player, full_height)
|
||||
else
|
||||
fs"style_type[label;font=italic;font_size=18]"
|
||||
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
|
||||
|
||||
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
|
||||
local selected = i == data.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"))
|
||||
local hover_texture = selected and PNG.tab_small_hover or PNG.tab_small
|
||||
|
||||
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]"
|
||||
image_button((data.inv_width - 0.65) + (i * (tab_len + 0.1)),
|
||||
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
|
||||
|
||||
if data.query_item == item then
|
||||
image(X, Y, btn_size, btn_size, PNG.slot)
|
||||
slot(X, Y, btn_size, btn_size)
|
||||
end
|
||||
|
||||
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
|
||||
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"
|
||||
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
|
||||
|
||||
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;
|
||||
font_size=16;textcolor=%s;content_offset=0;sound=i3_tab] ]],
|
||||
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"))
|
||||
local middle = btm and "16,0,-16,-16" or "16,0,-16,0"
|
||||
local padding = btm and "-16,0,16,16" or "-16,-16,16,16"
|
||||
|
||||
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 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]",
|
||||
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]
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
local fmt = string.format
|
||||
|
||||
local PNG = {
|
||||
blank = "i3_blank.png",
|
||||
bg = "i3_bg.png",
|
||||
@ -23,7 +25,7 @@ local PNG = {
|
||||
sign = "i3_sign.png",
|
||||
cancel = "i3_cancel.png",
|
||||
export = "i3_export.png",
|
||||
slot = "i3_slot.png",
|
||||
slot = "i3_slot.png^\\[resize:128x128",
|
||||
tab = "i3_tab.png",
|
||||
tab_small = "i3_tab_small.png",
|
||||
tab_top = "i3_tab.png^\\[transformFY",
|
||||
@ -44,6 +46,7 @@ local PNG = {
|
||||
edit = "i3_edit.png",
|
||||
no_result = "i3_no_result.png",
|
||||
find_more = "i3_find_more.png",
|
||||
search_outline = "i3_search_outline.png",
|
||||
|
||||
cancel_hover = "i3_cancel.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[button;border=false;content_offset=0]
|
||||
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[nofav;sound=i3_cannot]
|
||||
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[exit;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]
|
||||
@ -97,6 +101,7 @@ local styles = string.format([[
|
||||
]],
|
||||
PNG.slot,
|
||||
PNG.search_hover,
|
||||
PNG.search_outline,
|
||||
PNG.exit, PNG.exit_hover,
|
||||
PNG.cancel, PNG.cancel_hover,
|
||||
PNG.prev, PNG.prev_hover,
|
||||
@ -111,9 +116,10 @@ local fs_elements = {
|
||||
tooltip = "tooltip[%f,%f;%f,%f;%s]",
|
||||
button = "button[%f,%f;%f,%f;%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]",
|
||||
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]",
|
||||
model = "model[%f,%f;%f,%f;%s;%s;%s;%s;%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 |
BIN
textures/i3_search_outline.png
Normal file
BIN
textures/i3_search_outline.png
Normal file
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 |
Reference in New Issue
Block a user