mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-11-26 12:33:43 +01:00
Drop MT <= 5.0 support and fix positioning
This commit is contained in:
parent
c9773f1ee9
commit
f7ccd282be
81
init.lua
81
init.lua
@ -47,15 +47,7 @@ local on_leaveplayer = core.register_on_leaveplayer
|
|||||||
local on_receive_fields = core.register_on_player_receive_fields
|
local on_receive_fields = core.register_on_player_receive_fields
|
||||||
|
|
||||||
local ESC = core.formspec_escape
|
local ESC = core.formspec_escape
|
||||||
local S = CORE_VERSION >= 500 and core.get_translator("craftguide") or
|
local S = core.get_translator("craftguide")
|
||||||
function(...)
|
|
||||||
local args, i = {...}, 1
|
|
||||||
|
|
||||||
return args[1]:gsub("@%d+", function()
|
|
||||||
i = i + 1
|
|
||||||
return args[i]
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
local ES = function(...)
|
local ES = function(...)
|
||||||
return ESC(S(...))
|
return ESC(S(...))
|
||||||
@ -79,7 +71,7 @@ local IPP = ROWS * LINES
|
|||||||
local WH_LIMIT = 8
|
local WH_LIMIT = 8
|
||||||
|
|
||||||
local XOFFSET = sfinv_only and 3.83 or 11.2
|
local XOFFSET = sfinv_only and 3.83 or 11.2
|
||||||
local YOFFSET = sfinv_only and 6 or 1
|
local YOFFSET = sfinv_only and 4.9 or 1
|
||||||
|
|
||||||
local PNG = {
|
local PNG = {
|
||||||
bg = "craftguide_bg.png",
|
bg = "craftguide_bg.png",
|
||||||
@ -737,10 +729,8 @@ local function get_output_fs(fs, L)
|
|||||||
local tooltip = custom_recipe and custom_recipe.description or
|
local tooltip = custom_recipe and custom_recipe.description or
|
||||||
L.shapeless and S"Shapeless" or S"Cooking"
|
L.shapeless and S"Shapeless" or S"Cooking"
|
||||||
|
|
||||||
if CORE_VERSION >= 500 then
|
|
||||||
fs[#fs + 1] = fmt(FMT.tooltip, pos_x, pos_y + L.spacing, 0.5, 0.5, ESC(tooltip))
|
fs[#fs + 1] = fmt(FMT.tooltip, pos_x, pos_y + L.spacing, 0.5, 0.5, ESC(tooltip))
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local arrow_X = L.rightest + (L._btn_size or 1.1)
|
local arrow_X = L.rightest + (L._btn_size or 1.1)
|
||||||
local output_X = arrow_X + 0.9
|
local output_X = arrow_X + 0.9
|
||||||
@ -758,7 +748,7 @@ local function get_output_fs(fs, L)
|
|||||||
item = clean_name(item)
|
item = clean_name(item)
|
||||||
local name = match(item, "%S*")
|
local name = match(item, "%S*")
|
||||||
|
|
||||||
if CORE_VERSION >= 510 then
|
if CORE_VERSION >= 520 then
|
||||||
fs[#fs + 1] = fmt(FMT.image,
|
fs[#fs + 1] = fmt(FMT.image,
|
||||||
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
|
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
|
||||||
1.1, 1.1, PNG.selected)
|
1.1, 1.1, PNG.selected)
|
||||||
@ -870,7 +860,7 @@ local function get_grid_fs(fs, rcp, spacing)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if CORE_VERSION >= 510 and not large_recipe then
|
if CORE_VERSION >= 520 and not large_recipe then
|
||||||
fs[#fs + 1] = fmt(FMT.image,
|
fs[#fs + 1] = fmt(FMT.image,
|
||||||
X, Y + (sfinv_only and 0.7 or 0), btn_size, btn_size, PNG.selected)
|
X, Y + (sfinv_only and 0.7 or 0), btn_size, btn_size, PNG.selected)
|
||||||
end
|
end
|
||||||
@ -908,7 +898,18 @@ local function get_grid_fs(fs, rcp, spacing)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_panels(data, fs)
|
local function get_panels(data, fs)
|
||||||
local start_y = CORE_VERSION >= 520 and 0 or 0.33
|
local start_y
|
||||||
|
|
||||||
|
if CORE_VERSION >= 520 then
|
||||||
|
if sfinv_only then
|
||||||
|
start_y = 0.33
|
||||||
|
else
|
||||||
|
start_y = 0
|
||||||
|
end
|
||||||
|
else
|
||||||
|
start_y = 0.33
|
||||||
|
end
|
||||||
|
|
||||||
local panels = {
|
local panels = {
|
||||||
{dat = data.usages or {}, height = 3.5},
|
{dat = data.usages or {}, height = 3.5},
|
||||||
{dat = data.recipes or {}, height = 3.5},
|
{dat = data.recipes or {}, height = 3.5},
|
||||||
@ -916,6 +917,7 @@ local function get_panels(data, fs)
|
|||||||
|
|
||||||
if CORE_VERSION >= 520 and not sfinv_only then
|
if CORE_VERSION >= 520 and not sfinv_only then
|
||||||
panels.favs = {dat = {}, height = 2.19}
|
panels.favs = {dat = {}, height = 2.19}
|
||||||
|
|
||||||
elseif sfinv_only then
|
elseif sfinv_only then
|
||||||
panels = data.show_usages and
|
panels = data.show_usages and
|
||||||
{{dat = data.usages}} or {{dat = data.recipes}}
|
{{dat = data.usages}} or {{dat = data.recipes}}
|
||||||
@ -926,13 +928,10 @@ local function get_panels(data, fs)
|
|||||||
local spacing = (start_y - 1) * 3.6
|
local spacing = (start_y - 1) * 3.6
|
||||||
|
|
||||||
if not sfinv_only then
|
if not sfinv_only then
|
||||||
fs[#fs + 1] = CORE_VERSION >= 510 and
|
fs[#fs + 1] = fmt("background9[8.1,%f;6.6,%f;%s;false;%d]",
|
||||||
fmt("background9[8.1,%f;6.6,%f;%s;false;%d]",
|
-0.2 + spacing, v.height, PNG.bg_full, 10)
|
||||||
-0.2 + spacing, v.height, PNG.bg_full, 10) or
|
|
||||||
fmt("background[8.1,%f;6.6,%f;%s;false]",
|
|
||||||
-0.2 + spacing, v.height, PNG.bg_full)
|
|
||||||
|
|
||||||
if k ~= "favs" then
|
if CORE_VERSION >= 520 and k ~= "favs" then
|
||||||
local fav = is_fav(data)
|
local fav = is_fav(data)
|
||||||
local nfavs = #data.favs
|
local nfavs = #data.favs
|
||||||
|
|
||||||
@ -980,14 +979,14 @@ local function get_panels(data, fs)
|
|||||||
|
|
||||||
fs[#fs + 1] = fmt(FMT.label,
|
fs[#fs + 1] = fmt(FMT.label,
|
||||||
XOFFSET + (sfinv_only and 2.3 or 1.6) + (is_recipe and xr or xu),
|
XOFFSET + (sfinv_only and 2.3 or 1.6) + (is_recipe and xr or xu),
|
||||||
YOFFSET + (sfinv_only and 2.3 or 1.5 + spacing), lbl)
|
YOFFSET + (sfinv_only and 3.4 or 1.5 + spacing), lbl)
|
||||||
|
|
||||||
if rn > 1 then
|
if rn > 1 then
|
||||||
local btn_suffix = is_recipe and "recipe" or "usage"
|
local btn_suffix = is_recipe and "recipe" or "usage"
|
||||||
local prev_name = fmt("prev_%s", btn_suffix)
|
local prev_name = fmt("prev_%s", btn_suffix)
|
||||||
local next_name = fmt("next_%s", btn_suffix)
|
local next_name = fmt("next_%s", btn_suffix)
|
||||||
local x_arrow = XOFFSET + (sfinv_only and 1.7 or 1)
|
local x_arrow = XOFFSET + (sfinv_only and 1.7 or 1)
|
||||||
local y_arrow = YOFFSET + (sfinv_only and 2.2 or 1.4 + spacing)
|
local y_arrow = YOFFSET + (sfinv_only and 3.3 or 1.4 + spacing)
|
||||||
|
|
||||||
if CORE_VERSION >= 520 then
|
if CORE_VERSION >= 520 then
|
||||||
fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
|
fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
|
||||||
@ -1039,11 +1038,8 @@ local function make_formspec(name)
|
|||||||
ROWS + (data.query_item and 6.7 or 0) - 1.2, LINES - 0.3)
|
ROWS + (data.query_item and 6.7 or 0) - 1.2, LINES - 0.3)
|
||||||
|
|
||||||
if not sfinv_only then
|
if not sfinv_only then
|
||||||
fs[#fs + 1] = CORE_VERSION >= 510 and
|
fs[#fs + 1] = fmt("background9[-0.15,-0.2;%f,%f;%s;false;%d]",
|
||||||
fmt("background9[-0.15,-0.2;%f,%f;%s;false;%d]",
|
ROWS - 0.9, LINES + 0.4, PNG.bg_full, 10)
|
||||||
ROWS - 0.9, LINES + 0.4, PNG.bg_full, 10) or
|
|
||||||
fmt("background[-0.15,-0.2;%f,%f;%s;false]",
|
|
||||||
ROWS - 0.9, LINES + 0.4, PNG.bg_full)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fs[#fs + 1] = fmt([[
|
fs[#fs + 1] = fmt([[
|
||||||
@ -1114,7 +1110,7 @@ local function make_formspec(name)
|
|||||||
local X = i % ROWS
|
local X = i % ROWS
|
||||||
local Y = (i % IPP - X) / ROWS + 1
|
local Y = (i % IPP - X) / ROWS + 1
|
||||||
|
|
||||||
if CORE_VERSION >= 510 and data.query_item == item then
|
if CORE_VERSION >= 520 and data.query_item == item then
|
||||||
fs[#fs + 1] = fmt(FMT.image,
|
fs[#fs + 1] = fmt(FMT.image,
|
||||||
X - (X * (sfinv_only and 0.12 or 0.14)) - 0.05,
|
X - (X * (sfinv_only and 0.12 or 0.14)) - 0.05,
|
||||||
Y - (Y * 0.1) - 0.1,
|
Y - (Y * 0.1) - 0.1,
|
||||||
@ -1528,14 +1524,11 @@ local function get_init_items()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function init_data(name)
|
local function init_data(name)
|
||||||
local items = CORE_VERSION >= 500 and init_items or
|
|
||||||
(#init_items == 0 and get_init_items() or init_items)
|
|
||||||
|
|
||||||
pdata[name] = {
|
pdata[name] = {
|
||||||
filter = "",
|
filter = "",
|
||||||
pagenum = 1,
|
pagenum = 1,
|
||||||
items = items,
|
items = init_items,
|
||||||
items_raw = items,
|
items_raw = init_items,
|
||||||
favs = {},
|
favs = {},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -1552,9 +1545,7 @@ local function reset_data(data)
|
|||||||
data.items = data.items_raw
|
data.items = data.items_raw
|
||||||
end
|
end
|
||||||
|
|
||||||
if CORE_VERSION >= 500 then
|
on_mods_loaded(get_init_items)
|
||||||
on_mods_loaded(get_init_items)
|
|
||||||
end
|
|
||||||
|
|
||||||
on_joinplayer(function(player)
|
on_joinplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
@ -1960,14 +1951,9 @@ if progressive_mode then
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
|
|
||||||
if CORE_VERSION >= 500 then
|
|
||||||
local meta = player:get_meta()
|
local meta = player:get_meta()
|
||||||
data.inv_items = dslz(meta:get_string("inv_items")) or {}
|
data.inv_items = dslz(meta:get_string("inv_items")) or {}
|
||||||
data.known_recipes = dslz(meta:get_string("known_recipes")) or 0
|
data.known_recipes = dslz(meta:get_string("known_recipes")) or 0
|
||||||
else
|
|
||||||
data.inv_items = dslz(player:get_attribute("inv_items")) or {}
|
|
||||||
data.known_recipes = dslz(player:get_attribute("known_recipes")) or 0
|
|
||||||
end
|
|
||||||
|
|
||||||
data.hud = {
|
data.hud = {
|
||||||
bg = player:hud_add{
|
bg = player:hud_add{
|
||||||
@ -2002,22 +1988,13 @@ if progressive_mode then
|
|||||||
}
|
}
|
||||||
|
|
||||||
local function save_meta(player)
|
local function save_meta(player)
|
||||||
local meta
|
local meta = player:get_meta()
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
|
|
||||||
if CORE_VERSION >= 500 then
|
|
||||||
meta = player:get_meta()
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = 1, #to_save do
|
for i = 1, #to_save do
|
||||||
local meta_name = to_save[i]
|
local meta_name = to_save[i]
|
||||||
|
|
||||||
if CORE_VERSION >= 500 then
|
|
||||||
meta:set_string(meta_name, slz(data[meta_name]))
|
meta:set_string(meta_name, slz(data[meta_name]))
|
||||||
else
|
|
||||||
player:set_attribute(meta_name, slz(data[meta_name]))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user