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 return buttons_num
> 0
29 get
= function(self
, player
, context
)
34 if buttons_num
> MAX_ROWS
then
39 for name
, def
in pairs(buttons
) do
40 if def
.image
~= nil then
41 f
= f
.. "image["..(x
+0.1)..","..(y
+0.1)..";0.8,0.8;"..def
.image
.."]"
43 local button_id
= minetest
.formspec_escape(button_prefix
.. name
)
45 (x
+1)..","..y
..";"..w
..",1;"..
47 minetest
.formspec_escape(def
.title
)..
49 if def
.tooltip
~= nil then
50 f
= f
.. "tooltip["..button_id
..";"..
51 minetest
.formspec_escape(def
.tooltip
).."]"
59 return sfinv
.make_formspec(player
, context
, f
)
61 on_player_receive_fields
= function(self
, player
, context
, fields
)
62 for widget_name
, _
in pairs(fields
) do
63 local id
= string.sub(widget_name
, string.len(button_prefix
) + 1, -1)
64 if buttons
[id
] ~= nil and buttons
[id
].action
~= nil then
65 buttons
[id
].action(player
)