Allow per-user "full" mode when "lite" mode is set as global

default (give the user "ui_full" priv to turn it on).

Also, a few whitespace fixes.
This commit is contained in:
Vanessa Ezekowitz 2015-10-05 04:24:01 -04:00
parent babe4380ac
commit 9fe84789ba
6 changed files with 212 additions and 160 deletions

View File

@ -26,7 +26,8 @@ unified_inventory.register_page("bags", {
unified_inventory.register_button("bags", { unified_inventory.register_button("bags", {
type = "image", type = "image",
image = "ui_bags_icon.png", image = "ui_bags_icon.png",
tooltip = S("Bags") tooltip = S("Bags"),
hide_lite=true
}) })
for i = 1, 4 do for i = 1, 4 do

View File

@ -14,7 +14,7 @@ minetest.register_on_joinplayer(function(player)
unified_inventory.players[player_name] = {} unified_inventory.players[player_name] = {}
unified_inventory.current_index[player_name] = 1 unified_inventory.current_index[player_name] = 1
unified_inventory.filtered_items_list[player_name] = unified_inventory.filtered_items_list[player_name] =
unified_inventory.items_list unified_inventory.items_list
unified_inventory.activefilter[player_name] = "" unified_inventory.activefilter[player_name] = ""
unified_inventory.active_search_direction[player_name] = "nochange" unified_inventory.active_search_direction[player_name] = "nochange"
unified_inventory.apply_filter(player, "", "nochange") unified_inventory.apply_filter(player, "", "nochange")
@ -23,7 +23,7 @@ minetest.register_on_joinplayer(function(player)
unified_inventory.current_item[player_name] = nil unified_inventory.current_item[player_name] = nil
unified_inventory.current_craft_direction[player_name] = "recipe" unified_inventory.current_craft_direction[player_name] = "recipe"
unified_inventory.set_inventory_formspec(player, unified_inventory.set_inventory_formspec(player,
unified_inventory.default) unified_inventory.default)
-- Refill slot -- Refill slot
local refill = minetest.create_detached_inventory(player_name.."refill", { local refill = minetest.create_detached_inventory(player_name.."refill", {
@ -48,10 +48,13 @@ minetest.register_on_joinplayer(function(player)
end) end)
minetest.register_on_player_receive_fields(function(player, formname, fields) 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 if formname ~= "" then
return return
end end
local player_name = player:get_player_name()
-- always take new search text, even if not searching on it yet -- always take new search text, even if not searching on it yet
if fields.searchbox if fields.searchbox
@ -71,11 +74,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
-- Inventory page controls -- Inventory page controls
local start = math.floor( local start = math.floor(
unified_inventory.current_index[player_name] / unified_inventory.items_per_page + 1) unified_inventory.current_index[player_name] / ui_peruser.items_per_page + 1)
local start_i = start local start_i = start
local pagemax = math.floor( local pagemax = math.floor(
(#unified_inventory.filtered_items_list[player_name] - 1) (#unified_inventory.filtered_items_list[player_name] - 1)
/ (unified_inventory.items_per_page) + 1) / (ui_peruser.items_per_page) + 1)
if fields.start_list then if fields.start_list then
start_i = 1 start_i = 1
@ -104,7 +107,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if start_i ~= start then if start_i ~= start then
minetest.sound_play("paperflip1", minetest.sound_play("paperflip1",
{to_player=player_name, gain = 1.0}) {to_player=player_name, gain = 1.0})
unified_inventory.current_index[player_name] = (start_i - 1) * unified_inventory.items_per_page + 1 unified_inventory.current_index[player_name] = (start_i - 1) * ui_peruser.items_per_page + 1
unified_inventory.set_inventory_formspec(player, unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name]) unified_inventory.current_page[player_name])
end end

View File

@ -47,20 +47,6 @@ unified_inventory = {
form_header_y = 0 form_header_y = 0
} }
if unified_inventory.lite_mode then
unified_inventory.pagecols = 4
unified_inventory.pagerows = 6
unified_inventory.page_y = 0.25
unified_inventory.formspec_y = 0.47
unified_inventory.main_button_x = 8.2
unified_inventory.main_button_y = 6.5
unified_inventory.craft_result_x = 2.8
unified_inventory.craft_result_y = 3.4
unified_inventory.form_header_y = -0.1
end
unified_inventory.items_per_page = unified_inventory.pagecols * unified_inventory.pagerows
-- Disable default creative inventory -- Disable default creative inventory
if rawget(_G, "creative_inventory") then if rawget(_G, "creative_inventory") then
function creative_inventory.set_creative_formspec(player, start_i, pagenum) function creative_inventory.set_creative_formspec(player, start_i, pagenum)
@ -73,14 +59,11 @@ dofile(modpath.."/api.lua")
dofile(modpath.."/internal.lua") dofile(modpath.."/internal.lua")
dofile(modpath.."/callbacks.lua") dofile(modpath.."/callbacks.lua")
dofile(modpath.."/register.lua") dofile(modpath.."/register.lua")
dofile(modpath.."/bags.lua")
if not unified_inventory.lite_mode then
dofile(modpath.."/bags.lua")
end
dofile(modpath.."/item_names.lua") dofile(modpath.."/item_names.lua")
if minetest.get_modpath("datastorage") and not unified_inventory.lite_mode then if minetest.get_modpath("datastorage") then
dofile(modpath.."/waypoints.lua") dofile(modpath.."/waypoints.lua")
end end

View File

@ -15,11 +15,45 @@ function unified_inventory.demangle_for_formspec(str)
return string.gsub(str, "_([0-9]+)_", function (v) return string.char(v) end) return string.gsub(str, "_([0-9]+)_", function (v) return string.char(v) end)
end end
function unified_inventory.get_per_player_formspec(player_name)
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) function unified_inventory.get_formspec(player, page)
if not player then if not player then
return "" return ""
end end
local player_name = player:get_player_name() local player_name = player:get_player_name()
local ui_peruser,draw_lite_mode = unified_inventory.get_per_player_formspec(player_name)
unified_inventory.current_page[player_name] = page unified_inventory.current_page[player_name] = page
local pagedef = unified_inventory.pages[page] local pagedef = unified_inventory.pages[page]
@ -29,14 +63,14 @@ function unified_inventory.get_formspec(player, page)
} }
local n = 3 local n = 3
if unified_inventory.lite_mode then if draw_lite_mode then
formspec[1] = "size[11,7.7]" formspec[1] = "size[11,7.7]"
formspec[2] = "background[-0.19,-0.2;11.4,8.4;ui_form_bg.png]" formspec[2] = "background[-0.19,-0.2;11.4,8.4;ui_form_bg.png]"
end end
if unified_inventory.is_creative(player_name) if unified_inventory.is_creative(player_name)
and page == "craft" then and page == "craft" then
formspec[n] = "background[0,"..(unified_inventory.formspec_y + 2)..";1,1;ui_single_slot.png]" formspec[n] = "background[0,"..(ui_peruser.formspec_y + 2)..";1,1;ui_single_slot.png]"
n = n+1 n = n+1
end end
@ -44,7 +78,10 @@ function unified_inventory.get_formspec(player, page)
if not unified_inventory.pages[page] then if not unified_inventory.pages[page] then
return "" -- Invalid page name return "" -- Invalid page name
end end
local fsdata = pagedef.get_formspec(player)
local perplayer_formspec = unified_inventory.get_per_player_formspec(player_name)
local fsdata = pagedef.get_formspec(player, perplayer_formspec)
formspec[n] = fsdata.formspec formspec[n] = fsdata.formspec
n = n+1 n = n+1
@ -52,17 +89,26 @@ function unified_inventory.get_formspec(player, page)
local button_col = 0 local button_col = 0
-- Main buttons -- Main buttons
for i, def in pairs(unified_inventory.buttons) do
if unified_inventory.lite_mode and i > 4 then local filtered_inv_buttons = {}
for i, def in pairs(unified_inventory.buttons) do
if not (draw_lite_mode and def.hide_lite) then
table.insert(filtered_inv_buttons, def)
end
end
for i, def in pairs(filtered_inv_buttons) do
if draw_lite_mode and i > 4 then
button_row = 1 button_row = 1
button_col = 1 button_col = 1
end end
if def.type == "image" then if def.type == "image" then
formspec[n] = "image_button[" formspec[n] = "image_button["
formspec[n+1] = ( unified_inventory.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4) formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4)
formspec[n+2] = ","..(unified_inventory.main_button_y + button_row * 0.7)..";0.8,0.8;" 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+3] = minetest.formspec_escape(def.image)..";"
formspec[n+4] = minetest.formspec_escape(def.name)..";]" formspec[n+4] = minetest.formspec_escape(def.name)..";]"
formspec[n+5] = "tooltip["..minetest.formspec_escape(def.name) formspec[n+5] = "tooltip["..minetest.formspec_escape(def.name)
@ -74,7 +120,7 @@ function unified_inventory.get_formspec(player, page)
if fsdata.draw_inventory ~= false then if fsdata.draw_inventory ~= false then
-- Player inventory -- Player inventory
formspec[n] = "listcolors[#00000000;#00000000]" formspec[n] = "listcolors[#00000000;#00000000]"
formspec[n+1] = "list[current_player;main;0,"..(unified_inventory.formspec_y + 3.5)..";8,4;]" formspec[n+1] = "list[current_player;main;0,"..(ui_peruser.formspec_y + 3.5)..";8,4;]"
n = n+2 n = n+2
end end
@ -85,7 +131,7 @@ function unified_inventory.get_formspec(player, page)
-- Controls to flip items pages -- Controls to flip items pages
local start_x = 9.2 local start_x = 9.2
if not unified_inventory.lite_mode then if not draw_lite_mode then
formspec[n] = formspec[n] =
"image_button[" .. (start_x + 0.6 * 0) "image_button[" .. (start_x + 0.6 * 0)
.. ",9;.8,.8;ui_skip_backward_icon.png;start_list;]" .. ",9;.8,.8;ui_skip_backward_icon.png;start_list;]"
@ -127,7 +173,7 @@ function unified_inventory.get_formspec(player, page)
-- Search box -- Search box
if not unified_inventory.lite_mode then if not draw_lite_mode then
formspec[n] = "field[9.5,8.325;3,1;searchbox;;" formspec[n] = "field[9.5,8.325;3,1;searchbox;;"
.. minetest.formspec_escape(unified_inventory.current_searchbox[player_name]) .. "]" .. 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;]" formspec[n+1] = "image_button[12.2,8.1;.8,.8;ui_search_icon.png;searchbutton;]"
@ -141,28 +187,28 @@ function unified_inventory.get_formspec(player, page)
n = n+2 n = n+2
local no_matches = "No matching items" local no_matches = "No matching items"
if unified_inventory.lite_mode then if draw_lite_mode then
no_matches = "No matches." no_matches = "No matches."
end end
-- Items list -- Items list
if #unified_inventory.filtered_items_list[player_name] == 0 then if #unified_inventory.filtered_items_list[player_name] == 0 then
formspec[n] = "label[8.2,"..unified_inventory.form_header_y..";" .. S(no_matches) .. "]" formspec[n] = "label[8.2,"..ui_peruser.form_header_y..";" .. S(no_matches) .. "]"
else else
local dir = unified_inventory.active_search_direction[player_name] local dir = unified_inventory.active_search_direction[player_name]
local list_index = unified_inventory.current_index[player_name] local list_index = unified_inventory.current_index[player_name]
local page = math.floor(list_index / (unified_inventory.items_per_page) + 1) local page = math.floor(list_index / (ui_peruser.items_per_page) + 1)
local pagemax = math.floor( local pagemax = math.floor(
(#unified_inventory.filtered_items_list[player_name] - 1) (#unified_inventory.filtered_items_list[player_name] - 1)
/ (unified_inventory.items_per_page) + 1) / (ui_peruser.items_per_page) + 1)
local item = {} local item = {}
for y = 0, unified_inventory.pagerows - 1 do for y = 0, ui_peruser.pagerows - 1 do
for x = 0, unified_inventory.pagecols - 1 do for x = 0, ui_peruser.pagecols - 1 do
local name = unified_inventory.filtered_items_list[player_name][list_index] local name = unified_inventory.filtered_items_list[player_name][list_index]
if minetest.registered_items[name] then if minetest.registered_items[name] then
formspec[n] = "item_image_button[" formspec[n] = "item_image_button["
..(8.2 + x * 0.7).."," ..(8.2 + x * 0.7)..","
..(unified_inventory.formspec_y + unified_inventory.page_y + y * 0.7)..";.81,.81;" ..(ui_peruser.formspec_y + ui_peruser.page_y + y * 0.7)..";.81,.81;"
..name..";item_button_"..dir.."_" ..name..";item_button_"..dir.."_"
..unified_inventory.mangle_for_formspec(name)..";]" ..unified_inventory.mangle_for_formspec(name)..";]"
n = n+1 n = n+1
@ -170,14 +216,14 @@ function unified_inventory.get_formspec(player, page)
end end
end end
end end
formspec[n] = "label[8.2,"..unified_inventory.form_header_y..";"..S("Page") .. ": " formspec[n] = "label[8.2,"..ui_peruser.form_header_y..";"..S("Page") .. ": "
.. S("%s of %s"):format(page,pagemax).."]" .. S("%s of %s"):format(page,pagemax).."]"
end end
n= n+1 n= n+1
if unified_inventory.activefilter[player_name] ~= "" then if unified_inventory.activefilter[player_name] ~= "" then
formspec[n] = "label[8.2,"..(unified_inventory.form_header_y + 0.4)..";" .. S("Filter") .. ":]" formspec[n] = "label[8.2,"..(ui_peruser.form_header_y + 0.4)..";" .. S("Filter") .. ":]"
formspec[n+1] = "label[9.1,"..(unified_inventory.form_header_y + 0.4)..";"..minetest.formspec_escape(unified_inventory.activefilter[player_name]).."]" formspec[n+1] = "label[9.1,"..(ui_peruser.form_header_y + 0.4)..";"..minetest.formspec_escape(unified_inventory.activefilter[player_name]).."]"
end end
return table.concat(formspec, "") return table.concat(formspec, "")
end end
@ -232,7 +278,7 @@ function unified_inventory.apply_filter(player, filter, search_dir)
unified_inventory.activefilter[player_name] = filter unified_inventory.activefilter[player_name] = filter
unified_inventory.active_search_direction[player_name] = search_dir unified_inventory.active_search_direction[player_name] = search_dir
unified_inventory.set_inventory_formspec(player, unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name]) unified_inventory.current_page[player_name])
end end
function unified_inventory.items_in_group(groups) function unified_inventory.items_in_group(groups)

