1 -- Boilerplate to support localized strings if intllib mod is installed.
3 if minetest
.get_modpath("intllib") then
6 S
= function(s
) return s
end
12 local button_prefix
= "sfinv_button_"
17 sfinv_buttons
.register_button
= function(name
, def
)
19 buttons_num
= buttons_num
+ 1
24 sfinv
.register_page("sfinv_buttons:buttons", {
26 is_in_nav
= function(self
, player
, context
)
27 -- Tab is shown only if at least 1 button is visible to player
28 for _
, def
in pairs(buttons
) do
29 if def
.show
== nil or def
.show(player
) == true then
35 get
= function(self
, player
, context
)
40 if buttons_num
> MAX_ROWS
then
45 for name
, def
in pairs(buttons
) do
46 if def
.show
== nil or def
.show(player
) == true then
47 if def
.image
~= nil then
48 f
= f
.. "image["..(x
+0.1)..","..(y
+0.1)..";0.8,0.8;"..def
.image
.."]"
50 local button_id
= minetest
.formspec_escape(button_prefix
.. name
)
52 (x
+1)..","..y
..";"..w
..",1;"..
54 minetest
.formspec_escape(def
.title
)..
56 if def
.tooltip
~= nil then
57 f
= f
.. "tooltip["..button_id
..";"..
58 minetest
.formspec_escape(def
.tooltip
).."]"
67 return sfinv
.make_formspec(player
, context
, f
)
69 on_player_receive_fields
= function(self
, player
, context
, fields
)
70 for widget_name
, _
in pairs(fields
) do
71 local id
= string.sub(widget_name
, string.len(button_prefix
) + 1, -1)
72 if buttons
[id
] ~= nil and buttons
[id
].action
~= nil then
73 buttons
[id
].action(player
)