mirror of
https://github.com/minetest-mods/unified_inventory.git
synced 2024-09-12 08:18:28 +02:00
use local "ui" to reference "unified_inventory", where practical
(makes code shorter, easier to read and write)
This commit is contained in:
parent
d52303a89e
commit
55692900f9
91
api.lua
91
api.lua
@ -1,5 +1,6 @@
|
|||||||
local S = minetest.get_translator("unified_inventory")
|
local S = minetest.get_translator("unified_inventory")
|
||||||
local F = minetest.formspec_escape
|
local F = minetest.formspec_escape
|
||||||
|
local ui = unified_inventory
|
||||||
|
|
||||||
-- Create detached creative inventory after loading all mods
|
-- Create detached creative inventory after loading all mods
|
||||||
minetest.after(0.01, function()
|
minetest.after(0.01, function()
|
||||||
@ -8,12 +9,12 @@ minetest.after(0.01, function()
|
|||||||
if not rev_aliases[target] then rev_aliases[target] = {} end
|
if not rev_aliases[target] then rev_aliases[target] = {} end
|
||||||
table.insert(rev_aliases[target], source)
|
table.insert(rev_aliases[target], source)
|
||||||
end
|
end
|
||||||
unified_inventory.items_list = {}
|
ui.items_list = {}
|
||||||
for name, def in pairs(minetest.registered_items) do
|
for name, def in pairs(minetest.registered_items) do
|
||||||
if (not def.groups.not_in_creative_inventory or
|
if (not def.groups.not_in_creative_inventory or
|
||||||
def.groups.not_in_creative_inventory == 0) and
|
def.groups.not_in_creative_inventory == 0) and
|
||||||
def.description and def.description ~= "" then
|
def.description and def.description ~= "" then
|
||||||
table.insert(unified_inventory.items_list, name)
|
table.insert(ui.items_list, name)
|
||||||
local all_names = rev_aliases[name] or {}
|
local all_names = rev_aliases[name] or {}
|
||||||
table.insert(all_names, name)
|
table.insert(all_names, name)
|
||||||
for _, player_name in ipairs(all_names) do
|
for _, player_name in ipairs(all_names) do
|
||||||
@ -26,30 +27,30 @@ minetest.after(0.01, function()
|
|||||||
for _,chk in pairs(recipe.items) do
|
for _,chk in pairs(recipe.items) do
|
||||||
local groupchk = string.find(chk, "group:")
|
local groupchk = string.find(chk, "group:")
|
||||||
if (not groupchk and not minetest.registered_items[chk])
|
if (not groupchk and not minetest.registered_items[chk])
|
||||||
or (groupchk and not unified_inventory.get_group_item(string.gsub(chk, "group:", "")).item)
|
or (groupchk and not ui.get_group_item(string.gsub(chk, "group:", "")).item)
|
||||||
or minetest.get_item_group(chk, "not_in_craft_guide") ~= 0 then
|
or minetest.get_item_group(chk, "not_in_craft_guide") ~= 0 then
|
||||||
unknowns = true
|
unknowns = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not unknowns then
|
if not unknowns then
|
||||||
unified_inventory.register_craft(recipe)
|
ui.register_craft(recipe)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(unified_inventory.items_list)
|
table.sort(ui.items_list)
|
||||||
unified_inventory.items_list_size = #unified_inventory.items_list
|
ui.items_list_size = #ui.items_list
|
||||||
print("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
|
print("Unified Inventory. inventory size: "..ui.items_list_size)
|
||||||
for _, name in ipairs(unified_inventory.items_list) do
|
for _, name in ipairs(ui.items_list) do
|
||||||
local def = minetest.registered_items[name]
|
local def = minetest.registered_items[name]
|
||||||
-- Simple drops
|
-- Simple drops
|
||||||
if type(def.drop) == "string" then
|
if type(def.drop) == "string" then
|
||||||
local dstack = ItemStack(def.drop)
|
local dstack = ItemStack(def.drop)
|
||||||
if not dstack:is_empty() and dstack:get_name() ~= name then
|
if not dstack:is_empty() and dstack:get_name() ~= name then
|
||||||
unified_inventory.register_craft({
|
ui.register_craft({
|
||||||
type = "digging",
|
type = "digging",
|
||||||
items = {name},
|
items = {name},
|
||||||
output = def.drop,
|
output = def.drop,
|
||||||
@ -115,7 +116,7 @@ minetest.after(0.01, function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
for itemstring, count in pairs(drop_guaranteed) do
|
for itemstring, count in pairs(drop_guaranteed) do
|
||||||
unified_inventory.register_craft({
|
ui.register_craft({
|
||||||
type = "digging",
|
type = "digging",
|
||||||
items = {name},
|
items = {name},
|
||||||
output = itemstring .. " " .. count,
|
output = itemstring .. " " .. count,
|
||||||
@ -123,7 +124,7 @@ minetest.after(0.01, function()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
for itemstring, count in pairs(drop_maybe) do
|
for itemstring, count in pairs(drop_maybe) do
|
||||||
unified_inventory.register_craft({
|
ui.register_craft({
|
||||||
type = "digging_chance",
|
type = "digging_chance",
|
||||||
items = {name},
|
items = {name},
|
||||||
output = itemstring .. " " .. count,
|
output = itemstring .. " " .. count,
|
||||||
@ -132,22 +133,22 @@ minetest.after(0.01, function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _, recipes in pairs(unified_inventory.crafts_for.recipe) do
|
for _, recipes in pairs(ui.crafts_for.recipe) do
|
||||||
for _, recipe in ipairs(recipes) do
|
for _, recipe in ipairs(recipes) do
|
||||||
local ingredient_items = {}
|
local ingredient_items = {}
|
||||||
for _, spec in pairs(recipe.items) do
|
for _, spec in pairs(recipe.items) do
|
||||||
local matches_spec = unified_inventory.canonical_item_spec_matcher(spec)
|
local matches_spec = ui.canonical_item_spec_matcher(spec)
|
||||||
for _, name in ipairs(unified_inventory.items_list) do
|
for _, name in ipairs(ui.items_list) do
|
||||||
if matches_spec(name) then
|
if matches_spec(name) then
|
||||||
ingredient_items[name] = true
|
ingredient_items[name] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for name, _ in pairs(ingredient_items) do
|
for name, _ in pairs(ingredient_items) do
|
||||||
if unified_inventory.crafts_for.usage[name] == nil then
|
if ui.crafts_for.usage[name] == nil then
|
||||||
unified_inventory.crafts_for.usage[name] = {}
|
ui.crafts_for.usage[name] = {}
|
||||||
end
|
end
|
||||||
table.insert(unified_inventory.crafts_for.usage[name], recipe)
|
table.insert(ui.crafts_for.usage[name], recipe)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -156,9 +157,9 @@ end)
|
|||||||
|
|
||||||
-- load_home
|
-- load_home
|
||||||
local function load_home()
|
local function load_home()
|
||||||
local input = io.open(unified_inventory.home_filename, "r")
|
local input = io.open(ui.home_filename, "r")
|
||||||
if not input then
|
if not input then
|
||||||
unified_inventory.home_pos = {}
|
ui.home_pos = {}
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
while true do
|
while true do
|
||||||
@ -167,25 +168,25 @@ local function load_home()
|
|||||||
local y = input:read("*n")
|
local y = input:read("*n")
|
||||||
local z = input:read("*n")
|
local z = input:read("*n")
|
||||||
local name = input:read("*l")
|
local name = input:read("*l")
|
||||||
unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z}
|
ui.home_pos[name:sub(2)] = {x = x, y = y, z = z}
|
||||||
end
|
end
|
||||||
io.close(input)
|
io.close(input)
|
||||||
end
|
end
|
||||||
load_home()
|
load_home()
|
||||||
|
|
||||||
function unified_inventory.set_home(player, pos)
|
function ui.set_home(player, pos)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
unified_inventory.home_pos[player_name] = vector.round(pos)
|
ui.home_pos[player_name] = vector.round(pos)
|
||||||
-- save the home data from the table to the file
|
-- save the home data from the table to the file
|
||||||
local output = io.open(unified_inventory.home_filename, "w")
|
local output = io.open(ui.home_filename, "w")
|
||||||
for k, v in pairs(unified_inventory.home_pos) do
|
for k, v in pairs(ui.home_pos) do
|
||||||
output:write(v.x.." "..v.y.." "..v.z.." "..k.."\n")
|
output:write(v.x.." "..v.y.." "..v.z.." "..k.."\n")
|
||||||
end
|
end
|
||||||
io.close(output)
|
io.close(output)
|
||||||
end
|
end
|
||||||
|
|
||||||
function unified_inventory.go_home(player)
|
function ui.go_home(player)
|
||||||
local pos = unified_inventory.home_pos[player:get_player_name()]
|
local pos = ui.home_pos[player:get_player_name()]
|
||||||
if pos then
|
if pos then
|
||||||
player:set_pos(pos)
|
player:set_pos(pos)
|
||||||
return true
|
return true
|
||||||
@ -194,7 +195,7 @@ function unified_inventory.go_home(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- register_craft
|
-- register_craft
|
||||||
function unified_inventory.register_craft(options)
|
function ui.register_craft(options)
|
||||||
if not options.output then
|
if not options.output then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -205,10 +206,10 @@ function unified_inventory.register_craft(options)
|
|||||||
if options.type == "normal" and options.width == 0 then
|
if options.type == "normal" and options.width == 0 then
|
||||||
options = { type = "shapeless", items = options.items, output = options.output, width = 0 }
|
options = { type = "shapeless", items = options.items, output = options.output, width = 0 }
|
||||||
end
|
end
|
||||||
if not unified_inventory.crafts_for.recipe[itemstack:get_name()] then
|
if not ui.crafts_for.recipe[itemstack:get_name()] then
|
||||||
unified_inventory.crafts_for.recipe[itemstack:get_name()] = {}
|
ui.crafts_for.recipe[itemstack:get_name()] = {}
|
||||||
end
|
end
|
||||||
table.insert(unified_inventory.crafts_for.recipe[itemstack:get_name()],options)
|
table.insert(ui.crafts_for.recipe[itemstack:get_name()],options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -219,7 +220,7 @@ local craft_type_defaults = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function unified_inventory.craft_type_defaults(name, options)
|
function ui.craft_type_defaults(name, options)
|
||||||
if not options.description then
|
if not options.description then
|
||||||
options.description = name
|
options.description = name
|
||||||
end
|
end
|
||||||
@ -228,13 +229,13 @@ function unified_inventory.craft_type_defaults(name, options)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function unified_inventory.register_craft_type(name, options)
|
function ui.register_craft_type(name, options)
|
||||||
unified_inventory.registered_craft_types[name] =
|
ui.registered_craft_types[name] =
|
||||||
unified_inventory.craft_type_defaults(name, options)
|
ui.craft_type_defaults(name, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
unified_inventory.register_craft_type("normal", {
|
ui.register_craft_type("normal", {
|
||||||
description = F(S("Crafting")),
|
description = F(S("Crafting")),
|
||||||
icon = "ui_craftgrid_icon.png",
|
icon = "ui_craftgrid_icon.png",
|
||||||
width = 3,
|
width = 3,
|
||||||
@ -250,7 +251,7 @@ unified_inventory.register_craft_type("normal", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
unified_inventory.register_craft_type("shapeless", {
|
ui.register_craft_type("shapeless", {
|
||||||
description = F(S("Mixing")),
|
description = F(S("Mixing")),
|
||||||
icon = "ui_craftgrid_icon.png",
|
icon = "ui_craftgrid_icon.png",
|
||||||
width = 3,
|
width = 3,
|
||||||
@ -265,7 +266,7 @@ unified_inventory.register_craft_type("shapeless", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
unified_inventory.register_craft_type("cooking", {
|
ui.register_craft_type("cooking", {
|
||||||
description = F(S("Cooking")),
|
description = F(S("Cooking")),
|
||||||
icon = "default_furnace_front.png",
|
icon = "default_furnace_front.png",
|
||||||
width = 1,
|
width = 1,
|
||||||
@ -273,37 +274,37 @@ unified_inventory.register_craft_type("cooking", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
unified_inventory.register_craft_type("digging", {
|
ui.register_craft_type("digging", {
|
||||||
description = F(S("Digging")),
|
description = F(S("Digging")),
|
||||||
icon = "default_tool_steelpick.png",
|
icon = "default_tool_steelpick.png",
|
||||||
width = 1,
|
width = 1,
|
||||||
height = 1,
|
height = 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
unified_inventory.register_craft_type("digging_chance", {
|
ui.register_craft_type("digging_chance", {
|
||||||
description = "Digging (by chance)",
|
description = "Digging (by chance)",
|
||||||
icon = "default_tool_steelpick.png^[transformFY.png",
|
icon = "default_tool_steelpick.png^[transformFY.png",
|
||||||
width = 1,
|
width = 1,
|
||||||
height = 1,
|
height = 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
function unified_inventory.register_page(name, def)
|
function ui.register_page(name, def)
|
||||||
unified_inventory.pages[name] = def
|
ui.pages[name] = def
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function unified_inventory.register_button(name, def)
|
function ui.register_button(name, def)
|
||||||
if not def.action then
|
if not def.action then
|
||||||
def.action = function(player)
|
def.action = function(player)
|
||||||
unified_inventory.set_inventory_formspec(player, name)
|
ui.set_inventory_formspec(player, name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def.name = name
|
def.name = name
|
||||||
table.insert(unified_inventory.buttons, def)
|
table.insert(ui.buttons, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function unified_inventory.is_creative(playername)
|
function ui.is_creative(playername)
|
||||||
return minetest.check_player_privs(playername, {creative=true})
|
return minetest.check_player_privs(playername, {creative=true})
|
||||||
or minetest.settings:get_bool("creative_mode")
|
or minetest.settings:get_bool("creative_mode")
|
||||||
end
|
end
|
||||||
|
31
bags.lua
31
bags.lua
@ -7,15 +7,16 @@ License: GPLv3
|
|||||||
|
|
||||||
local S = minetest.get_translator("unified_inventory")
|
local S = minetest.get_translator("unified_inventory")
|
||||||
local F = minetest.formspec_escape
|
local F = minetest.formspec_escape
|
||||||
local bags_inv_bg_prefix = "image[0.3,1.5;"..(unified_inventory.imgscale*8)..","
|
local ui = unified_inventory
|
||||||
|
local bags_inv_bg_prefix = "image[0.3,1.5;"..(ui.imgscale*8)..","
|
||||||
|
|
||||||
unified_inventory.register_page("bags", {
|
ui.register_page("bags", {
|
||||||
get_formspec = function(player)
|
get_formspec = function(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
return { formspec = table.concat({
|
return { formspec = table.concat({
|
||||||
unified_inventory.style_full.standard_inv_bg,
|
ui.style_full.standard_inv_bg,
|
||||||
bags_inv_bg_prefix..unified_inventory.imgscale..";ui_bags_header.png]",
|
bags_inv_bg_prefix..ui.imgscale..";ui_bags_header.png]",
|
||||||
"label["..unified_inventory.style_full.form_header_x..","..unified_inventory.style_full.form_header_y..";" .. F(S("Bags")) .. "]",
|
"label["..ui.style_full.form_header_x..","..ui.style_full.form_header_y..";" .. F(S("Bags")) .. "]",
|
||||||
"button[0.6125,2.75;1.875,0.75;bag1;" .. F(S("Bag @1", 1)) .. "]",
|
"button[0.6125,2.75;1.875,0.75;bag1;" .. F(S("Bag @1", 1)) .. "]",
|
||||||
"button[3.1125,2.75;1.875,0.75;bag2;" .. F(S("Bag @1", 2)) .. "]",
|
"button[3.1125,2.75;1.875,0.75;bag2;" .. F(S("Bag @1", 2)) .. "]",
|
||||||
"button[5.6125,2.75;1.875,0.75;bag3;" .. F(S("Bag @1", 3)) .. "]",
|
"button[5.6125,2.75;1.875,0.75;bag3;" .. F(S("Bag @1", 3)) .. "]",
|
||||||
@ -29,7 +30,7 @@ unified_inventory.register_page("bags", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
unified_inventory.register_button("bags", {
|
ui.register_button("bags", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "ui_bags_icon.png",
|
image = "ui_bags_icon.png",
|
||||||
tooltip = S("Bags"),
|
tooltip = S("Bags"),
|
||||||
@ -44,12 +45,12 @@ local function get_player_bag_stack(player, i)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for bag_i = 1, 4 do
|
for bag_i = 1, 4 do
|
||||||
unified_inventory.register_page("bag" .. bag_i, {
|
ui.register_page("bag" .. bag_i, {
|
||||||
get_formspec = function(player)
|
get_formspec = function(player)
|
||||||
local stack = get_player_bag_stack(player, bag_i)
|
local stack = get_player_bag_stack(player, bag_i)
|
||||||
local image = stack:get_definition().inventory_image
|
local image = stack:get_definition().inventory_image
|
||||||
local fs = {
|
local fs = {
|
||||||
unified_inventory.style_full.standard_inv_bg,
|
ui.style_full.standard_inv_bg,
|
||||||
"image[9.2,0.4;1,1;" .. image .. "]",
|
"image[9.2,0.4;1,1;" .. image .. "]",
|
||||||
"label[0.3,0.65;" .. F(S("Bag @1", bag_i)) .. "]",
|
"label[0.3,0.65;" .. F(S("Bag @1", bag_i)) .. "]",
|
||||||
"listcolors[#00000000;#00000000]",
|
"listcolors[#00000000;#00000000]",
|
||||||
@ -57,20 +58,20 @@ for bag_i = 1, 4 do
|
|||||||
}
|
}
|
||||||
local slots = stack:get_definition().groups.bagslots
|
local slots = stack:get_definition().groups.bagslots
|
||||||
if slots == 8 then
|
if slots == 8 then
|
||||||
fs[#fs + 1] = bags_inv_bg_prefix..unified_inventory.imgscale..";ui_bags_inv_small.png]"
|
fs[#fs + 1] = bags_inv_bg_prefix..ui.imgscale..";ui_bags_inv_small.png]"
|
||||||
elseif slots == 16 then
|
elseif slots == 16 then
|
||||||
fs[#fs + 1] = bags_inv_bg_prefix..(unified_inventory.imgscale*2)..";ui_bags_inv_medium.png]"
|
fs[#fs + 1] = bags_inv_bg_prefix..(ui.imgscale*2)..";ui_bags_inv_medium.png]"
|
||||||
elseif slots == 24 then
|
elseif slots == 24 then
|
||||||
fs[#fs + 1] = bags_inv_bg_prefix..(unified_inventory.imgscale*3)..";ui_bags_inv_large.png]"
|
fs[#fs + 1] = bags_inv_bg_prefix..(ui.imgscale*3)..";ui_bags_inv_large.png]"
|
||||||
end
|
end
|
||||||
fs[#fs + 1] = "list[current_player;bag" .. bag_i .. "contents;0.45,1.65;8,3;]"
|
fs[#fs + 1] = "list[current_player;bag" .. bag_i .. "contents;0.45,1.65;8,3;]"
|
||||||
fs[#fs + 1] = "listring[current_name;bag" .. bag_i .. "contents]"
|
fs[#fs + 1] = "listring[current_name;bag" .. bag_i .. "contents]"
|
||||||
|
|
||||||
local player_name = player:get_player_name() -- For if statement.
|
local player_name = player:get_player_name() -- For if statement.
|
||||||
if unified_inventory.trash_enabled
|
if ui.trash_enabled
|
||||||
or unified_inventory.is_creative(player_name)
|
or ui.is_creative(player_name)
|
||||||
or minetest.get_player_privs(player_name).give then
|
or minetest.get_player_privs(player_name).give then
|
||||||
fs[#fs + 1] = "image[7.8,0.25;"..unified_inventory.imgscale..","..unified_inventory.imgscale..";ui_trash_slot.png]"
|
fs[#fs + 1] = "image[7.8,0.25;"..ui.imgscale..","..ui.imgscale..";ui_trash_slot.png]"
|
||||||
.. "list[detached:trash;main;7.95,0.25;1,1;]"
|
.. "list[detached:trash;main;7.95,0.25;1,1;]"
|
||||||
end
|
end
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
@ -107,7 +108,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if not stack:get_definition().groups.bagslots then
|
if not stack:get_definition().groups.bagslots then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
unified_inventory.set_inventory_formspec(player, "bag" .. i)
|
ui.set_inventory_formspec(player, "bag" .. i)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
99
internal.lua
99
internal.lua
@ -1,5 +1,6 @@
|
|||||||
local S = minetest.get_translator("unified_inventory")
|
local S = minetest.get_translator("unified_inventory")
|
||||||
local F = minetest.formspec_escape
|
local F = minetest.formspec_escape
|
||||||
|
local ui = unified_inventory
|
||||||
|
|
||||||
-- This pair of encoding functions is used where variable text must go in
|
-- This pair of encoding functions is used where variable text must go in
|
||||||
-- button names, where the text might contain formspec metacharacters.
|
-- button names, where the text might contain formspec metacharacters.
|
||||||
@ -10,44 +11,44 @@ local F = minetest.formspec_escape
|
|||||||
-- fixed some day we don't want to rely on it. So for safety we apply
|
-- fixed some day we don't want to rely on it. So for safety we apply
|
||||||
-- an encoding that avoids all formspec metacharacters.
|
-- an encoding that avoids all formspec metacharacters.
|
||||||
|
|
||||||
function unified_inventory.mangle_for_formspec(str)
|
function ui.mangle_for_formspec(str)
|
||||||
return string.gsub(str, "([^A-Za-z0-9])", function (c) return string.format("_%d_", string.byte(c)) end)
|
return string.gsub(str, "([^A-Za-z0-9])", function (c) return string.format("_%d_", string.byte(c)) end)
|
||||||
end
|
end
|
||||||
function unified_inventory.demangle_for_formspec(str)
|
function ui.demangle_for_formspec(str)
|
||||||
return string.gsub(str, "_([0-9]+)_", function (v) return string.char(v) end)
|
return string.gsub(str, "_([0-9]+)_", function (v) return string.char(v) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function unified_inventory.get_per_player_formspec(player_name)
|
function ui.get_per_player_formspec(player_name)
|
||||||
local lite = unified_inventory.lite_mode and not minetest.check_player_privs(player_name, {ui_full=true})
|
local lite = ui.lite_mode and not minetest.check_player_privs(player_name, {ui_full=true})
|
||||||
|
|
||||||
local ui = unified_inventory.style_full
|
local style = ui.style_full
|
||||||
|
|
||||||
if lite then
|
if lite then
|
||||||
ui = unified_inventory.style_lite
|
style = ui.style_lite
|
||||||
end
|
end
|
||||||
|
|
||||||
ui.items_per_page = ui.pagecols * ui.pagerows
|
style.items_per_page = style.pagecols * style.pagerows
|
||||||
ui.standard_inv = string.format("list[current_player;main;%f,%f;8,4;]",
|
style.standard_inv = string.format("list[current_player;main;%f,%f;8,4;]",
|
||||||
ui.std_inv_x+0.15, ui.std_inv_y+0.15)
|
style.std_inv_x+0.15, style.std_inv_y+0.15)
|
||||||
|
|
||||||
ui.standard_inv_bg = string.format("image[%f,%f;%f,%f;ui_main_inventory.png]",
|
style.standard_inv_bg = string.format("image[%f,%f;%f,%f;ui_main_inventory.png]",
|
||||||
ui.std_inv_x, ui.std_inv_y,
|
style.std_inv_x, style.std_inv_y,
|
||||||
unified_inventory.imgscale*8, unified_inventory.imgscale*4)
|
ui.imgscale*8, ui.imgscale*4)
|
||||||
return ui, lite
|
return style, lite
|
||||||
end
|
end
|
||||||
|
|
||||||
function unified_inventory.get_formspec(player, page)
|
function ui.get_formspec(player, page)
|
||||||
|
|
||||||
if not player then
|
if not player then
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local ui_peruser,draw_lite_mode = unified_inventory.get_per_player_formspec(player_name)
|
local ui_peruser,draw_lite_mode = ui.get_per_player_formspec(player_name)
|
||||||
|
|
||||||
unified_inventory.current_page[player_name] = page
|
ui.current_page[player_name] = page
|
||||||
local pagedef = unified_inventory.pages[page]
|
local pagedef = ui.pages[page]
|
||||||
|
|
||||||
if not pagedef then
|
if not pagedef then
|
||||||
return "" -- Invalid page name
|
return "" -- Invalid page name
|
||||||
@ -56,22 +57,22 @@ function unified_inventory.get_formspec(player, page)
|
|||||||
local formspec = {
|
local formspec = {
|
||||||
"formspec_version[4]size[17.75,12.25]",
|
"formspec_version[4]size[17.75,12.25]",
|
||||||
pagedef.formspec_prepend and "" or "no_prepend[]",
|
pagedef.formspec_prepend and "" or "no_prepend[]",
|
||||||
unified_inventory.standard_background -- Background
|
ui.standard_background -- Background
|
||||||
}
|
}
|
||||||
local n = 4
|
local n = 4
|
||||||
|
|
||||||
if draw_lite_mode then
|
if draw_lite_mode then
|
||||||
formspec[1] = "formspec_version[4]size[14,9.75]"
|
formspec[1] = "formspec_version[4]size[14,9.75]"
|
||||||
formspec[3] = unified_inventory.standard_background
|
formspec[3] = ui.standard_background
|
||||||
end
|
end
|
||||||
|
|
||||||
if unified_inventory.is_creative(player_name)
|
if ui.is_creative(player_name)
|
||||||
and page == "craft" then -- add the "Refill" slot.
|
and page == "craft" then -- add the "Refill" slot.
|
||||||
formspec[n] = "image["..(ui_peruser.craft_x-2.5)..","..(ui_peruser.craft_y+2.5)..";"..unified_inventory.imgscale..","..unified_inventory.imgscale..";ui_single_slot.png]"
|
formspec[n] = "image["..(ui_peruser.craft_x-2.5)..","..(ui_peruser.craft_y+2.5)..";"..ui.imgscale..","..ui.imgscale..";ui_single_slot.png]"
|
||||||
n = n+1
|
n = n+1
|
||||||
end
|
end
|
||||||
|
|
||||||
local perplayer_formspec = unified_inventory.get_per_player_formspec(player_name)
|
local perplayer_formspec = ui.get_per_player_formspec(player_name)
|
||||||
local fsdata = pagedef.get_formspec(player, perplayer_formspec)
|
local fsdata = pagedef.get_formspec(player, perplayer_formspec)
|
||||||
|
|
||||||
formspec[n] = fsdata.formspec
|
formspec[n] = fsdata.formspec
|
||||||
@ -84,7 +85,7 @@ function unified_inventory.get_formspec(player, page)
|
|||||||
|
|
||||||
local filtered_inv_buttons = {}
|
local filtered_inv_buttons = {}
|
||||||
|
|
||||||
for i, def in pairs(unified_inventory.buttons) do
|
for i, def in pairs(ui.buttons) do
|
||||||
if not (draw_lite_mode and def.hide_lite) then
|
if not (draw_lite_mode and def.hide_lite) then
|
||||||
table.insert(filtered_inv_buttons, def)
|
table.insert(filtered_inv_buttons, def)
|
||||||
end
|
end
|
||||||
@ -136,7 +137,7 @@ function unified_inventory.get_formspec(player, page)
|
|||||||
ui_peruser.page_buttons_y..";"..
|
ui_peruser.page_buttons_y..";"..
|
||||||
(ui_peruser.searchwidth - 0.1)..","..
|
(ui_peruser.searchwidth - 0.1)..","..
|
||||||
ui_peruser.btn_size..";searchbox;;"..
|
ui_peruser.btn_size..";searchbox;;"..
|
||||||
F(unified_inventory.current_searchbox[player_name]) .. "]"
|
F(ui.current_searchbox[player_name]) .. "]"
|
||||||
formspec[n+2] = "image_button["..(ui_peruser.page_buttons_x + ui_peruser.searchwidth)..","..
|
formspec[n+2] = "image_button["..(ui_peruser.page_buttons_x + ui_peruser.searchwidth)..","..
|
||||||
ui_peruser.page_buttons_y..";"..
|
ui_peruser.page_buttons_y..";"..
|
||||||
ui_peruser.btn_size..","..ui_peruser.btn_size..
|
ui_peruser.btn_size..","..ui_peruser.btn_size..
|
||||||
@ -185,23 +186,23 @@ function unified_inventory.get_formspec(player, page)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Items list
|
-- Items list
|
||||||
if #unified_inventory.filtered_items_list[player_name] == 0 then
|
if #ui.filtered_items_list[player_name] == 0 then
|
||||||
formspec[n] = "label["..ui_peruser.page_x..","..(ui_peruser.page_y+0.15)..";" .. F(no_matches) .. "]"
|
formspec[n] = "label["..ui_peruser.page_x..","..(ui_peruser.page_y+0.15)..";" .. F(no_matches) .. "]"
|
||||||
else
|
else
|
||||||
local dir = unified_inventory.active_search_direction[player_name]
|
local dir = ui.active_search_direction[player_name]
|
||||||
local list_index = unified_inventory.current_index[player_name]
|
local list_index = ui.current_index[player_name]
|
||||||
local page2 = math.floor(list_index / (ui_peruser.items_per_page) + 1)
|
local page2 = math.floor(list_index / (ui_peruser.items_per_page) + 1)
|
||||||
local pagemax = math.floor(
|
local pagemax = math.floor(
|
||||||
(#unified_inventory.filtered_items_list[player_name] - 1)
|
(#ui.filtered_items_list[player_name] - 1)
|
||||||
/ (ui_peruser.items_per_page) + 1)
|
/ (ui_peruser.items_per_page) + 1)
|
||||||
for y = 0, ui_peruser.pagerows - 1 do
|
for y = 0, ui_peruser.pagerows - 1 do
|
||||||
for x = 0, ui_peruser.pagecols - 1 do
|
for x = 0, ui_peruser.pagecols - 1 do
|
||||||
local name = unified_inventory.filtered_items_list[player_name][list_index]
|
local name = ui.filtered_items_list[player_name][list_index]
|
||||||
local item = minetest.registered_items[name]
|
local item = minetest.registered_items[name]
|
||||||
if item then
|
if item then
|
||||||
-- Clicked on current item: Flip crafting direction
|
-- Clicked on current item: Flip crafting direction
|
||||||
if name == unified_inventory.current_item[player_name] then
|
if name == ui.current_item[player_name] then
|
||||||
local cdir = unified_inventory.current_craft_direction[player_name]
|
local cdir = ui.current_craft_direction[player_name]
|
||||||
if cdir == "recipe" then
|
if cdir == "recipe" then
|
||||||
dir = "usage"
|
dir = "usage"
|
||||||
elseif cdir == "usage" then
|
elseif cdir == "usage" then
|
||||||
@ -209,11 +210,11 @@ function unified_inventory.get_formspec(player, page)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Default: use active search direction by default
|
-- Default: use active search direction by default
|
||||||
dir = unified_inventory.active_search_direction[player_name]
|
dir = ui.active_search_direction[player_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
local button_name = "item_button_" .. dir .. "_"
|
local button_name = "item_button_" .. dir .. "_"
|
||||||
.. unified_inventory.mangle_for_formspec(name)
|
.. ui.mangle_for_formspec(name)
|
||||||
formspec[n] = ("item_image_button[%f,%f;%f,%f;%s;%s;]"):format(
|
formspec[n] = ("item_image_button[%f,%f;%f,%f;%s;%s;]"):format(
|
||||||
ui_peruser.page_x + x * ui_peruser.btn_spc,
|
ui_peruser.page_x + x * ui_peruser.btn_spc,
|
||||||
ui_peruser.page_y + y * ui_peruser.btn_spc,
|
ui_peruser.page_y + y * ui_peruser.btn_spc,
|
||||||
@ -234,21 +235,21 @@ function unified_inventory.get_formspec(player, page)
|
|||||||
end
|
end
|
||||||
n= n+1
|
n= n+1
|
||||||
|
|
||||||
if unified_inventory.activefilter[player_name] ~= "" then
|
if ui.activefilter[player_name] ~= "" then
|
||||||
formspec[n] = "label["..ui_peruser.page_x..","..(ui_peruser.page_y - 0.65)..";" .. F(S("Filter")) .. ":]"
|
formspec[n] = "label["..ui_peruser.page_x..","..(ui_peruser.page_y - 0.65)..";" .. F(S("Filter")) .. ":]"
|
||||||
formspec[n+1] = "label["..ui_peruser.page_x..","..(ui_peruser.page_y - 0.25)..";"..F(unified_inventory.activefilter[player_name]).."]"
|
formspec[n+1] = "label["..ui_peruser.page_x..","..(ui_peruser.page_y - 0.25)..";"..F(ui.activefilter[player_name]).."]"
|
||||||
end
|
end
|
||||||
return table.concat(formspec, "")
|
return table.concat(formspec, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
function unified_inventory.set_inventory_formspec(player, page)
|
function ui.set_inventory_formspec(player, page)
|
||||||
if player then
|
if player then
|
||||||
player:set_inventory_formspec(unified_inventory.get_formspec(player, page))
|
player:set_inventory_formspec(ui.get_formspec(player, page))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--apply filter to the inventory list (create filtered copy of full one)
|
--apply filter to the inventory list (create filtered copy of full one)
|
||||||
function unified_inventory.apply_filter(player, filter, search_dir)
|
function ui.apply_filter(player, filter, search_dir)
|
||||||
if not player then
|
if not player then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -277,26 +278,26 @@ function unified_inventory.apply_filter(player, filter, search_dir)
|
|||||||
or llocaldesc and string.find(llocaldesc, lfilter, 1, true)
|
or llocaldesc and string.find(llocaldesc, lfilter, 1, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
unified_inventory.filtered_items_list[player_name]={}
|
ui.filtered_items_list[player_name]={}
|
||||||
for name, def in pairs(minetest.registered_items) do
|
for name, def in pairs(minetest.registered_items) do
|
||||||
if (not def.groups.not_in_creative_inventory
|
if (not def.groups.not_in_creative_inventory
|
||||||
or def.groups.not_in_creative_inventory == 0)
|
or def.groups.not_in_creative_inventory == 0)
|
||||||
and def.description
|
and def.description
|
||||||
and def.description ~= ""
|
and def.description ~= ""
|
||||||
and ffilter(name, def) then
|
and ffilter(name, def) then
|
||||||
table.insert(unified_inventory.filtered_items_list[player_name], name)
|
table.insert(ui.filtered_items_list[player_name], name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(unified_inventory.filtered_items_list[player_name])
|
table.sort(ui.filtered_items_list[player_name])
|
||||||
unified_inventory.filtered_items_list_size[player_name] = #unified_inventory.filtered_items_list[player_name]
|
ui.filtered_items_list_size[player_name] = #ui.filtered_items_list[player_name]
|
||||||
unified_inventory.current_index[player_name] = 1
|
ui.current_index[player_name] = 1
|
||||||
unified_inventory.activefilter[player_name] = filter
|
ui.activefilter[player_name] = filter
|
||||||
unified_inventory.active_search_direction[player_name] = search_dir
|
ui.active_search_direction[player_name] = search_dir
|
||||||
unified_inventory.set_inventory_formspec(player,
|
ui.set_inventory_formspec(player,
|
||||||
unified_inventory.current_page[player_name])
|
ui.current_page[player_name])
|
||||||
end
|
end
|
||||||
|
|
||||||
function unified_inventory.items_in_group(groups)
|
function ui.items_in_group(groups)
|
||||||
local items = {}
|
local items = {}
|
||||||
for name, item in pairs(minetest.registered_items) do
|
for name, item in pairs(minetest.registered_items) do
|
||||||
for _, group in pairs(groups:split(',')) do
|
for _, group in pairs(groups:split(',')) do
|
||||||
@ -308,7 +309,7 @@ function unified_inventory.items_in_group(groups)
|
|||||||
return items
|
return items
|
||||||
end
|
end
|
||||||
|
|
||||||
function unified_inventory.sort_inventory(inv)
|
function ui.sort_inventory(inv)
|
||||||
local inlist = inv:get_list("main")
|
local inlist = inv:get_list("main")
|
||||||
local typecnt = {}
|
local typecnt = {}
|
||||||
local typekeys = {}
|
local typekeys = {}
|
||||||
|
85
register.lua
85
register.lua
@ -1,6 +1,7 @@
|
|||||||
local S = minetest.get_translator("unified_inventory")
|
local S = minetest.get_translator("unified_inventory")
|
||||||
local NS = function(s) return s end
|
local NS = function(s) return s end
|
||||||
local F = minetest.formspec_escape
|
local F = minetest.formspec_escape
|
||||||
|
local ui = unified_inventory
|
||||||
|
|
||||||
minetest.register_privilege("creative", {
|
minetest.register_privilege("creative", {
|
||||||
description = S("Can use the creative inventory"),
|
description = S("Can use the creative inventory"),
|
||||||
@ -14,7 +15,7 @@ minetest.register_privilege("ui_full", {
|
|||||||
|
|
||||||
local trash = minetest.create_detached_inventory("trash", {
|
local trash = minetest.create_detached_inventory("trash", {
|
||||||
--allow_put = function(inv, listname, index, stack, player)
|
--allow_put = function(inv, listname, index, stack, player)
|
||||||
-- if unified_inventory.is_creative(player:get_player_name()) then
|
-- if ui.is_creative(player:get_player_name()) then
|
||||||
-- return stack:get_count()
|
-- return stack:get_count()
|
||||||
-- else
|
-- else
|
||||||
-- return 0
|
-- return 0
|
||||||
@ -28,19 +29,19 @@ local trash = minetest.create_detached_inventory("trash", {
|
|||||||
})
|
})
|
||||||
trash:set_size("main", 1)
|
trash:set_size("main", 1)
|
||||||
|
|
||||||
unified_inventory.register_button("craft", {
|
ui.register_button("craft", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "ui_craft_icon.png",
|
image = "ui_craft_icon.png",
|
||||||
tooltip = S("Crafting Grid")
|
tooltip = S("Crafting Grid")
|
||||||
})
|
})
|
||||||
|
|
||||||
unified_inventory.register_button("craftguide", {
|
ui.register_button("craftguide", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "ui_craftguide_icon.png",
|
image = "ui_craftguide_icon.png",
|
||||||
tooltip = S("Crafting Guide")
|
tooltip = S("Crafting Guide")
|
||||||
})
|
})
|
||||||
|
|
||||||
unified_inventory.register_button("home_gui_set", {
|
ui.register_button("home_gui_set", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "ui_sethome_icon.png",
|
image = "ui_sethome_icon.png",
|
||||||
tooltip = S("Set home position"),
|
tooltip = S("Set home position"),
|
||||||
@ -48,8 +49,8 @@ unified_inventory.register_button("home_gui_set", {
|
|||||||
action = function(player)
|
action = function(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
if minetest.check_player_privs(player_name, {home=true}) then
|
if minetest.check_player_privs(player_name, {home=true}) then
|
||||||
unified_inventory.set_home(player, player:get_pos())
|
ui.set_home(player, player:get_pos())
|
||||||
local home = unified_inventory.home_pos[player_name]
|
local home = ui.home_pos[player_name]
|
||||||
if home ~= nil then
|
if home ~= nil then
|
||||||
minetest.sound_play("dingdong",
|
minetest.sound_play("dingdong",
|
||||||
{to_player=player_name, gain = 1.0})
|
{to_player=player_name, gain = 1.0})
|
||||||
@ -59,7 +60,7 @@ unified_inventory.register_button("home_gui_set", {
|
|||||||
else
|
else
|
||||||
minetest.chat_send_player(player_name,
|
minetest.chat_send_player(player_name,
|
||||||
S("You don't have the \"home\" privilege!"))
|
S("You don't have the \"home\" privilege!"))
|
||||||
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
condition = function(player)
|
condition = function(player)
|
||||||
@ -67,7 +68,7 @@ unified_inventory.register_button("home_gui_set", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
unified_inventory.register_button("home_gui_go", {
|
ui.register_button("home_gui_go", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "ui_gohome_icon.png",
|
image = "ui_gohome_icon.png",
|
||||||
tooltip = S("Go home"),
|
tooltip = S("Go home"),
|
||||||
@ -75,13 +76,13 @@ unified_inventory.register_button("home_gui_go", {
|
|||||||
action = function(player)
|
action = function(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
if minetest.check_player_privs(player_name, {home=true}) then
|
if minetest.check_player_privs(player_name, {home=true}) then
|
||||||
if unified_inventory.go_home(player) then
|
if ui.go_home(player) then
|
||||||
minetest.sound_play("teleport", {to_player = player_name})
|
minetest.sound_play("teleport", {to_player = player_name})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(player_name,
|
minetest.chat_send_player(player_name,
|
||||||
S("You don't have the \"home\" privilege!"))
|
S("You don't have the \"home\" privilege!"))
|
||||||
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
condition = function(player)
|
condition = function(player)
|
||||||
@ -89,7 +90,7 @@ unified_inventory.register_button("home_gui_go", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
unified_inventory.register_button("misc_set_day", {
|
ui.register_button("misc_set_day", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "ui_sun_icon.png",
|
image = "ui_sun_icon.png",
|
||||||
tooltip = S("Set time to day"),
|
tooltip = S("Set time to day"),
|
||||||
@ -105,7 +106,7 @@ unified_inventory.register_button("misc_set_day", {
|
|||||||
else
|
else
|
||||||
minetest.chat_send_player(player_name,
|
minetest.chat_send_player(player_name,
|
||||||
S("You don't have the settime privilege!"))
|
S("You don't have the settime privilege!"))
|
||||||
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
condition = function(player)
|
condition = function(player)
|
||||||
@ -113,7 +114,7 @@ unified_inventory.register_button("misc_set_day", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
unified_inventory.register_button("misc_set_night", {
|
ui.register_button("misc_set_night", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "ui_moon_icon.png",
|
image = "ui_moon_icon.png",
|
||||||
tooltip = S("Set time to night"),
|
tooltip = S("Set time to night"),
|
||||||
@ -129,7 +130,7 @@ unified_inventory.register_button("misc_set_night", {
|
|||||||
else
|
else
|
||||||
minetest.chat_send_player(player_name,
|
minetest.chat_send_player(player_name,
|
||||||
S("You don't have the settime privilege!"))
|
S("You don't have the settime privilege!"))
|
||||||
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
condition = function(player)
|
condition = function(player)
|
||||||
@ -137,19 +138,19 @@ unified_inventory.register_button("misc_set_night", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
unified_inventory.register_button("clear_inv", {
|
ui.register_button("clear_inv", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "ui_trash_icon.png",
|
image = "ui_trash_icon.png",
|
||||||
tooltip = S("Clear inventory"),
|
tooltip = S("Clear inventory"),
|
||||||
action = function(player)
|
action = function(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
if not unified_inventory.is_creative(player_name) then
|
if not ui.is_creative(player_name) then
|
||||||
minetest.chat_send_player(player_name,
|
minetest.chat_send_player(player_name,
|
||||||
S("This button has been disabled outside"
|
S("This button has been disabled outside"
|
||||||
.." of creative mode to prevent"
|
.." of creative mode to prevent"
|
||||||
.." accidental inventory trashing."
|
.." accidental inventory trashing."
|
||||||
.."\nUse the trash slot instead."))
|
.."\nUse the trash slot instead."))
|
||||||
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
player:get_inventory():set_list("main", {})
|
player:get_inventory():set_list("main", {})
|
||||||
@ -158,11 +159,11 @@ unified_inventory.register_button("clear_inv", {
|
|||||||
{to_player=player_name, gain = 1.0})
|
{to_player=player_name, gain = 1.0})
|
||||||
end,
|
end,
|
||||||
condition = function(player)
|
condition = function(player)
|
||||||
return unified_inventory.is_creative(player:get_player_name())
|
return ui.is_creative(player:get_player_name())
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
unified_inventory.register_page("craft", {
|
ui.register_page("craft", {
|
||||||
get_formspec = function(player, perplayer_formspec)
|
get_formspec = function(player, perplayer_formspec)
|
||||||
|
|
||||||
local formheaderx = perplayer_formspec.form_header_x
|
local formheaderx = perplayer_formspec.form_header_x
|
||||||
@ -172,20 +173,20 @@ unified_inventory.register_page("craft", {
|
|||||||
local craftresultx = craftx + 5
|
local craftresultx = craftx + 5
|
||||||
|
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local formspec = "image["..craftx..","..crafty..";"..(unified_inventory.imgscale*6)..","..(unified_inventory.imgscale*3)..";ui_crafting_form.png]"
|
local formspec = "image["..craftx..","..crafty..";"..(ui.imgscale*6)..","..(ui.imgscale*3)..";ui_crafting_form.png]"
|
||||||
formspec = formspec..perplayer_formspec.standard_inv_bg
|
formspec = formspec..perplayer_formspec.standard_inv_bg
|
||||||
formspec = formspec.."label["..formheaderx..","..formheadery..";" ..F(S("Crafting")).."]"
|
formspec = formspec.."label["..formheaderx..","..formheadery..";" ..F(S("Crafting")).."]"
|
||||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||||
formspec = formspec.."list[current_player;craftpreview;"..(craftresultx+0.15)..","..(crafty+0.15)..";1,1;]"
|
formspec = formspec.."list[current_player;craftpreview;"..(craftresultx+0.15)..","..(crafty+0.15)..";1,1;]"
|
||||||
formspec = formspec.."list[current_player;craft;"..(craftx+0.15)..","..(crafty+0.15)..";3,3;]"
|
formspec = formspec.."list[current_player;craft;"..(craftx+0.15)..","..(crafty+0.15)..";3,3;]"
|
||||||
if unified_inventory.trash_enabled or unified_inventory.is_creative(player_name) or minetest.get_player_privs(player_name).give then
|
if ui.trash_enabled or ui.is_creative(player_name) or minetest.get_player_privs(player_name).give then
|
||||||
formspec = formspec.."label["..(craftx+6.45)..","..(crafty + 2.4)..";" .. F(S("Trash:")) .. "]"
|
formspec = formspec.."label["..(craftx+6.45)..","..(crafty + 2.4)..";" .. F(S("Trash:")) .. "]"
|
||||||
formspec = formspec.."image["..(craftx+6.25)..","..(crafty + 2.5)..";"..unified_inventory.imgscale..","..unified_inventory.imgscale..";ui_trash_slot.png]"
|
formspec = formspec.."image["..(craftx+6.25)..","..(crafty + 2.5)..";"..ui.imgscale..","..ui.imgscale..";ui_trash_slot.png]"
|
||||||
formspec = formspec.."list[detached:trash;main;"..(craftx+6.4)..","..(crafty + 2.65)..";1,1;]"
|
formspec = formspec.."list[detached:trash;main;"..(craftx+6.4)..","..(crafty + 2.65)..";1,1;]"
|
||||||
end
|
end
|
||||||
formspec = formspec.."listring[current_name;craft]"
|
formspec = formspec.."listring[current_name;craft]"
|
||||||
formspec = formspec.."listring[current_player;main]"
|
formspec = formspec.."listring[current_player;main]"
|
||||||
if unified_inventory.is_creative(player_name) then
|
if ui.is_creative(player_name) then
|
||||||
formspec = formspec.."label["..(craftx-2.3)..","..(crafty + 2.4)..";" .. F(S("Refill:")) .. "]"
|
formspec = formspec.."label["..(craftx-2.3)..","..(crafty + 2.4)..";" .. F(S("Refill:")) .. "]"
|
||||||
formspec = formspec.."list[detached:"..F(player_name).."refill;main;"..(craftx-2.35)..","..(crafty + 2.65)..";1,1;]"
|
formspec = formspec.."list[detached:"..F(player_name).."refill;main;"..(craftx-2.35)..","..(crafty + 2.65)..";1,1;]"
|
||||||
end
|
end
|
||||||
@ -208,18 +209,18 @@ local function stack_image_button(x, y, w, h, buttonname_prefix, item)
|
|||||||
local selectitem = name
|
local selectitem = name
|
||||||
if name:sub(1, 6) == "group:" then
|
if name:sub(1, 6) == "group:" then
|
||||||
local group_name = name:sub(7)
|
local group_name = name:sub(7)
|
||||||
local group_item = unified_inventory.get_group_item(group_name)
|
local group_item = ui.get_group_item(group_name)
|
||||||
show_is_group = not group_item.sole
|
show_is_group = not group_item.sole
|
||||||
displayitem = group_item.item or "unknown"
|
displayitem = group_item.item or "unknown"
|
||||||
selectitem = group_item.sole and displayitem or name
|
selectitem = group_item.sole and displayitem or name
|
||||||
end
|
end
|
||||||
local label = show_is_group and "G" or ""
|
local label = show_is_group and "G" or ""
|
||||||
local buttonname = F(buttonname_prefix..unified_inventory.mangle_for_formspec(selectitem))
|
local buttonname = F(buttonname_prefix..ui.mangle_for_formspec(selectitem))
|
||||||
local button = string.format("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
|
local button = string.format("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
|
||||||
x, y, w, h,
|
x, y, w, h,
|
||||||
F(displayitem), buttonname, label)
|
F(displayitem), buttonname, label)
|
||||||
if show_is_group then
|
if show_is_group then
|
||||||
local groupstring, andcount = unified_inventory.extract_groupnames(name)
|
local groupstring, andcount = ui.extract_groupnames(name)
|
||||||
local grouptip
|
local grouptip
|
||||||
if andcount == 1 then
|
if andcount == 1 then
|
||||||
grouptip = S("Any item belonging to the @1 group", groupstring)
|
grouptip = S("Any item belonging to the @1 group", groupstring)
|
||||||
@ -259,7 +260,7 @@ local other_dir = {
|
|||||||
usage = "recipe",
|
usage = "recipe",
|
||||||
}
|
}
|
||||||
|
|
||||||
unified_inventory.register_page("craftguide", {
|
ui.register_page("craftguide", {
|
||||||
get_formspec = function(player, perplayer_formspec)
|
get_formspec = function(player, perplayer_formspec)
|
||||||
|
|
||||||
local craftx = perplayer_formspec.craft_x
|
local craftx = perplayer_formspec.craft_x
|
||||||
@ -277,7 +278,7 @@ unified_inventory.register_page("craftguide", {
|
|||||||
"label["..formheaderx..","..formheadery..";" .. F(S("Crafting Guide")) .. "]",
|
"label["..formheaderx..","..formheadery..";" .. F(S("Crafting Guide")) .. "]",
|
||||||
"listcolors[#00000000;#00000000]"
|
"listcolors[#00000000;#00000000]"
|
||||||
}
|
}
|
||||||
local item_name = unified_inventory.current_item[player_name]
|
local item_name = ui.current_item[player_name]
|
||||||
if not item_name then
|
if not item_name then
|
||||||
return { formspec = table.concat(fs) }
|
return { formspec = table.concat(fs) }
|
||||||
end
|
end
|
||||||
@ -291,17 +292,17 @@ unified_inventory.register_page("craftguide", {
|
|||||||
item_name_shown = item_name
|
item_name_shown = item_name
|
||||||
end
|
end
|
||||||
|
|
||||||
local dir = unified_inventory.current_craft_direction[player_name]
|
local dir = ui.current_craft_direction[player_name]
|
||||||
local rdir = dir == "recipe" and "usage" or "recipe"
|
local rdir = dir == "recipe" and "usage" or "recipe"
|
||||||
|
|
||||||
local crafts = unified_inventory.crafts_for[dir][item_name]
|
local crafts = ui.crafts_for[dir][item_name]
|
||||||
local alternate = unified_inventory.alternate[player_name]
|
local alternate = ui.alternate[player_name]
|
||||||
local alternates, craft
|
local alternates, craft
|
||||||
if crafts and #crafts > 0 then
|
if crafts and #crafts > 0 then
|
||||||
alternates = #crafts
|
alternates = #crafts
|
||||||
craft = crafts[alternate]
|
craft = crafts[alternate]
|
||||||
end
|
end
|
||||||
local has_give = player_privs.give or unified_inventory.is_creative(player_name)
|
local has_give = player_privs.give or ui.is_creative(player_name)
|
||||||
|
|
||||||
fs[#fs + 1] = "image["..craftarrowx..","..crafty..";1.25,1.25;ui_crafting_arrow.png]"
|
fs[#fs + 1] = "image["..craftarrowx..","..crafty..";1.25,1.25;ui_crafting_arrow.png]"
|
||||||
fs[#fs + 1] = string.format("textarea[%f,%f;10,1;;%s: %s;]",
|
fs[#fs + 1] = string.format("textarea[%f,%f;10,1;;%s: %s;]",
|
||||||
@ -334,8 +335,8 @@ unified_inventory.register_page("craftguide", {
|
|||||||
"item_button_usage_", ItemStack(item_name))
|
"item_button_usage_", ItemStack(item_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
local craft_type = unified_inventory.registered_craft_types[craft.type] or
|
local craft_type = ui.registered_craft_types[craft.type] or
|
||||||
unified_inventory.craft_type_defaults(craft.type, {})
|
ui.craft_type_defaults(craft.type, {})
|
||||||
if craft_type.icon then
|
if craft_type.icon then
|
||||||
fs[#fs + 1] = string.format("image[%f,%f;%f,%f;%s]",
|
fs[#fs + 1] = string.format("image[%f,%f;%f,%f;%s]",
|
||||||
craftarrowx+0.1, crafty + 0.95, 1, 1, craft_type.icon)
|
craftarrowx+0.1, crafty + 0.95, 1, 1, craft_type.icon)
|
||||||
@ -426,7 +427,7 @@ local function craftguide_giveme(player, formname, fields)
|
|||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local player_privs = minetest.get_player_privs(player_name)
|
local player_privs = minetest.get_player_privs(player_name)
|
||||||
if not player_privs.give and
|
if not player_privs.give and
|
||||||
not unified_inventory.is_creative(player_name) then
|
not ui.is_creative(player_name) then
|
||||||
minetest.log("action", "[unified_inventory] Denied give action to player " ..
|
minetest.log("action", "[unified_inventory] Denied give action to player " ..
|
||||||
player_name)
|
player_name)
|
||||||
return
|
return
|
||||||
@ -441,7 +442,7 @@ local function craftguide_giveme(player, formname, fields)
|
|||||||
amount = tonumber(amount) or 0
|
amount = tonumber(amount) or 0
|
||||||
if amount == 0 then return end
|
if amount == 0 then return end
|
||||||
|
|
||||||
local output = unified_inventory.current_item[player_name]
|
local output = ui.current_item[player_name]
|
||||||
if (not output) or (output == "") then return end
|
if (not output) or (output == "") then return end
|
||||||
|
|
||||||
local player_inv = player:get_inventory()
|
local player_inv = player:get_inventory()
|
||||||
@ -462,21 +463,21 @@ local function craftguide_craft(player, formname, fields)
|
|||||||
|
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
|
|
||||||
local output = unified_inventory.current_item[player_name] or ""
|
local output = ui.current_item[player_name] or ""
|
||||||
if output == "" then return end
|
if output == "" then return end
|
||||||
|
|
||||||
local crafts = unified_inventory.crafts_for[
|
local crafts = ui.crafts_for[
|
||||||
unified_inventory.current_craft_direction[player_name]][output] or {}
|
ui.current_craft_direction[player_name]][output] or {}
|
||||||
if #crafts == 0 then return end
|
if #crafts == 0 then return end
|
||||||
|
|
||||||
local alternate = unified_inventory.alternate[player_name]
|
local alternate = ui.alternate[player_name]
|
||||||
|
|
||||||
local craft = crafts[alternate]
|
local craft = crafts[alternate]
|
||||||
if craft.width > 3 then return end
|
if craft.width > 3 then return end
|
||||||
|
|
||||||
unified_inventory.craftguide_match_craft(player, "main", "craft", craft, amount)
|
ui.craftguide_match_craft(player, "main", "craft", craft, amount)
|
||||||
|
|
||||||
unified_inventory.set_inventory_formspec(player, "craft")
|
ui.set_inventory_formspec(player, "craft")
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
local S = minetest.get_translator("unified_inventory")
|
local S = minetest.get_translator("unified_inventory")
|
||||||
local F = minetest.formspec_escape
|
local F = minetest.formspec_escape
|
||||||
|
local ui = unified_inventory
|
||||||
|
|
||||||
local hud_colors = {
|
local hud_colors = {
|
||||||
{"#FFFFFF", 0xFFFFFF, S("White")},
|
{"#FFFFFF", 0xFFFFFF, S("White")},
|
||||||
@ -14,30 +15,30 @@ local hud_colors_max = #hud_colors
|
|||||||
-- Stores temporary player data (persists until player leaves)
|
-- Stores temporary player data (persists until player leaves)
|
||||||
local waypoints_temp = {}
|
local waypoints_temp = {}
|
||||||
|
|
||||||
unified_inventory.register_page("waypoints", {
|
ui.register_page("waypoints", {
|
||||||
get_formspec = function(player)
|
get_formspec = function(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local wp_info_x = unified_inventory.style_full.form_header_x + 1.25
|
local wp_info_x = ui.style_full.form_header_x + 1.25
|
||||||
local wp_info_y = unified_inventory.style_full.form_header_y + 0.5
|
local wp_info_y = ui.style_full.form_header_y + 0.5
|
||||||
local wp_bottom_row = unified_inventory.style_full.std_inv_y - 1
|
local wp_bottom_row = ui.style_full.std_inv_y - 1
|
||||||
local wp_buttons_rj = unified_inventory.style_full.std_inv_x + 10.1 - unified_inventory.style_full.btn_spc
|
local wp_buttons_rj = ui.style_full.std_inv_x + 10.1 - ui.style_full.btn_spc
|
||||||
local wp_edit_w = unified_inventory.style_full.btn_spc * 4 - 0.1
|
local wp_edit_w = ui.style_full.btn_spc * 4 - 0.1
|
||||||
|
|
||||||
-- build a "fake" temp entry if the server took too long
|
-- build a "fake" temp entry if the server took too long
|
||||||
-- during sign-on and returned an empty entry
|
-- during sign-on and returned an empty entry
|
||||||
if not waypoints_temp[player_name] then waypoints_temp[player_name] = {hud = 1} end
|
if not waypoints_temp[player_name] then waypoints_temp[player_name] = {hud = 1} end
|
||||||
|
|
||||||
local waypoints = datastorage.get(player_name, "waypoints")
|
local waypoints = datastorage.get(player_name, "waypoints")
|
||||||
local formspec = unified_inventory.style_full.standard_inv_bg..
|
local formspec = ui.style_full.standard_inv_bg..
|
||||||
"label["..unified_inventory.style_full.form_header_x..","..unified_inventory.style_full.form_header_y..";" .. F(S("Waypoints")) .. "]"..
|
"label["..ui.style_full.form_header_x..","..ui.style_full.form_header_y..";" .. F(S("Waypoints")) .. "]"..
|
||||||
"image["..wp_info_x..","..wp_info_y..";1,1;ui_waypoints_icon.png]"
|
"image["..wp_info_x..","..wp_info_y..";1,1;ui_waypoints_icon.png]"
|
||||||
|
|
||||||
-- Tabs buttons:
|
-- Tabs buttons:
|
||||||
for i = 1, 5 do
|
for i = 1, 5 do
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
"image_button["..unified_inventory.style_full.main_button_x..","..
|
"image_button["..ui.style_full.main_button_x..","..
|
||||||
(wp_bottom_row - (5-i) * unified_inventory.style_full.btn_spc)..";"..
|
(wp_bottom_row - (5-i) * ui.style_full.btn_spc)..";"..
|
||||||
unified_inventory.style_full.btn_size..","..unified_inventory.style_full.btn_size..";" ..
|
ui.style_full.btn_size..","..ui.style_full.btn_size..";" ..
|
||||||
(i == waypoints.selected and "ui_blue_icon_background.png^" or "") ..
|
(i == waypoints.selected and "ui_blue_icon_background.png^" or "") ..
|
||||||
"ui_" .. i .. "_icon.png;" ..
|
"ui_" .. i .. "_icon.png;" ..
|
||||||
"select_waypoint" .. i .. ";]" ..
|
"select_waypoint" .. i .. ";]" ..
|
||||||
@ -63,9 +64,9 @@ unified_inventory.register_page("waypoints", {
|
|||||||
local x = 4
|
local x = 4
|
||||||
for _, b in pairs(btnlist) do
|
for _, b in pairs(btnlist) do
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
"image_button["..(wp_buttons_rj - unified_inventory.style_full.btn_spc * x)..","..
|
"image_button["..(wp_buttons_rj - ui.style_full.btn_spc * x)..","..
|
||||||
wp_bottom_row..";"..
|
wp_bottom_row..";"..
|
||||||
unified_inventory.style_full.btn_size..","..unified_inventory.style_full.btn_size..";"..
|
ui.style_full.btn_size..","..ui.style_full.btn_size..";"..
|
||||||
b[1]..";"..
|
b[1]..";"..
|
||||||
b[2]..i..";]"..
|
b[2]..i..";]"..
|
||||||
"tooltip["..b[2]..i..";"..F(S(b[3], b[4] or "")).."]"
|
"tooltip["..b[2]..i..";"..F(S(b[3], b[4] or "")).."]"
|
||||||
@ -82,11 +83,11 @@ unified_inventory.register_page("waypoints", {
|
|||||||
|
|
||||||
if temp.edit then
|
if temp.edit then
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
"field["..(wp_buttons_rj - wp_edit_w - 0.1)..","..(wp_bottom_row - unified_inventory.style_full.btn_spc)..";"..
|
"field["..(wp_buttons_rj - wp_edit_w - 0.1)..","..(wp_bottom_row - ui.style_full.btn_spc)..";"..
|
||||||
wp_edit_w..","..unified_inventory.style_full.btn_size..";rename_box" .. i .. ";;"..
|
wp_edit_w..","..ui.style_full.btn_size..";rename_box" .. i .. ";;"..
|
||||||
(waypoint.name or default_name).."]" ..
|
(waypoint.name or default_name).."]" ..
|
||||||
"image_button["..wp_buttons_rj..","..(wp_bottom_row - unified_inventory.style_full.btn_spc)..";"..
|
"image_button["..wp_buttons_rj..","..(wp_bottom_row - ui.style_full.btn_spc)..";"..
|
||||||
unified_inventory.style_full.btn_size..","..unified_inventory.style_full.btn_size..";"..
|
ui.style_full.btn_size..","..ui.style_full.btn_size..";"..
|
||||||
"ui_ok_icon.png;"..
|
"ui_ok_icon.png;"..
|
||||||
"confirm_rename"..i.. ";]"..
|
"confirm_rename"..i.. ";]"..
|
||||||
"tooltip[confirm_rename" .. i .. ";"
|
"tooltip[confirm_rename" .. i .. ";"
|
||||||
@ -103,7 +104,7 @@ unified_inventory.register_page("waypoints", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
unified_inventory.register_button("waypoints", {
|
ui.register_button("waypoints", {
|
||||||
type = "image",
|
type = "image",
|
||||||
image = "ui_waypoints_icon.png",
|
image = "ui_waypoints_icon.png",
|
||||||
tooltip = S("Waypoints"),
|
tooltip = S("Waypoints"),
|
||||||
@ -218,7 +219,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
update_hud(player, waypoints, temp, i)
|
update_hud(player, waypoints, temp, i)
|
||||||
end
|
end
|
||||||
if update_formspec then
|
if update_formspec then
|
||||||
unified_inventory.set_inventory_formspec(player, "waypoints")
|
ui.set_inventory_formspec(player, "waypoints")
|
||||||
end
|
end
|
||||||
if hit then return end
|
if hit then return end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user