forked from mtcontrib/exchange_shop
Clean up formspec, remove old pipeworks code
This commit is contained in:
parent
130389705b
commit
7cb00df6dc
108
shop.lua
108
shop.lua
@ -8,63 +8,83 @@ This code is based on the idea of Dan Duncombe's exchange shop
|
|||||||
|
|
||||||
local shop_positions = {}
|
local shop_positions = {}
|
||||||
|
|
||||||
local function get_exchange_shop_formspec(mode, pos, title)
|
local function get_exchange_shop_formspec(mode, pos, meta)
|
||||||
local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z
|
local name = "nodemeta:"..pos.x..","..pos.y..","..pos.z
|
||||||
|
meta = meta or minetest.get_meta(pos)
|
||||||
|
|
||||||
local function listring(src)
|
local function listring(src)
|
||||||
return "listring[".. name ..";" .. src .. "]" ..
|
return "listring[".. name ..";" .. src .. "]" ..
|
||||||
"listring[current_player;main]"
|
"listring[current_player;main]"
|
||||||
end
|
end
|
||||||
if mode == "customer" then
|
if mode == "customer" then
|
||||||
|
local overflow = not meta:get_inventory():is_empty("cust_ej")
|
||||||
|
|
||||||
-- customer
|
-- customer
|
||||||
return (
|
local formspec = (
|
||||||
"size[8,9;]"..
|
(overflow and "size[8,9]" or "size[8,8]")..
|
||||||
"label[0,0;Exchange shop]"..
|
"label[1,0.4;You give:]"..
|
||||||
"label[1,0.5;Owner needs:]"..
|
|
||||||
"list["..name..";cust_ow;1,1;2,2;]"..
|
"list["..name..";cust_ow;1,1;2,2;]"..
|
||||||
"button[3,2.4;2,1;exchange;Exchange]"..
|
"button[3,2.4;2,1;exchange;Exchange]"..
|
||||||
"label[5,0.5;Owner gives:]"..
|
"label[5,0.4;You get:]"..
|
||||||
"list["..name..";cust_og;5,1;2,2;]"..
|
"list["..name..";cust_og;5,1;2,2;]"
|
||||||
"label[0.7,3.5;Ejected items:]"..
|
)
|
||||||
"label[0.7,3.8;(Remove me!)]"..
|
-- Insert fallback slots
|
||||||
"list["..name..";cust_ej;3,3.5;4,1;]"..
|
local inv_pos = 4
|
||||||
"list[current_player;main;0,5;8,4;]"..
|
if overflow then
|
||||||
listring("cust_ej")
|
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;]"
|
||||||
|
)
|
||||||
|
inv_pos = 5
|
||||||
|
end
|
||||||
|
return (formspec ..
|
||||||
|
"list[current_player;main;0," .. inv_pos .. ";8,4;]"..
|
||||||
|
(overflow and listring("cust_ej") or "")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
if mode == "owner_custm"
|
if mode == "owner_custm"
|
||||||
or mode == "owner_stock" then
|
or mode == "owner_stock" then
|
||||||
|
local overflow = not meta:get_inventory():is_empty("custm_ej")
|
||||||
|
local title = meta:get_string("title")
|
||||||
|
|
||||||
-- owner
|
-- owner
|
||||||
local formspec = (
|
local formspec = (
|
||||||
"size[11,10;]"..
|
"size[10,10]"..
|
||||||
"label[0.3,0.1;Title:]"..
|
"label[0,0.1;Title:]"..
|
||||||
"field[1.5,0.5;3,0.5;title;;"..title.."]"..
|
"field[1.2,0.5;3,0.5;title;;"..title.."]"..
|
||||||
"field_close_on_enter[title;false]"..
|
"field_close_on_enter[title;false]"..
|
||||||
"button[4.1,0.2;1,0.5;set_title;Set]"..
|
"button[3.9,0.2;1,0.5;set_title;Set]"..
|
||||||
"label[0,0.7;You need:]"..
|
"container[0,2]"..
|
||||||
"list["..name..";cust_ow;0,1.2;2,2;]"..
|
"label[0,-0.6;You need:]"..
|
||||||
"label[3,0.7;You give:]"..
|
"list["..name..";cust_ow;0,0;2,2;]"..
|
||||||
"list["..name..";cust_og;3,1.2;2,2;]"..
|
"label[2.5,-0.6;You give:]"..
|
||||||
"label[0,3.5;Ejected items: (Remove me!)]"..
|
"list["..name..";cust_og;2.5,0;2,2;]"..
|
||||||
"list["..name..";custm_ej;0,4;4,1;]"..
|
"container_end[]"..
|
||||||
"label[6,0;You are viewing:]"..
|
"label[5,0.1;Current stock:]"
|
||||||
"label[6,0.3;(Click to switch)]"..
|
|
||||||
listring("custm_ej")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if overflow then
|
||||||
|
formspec = (formspec..
|
||||||
|
"list["..name..";custm_ej;0.2,4;4,1;]"..
|
||||||
|
"label[0.2,4.9;Ejected items: (Remove me!)]"..
|
||||||
|
listring("custm_ej")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
if mode == "owner_custm" then
|
if mode == "owner_custm" then
|
||||||
formspec = (formspec..
|
formspec = (formspec..
|
||||||
"button[8.5,0.2;2.5,0.5;view_stock;Customers stock]"..
|
"button[7.5,0.2;2.5,0.5;view_stock;Income]"..
|
||||||
"list["..name..";custm;6,1;5,4;]"..
|
"list["..name..";custm;5,1;5,4;]"..
|
||||||
listring("custm"))
|
listring("custm"))
|
||||||
else
|
else
|
||||||
formspec = (formspec..
|
formspec = (formspec..
|
||||||
"button[8.5,0.2;2.5,0.5;view_custm;Your stock]"..
|
"button[7.5,0.2;2.5,0.5;view_custm;Outgoing]"..
|
||||||
"list["..name..";stock;6,1;5,4;]"..
|
"list["..name..";stock;5,1;5,4;]"..
|
||||||
listring("stock"))
|
listring("stock"))
|
||||||
end
|
end
|
||||||
return (formspec..
|
return (formspec..
|
||||||
"label[1,5;Use (E) + (Right click) for customer interface]"..
|
"label[1,5.4;Use (E) + (Right click) for customer interface]"..
|
||||||
"list[current_player;main;1,6;8,4;]")
|
"list[current_player;main;1,6;8,4;]")
|
||||||
end
|
end
|
||||||
return ""
|
return ""
|
||||||
@ -115,23 +135,25 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local err_msg = exchange_shop.exchange_action(player_inv, shop_inv)
|
local err_msg, resend = exchange_shop.exchange_action(player_inv, shop_inv)
|
||||||
-- Throw error message
|
-- Throw error message
|
||||||
if err_msg then
|
if err_msg then
|
||||||
minetest.chat_send_player(player_name, minetest.colorize("#F33",
|
minetest.chat_send_player(player_name, minetest.colorize("#F33",
|
||||||
"Exchange shop: " .. err_msg))
|
"Exchange shop: " .. err_msg))
|
||||||
end
|
end
|
||||||
elseif exchange_shop.has_access(meta, player_name) then
|
if resend then
|
||||||
local mode
|
minetest.show_formspec(player_name, "exchange_shop:shop_formspec",
|
||||||
|
get_exchange_shop_formspec("customer", pos, meta))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (fields.view_custm or fields.view_stock)
|
||||||
|
and exchange_shop.has_access(meta, player_name) then
|
||||||
|
local mode = "owner_stock"
|
||||||
if fields.view_custm then
|
if fields.view_custm then
|
||||||
mode = "owner_custm"
|
mode = "owner_custm"
|
||||||
elseif fields.view_stock then
|
|
||||||
mode = "owner_stock"
|
|
||||||
else
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
minetest.show_formspec(player_name, "exchange_shop:shop_formspec",
|
minetest.show_formspec(player_name, "exchange_shop:shop_formspec",
|
||||||
get_exchange_shop_formspec(mode, pos, title))
|
get_exchange_shop_formspec(mode, pos, meta))
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -202,7 +224,7 @@ minetest.register_node(exchange_shop.shopname, {
|
|||||||
end
|
end
|
||||||
shop_positions[player_name] = pos
|
shop_positions[player_name] = pos
|
||||||
minetest.show_formspec(player_name, "exchange_shop:shop_formspec",
|
minetest.show_formspec(player_name, "exchange_shop:shop_formspec",
|
||||||
get_exchange_shop_formspec(mode, pos, meta:get_string("title")))
|
get_exchange_shop_formspec(mode, pos, meta))
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -212,12 +234,9 @@ minetest.register_node(exchange_shop.shopname, {
|
|||||||
return 0
|
return 0
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
if player:get_player_name() == ":pipeworks" then
|
|
||||||
return stack:get_count()
|
|
||||||
end
|
|
||||||
if listname == "custm" then
|
if listname == "custm" then
|
||||||
minetest.chat_send_player(player:get_player_name(),
|
minetest.chat_send_player(player:get_player_name(),
|
||||||
"Exchange shop: Please press 'Customers stock' and insert your items there.")
|
"Exchange shop: Insert your trade goods into 'Outgoing'.")
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -229,9 +248,6 @@ minetest.register_node(exchange_shop.shopname, {
|
|||||||
return 0
|
return 0
|
||||||
end,
|
end,
|
||||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
if player:get_player_name() == ":pipeworks" then
|
|
||||||
return stack:get_count()
|
|
||||||
end
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if exchange_shop.has_access(meta, player:get_player_name())
|
if exchange_shop.has_access(meta, player:get_player_name())
|
||||||
or listname == "cust_ej" then
|
or listname == "cust_ej" then
|
||||||
|
@ -157,6 +157,6 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not fully_exchanged then
|
if not fully_exchanged then
|
||||||
return "Warning! Stacks are overflowing somewhere!"
|
return "Warning! Stacks are overflowing somewhere!", true
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user