Version MFF.

This commit is contained in:
sys4-fr 2018-09-08 23:00:32 +02:00
parent 4bae2c7fa3
commit c884727ff3
98 changed files with 1273 additions and 409 deletions

0
.gitignore vendored Normal file → Executable file
View File

11
README.md Normal file → Executable file
View File

@ -15,8 +15,17 @@ Licenses for textures:
VanessaE: (WTFPL)
* ui\_group.png
* ui_form_bg : credits to moretrees mod.
© 2013, Vanessa Ezekowitz <vanessaezekowitz@gmail.com>
Published under the terms and conditions of CC-BY-SA-3.0 Unported.
RealBadAngel: (WTFPL)
* Everything else.
* Bags icons
* ui_numbers
* waypoints icons, ui_group, ui_ok, circular_arrows, xyz_icons
Obani : (CC-BY)
* Ui formspecs textures
* Every other icon

175
api.lua Normal file → Executable file
View File

@ -1,9 +1,5 @@
local S
if intllib then
S = intllib.Getter()
else
S = function(s) return s end
end
local S = unified_inventory.gettext
local F = unified_inventory.fgettext
-- Create detached creative inventory after loading all mods
minetest.after(0.01, function()
@ -24,7 +20,33 @@ minetest.after(0.01, function()
local recipes = minetest.get_all_craft_recipes(name)
if recipes then
for _, recipe in ipairs(recipes) do
unified_inventory.register_craft(recipe)
local unknowns
for _,chk in pairs(recipe.items) do
local groupchk = string.find(chk, "group:")
if groupchk then
for _,groupname in pairs(string.gsub(chk, "group:", ""):split(",")) do
if not unified_inventory.get_group_item(groupname).item then
unknowns = true
if minetest.setting_getbool("show_unknown_craftrecipes") then
minetest.log("error", "Recipe for item " .. recipe.output .. " contains unknown group " .. groupname)
end
break
end
end
elseif not minetest.registered_items[chk] then
unknowns = true
if minetest.setting_getbool("show_unknown_craftrecipes") then
minetest.log("error", "Recipe for item " .. recipe.output .. " contains unknown item " .. chk)
end
break
end
end
if not unknowns then
unified_inventory.register_craft(recipe)
end
end
end
end
@ -32,9 +54,10 @@ minetest.after(0.01, function()
end
table.sort(unified_inventory.items_list)
unified_inventory.items_list_size = #unified_inventory.items_list
print("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
minetest.log("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
for _, name in ipairs(unified_inventory.items_list) do
local def = minetest.registered_items[name]
-- Simple drops
if type(def.drop) == "string" then
local dstack = ItemStack(def.drop)
if not dstack:is_empty() and dstack:get_name() ~= name then
@ -46,6 +69,79 @@ minetest.after(0.01, function()
})
end
-- Complex drops. Yes, it's really complex!
elseif type(def.drop) == "table" then
--[[ Extract single items from the table and save them into dedicated tables
to register them later, in order to avoid duplicates. These tables counts
the total number of guaranteed drops and drops by chance (maybes) for each item.
For maybes, the final count is the theoretical maximum number of items, not
neccessarily the actual drop count. ]]
local drop_guaranteed = {}
local drop_maybe = {}
-- This is for catching an obscure corner case: If the top items table has
-- only items with rarity = 1, but max_items is set, then only the first
-- max_items will be part of the drop, any later entries are logically
-- impossible, so this variable is for keeping track of this
local max_items_left = def.drop.max_items
-- For checking whether we still encountered only guaranteed only so far;
-- for the first “maybe” item it will become false which will cause ALL
-- later items to be considered “maybes”.
-- A common idiom is:
-- { max_items 1, { items = {
-- { items={"example:1"}, rarity = 5 },
-- { items={"example:2"}, rarity = 1 }, }}}
-- example:2 must be considered a “maybe” because max_items is set and it
-- appears after a “maybe”
local max_start = true
-- Let's iterate through the items madness!
if def.drop.items then
for i=1,#def.drop.items do
if max_items_left ~= nil and max_items_left <= 0 then break end
local itit = def.drop.items[i]
for j=1,#itit.items do
local dstack = ItemStack(itit.items[j])
if not dstack:is_empty() and dstack:get_name() ~= name then
local dname = dstack:get_name()
local dcount = dstack:get_count()
-- Guaranteed drops AND we are not yet in “maybe mode”
if #itit.items == 1 and itit.rarity == 1 and max_start then
if drop_guaranteed[dname] == nil then
drop_guaranteed[dname] = 0
end
drop_guaranteed[dname] = drop_guaranteed[dname] + dcount
if max_items_left ~= nil then
max_items_left = max_items_left - 1
if max_items_left <= 0 then break end
end
-- Drop was a “maybe”
else
if max_items_left ~= nil then max_start = false end
if drop_maybe[dname] == nil then
drop_maybe[dname] = 0
end
drop_maybe[dname] = drop_maybe[dname] + dcount
end
end
end
end
end
for itemstring, count in pairs(drop_guaranteed) do
unified_inventory.register_craft({
type = "digging",
items = {name},
output = itemstring .. " " .. count,
width = 0,
})
end
for itemstring, count in pairs(drop_maybe) do
unified_inventory.register_craft({
type = "digging_chance",
items = {name},
output = itemstring .. " " .. count,
width = 0,
})
end
end
end
for _, recipes in pairs(unified_inventory.crafts_for.recipe) do
@ -73,50 +169,43 @@ end)
-- load_home
local function load_home()
local input = io.open(unified_inventory.home_filename, "r")
if input then
while true do
local x = input:read("*n")
if x == nil then
break
end
local y = input:read("*n")
local z = input:read("*n")
local name = input:read("*l")
unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z}
end
io.close(input)
else
if not input then
unified_inventory.home_pos = {}
return
end
while true do
local x = input:read("*n")
if not x then break end
local y = input:read("*n")
local z = input:read("*n")
local name = input:read("*l")
unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z}
end
io.close(input)
end
load_home()
function unified_inventory.set_home(player, pos)
local player_name = player:get_player_name()
unified_inventory.home_pos[player_name] = pos
unified_inventory.home_pos[player_name] = vector.round(pos)
-- save the home data from the table to the file
local output = io.open(unified_inventory.home_filename, "w")
for k, v in pairs(unified_inventory.home_pos) do
if v ~= nil then
output:write(math.floor(v.x).." "
..math.floor(v.y).." "
..math.floor(v.z).." "
..k.."\n")
end
output:write(v.x.." "..v.y.." "..v.z.." "..k.."\n")
end
io.close(output)
end
function unified_inventory.go_home(player)
local pos = unified_inventory.home_pos[player:get_player_name()]
if pos ~= nil then
if pos then
player:setpos(pos)
end
end
-- register_craft
function unified_inventory.register_craft(options)
if options.output == nil then
if not options.output then
return
end
local itemstack = ItemStack(options.output)
@ -126,7 +215,7 @@ function unified_inventory.register_craft(options)
if options.type == "normal" and options.width == 0 then
options = { type = "shapeless", items = options.items, output = options.output, width = 0 }
end
if unified_inventory.crafts_for.recipe[itemstack:get_name()] == nil then
if not unified_inventory.crafts_for.recipe[itemstack:get_name()] then
unified_inventory.crafts_for.recipe[itemstack:get_name()] = {}
end
table.insert(unified_inventory.crafts_for.recipe[itemstack:get_name()],options)
@ -156,7 +245,8 @@ end
unified_inventory.register_craft_type("normal", {
description = "Crafting",
description = F("Crafting"),
icon = "ui_craftgrid_icon.png",
width = 3,
height = 3,
get_shaped_craft_width = function (craft) return craft.width end,
@ -171,7 +261,8 @@ unified_inventory.register_craft_type("normal", {
unified_inventory.register_craft_type("shapeless", {
description = "Mixing",
description = F("Mixing"),
icon = "ui_craftgrid_icon.png",
width = 3,
height = 3,
dynamic_display_size = function (craft)
@ -185,18 +276,26 @@ unified_inventory.register_craft_type("shapeless", {
unified_inventory.register_craft_type("cooking", {
description = "Cooking",
description = F("Cooking"),
icon = "default_furnace_front.png",
width = 1,
height = 1,
})
unified_inventory.register_craft_type("digging", {
description = "Digging",
description = F("Digging"),
icon = "default_tool_steelpick.png",
width = 1,
height = 1,
})
unified_inventory.register_craft_type("digging_chance", {
description = "Digging (by chance)",
icon = "default_tool_steelpick.png^[transformFY.png",
width = 1,
height = 1,
})
function unified_inventory.register_page(name, def)
unified_inventory.pages[name] = def
@ -215,9 +314,7 @@ end
function unified_inventory.is_creative(playername)
if minetest.check_player_privs(playername, {creative=true}) or
minetest.setting_getbool("creative_mode") then
return true
end
return minetest.check_player_privs(playername, {creative=true})
or minetest.setting_getbool("creative_mode")
end

237
bags.lua Normal file → Executable file
View File

@ -3,22 +3,18 @@
-- Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
-- License: GPLv3
local S
if intllib then
S = intllib.Getter()
else
S = function(s) return s end
end
local S = unified_inventory.gettext
local F = unified_inventory.fgettext
unified_inventory.register_page("bags", {
get_formspec = function(player)
local player_name = player:get_player_name()
local formspec = "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
formspec = formspec.."label[0,0;"..S("Bags").."]"
formspec = formspec.."button[0,2;2,0.5;bag1;Bag 1]"
formspec = formspec.."button[2,2;2,0.5;bag2;Bag 2]"
formspec = formspec.."button[4,2;2,0.5;bag3;Bag 3]"
formspec = formspec.."button[6,2;2,0.5;bag4;Bag 4]"
formspec = formspec.."label[0,0;"..F("Bags").."]"
formspec = formspec.."button[0,2;2,0.5;bag1;"..F("Bag 1").."]" .. "button[0,3;2,0.5;unequip_bag1;Unequip]"
formspec = formspec.."button[2,2;2,0.5;bag2;"..F("Bag 2").."]" .. "button[2,3;2,0.5;unequip_bag2;Unequip]"
formspec = formspec.."button[4,2;2,0.5;bag3;"..F("Bag 3").."]" .. "button[4,3;2,0.5;unequip_bag3;Unequip]"
formspec = formspec.."button[6,2;2,0.5;bag4;"..F("Bag 4").."]" .. "button[6,3;2,0.5;unequip_bag4;Unequip]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag1;0.5,1;1,1;]"
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag2;2.5,1;1,1;]"
@ -31,18 +27,85 @@ unified_inventory.register_page("bags", {
unified_inventory.register_button("bags", {
type = "image",
image = "ui_bags_icon.png",
tooltip = S("Bags")
tooltip = S("Bags"),
hide_lite=true,
show_with = false, --Modif MFF (Crabman 30/06/2015)
})
for i = 1, 4 do
unified_inventory.register_page("bag"..i, {
unified_inventory.register_page("bag1", {
get_formspec = function(player)
local stack = player:get_inventory():get_stack("bag"..i, 1)
local stack = player:get_inventory():get_stack("bag1", 1)
local image = stack:get_definition().inventory_image
local formspec = "image[7,0;1,1;"..image.."]"
formspec = formspec.."label[0,0;Bag "..i.."]"
formspec = formspec.."label[0,0;"..F("Bag 1").."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;bag"..i.."contents;0,1;8,3;]"
formspec = formspec.."list[current_player;bag1contents;0,1;8,3;]"
formspec = formspec.."listring[current_name;bag1contents]"
formspec = formspec.."listring[current_player;main]"
local slots = stack:get_definition().groups.bagslots
if slots == 8 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]"
elseif slots == 16 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_med_form.png]"
elseif slots == 24 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]"
end
return {formspec=formspec}
end,
})
unified_inventory.register_page("bag2", {
get_formspec = function(player)
local stack = player:get_inventory():get_stack("bag2", 1)
local image = stack:get_definition().inventory_image
local formspec = "image[7,0;1,1;"..image.."]"
formspec = formspec.."label[0,0;"..F("Bag 2").."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;bag2contents;0,1;8,3;]"
formspec = formspec.."listring[current_name;bag2contents]"
formspec = formspec.."listring[current_player;main]"
local slots = stack:get_definition().groups.bagslots
if slots == 8 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]"
elseif slots == 16 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_med_form.png]"
elseif slots == 24 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]"
end
return {formspec=formspec}
end,
})
unified_inventory.register_page("bag3", {
get_formspec = function(player)
local stack = player:get_inventory():get_stack("bag3", 1)
local image = stack:get_definition().inventory_image
local formspec = "image[7,0;1,1;"..image.."]"
formspec = formspec.."label[0,0;"..F("Bag 3").."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;bag3contents;0,1;8,3;]"
formspec = formspec.."listring[current_name;bag3contents]"
formspec = formspec.."listring[current_player;main]"
local slots = stack:get_definition().groups.bagslots
if slots == 8 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]"
elseif slots == 16 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_med_form.png]"
elseif slots == 24 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]"
end
return {formspec=formspec}
end,
})
unified_inventory.register_page("bag4", {
get_formspec = function(player)
local stack = player:get_inventory():get_stack("bag4", 1)
local image = stack:get_definition().inventory_image
local formspec = "image[7,0;1,1;"..image.."]"
formspec = formspec.."label[0,0;"..F("Bag 4").."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;bag4contents;0,1;8,3;]"
formspec = formspec.."listring[current_name;bag4contents]"
formspec = formspec.."listring[current_player;main]"
local slots = stack:get_definition().groups.bagslots
if slots == 8 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]"
@ -54,7 +117,6 @@ for i = 1, 4 do
return {formspec=formspec}
end,
})
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "" then
@ -68,6 +130,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
unified_inventory.set_inventory_formspec(player, "bag"..i)
return
elseif fields["unequip_bag" .. i] then
local stack = unified_inventory.extract_bag(player, i)
if not stack then
return
elseif stack == "overflow" then
minetest.chat_send_player(player:get_player_name(), "You bag is too heavy to be unequipped... Remove some items and retry")
return
elseif not player:get_inventory():room_for_item("main", stack) then
local pos = player:getpos()
pos.y = pos.y + 2
minetest.add_item(pos, stack)
return
end
player:get_inventory():add_item("main", stack)
end
end
end)
@ -76,12 +152,20 @@ minetest.register_on_joinplayer(function(player)
local player_inv = player:get_inventory()
local bags_inv = minetest.create_detached_inventory(player:get_player_name().."_bags",{
on_put = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, stack)
player:get_inventory():set_size(listname.."contents",
local pinv = player:get_inventory()
pinv:set_stack(listname, index, stack)
pinv:set_size(listname.."contents",
stack:get_definition().groups.bagslots)
-- Retrieve the serialized inventory if any
if stack:get_metadata() ~= "" then
for i, item in pairs(minetest.deserialize(stack:get_metadata())) do
pinv:set_stack(listname .. "contents", i, ItemStack(item))
end
end
end,
on_take = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, nil)
allow_take = function()
return 0
end,
allow_put = function(inv, listname, index, stack, player)
if stack:get_definition().groups.bagslots then
@ -90,13 +174,6 @@ minetest.register_on_joinplayer(function(player)
return 0
end
end,
allow_take = function(inv, listname, index, stack, player)
if player:get_inventory():is_empty(listname.."contents") then
return stack:get_count()
else
return 0
end
end,
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
return 0
end,
@ -128,13 +205,65 @@ minetest.register_tool("unified_inventory:bag_large", {
groups = {bagslots=24},
})
local colours = {"orange", "blue", "green", "violet"}
for _, colour in pairs(colours) do
minetest.register_tool("unified_inventory:bag_small_" .. colour, {
description = S("Small Bag"),
inventory_image = "bags_small_" .. colour .. ".png",
groups = {bagslots=8},
})
minetest.register_tool("unified_inventory:bag_medium_" .. colour, {
description = S("Medium Bag"),
inventory_image = "bags_medium_" .. colour .. ".png",
groups = {bagslots=16},
})
minetest.register_tool("unified_inventory:bag_large_" .. colour, {
description = S("Large Bag"),
inventory_image = "bags_large_" .. colour .. ".png",
groups = {bagslots=24},
})
-- register bag crafts
minetest.register_craft({
output = "unified_inventory:bag_small_" .. colour,
recipe = {
{"dye:"..colour, "unified_inventory:bag_small"},
},
})
minetest.register_craft({
output = "unified_inventory:bag_medium_" .. colour,
recipe = {
{"", "", ""},
{"farming:cotton", "unified_inventory:bag_small_" .. colour, "farming:cotton"},
{"farming:cotton", "unified_inventory:bag_small_" .. colour, "farming:cotton"},
},
})
minetest.register_craft({
output = "unified_inventory:bag_large_" .. colour,
recipe = {
{"", "", ""},
{"farming:cotton", "unified_inventory:bag_medium_" .. colour, "farming:cotton"},
{"farming:cotton", "unified_inventory:bag_medium_" .. colour, "farming:cotton"},
},
})
end
--minetest.register_alias("unified_inventory:bag_small", "unified_inventory:bad_small_red")
--minetest.register_alias("unified_inventory:bag_medium", "unified_inventory:bad_medium_red")
--minetest.register_alias("unified_inventory:bag_large", "unified_inventory:bad_large_red")
-- register bag crafts
minetest.register_craft({
output = "unified_inventory:bag_small",
recipe = {
{"", "default:stick", ""},
{"group:wood", "group:wood", "group:wood"},
{"group:wood", "group:wood", "group:wood"},
{"", "farming:cotton", ""},
{"group:wool", "group:wool", "group:wool"},
{"group:wool", "group:wool", "group:wool"},
},
})
@ -142,8 +271,8 @@ minetest.register_craft({
output = "unified_inventory:bag_medium",
recipe = {
{"", "", ""},
{"default:stick", "unified_inventory:bag_small", "default:stick"},
{"default:stick", "unified_inventory:bag_small", "default:stick"},
{"farming:cotton", "unified_inventory:bag_small", "farming:cotton"},
{"farming:cotton", "unified_inventory:bag_small", "farming:cotton"},
},
})
@ -151,8 +280,44 @@ minetest.register_craft({
output = "unified_inventory:bag_large",
recipe = {
{"", "", ""},
{"default:stick", "unified_inventory:bag_medium", "default:stick"},
{"default:stick", "unified_inventory:bag_medium", "default:stick"},
{"farming:cotton", "unified_inventory:bag_medium", "farming:cotton"},
{"farming:cotton", "unified_inventory:bag_medium", "farming:cotton"},
},
})
function unified_inventory.extract_bag(player, id)
if not player then
minetest.log("error", "[u_inv] Invalid player for bag extraction : nil")
return
end
if tonumber(id) == nil or id > 4 or id < 0 then
minetest.log("error", "Invalid id: " .. (id or 'nil'))
return
end
local stack = player:get_inventory():get_stack("bag"..id, 1)
if not stack:get_definition().groups.bagslots then
return
end
local pinv = player:get_inventory()
local inv = pinv:get_list("bag" .. id .. "contents")
local list = {}
for i, item in pairs(inv) do
list[i] = item:to_table()
end
if minetest.serialize(list):len() >= 4096 then
minetest.log("warning", "[U_Inv] Preventing metadata overflow with bag metadata")
return "overflow"
end
pinv:remove_item("bag" .. id, stack)
local dinv = minetest.get_inventory({type = "detached", name = minetest.formspec_escape(player:get_player_name()) .. "_bags"})
if dinv then
dinv:set_stack("bag" .. id, 1, nil)
end
pinv:set_list("bag" .. id .. "contents", {})
stack:set_metadata(minetest.serialize(list))
return stack
end

132
callbacks.lua Normal file → Executable file
View File

@ -1,7 +1,9 @@
local function default_refill(stack)
stack:set_count(stack:get_stack_max())
local itemdef = minetest.registered_items[stack:get_name()]
if itemdef and (itemdef.wear_represents or "mechanical_wear") == "mechanical_wear" and stack:get_wear() ~= 0 then
if itemdef
and (itemdef.wear_represents or "mechanical_wear") == "mechanical_wear"
and stack:get_wear() ~= 0 then
stack:set_wear(0)
end
return stack
@ -12,7 +14,7 @@ minetest.register_on_joinplayer(function(player)
unified_inventory.players[player_name] = {}
unified_inventory.current_index[player_name] = 1
unified_inventory.filtered_items_list[player_name] =
unified_inventory.items_list
unified_inventory.items_list
unified_inventory.activefilter[player_name] = ""
unified_inventory.active_search_direction[player_name] = "nochange"
unified_inventory.apply_filter(player, "", "nochange")
@ -21,7 +23,7 @@ minetest.register_on_joinplayer(function(player)
unified_inventory.current_item[player_name] = nil
unified_inventory.current_craft_direction[player_name] = "recipe"
unified_inventory.set_inventory_formspec(player,
unified_inventory.default)
unified_inventory.default)
-- Refill slot
local refill = minetest.create_detached_inventory(player_name.."refill", {
@ -46,13 +48,27 @@ minetest.register_on_joinplayer(function(player)
end)
minetest.register_on_player_receive_fields(function(player, formname, fields)
local player_name = player:get_player_name()
local ui_peruser,draw_lite_mode = unified_inventory.get_per_player_formspec(player_name)
if formname ~= "" then
return
end
local player_name = player:get_player_name()
if fields.hidebutton then --MFF crabman(29/11/2015) hide guide, textfield bug
if not unified_inventory.hidden_guide[player_name] then
unified_inventory.hidden_guide[player_name] = true
else
unified_inventory.hidden_guide[player_name] = false
end
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
return
end
-- always take new search text, even if not searching on it yet
if fields.searchbox ~= nil and fields.searchbox ~= unified_inventory.current_searchbox[player_name] then
if fields.searchbox
and fields.searchbox ~= unified_inventory.current_searchbox[player_name] then
unified_inventory.current_searchbox[player_name] = fields.searchbox
unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name])
end
@ -68,11 +84,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- Inventory page controls
local start = math.floor(
unified_inventory.current_index[player_name] / 80 + 1)
unified_inventory.current_index[player_name] / ui_peruser.items_per_page + 1)
local start_i = start
local pagemax = math.floor(
(#unified_inventory.filtered_items_list[player_name] - 1)
/ (80) + 1)
/ (ui_peruser.items_per_page) + 1)
if fields.start_list then
start_i = 1
@ -98,15 +114,15 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if start_i > pagemax then
start_i = pagemax
end
if not (start_i == start) then
if start_i ~= start then
minetest.sound_play("paperflip1",
{to_player=player_name, gain = 1.0})
unified_inventory.current_index[player_name] = (start_i - 1) * 80 + 1
unified_inventory.current_index[player_name] = (start_i - 1) * ui_peruser.items_per_page + 1
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
end
local clicked_item = nil
local clicked_item
for name, value in pairs(fields) do
if string.sub(name, 1, 12) == "item_button_" then
local new_dir, mangled_item = string.match(name, "^item_button_([a-z]+)_(.*)$")
@ -114,9 +130,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if string.sub(clicked_item, 1, 6) == "group:" then
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
unified_inventory.apply_filter(player, clicked_item, new_dir)
unified_inventory.current_searchbox[player_name] = clicked_item
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
return
end
if new_dir == "recipe" or new_dir == "usage" then
if new_dir == "recipe"
or new_dir == "usage" then
unified_inventory.current_craft_direction[player_name] = new_dir
end
break
@ -126,57 +146,79 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
minetest.sound_play("click",
{to_player=player_name, gain = 0.1})
local page = unified_inventory.current_page[player_name]
if not unified_inventory.is_creative(player_name) then
local player_creative = unified_inventory.is_creative(player_name)
if not player_creative then
page = "craftguide"
end
if page == "craftguide" then
unified_inventory.current_item[player_name] = clicked_item
unified_inventory.alternate[player_name] = 1
unified_inventory.set_inventory_formspec(player,
"craftguide")
else
if unified_inventory.is_creative(player_name) then
local inv = player:get_inventory()
local stack = ItemStack(clicked_item)
stack:set_count(stack:get_stack_max())
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
end
unified_inventory.set_inventory_formspec(player, "craftguide")
elseif player_creative then
local inv = player:get_inventory()
local stack = ItemStack(clicked_item)
stack:set_count(stack:get_stack_max())
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
end
end
end
if fields.searchbutton then
if fields.searchbutton or fields.key_enter_field == "searchbox" then
unified_inventory.apply_filter(player, unified_inventory.current_searchbox[player_name], "nochange")
unified_inventory.current_searchbox[player_name] = ""
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
minetest.sound_play("paperflip2",
{to_player=player_name, gain = 1.0})
end
-- alternate button
if fields.alternate then
elseif fields.searchresetbutton then
unified_inventory.apply_filter(player, "", "nochange")
unified_inventory.current_searchbox[player_name] = ""
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
minetest.sound_play("click",
{to_player=player_name, gain = 0.1})
local item_name = unified_inventory.current_item[player_name]
if item_name then
local alternates = 0
local alternate = unified_inventory.alternate[player_name]
local crafts = unified_inventory.crafts_for[unified_inventory.current_craft_direction[player_name]][item_name]
if crafts ~= nil then
alternates = #crafts
end
if alternates > 1 then
alternate = alternate + 1
if alternate > alternates then
alternate = 1
end
unified_inventory.alternate[player_name] = alternate
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
end
end
-- alternate buttons
if not (fields.alternate or fields.alternate_prev) then
return
end
minetest.sound_play("click",
{to_player=player_name, gain = 0.1})
local item_name = unified_inventory.current_item[player_name]
if not item_name then
return
end
local crafts = unified_inventory.crafts_for[unified_inventory.current_craft_direction[player_name]][item_name]
if not crafts then
return
end
local alternates = #crafts
if alternates <= 1 then
return
end
local alternate
if fields.alternate then
alternate = unified_inventory.alternate[player_name] + 1
if alternate > alternates then
alternate = 1
end
elseif fields.alternate_prev then
alternate = unified_inventory.alternate[player_name] - 1
if alternate < 1 then
alternate = alternates
end
end
unified_inventory.alternate[player_name] = alternate
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
end)
if minetest.delete_detached_inventory then
minetest.register_on_leaveplayer(function(player)
local player_name = player:get_player_name()
minetest.delete_detached_inventory(player_name.."_bags")
minetest.delete_detached_inventory(player_name.."craftrecipe")
minetest.delete_detached_inventory(player_name.."refill")
end)
end

3
depends.txt Normal file → Executable file
View File

@ -1,4 +1,5 @@
h2omes
creative?
intllib?
datastorage?
farming?

1
description.txt Normal file
View File

@ -0,0 +1 @@
Unified Inventory replaces the default survival and creative inventory. It adds a nicer interface and a number of features, such as a crafting guide.

30
group.lua Normal file → Executable file
View File

@ -1,3 +1,5 @@
local S = unified_inventory.gettext
function unified_inventory.canonical_item_spec_matcher(spec)
local specname = ItemStack(spec):get_name()
if specname:sub(1, 6) == "group:" then
@ -21,10 +23,38 @@ function unified_inventory.item_matches_spec(item, spec)
return unified_inventory.canonical_item_spec_matcher(spec)(itemname)
end
function unified_inventory.extract_groupnames(groupname)
local specname = ItemStack(groupname):get_name()
if specname:sub(1, 6) == "group:" then
local group_names = specname:sub(7):split(",")
if #group_names == 1 then
return group_names[1], 1
end
local s = ""
for g=1,#group_names do
if g > 1 then
-- List connector
s = s .. S(" and ")
end
s = s .. group_names[g]
end
return s, #group_names
else
return nil, 0
end
end
unified_inventory.registered_group_items = {
mesecon_conductor_craftable = "mesecons:wire_00000000_off",
stone = "default:cobble",
wood = "default:wood",
book = "default:book",
sand = "default:sand",
leaves = "default:leaves",
tree = "default:tree",
vessel = "vessels:glass_bottle",
wool = "wool:white",
ingot = "default:steel_ingot",
}
function unified_inventory.register_group_item(groupname, itemname)

0
image_credits.txt Normal file → Executable file
View File

74
init.lua Normal file → Executable file
View File

@ -2,38 +2,58 @@
local modpath = minetest.get_modpath(minetest.get_current_modname())
local worldpath = minetest.get_worldpath()
local mygettext = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end
-- Data tables definitions
unified_inventory = {}
unified_inventory.activefilter = {}
unified_inventory.active_search_direction = {}
unified_inventory.alternate = {}
unified_inventory.current_page = {}
unified_inventory.current_searchbox = {}
unified_inventory.current_index = {}
unified_inventory.current_item = {}
unified_inventory.current_craft_direction = {}
unified_inventory.registered_craft_types = {}
unified_inventory.crafts_for = { usage = {}, recipe = {} }
unified_inventory.players = {}
unified_inventory.items_list_size = 0
unified_inventory.items_list = {}
unified_inventory.filtered_items_list_size = {}
unified_inventory.filtered_items_list = {}
unified_inventory.pages = {}
unified_inventory.buttons = {}
unified_inventory = {
activefilter = {},
active_search_direction = {},
alternate = {},
current_page = {},
current_searchbox = {},
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 = {},
hidden_guide = {}, --MFF crabman(29/11/2015) hide guide, textfield bug
-- Homepos stuff
unified_inventory.home_pos = {}
unified_inventory.home_filename =
worldpath.."/unified_inventory_home.home"
-- Homepos stuff
home_pos = {},
home_filename = worldpath.."/unified_inventory_home.home",
-- Default inventory page
unified_inventory.default = "craft"
-- Default inventory page
default = "craft",
-- intllib
gettext = mygettext,
fgettext = function(s) return minetest.formspec_escape(mygettext(s)) end,
-- "Lite" mode
lite_mode = minetest.setting_getbool("unified_inventory_lite"),
pagecols = 8,
pagerows = 10,
page_y = 0,
formspec_y = 1,
main_button_x = 0,
main_button_y = 9,
craft_result_x = 0.3,
craft_result_y = 0.5,
form_header_y = 0
}
-- Disable default creative inventory
if creative_inventory then
function creative_inventory.set_creative_formspec(player, start_i, pagenum)
local creative = rawget(_G, "creative") or rawget(_G, "creative_inventory")
if creative then
function creative.set_creative_formspec(player, start_i, pagenum)
return
end
end
@ -44,7 +64,9 @@ dofile(modpath.."/internal.lua")
dofile(modpath.."/callbacks.lua")
dofile(modpath.."/register.lua")
dofile(modpath.."/bags.lua")
dofile(modpath.."/item_names.lua")
if minetest.get_modpath("datastorage") then
dofile(modpath.."/waypoints.lua")
end

281
internal.lua Normal file → Executable file
View File

@ -1,9 +1,5 @@
local S
if intllib then
S = intllib.Getter()
else
S = function(s) return s end
end
local S = unified_inventory.gettext
local F = unified_inventory.fgettext
-- This pair of encoding functions is used where variable text must go in
-- button names, where the text might contain formspec metacharacters.
@ -20,126 +16,266 @@ function unified_inventory.demangle_for_formspec(str)
return string.gsub(str, "_([0-9]+)_", function (v) return string.char(v) end)
end
function unified_inventory.get_per_player_formspec(player_name)
local lite = unified_inventory.lite_mode and not minetest.check_player_privs(player_name, {ui_full=true})
local ui = {}
ui.pagecols = unified_inventory.pagecols
ui.pagerows = unified_inventory.pagerows
ui.page_y = unified_inventory.page_y
ui.formspec_y = unified_inventory.formspec_y
ui.main_button_x = unified_inventory.main_button_x
ui.main_button_y = unified_inventory.main_button_y
ui.craft_result_x = unified_inventory.craft_result_x
ui.craft_result_y = unified_inventory.craft_result_y
ui.form_header_y = unified_inventory.form_header_y
if lite then
ui.pagecols = 4
ui.pagerows = 6
ui.page_y = 0.25
ui.formspec_y = 0.47
ui.main_button_x = 8.2
ui.main_button_y = 6.5
ui.craft_result_x = 2.8
ui.craft_result_y = 3.4
ui.form_header_y = -0.1
end
ui.items_per_page = ui.pagecols * ui.pagerows
return ui, lite
end
function unified_inventory.get_formspec(player, page)
if not player then
return ""
end
local player_name = player:get_player_name()
local ui_peruser,draw_lite_mode = unified_inventory.get_per_player_formspec(player_name)
unified_inventory.current_page[player_name] = page
local pagedef = unified_inventory.pages[page]
local formspec = "size[14,10]"
local fsdata = nil
local formspec = {
"size[14,10]",
"background[-0.19,-0.25;14.4,10.75;ui_form_bg.png]" -- Background
}
local n = 3
if draw_lite_mode then
formspec[1] = "size[11,7.7]"
formspec[2] = "background[-0.19,-0.2;11.4,8.4;ui_form_bg.png]"
end
if unified_inventory.is_creative(player_name)
and page == "craft" then
formspec[n] = "background[0,"..(ui_peruser.formspec_y + 2)..";1,1;ui_single_slot.png]"
n = n+1
end
-- Background
formspec = formspec .. "background[-0.19,-0.25;14.4,10.75;ui_form_bg.png]"
-- Current page
if unified_inventory.pages[page] then
fsdata = pagedef.get_formspec(player)
formspec = formspec .. fsdata.formspec
else
if not unified_inventory.pages[page] then
return "" -- Invalid page name
end
local perplayer_formspec = unified_inventory.get_per_player_formspec(player_name)
local fsdata = pagedef.get_formspec(player, perplayer_formspec)
formspec[n] = fsdata.formspec
n = n+1
local privs = minetest.get_player_privs(player_name) --Modif MFF (Crabman 13/10/2015) not show if player has not privs requiered
local button_row = 0
local button_col = 0
-- Main buttons
local filtered_inv_buttons = {}
for i, def in pairs(unified_inventory.buttons) do
local tooltip = def.tooltip or ""
if def.type == "image" then
formspec = formspec.."image_button["
..(0.65 * (i - 1))..",9;0.8,0.8;"
..minetest.formspec_escape(def.image)..";"
..minetest.formspec_escape(def.name)..";]"
.."tooltip["..minetest.formspec_escape(def.name)
..";"..tooltip.."]"
if not (draw_lite_mode and def.hide_lite) and (not def.show_with or (privs[def.show_with] and privs[def.show_with] == true)) then --Modif MFF (Crabman 13/10/2015) not show if player has not privs requiered
table.insert(filtered_inv_buttons, def)
end
end
local i = 1 --Modif MFF (Crabman 13/10/2015) 12 buttons max by row
for _, def in pairs(filtered_inv_buttons) do --Modif MFF (Crabman 13/10/2015)
if draw_lite_mode and i > 4 then
button_row = 1
button_col = 1
elseif not draw_lite_mode and i > 12 then --Modif MFF (Crabman 13/10/2015)
button_row = 1
i = 1
end
if def.type == "image" then
formspec[n] = "image_button["
formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4)
formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * 0.7)..";0.8,0.8;"
formspec[n+3] = minetest.formspec_escape(def.image)..";"
formspec[n+4] = minetest.formspec_escape(def.name)..";]"
formspec[n+5] = "tooltip["..minetest.formspec_escape(def.name)
formspec[n+6] = ";"..(def.tooltip or "").."]"
n = n+7
end
i = i + 1 --Modif MFF (Crabman 13/10/2015)
end
if fsdata.draw_inventory ~= false then
-- Player inventory
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec .. "list[current_player;main;0,4.5;8,4;]"
formspec[n] = "listcolors[#00000000;#00000000]"
formspec[n+1] = "list[current_player;main;0,"..(ui_peruser.formspec_y + 3.5)..";8,4;]"
n = n+2
end
if fsdata.draw_item_list == false then
return formspec
return table.concat(formspec, "")
end
if not unified_inventory.hidden_guide[player_name] then --MFF crabman(29/11/2015) hide guide, textfield bug
formspec[n] = "image_button[13.2,0.1;.8,.8;ui_on_icon.png;hidebutton;]"
.. "tooltip[hidebutton;" ..F("Hide guide") .. "]"
n = n+1
else
formspec[n] = "image_button[13.2,0.1;.8,.8;ui_off_icon.png;hidebutton;]"
.. "tooltip[hidebutton;" ..F("Show guide") .. "]"
return table.concat(formspec, "")
end
-- Controls to flip items pages
local start_x = 9.2
formspec = formspec
.. "image_button[" .. (start_x + 0.6 * 0)
.. ",9;.8,.8;ui_skip_backward_icon.png;start_list;]"
.. "tooltip[start_list;" .. minetest.formspec_escape(S("First page")) .. "]"
.. "image_button[" .. (start_x + 0.6 * 1)
.. ",9;.8,.8;ui_doubleleft_icon.png;rewind3;]"
.. "tooltip[rewind3;" .. minetest.formspec_escape(S("Back three pages")) .. "]"
if not draw_lite_mode then
formspec[n] =
"image_button[" .. (start_x + 0.6 * 0)
.. ",9;.8,.8;ui_skip_backward_icon.png;start_list;]"
.. "tooltip[start_list;" .. F("First page") .. "]"
.. "image_button[" .. (start_x + 0.6 * 2)
.. ",9;.8,.8;ui_left_icon.png;rewind1;]"
.. "tooltip[rewind1;" .. minetest.formspec_escape(S("Back one page")) .. "]"
.. "image_button[" .. (start_x + 0.6 * 1)
.. ",9;.8,.8;ui_doubleleft_icon.png;rewind3;]"
.. "tooltip[rewind3;" .. F("Back three pages") .. "]"
.. "image_button[" .. (start_x + 0.6 * 2)
.. ",9;.8,.8;ui_left_icon.png;rewind1;]"
.. "tooltip[rewind1;" .. F("Back one page") .. "]"
.. "image_button[" .. (start_x + 0.6 * 3)
.. ",9;.8,.8;ui_right_icon.png;forward1;]"
.. "tooltip[forward1;" .. minetest.formspec_escape(S("Forward one page")) .. "]"
.. "image_button[" .. (start_x + 0.6 * 3)
.. ",9;.8,.8;ui_right_icon.png;forward1;]"
.. "tooltip[forward1;" .. F("Forward one page") .. "]"
.. "image_button[" .. (start_x + 0.6 * 4)
.. ",9;.8,.8;ui_doubleright_icon.png;forward3;]"
.. "tooltip[forward3;" .. F("Forward three pages") .. "]"
.. "image_button[" .. (start_x + 0.6 * 4)
.. ",9;.8,.8;ui_doubleright_icon.png;forward3;]"
.. "tooltip[forward3;" .. minetest.formspec_escape(S("Forward three pages")) .. "]"
.. "image_button[" .. (start_x + 0.6 * 5)
.. ",9;.8,.8;ui_skip_forward_icon.png;end_list;]"
.. "tooltip[end_list;" .. minetest.formspec_escape(S("Last page")) .. "]"
.. "image_button[" .. (start_x + 0.6 * 5)
.. ",9;.8,.8;ui_skip_forward_icon.png;end_list;]"
.. "tooltip[end_list;" .. F("Last page") .. "]"
else
formspec[n] =
"image_button[" .. (8.2 + 0.65 * 0)
.. ",5.8;.8,.8;ui_skip_backward_icon.png;start_list;]"
.. "tooltip[start_list;" .. F("First page") .. "]"
.. "image_button[" .. (8.2 + 0.65 * 1)
.. ",5.8;.8,.8;ui_left_icon.png;rewind1;]"
.. "tooltip[rewind1;" .. F("Back one page") .. "]"
.. "image_button[" .. (8.2 + 0.65 * 2)
.. ",5.8;.8,.8;ui_right_icon.png;forward1;]"
.. "tooltip[forward1;" .. F("Forward one page") .. "]"
.. "image_button[" .. (8.2 + 0.65 * 3)
.. ",5.8;.8,.8;ui_skip_forward_icon.png;end_list;]"
.. "tooltip[end_list;" .. F("Last page") .. "]"
end
n = n+1
-- Search box
formspec = formspec .. "field[9.5,8.325;3,1;searchbox;;"
.. minetest.formspec_escape(unified_inventory.current_searchbox[player_name]) .. "]"
formspec = formspec .. "image_button[12.2,8.1;.8,.8;ui_search_icon.png;searchbutton;]"
.. "tooltip[searchbutton;" ..S("Search") .. "]"
formspec[n] = "field_close_on_enter[searchbox;false]"
n = n+1
if not draw_lite_mode then
formspec[n] = "field[9.5,8.325;3,1;searchbox;;"
.. minetest.formspec_escape(unified_inventory.current_searchbox[player_name]) .. "]"
formspec[n+1] = "image_button[12.2,8.1;.8,.8;ui_search_icon.png;searchbutton;]"
.. "tooltip[searchbutton;" ..F("Search") .. "]"
formspec[n+2] = "image_button[12.9,8.1;.8,.8;ui_reset_icon.png;searchresetbutton;]"
.. "tooltip[searchbutton;" ..F("Search") .. "]"
.. "tooltip[searchresetbutton;" ..F("Reset search and display everything") .. "]"
else
formspec[n] = "field[8.5,5.225;2.2,1;searchbox;;"
.. minetest.formspec_escape(unified_inventory.current_searchbox[player_name]) .. "]"
formspec[n+1] = "image_button[10.3,5;.8,.8;ui_search_icon.png;searchbutton;]"
.. "tooltip[searchbutton;" ..F("Search") .. "]"
formspec[n+2] = "image_button[11,5;.8,.8;ui_reset_icon.png;searchresetbutton;]"
.. "tooltip[searchbutton;" ..F("Search") .. "]"
.. "tooltip[searchresetbutton;" ..F("Reset search and display everything") .. "]"
end
n = n+3
local no_matches = "No matching items"
if draw_lite_mode then
no_matches = "No matches."
end
-- Items list
if #unified_inventory.filtered_items_list[player_name] == 0 then
formspec = formspec.."label[8.2,0;" .. S("No matching items") .. "]"
formspec[n] = "label[8.2,"..ui_peruser.form_header_y..";" .. F(no_matches) .. "]"
else
local dir = unified_inventory.active_search_direction[player_name]
local list_index = unified_inventory.current_index[player_name]
local page = math.floor(list_index / (80) + 1)
local page = math.floor(list_index / (ui_peruser.items_per_page) + 1)
local pagemax = math.floor(
(#unified_inventory.filtered_items_list[player_name] - 1)
/ (80) + 1)
/ (ui_peruser.items_per_page) + 1)
local item = {}
for y = 0, 9 do
for x = 0, 7 do
local name = unified_inventory.filtered_items_list[player_name][list_index]
if minetest.registered_items[name] then
formspec = formspec.."item_image_button["
for y = 0, ui_peruser.pagerows - 1 do
for x = 0, ui_peruser.pagecols - 1 do
local name = unified_inventory.filtered_items_list[player_name][list_index]
if minetest.registered_items[name] then
-- Clicked on current item: Flip crafting direction
if name == unified_inventory.current_item[player_name] then
local cdir = unified_inventory.current_craft_direction[player_name]
if cdir == "recipe" then
dir = "usage"
elseif cdir == "usage" then
dir = "recipe"
end
else
-- Default: use active search direction by default
dir = unified_inventory.active_search_direction[player_name]
end
formspec[n] = "item_image_button["
..(8.2 + x * 0.7)..","
..(1 + y * 0.7)..";.81,.81;"
..(ui_peruser.formspec_y + ui_peruser.page_y + y * 0.7)..";.81,.81;"
..name..";item_button_"..dir.."_"
..unified_inventory.mangle_for_formspec(name)..";]"
list_index = list_index + 1
n = n+1
list_index = list_index + 1
end
end
end
end
formspec = formspec.."label[8.2,0;"..S("Page") .. ": "
formspec[n] = "label[8.2,"..ui_peruser.form_header_y..";"..F("Page") .. ": "
.. S("%s of %s"):format(page,pagemax).."]"
end
n= n+1
if unified_inventory.activefilter[player_name] ~= "" then
formspec = formspec.."label[8.2,0.4;" .. S("Filter") .. ":]"
formspec = formspec.."label[9,0.4;"..minetest.formspec_escape(unified_inventory.activefilter[player_name]).."]"
formspec[n] = "label[8.2,"..(ui_peruser.form_header_y + 0.4)..";" .. F("Filter") .. ":]"
formspec[n+1] = "label[9.1,"..(ui_peruser.form_header_y + 0.4)..";"..minetest.formspec_escape(unified_inventory.activefilter[player_name]).."]"
end
return formspec
return table.concat(formspec, "")
end
function unified_inventory.set_inventory_formspec(player, page)
if player then
local formspec = unified_inventory.get_formspec(player, page)
player:set_inventory_formspec(formspec)
player:set_inventory_formspec(unified_inventory.get_formspec(player, page))
end
end
--apply filter to the inventory list (create filtered copy of full one)
function unified_inventory.apply_filter(player, filter, search_dir)
if not player then
return false
end
local player_name = player:get_player_name()
local lfilter = string.lower(filter)
local ffilter
@ -147,7 +283,8 @@ function unified_inventory.apply_filter(player, filter, search_dir)
local groups = lfilter:sub(7):split(",")
ffilter = function(name, def)
for _, group in ipairs(groups) do
if not ((def.groups[group] or 0) > 0) then
if not def.groups[group]
or def.groups[group] <= 0 then
return false
end
end
@ -162,7 +299,13 @@ function unified_inventory.apply_filter(player, filter, search_dir)
end
unified_inventory.filtered_items_list[player_name]={}
for name, def in pairs(minetest.registered_items) do
if (def.groups.not_in_creative_inventory or 0) == 0 and (def.description or "") ~= "" and ffilter(name, def) then
if (not def.groups.not_in_creative_inventory
or def.groups.not_in_creative_inventory == 0)
and def.description
and def.description ~= ""
and ffilter(name, def)
and (unified_inventory.is_creative(player_name)
or unified_inventory.crafts_for.recipe[def.name]) then
table.insert(unified_inventory.filtered_items_list[player_name], name)
end
end
@ -172,7 +315,7 @@ function unified_inventory.apply_filter(player, filter, search_dir)
unified_inventory.activefilter[player_name] = filter
unified_inventory.active_search_direction[player_name] = search_dir
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
unified_inventory.current_page[player_name])
end
function unified_inventory.items_in_group(groups)

42
item_names.lua Normal file → Executable file
View File

@ -1,25 +1,20 @@
-- code based on 4itemnames mod by 4aiman
-- Based on 4itemnames mod by 4aiman
local wield = {}
local huds = {}
local dtimes = {}
local dlimit = 3 -- hud will be hidden after this much seconds
local airhudmod = minetest.get_modpath("4air")
local dlimit = 3 -- HUD element will be hidden after this many seconds
local air_hud_mod = minetest.get_modpath("4air")
local hud_mod = minetest.get_modpath("hud")
local hudbars_mod = minetest.get_modpath("hudbars")
local function get_desc(item)
if minetest.registered_nodes[item] then return minetest.registered_nodes[item]["description"] end
if minetest.registered_items[item] then return minetest.registered_items[item]["description"] end
if minetest.registered_craftitems[item] then return minetest.registered_craftitems[item]["description"] end
if minetest.registered_tools[item] then return minetest.registered_tools[item]["description"] end
return ""
end
minetest.register_on_joinplayer(function(player)
minetest.after(0.0, function()
local player_name = player:get_player_name()
local function set_hud(player)
local player_name = player:get_player_name()
local off = {x=0, y=-70}
if airhudmod then
off.y=off.y-20
if air_hud_mod or hud_mod then
off.y = off.y - 20
elseif hudbars_mod then
off.y = off.y + 5
end
huds[player_name] = player:hud_add({
hud_elem_type = "text",
@ -29,13 +24,14 @@ minetest.register_on_joinplayer(function(player)
number = 0xFFFFFF ,
text = "",
})
--print(dump("item hud id: "..huds[player_name]))
end)
end
minetest.register_on_joinplayer(function(player)
minetest.after(0, set_hud, player)
end)
minetest.register_globalstep(function(dtime)
local players = minetest.get_connected_players()
for i,player in ipairs(players) do
for _, player in pairs(minetest.get_connected_players()) do
local player_name = player:get_player_name()
local wstack = player:get_wielded_item():get_name()
@ -48,11 +44,13 @@ minetest.register_globalstep(function(dtime)
if wstack ~= wield[player_name] then
wield[player_name] = wstack
local desc = get_desc(wstack)
dtimes[player_name] = 0
if huds[player_name] then
if huds[player_name] then
local def = minetest.registered_items[wstack]
local desc = def and def.description or ""
player:hud_change(huds[player_name], 'text', desc)
end
end
end
end)

136
locale/de.txt Normal file → Executable file
View File

@ -1,71 +1,101 @@
# Translation by Xanthin
# Translation mostly by Xanthin
### api.lua ###
Digging (by chance) = Graben (durch Zufall)
### bags.lua ###
Bags = Rucksaecke
Bag 1 = Rucksack 1
Bag 2 = Rucksack 2
Bag 3 = Rucksack 3
Bag 4 = Rucksack 4
Small Bag = Rucksack (klein)
Medium Bag = Rucksack (mittel)
Large Bag = Rucksack (gross)
Bags = Taschen
Bag 1 = Tasche 1
Bag 2 = Tasche 2
Bag 3 = Tasche 3
Bag 4 = Tasche 4
Small Bag = Kleine Tasche
Medium Bag = Mittelgroße Tasche
Large Bag = Große Tasche
### inernal.lua ###
First page =
Back three pages =
Back one page =
Forward one page =
Forward three pages =
Last page =
No matching items =
First page = Erste Seite
Back three pages = Drei Seiten zurueckblättern
Back one page = Eine Seite zurueckblättern
Forward one page = Eine Seite vorblättern
Forward three pages = Drei Seiten vorblättern
Last page = Letzte Seite
No matching items = Keine passenden Gegenstände
Page = Seite
%s of %s = %s von %s
Filter = Suche
Search =
Filter = Filter
Search = Suchen
Reset search and display everything = Suche zurücksetzen und alles anzeigen
### register.lua ###
Can use the creative inventory = Kann das Kreativinventar nutzen
Home position set to: %s = Ausgangsposition nach: %s gesetzt
Time of day set to 6am = Tageszeit auf 6 Uhr morgens geaendert
You don't have the settime priviledge! = Du hast nicht das "settime" Privileg!
Time of day set to 9pm = Tageszeit auf 9 Uhr abends geaendert
This button has been disabled outside of creative mode to prevent accidental inventory trashing. Use the trash slot instead. = Diese Funktion ist ausserhalb des Kreativmodus deaktiviert um ein versehentliches Loeschen des ganzen Inventars zu verhindern.\nNutze stattdessen das Muellfeld.
Inventory Cleared! = Inventar geleert!
Crafting = Bauen
Trash: = Muell:
Refill: = Nachfuellen:
Crafting Guide = Bauanleitung
Home position set to: %s = Heimatposition nach: %s gesetzt
Time of day set to 6am = Tageszeit auf 6 Uhr geändert
You don't have the settime privilege! = Du hast nicht das „settime“-Privileg!
Time of day set to 9pm = Tageszeit auf 21 Uhr geändert
This button has been disabled outside of creative mode to prevent accidental inventory trashing. Use the trash slot instead. = Diese Funktion ist außerhalb des Kreativmodus deaktiviert, um ein versehentliches Löschen des ganzen Inventars zu verhindern.\nNutze stattdessen das Müllfeld.
Inventory cleared! = Inventar geleert!
Crafting = Fertigung
Digging = Graben
Cooking = Kochen
Mixing = Mischen
Trash: = Müll:
Refill: = Nachfüllen:
Crafting Guide = Fertigungsführer
Method: = Methode:
Result: %s = Ergebnis: %s
crafting = Bauen
shapeless crafting = Formloses Bauen
shapeless crafting = Formlose Fertigung
cooking = Kochen
alloy cooking = Legierung Kochen
Copy to craft grid: = Kopiere ins Baufeld:
Copy to craft grid: = Ins Fertigungsraster kopieren:
All = Alles
Recipe %s of %s = Rezept %s von %s
Alternate = Alternative
Crafting Grid =
Crafting Grid = Fertigungsraster
Show next recipe = Nächstes Rezept zeigen
Show next usage = Nächste Verwendung zeigen
Show previous recipe = Vorheriges Rezept zeigen
Show previous usage = Vorherige Verwendung zeigen
This recipe is too\nlarge to be displayed. = Dieses Rezept ist zu\ngroß, um angezeigt\nzu werden.
Any item belonging to the %s group = Irgendein Gegenstand, der zur Gruppe %s gehört
Any item belonging to the groups %s = Irgendein Gegenstand, der zu den Gruppen %s gehört
Recipe %d of %d = Rezept %d von %d
Usage %d of %d = Verwendung %d von %d
No recipes = Keine Rezepte
No usages = Keine Verwendungen
Result = Ergebnis
Ingredient = Zutat
Set time to day = Zur Tageszeit wechseln
Set time to night = Zur Nachtzeit wechseln
Set home position = Heimatposition setzen
Go home = Nach Hause gehen
Clear inventory = Inventar leeren
Give me: = Gib mir:
To craft grid: = Ins Fertigungsraster:
### group.lua ###
\sand\s=\sund\s
### waypoints.lua ###
White =
Yellow =
Red =
Green =
Blue =
Waypoints =
Waypoint active =
Waypoint inactive =
World position =
Name =
HUD text color =
Edit waypoint name =
Rename waypoint =
Change color of waypoint display =
Set waypoint to current location =
Make waypoint visible =
Make waypoint invisible =
Disable display of waypoint coordinates =
Enable display of waypoint coordinates =
Finish editing =
Select Waypoint #%d =
White = Weiß
Yellow = Gelb
Red = Rot
Green = Grün
Blue = Blau
Waypoints = Wegpunkte
Waypoint %d = Wegpunkt Nr. %d
Waypoint active = Wegpunkt aktiv
Waypoint inactive = Wegpunkt inaktiv
World position = Weltposition
Name = Name
HUD text color = HUD-Textfarbe
Edit waypoint name = Name des Wegpunkts ändern
Rename waypoint = Wegpunkt umbenennen
Change color of waypoint display = Farbe der Darstellung der Wegpunkte ändern
Set waypoint to current location = Setze Wegpunkt zur derzeitigen Position
Make waypoint visible = Wegpunkt sichtbar machen
Make waypoint invisible = Wegpunkt verstecken
Disable display of waypoint coordinates = Anzeige der Wegpunktkoordinaten deaktivieren
Enable display of waypoint coordinates = Anzeige der Wegpunktkoordinaten aktivieren
Finish editing = Bearbeitung abschließen
Select Waypoint #%d = Wegpunkt Nr. %d auswählen

2
locale/es.txt Normal file → Executable file
View File

@ -31,7 +31,7 @@ Time of day set to 6am = Hora del día cambiada a 6AM
You don't have the settime priviledge! = ¡No tienes el privilegio `settime'!
Time of day set to 9pm = Hora del día cambiada a 9PM
This button has been disabled outside of creative mode to prevent accidental inventory trashing. Use the trash slot instead. = Éste botón ha sido deshabilitado para prevenir la destrucción accidental del inventario.\nUsa la ranura para basura en su lugar.
Inventory Cleared! = ¡Inventario limpio!
Inventory cleared! = ¡Inventario limpio!
Crafting = Elaboración
Trash: = Basura:
Refill: = Rellenar:

2
locale/fr.txt Normal file → Executable file
View File

@ -31,7 +31,7 @@ Time of day set to 6am = Heure fixée à 6h
You don't have the settime priviledge! = Vous n'avez pas le privilège 'settime' !
Time of day set to 9pm = Heure fixée à 21h
This button has been disabled outside of creative mode to prevent accidental inventory trashing.\nUse the trash slot instead. = Ce bouton a été désactivé en dehors du mode créatif pour éviter des saccages dans l'inventaire.\nUtilisez plutôt la case poubelle.
Inventory Cleared! = Inventaire vidé !
Inventory cleared! = Inventaire vidé !
Crafting = Création
Trash: = Poubelle :
Refill: = Remplir :

2
locale/pl.txt Normal file → Executable file
View File

@ -30,7 +30,7 @@ Time of day set to 6am = Czas ustawiony na 6:00
You don't have the settime priviledge! = Nie masz uprawnien do zmiany czasu (settime)!
Time of day set to 9pm = Czas ustawiony na 21:00
This button has been disabled outside of creative mode to prevent accidental inventory trashing.\nUse the trash slot instead. =
Inventory Cleared! =
Inventory cleared! =
Crafting =
Trash: = Smietnik:
Refill: = Uzupelnianie:

2
locale/ru.txt Normal file → Executable file
View File

@ -31,7 +31,7 @@ Time of day set to 6am = Установлено время 6 утра
You don't have the settime priviledge! = Вам не разрешено устанавливать время!
Time of day set to 9pm = Установлено время 9 вечера
This button has been disabled outside of creative mode to prevent accidental inventory trashing.\nUse the trash slot instead. = Эта кнопка отключена вне творческого режима, чтобы предотвратить случайное уничтожение предметов.\nИспользуйте слот корзины вместо нее.
Inventory Cleared! = Инвентарь очищен!
Inventory cleared! = Инвентарь очищен!
Crafting = Крафт
Trash: = Корзина:
Refill: = Размножить:

39
locale/template.txt Normal file → Executable file
View File

@ -1,5 +1,8 @@
# Translation by
### api.lua ###
Digging (by chance) =
# Template
### bags.lua ###
Bags =
@ -23,16 +26,21 @@ Page =
%s of %s =
Filter =
Search =
Reset search and display everything =
### register.lua ###
Can use the creative inventory =
Forces Unified Inventory to be displayed in Full mode if Lite mode is configured globally =
Home position set to: %s =
Time of day set to 6am =
You don't have the settime priviledge! =
Time of day set to 9pm =
This button has been disabled outside of creative mode to prevent accidental inventory trashing.\nUse the trash slot instead. =
Inventory Cleared! =
Inventory cleared! =
Crafting =
Digging =
Cooking =
Mixing =
Trash: =
Refill: =
Crafting Guide =
@ -44,9 +52,35 @@ cooking =
alloy cooking =
Copy to craft grid: =
All =
Recipe %s of %s =
Alternate =
Crafting Grid =
Show next recipe =
Show next usage =
Show previous recipe =
Show previous usage =
# Shown for huge crafting recipes; try to keep the line length short and use multiple line breaks as needed
This recipe is too\nlarge to be displayed. =
# %s = group name (e.g. wool)
Any item belonging to the %s group =
# %s = List of “and”-concatenated group names
Any item belonging to the groups %s =
Recipe %d of %d =
Usage %d of %d =
No recipes =
No usages =
Result =
Ingredient =
Set time to day =
Set time to night =
Set home position =
Go home =
Clear inventory =
Give me: =
To craft grid: =
### group.lua ###
# Logical connective, example: “Any item belonging to the groups foo and bar”
\sand\s =
### waypoints.lua ###
White =
@ -55,6 +89,7 @@ Red =
Green =
Blue =
Waypoints =
Waypoint %d =
Waypoint active =
Waypoint inactive =
World position =

72
locale/tr.txt Executable file
View File

@ -0,0 +1,72 @@
# Translation by Mahmutelmas06@hotmail.com
# Template
### bags.lua ###
Bags = Çantalarım
Bag 1 = 1. Çanta
Bag 2 = 2. Çanta
Bag 3 = 3. Çanta
Bag 4 = 4. Çanta
Small Bag = Küçük Çanta
Medium Bag = Çanta
Large Bag = Büyük Çanta
### inernal.lua ###
First page = İlk Sayfa
Back three pages = 3 Sayfa Gerile
Back one page = Geri
Forward one page = İleri
Forward three pages = 3 Sayfa İlerile
Last page = Son Sayfa
No matching items = Eşleşme yok
Page = Sayfa
%s of %s = %s dan %s
Filter = Süzgeç
Search = Ara
### register.lua ###
Can use the creative inventory = Yaratıcı envanteri kullanabilir
Home position set to: %s = Yeni eviniz: %s
Time of day set to 6am = Saat 06:00 olarak ayarlandı
You don't have the settime priviledge = Saati düzenleme yetkiniz yok!
Time of day set to 9pm = Saat 19:00 olarak ayarlandı
This button has been disabled outside of creative mode to prevent accidental inventory trashing.\nUse the trash slot instead. = Yaratıcı modu dışında iken bu tuş kullanılamaz.
Inventory cleared! = Envanter temizlendi!
Crafting = Üretim
Trash: = Çöp
Refill: = Doldur
Crafting Guide = Kılavuz
Method: = Yöntem
Result: %s = Çıktı: %s
crafting = üretim
shapeless crafting = şekilsiz üretim
cooking = pişirme
alloy cooking = karıştırma
Copy to craft grid: = Üretim tablosuna kopyala
All = Tümü
Recipe %s of %s = %s dan %s tarifi
Alternate = Altarnatif
Crafting Grid = Üretim tablosu
### waypoints.lua ###
White = Beyaz
Yellow = Sarı
Red = Kırmızı
Green = Yeşil
Blue = Mavi
Waypoints = Konum Noktaları
Waypoint active = Konum Etkin
Waypoint inactive = Konum Devredışı
World position = Dünya konumu
Name = İsim
HUD text color = Metin rengi
Edit waypoint name = Konum Noktasını Düzenle
Rename waypoint = Konum Noktasını Adlandır
Change color of waypoint display = Konum Gösterge Rengi
Set waypoint to current location = Bulunduğun noktayı işaretle
Make waypoint visible = Konumlar görünür
Make waypoint invisible = Konumlar gözükmez
Disable display of waypoint coordinates = Koordinatları gizle
Enable display of waypoint coordinates = Koordinatları göster
Finish editing = Düzenleme bitti
Select Waypoint #%d = #%d konum noktası seç

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name = unified_inventory

393
register.lua Normal file → Executable file
View File

@ -1,15 +1,17 @@
local S
if intllib then
S = intllib.Getter()
else
S = function(s) return s end
end
local S = unified_inventory.gettext
local F = unified_inventory.fgettext
minetest.register_privilege("creative", {
description = "Can use the creative inventory",
description = S("Can use the creative inventory"),
give_to_singleplayer = false,
})
minetest.register_privilege("ui_full", {
description = S("Forces Unified Inventory to be displayed in Full mode if Lite mode is configured globally"),
give_to_singleplayer = false,
})
local trash = minetest.create_detached_inventory("trash", {
--allow_put = function(inv, listname, index, stack, player)
-- if unified_inventory.is_creative(player:get_player_name()) then
@ -29,40 +31,67 @@ trash:set_size("main", 1)
unified_inventory.register_button("craft", {
type = "image",
image = "ui_craft_icon.png",
tooltip = S("Crafting Grid")
tooltip = S("Crafting Grid"),
show_with = false, --Modif MFF (Crabman 30/06/2015)
})
unified_inventory.register_button("craftguide", {
type = "image",
image = "ui_craftguide_icon.png",
tooltip = S("Crafting Guide")
tooltip = S("Crafting Guide"),
show_with = false, --Modif MFF (Crabman 30/06/2015)
})
--[[
unified_inventory.register_button("home_gui_set", {
type = "image",
image = "ui_sethome_icon.png",
tooltip = S("Set home position"),
hide_lite=true,
show_with = "interact", --Modif MFF (Crabman 30/06/2015)
action = function(player)
local player_name = player:get_player_name()
unified_inventory.set_home(player, player:getpos())
local home = unified_inventory.home_pos[player_name]
if home ~= nil then
minetest.sound_play("dingdong",
{to_player=player_name, gain = 1.0})
minetest.chat_send_player(player_name,
S("Home position set to: %s"):format(minetest.pos_to_string(home)))
end
end,
if home.sethome(player:get_player_name()) == true then --modif MFF
minetest.sound_play("dingdong",
{to_player=player:get_player_name(), gain = 1.0})
end
end,
})
unified_inventory.register_button("home_gui_go", {
type = "image",
image = "ui_gohome_icon.png",
tooltip = S("Go home"),
hide_lite=true,
show_with = "interact", --Modif MFF (Crabman 30/06/2015)
action = function(player)
minetest.sound_play("teleport",
if home.tohome(player:get_player_name()) == true then --modif MFF
minetest.sound_play("teleport",
{to_player=player:get_player_name(), gain = 1.0})
unified_inventory.go_home(player)
end
end,
})
--]]
if minetest.get_modpath("news") then
unified_inventory.register_button("news", {
type = "image",
image = "ui_news_icon.png",
tooltip = S("News"),
hide_lite = true,
show_with = "interact",
action = function(player)
core.chatcommands["news"].func(player:get_player_name())
end,
})
end
unified_inventory.register_button("home_gui_set", { --new h2omes
type = "image",
image = "ui_gohome_icon.png",
tooltip = S("My Homes"),
hide_lite=true,
show_with = "home", --Modif MFF (Crabman 30/06/2015)
action = function(player)
h2omes.show_formspec_home(player:get_player_name())
end,
})
@ -70,6 +99,8 @@ unified_inventory.register_button("misc_set_day", {
type = "image",
image = "ui_sun_icon.png",
tooltip = S("Set time to day"),
hide_lite=true,
show_with = "settime", --Modif MFF (Crabman 30/06/2015)
action = function(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {settime=true}) then
@ -80,7 +111,7 @@ unified_inventory.register_button("misc_set_day", {
S("Time of day set to 6am"))
else
minetest.chat_send_player(player_name,
S("You don't have the settime priviledge!"))
S("You don't have the settime privilege!"))
end
end,
})
@ -89,6 +120,8 @@ unified_inventory.register_button("misc_set_night", {
type = "image",
image = "ui_moon_icon.png",
tooltip = S("Set time to night"),
hide_lite=true,
show_with = "settime", --Modif MFF (Crabman 30/06/2015)
action = function(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {settime=true}) then
@ -99,7 +132,7 @@ unified_inventory.register_button("misc_set_night", {
S("Time of day set to 9pm"))
else
minetest.chat_send_player(player_name,
S("You don't have the settime priviledge!"))
S("You don't have the settime privilege!"))
end
end,
})
@ -108,6 +141,7 @@ unified_inventory.register_button("clear_inv", {
type = "image",
image = "ui_trash_icon.png",
tooltip = S("Clear inventory"),
show_with = "creative", --Modif MFF (Crabman 30/06/2015)
action = function(player)
local player_name = player:get_player_name()
if not unified_inventory.is_creative(player_name) then
@ -119,39 +153,39 @@ unified_inventory.register_button("clear_inv", {
return
end
player:get_inventory():set_list("main", {})
minetest.chat_send_player(player_name, 'Inventory Cleared!')
minetest.chat_send_player(player_name, S('Inventory cleared!'))
minetest.sound_play("trash_all",
{to_player=player_name, gain = 1.0})
end,
})
unified_inventory.register_page("craft", {
get_formspec = function(player, formspec)
get_formspec = function(player, perplayer_formspec)
local formspecy = perplayer_formspec.formspec_y
local formheadery = perplayer_formspec.form_header_y
local player_name = player:get_player_name()
local formspec = "background[0,1;8,3;ui_crafting_form.png]"
formspec = formspec.."background[0,4.5;8,4;ui_main_inventory.png]"
formspec = formspec.."label[0,0;Crafting]"
local formspec = "background[2,"..formspecy..";6,3;ui_crafting_form.png]"
formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]"
formspec = formspec.."label[0,"..formheadery..";" ..F("Crafting").."]"
formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;craftpreview;6,1;1,1;]"
formspec = formspec.."list[current_player;craft;2,1;3,3;]"
formspec = formspec.."label[7,2.5;" .. S("Trash:") .. "]"
formspec = formspec.."list[detached:trash;main;7,3;1,1;]"
formspec = formspec.."list[current_player;craftpreview;6,"..formspecy..";1,1;]"
formspec = formspec.."list[current_player;craft;2,"..formspecy..";3,3;]"
formspec = formspec.."label[7,"..(formspecy + 1.5)..";" .. F("Trash:") .. "]"
formspec = formspec.."list[detached:trash;main;7,"..(formspecy + 2)..";1,1;]"
formspec = formspec.."listring[current_name;craft]"
formspec = formspec.."listring[current_player;main]"
if unified_inventory.is_creative(player_name) then
formspec = formspec.."label[0,2.5;" .. S("Refill:") .. "]"
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."refill;main;0,3;1,1;]"
formspec = formspec.."label[0,"..(formspecy + 1.5)..";" .. F("Refill:") .. "]"
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."refill;main;0,"..(formspecy +2)..";1,1;]"
end
return {formspec=formspec}
end,
})
-- stack_image_button(): generate a form button displaying a stack of items
--
-- Normally a simple item_image_button[] is used. If the stack contains
-- more than one item, item_image_button[] doesn't have an option to
-- display an item count in the way that an inventory slot does, so
-- we have to fake it using the label facility.
--
-- The specified item may be a group. In that case, the group will be
-- represented by some item in the group, along with a flag indicating
-- that it's a group. If the group contains only one item, it will be
@ -161,7 +195,7 @@ local function stack_image_button(x, y, w, h, buttonname_prefix, item)
local name = item:get_name()
local count = item:get_count()
local show_is_group = false
local displayitem = name
local displayitem = name.." "..count
local selectitem = name
if name:sub(1, 6) == "group:" then
local group_name = name:sub(7)
@ -170,18 +204,30 @@ local function stack_image_button(x, y, w, h, buttonname_prefix, item)
displayitem = group_item.item or "unknown"
selectitem = group_item.sole and displayitem or name
end
local label = string.format("\n\n%s%7d", show_is_group and "G" or " ", count):gsub(" 1$", " .")
if label == "\n\n ." then label = "" end
return string.format("item_image_button[%u,%u;%u,%u;%s;%s;%s]",
local label = show_is_group and "G" or ""
local buttonname = minetest.formspec_escape(buttonname_prefix..unified_inventory.mangle_for_formspec(selectitem))
local button = string.format("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
x, y, w, h,
minetest.formspec_escape(displayitem),
minetest.formspec_escape(buttonname_prefix..unified_inventory.mangle_for_formspec(selectitem)),
label)
minetest.formspec_escape(displayitem), buttonname, label)
if show_is_group then
local groupstring, andcount = unified_inventory.extract_groupnames(name)
local grouptip
if andcount == 1 then
grouptip = string.format(S("Any item belonging to the %s group"), groupstring)
elseif andcount > 1 then
grouptip = string.format(S("Any item belonging to the groups %s"), groupstring)
end
grouptip = minetest.formspec_escape(grouptip)
if andcount >= 1 then
button = button .. string.format("tooltip[%s;%s]", buttonname, grouptip)
end
end
return button
end
local recipe_text = {
recipe = "Recipe",
usage = "Usage",
recipe = "Recipe %d of %d",
usage = "Usage %d of %d",
}
local no_recipe_text = {
recipe = "No recipes",
@ -191,22 +237,40 @@ local role_text = {
recipe = "Result",
usage = "Ingredient",
}
local next_alt_text = {
recipe = "Show next recipe",
usage = "Show next usage",
}
local prev_alt_text = {
recipe = "Show previous recipe",
usage = "Show previous usage",
}
local other_dir = {
recipe = "usage",
usage = "recipe",
}
unified_inventory.register_page("craftguide", {
get_formspec = function(player)
get_formspec = function(player, perplayer_formspec)
local formspecy = perplayer_formspec.formspec_y
local formheadery = perplayer_formspec.form_header_y
local craftresultx = perplayer_formspec.craft_result_x
local craftresulty = perplayer_formspec.craft_result_y
local player_name = player:get_player_name()
local player_privs = minetest.get_player_privs(player_name)
local formspec = ""
formspec = formspec.."background[0,4.5;8,4;ui_main_inventory.png]"
formspec = formspec.."label[0,0;" .. S("Crafting Guide") .. "]"
formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]"
formspec = formspec.."label[0,"..formheadery..";" .. F("Crafting Guide") .. "]"
formspec = formspec.."listcolors[#00000000;#00000000]"
local item_name = unified_inventory.current_item[player_name]
if not item_name then return {formspec=formspec} end
local dir = unified_inventory.current_craft_direction[player_name]
local rdir
if dir == "recipe" then rdir = "usage" end
if dir == "usage" then rdir = "recipe" end
local crafts = unified_inventory.crafts_for[dir][item_name]
local alternate = unified_inventory.alternate[player_name]
local alternates, craft
@ -215,68 +279,212 @@ unified_inventory.register_page("craftguide", {
craft = crafts[alternate]
end
formspec = formspec.."background[0,1;8,3;ui_craftguide_form.png]"
formspec = formspec.."textarea[0.3,0.6;10,1;;"..minetest.formspec_escape(role_text[dir]..": "..item_name)..";]"
formspec = formspec.."background[0.5,"..(formspecy + 0.2)..";8,3;ui_craftguide_form.png]"
formspec = formspec.."textarea["..craftresultx..","..craftresulty
..";10,1;;"..minetest.formspec_escape(F(role_text[dir])..": "..item_name)..";]"
formspec = formspec..stack_image_button(0, formspecy, 1.1, 1.1, "item_button_"
.. rdir .. "_", ItemStack(item_name))
if not craft then
formspec = formspec.."label[6,3.35;"..minetest.formspec_escape(no_recipe_text[dir]).."]"
local no_pos = dir == "recipe" and 4 or 6
local item_pos = dir == "recipe" and 6 or 4
formspec = formspec.."image["..no_pos..",1;1.1,1.1;ui_no.png]"
formspec = formspec..stack_image_button(item_pos, 1, 1.1, 1.1, "item_button_"..other_dir[dir].."_", ItemStack(item_name))
formspec = formspec.."label[5.5,"..(formspecy + 2.35)..";"
..minetest.formspec_escape(F(no_recipe_text[dir])).."]"
local no_pos = dir == "recipe" and 4.5 or 6.5
local item_pos = dir == "recipe" and 6.5 or 4.5
formspec = formspec.."image["..no_pos..","..formspecy..";1.1,1.1;ui_no.png]"
formspec = formspec..stack_image_button(item_pos, formspecy, 1.1, 1.1, "item_button_"
..other_dir[dir].."_", ItemStack(item_name))
if player_privs.give == true then
formspec = formspec.."label[0,"..(formspecy + 2.10)..";" .. F("Give me:") .. "]"
.."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
.."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
.."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
end
return {formspec = formspec}
end
local craft_type = unified_inventory.registered_craft_types[craft.type] or
unified_inventory.craft_type_defaults(craft.type, {})
formspec = formspec.."label[6,3.35;" .. S("Method:") .. "]"
formspec = formspec.."label[6,3.75;"
..minetest.formspec_escape(craft_type.description).."]"
formspec = formspec..stack_image_button(6, 1, 1.1, 1.1, "item_button_usage_", ItemStack(craft.output))
if craft_type.icon then
formspec = formspec..string.format(" image[%f,%f;%f,%f;%s]",5.7,(formspecy + 0.05),0.5,0.5,craft_type.icon)
end
formspec = formspec.."label[5.5,"..(formspecy + 1)..";" .. minetest.formspec_escape(craft_type.description).."]"
formspec = formspec..stack_image_button(6.5, formspecy, 1.1, 1.1, "item_button_usage_", ItemStack(craft.output))
local display_size = craft_type.dynamic_display_size and craft_type.dynamic_display_size(craft) or { width = craft_type.width, height = craft_type.height }
local craft_width = craft_type.get_shaped_craft_width and craft_type.get_shaped_craft_width(craft) or display_size.width
-- This keeps recipes aligned to the right,
-- so that they're close to the arrow.
local xoffset = 1 + (3 - display_size.width)
local xoffset = 5.5
-- Offset factor for crafting grids with side length > 4
local of = (3/math.max(3, math.max(display_size.width, display_size.height)))
local od = 0
-- Minimum grid size at which size optimazation measures kick in
local mini_craft_size = 6
if display_size.width >= mini_craft_size then
od = math.max(1, display_size.width - 2)
xoffset = xoffset - 0.1
end
-- Size modifier factor
local sf = math.min(1, of * (1.05 + 0.05*od))
-- Button size
local bsize_h = 1.1 * sf
local bsize_w = bsize_h
if display_size.width >= mini_craft_size then
bsize_w = 1.175 * sf
end
if (bsize_h > 0.35 and display_size.width) then
for y = 1, display_size.height do
for x = 1, display_size.width do
local item
if craft and x <= craft_width then
item = craft.items[(y-1) * craft_width + x]
end
-- Flipped x, used to build formspec buttons from right to left
local fx = display_size.width - (x-1)
-- x offset, y offset
local xof = (fx-1) * of + of
local yof = (y-1) * of + 1
if item then
formspec = formspec..stack_image_button(
xoffset + x, y, 1.1, 1.1,
xoffset - xof, formspecy - 1 + yof, bsize_w, bsize_h,
"item_button_recipe_",
ItemStack(item))
else
-- Fake buttons just to make grid
formspec = formspec.."image_button["
..tostring(xoffset + x)..","..tostring(y)
..";1,1;ui_blank_image.png;;]"
..tostring(xoffset - xof)..","..tostring(formspecy - 1 + yof)
..";"..bsize_w..","..bsize_h..";ui_blank_image.png;;]"
end
end
end
else
-- Error
formspec = formspec.."label["
..tostring(2)..","..tostring(formspecy)
..";"..minetest.formspec_escape(S("This recipe is too\nlarge to be displayed.")).."]"
end
if craft_type.uses_crafting_grid then
formspec = formspec.."label[6,1.95;" .. S("Copy to craft grid:") .. "]"
.."button[6,2.5;0.6,0.5;craftguide_craft_1;1]"
.."button[6.6,2.5;0.6,0.5;craftguide_craft_10;10]"
.."button[7.2,2.5;0.6,0.5;craftguide_craft_max;" .. S("All") .. "]"
if craft_type.uses_crafting_grid and display_size.width <= 3 then
formspec = formspec.."label[0,"..(formspecy + 0.9)..";" .. F("To craft grid:") .. "]"
.."button[0, "..(formspecy + 1.5)..";0.6,0.5;craftguide_craft_1;1]"
.."button[0.6,"..(formspecy + 1.5)..";0.7,0.5;craftguide_craft_10;10]"
.."button[1.3,"..(formspecy + 1.5)..";0.8,0.5;craftguide_craft_max;" .. F("All") .. "]"
end
if player_privs.give then
formspec = formspec.."label[0,"..(formspecy + 2.1)..";" .. F("Give me:") .. "]"
.."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
.."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
.."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
end
if alternates and alternates > 1 then
formspec = formspec.."label[0,2.6;"..recipe_text[dir].." "
..tostring(alternate).." of "
..tostring(alternates).."]"
.."button[0,3.15;2,1;alternate;" .. S("Alternate") .. "]"
formspec = formspec.."label[5.5,"..(formspecy + 1.6)..";"
..string.format(F(recipe_text[dir]), alternate, alternates).."]"
.."image_button[5.5,"..(formspecy + 2)..";1,1;ui_left_icon.png;alternate_prev;]"
.."image_button[6.5,"..(formspecy + 2)..";1,1;ui_right_icon.png;alternate;]"
.."tooltip[alternate_prev;"..F(prev_alt_text[dir]).."]"
.."tooltip[alternate;"..F(next_alt_text[dir]).."]"
end
return {formspec = formspec}
end,
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
local function craftguide_giveme(player, formname, fields)
local amount
for k, v in pairs(fields) do
amount = k:match("craftguide_giveme_(.*)")
if amount then break end
end
if not amount then return end
amount = tonumber(amount)
if amount == 0 then return end
local player_name = player:get_player_name()
local output = unified_inventory.current_item[player_name]
if (not output) or (output == "") then return end
local player_inv = player:get_inventory()
player_inv:add_item("main", {name = output, count = amount})
end
-- tells if an item can be moved and returns an index if so
local function item_fits(player_inv, craft_item, needed_item)
local need_group = string.sub(needed_item, 1, 6) == "group:"
if need_group then
need_group = string.sub(needed_item, 7)
end
if craft_item
and not craft_item:is_empty() then
local ciname = craft_item:get_name()
-- abort if the item there isn't usable
if ciname ~= needed_item
and not need_group then
return
end
-- abort if no item fits onto it
if craft_item:get_count() >= craft_item:get_definition().stack_max then
return
end
-- use the item there if it's in the right group and a group item is needed
if need_group then
if minetest.get_item_group(ciname, need_group) == 0 then
return
end
needed_item = ciname
need_group = false
end
end
if need_group then
-- search an item of the specific group
for i,item in pairs(player_inv:get_list("main")) do
if not item:is_empty()
and minetest.get_item_group(item:get_name(), need_group) > 0 then
return i
end
end
-- no index found
return
end
-- search an item with a the name needed_item
for i,item in pairs(player_inv:get_list("main")) do
if not item:is_empty()
and item:get_name() == needed_item then
return i
end
end
-- no index found
end
-- modifies the player inventory and returns the changed craft_item if possible
local function move_item(player_inv, craft_item, needed_item)
local stackid = item_fits(player_inv, craft_item, needed_item)
if not stackid then
return
end
local wanted_stack = player_inv:get_stack("main", stackid)
local taken_item = wanted_stack:take_item()
player_inv:set_stack("main", stackid, wanted_stack)
if not craft_item
or craft_item:is_empty() then
return taken_item
end
craft_item:add_item(taken_item)
return craft_item
end
local function craftguide_craft(player, formname, fields)
local amount
for k, v in pairs(fields) do
amount = k:match("craftguide_craft_(.*)")
@ -308,11 +516,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
width = 3
end
amount = tonumber(amount) or 99
--[[
if amount == "max" then
amount = 99 -- Arbitrary; need better way to do this.
else
amount = tonumber(amount)
end
end--]]
for iter = 1, amount do
local index = 1
@ -322,17 +532,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if needed_item then
local craft_index = ((y - 1) * 3) + x
local craft_item = craft_list[craft_index]
if (not craft_item) or (craft_item:is_empty()) or (craft_item:get_name() == needed_item) then
itemname = craft_item and craft_item:get_name() or needed_item
local needed_stack = ItemStack(needed_item)
if player_inv:contains_item("main", needed_stack) then
local count = (craft_item and craft_item:get_count() or 0) + 1
if count <= needed_stack:get_definition().stack_max then
local stack = ItemStack({name=needed_item, count=count})
craft_list[craft_index] = stack
player_inv:remove_item("main", needed_stack)
end
end
local newitem = move_item(player_inv, craft_item, needed_item)
if newitem then
craft_list[craft_index] = newitem
end
end
index = index + 1
@ -343,4 +545,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
player_inv:set_list("craft", craft_list)
unified_inventory.set_inventory_formspec(player, "craft")
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
for k, v in pairs(fields) do
if k:match("craftguide_craft_") then
craftguide_craft(player, formname, fields)
return
end
if k:match("craftguide_giveme_") then
craftguide_giveme(player, formname, fields)
return
end
end
end)

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

BIN
sounds/birds.ogg Normal file → Executable file

Binary file not shown.

BIN
sounds/click.ogg Normal file → Executable file

Binary file not shown.

BIN
sounds/dingdong.ogg Normal file → Executable file

Binary file not shown.

BIN
sounds/electricity.ogg Normal file → Executable file

Binary file not shown.

BIN
sounds/owl.ogg Normal file → Executable file

Binary file not shown.

BIN
sounds/paperflip1.ogg Normal file → Executable file

Binary file not shown.

BIN
sounds/paperflip2.ogg Normal file → Executable file

Binary file not shown.

BIN
sounds/teleport.ogg Normal file → Executable file

Binary file not shown.

BIN
sounds/trash.ogg Normal file → Executable file

Binary file not shown.

BIN
sounds/trash_all.ogg Normal file → Executable file

Binary file not shown.

BIN
textures/bags_large.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

BIN
textures/bags_medium.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

BIN
textures/bags_small.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 688 B

After

Width:  |  Height:  |  Size: 358 B

BIN
textures/ui_2_icon.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 715 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 856 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 727 B

BIN
textures/ui_bags_icon.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
textures/ui_bags_lg_form.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 378 B

BIN
textures/ui_bags_main_form.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 503 B

BIN
textures/ui_bags_med_form.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 367 B

BIN
textures/ui_bags_sm_form.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 355 B

BIN
textures/ui_blank_image.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 B

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 234 B

BIN
textures/ui_circular_arrows_icon.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 277 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 724 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 234 B

BIN
textures/ui_group.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 689 B

BIN
textures/ui_main_inventory.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 321 B

BIN
textures/ui_misc_form.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 408 B

BIN
textures/ui_moon_icon.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
textures/ui_news_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 234 B

BIN
textures/ui_reset_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 535 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 696 B

BIN
textures/ui_single_slot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 678 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
textures/ui_waypoint_set_icon.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
textures/ui_waypoints_icon.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
textures/ui_xyz_icon.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
textures/ui_xyz_on_icon.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

47
waypoints.lua Normal file → Executable file
View File

@ -1,9 +1,5 @@
local S
if intllib then
S = intllib.Getter()
else
S = function(s) return s end
end
local S = unified_inventory.gettext
local F = unified_inventory.fgettext
local hud_colors = {
{"#FFFFFF", 0xFFFFFF, S("White")},
@ -21,10 +17,15 @@ local waypoints_temp = {}
unified_inventory.register_page("waypoints", {
get_formspec = function(player)
local player_name = player:get_player_name()
-- build a "fake" temp entry if the server took too long
-- during sign-on and returned an empty entry
if not waypoints_temp[player_name] then waypoints_temp[player_name] = {hud = 1} end
local waypoints = datastorage.get(player_name, "waypoints")
local formspec = "background[0,4.5;8,4;ui_main_inventory.png]" ..
"image[0,0;1,1;ui_waypoints_icon.png]" ..
"label[1,0;" .. S("Waypoints") .. "]"
"label[1,0;" .. F("Waypoints") .. "]"
-- Tabs buttons:
for i = 1, 5, 1 do
@ -34,13 +35,13 @@ unified_inventory.register_page("waypoints", {
"ui_" .. i .. "_icon.png;" ..
"select_waypoint" .. i .. ";]" ..
"tooltip[select_waypoint" .. i .. ";"
.. minetest.formspec_escape(S("Select Waypoint #%d"):format(i)).."]"
.. (S("Select Waypoint #%d"):format(i)).."]"
end
local i = waypoints.selected or 1
local waypoint = waypoints[i] or {}
local temp = waypoints_temp[player_name][i] or {}
local default_name = "Waypoint "..i
local default_name = string.format(S("Waypoint %d"), i)
-- Main buttons:
formspec = formspec ..
@ -48,43 +49,43 @@ unified_inventory.register_page("waypoints", {
"ui_waypoint_set_icon.png;"..
"set_waypoint"..i..";]"..
"tooltip[set_waypoint" .. i .. ";"
.. minetest.formspec_escape(S("Set waypoint to current location")).."]"
.. F("Set waypoint to current location").."]"
formspec = formspec ..
"image_button[5.2,3.7;.8,.8;"..
(waypoint.active and "ui_on_icon.png" or "ui_off_icon.png")..";"..
"toggle_waypoint"..i..";]"..
"tooltip[toggle_waypoint" .. i .. ";"
.. minetest.formspec_escape(S("Make waypoint "
..(waypoint.active and "invisible" or "visible"))).."]"
.. F("Make waypoint "
..(waypoint.active and "invisible" or "visible")).."]"
formspec = formspec ..
"image_button[5.9,3.7;.8,.8;"..
(waypoint.display_pos and "ui_green_icon_background.png" or "ui_red_icon_background.png").."^ui_xyz_icon.png;"..
"toggle_display_pos" .. i .. ";]"..
"tooltip[toggle_display_pos" .. i .. ";"
.. minetest.formspec_escape(S((waypoint.display_pos and "Disable" or "Enable")
.." display of waypoint coordinates")).."]"
.. F((waypoint.display_pos and "Disable" or "Enable")
.." display of waypoint coordinates").."]"
formspec = formspec ..
"image_button[6.6,3.7;.8,.8;"..
"ui_circular_arrows_icon.png;"..
"toggle_color"..i..";]"..
"tooltip[toggle_color" .. i .. ";"
.. minetest.formspec_escape(S("Change color of waypoint display")).."]"
.. F("Change color of waypoint display").."]"
formspec = formspec ..
"image_button[7.3,3.7;.8,.8;"..
"ui_pencil_icon.png;"..
"rename_waypoint"..i..";]"..
"tooltip[rename_waypoint" .. i .. ";"
.. minetest.formspec_escape(S("Edit waypoint name")).."]"
.. F("Edit waypoint name").."]"
-- Waypoint's info:
if waypoint.active then
formspec = formspec .. "label[1,0.8;"..S("Waypoint active").."]"
formspec = formspec .. "label[1,0.8;"..F("Waypoint active").."]"
else
formspec = formspec .. "label[1,0.8;"..S("Waypoint inactive").."]"
formspec = formspec .. "label[1,0.8;"..F("Waypoint inactive").."]"
end
if temp.edit then
@ -95,13 +96,13 @@ unified_inventory.register_page("waypoints", {
"ui_ok_icon.png;"..
"confirm_rename"..i.. ";]"..
"tooltip[confirm_rename" .. i .. ";"
.. minetest.formspec_escape(S("Finish editing")).."]"
.. F("Finish editing").."]"
end
formspec = formspec .. "label[1,1.3;"..S("World position")..": " ..
formspec = formspec .. "label[1,1.3;"..F("World position")..": " ..
minetest.pos_to_string(waypoint.world_pos or vector.new()) .. "]" ..
"label[1,1.8;"..S("Name")..": ".. (waypoint.name or default_name) .. "]" ..
"label[1,2.3;"..S("HUD text color")..": " ..
"label[1,1.8;"..F("Name")..": ".. (waypoint.name or default_name) .. "]" ..
"label[1,2.3;"..F("HUD text color")..": " ..
hud_colors[waypoint.color or 1][3] .. "]"
return {formspec=formspec}
@ -112,6 +113,8 @@ unified_inventory.register_button("waypoints", {
type = "image",
image = "ui_waypoints_icon.png",
tooltip = S("Waypoints"),
hide_lite=true,
show_with = false, --Modif MFF (Crabman 30/06/2015)
})
local function update_hud(player, waypoints, temp, i)