Compare commits

...

5 Commits
1.7.5 ... 1.8

Author SHA1 Message Date
aa10460886 Bump version 2022-08-07 16:34:41 +02:00
cef11f5301 Update README 2022-08-07 16:34:19 +02:00
2297b47dc0 Minor Fix 2022-08-07 01:40:49 +02:00
a67ef8b08b Some adjusting 2022-08-07 01:23:36 +02:00
48ab26b4c6 Add a font size global change slider 2022-08-07 00:42:52 +02:00
7 changed files with 50 additions and 73 deletions

View File

@ -7,7 +7,7 @@
This mod features a modern, powerful inventory menu with a good user experience.
**`i3`** provides a rich [**API**](https://github.com/minetest-mods/i3/blob/master/API.md) for mod developers who want to extend it.
This mod requires **Minetest 5.4+**
This mod requires **Minetest 5.6+**
#### List of features:
- Crafting Guide (survival mode only)
@ -43,6 +43,8 @@ To use this mod in the best conditions:
If the inventory's font size is too big on certain setups (namely Windows 10/11 or 144 DPI display), you should lower the
value of the setting `display_density_factor` in your `minetest.conf`. Note that the change is applied after restart.
You can also use the font size slider in the inventory, settings window.
#### Notes
`i3` uses a larger inventory than the usual inventories in Minetest games.

View File

@ -20,7 +20,7 @@ local function lf(path)
end
i3 = {
version = 175,
version = 180,
data = core.deserialize(storage:get_string"data") or {},
settings = {
@ -52,9 +52,9 @@ i3 = {
saves = { -- Metadata to save
bag = true,
home = true,
font_size = true,
waypoints = true,
inv_items = true,
drop_items = true,
known_recipes = true,
},

View File

@ -149,6 +149,7 @@ local function init_data(player, info)
data.itab = 1
data.subcat = 1
data.scrbar_inv = 0
data.font_size = data.font_size or 0
data.lang_code = get_lang_code(info)
data.fs_version = info.formspec_version

View File

@ -558,35 +558,12 @@ local function compress_items(list, start_i)
return new_inv
end
local function drop_items(player, inv, list, start_i, rej, remove)
for i = start_i, #list do
local stack = list[i]
local name = stack:get_name()
for _, it in ipairs(rej) do
if name == it then
if not remove then
spawn_item(player, stack)
end
inv:set_stack("main", i, ItemStack(""))
end
end
end
return inv:get_list"main"
end
local function sort_inventory(player, data)
local inv = player:get_inventory()
local list = inv:get_list"main"
local size = inv:get_size"main"
local start_i = data.ignore_hotbar and (i3.settings.hotbar_len + 1) or 1
if true_table(data.drop_items) then
list = drop_items(player, inv, list, start_i, data.drop_items, true)
end
if data.inv_compress then
list = compress_items(list, start_i)
else

View File

@ -19,11 +19,6 @@ local function inv_fields(player, data, fields)
return
end
if fields.drop_items then
local items = split(fields.drop_items, ",")
data.drop_items = items
end
for field in pairs(fields) do
if sub(field, 1, 4) == "btn_" then
data.subcat = indexof(i3.categories, sub(field, 5))
@ -158,6 +153,9 @@ local function inv_fields(player, data, fields)
elseif fields.bag_rename then
data.bag_rename = true
elseif fields.sb_font_size then
data.font_size = tonumber(fields.sb_font_size:match"-?%d+$")
elseif fields.confirm_rename then
local bag = get_detached_inv("bag", name)
local bagstack = bag:get_stack("main", 1)

View File

@ -37,9 +37,13 @@ local function weird_desc(str)
return not true_str(str) or find(str, "\n") or not find(str, "%u")
end
local function snip(str, limit)
local function snip(str, limit, font_size)
limit -= (font_size > 3 and font_size + 1 or font_size)
if utf8_len(str) > limit then
return fmt("%s...", sub(str, 1, limit - 3))
end
end
local function get_desc(item, lang_code)
if sub(item, 1, 1) == "_" then
@ -171,17 +175,11 @@ local function get_award_list(data, fs, ctn_len, yextra, award_list, awards_unlo
title = translate(data.lang_code, title)
desc = translate(data.lang_code, desc):gsub("%.$", "")
local title_lim, _title = 27
local desc_lim, _desc = 39
local title_lim, desc_lim = 27, 39
local icon_size = 1.1
if utf8_len(title) > title_lim then
_title = snip(title, title_lim)
end
if utf8_len(desc) > desc_lim then
_desc = snip(desc, desc_lim)
end
local _title = snip(title, title_lim, data.font_size) or title
local _desc = snip(desc, desc_lim, data.font_size) or desc
if not award.unlocked and def.secret then
title = ES"Secret award"
@ -191,7 +189,7 @@ local function get_award_list(data, fs, ctn_len, yextra, award_list, awards_unlo
local icon = def.icon or "awards_unknown.png"
if not award.unlocked then
icon = fmt("%s^\\[colorize:#000:200", icon)
icon = fmt("%s^\\[colorize:#000:220", icon)
end
insert(fs, fmt("image", 0, y, icon_size, icon_size, icon))
@ -316,11 +314,8 @@ local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
fs"style_type[box;colors=#bababa30,#bababa30,#bababa05,#bababa05]"
box(0, y, ctn_len, 0.6, "")
local waypoint_name, lim = v.name, 18
if utf8_len(v.name) > lim then
waypoint_name = snip(waypoint_name, lim)
end
local waypoint_name, lim = v.name, 22
waypoint_name = snip(waypoint_name, lim, data.font_size) or waypoint_name
local hex = fmt("%02x", v.color)
@ -370,9 +365,9 @@ local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
if waypoint_preview then
image(0.25, y - 3.5, 5, 4, PNG.bg_content)
fs"style[area_preview;font_size=16]"
button(0.25, y - 3.35, 5, 0.55, "area_preview", v.name)
image_button(4.65, y - 3.25, 0.25, 0.25,
PNG.cancel_hover .. "^\\[brighten", "close_preview", "")
image_button(4.65, y - 3.25, 0.25, 0.25, PNG.cancel_hover .. "^\\[brighten", "close_preview", "")
local pos = str_to_pos(data.waypoints[i].pos)
get_isometric_view(fs, pos, 0.6, y - 2.5)
@ -576,11 +571,11 @@ local function show_popup(fs, data)
local show_sorting = data.show_setting == "sorting"
local show_misc = data.show_setting == "misc"
fs(fmt("style[setting_home;textcolor=%s;font=bold;sound=i3_click]",
fs(fmt("style[setting_home;textcolor=%s;font=bold;font_size=16;sound=i3_click]",
show_home and colors.yellow or "#fff"),
fmt("style[setting_sorting;textcolor=%s;font=bold;sound=i3_click]",
fmt("style[setting_sorting;textcolor=%s;font=bold;font_size=16;sound=i3_click]",
show_sorting and colors.yellow or "#fff"),
fmt("style[setting_misc;textcolor=%s;font=bold;sound=i3_click]",
fmt("style[setting_misc;textcolor=%s;font=bold;font_size=16;sound=i3_click]",
show_misc and colors.yellow or "#fff"))
button(2.2, 9.25, 1.8, 0.55, "setting_home", "Home")
@ -624,14 +619,12 @@ local function show_popup(fs, data)
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))
for _ = 1, 3 do
box(5.4, 10.68, 2.4, 0.45, "#707070")
end
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))
fs("style[drop_items;font_size=15;font=mono;textcolor=#dbeeff]",
fmt("field[5.4,10.68;2.4,0.45;drop_items;Remove items:;%s]",
ESC(concat(data.drop_items or {}, ","))),
"field_close_on_enter[drop_items;false]")
local range = 5
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("tooltip[cb_inv_compress;%s;#707070;#fff]",
ES"Enable this option to compress your inventory"),
@ -640,10 +633,7 @@ local function show_popup(fs, data)
fmt("tooltip[cb_ignore_hotbar;%s;#707070;#fff]",
ES"Enable this option to sort your inventory except the hotbar slots"),
fmt("tooltip[cb_auto_sorting;%s;#707070;#fff]",
ES"Enable this option to sort your inventory automatically"),
fmt("tooltip[drop_items;%s;#707070;#fff]",
"Add a comma-separated list of items to remove on inventory sorting.\n" ..
"Format: " .. ("mod:item,mod:item, ..."):gsub("(%a+:%a+)", clr("#bddeff", "%1"))))
ES"Enable this option to sort your inventory automatically"))
end
end
end
@ -1189,20 +1179,20 @@ local function get_header(fs, data)
local Y1 = data.yoffset + 0.47
local Y2 = Y1 + 0.5
if utf8_len(desc) > desc_lim then
local _desc = snip(desc, desc_lim, data.font_size)
if _desc then
tooltip(X, Y1 - 0.1, 5.7, 0.24, desc)
desc = snip(desc, desc_lim)
end
if utf8_len(tech_name) > name_lim then
local _tech_name = snip(tech_name, name_lim, data.font_size)
if _tech_name then
tooltip(X, Y2 - 0.1, 5.7, 0.24, tech_name)
tech_name = snip(tech_name, name_lim)
end
fs"style_type[label;font=bold;font_size=20]"
label(X, Y1, desc)
label(X, Y1, _desc or desc)
fs"style_type[label;font=mono;font_size=16]"
label(X, Y2, clr(colors.blue, tech_name))
label(X, Y2, clr(colors.blue, _tech_name or tech_name))
fs"style_type[label;font=normal;font_size=16]"
local def = reg_items[data.query_item]
@ -1495,7 +1485,7 @@ 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)
local desc_len = utf8_len(desc) + data.font_size
fs("style_type[image;noclip=true]")
image(X + (tab_len / 2) - ((desc_len * 0.1) / 2) - 0.55, Y + 0.05, 0.35, 0.35, def.image)
@ -1586,7 +1576,15 @@ local function make_fs(player, data)
msg(data.player_name, fmt("#fs elements: %u", #fs))
end
return concat(fs)
fs = concat(fs)
if data.font_size ~= 0 then
fs = fs:gsub("([font][global]*)([%s_])size=(%d+)", function(a, b, c)
return fmt("%s%ssize=%s", a, b, tostring(tonumber(c) + data.font_size))
end)
end
return fs
end
return make_fs, get_inventory_fs

View File

@ -77,7 +77,8 @@ 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;bgimg_middle=9;padding=-9]
style_type[item_image_button;bgimg_middle=9;padding=-9]
style_type[item_image_button:hovered;bgimg=%s]
style[;sound=]
style[nofav;sound=i3_cannot]