mirror of
https://github.com/minetest-mods/unified_inventory.git
synced 2025-07-14 22:40:16 +02:00
Compare commits
31 Commits
match_copy
...
aa04d4539f
Author | SHA1 | Date | |
---|---|---|---|
aa04d4539f | |||
15d729c351 | |||
b2cc3d1532 | |||
37969b2a1b | |||
1b074828a6 | |||
de0063835c | |||
bda9f2598f | |||
b590764026 | |||
a977ec47fd | |||
8c56e27c94 | |||
6da71e1819 | |||
9649c0ed0e | |||
4633a276a2 | |||
1ac54a017d | |||
4c4fb3ba88 | |||
9d66a21271 | |||
15a84bdbf4 | |||
838c67ae86 | |||
132a362f85 | |||
03b077cd1b | |||
829b38c6fc | |||
70fdb8556b | |||
497c632b24 | |||
46eeb36784 | |||
9a31609cfd | |||
8e6a3740ae | |||
1fd87f5c51 | |||
e5dc9ed53a | |||
4bf5f22696 | |||
4f666f93d0 | |||
264833ed41 |
16
README.md
16
README.md
@ -71,6 +71,9 @@ From http://www.clker.com (Public Domain, CC-BY-4.0):
|
||||
* [`ui_pencil_icon.pnc`](http://www.clker.com/clipart-2256.html)
|
||||
* [`ui_waypoint_set_icon.png`](http://www.clker.com/clipart-larger-flag.html)
|
||||
|
||||
From https://www.svgrepo.com (CC-BY)
|
||||
* [`ui_teleport.png`](https://www.svgrepo.com/svg/321565/teleport)
|
||||
|
||||
Everaldo Coelho (YellowIcon) (LGPL v2.1+):
|
||||
|
||||
* [`ui_craftguide_icon.png` / `ui_craft_icon.png`](http://commons.wikimedia.org/wiki/File:Advancedsettings.png)
|
||||
@ -102,3 +105,16 @@ Other files from Wikimedia Commons:
|
||||
RealBadAngel: (CC-BY-4.0)
|
||||
|
||||
* Everything else.
|
||||
|
||||
|
||||
## Sounds
|
||||
|
||||
* [`bell.ogg`](https://freesound.org/people/bennstir/sounds/81072/) by bennstir, CC 4.0
|
||||
* [`electricity.ogg`](https://freesound.org/people/Halleck/sounds/19486/) by Halleck, CC 4.0 (cut)
|
||||
* [`pageflip1.ogg`](https://freesound.org/people/themfish/sounds/45823/) by themfish, CC 4.0 (cut, slowed down)
|
||||
* `pageflip2.ogg` (derived from `pageflip1.ogg`)
|
||||
* [`trash.ogg`](https://freesound.org/people/OwlStorm/sounds/151231/) by OwlStorm, CC 0 (speed up)
|
||||
* [`trash_all.ogg`](https://freesound.org/people/abel_K/sounds/68280/) by abel_K, Sampling Plus 1.0 (speed up)
|
||||
* [`ui_click.ogg`](https://freesound.org/people/lartti/sounds/527569/) by lartti, CC 0 (cut)
|
||||
* [`ui_morning.ogg`](https://freesound.org/people/InspectorJ/sounds/439472/) by InspectorJ, CC 4.0
|
||||
* [`ui_owl.ogg`](https://freesound.org/people/manda_g/sounds/54987/) by manda_g, Sampling Plus 1.0 (cut)
|
||||
|
55
api.lua
55
api.lua
@ -145,50 +145,18 @@ minetest.after(0.01, function()
|
||||
end
|
||||
end
|
||||
|
||||
-- Step 1: group-indexed lookup table for items
|
||||
local spec_matcher = {}
|
||||
for _, name in ipairs(ui.items_list) do
|
||||
-- we only need to care about groups, exact items are handled separately
|
||||
for group, value in pairs(minetest.registered_items[name].groups) do
|
||||
if value and value ~= 0 then
|
||||
if not spec_matcher[group] then
|
||||
spec_matcher[group] = {}
|
||||
end
|
||||
spec_matcher[group][name] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Step 1: Initialize cache for looking up groups
|
||||
unified_inventory.init_matching_cache()
|
||||
|
||||
-- Step 2: Find all matching items for the given spec (groups)
|
||||
local function get_matching_spec_items(specname)
|
||||
if specname:sub(1,6) ~= "group:" then
|
||||
return { [specname] = true }
|
||||
end
|
||||
local get_matching_spec_items = unified_inventory.get_matching_items
|
||||
|
||||
local accepted = {}
|
||||
for i, group in ipairs(specname:sub(7):split(",")) do
|
||||
if i == 1 then
|
||||
-- First step: Copy all possible item names in this group
|
||||
for name, _ in pairs(spec_matcher[group] or {}) do
|
||||
accepted[name] = true
|
||||
end
|
||||
else
|
||||
-- Perform filtering
|
||||
if spec_matcher[group] then
|
||||
for name, _ in pairs(accepted) do
|
||||
accepted[name] = spec_matcher[group][name]
|
||||
end
|
||||
else
|
||||
-- No matching items
|
||||
return {}
|
||||
end
|
||||
end
|
||||
end
|
||||
return accepted
|
||||
end
|
||||
|
||||
for _, recipes in pairs(ui.crafts_for.recipe) do
|
||||
for outputitemname, recipes in pairs(ui.crafts_for.recipe) do
|
||||
-- List of crafts that return this item string (variable "_")
|
||||
|
||||
-- Problem: The group cache must be initialized after all mods finished loading
|
||||
-- thus, invalid recipes might be indexed. Hence perform filtering with `new_recipe_list`
|
||||
local new_recipe_list = {}
|
||||
for _, recipe in ipairs(recipes) do
|
||||
local ingredient_items = {}
|
||||
for _, spec in pairs(recipe.items) do
|
||||
@ -204,7 +172,14 @@ minetest.after(0.01, function()
|
||||
end
|
||||
table.insert(ui.crafts_for.usage[name], recipe)
|
||||
end
|
||||
|
||||
if next(ingredient_items) then
|
||||
-- There's at least one known ingredient: mark as good recipe
|
||||
-- PS: What whatll be done about partially incomplete recipes?
|
||||
table.insert(new_recipe_list, recipe)
|
||||
end
|
||||
end
|
||||
ui.crafts_for.recipe[outputitemname] = new_recipe_list
|
||||
end
|
||||
|
||||
for _, callback in ipairs(ui.initialized_callbacks) do
|
||||
|
65
bags.lua
65
bags.lua
@ -10,25 +10,26 @@ local F = minetest.formspec_escape
|
||||
local ui = unified_inventory
|
||||
|
||||
ui.register_page("bags", {
|
||||
get_formspec = function(player)
|
||||
get_formspec = function(player, perplayer_formspec)
|
||||
local player_name = player:get_player_name()
|
||||
return { formspec = table.concat({
|
||||
ui.style_full.standard_inv_bg,
|
||||
ui.single_slot(0.925, 1.5),
|
||||
ui.single_slot(3.425, 1.5),
|
||||
ui.single_slot(5.925, 1.5),
|
||||
ui.single_slot(8.425, 1.5),
|
||||
"label["..ui.style_full.form_header_x..","..ui.style_full.form_header_y..";" .. F(S("Bags")) .. "]",
|
||||
"button[0.6125,2.75;1.875,0.75;bag1;" .. F(S("Bag @1", 1)) .. "]",
|
||||
"button[3.1125,2.75;1.875,0.75;bag2;" .. F(S("Bag @1", 2)) .. "]",
|
||||
"button[5.6125,2.75;1.875,0.75;bag3;" .. F(S("Bag @1", 3)) .. "]",
|
||||
"button[8.1125,2.75;1.875,0.75;bag4;" .. F(S("Bag @1", 4)) .. "]",
|
||||
local std_inv_x = perplayer_formspec.std_inv_x
|
||||
local formspec = {
|
||||
perplayer_formspec.standard_inv_bg,
|
||||
"label[", perplayer_formspec.form_header_x, ",",
|
||||
perplayer_formspec.form_header_y, ";", F(S("Bags")), "]",
|
||||
"listcolors[#00000000;#00000000]",
|
||||
"list[detached:" .. F(player_name) .. "_bags;bag1;1.075,1.65;1,1;]",
|
||||
"list[detached:" .. F(player_name) .. "_bags;bag2;3.575,1.65;1,1;]",
|
||||
"list[detached:" .. F(player_name) .. "_bags;bag3;6.075,1.65;1,1;]",
|
||||
"list[detached:" .. F(player_name) .. "_bags;bag4;8.575,1.65;1,1;]"
|
||||
}) }
|
||||
}
|
||||
|
||||
for i = 1, 4 do
|
||||
local x = std_inv_x + i * 2.5
|
||||
formspec[#formspec + 1] = ui.single_slot(x - 1.875, 1.5)
|
||||
formspec[#formspec + 1] = string.format("list[detached:%s_bags;bag%i;%.3f,1.65;1,1;]",
|
||||
F(player_name), i, x - 1.725)
|
||||
formspec[#formspec + 1] = string.format("button[%.4f,2.75;1.875,0.75;bag%i;%s]",
|
||||
x - 2.1875, i, F(S("Bag @1", i)))
|
||||
end
|
||||
|
||||
return { formspec = table.concat(formspec) }
|
||||
end,
|
||||
})
|
||||
|
||||
@ -36,7 +37,6 @@ ui.register_button("bags", {
|
||||
type = "image",
|
||||
image = "ui_bags_icon.png",
|
||||
tooltip = S("Bags"),
|
||||
hide_lite=true
|
||||
})
|
||||
|
||||
local function get_player_bag_stack(player, i)
|
||||
@ -48,23 +48,38 @@ end
|
||||
|
||||
for bag_i = 1, 4 do
|
||||
ui.register_page("bag" .. bag_i, {
|
||||
get_formspec = function(player)
|
||||
get_formspec = function(player, perplayer_formspec)
|
||||
local stack = get_player_bag_stack(player, bag_i)
|
||||
local image = stack:get_definition().inventory_image
|
||||
local slots = stack:get_definition().groups.bagslots
|
||||
local std_inv_x = perplayer_formspec.std_inv_x
|
||||
local lite_mode = perplayer_formspec.is_lite_mode
|
||||
|
||||
local bag_inv_y, header_x, header_y = 1.5, 0.3, 0.65
|
||||
if lite_mode then
|
||||
bag_inv_y = 0.5
|
||||
header_x = perplayer_formspec.form_header_x
|
||||
header_y = perplayer_formspec.form_header_y
|
||||
end
|
||||
|
||||
local formspec = {
|
||||
ui.style_full.standard_inv_bg,
|
||||
ui.make_inv_img_grid(0.3, 1.5, 8, slots/8),
|
||||
"image[9.2,0.4;1,1;" .. image .. "]",
|
||||
"label[0.3,0.65;" .. F(S("Bag @1", bag_i)) .. "]",
|
||||
perplayer_formspec.standard_inv_bg,
|
||||
ui.make_inv_img_grid(std_inv_x, bag_inv_y, 8, slots/8),
|
||||
"label[", header_x, ",", header_y, ";", F(S("Bag @1", bag_i)), "]",
|
||||
"listcolors[#00000000;#00000000]",
|
||||
"listring[current_player;main]",
|
||||
string.format("list[current_player;bag%icontents;%f,%f;8,3;]",
|
||||
bag_i, 0.3 + ui.list_img_offset, 1.5 + ui.list_img_offset),
|
||||
"listring[current_name;bag" .. bag_i .. "contents]",
|
||||
bag_i, std_inv_x + ui.list_img_offset, bag_inv_y + ui.list_img_offset),
|
||||
"listring[current_name;bag", bag_i, "contents]",
|
||||
}
|
||||
|
||||
if lite_mode then
|
||||
return { formspec = table.concat(formspec) }
|
||||
end
|
||||
|
||||
local n = #formspec + 1
|
||||
formspec[n] = "image[" .. std_inv_x + 8.9 .. ",0.4;1,1;" .. image .. "]"
|
||||
n = n + 1
|
||||
|
||||
local player_name = player:get_player_name() -- For if statement.
|
||||
if ui.trash_enabled
|
||||
|
@ -57,30 +57,47 @@ end)
|
||||
local function apply_new_filter(player, search_text, new_dir)
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
|
||||
minetest.sound_play("ui_click", {to_player=player_name, gain = 0.1})
|
||||
ui.apply_filter(player, search_text, new_dir)
|
||||
ui.current_searchbox[player_name] = search_text
|
||||
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
-- Search box handling
|
||||
local function receive_fields_searchbox(player, formname, fields)
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
local ui_peruser,draw_lite_mode = unified_inventory.get_per_player_formspec(player_name)
|
||||
-- always take new search text, even if not searching on it yet
|
||||
if fields.searchbox and fields.searchbox ~= ui.current_searchbox[player_name] then
|
||||
ui.current_searchbox[player_name] = fields.searchbox
|
||||
end
|
||||
|
||||
if fields.searchbutton
|
||||
or fields.key_enter_field == "searchbox" then
|
||||
|
||||
if ui.current_searchbox[player_name] ~= ui.activefilter[player_name] then
|
||||
ui.apply_filter(player, ui.current_searchbox[player_name], "nochange")
|
||||
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||
minetest.sound_play("paperflip2",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
end
|
||||
elseif fields.searchresetbutton then
|
||||
if ui.activefilter[player_name] ~= "" then
|
||||
apply_new_filter(player, "", "nochange")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= "" then
|
||||
return
|
||||
end
|
||||
|
||||
-- always take new search text, even if not searching on it yet
|
||||
local dirty_search_filter = false
|
||||
receive_fields_searchbox(player, formname, fields)
|
||||
|
||||
if fields.searchbox
|
||||
and fields.searchbox ~= unified_inventory.current_searchbox[player_name] then
|
||||
unified_inventory.current_searchbox[player_name] = fields.searchbox
|
||||
dirty_search_filter = true
|
||||
end
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
local ui_peruser,draw_lite_mode = unified_inventory.get_per_player_formspec(player_name)
|
||||
|
||||
local clicked_category
|
||||
for name, value in pairs(fields) do
|
||||
@ -114,7 +131,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
for i, def in pairs(unified_inventory.buttons) do
|
||||
if fields[def.name] then
|
||||
def.action(player)
|
||||
minetest.sound_play("click",
|
||||
minetest.sound_play("ui_click",
|
||||
{to_player=player_name, gain = 0.1})
|
||||
return
|
||||
end
|
||||
@ -179,7 +196,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
end
|
||||
if clicked_item then
|
||||
minetest.sound_play("click",
|
||||
minetest.sound_play("ui_click",
|
||||
{to_player=player_name, gain = 0.1})
|
||||
local page = unified_inventory.current_page[player_name]
|
||||
local player_creative = unified_inventory.is_creative(player_name)
|
||||
@ -201,25 +218,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
end
|
||||
|
||||
if fields.searchbutton
|
||||
or fields.key_enter_field == "searchbox" then
|
||||
if dirty_search_filter then
|
||||
ui.apply_filter(player, ui.current_searchbox[player_name], "nochange")
|
||||
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||
minetest.sound_play("paperflip2",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
end
|
||||
elseif fields.searchresetbutton then
|
||||
if ui.activefilter[player_name] ~= "" then
|
||||
apply_new_filter(player, "", "nochange")
|
||||
end
|
||||
end
|
||||
|
||||
-- alternate buttons
|
||||
if not (fields.alternate or fields.alternate_prev) then
|
||||
return
|
||||
end
|
||||
minetest.sound_play("click",
|
||||
minetest.sound_play("ui_click",
|
||||
{to_player=player_name, gain = 0.1})
|
||||
local item_name = unified_inventory.current_item[player_name]
|
||||
if not item_name then
|
||||
|
@ -24,7 +24,9 @@ Grouped by use-case, afterwards sorted alphabetically.
|
||||
Callbacks
|
||||
---------
|
||||
|
||||
Register a callback that will be run whenever a craft is registered via unified_inventory.register_craft:
|
||||
Register a callback that will be run whenever a craft is registered via unified_inventory.register_craft.
|
||||
This callback is run before any recipe ingredients checks, hence it is also executed on recipes that are
|
||||
purged after all mods finished loading.
|
||||
|
||||
unified_inventory.register_on_craft_registered(
|
||||
function (item_name, options)
|
||||
|
60
group.lua
60
group.lua
@ -1,4 +1,5 @@
|
||||
local S = minetest.get_translator("unified_inventory")
|
||||
local ui = unified_inventory
|
||||
|
||||
function unified_inventory.extract_groupnames(groupname)
|
||||
local specname = ItemStack(groupname):get_name()
|
||||
@ -26,6 +27,7 @@ end
|
||||
-- It may be a comma-separated list of group names. This is really a
|
||||
-- "group:..." ingredient specification, minus the "group:" prefix.
|
||||
|
||||
-- TODO Replace this with the more efficient spec matcher (below)
|
||||
local function compute_group_item(group_name_list)
|
||||
local group_names = group_name_list:split(",")
|
||||
local candidate_items = {}
|
||||
@ -84,3 +86,61 @@ function unified_inventory.get_group_item(group_name)
|
||||
return group_item_cache[group_name]
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
This is for filtering known items by groups
|
||||
e.g. find all items that match "group:flower,yellow" (flower AND yellow groups)
|
||||
]]
|
||||
local spec_matcher = {}
|
||||
function unified_inventory.init_matching_cache()
|
||||
for _, name in ipairs(ui.items_list) do
|
||||
-- we only need to care about groups, exact items are handled separately
|
||||
for group, value in pairs(minetest.registered_items[name].groups) do
|
||||
if value and value ~= 0 then
|
||||
if not spec_matcher[group] then
|
||||
spec_matcher[group] = {}
|
||||
end
|
||||
spec_matcher[group][name] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
Retrieves all matching items
|
||||
|
||||
Arguments:
|
||||
specname (string): Item name or group(s) to filter
|
||||
|
||||
Output:
|
||||
{
|
||||
matchingitem1 = true,
|
||||
...
|
||||
}
|
||||
]]
|
||||
function unified_inventory.get_matching_items(specname)
|
||||
if specname:sub(1,6) ~= "group:" then
|
||||
return { [specname] = true }
|
||||
end
|
||||
|
||||
local accepted = {}
|
||||
for i, group in ipairs(specname:sub(7):split(",")) do
|
||||
if i == 1 then
|
||||
-- First step: Copy all possible item names in this group
|
||||
for name, _ in pairs(spec_matcher[group] or {}) do
|
||||
accepted[name] = true
|
||||
end
|
||||
else
|
||||
-- Perform filtering
|
||||
if spec_matcher[group] then
|
||||
for name, _ in pairs(accepted) do
|
||||
accepted[name] = spec_matcher[group][name]
|
||||
end
|
||||
else
|
||||
-- No matching items
|
||||
return {}
|
||||
end
|
||||
end
|
||||
end
|
||||
return accepted
|
||||
end
|
||||
|
2
init.lua
2
init.lua
@ -195,3 +195,5 @@ end
|
||||
dofile(modpath.."/item_names.lua")
|
||||
dofile(modpath.."/waypoints.lua")
|
||||
dofile(modpath.."/legacy.lua") -- mod compatibility
|
||||
|
||||
minetest.log("action", "[unified_inventory] loaded.")
|
||||
|
@ -274,9 +274,11 @@ local function formspec_add_item_browser(player, formspec, ui_peruser)
|
||||
end
|
||||
end
|
||||
end
|
||||
formspec[n] = string.format("label[%f,%f;%s: %s]",
|
||||
ui_peruser.page_buttons_x + ui_peruser.btn_spc * (ui_peruser.is_lite_mode and 1 or 2),
|
||||
ui_peruser.page_buttons_y + 0.1 + ui_peruser.btn_spc * 2,
|
||||
formspec[n] = "style[page_number;content_offset=0]"
|
||||
formspec[n + 1] = string.format("image_button[%f,%f;%f,0.4;;page_number;%s: %s;false;false;]",
|
||||
ui_peruser.page_buttons_x,
|
||||
ui_peruser.page_buttons_y + ui_peruser.btn_spc * 2 - 0.1,
|
||||
ui_peruser.btn_spc * (bn - 1) + ui_peruser.btn_size,
|
||||
F(S("Page")), S("@1 of @2",page2,pagemax))
|
||||
end
|
||||
|
||||
|
@ -126,25 +126,18 @@ Example output:
|
||||
}
|
||||
--]]
|
||||
function unified_inventory.find_usable_items(inv_items, craft_items)
|
||||
local get_group = minetest.get_item_group
|
||||
local result = {}
|
||||
|
||||
for craft_item in pairs(craft_items) do
|
||||
local group = craft_item:match("^group:(.+)")
|
||||
local found = {}
|
||||
-- may specify group:type1,type2
|
||||
local items = unified_inventory.get_matching_items(craft_item)
|
||||
|
||||
if group ~= nil then
|
||||
for inv_item in pairs(inv_items) do
|
||||
if get_group(inv_item, group) > 0 then
|
||||
found[inv_item] = true
|
||||
end
|
||||
end
|
||||
else
|
||||
if inv_items[craft_item] ~= nil then
|
||||
found[craft_item] = true
|
||||
local found = {}
|
||||
for itemname, _ in pairs(items) do
|
||||
if inv_items[itemname] then
|
||||
found[itemname] = true
|
||||
end
|
||||
end
|
||||
|
||||
result[craft_item] = found
|
||||
end
|
||||
|
||||
|
57
register.lua
57
register.lua
@ -41,55 +41,6 @@ ui.register_button("craftguide", {
|
||||
tooltip = S("Crafting Guide")
|
||||
})
|
||||
|
||||
ui.register_button("home_gui_set", {
|
||||
type = "image",
|
||||
image = "ui_sethome_icon.png",
|
||||
tooltip = S("Set home position"),
|
||||
hide_lite=true,
|
||||
action = function(player)
|
||||
local player_name = player:get_player_name()
|
||||
if minetest.check_player_privs(player_name, {home=true}) then
|
||||
ui.set_home(player, player:get_pos())
|
||||
local home = ui.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: @1", minetest.pos_to_string(home)))
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(player_name,
|
||||
S("You don't have the \"home\" privilege!"))
|
||||
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||
end
|
||||
end,
|
||||
condition = function(player)
|
||||
return minetest.check_player_privs(player:get_player_name(), {home=true})
|
||||
end,
|
||||
})
|
||||
|
||||
ui.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
|
||||
if ui.go_home(player) then
|
||||
minetest.sound_play("teleport", {to_player = player_name})
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(player_name,
|
||||
S("You don't have the \"home\" privilege!"))
|
||||
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
||||
end
|
||||
end,
|
||||
condition = function(player)
|
||||
return minetest.check_player_privs(player:get_player_name(), {home=true})
|
||||
end,
|
||||
})
|
||||
|
||||
ui.register_button("misc_set_day", {
|
||||
type = "image",
|
||||
image = "ui_sun_icon.png",
|
||||
@ -98,7 +49,7 @@ ui.register_button("misc_set_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",
|
||||
minetest.sound_play("ui_morning",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
minetest.set_timeofday((6000 % 24000) / 24000)
|
||||
minetest.chat_send_player(player_name,
|
||||
@ -122,7 +73,7 @@ ui.register_button("misc_set_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",
|
||||
minetest.sound_play("ui_owl",
|
||||
{to_player=player_name, gain = 1.0})
|
||||
minetest.set_timeofday((21000 % 24000) / 24000)
|
||||
minetest.chat_send_player(player_name,
|
||||
@ -183,14 +134,14 @@ ui.register_page("craft", {
|
||||
local n=#formspec+1
|
||||
|
||||
if ui.trash_enabled or ui.is_creative(player_name) or minetest.get_player_privs(player_name).give then
|
||||
formspec[n] = string.format("label[%f,%f;%s]", craftx + 6.45, crafty + 2.4, F(S("Trash:")))
|
||||
formspec[n] = string.format("label[%f,%f;%s]", craftx + 6.35, crafty + 2.3, F(S("Trash:")))
|
||||
formspec[n+1] = ui.make_trash_slot(craftx + 6.25, crafty + 2.5)
|
||||
n=n + 2
|
||||
end
|
||||
|
||||
if ui.is_creative(player_name) then
|
||||
formspec[n] = ui.single_slot(craftx - 2.5, crafty + 2.5)
|
||||
formspec[n+1] = string.format("label[%f,%f;%s]", craftx - 2.3, crafty + 2.4,F(S("Refill:")))
|
||||
formspec[n+1] = string.format("label[%f,%f;%s]", craftx - 2.4, crafty + 2.3, F(S("Refill:")))
|
||||
formspec[n+2] = string.format("list[detached:%srefill;main;%f,%f;1,1;]",
|
||||
F(player_name), craftx - 2.5 + ui.list_img_offset, crafty + 2.5 + ui.list_img_offset)
|
||||
end
|
||||
|
BIN
sounds/birds.ogg
BIN
sounds/birds.ogg
Binary file not shown.
BIN
sounds/owl.ogg
BIN
sounds/owl.ogg
Binary file not shown.
BIN
sounds/ui_click.ogg
Normal file
BIN
sounds/ui_click.ogg
Normal file
Binary file not shown.
BIN
sounds/ui_morning.ogg
Normal file
BIN
sounds/ui_morning.ogg
Normal file
Binary file not shown.
BIN
sounds/ui_owl.ogg
Normal file
BIN
sounds/ui_owl.ogg
Normal file
Binary file not shown.
BIN
textures/ui_teleport.png
Normal file
BIN
textures/ui_teleport.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
@ -140,36 +140,49 @@ ui.register_page("waypoints", {
|
||||
|
||||
-- Main buttons:
|
||||
local btnlist = {
|
||||
set_waypoint = {
|
||||
"ui_waypoint_set_icon.png",
|
||||
S("Set waypoint to current location")
|
||||
},
|
||||
toggle_waypoint = {
|
||||
-- 1. formspec name
|
||||
-- 2. button image
|
||||
-- 3. translation text
|
||||
{
|
||||
"toggle_waypoint",
|
||||
waypoint.active and "ui_on_icon.png" or "ui_off_icon.png",
|
||||
waypoint.active and S("Hide waypoint") or S("Show waypoint")
|
||||
},
|
||||
toggle_display_pos = {
|
||||
{
|
||||
"rename_waypoint",
|
||||
"ui_pencil_icon.png",
|
||||
S("Edit waypoint name")
|
||||
},
|
||||
{
|
||||
"set_waypoint",
|
||||
"ui_waypoint_set_icon.png",
|
||||
S("Set waypoint to current location")
|
||||
},
|
||||
{
|
||||
"toggle_display_pos",
|
||||
waypoint.display_pos and "ui_green_icon_background.png^ui_xyz_icon.png" or "ui_red_icon_background.png^ui_xyz_icon.png^(ui_no.png^[transformR90)",
|
||||
waypoint.display_pos and S("Hide coordinates") or S("Show coordinates")
|
||||
},
|
||||
toggle_color = {
|
||||
{
|
||||
"toggle_color",
|
||||
"ui_circular_arrows_icon.png",
|
||||
S("Change color of waypoint display")
|
||||
},
|
||||
rename_waypoint = {
|
||||
"ui_pencil_icon.png",
|
||||
S("Edit waypoint name")
|
||||
}
|
||||
}
|
||||
if minetest.get_player_privs(player_name).teleport then
|
||||
table.insert(btnlist, {
|
||||
"teleport_waypoint",
|
||||
"ui_teleport.png",
|
||||
S("Teleport to waypoint")
|
||||
})
|
||||
end
|
||||
|
||||
local x = 4
|
||||
for name, def in pairs(btnlist) do
|
||||
for i, def in pairs(btnlist) do
|
||||
formspec[n] = string.format("image_button[%f,%f;%f,%f;%s;%s%i;]",
|
||||
wp_buttons_rj - ui.style_full.btn_spc * x, wp_bottom_row,
|
||||
wp_buttons_rj + ui.style_full.btn_spc * (i - #btnlist), wp_bottom_row,
|
||||
ui.style_full.btn_size, ui.style_full.btn_size,
|
||||
def[1], name, sel)
|
||||
formspec[n+1] = "tooltip["..name..sel..";"..F(def[2]).."]"
|
||||
x = x - 1
|
||||
def[2], def[1], sel)
|
||||
formspec[n+1] = "tooltip["..def[1]..sel..";"..F(def[3]).."]"
|
||||
n = n + 2
|
||||
end
|
||||
|
||||
@ -313,6 +326,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
update_formspec = true
|
||||
end
|
||||
|
||||
if fields["teleport_waypoint" .. i] and waypoint.world_pos then
|
||||
if minetest.get_player_privs(player_name).teleport then
|
||||
minetest.sound_play("teleport", {to_player = player_name})
|
||||
player:set_pos(waypoint.world_pos)
|
||||
end
|
||||
end
|
||||
|
||||
if hit then
|
||||
-- Save first
|
||||
waypoints.data[i] = waypoint
|
||||
@ -323,6 +343,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
update_hud(player, waypoints, temp, i)
|
||||
end
|
||||
if update_formspec then
|
||||
minetest.sound_play("ui_click", {to_player=player_name, gain = 0.1})
|
||||
ui.set_inventory_formspec(player, "waypoints")
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user