From 3b86d9a7d511c0ac5480a3e7f978004833e4ea33 Mon Sep 17 00:00:00 2001 From: Maksim Date: Wed, 23 Mar 2022 23:37:58 +0100 Subject: [PATCH] Update --- init.lua | 3 +- locale/exchange_shop.fr.tr | 10 ++- locale/exchange_shop.ru.tr | 17 +++++ locale/template.txt | 8 +-- shop.lua | 132 ++++++++++++++++++++----------------- shop_functions.lua | 7 +- 6 files changed, 99 insertions(+), 78 deletions(-) create mode 100644 locale/exchange_shop.ru.tr diff --git a/init.lua b/init.lua index 64cec19..7ce2310 100644 --- a/init.lua +++ b/init.lua @@ -3,8 +3,7 @@ exchange_shop.storage_size = 5 * 4 exchange_shop.shopname = "exchange_shop:shop" -- Internationalisaton ---exchange_shop.S = minetest.get_translator("exchange_shop") -exchange_shop.S = intllib.make_gettext_pair() +exchange_shop.S = minetest.get_translator_auto("ru") exchange_shop.FS = function(...) return minetest.formspec_escape(exchange_shop.S(...)) end diff --git a/locale/exchange_shop.fr.tr b/locale/exchange_shop.fr.tr index 37812dd..c05e324 100644 --- a/locale/exchange_shop.fr.tr +++ b/locale/exchange_shop.fr.tr @@ -6,16 +6,14 @@ Set=Définir You give:=Vous donnez : You get:=Vous recevez : Exchange=Échanger -You need=Vous avez besoin de -You give=Vous donnez -:= : +You need:=Vous avez besoin de Current stock:=Stock affiché : Income=Entrée Outgoing=Sortie Use (E) + (Right click) for customer interface=Utilisez (E) + (Clic droit) pour afficher l'interface du client -owned by @1=propriété de @1 -Exchange shop (owned by @1=Boutique d'échange (propriété de @1 -Exchange shop:=Boutique d'échange : +Exchange Shop: "@1"=Boutique d'échange : "@1" +Owned by @1=Propriété de @1 +Exchange Shop:=Boutique d'échange : Exchange Shop=Boutique d'échange Exchange shop (constructing)=Boutique d'échange (en construction) Cannot dig exchange shop: one or multiple stocks are in use.=Un ou plusieurs stocks sont en cours d'utilisation, impossible d'enlever la boutique d'échange. diff --git a/locale/exchange_shop.ru.tr b/locale/exchange_shop.ru.tr new file mode 100644 index 0000000..33fc4a3 --- /dev/null +++ b/locale/exchange_shop.ru.tr @@ -0,0 +1,17 @@ +# textdomain: exchange_shop + +# shop.lua +Exchange Shop=Обменный Магазин +Exchange Shop:=Обменный Магазин: +Exchange Shop: "@1"=Обменный Магазин: "@1" +Owned by @1=Владелец: @1 + +Current stock:=Склад: +You need:=Вам нужно: +You give:=Вы отдадите: +Exchange=Обменять +You get:=Вы получите: +Income=Полученное +Outgoing=Продаваемое +Title:=Название: +Set=Устан. diff --git a/locale/template.txt b/locale/template.txt index 4a19309..f61d7b2 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -6,15 +6,13 @@ Set= You give:= You get:= Exchange= -You need= -You give= -:= +You need:= Current stock:= Income= Outgoing= Use (E) + (Right click) for customer interface= -owned by @1= -Exchange shop (owned by @1= +Exchange Shop: \"@1\"= +Owned by @1= Exchange shop:= Exchange Shop= Exchange shop (constructing)= diff --git a/shop.lua b/shop.lua index 813dc44..ce80ce1 100644 --- a/shop.lua +++ b/shop.lua @@ -10,23 +10,26 @@ local FS = exchange_shop.FS local shop_positions = {} local function get_exchange_shop_formspec(mode, pos, meta) - local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z + local fs_prepend = default.gui_bg .. -- default.listcolors .. + "background[0,0;0,0;formspec_background_color.png^formspec_backround.png;true]" + + local name = "nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z meta = meta or minetest.get_meta(pos) local function listring(src) - return "listring[".. name ..";" .. src .. "]" .. + return "listring[" .. name .. ";" .. src .. "]" .. "listring[current_player;main]" end local function make_slots(x, y, list, label) - local arrow = "default_arrow_bg.png" - if list == "cust_ow" then - arrow = arrow .. "\\^\\[transformFY" - end + -- local arrow = "default_arrow_bg.png" + -- if list == "cust_ow" then + -- arrow = arrow .. "\\^\\[transformFY" + -- end return table.concat({ - ("label[%f,%f;%s]"):format(x, y - 0.6, label), - ("image[%f,%f;0.6,0.6;shop_front.png]"):format(x + 0.15, y + 0.3), - ("image[%f,%f;0.6,0.6;%s]"):format(x + 0.15, y + 0.0, arrow), - ("list["..name..";%s;%f,%f;2,2;]"):format(list, x, y) + ("label[%f,%f;%s]"):format(x, y - 0.5, label), + -- ("image[%f,%f;0.6,0.6;shop_front.png]"):format(x + 0.15, y + 0.3), + -- ("image[%f,%f;0.6,0.6;%s]"):format(x + 0.15, y + 0.0, arrow), + ("list[" .. name .. ";%s;%f,%f;2,2;]"):format(list, x, y) }) end if mode == "customer" then @@ -34,68 +37,74 @@ local function get_exchange_shop_formspec(mode, pos, meta) -- customer local formspec = ( - (overflow and "size[8,9]" or "size[8,8]").. - make_slots(1, 1, "cust_ow", FS("You give:")) .. - "button[3,2.5;2,1;exchange;" .. FS("Exchange") .. "]".. - make_slots(5, 1, "cust_og", FS("You get:")) + "size[9,8.75]" .. + "item_image[0,-0.1;1,1;".. exchange_shop.shopname .. "]" .. + "label[0.9,0.1;" .. S("Exchange Shop") .. "]" .. + fs_prepend .. + default.gui_close_btn() .. + make_slots(1, 1.1, "cust_ow", FS("You give:")) .. + "button[3,3.2;3,1;exchange;" .. FS("Exchange") .. "]" .. + make_slots(6, 1.1, "cust_og", FS("You get:")) ) -- Insert fallback slots - local inv_pos = 4 + local inv_pos = 4.5 if overflow then formspec = (formspec .. - "label[0.7,3.5;Ejected items:]".. - "label[0.7,3.8;(Remove me!)]".. - "list["..name..";cust_ej;3,3.5;4,1;]" + "label[0.7,3.5;Ejected items:]" .. + "label[0.7,3.8;(Remove me!)]" .. + "list[" .. name .. ";cust_ej;3,3.5;4,1;]" ) inv_pos = 5 end return (formspec .. - "list[current_player;main;0," .. inv_pos .. ";8,4;]".. + "list[current_player;main;0," .. inv_pos .. ";9,4;]" .. (overflow and listring("cust_ej") or "") ) end if mode == "owner_custm" or mode == "owner_stock" then local overflow = not meta:get_inventory():is_empty("custm_ej") - local title = meta:get_string("title") + -- local title = meta:get_string("title") -- owner local formspec = ( - "size[10,10]".. - "label[0,0.1;" .. FS("Title:") .. "]".. - "field[1.2,0.5;3,0.5;title;;"..title.."]".. - "field_close_on_enter[title;false]".. - "button[3.9,0.2;1,0.5;set_title;" .. FS("Set") .. "]".. - make_slots( 0, 2, "cust_ow", FS("You need") .. FS(":")) .. - make_slots(2.5, 2, "cust_og", FS("You give") .. FS(":")) .. - "label[5,0.1;" .. FS("Current stock:") .. "]" + "size[10,10]" .. fs_prepend .. + "item_image[0,-0.1;1,1;".. exchange_shop.shopname .. "]" .. + "label[0.9,0.1;" .. S("Exchange Shop") .. "]" .. + default.gui_close_btn("9.3,-0.1") .. + -- "field[0.3,0.65;3,0.5;title;" .. FS("Title:") .. ";" .. title .. "]" .. + -- "field_close_on_enter[title;false]" .. + -- "button[2.8,0.3;1,0.61;set_title;" .. FS("Set") .. "]" .. + make_slots(0.1, 2, "cust_ow", FS("You need:")) .. + make_slots(2.6, 2, "cust_og", FS("You give:")) .. + "label[5,0.4;" .. FS("Current stock:") .. "]" ) if overflow then - formspec = (formspec.. - "list["..name..";custm_ej;0.2,4;4,1;]".. - "label[0.2,4.9;Ejected items: (Remove me!)]".. + formspec = (formspec .. + "list[" .. name .. ";custm_ej;0.2,4;4,1;]" .. + "label[0.2,4.9;Ejected items: (Remove me!)]" .. listring("custm_ej") ) end local arrow = "default_arrow_bg.png" if mode == "owner_custm" then - formspec = (formspec.. - "button[7.5,0.2;2.5,0.5;view_stock;" .. FS("Income") .. "]".. - "list["..name..";custm;5,1;5,4;]".. + formspec = (formspec .. + "button[6,5.25;2,0.5;view_stock;" .. FS("Income") .. "]" .. + "list[" .. name .. ";custm;5,1;5,4;]" .. listring("custm")) arrow = arrow .. "\\^\\[transformFY" else - formspec = (formspec.. - "button[7.5,0.2;2.5,0.5;view_custm;" .. FS("Outgoing") .. "]".. - "list["..name..";stock;5,1;5,4;]".. + formspec = (formspec .. + "button[6,5.25;2,0.5;view_custm;" .. FS("Outgoing") .. "]" .. + "list[" .. name .. ";stock;5,1;5,4;]" .. listring("stock")) end - return (formspec.. - "label[1,5.4;" .. FS("Use (E) + (Right click) for customer interface") .. "]".. + return (formspec .. + "label[1,5.4;" .. FS("Use (E) + (Right click) for customer interface") .. "]" .. "image[8.2,5.2;0.6,0.6;" .. arrow .. "]" .. - "list[current_player;main;1,6;8,4;]") + "list[current_player;main;0.5,6;9,4;]") end return "" end @@ -113,7 +122,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields) end if (fields.quit and fields.quit ~= "") or - minetest.get_node(pos).name ~= "exchange_shop:shop" then + minetest.get_node(pos).name ~= exchange_shop.shopname then shop_positions[player_name] = nil return end @@ -122,17 +131,15 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields) local title = meta:get_string("title") local shop_owner = meta:get_string("owner") - if fields.title and exchange_shop.has_access(meta, player_name) then + local ftitle = fields.title + if ftitle and exchange_shop.has_access(meta, player_name) then -- Limit title length - fields.title = fields.title:sub(1, 80) - if title ~= fields.title then - if fields.title ~= "" then - meta:set_string("infotext", "'" .. fields.title - .. "' (" .. S("owned by @1", shop_owner) .. ")") - else - meta:set_string("infotext", S("Exchange shop (owned by @1", shop_owner) .. ")" ) - end - meta:set_string("title", minetest.formspec_escape(fields.title)) + ftitle = ftitle:sub(1, 80) + if title ~= ftitle then + local title_text = (ftitle and ftitle ~= "") and + S("Exchange Shop: \"@1\"", ftitle) or S("Exchange Shop") + meta:set_string("infotext", title_text .. "\n" .. S("Owned by @1", shop_owner)) + meta:set_string("title", minetest.formspec_escape(ftitle)) end end @@ -144,11 +151,11 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields) return end - local err_msg, resend = exchange_shop.exchange_action(player_inv, shop_inv) + local err_msg, resend = exchange_shop.exchange_action(player_inv, shop_inv, pos) -- Throw error message if err_msg then minetest.chat_send_player(player_name, minetest.colorize("#F33", - S("Exchange shop:") .. " " .. err_msg)) + S("Exchange Shop:") .. " " .. err_msg)) end if resend then minetest.show_formspec(player_name, "exchange_shop:shop_formspec", @@ -167,7 +174,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields) end) minetest.register_node(exchange_shop.shopname, { - description = S"Exchange Shop", + description = S("Exchange Shop"), tiles = { "shop_top.png", "shop_top.png", "shop_side.png","shop_side.png", @@ -180,7 +187,7 @@ minetest.register_node(exchange_shop.shopname, { local meta = minetest.get_meta(pos) local owner = placer:get_player_name() meta:set_string("owner", owner) - meta:set_string("infotext", S("Exchange shop (owned by @1", owner) .. ")") + meta:set_string("infotext", S("Exchange Shop") .. "\n" .. S("Owned by @1", owner)) end, on_construct = function(pos) local meta = minetest.get_meta(pos) @@ -206,7 +213,7 @@ minetest.register_node(exchange_shop.shopname, { S("Cannot dig exchange shop: one or multiple stocks are in use.")) return false end, - on_rightclick = function(pos, node, clicker, itemstack) + on_rightclick = function(pos, _, clicker) local meta = minetest.get_meta(pos) local player_name = clicker:get_player_name() @@ -219,14 +226,14 @@ minetest.register_node(exchange_shop.shopname, { minetest.show_formspec(player_name, "exchange_shop:shop_formspec", get_exchange_shop_formspec(mode, pos, meta)) end, - allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + allow_metadata_inventory_move = function(pos, _, _, _, _, count, player) local meta = minetest.get_meta(pos) if exchange_shop.has_access(meta, player:get_player_name()) then return count end return 0 end, - allow_metadata_inventory_put = function(pos, listname, index, stack, player) + allow_metadata_inventory_put = function(pos, listname, _, stack, player) if listname == "custm" then minetest.chat_send_player(player:get_player_name(), S("Exchange shop: Insert your trade goods into 'Outgoing'.")) @@ -240,7 +247,7 @@ minetest.register_node(exchange_shop.shopname, { end return 0 end, - allow_metadata_inventory_take = function(pos, listname, index, stack, player) + allow_metadata_inventory_take = function(pos, listname, _, stack, player) local meta = minetest.get_meta(pos) if exchange_shop.has_access(meta, player:get_player_name()) or listname == "cust_ej" then @@ -251,10 +258,11 @@ minetest.register_node(exchange_shop.shopname, { }) minetest.register_craft({ - output = "exchange_shop:shop", + output = exchange_shop.shopname, recipe = { - {"default:sign_wall"}, - {"default:chest_locked"}, + {"default:ruby", "default:ruby", "default:ruby"}, + {"default:ruby", "default:chest", "default:ruby"}, + {"default:ruby", "default:ruby", "default:ruby"} } }) diff --git a/shop_functions.lua b/shop_functions.lua index 9157e38..ab0aaaf 100644 --- a/shop_functions.lua +++ b/shop_functions.lua @@ -66,7 +66,7 @@ function exchange_shop.list_remove_item(inv, listname, stack) return removed_stack end -function exchange_shop.exchange_action(player_inv, shop_inv) +function exchange_shop.exchange_action(player_inv, shop_inv, pos) if not shop_inv:is_empty("cust_ej") or not shop_inv:is_empty("custm_ej") then return S("One or multiple ejection fields are filled.") .. " " .. @@ -153,9 +153,10 @@ function exchange_shop.exchange_action(player_inv, shop_inv) if player_inv:room_for_item("main", stack) then player_inv:add_item("main", stack) else + minetest.item_drop(stack, nil, pos) -- Move to ejection field - shop_inv:add_item("cust_ej", stack) - fully_exchanged = false + -- shop_inv:add_item("cust_ej", stack) + -- fully_exchanged = false end end if not fully_exchanged then