Compare commits

..

7 Commits
1.6 ... 1.6.2

8 changed files with 49 additions and 41 deletions

4
API.md
View File

@ -17,9 +17,7 @@ i3.new_tab("stuff", {
-- Determine if the tab is visible by a player, `false` or `nil` hide the tab
access = function(player, data)
local name = player:get_player_name()
if name == "singleplayer" then
return false
end
return name == "singleplayer"
end,
formspec = function(player, data, fs)

View File

@ -167,6 +167,13 @@ function i3.set_fs(player)
sort_inventory(player, data)
end
for i, tab in ipairs(i3.tabs) do
if data.tab == i and tab.access and not tab.access(player, data) then
data.tab = 1
break
end
end
local fs = make_fs(player, data)
player:set_inventory_formspec(fs)
end
@ -221,8 +228,8 @@ function i3.set_tab(player, tabname)
return
end
for i, def in ipairs(i3.tabs) do
if def.name == tabname then
for i, tab in ipairs(i3.tabs) do
if tab.name == tabname then
data.tab = i
return
end

View File

@ -242,7 +242,7 @@ local function resolve_aliases(hash)
end
end
if newname ~= "" and i3.recipes_cache[oldname] and not hash[newname] then
if newname ~= "" and i3.recipes_cache[oldname] and reg_items[newname] and not hash[newname] then
insert(i3.init_items, newname)
end
end

View File

@ -101,7 +101,7 @@ local function search(data)
for i = 1, #data.items_raw do
local item = data.items_raw[i]
local def = reg_items[item]
local desc = lower(translate(data.lang_code, def and def.description)) or ""
local desc = lower(translate(data.lang_code, def.description)) or ""
local search_in = fmt("%s %s", item, desc)
local temp, j, to_add = {}, 1
@ -592,7 +592,7 @@ local function add_hud_waypoint(player, name, pos, color)
return player:hud_add {
hud_elem_type = "waypoint",
name = name,
text = " m",
text = "m",
world_pos = pos,
number = color,
z_index = -300,

View File

@ -215,10 +215,10 @@ local function inv_fields(player, data, fields)
return set_fs(player)
end
local function select_item(player, data, _f)
local function select_item(player, data, fields)
local item
for field in pairs(_f) do
for field in pairs(fields) do
if find(field, ":") then
item = field
break

View File

@ -494,17 +494,21 @@ local function get_container(fs, data, player, yoffset, ctn_len, award_list, awa
local _skins = skins.get_skinlist_for_player(name)
local skin_name = skins.get_player_skin(player).name
local btn_y = yextra + 0.75
local spp = 24
local spp, add_y = 24, 0
data.skin_pagemax = max(1, ceil(#_skins / spp))
if #_skins > spp then
local btn_y = yextra + 0.75
add_y += 0.6
fs("image_button", 1.5, btn_y, 0.35, 0.35, "", "prev_skin", "")
fs("image_button", 3.85, btn_y, 0.35, 0.35, "", "next_skin", "")
data.skin_pagemax = max(1, ceil(#_skins / spp))
fs"style[skin_page;font=bold;font_size=18]"
fs("button", 1.85, btn_y - 0.23, 2, 0.8, "skin_page",
fmt("%s / %u", clr(colors.yellow, data.skin_pagenum), data.skin_pagemax))
fs("image_button", 1.5, btn_y, 0.35, 0.35, "", "prev_skin", "")
fs("image_button", 3.85, btn_y, 0.35, 0.35, "", "next_skin", "")
fs"style[skin_page;font=bold;font_size=18]"
fs("button", 1.85, btn_y - 0.23, 2, 0.8, "skin_page",
fmt("%s / %u", clr(colors.yellow, data.skin_pagenum), data.skin_pagemax))
end
local first = (data.skin_pagenum - 1) * spp
local last = first + spp - 1
@ -523,7 +527,7 @@ local function get_container(fs, data, player, yoffset, ctn_len, award_list, awa
local X = (i % 3) * 1.93
local Y = ceil((i % spp - X) / 3 + 1)
Y += (Y * 2.45) + yextra - 2.15
Y += (Y * 2.45) + yextra - 2.75 + add_y
fs("image_button", X, Y, 1.86, 3.4, "", btn_name, "")
fs(fmt("tooltip[%s;%s]", btn_name, ESC(skin.name)))
@ -688,9 +692,10 @@ local function get_inventory_fs(player, data, fs)
elseif i3.modules.skins and data.subcat == 3 then
local spp = 24
local _skins = skins.get_skinlist_for_player(data.player_name)
local num = max(1, min(spp, #_skins - ((data.skin_pagenum - 1) * spp)))
local nb = #_skins
local num = max(1, min(spp, nb - ((data.skin_pagenum - 1) * spp)))
max_val += ceil(num / 3) * 34
max_val += ceil(num / 3) * (nb > spp and 34 or 31)
elseif i3.modules.awards and data.subcat == 4 then
award_list = awards.get_award_states(data.player_name)
@ -824,7 +829,7 @@ local function get_tooltip(item, info, pos)
return fmt("tooltip[%s;%s]", item, ESC(tooltip))
end
local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_size, _btn_size)
local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_size, btn_size2)
local custom_recipe = i3.craft_types[rcp.type]
local cooking = rcp.type == "cooking"
local fuel = rcp.type == "fuel"
@ -861,7 +866,7 @@ local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_siz
end
local BTN_SIZE = i3.settings.item_btn_size
local arrow_X = right + 0.2 + (_btn_size or BTN_SIZE)
local arrow_X = right + 0.2 + (btn_size2 or BTN_SIZE)
local X = arrow_X + 1.2
local Y = data.yoffset + 1.4
@ -1511,6 +1516,7 @@ local function make_fs(player, data)
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
@ -1521,7 +1527,15 @@ local function make_fs(player, data)
get_items_fs(fs, data, player, full_height)
end
if #i3.tabs > 1 then
local visible_tabs = 1
for _, def in ipairs(i3.tabs) do
if visible_tabs < 2 and def.access and def.access(player, data) then
visible_tabs++
end
end
if visible_tabs > 1 then
get_tabs_fs(fs, player, data, full_height)
end

View File

@ -74,6 +74,7 @@ local styles = string.format([[
style_type[image_button,item_image_button,checkbox,dropdown;border=false;sound=i3_click]
style_type[item_image_button;bgimg_hovered=%s]
style[;sound=]
style[nofav;sound=i3_cannot]
style[pagenum,no_item,no_rcp;font=bold;font_size=18]
style[exit;fgimg=%s;fgimg_hovered=%s;content_offset=0]

View File

@ -16,30 +16,18 @@ i3.new_tab("test2", {
end,
})
i3.new_tab("test3", {
description = "Test 3",
i3.new_tab("test_creative", {
description = "Test creative",
access = function(player, data)
local name = player:get_player_name()
if name == "singleplayer" then
return true
end
return core.is_creative_enabled(name)
end,
formspec = function(player, data, fs)
fs("label[3,1;Test 3]")
fs("label[3,1;Creative enabled]")
end,
fields = function(player, data, fields)
i3.set_fs(player, "label[3,2;Test extra_fs]")
end,
fields = i3.set_fs,
})
i3.override_tab("test2", {
description = "Test override",
image = "i3_mesepick.png",
formspec = function(player, data, fs)
fs("label[3,1;Override!]")
end,
})