Compare commits

...

4 Commits

Author SHA1 Message Date
d9a16bf39d Bump version 2022-12-05 03:08:19 +01:00
2a2837dd0c Minor cleaning 2022-12-01 20:28:44 +01:00
080579b2a4 Show player name based on nametag 2022-12-01 20:23:53 +01:00
b711f8f195 API doc clarification 2022-11-12 19:54:17 +01:00
4 changed files with 25 additions and 15 deletions

16
API.md
View File

@ -12,23 +12,31 @@ Custom tabs can be added to the `i3` inventory as follow (example):
```Lua ```Lua
i3.new_tab("stuff", { i3.new_tab("stuff", {
description = "Stuff", description = "Stuff",
image = "image.png", -- Optional, adds an image next to the tab description image = "image.png", -- Optional, add an image next to the tab description
-- Determine if the tab is visible by a player, `false` or `nil` hide the tab --
-- The functions below are all optional
--
-- Determine if the tab is visible by a player, return false to hide the tab
access = function(player, data) access = function(player, data)
local name = player:get_player_name() local name = player:get_player_name()
return name == "singleplayer" return name == "singleplayer"
end, end,
formspec = function(player, data, fs) formspec = function(player, data, fs)
fs"label[3,1;This is just a test]" fs("label", 3, 1, "Just a test")
fs"label[3,2;Lorem Ipsum]"
-- No need to return anything
end, end,
-- Events handling happens here -- Events handling happens here
fields = function(player, data, fields) fields = function(player, data, fields)
if fields.mybutton then if fields.mybutton then
do_things() -- Do things
end end
i3.set_fs(player) -- Update the formspec, mandatory
end, end,
}) })
``` ```

View File

@ -20,7 +20,7 @@ local function lf(path)
end end
i3 = { i3 = {
version = 1121, version = 1123,
data = core.deserialize(storage:get_string"data") or {}, data = core.deserialize(storage:get_string"data") or {},
settings = { settings = {

View File

@ -380,9 +380,9 @@ local function get_waypoint_fs(fs, data, player, yextra, ctn_len)
fs"style_type[label;font=normal;font_size=16;textcolor=#fff]" fs"style_type[label;font=normal;font_size=16;textcolor=#fff]"
end end
local function get_bag_fs(fs, data, name, esc_name, bag_size, yextra) local function get_bag_fs(fs, data, bag_size, yextra)
fs("list[detached:i3_bag_%s;main;0,%f;1,1;]", esc_name, yextra + 0.7) fs("list[detached:i3_bag_%s;main;0,%f;1,1;]", data.player_name, yextra + 0.7)
local bag = get_detached_inv("bag", name) local bag = get_detached_inv("bag", data.player_name)
if bag:is_empty"main" then return end if bag:is_empty"main" then return end
local v = {{1.9, 2, 0.12}, {3.05, 5, 0.06}, {4.2, 10}, {4.75, 10}} local v = {{1.9, 2, 0.12}, {3.05, 5, 0.06}, {4.2, 10}, {4.75, 10}}
@ -416,12 +416,13 @@ local function get_bag_fs(fs, data, name, esc_name, bag_size, yextra)
end end
fs("style_type[list;size=%f;spacing=%f]", size, spacing) fs("style_type[list;size=%f;spacing=%f]", size, spacing)
fs("list[detached:i3_bag_content_%s;main;%f,%f;4,%u;]", esc_name, x, yextra + 1.3, bag_size) fs("list[detached:i3_bag_content_%s;main;%f,%f;4,%u;]", data.player_name, x, yextra + 1.3, bag_size)
fs"style_type[list;size=1;spacing=0.15]" fs"style_type[list;size=1;spacing=0.15]"
end end
local function get_container(fs, data, player, yoffset, ctn_len, award_list, awards_unlocked, award_list_nb, bag_size) local function get_container(fs, data, player, yoffset, ctn_len, award_list, awards_unlocked, award_list_nb, bag_size)
local name = data.player_name local nametag = player:get_nametag_attributes()
local name = true_str(nametag.text) and nametag.text or data.player_name
local esc_name = ESC(name) local esc_name = ESC(name)
add_subtitle(fs, "player_name", 0, ctn_len, 22, true, esc_name) add_subtitle(fs, "player_name", 0, ctn_len, 22, true, esc_name)
@ -474,14 +475,14 @@ local function get_container(fs, data, player, yoffset, ctn_len, award_list, awa
end end
if data.subcat == 1 then if data.subcat == 1 then
get_bag_fs(fs, data, name, esc_name, bag_size, yextra) get_bag_fs(fs, data, bag_size, yextra)
elseif data.subcat == 2 then elseif data.subcat == 2 then
if not i3.modules.armor then if not i3.modules.armor then
return not_installed "3d_armor" return not_installed "3d_armor"
end end
local armor_def = armor.def[name] local armor_def = armor.def[data.player_name]
local _, armor_inv = armor:get_valid_player(player, "3d_armor") local _, armor_inv = armor:get_valid_player(player, "3d_armor")
fs("list[detached:%s_armor;armor;0,%f;5,1;]", esc_name, yextra + 0.7) fs("list[detached:%s_armor;armor;0,%f;5,1;]", esc_name, yextra + 0.7)
@ -522,7 +523,7 @@ local function get_container(fs, data, player, yoffset, ctn_len, award_list, awa
return not_installed "skinsdb" return not_installed "skinsdb"
end end
local _skins = skins.get_skinlist_for_player(name) local _skins = skins.get_skinlist_for_player(data.player_name)
local skin_name = skins.get_player_skin(player).name local skin_name = skins.get_player_skin(player).name
local spp, add_y = 24, 0 local spp, add_y = 24, 0
@ -1695,7 +1696,7 @@ local function make_fs(player, data)
local tab = i3.tabs[data.tab] local tab = i3.tabs[data.tab]
if tab then if tab and tab.formspec then
tab.formspec(player, data, fs) tab.formspec(player, data, fs)
end end

View File

@ -3,7 +3,8 @@ i3.new_tab("test1", {
image = "i3_heart.png", image = "i3_heart.png",
formspec = function(player, data, fs) formspec = function(player, data, fs)
fs("label[3,1;Test 1]") fs("label", 3, 1, "Just a test")
fs"label[3,2;Lorem Ipsum]"
end, end,
}) })