mirror of
https://github.com/minetest-mods/i3.git
synced 2025-07-02 00:20:23 +02:00
Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
1e9c3ce55a | |||
1627172cce | |||
bd356e4a40 | |||
f26c6af9c4 | |||
3f2d983091 | |||
6dd95a6a87 | |||
32779ab56f | |||
4ccff6621b | |||
7d0f25e8b2 | |||
652c486249 | |||
9ab47fc0f0 | |||
c635343c9b | |||
662c938afb | |||
b2c8447971 |
1
init.lua
1
init.lua
@ -20,6 +20,7 @@ local function lf(path)
|
||||
end
|
||||
|
||||
i3 = {
|
||||
version = 173,
|
||||
data = core.deserialize(storage:get_string"data") or {},
|
||||
|
||||
settings = {
|
||||
|
@ -34,7 +34,7 @@ local function cache_groups(group, groups)
|
||||
local items = i3.groups[group].items
|
||||
if #items <= 1 then return end
|
||||
|
||||
local c, px, lim = 0, 256, 10
|
||||
local px, lim, c = 64, 10, 0
|
||||
local sprite = "[combine:WxH"
|
||||
|
||||
for _, item in ipairs(items) do
|
||||
@ -44,11 +44,10 @@ local function cache_groups(group, groups)
|
||||
|
||||
if def.drawtype and is_cube(def.drawtype) then
|
||||
texture = get_cube(tiles)
|
||||
elseif texture then
|
||||
texture = texture:gsub("%^", "\\^"):gsub(":", "\\:") .. "\\^[resize\\:150x150"
|
||||
end
|
||||
|
||||
if texture then
|
||||
texture = texture:gsub("%^", "\\^"):gsub(":", "\\:") .. fmt("\\^[resize\\:%ux%u", px, px)
|
||||
sprite = sprite .. fmt(":0,%u=%s", c * px, texture)
|
||||
c++
|
||||
if c == lim then break end
|
||||
|
@ -77,6 +77,16 @@ local function toupper(str)
|
||||
return str:gsub("%f[%w]%l", upper):gsub("_", " ")
|
||||
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
|
||||
c++
|
||||
end
|
||||
|
||||
return c
|
||||
end
|
||||
|
||||
local function get_bag_description(data, stack)
|
||||
local desc = translate(data.lang_code, stack:get_description())
|
||||
desc = split(desc, "(")[1] or desc
|
||||
@ -606,6 +616,7 @@ local function reset_data(data)
|
||||
data.scrbar_rcp = 1
|
||||
data.scrbar_usg = 1
|
||||
data.query_item = nil
|
||||
data.enable_search = nil
|
||||
data.recipes = nil
|
||||
data.usages = nil
|
||||
data.export_rcp = nil
|
||||
@ -748,6 +759,7 @@ local _ = {
|
||||
match = string.match,
|
||||
gmatch = string.gmatch,
|
||||
toupper = toupper,
|
||||
utf8_len = utf8_len,
|
||||
|
||||
-- Table
|
||||
maxn = table.maxn,
|
||||
|
@ -95,6 +95,10 @@ local function inv_fields(player, data, fields)
|
||||
data.waypoint_see = nil
|
||||
data.bag_rename = nil
|
||||
|
||||
if data.filter == "" then
|
||||
data.enable_search = nil
|
||||
end
|
||||
|
||||
elseif fields.trash then
|
||||
data.show_settings = nil
|
||||
data.confirm_trash = true
|
||||
@ -309,13 +313,21 @@ end
|
||||
local function rcp_fields(player, data, fields)
|
||||
local sb_rcp, sb_usg = fields.scrbar_rcp, fields.scrbar_usg
|
||||
|
||||
if data.filter == "" then
|
||||
data.enable_search = nil
|
||||
end
|
||||
|
||||
if fields.cancel then
|
||||
reset_data(data)
|
||||
|
||||
elseif fields.exit then
|
||||
data.query_item = nil
|
||||
|
||||
elseif fields.key_enter_field == "filter" or fields.search then
|
||||
elseif fields.enable_search then
|
||||
data.enable_search = true
|
||||
return set_fs(player)
|
||||
|
||||
elseif fields.filter and (fields.key_enter_field == "filter" or fields.search) then
|
||||
if fields.filter == "" then
|
||||
reset_data(data)
|
||||
return set_fs(player)
|
||||
|
63
src/gui.lua
63
src/gui.lua
@ -14,9 +14,9 @@ IMPORT("clr", "ESC", "msg", "check_privs")
|
||||
IMPORT("min", "max", "floor", "ceil", "round")
|
||||
IMPORT("reg_items", "reg_tools", "reg_entities")
|
||||
IMPORT("true_str", "is_fav", "is_num", "str_to_pos")
|
||||
IMPORT("S", "ES", "translate", "ItemStack", "toupper")
|
||||
IMPORT("get_sorting_idx", "compression_active", "compressible")
|
||||
IMPORT("get_bag_description", "get_detached_inv", "get_recipes")
|
||||
IMPORT("S", "ES", "translate", "ItemStack", "toupper", "utf8_len")
|
||||
IMPORT("maxn", "sort", "concat", "copy", "insert", "remove", "unpack")
|
||||
IMPORT("extract_groups", "groups_to_items", "is_group", "item_has_groups", "get_group")
|
||||
|
||||
@ -38,7 +38,7 @@ local function weird_desc(str)
|
||||
end
|
||||
|
||||
local function snip(str, limit)
|
||||
return #str > limit and fmt("%s...", sub(str, 1, limit - 3)) or str
|
||||
return fmt("%s...", sub(str, 1, limit - 3))
|
||||
end
|
||||
|
||||
local function get_desc(item)
|
||||
@ -175,11 +175,11 @@ local function get_award_list(data, fs, ctn_len, yextra, award_list, awards_unlo
|
||||
local desc_lim, _desc = 39
|
||||
local icon_size = 1.1
|
||||
|
||||
if #title > title_lim then
|
||||
if utf8_len(title) > title_lim then
|
||||
_title = snip(title, title_lim)
|
||||
end
|
||||
|
||||
if #desc > desc_lim then
|
||||
if utf8_len(desc) > desc_lim then
|
||||
_desc = snip(desc, desc_lim)
|
||||
end
|
||||
|
||||
@ -318,7 +318,7 @@ local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
|
||||
|
||||
local waypoint_name, lim = v.name, 18
|
||||
|
||||
if #v.name > lim then
|
||||
if utf8_len(v.name) > lim then
|
||||
waypoint_name = snip(waypoint_name, lim)
|
||||
end
|
||||
|
||||
@ -998,7 +998,7 @@ local function get_grid_fs(fs, data, rcp, is_recipe)
|
||||
if is_group(name) then
|
||||
groups = group_cache and group_cache.groups or extract_groups(name)
|
||||
name = group_cache and (group_cache.stereotype or group_cache.items[1]) or
|
||||
groups_to_items(groups)[1]
|
||||
groups_to_items(groups)[1] or ""
|
||||
end
|
||||
|
||||
local label = groups and "\nG" or ""
|
||||
@ -1034,9 +1034,10 @@ local function get_grid_fs(fs, data, rcp, is_recipe)
|
||||
|
||||
if group_cache and group_cache.sprite and not large_recipe then
|
||||
local sprite = ESC(group_cache.sprite)
|
||||
local size = btn_size - 0.02
|
||||
|
||||
item_image_button(X, Y, btn_size, btn_size, "", btn_name, "")
|
||||
animated_image(X + 0.01, Y + 0.01, 1.89, 1.89, sprite, group_cache.count, 1000)
|
||||
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
|
||||
@ -1188,12 +1189,12 @@ local function get_header(fs, data)
|
||||
local Y1 = data.yoffset + 0.47
|
||||
local Y2 = Y1 + 0.5
|
||||
|
||||
if #desc > desc_lim then
|
||||
if utf8_len(desc) > desc_lim then
|
||||
tooltip(X, Y1 - 0.1, 5.7, 0.24, desc)
|
||||
desc = snip(desc, desc_lim)
|
||||
end
|
||||
|
||||
if #tech_name > name_lim then
|
||||
if utf8_len(tech_name) > name_lim then
|
||||
tooltip(X, Y2 - 0.1, 5.7, 0.24, tech_name)
|
||||
tech_name = snip(tech_name, name_lim)
|
||||
end
|
||||
@ -1325,16 +1326,29 @@ local function get_items_fs(fs, data, player, full_height)
|
||||
|
||||
bg9(data.inv_width + 0.1, 0, 7.9, full_height, PNG.bg_full, 10)
|
||||
|
||||
fs(fmt("box[%f,0.2;4.05,0.6;#bababa25]", data.inv_width + 0.3),
|
||||
"set_focus[filter]",
|
||||
fmt("field[%f,0.2;2.95,0.6;filter;;%s]", data.inv_width + 0.35, ESC(data.filter)),
|
||||
"field_close_on_enter[filter;false]")
|
||||
if data.enable_search then
|
||||
fs("set_focus[filter]",
|
||||
"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)),
|
||||
"field_close_on_enter[filter;false]")
|
||||
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", "")
|
||||
end
|
||||
|
||||
image_button(data.inv_width + 3.35, 0.35, 0.3, 0.3, "", "cancel", "")
|
||||
image_button(data.inv_width + 3.85, 0.32, 0.35, 0.35, "", "search", "")
|
||||
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
|
||||
image_button(data.inv_width + 4.3, 0.4, 0.2, 0.2, "", "cancel", "")
|
||||
fs(fmt("tooltip[cancel;%s]", ES"Clear"))
|
||||
box(data.inv_width + 0.85, 0.75, 3.74, 0.01, "#f9826c")
|
||||
end
|
||||
|
||||
data.pagemax = max(1, ceil(#items / ipp))
|
||||
|
||||
button(data.inv_width + 5.6, 0.14, 1.88, 0.7, "pagenum",
|
||||
@ -1342,12 +1356,15 @@ local function get_items_fs(fs, data, player, full_height)
|
||||
|
||||
if #items == 0 then
|
||||
local lbl = ES"No item to show"
|
||||
local icon, width, offset = PNG.no_result, 4, 2
|
||||
|
||||
if next(i3.recipe_filters) and #i3.init_items > 0 and data.filter == "" then
|
||||
lbl = ES"Collect items to reveal more recipes"
|
||||
lbl = ES"Collect items to reveal more recipes" -- Progressive mode, etc.
|
||||
icon, width, offset = PNG.find_more, 2.5, 2.75
|
||||
end
|
||||
|
||||
button(data.inv_width + 0.1, 3, 8, 1, "no_item", lbl)
|
||||
image(data.inv_width + offset, 3.5, width, width, icon)
|
||||
button(data.inv_width + 0.1, 7, 8, 1, "no_item", lbl)
|
||||
else
|
||||
local first_item = (data.pagenum - 1) * ipp
|
||||
|
||||
@ -1362,7 +1379,7 @@ local function get_items_fs(fs, data, player, full_height)
|
||||
X -= (X * 0.045) + data.inv_width + 0.28
|
||||
|
||||
local Y = round((i % ipp - X) / rows + 1, 0)
|
||||
Y -= (Y * 0.085) + 0.95
|
||||
Y -= (Y * 0.085) + 0.92
|
||||
|
||||
insert(fs, fmt("item_image_button", X, Y, size, size, name, item, ""))
|
||||
|
||||
@ -1469,8 +1486,10 @@ local function get_tabs_fs(fs, player, data, full_height)
|
||||
|
||||
if true_str(def.image) then
|
||||
local desc = translate(data.lang_code, def.description)
|
||||
local desc_len = utf8_len(desc)
|
||||
|
||||
fs("style_type[image;noclip=true]")
|
||||
image(X + (tab_len / 2) - ((#desc * 0.1) / 2) - 0.55, Y + 0.05, 0.35, 0.35, def.image)
|
||||
image(X + (tab_len / 2) - ((desc_len * 0.1) / 2) - 0.55, Y + 0.05, 0.35, 0.35, def.image)
|
||||
end
|
||||
|
||||
c++
|
||||
@ -1540,11 +1559,11 @@ local function make_fs(player, data)
|
||||
get_items_fs(fs, data, player, full_height)
|
||||
end
|
||||
|
||||
local visible_tabs = 1
|
||||
local visible_tabs = #i3.tabs
|
||||
|
||||
for _, def in ipairs(i3.tabs) do
|
||||
if visible_tabs < 2 and def.access and def.access(player, data) then
|
||||
visible_tabs++
|
||||
if def.access and not def.access(player, data) then
|
||||
visible_tabs -= 1
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -42,6 +42,8 @@ local PNG = {
|
||||
home = "i3_home.png",
|
||||
flag = "i3_flag.png",
|
||||
edit = "i3_edit.png",
|
||||
no_result = "i3_no_result.png",
|
||||
find_more = "i3_find_more.png",
|
||||
|
||||
cancel_hover = "i3_cancel.png^\\[brighten",
|
||||
search_hover = "i3_search.png^\\[brighten",
|
||||
@ -77,9 +79,9 @@ local styles = string.format([[
|
||||
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[exit;fgimg=%s;fgimg_hovered=%s;content_offset=0]
|
||||
style[cancel;fgimg=%s;fgimg_hovered=%s;content_offset=0]
|
||||
style[search;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[next_page,next_recipe,next_usage,next_sort,next_skin;fgimg=%s;fgimg_hovered=%s]
|
||||
style[waypoint_add;fgimg=%s;fgimg_hovered=%s;content_offset=0]
|
||||
@ -94,9 +96,9 @@ local styles = string.format([[
|
||||
style[confirm_trash_yes;sound=i3_trash]
|
||||
]],
|
||||
PNG.slot,
|
||||
PNG.search_hover,
|
||||
PNG.exit, PNG.exit_hover,
|
||||
PNG.cancel, PNG.cancel_hover,
|
||||
PNG.search, PNG.search_hover,
|
||||
PNG.prev, PNG.prev_hover,
|
||||
PNG.next, PNG.next_hover,
|
||||
PNG.add, PNG.add_hover,
|
||||
|
BIN
textures/i3_find_more.png
Normal file
BIN
textures/i3_find_more.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
BIN
textures/i3_no_result.png
Normal file
BIN
textures/i3_no_result.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Reference in New Issue
Block a user