2021-07-17 10:35:39 +02:00
|
|
|
-- Unified Inventory
|
2013-09-21 21:40:20 +02:00
|
|
|
|
2022-02-26 11:36:56 +01:00
|
|
|
if not minetest.features.formspec_version_element then
|
|
|
|
-- At least formspec_version[] is the minimal feature requirement
|
|
|
|
error("Unified Inventory requires Minetest version 5.4.0 or newer.\n" ..
|
|
|
|
" Please update Minetest or use an older version of Unified Inventory.")
|
|
|
|
end
|
|
|
|
|
2013-09-29 00:15:37 +02:00
|
|
|
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
local worldpath = minetest.get_worldpath()
|
2018-04-02 13:33:36 +02:00
|
|
|
|
2013-09-29 00:15:37 +02:00
|
|
|
-- Data tables definitions
|
2015-02-05 10:03:07 +01:00
|
|
|
unified_inventory = {
|
|
|
|
activefilter = {},
|
|
|
|
active_search_direction = {},
|
|
|
|
alternate = {},
|
|
|
|
current_page = {},
|
|
|
|
current_searchbox = {},
|
2021-04-05 20:07:14 +02:00
|
|
|
current_category = {},
|
|
|
|
current_category_scroll = {},
|
2015-02-05 10:03:07 +01:00
|
|
|
current_index = {},
|
|
|
|
current_item = {},
|
|
|
|
current_craft_direction = {},
|
|
|
|
registered_craft_types = {},
|
|
|
|
crafts_for = {usage = {}, recipe = {} },
|
|
|
|
players = {},
|
|
|
|
items_list_size = 0,
|
|
|
|
items_list = {},
|
|
|
|
filtered_items_list_size = {},
|
|
|
|
filtered_items_list = {},
|
|
|
|
pages = {},
|
|
|
|
buttons = {},
|
2021-10-14 18:38:07 +02:00
|
|
|
initialized_callbacks = {},
|
|
|
|
craft_registered_callbacks = {},
|
2015-02-05 10:03:07 +01:00
|
|
|
|
|
|
|
-- Homepos stuff
|
|
|
|
home_pos = {},
|
|
|
|
home_filename = worldpath.."/unified_inventory_home.home",
|
|
|
|
|
|
|
|
-- Default inventory page
|
|
|
|
default = "craft",
|
|
|
|
|
2015-06-28 09:47:03 +02:00
|
|
|
-- "Lite" mode
|
2018-06-23 14:56:27 +02:00
|
|
|
lite_mode = minetest.settings:get_bool("unified_inventory_lite"),
|
2018-04-02 13:33:36 +02:00
|
|
|
|
2021-04-05 20:07:14 +02:00
|
|
|
-- Items automatically added to categories based on item definitions
|
|
|
|
automatic_categorization = (minetest.settings:get_bool("unified_inventory_automatic_categorization") ~= false),
|
|
|
|
|
2017-03-01 23:28:40 +01:00
|
|
|
-- Trash enabled
|
2018-06-23 14:56:27 +02:00
|
|
|
trash_enabled = (minetest.settings:get_bool("unified_inventory_trash") ~= false),
|
2021-03-07 12:27:40 +01:00
|
|
|
imgscale = 1.25,
|
Use 9-slicing to build inventory-type backgrounds
This way the slots are all nice and crisp regardless of GUI scale or
image size, and we only need the single slot and its bright version.
This also makes the standard crafting grid into a style table entry that
can be referenced to insert the crafting grid at its proper
style-specific position in any formspec.
And it also makes the craft grid arrow, its X position, and the crafting
grid's result slot X position into style table entries.
Includes a few public helper functions to do most of the work:
`ui.single_slot(xpos, ypos, bright)`
Does just what it sounds like: it returns a single slot image.
`xpos` and `ypos` are normal coordinates in slots, as you'd use in
`image[]` element. `bright` is a flag that switches to the brighter
version of the slot image.
`ui.make_trash_slot(xpos, ypos)`
Creates a single slot, with a one-item `list[]` and a trash can icon
overlay.
`ui.make_inv_img_grid(xpos, ypos, width, height, bright)`
Generates a `width` by `height` grid of slot images, using the
single_slot function above, starting at (`xpos`,`ypos`) for the
top-left. Position is as in any `image[]` element, and dimensions
are in integer numbers of slots (so 8,4 would be a standard inventory).
`bright` is as above.
All three return a string that can be directly inserted into a formspec.
2021-03-08 18:14:31 +01:00
|
|
|
list_img_offset = 0.13,
|
2022-04-03 22:30:21 +02:00
|
|
|
standard_background = "bgcolor[#0000]background9[0,0;1,1;ui_formbg_9_sliced.png;true;16]",
|
2021-08-14 15:30:50 +02:00
|
|
|
|
2022-02-26 11:36:56 +01:00
|
|
|
version = 4
|
2021-03-08 11:07:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
local ui = unified_inventory
|
2021-03-07 12:27:40 +01:00
|
|
|
|
|
|
|
-- These tables establish position and layout for the two UI styles.
|
|
|
|
-- UI doesn't use formspec_[xy] anymore, but other mods may need them.
|
2015-06-28 09:47:03 +02:00
|
|
|
|
2021-03-08 11:07:38 +01:00
|
|
|
ui.style_full = {
|
2021-03-07 12:27:40 +01:00
|
|
|
formspec_x = 1,
|
|
|
|
formspec_y = 1,
|
2021-03-31 06:52:30 +02:00
|
|
|
formw = 17.75,
|
|
|
|
formh = 12.25,
|
2022-02-26 11:41:15 +01:00
|
|
|
-- Item browser size, pos
|
2015-06-28 09:47:03 +02:00
|
|
|
pagecols = 8,
|
2022-08-18 16:45:17 +02:00
|
|
|
pagerows = 11,
|
2021-03-05 16:58:18 +01:00
|
|
|
page_x = 10.75,
|
2022-08-18 16:45:17 +02:00
|
|
|
page_y = 0.30,
|
2022-02-26 11:41:15 +01:00
|
|
|
-- Item browser controls
|
|
|
|
page_buttons_x = 11.60,
|
|
|
|
page_buttons_y = 10.15,
|
|
|
|
searchwidth = 3.4,
|
|
|
|
-- Crafting grid positions
|
2021-03-05 16:58:18 +01:00
|
|
|
craft_x = 2.8,
|
2021-03-07 09:57:39 +01:00
|
|
|
craft_y = 1.15,
|
2021-03-08 20:41:49 +01:00
|
|
|
craftresult_x = 7.8,
|
|
|
|
craft_arrow_x = 6.55,
|
|
|
|
craft_guide_x = 3.3,
|
|
|
|
craft_guide_y = 1.15,
|
|
|
|
craft_guide_arrow_x = 7.05,
|
|
|
|
craft_guide_result_x = 8.3,
|
|
|
|
craft_guide_resultstr_x = 0.3,
|
|
|
|
craft_guide_resultstr_y = 0.6,
|
2021-03-07 10:13:36 +01:00
|
|
|
give_btn_x = 0.25,
|
2022-02-26 11:41:15 +01:00
|
|
|
-- Tab switching buttons
|
2021-03-05 16:58:18 +01:00
|
|
|
main_button_x = 0.4,
|
|
|
|
main_button_y = 11.0,
|
2022-02-26 11:41:15 +01:00
|
|
|
main_button_cols = 12,
|
|
|
|
main_button_rows = 1,
|
|
|
|
-- Tab title position
|
2021-03-05 16:58:18 +01:00
|
|
|
form_header_x = 0.4,
|
|
|
|
form_header_y = 0.4,
|
2022-02-26 11:41:15 +01:00
|
|
|
-- Generic sizes
|
2021-03-05 16:58:18 +01:00
|
|
|
btn_spc = 0.85,
|
|
|
|
btn_size = 0.75,
|
|
|
|
std_inv_x = 0.3,
|
2021-03-07 09:57:39 +01:00
|
|
|
std_inv_y = 5.75,
|
2021-03-07 12:27:40 +01:00
|
|
|
}
|
|
|
|
|
2021-03-08 11:07:38 +01:00
|
|
|
ui.style_lite = {
|
2021-03-07 12:27:40 +01:00
|
|
|
formspec_x = 0.6,
|
|
|
|
formspec_y = 0.6,
|
2021-03-31 06:52:30 +02:00
|
|
|
formw = 14,
|
|
|
|
formh = 9.75,
|
2022-02-26 11:41:15 +01:00
|
|
|
-- Item browser size, pos
|
2021-03-07 12:27:40 +01:00
|
|
|
pagecols = 4,
|
2022-08-18 16:45:17 +02:00
|
|
|
pagerows = 7,
|
2021-03-07 12:27:40 +01:00
|
|
|
page_x = 10.5,
|
2022-08-18 16:45:17 +02:00
|
|
|
page_y = 0.15,
|
2022-02-26 11:41:15 +01:00
|
|
|
-- Item browser controls
|
|
|
|
page_buttons_x = 10.5,
|
|
|
|
page_buttons_y = 6.15,
|
|
|
|
searchwidth = 1.6,
|
|
|
|
-- Crafting grid positions
|
2021-03-07 12:27:40 +01:00
|
|
|
craft_x = 2.6,
|
|
|
|
craft_y = 0.75,
|
2021-03-08 20:41:49 +01:00
|
|
|
craftresult_x = 5.75,
|
|
|
|
craft_arrow_x = 6.35,
|
|
|
|
craft_guide_x = 3.1,
|
|
|
|
craft_guide_y = 0.75,
|
|
|
|
craft_guide_arrow_x = 7.05,
|
|
|
|
craft_guide_result_x = 8.3,
|
|
|
|
craft_guide_resultstr_x = 0.15,
|
|
|
|
craft_guide_resultstr_y = 0.35,
|
2021-03-07 12:27:40 +01:00
|
|
|
give_btn_x = 0.15,
|
2022-02-26 11:41:15 +01:00
|
|
|
-- Tab switching buttons
|
2021-03-07 12:27:40 +01:00
|
|
|
main_button_x = 10.5,
|
2021-04-05 20:07:14 +02:00
|
|
|
main_button_y = 8.15,
|
2022-02-26 11:41:15 +01:00
|
|
|
main_button_cols = 4,
|
|
|
|
main_button_rows = 2,
|
|
|
|
-- Tab title position
|
2021-03-07 12:27:40 +01:00
|
|
|
form_header_x = 0.2,
|
|
|
|
form_header_y = 0.2,
|
2022-02-26 11:41:15 +01:00
|
|
|
-- Generic sizes
|
2021-03-07 12:27:40 +01:00
|
|
|
btn_spc = 0.8,
|
|
|
|
btn_size = 0.7,
|
|
|
|
std_inv_x = 0.1,
|
|
|
|
std_inv_y = 4.6,
|
2015-02-05 10:03:07 +01:00
|
|
|
}
|
2013-09-29 00:15:37 +02:00
|
|
|
|
Use 9-slicing to build inventory-type backgrounds
This way the slots are all nice and crisp regardless of GUI scale or
image size, and we only need the single slot and its bright version.
This also makes the standard crafting grid into a style table entry that
can be referenced to insert the crafting grid at its proper
style-specific position in any formspec.
And it also makes the craft grid arrow, its X position, and the crafting
grid's result slot X position into style table entries.
Includes a few public helper functions to do most of the work:
`ui.single_slot(xpos, ypos, bright)`
Does just what it sounds like: it returns a single slot image.
`xpos` and `ypos` are normal coordinates in slots, as you'd use in
`image[]` element. `bright` is a flag that switches to the brighter
version of the slot image.
`ui.make_trash_slot(xpos, ypos)`
Creates a single slot, with a one-item `list[]` and a trash can icon
overlay.
`ui.make_inv_img_grid(xpos, ypos, width, height, bright)`
Generates a `width` by `height` grid of slot images, using the
single_slot function above, starting at (`xpos`,`ypos`) for the
top-left. Position is as in any `image[]` element, and dimensions
are in integer numbers of slots (so 8,4 would be a standard inventory).
`bright` is as above.
All three return a string that can be directly inserted into a formspec.
2021-03-08 18:14:31 +01:00
|
|
|
dofile(modpath.."/api.lua")
|
|
|
|
|
2021-03-08 11:07:38 +01:00
|
|
|
for _, style in ipairs({ui.style_full, ui.style_lite}) do
|
2021-03-08 10:56:52 +01:00
|
|
|
style.items_per_page = style.pagecols * style.pagerows
|
2021-03-09 20:25:14 +01:00
|
|
|
style.standard_inv = string.format("list[current_player;main;%f,%f;8,4;]",
|
2021-03-10 00:31:16 +01:00
|
|
|
style.std_inv_x + ui.list_img_offset, style.std_inv_y + ui.list_img_offset)
|
Use 9-slicing to build inventory-type backgrounds
This way the slots are all nice and crisp regardless of GUI scale or
image size, and we only need the single slot and its bright version.
This also makes the standard crafting grid into a style table entry that
can be referenced to insert the crafting grid at its proper
style-specific position in any formspec.
And it also makes the craft grid arrow, its X position, and the crafting
grid's result slot X position into style table entries.
Includes a few public helper functions to do most of the work:
`ui.single_slot(xpos, ypos, bright)`
Does just what it sounds like: it returns a single slot image.
`xpos` and `ypos` are normal coordinates in slots, as you'd use in
`image[]` element. `bright` is a flag that switches to the brighter
version of the slot image.
`ui.make_trash_slot(xpos, ypos)`
Creates a single slot, with a one-item `list[]` and a trash can icon
overlay.
`ui.make_inv_img_grid(xpos, ypos, width, height, bright)`
Generates a `width` by `height` grid of slot images, using the
single_slot function above, starting at (`xpos`,`ypos`) for the
top-left. Position is as in any `image[]` element, and dimensions
are in integer numbers of slots (so 8,4 would be a standard inventory).
`bright` is as above.
All three return a string that can be directly inserted into a formspec.
2021-03-08 18:14:31 +01:00
|
|
|
|
|
|
|
style.standard_inv_bg = ui.make_inv_img_grid(style.std_inv_x, style.std_inv_y, 8, 1, true)..
|
2021-03-09 20:25:14 +01:00
|
|
|
ui.make_inv_img_grid(style.std_inv_x, style.std_inv_y + ui.imgscale, 8, 3)
|
|
|
|
|
|
|
|
style.craft_grid = table.concat({
|
|
|
|
ui.make_inv_img_grid(style.craft_x, style.craft_y, 3, 3),
|
|
|
|
ui.single_slot(style.craft_x + ui.imgscale*4, style.craft_y), -- the craft result slot
|
|
|
|
string.format("image[%f,%f;%f,%f;ui_crafting_arrow.png]",
|
|
|
|
style.craft_arrow_x, style.craft_y, ui.imgscale, ui.imgscale),
|
|
|
|
string.format("list[current_player;craft;%f,%f;3,3;]",
|
|
|
|
style.craft_x + ui.list_img_offset, style.craft_y + ui.list_img_offset),
|
|
|
|
string.format("list[current_player;craftpreview;%f,%f;1,1;]",
|
|
|
|
style.craftresult_x + ui.list_img_offset, style.craft_y + ui.list_img_offset)
|
|
|
|
})
|
2021-03-08 10:56:52 +01:00
|
|
|
end
|
|
|
|
|
2013-09-29 00:15:37 +02:00
|
|
|
-- Disable default creative inventory
|
2016-02-12 03:19:03 +01:00
|
|
|
local creative = rawget(_G, "creative") or rawget(_G, "creative_inventory")
|
|
|
|
if creative then
|
2016-02-08 13:07:23 +01:00
|
|
|
function creative.set_creative_formspec(player, start_i, pagenum)
|
2013-09-29 00:15:37 +02:00
|
|
|
return
|
2013-09-21 21:40:20 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-05 22:57:23 +02:00
|
|
|
-- Disable sfinv inventory
|
|
|
|
local sfinv = rawget(_G, "sfinv")
|
|
|
|
if sfinv then
|
|
|
|
sfinv.enabled = false
|
|
|
|
end
|
|
|
|
|
2014-05-12 04:00:32 +02:00
|
|
|
dofile(modpath.."/group.lua")
|
2013-09-29 00:15:37 +02:00
|
|
|
dofile(modpath.."/internal.lua")
|
|
|
|
dofile(modpath.."/callbacks.lua")
|
|
|
|
dofile(modpath.."/register.lua")
|
2016-11-28 20:46:42 +01:00
|
|
|
|
2014-05-26 05:41:40 +02:00
|
|
|
dofile(modpath.."/item_names.lua")
|
2022-02-26 11:36:56 +01:00
|
|
|
dofile(modpath.."/legacy.lua") -- mod compatibility
|