Bags: Code cleanup and per-bag trash slot.

* Turn page creation into a loop.
* Add per-bag trash slot.
* Changed i18n to allow replacements.
This commit is contained in:
Diego Martínez 2016-10-08 06:07:41 -03:00
parent 5b9a53bf29
commit 75a0e6a318
10 changed files with 33 additions and 102 deletions

@ -31,80 +31,18 @@ unified_inventory.register_button("bags", {
hide_lite=true hide_lite=true
}) })
for i = 1, 4 do
unified_inventory.register_page("bag1", { local bi = i
unified_inventory.register_page("bag"..bi, {
get_formspec = function(player) get_formspec = function(player)
local stack = player:get_inventory():get_stack("bag1", 1) local stack = player:get_inventory():get_stack("bag"..bi, 1)
local image = stack:get_definition().inventory_image local image = stack:get_definition().inventory_image
local formspec = "image[7,0;1,1;"..image.."]" local formspec = ("image[7,0;1,1;"..image.."]"
formspec = formspec.."label[0,0;"..F("Bag 1").."]" .."label[0,0;"..F("Bag @1", bi).."]"
formspec = formspec.."listcolors[#00000000;#00000000]" .."listcolors[#00000000;#00000000]"
formspec = formspec.."list[current_player;bag1contents;0,1;8,3;]" .."list[current_player;bag"..bi.."contents;0,1;8,3;]"
formspec = formspec.."listring[current_name;bag1contents]" .."listring[current_name;bag"..bi.."contents]"
formspec = formspec.."listring[current_player;main]" .."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 local slots = stack:get_definition().groups.bagslots
if slots == 8 then if slots == 8 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]" 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 elseif slots == 24 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]" formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]"
end 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} return {formspec=formspec}
end, end,
}) })
end
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "" then if formname ~= "" then

@ -2,7 +2,15 @@
local modpath = minetest.get_modpath(minetest.get_current_modname()) local modpath = minetest.get_modpath(minetest.get_current_modname())
local worldpath = minetest.get_worldpath() 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 -- Data tables definitions
unified_inventory = { unified_inventory = {
@ -33,7 +41,7 @@ unified_inventory = {
-- intllib -- intllib
gettext = mygettext, gettext = mygettext,
fgettext = function(s) return minetest.formspec_escape(mygettext(s)) end, fgettext = function(...) return minetest.formspec_escape(mygettext(...)) end,
-- "Lite" mode -- "Lite" mode
lite_mode = minetest.setting_getbool("unified_inventory_lite"), lite_mode = minetest.setting_getbool("unified_inventory_lite"),

@ -5,10 +5,7 @@ Digging (by chance) = Graben (durch Zufall)
### bags.lua ### ### bags.lua ###
Bags = Taschen Bags = Taschen
Bag 1 = Tasche 1 Bag @1 = Tasche @1
Bag 2 = Tasche 2
Bag 3 = Tasche 3
Bag 4 = Tasche 4
Small Bag = Kleine Tasche Small Bag = Kleine Tasche
Medium Bag = Mittelgroße Tasche Medium Bag = Mittelgroße Tasche
Large Bag = Große Tasche Large Bag = Große Tasche

@ -1,12 +1,12 @@
# Translation by Diego Martínez <kaeza> # Translation by Diego Martínez <kaeza>
### api.lua ###
Digging (by chance) = Excavado (por azar)
# Template # Template
### bags.lua ### ### bags.lua ###
Bags = Bolsas Bags = Bolsas
Bag 1 = Bolsa 1 Bag @1 = Bolsa @1
Bag 2 = Bolsa 2
Bag 3 = Bolsa 3
Bag 4 = Bolsa 4
Small Bag = Bolsa Pequeña Small Bag = Bolsa Pequeña
Medium Bag = Bolsa Mediana Medium Bag = Bolsa Mediana
Large Bag = Bolsa Grande Large Bag = Bolsa Grande

@ -3,10 +3,7 @@
# Template # Template
### bags.lua ### ### bags.lua ###
Bags = Sacs Bags = Sacs
Bag 1 = Sac 1 Bag @1 = Sac @1
Bag 2 = Sac 2
Bag 3 = Sac 3
Bag 4 = Sac 4
Small Bag = Petit sac Small Bag = Petit sac
Medium Bag = Sac moyen Medium Bag = Sac moyen
Large Bag = Grand sac Large Bag = Grand sac

@ -2,10 +2,7 @@
### bags.lua ### ### bags.lua ###
Bags = Plecaki Bags = Plecaki
Bag 1 = Plecak 1 Bag @1 = Plecak @1
Bag 2 = Plecak 2
Bag 3 = Plecak 3
Bag 4 = Plecak 4
Small Bag = Maly plecak Small Bag = Maly plecak
Medium Bag = Sredni plecak Medium Bag = Sredni plecak
Large Bag = Duzy plecak Large Bag = Duzy plecak

@ -3,10 +3,7 @@
# Template # Template
### bags.lua ### ### bags.lua ###
Bags = Сумки Bags = Сумки
Bag 1 = Сумка 1 Bag @1 = Сумка @1
Bag 2 = Сумка 2
Bag 3 = Сумка 3
Bag 4 = Сумка 4
Small Bag = Малая сумка Small Bag = Малая сумка
Medium Bag = Средняя сумка Medium Bag = Средняя сумка
Large Bag = Большая сумка Large Bag = Большая сумка

@ -6,10 +6,7 @@ Digging (by chance) =
# Template # Template
### bags.lua ### ### bags.lua ###
Bags = Bags =
Bag 1 = Bag @1 =
Bag 2 =
Bag 3 =
Bag 4 =
Small Bag = Small Bag =
Medium Bag = Medium Bag =
Large Bag = Large Bag =

@ -3,10 +3,7 @@
# Template # Template
### bags.lua ### ### bags.lua ###
Bags = Çantalarım Bags = Çantalarım
Bag 1 = 1. Çanta Bag @1 = @1. Çanta
Bag 2 = 2. Çanta
Bag 3 = 3. Çanta
Bag 4 = 4. Çanta
Small Bag = Küçük Çanta Small Bag = Küçük Çanta
Medium Bag = Çanta Medium Bag = Çanta
Large Bag = Büyük Çanta Large Bag = Büyük Çanta

BIN
textures/ui_bags_trash.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB