From 75a0e6a31880bb3b0412288e7add99257805e8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Mart=C3=ADnez?= Date: Sat, 8 Oct 2016 06:07:41 -0300 Subject: [PATCH] Bags: Code cleanup and per-bag trash slot. * Turn page creation into a loop. * Add per-bag trash slot. * Changed i18n to allow replacements. --- bags.lua | 85 ++++++------------------------------- init.lua | 12 +++++- locale/de.txt | 5 +-- locale/es.txt | 8 ++-- locale/fr.txt | 5 +-- locale/pl.txt | 5 +-- locale/ru.txt | 5 +-- locale/template.txt | 5 +-- locale/tr.txt | 5 +-- textures/ui_bags_trash.png | Bin 0 -> 1790 bytes 10 files changed, 33 insertions(+), 102 deletions(-) create mode 100644 textures/ui_bags_trash.png diff --git a/bags.lua b/bags.lua index 7e925db..6cedffa 100644 --- a/bags.lua +++ b/bags.lua @@ -31,80 +31,18 @@ unified_inventory.register_button("bags", { hide_lite=true }) - - unified_inventory.register_page("bag1", { +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("bag1", 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 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", { - 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 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 diff --git a/init.lua b/init.lua index e24fff2..f92d278 100644 --- a/init.lua +++ b/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"), diff --git a/locale/de.txt b/locale/de.txt index a2f7c3d..ad8009d 100644 --- a/locale/de.txt +++ b/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/locale/es.txt b/locale/es.txt index 26508fb..d8c0dd6 100644 --- a/locale/es.txt +++ b/locale/es.txt @@ -1,12 +1,12 @@ # Translation by Diego Martínez +### 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/locale/fr.txt b/locale/fr.txt index e4923a0..43c52f0 100644 --- a/locale/fr.txt +++ b/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/locale/pl.txt b/locale/pl.txt index 6173a5f..ef3e821 100644 --- a/locale/pl.txt +++ b/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/locale/ru.txt b/locale/ru.txt index 821f2b1..a7bbe54 100644 --- a/locale/ru.txt +++ b/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/locale/template.txt b/locale/template.txt index bd27f2f..0ea805b 100644 --- a/locale/template.txt +++ b/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/locale/tr.txt b/locale/tr.txt index 138e66c..e171fd6 100644 --- a/locale/tr.txt +++ b/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/textures/ui_bags_trash.png b/textures/ui_bags_trash.png new file mode 100644 index 0000000000000000000000000000000000000000..6338999bc490da6d0fea459adf335377e18c336c GIT binary patch literal 1790 zcmVS}2eAJEw_RGa+E_wVDcz2S=jj>ltm{rdGso12@z zj7B5Y@Au((9vsJk<1D28nIOwDWLbtJNuZR%bUMZ7&!5fF(a}=?`)}U7G4tL#SA|=* zZpj-rZv4HqwRLS{V*|eL!*yM7&d-&2z_EY;ptXk98cHcBrEqj~gvn&`!5H)1t5>gP zdgDwbZr;4fZr{HB@Amfgwc&6G-}fPeXz&r%hb+r-A=5NP6h(;R_=Dp(+xz?bB~N6t zE;1gEA8l=IT{!Uoz;PT1A>er)f*`FDo12?=Mxzn)Jg*ZE0OuTG7^2_rLrQtK_h; z1hm6eDFtH;T-QYq1TzJp#XXIYX_^99eK*%?JqZtplw?#V^k%G!+xxJXvj zTIV9u*asYY=DZMI#=fnrU7LW*W>pGnAq284%e{`mzN&p&S-Um?m(8k8(^l55O~7Td zYSXlpwQKi4d(8V%R&5$PYXirEN+}_wto1&%j)7FsilXTF;$O(BO=D+mLTf#9N>zo% zvM`0rye!!?cGhlkcfGbNQ`Yl54@#-r8BM6x^J4M`3yixY1cIJ`D0zwCLrfLAE52l4_YSo-Vb_9hpjh+$78@#cQaHD9L_s40+95_Y+B8k)w)@rvH8lw#z!-z) zd5yGl*fb)b9b(k2N@d7d4d->H`>TVG@ga+aF$Xw9>Ns9ZFMO$E}$LGQp!d> zu=wkwHfUVHVmO~SW`0fU@@w#Q;A@`TZ6++pJf|uNxQY&^b;a)Oo_AthX$Mbw3qtN&;%F|7vosc2=PIq}`+*hT)$@yOMxPsRQcx zyr|IRzt`)5PVMwO4`CP{6m4e-_)aNh=t6ByO4k9}MH&nS7!HS^BLGhp18%h)R=8t=j|%zxQ*V)OCv@bI^p@1J+!=g*(Z;c)nml=3Qhp%4N> zh;y}4q4hIG8|@)dv>9VQPN&nI`}glJeh4k`;>8OlrF`7$^?nV4U}e9>Xc7{TL?lN! zagryK$>g^O4<0Ok46@D3moKI3x_5;TdjNi7jGe24xM`Ikgiun---QqdX_~&hckkX; g5903V=s45-2aKsLp4S>1^#A|>07*qoM6N<$f_6A-!2kdN literal 0 HcmV?d00001