2016-08-25 21:58:28 +02:00
|
|
|
--[[
|
|
|
|
signs mod for Minetest - Various signs with text displayed on
|
|
|
|
(c) Pierre-Yves Rollo
|
|
|
|
|
|
|
|
This file is part of signs.
|
|
|
|
|
|
|
|
signs is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
signs is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with signs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
--]]
|
|
|
|
|
2023-06-11 14:31:01 +02:00
|
|
|
local S = signs.S
|
2017-08-05 10:12:43 +02:00
|
|
|
|
2015-11-11 14:26:39 +01:00
|
|
|
-- Poster specific formspec
|
2017-12-22 22:39:40 +01:00
|
|
|
local function display_poster(pos, node, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2018-11-23 11:34:55 +01:00
|
|
|
|
2017-12-22 22:39:40 +01:00
|
|
|
local def = minetest.registered_nodes[node.name].display_entities["signs:display_text"]
|
2018-07-09 14:04:51 +02:00
|
|
|
local font = font_api.get_font(meta:get_string("font") or def.font_name)
|
2018-09-20 15:27:42 +02:00
|
|
|
|
2018-11-23 11:34:55 +01:00
|
|
|
local fs
|
|
|
|
local fname = string.format("%s@%s:display",
|
|
|
|
node.name, minetest.pos_to_string(pos))
|
|
|
|
|
2017-12-22 22:39:40 +01:00
|
|
|
-- Title texture
|
2018-12-05 15:41:56 +01:00
|
|
|
local titletexture = font:render(meta:get_string("display_text"),
|
|
|
|
font:get_height()*8.4, font:get_height(), { lines = 1 })
|
2017-12-22 22:39:40 +01:00
|
|
|
|
2018-11-23 11:34:55 +01:00
|
|
|
fs = string.format([=[
|
|
|
|
size[7,9]bgcolor[#0000]
|
|
|
|
background[0,0;7,9;signs_poster_formspec.png]
|
|
|
|
image[0,-0.2;8.4,2;%s]
|
2020-06-13 19:44:16 +02:00
|
|
|
style_type[textarea;textcolor=#111]
|
2018-11-23 11:34:55 +01:00
|
|
|
textarea[0.3,1.5;7,8;;%s;]]=],
|
|
|
|
titletexture,
|
|
|
|
minetest.colorize("#111",
|
|
|
|
minetest.formspec_escape(meta:get_string("text"))))
|
2017-12-22 22:39:40 +01:00
|
|
|
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
2023-06-11 14:31:01 +02:00
|
|
|
fs = string.format("%sbutton_exit[2.5,8;2,1;ok;%s]", fs, S("Close"))
|
2017-12-22 22:39:40 +01:00
|
|
|
else
|
2018-11-23 11:34:55 +01:00
|
|
|
fs = string.format(
|
|
|
|
"%sbutton[1,8;2,1;edit;%s]button_exit[4,8;2,1;ok;%s]",
|
2023-06-11 14:31:01 +02:00
|
|
|
fs, S("Edit"), S("Close"))
|
2017-12-22 22:39:40 +01:00
|
|
|
end
|
2018-11-23 11:34:55 +01:00
|
|
|
minetest.show_formspec(player:get_player_name(), fname, fs)
|
2017-12-22 22:39:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
local function edit_poster(pos, node, player)
|
2015-11-11 14:26:39 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2017-08-26 14:12:38 +02:00
|
|
|
|
2018-11-23 11:34:55 +01:00
|
|
|
local fs
|
|
|
|
local fname = string.format("%s@%s:edit",
|
|
|
|
node.name, minetest.pos_to_string(pos))
|
|
|
|
|
2015-11-11 14:26:39 +01:00
|
|
|
if not minetest.is_protected(pos, player:get_player_name()) then
|
2018-11-23 11:34:55 +01:00
|
|
|
fs = string.format([=[
|
|
|
|
size[6.5,7.5]%s%s%s
|
|
|
|
field[0.5,0.7;6,1;display_text;%s;%s]
|
|
|
|
textarea[0.5,1.7;6,6;text;%s;%s]
|
|
|
|
button[1.25,7;2,1;font;%s]
|
|
|
|
button_exit[3.25,7;2,1;write;%s]]=],
|
2023-06-11 14:31:01 +02:00
|
|
|
default.gui_bg, default.gui_bg_img, default.gui_slots, S("Title"),
|
2018-11-23 11:34:55 +01:00
|
|
|
minetest.formspec_escape(meta:get_string("display_text")),
|
2023-06-11 14:31:01 +02:00
|
|
|
S("Text"), minetest.formspec_escape(meta:get_string("text")),
|
|
|
|
S("Title font"), S("Write"))
|
2018-11-23 11:34:55 +01:00
|
|
|
minetest.show_formspec(player:get_player_name(), fname, fs)
|
2015-11-11 14:26:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Poster specific on_receive_fields callback
|
|
|
|
local function on_receive_fields_poster(pos, formname, fields, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2017-12-22 22:39:40 +01:00
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
|
|
|
|
if not minetest.is_protected(pos, player:get_player_name()) and fields then
|
2018-11-01 18:10:26 +01:00
|
|
|
if formname == node.name.."@"..minetest.pos_to_string(pos)..":display"
|
|
|
|
and fields.edit then
|
2017-12-22 22:39:40 +01:00
|
|
|
edit_poster(pos, node, player)
|
2018-11-23 11:34:55 +01:00
|
|
|
return true
|
2017-12-22 22:39:40 +01:00
|
|
|
end
|
2018-11-01 18:10:26 +01:00
|
|
|
if formname == node.name.."@"..minetest.pos_to_string(pos)..":edit"
|
2018-11-23 11:34:55 +01:00
|
|
|
then
|
|
|
|
if (fields.write or fields.font or fields.key_enter) then
|
|
|
|
meta:set_string("display_text", fields.display_text)
|
|
|
|
meta:set_string("text", fields.text)
|
|
|
|
meta:set_string("infotext", "\""..fields.display_text
|
|
|
|
.."\"\n"..S("(right-click to read more text)"))
|
|
|
|
display_api.update_entities(pos)
|
|
|
|
end
|
|
|
|
if (fields.write or fields.key_enter) then
|
|
|
|
display_poster(pos, node, player)
|
|
|
|
elseif (fields.font) then
|
|
|
|
font_api.show_font_list(player, pos, function (playername, pos)
|
|
|
|
local player = minetest.get_player_by_name(playername)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if player and node then
|
|
|
|
edit_poster(pos, node, player)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
return true
|
2015-11-11 14:26:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-28 20:44:04 +01:00
|
|
|
-- Text entity for all signs
|
2018-02-01 16:54:55 +01:00
|
|
|
display_api.register_display_entity("signs:display_text")
|
2015-11-28 20:44:04 +01:00
|
|
|
|
|
|
|
-- Sign models and registration
|
|
|
|
local models = {
|
2018-09-20 15:27:42 +02:00
|
|
|
wooden_sign = {
|
2018-11-01 18:10:26 +01:00
|
|
|
depth = 1/16, width = 14/16, height = 12/16,
|
2018-09-20 15:27:42 +02:00
|
|
|
entity_fields = {
|
|
|
|
size = { x = 12/16, y = 10/16 },
|
|
|
|
maxlines = 3,
|
|
|
|
color = "#000",
|
|
|
|
},
|
|
|
|
node_fields = {
|
|
|
|
description = S("Wooden sign"),
|
|
|
|
tiles = { "signs_wooden.png" },
|
|
|
|
inventory_image = "signs_wooden_inventory.png",
|
2018-11-01 18:10:26 +01:00
|
|
|
groups= { dig_immediate = 2 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wooden_long_sign = {
|
|
|
|
depth = 1/16, width = 1, height = 7/16,
|
|
|
|
entity_fields = {
|
|
|
|
size = { x = 1, y = 6/16 },
|
|
|
|
maxlines = 2,
|
|
|
|
color = "#000",
|
|
|
|
},
|
|
|
|
node_fields = {
|
|
|
|
description = S("Wooden long sign"),
|
|
|
|
tiles = { "signs_wooden_long.png", "signs_wooden_long.png",
|
|
|
|
"signs_wooden_long.png^[transformR90",
|
|
|
|
"signs_wooden_long.png^[transformR90",
|
|
|
|
"signs_wooden_long.png", "signs_wooden_long.png",
|
|
|
|
},
|
|
|
|
inventory_image = "signs_wooden_long_inventory.png",
|
|
|
|
groups= { dig_immediate = 2 },
|
2018-09-20 15:27:42 +02:00
|
|
|
},
|
|
|
|
},
|
2017-08-26 14:12:38 +02:00
|
|
|
wooden_right_sign = {
|
2018-11-01 18:10:26 +01:00
|
|
|
depth = 1/16, width = 14/16, height = 7/16,
|
2015-11-28 20:44:04 +01:00
|
|
|
entity_fields = {
|
2018-02-01 16:54:55 +01:00
|
|
|
right = -3/32,
|
2017-08-26 14:12:38 +02:00
|
|
|
size = { x = 12/16, y = 6/16 },
|
2015-11-28 20:44:04 +01:00
|
|
|
maxlines = 2,
|
|
|
|
color="#000",
|
|
|
|
},
|
|
|
|
node_fields = {
|
2017-08-26 14:12:38 +02:00
|
|
|
description = S("Wooden direction sign"),
|
|
|
|
tiles = { "signs_wooden_direction.png" },
|
2018-09-20 15:27:42 +02:00
|
|
|
inventory_image = "signs_wooden_direction_inventory.png",
|
2018-02-01 16:54:55 +01:00
|
|
|
signs_other_dir = 'signs:wooden_left_sign',
|
|
|
|
on_place = signs_api.on_place_direction,
|
2016-08-25 21:58:28 +02:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "signs_dir_right.obj",
|
2017-08-26 14:12:38 +02:00
|
|
|
selection_box = { type="fixed", fixed = {-0.5, -7/32, 0.5, 7/16, 7/32, 7/16}},
|
|
|
|
collision_box = { type="fixed", fixed = {-0,5, -7/32, 0.5, 7/16, 7/32, 7/16}},
|
2018-11-01 18:10:26 +01:00
|
|
|
groups= { dig_immediate = 2 },
|
2015-11-11 14:26:39 +01:00
|
|
|
},
|
|
|
|
},
|
2017-08-26 14:12:38 +02:00
|
|
|
wooden_left_sign = {
|
2018-11-01 18:10:26 +01:00
|
|
|
depth = 1/16, width = 14/16, height = 7/16,
|
2015-11-28 20:44:04 +01:00
|
|
|
entity_fields = {
|
2018-02-01 16:54:55 +01:00
|
|
|
right = 3/32,
|
2017-08-26 14:12:38 +02:00
|
|
|
size = { x = 12/16, y = 6/16 },
|
2015-11-28 20:44:04 +01:00
|
|
|
maxlines = 2,
|
2017-08-26 14:12:38 +02:00
|
|
|
color = "#000",
|
2015-11-28 20:44:04 +01:00
|
|
|
},
|
|
|
|
node_fields = {
|
2017-08-26 14:12:38 +02:00
|
|
|
description = S("Wooden direction sign"),
|
|
|
|
tiles = { "signs_wooden_direction.png" },
|
2018-09-20 15:27:42 +02:00
|
|
|
inventory_image = "signs_wooden_direction_inventory.png",
|
2018-02-01 16:54:55 +01:00
|
|
|
signs_other_dir = 'signs:wooden_right_sign',
|
2016-08-25 21:58:28 +02:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "signs_dir_left.obj",
|
2017-08-26 14:12:38 +02:00
|
|
|
selection_box = { type="fixed", fixed = {-7/16, -7/32, 0.5, 0.5, 7/32, 7/16}},
|
|
|
|
collision_box = { type="fixed", fixed = {-7/16, -7/32, 0.5, 0.5, 7/32, 7/16}},
|
2018-11-01 18:10:26 +01:00
|
|
|
groups = { not_in_creative_inventory = 1, dig_immediate = 2 },
|
2017-08-26 14:12:38 +02:00
|
|
|
drop = "signs:wooden_right_sign",
|
2015-11-11 14:26:39 +01:00
|
|
|
},
|
|
|
|
},
|
2017-08-26 14:12:38 +02:00
|
|
|
paper_poster = {
|
2018-11-01 18:10:26 +01:00
|
|
|
depth = 1/32, width = 26/32, height = 30/32,
|
2015-11-28 20:44:04 +01:00
|
|
|
entity_fields = {
|
2018-07-13 20:41:53 +02:00
|
|
|
top = -11/32,
|
|
|
|
size = { x = 26/32, y = 6/32 },
|
2015-11-28 20:44:04 +01:00
|
|
|
maxlines = 1,
|
2018-07-13 20:41:53 +02:00
|
|
|
color = "#000",
|
2015-11-28 20:44:04 +01:00
|
|
|
},
|
|
|
|
node_fields = {
|
2017-08-26 14:12:38 +02:00
|
|
|
description = S("Poster"),
|
|
|
|
tiles = { "signs_poster_sides.png", "signs_poster_sides.png",
|
2018-02-01 16:54:55 +01:00
|
|
|
"signs_poster_sides.png", "signs_poster_sides.png",
|
|
|
|
"signs_poster_sides.png", "signs_poster.png" },
|
2017-08-26 14:12:38 +02:00
|
|
|
inventory_image = "signs_poster_inventory.png",
|
2018-11-01 18:10:26 +01:00
|
|
|
groups= { dig_immediate = 3 },
|
2018-02-01 16:54:55 +01:00
|
|
|
on_construct = display_api.on_construct,
|
2017-12-22 22:39:40 +01:00
|
|
|
on_rightclick = display_poster,
|
2017-08-26 14:12:38 +02:00
|
|
|
on_receive_fields = on_receive_fields_poster,
|
2020-02-10 19:38:48 +01:00
|
|
|
on_punch = function(pos, node, player, pointed_thing)
|
|
|
|
display_api.update_entities(pos)
|
|
|
|
end,
|
2015-11-11 14:26:39 +01:00
|
|
|
},
|
|
|
|
},
|
2018-11-01 18:10:26 +01:00
|
|
|
label_small = {
|
|
|
|
depth = 1/32, width = 4/16, height = 4/16,
|
|
|
|
entity_fields = {
|
|
|
|
size = { x = 4/16, y = 4/16 },
|
|
|
|
maxlines = 1,
|
|
|
|
color = "#000",
|
|
|
|
},
|
|
|
|
node_fields = {
|
|
|
|
description = S("Small label"),
|
|
|
|
tiles = { "signs_label.png" },
|
|
|
|
inventory_image = "signs_label_small_inventory.png",
|
|
|
|
groups= { dig_immediate = 3 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
label_medium = {
|
|
|
|
depth = 1/32, width = 8/16, height = 8/16,
|
|
|
|
entity_fields = {
|
|
|
|
size = { x = 8/16, y = 8/16 },
|
|
|
|
maxlines = 2,
|
|
|
|
color = "#000",
|
|
|
|
},
|
|
|
|
node_fields = {
|
|
|
|
description = S("Label"),
|
|
|
|
tiles = { "signs_label.png" },
|
|
|
|
inventory_image = "signs_label_medium_inventory.png",
|
|
|
|
groups= { dig_immediate = 3 },
|
|
|
|
},
|
|
|
|
},
|
2015-11-11 14:26:39 +01:00
|
|
|
}
|
|
|
|
|
2017-08-26 14:12:38 +02:00
|
|
|
-- Node registration
|
2015-11-28 20:44:04 +01:00
|
|
|
for name, model in pairs(models)
|
2015-11-11 14:26:39 +01:00
|
|
|
do
|
2018-02-01 16:54:55 +01:00
|
|
|
signs_api.register_sign("signs", name, model)
|
2015-11-28 20:44:04 +01:00
|
|
|
end
|