Compare commits

...

11 Commits
1.3 ... 1.3.2

5 changed files with 108 additions and 64 deletions

9
.editorconfig Normal file
View File

@ -0,0 +1,9 @@
[*]
end_of_line = lf
[*.{lua,txt,md,json}]
charset = utf8
indent_size = 8
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

4
API.md
View File

@ -38,7 +38,7 @@ i3.new_tab {
Updates the current formspec. `extra_formspec` adds an additional formspec string.
#### `i3.delete_tab(tabname)`
#### `i3.remove_tab(tabname)`
Deletes a tab by name.
@ -178,7 +178,7 @@ end)
Removes all recipe filters and adds a new one.
#### `i3.delete_recipe_filter(name)`
#### `i3.remove_recipe_filter(name)`
Removes the recipe filter with the given `name`.

View File

@ -49,4 +49,4 @@ Love this mod? Donations are appreciated: https://www.paypal.me/jpg84240
Demo video (outdated): https://www.youtube.com/watch?v=25nCAaqeacU
![Preview](https://user-images.githubusercontent.com/7883281/123556172-f670a180-d789-11eb-9168-eb38fc764736.png)
![Preview](https://user-images.githubusercontent.com/7883281/123561657-10ba7780-d7aa-11eb-8bbe-dcec348bb28c.png)

View File

@ -84,6 +84,9 @@ local styles = fmt([[
style[craft_rcp,craft_usg;noclip=true;font_size=16;sound=i3_craft;
bgimg=i3_btn9.png;bgimg_hovered=i3_btn9_hovered.png;
bgimg_pressed=i3_btn9_pressed.png;bgimg_middle=4,6]
style[confirm_trash_yes,confirm_trash_no;noclip=true;font_size=16;
bgimg=i3_btn9.png;bgimg_hovered=i3_btn9_hovered.png;
bgimg_pressed=i3_btn9_pressed.png;bgimg_middle=4,6]
]],
PNG.slot,
PNG.exit, PNG.exit_hover,

154
init.lua
View File

@ -21,12 +21,10 @@ local compress_groups, compressed = loadfile(modpath .. "/etc/compress.lua")()
local group_stereotypes, group_names = loadfile(modpath .. "/etc/groups.lua")()
local progressive_mode = core.settings:get_bool "i3_progressive_mode"
local item_compression = core.settings:get_bool "i3_item_compression"
local item_compression = core.settings:get_bool("i3_item_compression", true)
local damage_enabled = core.settings:get_bool "enable_damage"
local __3darmor, __skinsdb, __awards
local __sfinv, old_sfinv_fn
local __unified_inventory, old_unified_inventory_fn
local http = core.request_http_api()
local singleplayer = core.is_singleplayer()
@ -107,16 +105,20 @@ local function get_formspec_version(info)
end
local function outdated(name)
local fs = sprintf("size[5.8,1.3]image[0,0;1,1;%s]label[1,0;%s]button_exit[2.4,0.8;1,1;;OK]",
local fs = sprintf("size[6.3,1.3]image[0,0;1,1;%s]label[1,0;%s]button_exit[2.6,0.8;1,1;;OK]",
PNG.book,
"Your Minetest client is outdated.\nGet the latest version on minetest.net to use i3")
"Your Minetest client is outdated.\nGet the latest version on minetest.net to play the game.")
core.show_formspec(name, "i3", fs)
core.show_formspec(name, "i3_outdated", fs)
end
local old_is_creative_enabled = core.is_creative_enabled
function core.is_creative_enabled(name)
if name == "" then
return old_is_creative_enabled(name)
end
return check_privs(name, {creative = true}) or old_is_creative_enabled(name)
end
@ -422,7 +424,7 @@ function i3.set_recipe_filter(name, f)
recipe_filters = {[name] = f}
end
function i3.delete_recipe_filter(name)
function i3.remove_recipe_filter(name)
recipe_filters[name] = nil
end
@ -583,6 +585,8 @@ local function search(data)
local filters = {}
if search_filter then
search_filter = search_filter:trim()
for filter_name, values in gmatch(filter, sub(opt, 6)) do
if search_filters[filter_name] then
values = split(values, ",")
@ -616,7 +620,18 @@ local function search(data)
end
end
else
to_add = find(search_in, filter, 1, true)
local ok = true
for keyword in gmatch(filter, "%S+") do
if not find(search_in, keyword, 1, true) then
ok = nil
break
end
end
if ok then
to_add = true
end
end
if to_add then
@ -2038,16 +2053,21 @@ local function get_ctn_content(fs, data, player, yoffset, ctn_len, award_list, a
elseif data.subcat == 3 then
if __skinsdb then
local _skins = skins.get_skinlist_for_player(name)
local sks = {}
local skin_name = skins.get_player_skin(player).name
local sks, id = {}, 1
for i, skin in ipairs(_skins) do
if skin.name == skin_name then
id = i
end
for _, skin in ipairs(_skins) do
sks[#sks + 1] = skin.name
end
sks = concat(sks, ","):gsub(";", "")
fs("label", 0, yextra + 0.85, fmt("%s:", ES"Select a skin"))
fs(fmt("dropdown[0,%f;4,0.6;skins;%s;%u;true]", yextra + 1.1, sks, data.skin_id or 1))
fs(fmt("dropdown[0,%f;4,0.6;skins;%s;%u;true]", yextra + 1.1, sks, id))
else
not_installed("skinsdb")
end
@ -2115,18 +2135,26 @@ local function get_tabs_fs(player, data, fs, full_height)
end
local function get_debug_grid(data, fs, full_height)
local spacing = 0.2
fs("style_type[label;font_size=8;noclip=true]")
local spacing, i = 0.2, 1
for x = 0, data.inv_width + 8, spacing do
fs("box", x, 0, 0.01, full_height, "#ff0")
fs("label", x, full_height + 0.1, tostring(i))
i = i + 1
end
i = 61
for y = 0, full_height, spacing do
fs("box", 0, y, data.inv_width + 8, 0.01, "#ff0")
fs("label", -0.15, y, tostring(i))
i = i - 1
end
fs("box", data.inv_width / 2, 0, 0.01, full_height, "#f00")
fs("box", 0, full_height / 2, data.inv_width, 0.01, "#f00")
fs("style_type[label;font_size=16]")
end
local function make_fs(player, data)
@ -2207,9 +2235,9 @@ function i3.get_tabs()
return tabs
end
function i3.delete_tab(tabname)
function i3.remove_tab(tabname)
if not true_str(tabname) then
return err "i3.delete_tab: tab name missing"
return err "i3.remove_tab: tab name missing"
end
for i, def in ipairs(tabs) do
@ -2286,20 +2314,21 @@ local function init_data(player, info)
end
local function reset_data(data)
data.filter = ""
data.expand = ""
data.pagenum = 1
data.rnum = 1
data.unum = 1
data.scrbar_rcp = 1
data.scrbar_usg = 1
data.query_item = nil
data.recipes = nil
data.usages = nil
data.export_rcp = nil
data.export_usg = nil
data.alt_items = nil
data.items = data.items_raw
data.filter = ""
data.expand = ""
data.pagenum = 1
data.rnum = 1
data.unum = 1
data.scrbar_rcp = 1
data.scrbar_usg = 1
data.query_item = nil
data.recipes = nil
data.usages = nil
data.export_rcp = nil
data.export_usg = nil
data.alt_items = nil
data.confirm_trash = nil
data.items = data.items_raw
if data.current_itab > 1 then
sort_by_category(data)
@ -2501,7 +2530,7 @@ local function get_inventory_fs(player, data, fs)
fs("scroll_container_end[]")
local btn = {
{"trash", ES"Trash all items"},
{"trash", ES"Clear inventory"},
{"sort_az", ES"Sort items (A-Z)"},
{"sort_za", ES"Sort items (Z-A)"},
{"compress", ES"Compress items"},
@ -2516,6 +2545,18 @@ local function get_inventory_fs(player, data, fs)
fs("image_button", i + 3.447 - (i * 0.4), 11.43, 0.35, 0.35, "", btn_name, "")
fs(fmt("tooltip[%s;%s]", btn_name, tooltip))
end
if data.confirm_trash then
fs("style_type[box;colors=#999,#999,#808080,#808080]")
for _ = 1, 3 do
fs("box", 2.97, 10.75, 4.3, 0.5, "")
end
fs("label", 3.12, 11, "Confirm trash?")
fs("image_button", 5.17, 10.75, 1, 0.5, "", "confirm_trash_yes", "Yes")
fs("image_button", 6.27, 10.75, 1, 0.5, "", "confirm_trash_no", "No")
end
end
i3.new_tab {
@ -2527,10 +2568,10 @@ i3.new_tab {
local name = player:get_player_name()
local sb_inv = fields.scrbar_inv
if fields.skins and data.skin_id ~= tonum(fields.skins) then
data.skin_id = tonum(fields.skins)
if fields.skins then
local id = tonum(fields.skins)
local _skins = skins.get_skinlist_for_player(name)
skins.set_player_skin(player, _skins[data.skin_id])
skins.set_player_skin(player, _skins[id])
end
for field in pairs(fields) do
@ -2587,9 +2628,16 @@ i3.new_tab {
end
if fields.trash then
local inv = player:get_inventory()
inv:set_list("main", {})
inv:set_list("craft", {})
data.confirm_trash = true
elseif fields.confirm_trash_yes or fields.confirm_trash_no then
if fields.confirm_trash_yes then
local inv = player:get_inventory()
inv:set_list("main", {})
inv:set_list("craft", {})
end
data.confirm_trash = nil
elseif fields.compress then
compress_items(player)
@ -2870,18 +2918,12 @@ end
core.register_on_mods_loaded(function()
get_init_items()
__sfinv = rawget(_G, "sfinv")
if __sfinv then
old_sfinv_fn = sfinv.set_player_inventory_formspec
if rawget(_G, "sfinv") then
function sfinv.set_player_inventory_formspec() return end
sfinv.enabled = false
end
__unified_inventory = rawget(_G, "unified_inventory")
if __unified_inventory then
old_unified_inventory_fn = unified_inventory.set_inventory_formspec
if rawget(_G, "unified_inventory") then
function unified_inventory.set_inventory_formspec() return end
end
end)
@ -2961,21 +3003,7 @@ core.register_on_joinplayer(function(player)
local info = core.get_player_information and core.get_player_information(name)
if not info or get_formspec_version(info) < MIN_FORMSPEC_VERSION then
if __sfinv then
sfinv.set_player_inventory_formspec = old_sfinv_fn
sfinv.enabled = true
end
if __unified_inventory then
unified_inventory.set_inventory_formspec = old_unified_inventory_fn
if __sfinv then
sfinv.enabled = false
end
end
pdata[name] = nil
return outdated(name)
end
@ -3006,7 +3034,6 @@ end)
local META_SAVES = {
bag_size = true,
waypoints = true,
skin_id = true,
inv_items = true,
known_recipes = true,
}
@ -3044,11 +3071,14 @@ end
after(SAVE_INTERVAL, routine)
core.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "" then
local name = player:get_player_name()
if formname == "i3_outdated" then
return false, core.kick_player(name, "Come back when your client is up-to-date.")
elseif formname ~= "" then
return false
end
local name = player:get_player_name()
local data = pdata[name]
if not data then return end
@ -3256,6 +3286,7 @@ if progressive_mode then
local player = players[i]
local name = player:get_player_name()
local data = pdata[name]
if not data then return end
local inv_items = get_inv_items(player)
local diff = array_diff(inv_items, data.inv_items)
@ -3291,7 +3322,7 @@ if progressive_mode then
local name = player:get_player_name()
local data = pdata[name]
if data.show_hud ~= nil and singleplayer then
if data and data.show_hud ~= nil and singleplayer then
show_hud_success(player, data)
end
end
@ -3302,6 +3333,7 @@ if progressive_mode then
core.register_on_joinplayer(function(player)
local name = player:get_player_name()
local data = pdata[name]
if not data then return end
data.inv_items = data.inv_items or {}
data.known_recipes = data.known_recipes or 0