diff options
Diffstat (limited to 'unified_inventory')
-rw-r--r-- | unified_inventory/api.lua | 8 | ||||
-rw-r--r-- | unified_inventory/bags.lua | 90 | ||||
-rw-r--r-- | unified_inventory/callbacks.lua | 5 | ||||
-rw-r--r-- | unified_inventory/depends.txt | 2 | ||||
-rw-r--r-- | unified_inventory/init.lua | 24 | ||||
-rw-r--r-- | unified_inventory/internal.lua | 27 | ||||
-rw-r--r-- | unified_inventory/locale/de.txt | 5 | ||||
-rw-r--r-- | unified_inventory/locale/es.txt | 8 | ||||
-rw-r--r-- | unified_inventory/locale/fr.txt | 5 | ||||
-rw-r--r-- | unified_inventory/locale/pl.txt | 5 | ||||
-rw-r--r-- | unified_inventory/locale/ru.txt | 5 | ||||
-rw-r--r-- | unified_inventory/locale/template.txt | 5 | ||||
-rw-r--r-- | unified_inventory/locale/tr.txt | 5 | ||||
-rw-r--r-- | unified_inventory/register.lua | 32 | ||||
-rw-r--r-- | unified_inventory/settingtypes.txt | 7 | ||||
-rw-r--r-- | unified_inventory/textures/ui_bags_trash.png | bin | 0 -> 1790 bytes |
16 files changed, 111 insertions, 122 deletions
diff --git a/unified_inventory/api.lua b/unified_inventory/api.lua index 936ee72..e1b980a 100644 --- a/unified_inventory/api.lua +++ b/unified_inventory/api.lua @@ -82,9 +82,11 @@ minetest.after(0.01, function() -- appears after a “maybe” local max_start = true -- Let's iterate through the items madness! - for i=1,#def.drop.items do + -- Handle invalid drop entries gracefully. + local drop_items = def.drop.items or { } + for i=1,#drop_items do if max_items_left ~= nil and max_items_left <= 0 then break end - local itit = def.drop.items[i] + local itit = 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 @@ -133,7 +135,7 @@ minetest.after(0.01, function() for _, recipes in pairs(unified_inventory.crafts_for.recipe) do for _, recipe in ipairs(recipes) do local ingredient_items = {} - for _, spec in ipairs(recipe.items) do + for _, spec in pairs(recipe.items) do local matches_spec = unified_inventory.canonical_item_spec_matcher(spec) for _, name in ipairs(unified_inventory.items_list) do if matches_spec(name) then diff --git a/unified_inventory/bags.lua b/unified_inventory/bags.lua index 7e925db..4af4ff5 100644 --- a/unified_inventory/bags.lua +++ b/unified_inventory/bags.lua @@ -31,80 +31,18 @@ unified_inventory.register_button("bags", { hide_lite=true }) - - unified_inventory.register_page("bag1", { - get_formspec = function(player) - 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;"..F("Bag 1").."]" - formspec = formspec.."listcolors[#00000000;#00000000]" - 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", { +for i = 1, 4 do + local bi = i + unified_inventory.register_page("bag"..bi, { get_formspec = function(player) - local stack = player:get_inventory():get_stack("bag3", 1) + local stack = player:get_inventory():get_stack("bag"..bi, 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 formspec = ("image[7,0;1,1;"..image.."]" + .."label[0,0;"..F("Bag @1", bi).."]" + .."listcolors[#00000000;#00000000]" + .."list[current_player;bag"..bi.."contents;0,1;8,3;]" + .."listring[current_name;bag"..bi.."contents]" + .."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]" @@ -113,9 +51,12 @@ unified_inventory.register_button("bags", { elseif slots == 24 then formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]" end + formspec = (formspec.."background[6.06,0;0.92,0.92;ui_bags_trash.png]" + .."list[detached:trash;main;6,0.1;1,1;]") return {formspec=formspec} end, }) +end minetest.register_on_player_receive_fields(function(player, formname, fields) if formname ~= "" then @@ -135,7 +76,8 @@ end) minetest.register_on_joinplayer(function(player) local player_inv = player:get_inventory() - local bags_inv = minetest.create_detached_inventory(player:get_player_name().."_bags",{ + local player_name = player:get_player_name() + local bags_inv = minetest.create_detached_inventory(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", @@ -186,7 +128,7 @@ minetest.register_on_joinplayer(function(player) allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) return 0 end, - }) + }, player_name) for i=1,4 do local bag = "bag"..i player_inv:set_size(bag, 1) diff --git a/unified_inventory/callbacks.lua b/unified_inventory/callbacks.lua index ad6de0a..e6ea3e7 100644 --- a/unified_inventory/callbacks.lua +++ b/unified_inventory/callbacks.lua @@ -43,7 +43,7 @@ minetest.register_on_joinplayer(function(player) minetest.sound_play("electricity", {to_player=player_name, gain = 1.0}) end, - }) + }, player_name) refill:set_size("main", 1) end) @@ -154,7 +154,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) 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.set_inventory_formspec(player, unified_inventory.current_page[player_name]) diff --git a/unified_inventory/depends.txt b/unified_inventory/depends.txt index 3879b2c..20eb8b0 100644 --- a/unified_inventory/depends.txt +++ b/unified_inventory/depends.txt @@ -1,4 +1,6 @@ +default creative? +sfinv? intllib? datastorage? farming? diff --git a/unified_inventory/init.lua b/unified_inventory/init.lua index e24fff2..67bc56e 100644 --- a/unified_inventory/init.lua +++ b/unified_inventory/init.lua @@ -2,7 +2,15 @@ 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 +local mygettext +if rawget(_G, "intllib") then + mygettext = intllib.Getter() +else + function mygettext(s, ...) + local t = { ... } + return (s:gsub("@(%d+)", function(n) return t[tonumber(n)] end)) + end +end -- Data tables definitions unified_inventory = { @@ -33,7 +41,7 @@ unified_inventory = { -- intllib gettext = mygettext, - fgettext = function(s) return minetest.formspec_escape(mygettext(s)) end, + fgettext = function(...) return minetest.formspec_escape(mygettext(...)) end, -- "Lite" mode lite_mode = minetest.setting_getbool("unified_inventory_lite"), @@ -57,16 +65,24 @@ if creative then end end +-- Disable sfinv inventory +local sfinv = rawget(_G, "sfinv") +if sfinv then + sfinv.enabled = false +end + dofile(modpath.."/group.lua") dofile(modpath.."/api.lua") dofile(modpath.."/internal.lua") dofile(modpath.."/callbacks.lua") dofile(modpath.."/register.lua") -dofile(modpath.."/bags.lua") + +if minetest.setting_getbool("unified_inventory_bags") ~= false then + dofile(modpath.."/bags.lua") +end dofile(modpath.."/item_names.lua") if minetest.get_modpath("datastorage") then dofile(modpath.."/waypoints.lua") end - diff --git a/unified_inventory/internal.lua b/unified_inventory/internal.lua index 42ab722..5732971 100644 --- a/unified_inventory/internal.lua +++ b/unified_inventory/internal.lua @@ -107,14 +107,23 @@ function unified_inventory.get_formspec(player, page) 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 + if (def.condition == nil or def.condition(player) == true) 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 + else + formspec[n] = "image[" + 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).."^[colorize:#808080:alpha]" + n = n+4 + + end end end @@ -173,6 +182,8 @@ function unified_inventory.get_formspec(player, page) n = n+1 -- Search box + 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;;" diff --git a/unified_inventory/locale/de.txt b/unified_inventory/locale/de.txt index a2f7c3d..ad8009d 100644 --- a/unified_inventory/locale/de.txt +++ b/unified_inventory/locale/de.txt @@ -5,10 +5,7 @@ Digging (by chance) = Graben (durch Zufall) ### bags.lua ### Bags = Taschen -Bag 1 = Tasche 1 -Bag 2 = Tasche 2 -Bag 3 = Tasche 3 -Bag 4 = Tasche 4 +Bag @1 = Tasche @1 Small Bag = Kleine Tasche Medium Bag = Mittelgroße Tasche Large Bag = Große Tasche diff --git a/unified_inventory/locale/es.txt b/unified_inventory/locale/es.txt index 26508fb..d8c0dd6 100644 --- a/unified_inventory/locale/es.txt +++ b/unified_inventory/locale/es.txt @@ -1,12 +1,12 @@ # Translation by Diego Martínez <kaeza> +### api.lua ### +Digging (by chance) = Excavado (por azar) + # Template ### bags.lua ### Bags = Bolsas -Bag 1 = Bolsa 1 -Bag 2 = Bolsa 2 -Bag 3 = Bolsa 3 -Bag 4 = Bolsa 4 +Bag @1 = Bolsa @1 Small Bag = Bolsa Pequeña Medium Bag = Bolsa Mediana Large Bag = Bolsa Grande diff --git a/unified_inventory/locale/fr.txt b/unified_inventory/locale/fr.txt index e4923a0..43c52f0 100644 --- a/unified_inventory/locale/fr.txt +++ b/unified_inventory/locale/fr.txt @@ -3,10 +3,7 @@ # Template ### bags.lua ### Bags = Sacs -Bag 1 = Sac 1 -Bag 2 = Sac 2 -Bag 3 = Sac 3 -Bag 4 = Sac 4 +Bag @1 = Sac @1 Small Bag = Petit sac Medium Bag = Sac moyen Large Bag = Grand sac diff --git a/unified_inventory/locale/pl.txt b/unified_inventory/locale/pl.txt index 6173a5f..ef3e821 100644 --- a/unified_inventory/locale/pl.txt +++ b/unified_inventory/locale/pl.txt @@ -2,10 +2,7 @@ ### bags.lua ### Bags = Plecaki -Bag 1 = Plecak 1 -Bag 2 = Plecak 2 -Bag 3 = Plecak 3 -Bag 4 = Plecak 4 +Bag @1 = Plecak @1 Small Bag = Maly plecak Medium Bag = Sredni plecak Large Bag = Duzy plecak diff --git a/unified_inventory/locale/ru.txt b/unified_inventory/locale/ru.txt index 821f2b1..a7bbe54 100644 --- a/unified_inventory/locale/ru.txt +++ b/unified_inventory/locale/ru.txt @@ -3,10 +3,7 @@ # Template ### bags.lua ### Bags = Сумки -Bag 1 = Сумка 1 -Bag 2 = Сумка 2 -Bag 3 = Сумка 3 -Bag 4 = Сумка 4 +Bag @1 = Сумка @1 Small Bag = Малая сумка Medium Bag = Средняя сумка Large Bag = Большая сумка diff --git a/unified_inventory/locale/template.txt b/unified_inventory/locale/template.txt index bd27f2f..0ea805b 100644 --- a/unified_inventory/locale/template.txt +++ b/unified_inventory/locale/template.txt @@ -6,10 +6,7 @@ Digging (by chance) = # Template ### bags.lua ### Bags = -Bag 1 = -Bag 2 = -Bag 3 = -Bag 4 = +Bag @1 = Small Bag = Medium Bag = Large Bag = diff --git a/unified_inventory/locale/tr.txt b/unified_inventory/locale/tr.txt index 138e66c..e171fd6 100644 --- a/unified_inventory/locale/tr.txt +++ b/unified_inventory/locale/tr.txt @@ -3,10 +3,7 @@ # Template ### bags.lua ### Bags = Çantalarım -Bag 1 = 1. Çanta -Bag 2 = 2. Çanta -Bag 3 = 3. Çanta -Bag 4 = 4. Çanta +Bag @1 = @1. Çanta Small Bag = Küçük Çanta Medium Bag = Çanta Large Bag = Büyük Çanta diff --git a/unified_inventory/register.lua b/unified_inventory/register.lua index ff38168..127df7e 100644 --- a/unified_inventory/register.lua +++ b/unified_inventory/register.lua @@ -59,8 +59,12 @@ unified_inventory.register_button("home_gui_set", { else minetest.chat_send_player(player_name, S("You don't have the \"home\" privilege!")) + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) end end, + condition = function(player) + return minetest.check_player_privs(player:get_player_name(), {home=true}) + end, }) unified_inventory.register_button("home_gui_go", { @@ -77,8 +81,12 @@ unified_inventory.register_button("home_gui_go", { else minetest.chat_send_player(player_name, S("You don't have the \"home\" privilege!")) + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) end end, + condition = function(player) + return minetest.check_player_privs(player:get_player_name(), {home=true}) + end, }) unified_inventory.register_button("misc_set_day", { @@ -97,8 +105,12 @@ unified_inventory.register_button("misc_set_day", { else minetest.chat_send_player(player_name, S("You don't have the settime privilege!")) + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) end end, + condition = function(player) + return minetest.check_player_privs(player:get_player_name(), {settime=true}) + end, }) unified_inventory.register_button("misc_set_night", { @@ -117,8 +129,12 @@ unified_inventory.register_button("misc_set_night", { else minetest.chat_send_player(player_name, S("You don't have the settime privilege!")) + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) end end, + condition = function(player) + return minetest.check_player_privs(player:get_player_name(), {settime=true}) + end, }) unified_inventory.register_button("clear_inv", { @@ -133,6 +149,7 @@ unified_inventory.register_button("clear_inv", { .." of creative mode to prevent" .." accidental inventory trashing." .."\nUse the trash slot instead.")) + unified_inventory.set_inventory_formspec(player, unified_inventory.current_page[player_name]) return end player:get_inventory():set_list("main", {}) @@ -140,6 +157,9 @@ unified_inventory.register_button("clear_inv", { minetest.sound_play("trash_all", {to_player=player_name, gain = 1.0}) end, + condition = function(player) + return unified_inventory.is_creative(player:get_player_name()) + end, }) unified_inventory.register_page("craft", { @@ -249,6 +269,12 @@ unified_inventory.register_page("craftguide", { formspec = formspec.."listcolors[#00000000;#00000000]" local item_name = unified_inventory.current_item[player_name] if not item_name then return {formspec=formspec} end + local item_name_shown + if minetest.registered_items[item_name] and minetest.registered_items[item_name].description then + item_name_shown = string.format(S("%s (%s)"), minetest.registered_items[item_name].description, item_name) + else + item_name_shown = item_name + end local dir = unified_inventory.current_craft_direction[player_name] local rdir @@ -264,7 +290,7 @@ unified_inventory.register_page("craftguide", { 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)..";]" + ..";10,1;;"..minetest.formspec_escape(F(role_text[dir])..": "..item_name_shown)..";]" formspec = formspec..stack_image_button(0, formspecy, 1.1, 1.1, "item_button_" .. rdir .. "_", ItemStack(item_name)) @@ -276,7 +302,7 @@ unified_inventory.register_page("craftguide", { 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 + if player_privs.give == true or player_privs.creative == true or minetest.setting_getbool("creative_mode") == 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]" @@ -353,7 +379,7 @@ unified_inventory.register_page("craftguide", { .."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 + if player_privs.give == true or player_privs.creative == true or minetest.setting_getbool("creative_mode") == true 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]" diff --git a/unified_inventory/settingtypes.txt b/unified_inventory/settingtypes.txt new file mode 100644 index 0000000..1054fa9 --- /dev/null +++ b/unified_inventory/settingtypes.txt @@ -0,0 +1,7 @@ +#Enabling lite mode enables a smaller and simpler version of the Unified +#Inventory, optimized for small displays. +unified_inventory_lite (Lite mode) bool false + +#If enabled, bags will be made available which can be used to extend +#inventory storage size. +unified_inventory_bags (Enable bags) bool true diff --git a/unified_inventory/textures/ui_bags_trash.png b/unified_inventory/textures/ui_bags_trash.png Binary files differnew file mode 100644 index 0000000..6338999 --- /dev/null +++ b/unified_inventory/textures/ui_bags_trash.png |