2016-08-25 21:58:28 +02:00
|
|
|
--[[
|
|
|
|
steles mod for Minetest. Steles / graves with text on it.
|
|
|
|
(c) Pierre-Yves Rollo
|
|
|
|
|
|
|
|
This file is part of steles.
|
|
|
|
|
|
|
|
steles 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.
|
|
|
|
|
|
|
|
steles 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 steles. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
--]]
|
|
|
|
|
2017-08-05 10:12:43 +02:00
|
|
|
local S = steles.intllib
|
|
|
|
local F = function(...) return minetest.formspec_escape(S(...)) end
|
|
|
|
|
2018-02-01 16:54:55 +01:00
|
|
|
display_api.register_display_entity("steles:text")
|
2015-11-28 20:44:54 +01:00
|
|
|
|
2017-08-05 10:12:43 +02:00
|
|
|
for i, material in ipairs(steles.materials) do
|
2015-11-28 20:44:54 +01:00
|
|
|
|
|
|
|
local ndef = minetest.registered_nodes[material]
|
|
|
|
|
2015-12-03 15:43:39 +01:00
|
|
|
if ndef then
|
2018-02-02 22:44:58 +01:00
|
|
|
local groups = table.copy(ndef.groups)
|
2015-12-03 15:43:39 +01:00
|
|
|
local parts = material:split(":")
|
2018-02-01 16:54:55 +01:00
|
|
|
groups.display_modpack_node = 1
|
2015-12-03 15:43:39 +01:00
|
|
|
|
|
|
|
minetest.register_node("steles:"..parts[2].."_stele", {
|
2017-08-05 10:12:43 +02:00
|
|
|
description = steles.materials_desc[i],
|
2015-12-03 15:43:39 +01:00
|
|
|
sunlight_propagates = true,
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
tiles = ndef.tiles,
|
|
|
|
drawtype = "nodebox",
|
|
|
|
node_box = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = {
|
2018-07-13 20:41:53 +02:00
|
|
|
{-5/16, -5/16, -2/16, 5/16, 0.5, 2/16},
|
|
|
|
{-7/16, -0.5, -4/16, 7/16, -5/16, 4/16}
|
|
|
|
},
|
2015-11-28 20:44:54 +01:00
|
|
|
},
|
2018-01-27 17:40:42 +01:00
|
|
|
groups = groups,
|
2015-12-03 15:43:39 +01:00
|
|
|
display_entities = {
|
|
|
|
["steles:text"] = {
|
2018-02-01 16:54:55 +01:00
|
|
|
on_display_update = font_api.on_display_update,
|
2018-11-23 11:34:55 +01:00
|
|
|
depth = -2/16 - display_api.entity_spacing,
|
2018-07-13 20:41:53 +02:00
|
|
|
top = -2/16,
|
|
|
|
aspect_ratio = 0.4,
|
|
|
|
size = { x = 10/16, y = 12/16 },
|
2015-12-03 15:43:39 +01:00
|
|
|
maxlines = 3,
|
|
|
|
},
|
|
|
|
},
|
2018-01-18 22:13:15 +01:00
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
minetest.rotate_node(itemstack, placer, pointed_thing)
|
2018-10-03 09:07:42 +02:00
|
|
|
return display_api.on_place(itemstack, placer, pointed_thing)
|
2018-01-18 22:13:15 +01:00
|
|
|
end,
|
2015-12-03 15:43:39 +01:00
|
|
|
on_construct = function(pos)
|
2018-01-18 22:13:15 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2018-11-23 11:34:55 +01:00
|
|
|
meta:set_string("formspec", string.format([=[
|
|
|
|
size[6,4]%s%s%s
|
|
|
|
textarea[0.5,0.7;5.5,2;display_text;%s;${display_text}]
|
|
|
|
button[1,3;2,1;font;%s]
|
|
|
|
button_exit[3,3;2,1;ok;%s]]=],
|
|
|
|
default.gui_bg, default.gui_bg_img, default.gui_slots,
|
|
|
|
F("Displayed text (3 lines max)"),
|
|
|
|
F("Font"), F("Write")))
|
2018-02-01 16:54:55 +01:00
|
|
|
display_api.on_construct(pos)
|
2018-01-18 22:13:15 +01:00
|
|
|
end,
|
2018-02-01 16:54:55 +01:00
|
|
|
on_destruct = display_api.on_destruct,
|
|
|
|
on_rotate = display_api.on_rotate,
|
2015-12-03 15:43:39 +01:00
|
|
|
on_receive_fields = function(pos, formname, fields, player)
|
2018-01-18 22:13:15 +01:00
|
|
|
if not minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
local meta = minetest.get_meta(pos)
|
2018-11-23 11:34:55 +01:00
|
|
|
if fields.ok or fields.font then
|
2018-01-18 22:13:15 +01:00
|
|
|
meta:set_string("display_text", fields.display_text)
|
|
|
|
meta:set_string("infotext", "\""..fields.display_text.."\"")
|
2018-02-01 16:54:55 +01:00
|
|
|
display_api.update_entities(pos)
|
2018-01-18 22:13:15 +01:00
|
|
|
end
|
2018-11-23 11:34:55 +01:00
|
|
|
if fields.font then
|
|
|
|
font_api.show_font_list(player, pos)
|
|
|
|
end
|
2018-01-18 22:13:15 +01:00
|
|
|
end
|
|
|
|
end,
|
2018-02-01 16:54:55 +01:00
|
|
|
on_punch = display_api.update_entities,
|
2015-12-03 15:43:39 +01:00
|
|
|
})
|
|
|
|
end
|
2015-11-28 20:44:54 +01:00
|
|
|
end
|