add formspec_size_add_w and formspec_size_add_h to support resizing from multiple mods

This commit is contained in:
Alexander Weber 2019-01-15 12:06:27 +01:00
parent c2f0086916
commit 3101d46eb1
2 changed files with 26 additions and 4 deletions

View File

@ -15,6 +15,8 @@ Methods:
Method does set Attributes:
- enh.formspec_size
- enh.formspec_size_add_w
- enh.formspec_size_add_h
- enh.formspec_before_navfs
- enh.formspec_after_navfs
- enh.formspec_after_content
@ -33,7 +35,9 @@ end
local enh_handler_class = {
formspec_before_navfs = "",
formspec_after_navfs = "",
formspec_after_content = ""
formspec_after_content = "",
formspec_size_add_w = 0,
formspec_size_add_h = 0,
}
smart_sfinv_api.defaults = enh_handler_class
enh_handler_class_meta = {__index = enh_handler_class }
@ -84,12 +88,30 @@ function sfinv.make_formspec(player, context, content, show_inv, size)
if size then
handler.formspec_size = size
end
handler.formspec_size_add_w = 0
handler.formspec_size_add_h = 0
local nav_fs = sfinv.get_nav_fs(player, context, context.nav_titles, context.nav_idx)
handler:run_enhancements("make_formspec", player, context, content, show_inv)
local new_size
if handler.formspec_size_add_w ~= 0 or handler.formspec_size_add_h ~= 0 then
local b = "false"
local w, h = string.match(handler.formspec_size, "%[([%d.]+)%,([%d.]+)%]")
if not w or not h then
w, h, b = string.match(handler.formspec_size, "%[([%d.]+)%,([%d.]+)%;(%s+)%]")
end
w = w + handler.formspec_size_add_w
h = h + handler.formspec_size_add_h
new_size = "size[" .. w .. "," .. h .. ";" .. b .."]"
end
local tmp = enh_handler_class.patch_2275 and {
handler.formspec_size,
new_size or handler.formspec_size,
handler.theme_main,
handler.formspec_before_navfs,
nav_fs,
@ -98,7 +120,7 @@ function sfinv.make_formspec(player, context, content, show_inv, size)
content,
handler.formspec_after_content
} or { -- can be removed if patch_2275 merged to upstream
handler.formspec_size,
new_size or handler.formspec_size,
handler.theme_main,
handler.formspec_before_navfs,
nav_fs,

View File

@ -40,7 +40,7 @@ smart_sfinv_api.register_enhancement({
handler.formspec_before_navfs = "textlist[0,0;2.8,8.6;smart_sfinv_nav_site;" .. table.concat(nav_titles_site, ",") ..
";" .. context.current_idx_site .. ";true]container[3,0]"..handler.formspec_before_navfs
handler.formspec_after_content = handler.formspec_after_content.."container_end[]"
handler.formspec_size = 'size[11,8.6]'
handler.formspec_size_add_w = handler.formspec_size_add_w + 3
elseif current_idx_above >= 2 then
-- Because "Creative" is inserted, the index needs to be adjusted
current_idx_above = current_idx_above + 1