mirror of
https://github.com/minetest-mods/i3.git
synced 2025-07-03 00:50:22 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
b48c7862dc | |||
d8e17687e1 | |||
2fadcdefdd | |||
c7f6e1db62 | |||
16a1865e11 | |||
748cc9a7a1 |
25
init.lua
25
init.lua
@ -20,6 +20,7 @@ end
|
||||
|
||||
i3 = {
|
||||
settings = {
|
||||
debug_mode = false,
|
||||
max_favs = 6,
|
||||
min_fs_version = 4,
|
||||
item_btn_size = 1.1,
|
||||
@ -66,13 +67,6 @@ i3 = {
|
||||
model_alias = lf"/src/model_aliases.lua",
|
||||
progressive = lf"/src/progressive.lua",
|
||||
styles = lf"/src/styles.lua",
|
||||
|
||||
tests = {
|
||||
tabs = lf"/tests/test_tabs.lua",
|
||||
operators = lf"/tests/test_operators.lua",
|
||||
compression = lf"/tests/test_compression.lua",
|
||||
custom_recipes = lf"/tests/test_custom_recipes.lua",
|
||||
}
|
||||
},
|
||||
|
||||
-- Caches
|
||||
@ -121,10 +115,9 @@ local function get_formspec_version(info)
|
||||
end
|
||||
|
||||
local function outdated(name)
|
||||
local fs = ("size[6.3,1.3]image[0,0;1,1;i3_book.png]label[1,0;%s]button_exit[2.6,0.8;1,1;;OK]"):format(
|
||||
"Your Minetest client is outdated.\nGet the latest version on minetest.net to play the game.")
|
||||
|
||||
core.show_formspec(name, "i3_outdated", fs)
|
||||
core.show_formspec(name, "i3_outdated",
|
||||
("size[6.5,1.3]image[0,0;1,1;i3_book.png]label[1,0;%s]button_exit[2.6,0.8;1,1;;OK]"):format(
|
||||
"Your Minetest client is outdated.\nGet the latest version on minetest.net to play the game."))
|
||||
end
|
||||
|
||||
if rawget(_G, "armor") then
|
||||
@ -254,7 +247,9 @@ if i3.settings.progressive_mode then
|
||||
i3.files.progressive()
|
||||
end
|
||||
|
||||
--i3.files.tests.tabs()
|
||||
--i3.files.tests.operators()
|
||||
--i3.files.tests.compression()
|
||||
--i3.files.tests.custom_recipes(http)
|
||||
if i3.settings.debug_mode then
|
||||
lf("/tests/test_tabs.lua")()
|
||||
lf("/tests/test_operators.lua")()
|
||||
lf("/tests/test_compression.lua")()
|
||||
lf("/tests/test_custom_recipes.lua")()
|
||||
end
|
||||
|
35
src/api.lua
35
src/api.lua
@ -1,5 +1,5 @@
|
||||
local make_fs = i3.files.gui()
|
||||
local http = ...
|
||||
local make_fs = i3.files.gui()
|
||||
|
||||
IMPORT("gmatch", "split")
|
||||
IMPORT("S", "err", "fmt", "reg_items")
|
||||
@ -22,7 +22,7 @@ end
|
||||
function i3.register_craft(def)
|
||||
local width, c = 0, 0
|
||||
|
||||
if true_str(def.url) then
|
||||
if http and true_str(def.url) then
|
||||
http.fetch({url = def.url}, function(result)
|
||||
if result.succeeded then
|
||||
local t = core.parse_json(result.data)
|
||||
@ -51,7 +51,7 @@ function i3.register_craft(def)
|
||||
def.result = nil
|
||||
end
|
||||
|
||||
if not true_str(def.output) then
|
||||
if not true_str(def.output) and not def.url then
|
||||
return err "i3.register_craft: output missing"
|
||||
end
|
||||
|
||||
@ -69,9 +69,7 @@ function i3.register_craft(def)
|
||||
end
|
||||
|
||||
local cp = copy(def.grid)
|
||||
sort(cp, function(a, b)
|
||||
return #a > #b
|
||||
end)
|
||||
sort(cp, function(a, b) return #a > #b end)
|
||||
|
||||
width = #cp[1]
|
||||
|
||||
@ -86,26 +84,29 @@ function i3.register_craft(def)
|
||||
def.items[c] = def.key[symbol]
|
||||
end
|
||||
else
|
||||
local items, len = def.items, #def.items
|
||||
local items = copy(def.items)
|
||||
local lines = {}
|
||||
def.items = {}
|
||||
|
||||
for i = 1, len do
|
||||
local rlen = #split(items[i], ",")
|
||||
for i = 1, #items do
|
||||
lines[i] = split(items[i], ",", true)
|
||||
|
||||
if rlen > width then
|
||||
width = rlen
|
||||
if #lines[i] > width then
|
||||
width = #lines[i]
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, len do
|
||||
while #split(items[i], ",") < width do
|
||||
items[i] = fmt("%s,", items[i])
|
||||
for i = 1, #items do
|
||||
while #lines[i] < width do
|
||||
insert(lines[i], items[i])
|
||||
end
|
||||
end
|
||||
|
||||
for name in gmatch(concat(items, ","), "[%s%w_:]+") do
|
||||
c++
|
||||
def.items[c] = clean_name(name)
|
||||
for _, line in ipairs(lines) do
|
||||
for _, v in ipairs(line) do
|
||||
c++
|
||||
def.items[c] = clean_name(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -229,6 +229,9 @@ i3.new_tab("inventory", {
|
||||
})
|
||||
|
||||
data.scrbar_inv += 1000
|
||||
|
||||
elseif fields.hide_debug_grid then
|
||||
data.hide_debug_grid = not data.hide_debug_grid
|
||||
end
|
||||
|
||||
return set_fs(player)
|
||||
@ -376,13 +379,12 @@ local function rcp_fields(player, data, fields)
|
||||
data.scrbar_usg = 1
|
||||
|
||||
elseif fields.fav then
|
||||
local fav, i = is_fav(data.favs, data.query_item)
|
||||
local total = #data.favs
|
||||
local fav = is_fav(data)
|
||||
|
||||
if total < i3.settings.max_favs and not fav then
|
||||
data.favs[total + 1] = data.query_item
|
||||
if #data.favs < i3.settings.max_favs and not fav then
|
||||
insert(data.favs, data.query_item)
|
||||
elseif fav then
|
||||
remove(data.favs, i)
|
||||
remove(data.favs, fav)
|
||||
end
|
||||
|
||||
elseif fields.export_rcp or fields.export_usg then
|
||||
@ -423,7 +425,8 @@ core.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local name = player:get_player_name()
|
||||
|
||||
if formname == "i3_outdated" then
|
||||
return false, core.kick_player(name, S"Come back when your client is up-to-date.")
|
||||
return false, core.kick_player(name,
|
||||
S"Come back when your Minetest client is up-to-date (www.minetest.net).")
|
||||
elseif formname ~= "" then
|
||||
return false
|
||||
end
|
||||
|
@ -289,17 +289,12 @@ local function compressible(item, data)
|
||||
return compression_active(data) and i3.compress_groups[item]
|
||||
end
|
||||
|
||||
local function is_fav(favs, query_item)
|
||||
local fav, i
|
||||
for j = 1, #favs do
|
||||
if favs[j] == query_item then
|
||||
fav = true
|
||||
i = j
|
||||
break
|
||||
local function is_fav(data)
|
||||
for i = 1, #data.favs do
|
||||
if data.favs[i] == data.query_item then
|
||||
return i
|
||||
end
|
||||
end
|
||||
|
||||
return fav, i
|
||||
end
|
||||
|
||||
local function sort_by_category(data)
|
||||
|
117
src/gui.lua
117
src/gui.lua
@ -7,9 +7,9 @@ local PNG, styles, fs_elements, colors = i3.files.styles()
|
||||
local sprintf = string.format
|
||||
local VoxelArea, VoxelManip = VoxelArea, VoxelManip
|
||||
|
||||
IMPORT("clr", "ESC", "check_privs")
|
||||
IMPORT("find", "match", "sub", "upper")
|
||||
IMPORT("vec_new", "vec_sub", "vec_round")
|
||||
IMPORT("clr", "ESC", "msg", "check_privs")
|
||||
IMPORT("min", "max", "floor", "ceil", "round")
|
||||
IMPORT("reg_items", "reg_tools", "reg_entities")
|
||||
IMPORT("get_bag_description", "get_detached_inv")
|
||||
@ -234,14 +234,14 @@ local function get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
|
||||
local width = 8
|
||||
local base_height = 4
|
||||
local base_depth = depth == -1
|
||||
local max_depth = -10
|
||||
local max_depth = -7
|
||||
local height = base_depth and (base_height - 1) or depth
|
||||
|
||||
local pos1 = vec_new(pos.x - width, pos.y + depth, pos.z - width)
|
||||
local pos2 = vec_new(pos.x + width, pos.y + height, pos.z + width)
|
||||
|
||||
local vm = VoxelManip(pos1, pos2)
|
||||
local emin, emax = vm:read_from_map(pos1, pos2)
|
||||
local emin, emax = vm:get_emerged_area()
|
||||
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
|
||||
local data = vm:get_data()
|
||||
|
||||
@ -276,25 +276,25 @@ local function get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
|
||||
if cubes < maxc and depth > max_depth then
|
||||
-- if there's not enough map to preview, go deeper
|
||||
depth -= 1
|
||||
get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
|
||||
else
|
||||
local shift = -0.3 - high
|
||||
return get_isometric_view(fs, pos, X, Y, t, cubes, depth, high)
|
||||
end
|
||||
|
||||
for i = max_depth, 0 do
|
||||
local dth = t[i]
|
||||
if dth then
|
||||
dth[0] = #dth
|
||||
for j = 1, dth[0] do
|
||||
local params = dth[j]
|
||||
params[2] += shift
|
||||
insert(fs, fmt("image[%f,%f;%.1f,%.1f;%s]", unpack(params)))
|
||||
end
|
||||
local shift = -0.3 - high
|
||||
|
||||
for i = max_depth, 0 do
|
||||
local dth = t[i]
|
||||
if dth then
|
||||
dth[0] = #dth
|
||||
for j = 1, dth[0] do
|
||||
local params = dth[j]
|
||||
params[2] += shift
|
||||
insert(fs, fmt("image[%f,%f;%.1f,%.1f;%s]", unpack(params)))
|
||||
end
|
||||
end
|
||||
|
||||
shift += (base_depth and 0.45 or 0.95)
|
||||
fs("image", 2.7, Y + shift, 0.3, 0.3, PNG.flag)
|
||||
end
|
||||
|
||||
shift += (base_depth and 0.45 or 0.95)
|
||||
fs("image", 2.7, Y + shift, 0.3, 0.3, PNG.flag)
|
||||
end
|
||||
|
||||
local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
|
||||
@ -1093,8 +1093,7 @@ local function get_model_fs(fs, data, def, model_alias)
|
||||
hex = "0" .. hex
|
||||
end
|
||||
|
||||
_name = fmt("%s^[multiply:%s", v.name,
|
||||
fmt("#%s%s", sub(hex, 3), sub(hex, 1, 2)))
|
||||
_name = fmt("%s^[multiply:%s", v.name, fmt("#%s%s", sub(hex, 3), sub(hex, 1, 2)))
|
||||
else
|
||||
_name = fmt("%s^[multiply:%s", v.name, v.color)
|
||||
end
|
||||
@ -1115,7 +1114,7 @@ local function get_model_fs(fs, data, def, model_alias)
|
||||
end
|
||||
|
||||
local function get_header(fs, data)
|
||||
local fav = is_fav(data.favs, data.query_item)
|
||||
local fav = is_fav(data)
|
||||
local nfavs = #data.favs
|
||||
local max_favs = i3.settings.max_favs
|
||||
local star_x, star_y, size = data.inv_width + 0.3, data.yoffset + 0.2, 0.4
|
||||
@ -1201,7 +1200,7 @@ local function get_export_fs(fs, data, is_recipe, is_usage, max_stacks_rcp, max_
|
||||
fmt("craft_%s", name), ES("Craft (×@1)", stack_fs))
|
||||
end
|
||||
|
||||
local function get_rcp_extra(fs, player, data, panel, is_recipe, is_usage)
|
||||
local function get_rcp_extra(fs, data, player, panel, is_recipe, is_usage)
|
||||
fs"container[0,0.075]"
|
||||
local rn = panel.rcp and #panel.rcp
|
||||
|
||||
@ -1270,7 +1269,7 @@ local function hide_items(player, data)
|
||||
end
|
||||
end
|
||||
|
||||
local function get_items_fs(fs, player, data, full_height)
|
||||
local function get_items_fs(fs, data, player, full_height)
|
||||
hide_items(player, data)
|
||||
|
||||
local items = data.alt_items or data.items or {}
|
||||
@ -1278,6 +1277,8 @@ local function get_items_fs(fs, player, data, full_height)
|
||||
local ipp = rows * lines
|
||||
local size = 0.85
|
||||
|
||||
fs("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)),
|
||||
@ -1312,10 +1313,10 @@ local function get_items_fs(fs, player, data, full_height)
|
||||
local name = _compressed and item:sub(2) or item
|
||||
|
||||
local X = i % rows
|
||||
X -= (X * 0.045) + data.inv_width + 0.28
|
||||
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.95
|
||||
|
||||
insert(fs, fmt("item_image_button", X, Y, size, size, name, item, ""))
|
||||
|
||||
@ -1363,43 +1364,23 @@ local function get_favs(fs, data)
|
||||
end
|
||||
end
|
||||
|
||||
local function get_panels(fs, player, data, full_height)
|
||||
local _title = {name = "title", height = 1.4}
|
||||
local _favs = {name = "favs", height = 2.23}
|
||||
local _items = {name = "items", height = full_height}
|
||||
local _recipes = {name = "recipes", rcp = data.recipes, height = 4.045}
|
||||
local _usages = {name = "usages", rcp = data.usages, height = 4.045}
|
||||
local panels
|
||||
local function get_panels(fs, data, player)
|
||||
local title = {name = "title", height = 1.4, func = get_header}
|
||||
local favs = {name = "favs", height = 2.23, func = get_favs}
|
||||
local recipes = {name = "recipes", rcp = data.recipes, height = 4.045, func = get_rcp_extra}
|
||||
local usages = {name = "usages", rcp = data.usages, height = 4.045, func = get_rcp_extra}
|
||||
local panels = {title, recipes, usages, favs}
|
||||
data.yoffset = 0
|
||||
|
||||
if data.query_item then
|
||||
panels = {_title, _recipes, _usages, _favs}
|
||||
else
|
||||
panels = {_items}
|
||||
end
|
||||
|
||||
for idx = 1, #panels do
|
||||
local panel = panels[idx]
|
||||
data.yoffset = 0
|
||||
|
||||
if idx > 1 then
|
||||
for _idx = idx - 1, 1, -1 do
|
||||
data.yoffset = data.yoffset + panels[_idx].height + 0.1
|
||||
end
|
||||
for i, panel in ipairs(panels) do
|
||||
if i > 1 then
|
||||
data.yoffset += panels[i - 1].height + 0.1
|
||||
end
|
||||
|
||||
fs("bg9", data.inv_width + 0.1, data.yoffset, 7.9, panel.height, PNG.bg_full, 10)
|
||||
|
||||
local is_recipe, is_usage = panel.name == "recipes", panel.name == "usages"
|
||||
|
||||
if is_recipe or is_usage then
|
||||
get_rcp_extra(fs, player, data, panel, is_recipe, is_usage)
|
||||
elseif panel.name == "items" then
|
||||
get_items_fs(fs, player, data, full_height)
|
||||
elseif panel.name == "title" then
|
||||
get_header(fs, data)
|
||||
elseif panel.name == "favs" then
|
||||
get_favs(fs, data)
|
||||
end
|
||||
panel.func(fs, data, player, panel, is_recipe, is_usage)
|
||||
end
|
||||
end
|
||||
|
||||
@ -1452,6 +1433,10 @@ local function get_tabs_fs(fs, player, data, full_height)
|
||||
end
|
||||
|
||||
local function get_debug_grid(data, fs, full_height)
|
||||
fs"style[hide_debug_grid;noclip=true]"
|
||||
fs("button", -2, full_height - 1, 2, 1, "hide_debug_grid", "Toggle grid")
|
||||
if data.hide_debug_grid then return end
|
||||
|
||||
fs("style_type[label;font_size=8;noclip=true]")
|
||||
local spacing, i = 0.2, 1
|
||||
|
||||
@ -1475,7 +1460,7 @@ local function get_debug_grid(data, fs, full_height)
|
||||
end
|
||||
|
||||
local function make_fs(player, data)
|
||||
--local start = os.clock()
|
||||
local start = i3.settings.debug_mode and os.clock() or nil
|
||||
|
||||
local fs = setmetatable({}, {
|
||||
__call = function(t, ...)
|
||||
@ -1493,26 +1478,32 @@ local function make_fs(player, data)
|
||||
data.inv_width = 10.23
|
||||
local full_height = 12
|
||||
|
||||
local tab = i3.tabs[data.tab]
|
||||
|
||||
fs(fmt("formspec_version[%u]size[%f,%f]no_prepend[]bgcolor[#0000]",
|
||||
i3.settings.min_fs_version, data.inv_width + 8, full_height), styles)
|
||||
|
||||
fs("bg9", 0, 0, data.inv_width, full_height, PNG.bg_full, 10)
|
||||
|
||||
local tab = i3.tabs[data.tab]
|
||||
|
||||
if tab then
|
||||
tab.formspec(player, data, fs)
|
||||
end
|
||||
|
||||
get_panels(fs, player, data, full_height)
|
||||
if data.query_item then
|
||||
get_panels(fs, data, player)
|
||||
else
|
||||
get_items_fs(fs, data, player, full_height)
|
||||
end
|
||||
|
||||
if #i3.tabs > 1 then
|
||||
get_tabs_fs(fs, player, data, full_height)
|
||||
end
|
||||
|
||||
--get_debug_grid(data, fs, full_height)
|
||||
--print("make_fs()", fmt("%.2f ms", (os.clock() - start) * 1000))
|
||||
--print("#fs elements", #fs)
|
||||
if i3.settings.debug_mode then
|
||||
get_debug_grid(data, fs, full_height)
|
||||
msg(data.player_name, fmt("make_fs(): %.2f ms", (os.clock() - start) * 1000))
|
||||
msg(data.player_name, fmt("#fs elements: %u", #fs))
|
||||
end
|
||||
|
||||
return concat(fs)
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ local function init_hud(player)
|
||||
},
|
||||
}
|
||||
|
||||
if not i3.legacy_inventory then
|
||||
if not i3.settings.legacy_inventory then
|
||||
core.after(0, function()
|
||||
player:hud_set_hotbar_itemcount(i3.settings.hotbar_len)
|
||||
player:hud_set_hotbar_image"i3_hotbar.png"
|
||||
|
@ -38,6 +38,24 @@ i3.register_craft({
|
||||
items = {"default:copper_ingot 7, default:tin_ingot, default:steel_ingot 2"},
|
||||
})
|
||||
|
||||
i3.register_craft {
|
||||
result = "default:tree",
|
||||
items = {
|
||||
"default:wood",
|
||||
"",
|
||||
"default:wood"
|
||||
},
|
||||
}
|
||||
|
||||
i3.register_craft {
|
||||
result = "default:cobble 16",
|
||||
items = {
|
||||
"default:stone, default:stone",
|
||||
"default:stone, , default:stone",
|
||||
", default:stone, default:stone",
|
||||
}
|
||||
}
|
||||
|
||||
i3.register_craft({
|
||||
grid = {
|
||||
"X",
|
||||
@ -311,22 +329,3 @@ i3.register_craft({
|
||||
},
|
||||
result = "default:mese 3",
|
||||
})
|
||||
|
||||
i3.register_craft({
|
||||
grid = {
|
||||
"X #",
|
||||
" ## ",
|
||||
"X#X#",
|
||||
"#X#X#",
|
||||
"X X##X#X",
|
||||
" ## ",
|
||||
"#X#X#",
|
||||
"#X#X#",
|
||||
"X #",
|
||||
},
|
||||
key = {
|
||||
['#'] = "default:wood",
|
||||
['X'] = "default:glass",
|
||||
},
|
||||
result = "default:mese 3",
|
||||
})
|
||||
|
Reference in New Issue
Block a user