mirror of
https://github.com/minetest-mods/i3.git
synced 2025-07-03 00:50:22 +02:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
d9a16bf39d | |||
2a2837dd0c | |||
080579b2a4 | |||
b711f8f195 |
16
API.md
16
API.md
@ -12,23 +12,31 @@ Custom tabs can be added to the `i3` inventory as follow (example):
|
||||
```Lua
|
||||
i3.new_tab("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)
|
||||
local name = player:get_player_name()
|
||||
return name == "singleplayer"
|
||||
end,
|
||||
|
||||
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,
|
||||
|
||||
-- Events handling happens here
|
||||
fields = function(player, data, fields)
|
||||
if fields.mybutton then
|
||||
do_things()
|
||||
-- Do things
|
||||
end
|
||||
|
||||
i3.set_fs(player) -- Update the formspec, mandatory
|
||||
end,
|
||||
})
|
||||
```
|
||||
|
2
init.lua
2
init.lua
@ -20,7 +20,7 @@ local function lf(path)
|
||||
end
|
||||
|
||||
i3 = {
|
||||
version = 1121,
|
||||
version = 1123,
|
||||
data = core.deserialize(storage:get_string"data") or {},
|
||||
|
||||
settings = {
|
||||
|
19
src/gui.lua
19
src/gui.lua
@ -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]"
|
||||
end
|
||||
|
||||
local function get_bag_fs(fs, data, name, esc_name, bag_size, yextra)
|
||||
fs("list[detached:i3_bag_%s;main;0,%f;1,1;]", esc_name, yextra + 0.7)
|
||||
local bag = get_detached_inv("bag", name)
|
||||
local function get_bag_fs(fs, data, bag_size, yextra)
|
||||
fs("list[detached:i3_bag_%s;main;0,%f;1,1;]", data.player_name, yextra + 0.7)
|
||||
local bag = get_detached_inv("bag", data.player_name)
|
||||
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}}
|
||||
@ -416,12 +416,13 @@ local function get_bag_fs(fs, data, name, esc_name, bag_size, yextra)
|
||||
end
|
||||
|
||||
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]"
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
if not i3.modules.armor then
|
||||
return not_installed "3d_armor"
|
||||
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")
|
||||
|
||||
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"
|
||||
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 spp, add_y = 24, 0
|
||||
|
||||
@ -1695,7 +1696,7 @@ local function make_fs(player, data)
|
||||
|
||||
local tab = i3.tabs[data.tab]
|
||||
|
||||
if tab then
|
||||
if tab and tab.formspec then
|
||||
tab.formspec(player, data, fs)
|
||||
end
|
||||
|
||||
|
@ -3,7 +3,8 @@ i3.new_tab("test1", {
|
||||
image = "i3_heart.png",
|
||||
|
||||
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,
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user