View File

@ -5,6 +5,12 @@ minetest.register_privilege("creative", {
give_to_singleplayer = false, give_to_singleplayer = false,
}) })
minetest.register_privilege("ui_full", {
description = "Forces UI to display in Full mode when Lite mode is configured globally",
give_to_singleplayer = false,
})
local trash = minetest.create_detached_inventory("trash", { local trash = minetest.create_detached_inventory("trash", {
--allow_put = function(inv, listname, index, stack, player) --allow_put = function(inv, listname, index, stack, player)
-- if unified_inventory.is_creative(player:get_player_name()) then -- if unified_inventory.is_creative(player:get_player_name()) then
@ -33,84 +39,86 @@ unified_inventory.register_button("craftguide", {
tooltip = S("Crafting Guide") tooltip = S("Crafting Guide")
}) })
if not unified_inventory.lite_mode then unified_inventory.register_button("home_gui_set", {
unified_inventory.register_button("home_gui_set", { type = "image",
type = "image", image = "ui_sethome_icon.png",
image = "ui_sethome_icon.png", tooltip = S("Set home position"),
tooltip = S("Set home position"), hide_lite=true,
action = function(player) action = function(player)
local player_name = player:get_player_name() local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {home=true}) then if minetest.check_player_privs(player_name, {home=true}) then
unified_inventory.set_home(player, player:getpos()) unified_inventory.set_home(player, player:getpos())
local home = unified_inventory.home_pos[player_name] local home = unified_inventory.home_pos[player_name]
if home ~= nil then if home ~= nil then
minetest.sound_play("dingdong", minetest.sound_play("dingdong",
{to_player=player_name, gain = 1.0})
minetest.chat_send_player(player_name,
S("Home position set to: %s"):format(minetest.pos_to_string(home)))
end
else
minetest.chat_send_player(player_name,
S("You don't have the \"home\" privilege!"))
end
end,
})
unified_inventory.register_button("home_gui_go", {
type = "image",
image = "ui_gohome_icon.png",
tooltip = S("Go home"),
action = function(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {home=true}) then
minetest.sound_play("teleport",
{to_player=player:get_player_name(), gain = 1.0})
unified_inventory.go_home(player)
else
minetest.chat_send_player(player_name,
S("You don't have the \"home\" privilege!"))
end
end,
})
unified_inventory.register_button("misc_set_day", {
type = "image",
image = "ui_sun_icon.png",
tooltip = S("Set time to day"),
action = function(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {settime=true}) then
minetest.sound_play("birds",
{to_player=player_name, gain = 1.0}) {to_player=player_name, gain = 1.0})
minetest.set_timeofday((6000 % 24000) / 24000)
minetest.chat_send_player(player_name,
S("Time of day set to 6am"))
else
minetest.chat_send_player(player_name, minetest.chat_send_player(player_name,
S("Home position set to: %s"):format(minetest.pos_to_string(home)))
end
else
minetest.chat_send_player(player_name,
S("You don't have the \"home\" privilege!"))
end
end,
})
unified_inventory.register_button("home_gui_go", {
type = "image",
image = "ui_gohome_icon.png",
tooltip = S("Go home"),
hide_lite=true,
action = function(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {home=true}) then
minetest.sound_play("teleport",
{to_player=player:get_player_name(), gain = 1.0})
unified_inventory.go_home(player)
else
minetest.chat_send_player(player_name,
S("You don't have the \"home\" privilege!"))
end
end,
})
unified_inventory.register_button("misc_set_day", {
type = "image",
image = "ui_sun_icon.png",
tooltip = S("Set time to day"),
hide_lite=true,
action = function(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {settime=true}) then
minetest.sound_play("birds",
{to_player=player_name, gain = 1.0})
minetest.set_timeofday((6000 % 24000) / 24000)
minetest.chat_send_player(player_name,
S("Time of day set to 6am"))
else
minetest.chat_send_player(player_name,
S("You don't have the settime privilege!"))
end
end,
})
unified_inventory.register_button("misc_set_night", {
type = "image",
image = "ui_moon_icon.png",
tooltip = S("Set time to night"),
hide_lite=true,
action = function(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {settime=true}) then
minetest.sound_play("owl",
{to_player=player_name, gain = 1.0})
minetest.set_timeofday((21000 % 24000) / 24000)
minetest.chat_send_player(player_name,
S("Time of day set to 9pm"))
else
minetest.chat_send_player(player_name,
S("You don't have the settime privilege!")) S("You don't have the settime privilege!"))
end end
end, end,
}) })
unified_inventory.register_button("misc_set_night", {
type = "image",
image = "ui_moon_icon.png",
tooltip = S("Set time to night"),
action = function(player)
local player_name = player:get_player_name()
if minetest.check_player_privs(player_name, {settime=true}) then
minetest.sound_play("owl",
{to_player=player_name, gain = 1.0})
minetest.set_timeofday((21000 % 24000) / 24000)
minetest.chat_send_player(player_name,
S("Time of day set to 9pm"))
else
minetest.chat_send_player(player_name,
S("You don't have the settime privilege!"))
end
end,
})
end
unified_inventory.register_button("clear_inv", { unified_inventory.register_button("clear_inv", {
type = "image", type = "image",
@ -134,19 +142,23 @@ unified_inventory.register_button("clear_inv", {
}) })
unified_inventory.register_page("craft", { 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 player_name = player:get_player_name()
local formspec = "background[2,"..unified_inventory.formspec_y..";6,3;ui_crafting_form.png]" local formspec = "background[2,"..formspecy..";6,3;ui_crafting_form.png]"
formspec = formspec.."background[0,"..(unified_inventory.formspec_y + 3.5)..";8,4;ui_main_inventory.png]" formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]"
formspec = formspec.."label[0,"..unified_inventory.form_header_y..";Crafting]" formspec = formspec.."label[0,"..formheadery..";Crafting]"
formspec = formspec.."listcolors[#00000000;#00000000]" formspec = formspec.."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;craftpreview;6,"..unified_inventory.formspec_y..";1,1;]" formspec = formspec.."list[current_player;craftpreview;6,"..formspecy..";1,1;]"
formspec = formspec.."list[current_player;craft;2,"..unified_inventory.formspec_y..";3,3;]" formspec = formspec.."list[current_player;craft;2,"..formspecy..";3,3;]"
formspec = formspec.."label[7,"..(unified_inventory.formspec_y + 1.5)..";" .. S("Trash:") .. "]" formspec = formspec.."label[7,"..(formspecy + 1.5)..";" .. S("Trash:") .. "]"
formspec = formspec.."list[detached:trash;main;7,"..(unified_inventory.formspec_y + 2)..";1,1;]" formspec = formspec.."list[detached:trash;main;7,"..(formspecy + 2)..";1,1;]"
if unified_inventory.is_creative(player_name) then if unified_inventory.is_creative(player_name) then
formspec = formspec.."label[0,"..(unified_inventory.formspec_y + 1.5)..";" .. S("Refill:") .. "]" formspec = formspec.."label[0,"..(formspecy + 1.5)..";" .. S("Refill:") .. "]"
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."refill;main;0,"..(unified_inventory.formspec_y +2)..";1,1;]" formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."refill;main;0,"..(formspecy +2)..";1,1;]"
end end
return {formspec=formspec} return {formspec=formspec}
end, end,
@ -204,12 +216,18 @@ local other_dir = {
} }
unified_inventory.register_page("craftguide", { 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_name = player:get_player_name()
local player_privs = minetest.get_player_privs(player_name) local player_privs = minetest.get_player_privs(player_name)
local formspec = "" local formspec = ""
formspec = formspec.."background[0,"..(unified_inventory.formspec_y + 3.5)..";8,4;ui_main_inventory.png]" formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]"
formspec = formspec.."label[0,"..unified_inventory.form_header_y..";" .. S("Crafting Guide") .. "]" formspec = formspec.."label[0,"..formheadery..";" .. S("Crafting Guide") .. "]"
formspec = formspec.."listcolors[#00000000;#00000000]" formspec = formspec.."listcolors[#00000000;#00000000]"
local item_name = unified_inventory.current_item[player_name] local item_name = unified_inventory.current_item[player_name]
if not item_name then return {formspec=formspec} end if not item_name then return {formspec=formspec} end
@ -226,25 +244,25 @@ unified_inventory.register_page("craftguide", {
craft = crafts[alternate] craft = crafts[alternate]
end end
formspec = formspec.."background[0.5,"..(unified_inventory.formspec_y + 0.2)..";8,3;ui_craftguide_form.png]" formspec = formspec.."background[0.5,"..(formspecy + 0.2)..";8,3;ui_craftguide_form.png]"
formspec = formspec.."textarea["..unified_inventory.craft_result_x..","..unified_inventory.craft_result_y formspec = formspec.."textarea["..craftresultx..","..craftresulty
..";10,1;;"..minetest.formspec_escape(role_text[dir]..": "..item_name)..";]" ..";10,1;;"..minetest.formspec_escape(role_text[dir]..": "..item_name)..";]"
formspec = formspec..stack_image_button(0, unified_inventory.formspec_y, 1.1, 1.1, "item_button_" formspec = formspec..stack_image_button(0, formspecy, 1.1, 1.1, "item_button_"
.. rdir .. "_", ItemStack(item_name)) .. rdir .. "_", ItemStack(item_name))
if not craft then if not craft then
formspec = formspec.."label[5.5,"..(unified_inventory.formspec_y + 2.35)..";" formspec = formspec.."label[5.5,"..(formspecy + 2.35)..";"
..minetest.formspec_escape(no_recipe_text[dir]).."]" ..minetest.formspec_escape(no_recipe_text[dir]).."]"
local no_pos = dir == "recipe" and 4.5 or 6.5 local no_pos = dir == "recipe" and 4.5 or 6.5
local item_pos = dir == "recipe" and 6.5 or 4.5 local item_pos = dir == "recipe" and 6.5 or 4.5
formspec = formspec.."image["..no_pos..","..unified_inventory.formspec_y..";1.1,1.1;ui_no.png]" formspec = formspec.."image["..no_pos..","..formspecy..";1.1,1.1;ui_no.png]"
formspec = formspec..stack_image_button(item_pos, unified_inventory.formspec_y, 1.1, 1.1, "item_button_" formspec = formspec..stack_image_button(item_pos, formspecy, 1.1, 1.1, "item_button_"
..other_dir[dir].."_", ItemStack(item_name)) ..other_dir[dir].."_", ItemStack(item_name))
if player_privs.give == true then if player_privs.give == true then
formspec = formspec.."label[0,"..(unified_inventory.formspec_y + 2.10)..";" .. S("Give me:") .. "]" formspec = formspec.."label[0,"..(formspecy + 2.10)..";" .. S("Give me:") .. "]"
.."button[0, "..(unified_inventory.formspec_y + 2.7)..";0.6,0.5;craftguide_giveme_1;1]" .."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
.."button[0.6,"..(unified_inventory.formspec_y + 2.7)..";0.7,0.5;craftguide_giveme_10;10]" .."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
.."button[1.3,"..(unified_inventory.formspec_y + 2.7)..";0.8,0.5;craftguide_giveme_99;99]" .."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
end end
return {formspec = formspec} return {formspec = formspec}
end end
@ -252,10 +270,10 @@ unified_inventory.register_page("craftguide", {
local craft_type = unified_inventory.registered_craft_types[craft.type] or local craft_type = unified_inventory.registered_craft_types[craft.type] or
unified_inventory.craft_type_defaults(craft.type, {}) unified_inventory.craft_type_defaults(craft.type, {})
if craft_type.icon then if craft_type.icon then
formspec = formspec..string.format(" image[%f,%f;%f,%f;%s]",5.7,(unified_inventory.formspec_y + 0.05),0.5,0.5,craft_type.icon) formspec = formspec..string.format(" image[%f,%f;%f,%f;%s]",5.7,(formspecy + 0.05),0.5,0.5,craft_type.icon)
end end
formspec = formspec.."label[5.5,"..(unified_inventory.formspec_y + 1)..";" .. minetest.formspec_escape(craft_type.description).."]" formspec = formspec.."label[5.5,"..(formspecy + 1)..";" .. minetest.formspec_escape(craft_type.description).."]"
formspec = formspec..stack_image_button(6.5, unified_inventory.formspec_y, 1.1, 1.1, "item_button_usage_", ItemStack(craft.output)) 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 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 local craft_width = craft_type.get_shaped_craft_width and craft_type.get_shaped_craft_width(craft) or display_size.width
@ -270,36 +288,36 @@ unified_inventory.register_page("craftguide", {
end end
if item then if item then
formspec = formspec..stack_image_button( formspec = formspec..stack_image_button(
xoffset + x, unified_inventory.formspec_y - 1 + y, 1.1, 1.1, xoffset + x, formspecy - 1 + y, 1.1, 1.1,
"item_button_recipe_", "item_button_recipe_",
ItemStack(item)) ItemStack(item))
else else
-- Fake buttons just to make grid -- Fake buttons just to make grid
formspec = formspec.."image_button[" formspec = formspec.."image_button["
..tostring(xoffset + x)..","..tostring(unified_inventory.formspec_y - 1 + y) ..tostring(xoffset + x)..","..tostring(formspecy - 1 + y)
..";1,1;ui_blank_image.png;;]" ..";1,1;ui_blank_image.png;;]"
end end
end end
end end
if craft_type.uses_crafting_grid then if craft_type.uses_crafting_grid then
formspec = formspec.."label[0,"..(unified_inventory.formspec_y + 0.9)..";" .. S("To craft grid:") .. "]" formspec = formspec.."label[0,"..(formspecy + 0.9)..";" .. S("To craft grid:") .. "]"
.."button[0, "..(unified_inventory.formspec_y + 1.5)..";0.6,0.5;craftguide_craft_1;1]" .."button[0, "..(formspecy + 1.5)..";0.6,0.5;craftguide_craft_1;1]"
.."button[0.6,"..(unified_inventory.formspec_y + 1.5)..";0.7,0.5;craftguide_craft_10;10]" .."button[0.6,"..(formspecy + 1.5)..";0.7,0.5;craftguide_craft_10;10]"
.."button[1.3,"..(unified_inventory.formspec_y + 1.5)..";0.8,0.5;craftguide_craft_max;" .. S("All") .. "]" .."button[1.3,"..(formspecy + 1.5)..";0.8,0.5;craftguide_craft_max;" .. S("All") .. "]"
end end
if player_privs.give then if player_privs.give then
formspec = formspec.."label[0,"..(unified_inventory.formspec_y + 2.1)..";" .. S("Give me:") .. "]" formspec = formspec.."label[0,"..(formspecy + 2.1)..";" .. S("Give me:") .. "]"
.."button[0, "..(unified_inventory.formspec_y + 2.7)..";0.6,0.5;craftguide_giveme_1;1]" .."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
.."button[0.6,"..(unified_inventory.formspec_y + 2.7)..";0.7,0.5;craftguide_giveme_10;10]" .."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
.."button[1.3,"..(unified_inventory.formspec_y + 2.7)..";0.8,0.5;craftguide_giveme_99;99]" .."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
end end
if alternates and alternates > 1 then if alternates and alternates > 1 then
formspec = formspec.."label[5.5,"..(unified_inventory.formspec_y + 1.6)..";"..recipe_text[dir].." " formspec = formspec.."label[5.5,"..(formspecy + 1.6)..";"..recipe_text[dir].." "
..tostring(alternate).." of " ..tostring(alternate).." of "
..tostring(alternates).."]" ..tostring(alternates).."]"
.."button[5.5,"..(unified_inventory.formspec_y + 2)..";2,1;alternate;" .. S("Alternate") .. "]" .."button[5.5,"..(formspecy + 2)..";2,1;alternate;" .. S("Alternate") .. "]"
end end
return {formspec = formspec} return {formspec = formspec}
end, end,

View File

@ -107,6 +107,7 @@ unified_inventory.register_button("waypoints", {
type = "image", type = "image",
image = "ui_waypoints_icon.png", image = "ui_waypoints_icon.png",
tooltip = S("Waypoints"), tooltip = S("Waypoints"),
hide_lite=true
}) })
local function update_hud(player, waypoints, temp, i) local function update_hud(player, waypoints, temp, i)