mirror of
https://github.com/minetest-mods/i3.git
synced 2025-07-04 17:40:23 +02:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
aa10460886 | |||
cef11f5301 | |||
2297b47dc0 | |||
a67ef8b08b | |||
48ab26b4c6 |
@ -7,7 +7,7 @@
|
|||||||
This mod features a modern, powerful inventory menu with a good user experience.
|
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.
|
**`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:
|
#### List of features:
|
||||||
- Crafting Guide (survival mode only)
|
- 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
|
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.
|
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
|
#### Notes
|
||||||
|
|
||||||
`i3` uses a larger inventory than the usual inventories in Minetest games.
|
`i3` uses a larger inventory than the usual inventories in Minetest games.
|
||||||
|
4
init.lua
4
init.lua
@ -20,7 +20,7 @@ local function lf(path)
|
|||||||
end
|
end
|
||||||
|
|
||||||
i3 = {
|
i3 = {
|
||||||
version = 175,
|
version = 180,
|
||||||
data = core.deserialize(storage:get_string"data") or {},
|
data = core.deserialize(storage:get_string"data") or {},
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
@ -52,9 +52,9 @@ i3 = {
|
|||||||
saves = { -- Metadata to save
|
saves = { -- Metadata to save
|
||||||
bag = true,
|
bag = true,
|
||||||
home = true,
|
home = true,
|
||||||
|
font_size = true,
|
||||||
waypoints = true,
|
waypoints = true,
|
||||||
inv_items = true,
|
inv_items = true,
|
||||||
drop_items = true,
|
|
||||||
known_recipes = true,
|
known_recipes = true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -149,6 +149,7 @@ local function init_data(player, info)
|
|||||||
data.itab = 1
|
data.itab = 1
|
||||||
data.subcat = 1
|
data.subcat = 1
|
||||||
data.scrbar_inv = 0
|
data.scrbar_inv = 0
|
||||||
|
data.font_size = data.font_size or 0
|
||||||
data.lang_code = get_lang_code(info)
|
data.lang_code = get_lang_code(info)
|
||||||
data.fs_version = info.formspec_version
|
data.fs_version = info.formspec_version
|
||||||
|
|
||||||
|
@ -558,35 +558,12 @@ local function compress_items(list, start_i)
|
|||||||
return new_inv
|
return new_inv
|
||||||
end
|
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 function sort_inventory(player, data)
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local list = inv:get_list"main"
|
local list = inv:get_list"main"
|
||||||
local size = inv:get_size"main"
|
local size = inv:get_size"main"
|
||||||
local start_i = data.ignore_hotbar and (i3.settings.hotbar_len + 1) or 1
|
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
|
if data.inv_compress then
|
||||||
list = compress_items(list, start_i)
|
list = compress_items(list, start_i)
|
||||||
else
|
else
|
||||||
|
@ -19,11 +19,6 @@ local function inv_fields(player, data, fields)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields.drop_items then
|
|
||||||
local items = split(fields.drop_items, ",")
|
|
||||||
data.drop_items = items
|
|
||||||
end
|
|
||||||
|
|
||||||
for field in pairs(fields) do
|
for field in pairs(fields) do
|
||||||
if sub(field, 1, 4) == "btn_" then
|
if sub(field, 1, 4) == "btn_" then
|
||||||
data.subcat = indexof(i3.categories, sub(field, 5))
|
data.subcat = indexof(i3.categories, sub(field, 5))
|
||||||
@ -158,6 +153,9 @@ local function inv_fields(player, data, fields)
|
|||||||
elseif fields.bag_rename then
|
elseif fields.bag_rename then
|
||||||
data.bag_rename = true
|
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
|
elseif fields.confirm_rename then
|
||||||
local bag = get_detached_inv("bag", name)
|
local bag = get_detached_inv("bag", name)
|
||||||
local bagstack = bag:get_stack("main", 1)
|
local bagstack = bag:get_stack("main", 1)
|
||||||
|
78
src/gui.lua
78
src/gui.lua
@ -37,8 +37,12 @@ local function weird_desc(str)
|
|||||||
return not true_str(str) or find(str, "\n") or not find(str, "%u")
|
return not true_str(str) or find(str, "\n") or not find(str, "%u")
|
||||||
end
|
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))
|
return fmt("%s...", sub(str, 1, limit - 3))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_desc(item, lang_code)
|
local function get_desc(item, lang_code)
|
||||||
@ -171,17 +175,11 @@ local function get_award_list(data, fs, ctn_len, yextra, award_list, awards_unlo
|
|||||||
title = translate(data.lang_code, title)
|
title = translate(data.lang_code, title)
|
||||||
desc = translate(data.lang_code, desc):gsub("%.$", "")
|
desc = translate(data.lang_code, desc):gsub("%.$", "")
|
||||||
|
|
||||||
local title_lim, _title = 27
|
local title_lim, desc_lim = 27, 39
|
||||||
local desc_lim, _desc = 39
|
|
||||||
local icon_size = 1.1
|
local icon_size = 1.1
|
||||||
|
|
||||||
if utf8_len(title) > title_lim then
|
local _title = snip(title, title_lim, data.font_size) or title
|
||||||
_title = snip(title, title_lim)
|
local _desc = snip(desc, desc_lim, data.font_size) or desc
|
||||||
end
|
|
||||||
|
|
||||||
if utf8_len(desc) > desc_lim then
|
|
||||||
_desc = snip(desc, desc_lim)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not award.unlocked and def.secret then
|
if not award.unlocked and def.secret then
|
||||||
title = ES"Secret award"
|
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"
|
local icon = def.icon or "awards_unknown.png"
|
||||||
|
|
||||||
if not award.unlocked then
|
if not award.unlocked then
|
||||||
icon = fmt("%s^\\[colorize:#000:200", icon)
|
icon = fmt("%s^\\[colorize:#000:220", icon)
|
||||||
end
|
end
|
||||||
|
|
||||||
insert(fs, fmt("image", 0, y, icon_size, icon_size, icon))
|
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]"
|
fs"style_type[box;colors=#bababa30,#bababa30,#bababa05,#bababa05]"
|
||||||
box(0, y, ctn_len, 0.6, "")
|
box(0, y, ctn_len, 0.6, "")
|
||||||
|
|
||||||
local waypoint_name, lim = v.name, 18
|
local waypoint_name, lim = v.name, 22
|
||||||
|
waypoint_name = snip(waypoint_name, lim, data.font_size) or waypoint_name
|
||||||
if utf8_len(v.name) > lim then
|
|
||||||
waypoint_name = snip(waypoint_name, lim)
|
|
||||||
end
|
|
||||||
|
|
||||||
local hex = fmt("%02x", v.color)
|
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
|
if waypoint_preview then
|
||||||
image(0.25, y - 3.5, 5, 4, PNG.bg_content)
|
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)
|
button(0.25, y - 3.35, 5, 0.55, "area_preview", v.name)
|
||||||
image_button(4.65, y - 3.25, 0.25, 0.25,
|
image_button(4.65, y - 3.25, 0.25, 0.25, PNG.cancel_hover .. "^\\[brighten", "close_preview", "")
|
||||||
PNG.cancel_hover .. "^\\[brighten", "close_preview", "")
|
|
||||||
|
|
||||||
local pos = str_to_pos(data.waypoints[i].pos)
|
local pos = str_to_pos(data.waypoints[i].pos)
|
||||||
get_isometric_view(fs, pos, 0.6, y - 2.5)
|
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_sorting = data.show_setting == "sorting"
|
||||||
local show_misc = data.show_setting == "misc"
|
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"),
|
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"),
|
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"))
|
show_misc and colors.yellow or "#fff"))
|
||||||
|
|
||||||
button(2.2, 9.25, 1.8, 0.55, "setting_home", "Home")
|
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(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))
|
checkbox(5.4, 10.05, "cb_auto_sorting", "Automation", tostring(data.auto_sorting))
|
||||||
|
|
||||||
for _ = 1, 3 do
|
local sign = (data.font_size > 0 and "+") or (data.font_size > 0 and "-") or ""
|
||||||
box(5.4, 10.68, 2.4, 0.45, "#707070")
|
label(5.4, 10.55, ES"Font size" .. fmt(": %s", sign .. data.font_size))
|
||||||
end
|
|
||||||
|
|
||||||
fs("style[drop_items;font_size=15;font=mono;textcolor=#dbeeff]",
|
local range = 5
|
||||||
fmt("field[5.4,10.68;2.4,0.45;drop_items;Remove items:;%s]",
|
fs(fmt("scrollbaroptions[min=-%u;max=%u;smallstep=1;largestep=1;thumbsize=2]", range, range))
|
||||||
ESC(concat(data.drop_items or {}, ","))),
|
fs(fmt("scrollbar[5.4,10.8;2.5,0.25;horizontal;sb_font_size;%d]", data.font_size))
|
||||||
"field_close_on_enter[drop_items;false]")
|
|
||||||
|
|
||||||
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"),
|
||||||
@ -640,10 +633,7 @@ local function show_popup(fs, data)
|
|||||||
fmt("tooltip[cb_ignore_hotbar;%s;#707070;#fff]",
|
fmt("tooltip[cb_ignore_hotbar;%s;#707070;#fff]",
|
||||||
ES"Enable this option to sort your inventory except the hotbar slots"),
|
ES"Enable this option to sort your inventory except the hotbar slots"),
|
||||||
fmt("tooltip[cb_auto_sorting;%s;#707070;#fff]",
|
fmt("tooltip[cb_auto_sorting;%s;#707070;#fff]",
|
||||||
ES"Enable this option to sort your inventory automatically"),
|
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"))))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1189,20 +1179,20 @@ local function get_header(fs, data)
|
|||||||
local Y1 = data.yoffset + 0.47
|
local Y1 = data.yoffset + 0.47
|
||||||
local Y2 = Y1 + 0.5
|
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)
|
tooltip(X, Y1 - 0.1, 5.7, 0.24, desc)
|
||||||
desc = snip(desc, desc_lim)
|
|
||||||
end
|
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)
|
tooltip(X, Y2 - 0.1, 5.7, 0.24, tech_name)
|
||||||
tech_name = snip(tech_name, name_lim)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fs"style_type[label;font=bold;font_size=20]"
|
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]"
|
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]"
|
fs"style_type[label;font=normal;font_size=16]"
|
||||||
|
|
||||||
local def = reg_items[data.query_item]
|
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
|
if true_str(def.image) then
|
||||||
local desc = translate(data.lang_code, def.description)
|
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]")
|
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)
|
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))
|
msg(data.player_name, fmt("#fs elements: %u", #fs))
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
return make_fs, get_inventory_fs
|
return make_fs, get_inventory_fs
|
||||||
|
@ -77,7 +77,8 @@ 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;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[;sound=]
|
||||||
style[nofav;sound=i3_cannot]
|
style[nofav;sound=i3_cannot]
|
||||||
|
Reference in New Issue
Block a user