From f3970f641eb60bf92492b6715084273cc1bceb74 Mon Sep 17 00:00:00 2001 From: Thomas--S Date: Thu, 1 Feb 2018 16:54:55 +0100 Subject: Seperate signs API from signs definitions Change modnames from *_lib to *_api --- signs_api/LICENSE.txt | 166 +++++++++++++++++++++++++++++++++++++ signs_api/README.md | 29 +++++++ signs_api/common.lua | 188 ++++++++++++++++++++++++++++++++++++++++++ signs_api/copyright.txt | 10 +++ signs_api/depends.txt | 4 + signs_api/init.lua | 33 ++++++++ signs_api/intllib.lua | 45 ++++++++++ signs_api/locale/fr.po | 49 +++++++++++ signs_api/locale/ms.po | 46 +++++++++++ signs_api/locale/template.pot | 31 +++++++ signs_api/tools/updatepo.sh | 25 ++++++ 11 files changed, 626 insertions(+) create mode 100644 signs_api/LICENSE.txt create mode 100644 signs_api/README.md create mode 100644 signs_api/common.lua create mode 100644 signs_api/copyright.txt create mode 100644 signs_api/depends.txt create mode 100644 signs_api/init.lua create mode 100644 signs_api/intllib.lua create mode 100644 signs_api/locale/fr.po create mode 100644 signs_api/locale/ms.po create mode 100644 signs_api/locale/template.pot create mode 100755 signs_api/tools/updatepo.sh (limited to 'signs_api') diff --git a/signs_api/LICENSE.txt b/signs_api/LICENSE.txt new file mode 100644 index 0000000..341c30b --- /dev/null +++ b/signs_api/LICENSE.txt @@ -0,0 +1,166 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. + diff --git a/signs_api/README.md b/signs_api/README.md new file mode 100644 index 0000000..99ff20a --- /dev/null +++ b/signs_api/README.md @@ -0,0 +1,29 @@ +# Signs API + +This mod provides various helper functions for registereing signs with text display. Text is locked if area is protected. +No actual signs get registered by this mod, the signs are defined in the sign submod. + +For more information, see the [forum topic](https://forum.minetest.net/viewtopic.php?t=19365) at the Minetest forums. + +**Dependancies**: default, display\_lib, font\_lib + +**License**: Code under LGPL, Textures and models under CC-BY-SA + +## API Functions +### `signs_api.set_display_text(pos, text)` +Sets the text of a sign. Usually called in `on_receive_fields`. + +### `signs_api.set_formspec(pos)` +Usually called in `on_construct` to set the formspec. + +### `signs_api.on_receive_fields(pos, formname, fields, player)` +Helper function for `on_receive_fields`. Sets the display text and checks for protection. + +### `signs_api.on_place_direction(itemstack, placer, pointed_thing)` +On place callback for direction signs (chooses which sign according to look direction). + +### `signs_api.on_rotate(pos, node, player, mode, new_param2)` +Handles screwdriver rotation. Direction is affected for direction signs. + +### `signs_api.register_sign(mod, name, model)` +A method to quickly register signs. diff --git a/signs_api/common.lua b/signs_api/common.lua new file mode 100644 index 0000000..2528ff5 --- /dev/null +++ b/signs_api/common.lua @@ -0,0 +1,188 @@ +--[[ + 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 . +--]] + +local S = signs_api.intllib +local F = function(...) return minetest.formspec_escape(S(...)) end + +function signs_api.set_display_text(pos,text) + local meta = minetest.get_meta(pos) + meta:set_string("display_text", text) + meta:set_string("infotext", "\""..text.."\"") + display_api.update_entities(pos) +end + +function signs_api.set_formspec(pos) + local meta = minetest.get_meta(pos) + local ndef = minetest.registered_nodes[minetest.get_node(pos).name] + if ndef and ndef.display_entities and ndef.display_entities["signs:display_text"] then + local maxlines = ndef.display_entities["signs:display_text"].maxlines + local formspec + + if maxlines == 1 then + formspec = "size[6,3]".. + default.gui_bg .. default.gui_bg_img .. default.gui_slots .. + "field[0.5,0.7;5.5,1;display_text;"..F("Text")..";${display_text}]".. + "button_exit[2,2;2,1;ok;"..F("Write").."]" + else + local extralabel = "" + if maxlines then + extralabel = F(" (first %s lines only)"):format(maxlines) + end + + formspec = "size[6,4]".. + default.gui_bg .. default.gui_bg_img .. default.gui_slots .. + "textarea[0.5,0.7;5.5,2;display_text;"..F("Text")..""..extralabel..";${display_text}]".. + "button_exit[2,3;2,1;ok;"..F("Write").."]" + end + + meta:set_string("formspec", formspec) + end +end + +function signs_api.on_receive_fields(pos, formname, fields, player) + if not minetest.is_protected(pos, player:get_player_name()) then + if fields and (fields.ok or fields.key_enter) then + signs_api.set_display_text(pos, fields.display_text) + end + end +end + +-- On place callback for direction signs +-- (chooses which sign according to look direction) +function signs_api.on_place_direction(itemstack, placer, pointed_thing) + local name = itemstack:get_name() + local ndef = minetest.registered_nodes[name] + + local bdir = {x = pointed_thing.under.x - pointed_thing.above.x, + y = pointed_thing.under.y - pointed_thing.above.y, + z = pointed_thing.under.z - pointed_thing.above.z} + local pdir = placer:get_look_dir() + + local ndir, test + + if ndef.paramtype2 == "facedir" then + if bdir.x == 0 and bdir.z == 0 then + -- Ceiling or floor pointed (facedir chosen from player dir) + ndir = minetest.dir_to_facedir({x=pdir.x, y=0, z=pdir.z}) + else + -- Wall pointed + ndir = minetest.dir_to_facedir(bdir) + end + + test = {[0]=-pdir.x, pdir.z, pdir.x, -pdir.z} + end + + if ndef.paramtype2 == "wallmounted" then + ndir = minetest.dir_to_wallmounted(bdir) + if ndir == 0 or ndir == 1 then + -- Ceiling or floor + ndir = minetest.dir_to_wallmounted({x=pdir.x, y=0, z=pdir.z}) + end + + test = {0, pdir.z, -pdir.z, -pdir.x, pdir.x} + end + + -- Only for direction signs + if ndef.signs_other_dir then + if test[ndir] > 0 then + itemstack:set_name(ndef.signs_other_dir) + end + itemstack = minetest.item_place(itemstack, placer, pointed_thing, ndir) + itemstack:set_name(name) + + return itemstack + else + return minetest.item_place(itemstack, placer, pointed_thing, ndir) + end +end + +-- Handles screwdriver rotation. Direction is affected for direction signs +function signs_api.on_rotate(pos, node, player, mode, new_param2) + if mode == 2 then + local ndef = minetest.registered_nodes[node.name] + if ndef.signs_other_dir then + minetest.swap_node(pos, {name = ndef.signs_other_dir, + param1 = node.param1, param2 = node.param2}) + display_api.update_entities(pos) + end + else + display_api.on_rotate(pos, node, user, mode, new_param2) + end + return false; +end + +function signs_api.register_sign(mod, name, model) + -- Default fields + local fields = { + sunlight_propagates = true, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = {-model.width/2, -model.height/2, 0.5, + model.width/2, model.height/2, 0.5 - model.depth}, + }, + groups = {choppy=2, dig_immediate=2, not_blocking_trains = 1, display_modpack_node = 1}, + sounds = default.node_sound_defaults(), + display_entities = { + ["signs:display_text"] = { + on_display_update = font_api.on_display_update, + depth = 0.5 - display_api.entity_spacing - model.depth, + size = { x = model.width, y = model.height }, + resolution = { x = 64, y = 64 }, + maxlines = 1, + }, + + }, + on_place = display_api.on_place, + on_construct = function(pos) + signs_api.set_formspec(pos) + display_api.on_construct(pos) + end, + on_destruct = display_api.on_destruct, + on_rotate = signs_api.on_rotate, + on_receive_fields = signs_api.on_receive_fields, + on_punch = function(pos, node, player, pointed_thing) display_api.update_entities(pos) end, + } + + -- Node fields override + for key, value in pairs(model.node_fields) do + if key == "groups" then + for key2, value2 in pairs(value) do + fields[key][key2] = value2 + end + else + fields[key] = value + end + end + + if not fields.wield_image then fields.wield_image = fields.inventory_image end + + -- Entity fields override + for key, value in pairs(model.entity_fields) do + fields.display_entities["signs:display_text"][key] = value + end + + minetest.register_node(mod..":"..name, fields) +end + +-- Text entity for all signs +display_api.register_display_entity("signs:display_text") diff --git a/signs_api/copyright.txt b/signs_api/copyright.txt new file mode 100644 index 0000000..b70e051 --- /dev/null +++ b/signs_api/copyright.txt @@ -0,0 +1,10 @@ +Code by Pierre-Yves Rollo (pyrollo) +intllib support (i18n) by (fat115) +intllib fallback code and tools by Diego Martínez (kaeza) +Extra contributors: +(gpcf) +(Thomas--S) +Translations: +Muhammad Nur Hidayat Yasuyoshi (MuhdNurHidayat) +(fat115) + diff --git a/signs_api/depends.txt b/signs_api/depends.txt new file mode 100644 index 0000000..f75ffcc --- /dev/null +++ b/signs_api/depends.txt @@ -0,0 +1,4 @@ +default +intllib? +display_api +font_api diff --git a/signs_api/init.lua b/signs_api/init.lua new file mode 100644 index 0000000..c13a253 --- /dev/null +++ b/signs_api/init.lua @@ -0,0 +1,33 @@ +--[[ + 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 . +--]] + +signs_api = {} +signs_api.name = minetest.get_current_modname() +signs_api.path = minetest.get_modpath(signs_api.name) + +-- Load support for intllib. +local S, NS = dofile(signs_api.path.."/intllib.lua") +signs_api.intllib = S + +dofile(signs_api.path.."/common.lua") + + + + diff --git a/signs_api/intllib.lua b/signs_api/intllib.lua new file mode 100644 index 0000000..6669d72 --- /dev/null +++ b/signs_api/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- Get the latest version of this file at: +-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua + +local function format(str, ...) + local args = { ... } + local function repl(escape, open, num, close) + if escape == "" then + local replacement = tostring(args[tonumber(num)]) + if open == "" then + replacement = replacement..close + end + return replacement + else + return "@"..open..num..close + end + end + return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl)) +end + +local gettext, ngettext +if minetest.get_modpath("intllib") then + if intllib.make_gettext_pair then + -- New method using gettext. + gettext, ngettext = intllib.make_gettext_pair() + else + -- Old method using text files. + gettext = intllib.Getter() + end +end + +-- Fill in missing functions. + +gettext = gettext or function(msgid, ...) + return format(msgid, ...) +end + +ngettext = ngettext or function(msgid, msgid_plural, n, ...) + return format(n==1 and msgid or msgid_plural, ...) +end + +return gettext, ngettext diff --git a/signs_api/locale/fr.po b/signs_api/locale/fr.po new file mode 100644 index 0000000..e490d1b --- /dev/null +++ b/signs_api/locale/fr.po @@ -0,0 +1,49 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-01 05:56+0100\n" +"PO-Revision-Date: 2017-05-08 07:08+0200\n" +"Last-Translator: Peppy \n" +"Language-Team: \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.8.12\n" + +#: common.lua +msgid "Text" +msgstr "Texte" + +#: common.lua +msgid "Write" +msgstr "Écrire" + +#: common.lua +#, lua-format +msgid " (first %s lines only)" +msgstr " (uniquement les %s premières lignes)" + +#~ msgid "Title" +#~ msgstr "Titre" + +#~ msgid "Close" +#~ msgstr "Fermer" + +#~ msgid "(right-click to read more text)" +#~ msgstr "(Clic-droit pour afficher le texte entier)" + +#~ msgid "Wooden direction sign" +#~ msgstr "Panneau de direction en bois" + +#~ msgid "Poster" +#~ msgstr "Affiche" + +#~ msgid "Textd" +#~ msgstr "Texte" diff --git a/signs_api/locale/ms.po b/signs_api/locale/ms.po new file mode 100644 index 0000000..9c8aab8 --- /dev/null +++ b/signs_api/locale/ms.po @@ -0,0 +1,46 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# Muhammad Nur Hidayat , 2017. +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-01 05:56+0100\n" +"PO-Revision-Date: 2017-08-27 15:50+0800\n" +"Last-Translator: Muhammad Nur Hidayat \n" +"Language-Team: Malay \n" +"Language: ms\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: Vé 0.1.4\n" + +#: common.lua +msgid "Text" +msgstr "Teks" + +#: common.lua +msgid "Write" +msgstr "Tulis" + +#: common.lua +#, lua-format +msgid " (first %s lines only)" +msgstr "( %s baris pertama sahaja )" + +#~ msgid "Title" +#~ msgstr "Tajuk" + +#~ msgid "Close" +#~ msgstr "Tutup" + +#~ msgid "(right-click to read more text)" +#~ msgstr "(klik-kanan untuk baca teks penuh)" + +#~ msgid "Wooden direction sign" +#~ msgstr "Papan tanda arah kayu" + +#~ msgid "Poster" +#~ msgstr "Poster" diff --git a/signs_api/locale/template.pot b/signs_api/locale/template.pot new file mode 100644 index 0000000..6004024 --- /dev/null +++ b/signs_api/locale/template.pot @@ -0,0 +1,31 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-02-01 05:56+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: common.lua +msgid "Text" +msgstr "" + +#: common.lua +msgid "Write" +msgstr "" + +#: common.lua +#, lua-format +msgid " (first %s lines only)" +msgstr "" diff --git a/signs_api/tools/updatepo.sh b/signs_api/tools/updatepo.sh new file mode 100755 index 0000000..feb2504 --- /dev/null +++ b/signs_api/tools/updatepo.sh @@ -0,0 +1,25 @@ +#! /bin/bash + +# To create a new translation: +# msginit --locale=ll_CC -o locale/ll_CC.po -i locale/template.pot + +cd "$(dirname "${BASH_SOURCE[0]}")/.."; + +# Extract translatable strings. +xgettext --from-code=UTF-8 \ + --language=Lua \ + --sort-by-file \ + --keyword=S \ + --keyword=NS:1,2 \ + --keyword=N_ \ + --keyword=F \ + --add-comments='Translators:' \ + --add-location=file \ + -o locale/template.pot \ + $(find . -name '*.lua') + +# Update translations. +find locale -name '*.po' | while read -r file; do + echo $file + msgmerge --update $file locale/template.pot; +done -- cgit v1.2.3 From 8c7557e45d4744fe35ad058950062cf771640126 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Fri, 13 Jul 2018 20:41:53 +0200 Subject: Rework all nodes displaying text according to new font_api --- display_api/init.lua | 6 +- font_api/font.lua | 16 ++--- font_api/init.lua | 12 ++-- signs/nodes.lua | 12 ++-- signs_api/common.lua | 188 ------------------------------------------------- signs_api/init.lua | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++- signs_road/nodes.lua | 26 +++---- steles/nodes.lua | 13 ++-- 8 files changed, 233 insertions(+), 234 deletions(-) delete mode 100644 signs_api/common.lua (limited to 'signs_api') diff --git a/display_api/init.lua b/display_api/init.lua index 240ce21..2cd15a0 100644 --- a/display_api/init.lua +++ b/display_api/init.lua @@ -128,15 +128,15 @@ local function place_entities(pos) for entity_name, props in pairs(ndef.display_entities) do local depth = clip_pos_prop(props.depth) - local height = clip_pos_prop(props.height) local right = clip_pos_prop(props.right) + local top = clip_pos_prop(props.top) if not objrefs[entity_name] then objrefs[entity_name] = minetest.add_entity(pos, entity_name) end objrefs[entity_name]:setpos({ x = pos.x - values.dx * depth + values.rx * right, - y = pos.y + height, + y = pos.y - top, z = pos.z - values.dz * depth + values.rz * right}) objrefs[entity_name]:setyaw(values.yaw) @@ -268,4 +268,4 @@ minetest.register_lbm({ }) -- Compatibility -display_lib = display_api \ No newline at end of file +display_lib = display_api diff --git a/font_api/font.lua b/font_api/font.lua index 6c848f6..4619e7a 100644 --- a/font_api/font.lua +++ b/font_api/font.lua @@ -17,11 +17,6 @@ along with this program. If not, see . --]] - ---[[ - Margins, spacings, can be negative numbers -]]-- - -- Local functions ------------------ @@ -146,10 +141,10 @@ function font_api.Font:get_height(nb_of_lines) return ( (self.height or 0) + - (self.margin_top or 0) + - (self.margin_bottom or 0) + (self.margintop or 0) + + (self.marginbottom or 0) ) * nb_of_lines + - (self.line_spacing or 0) * (nb_of_lines -1) + (self.linespacing or 0) * (nb_of_lines -1) else return nb_of_lines == 0 and 0 or nil end @@ -192,6 +187,7 @@ function font_api.Font:make_line_texture(line, texturew, x, y) -- Replace chars with no texture by the NULL(0) char if self.widths[char] == nil +or char == 88 then print(string.format("["..font_api.name .."] Missing char %d (%04x)",char,char)) @@ -243,6 +239,8 @@ function font_api.Font:make_text_texture(text, texturew, textureh, maxlines, y = (textureh - textheight) / 2 end end + + y = y + (self.margintop or 0) for _, line in pairs(lines) do if halign == "left" then @@ -259,7 +257,7 @@ function font_api.Font:make_text_texture(text, texturew, textureh, maxlines, (texturew - line.width) / 2, y) end - y = y + self:get_height() + (self.line_spacing or 0) + y = y + self:get_height() + (self.linespacing or 0) end texture = string.format("[combine:%dx%d", texturew, textureh)..texture diff --git a/font_api/init.lua b/font_api/init.lua index 2dc38ec..06619be 100644 --- a/font_api/init.lua +++ b/font_api/init.lua @@ -45,10 +45,14 @@ function font_api.on_display_update(pos, objref) if entity and ndef.display_entities[entity.name] then local def = ndef.display_entities[entity.name] local font = font_api.get_font(meta:get_string("font") or def.font_name) - objref:set_properties({ - textures={font:make_text_texture(text, - def.size.x * def.resolution.x * font.height, - def.size.y * def.resolution.y * font.height, + + local maxlines = def.maxlines or 1 -- TODO:How to do w/o maxlines ? + + objref:set_properties({ + textures={font:make_text_texture(text, + font:get_height(maxlines) * def.size.x / def.size.y + / (def.aspect_ratio or 1), + font:get_height(maxlines), def.maxlines, def.halign, def.valign, def.color)}, visual_size = def.size }) diff --git a/signs/nodes.lua b/signs/nodes.lua index d635f8f..7e2dbe8 100644 --- a/signs/nodes.lua +++ b/signs/nodes.lua @@ -30,12 +30,12 @@ local function display_poster(pos, node, player) -- Title texture local titletexture = font:make_text_texture( - meta:get_string("display_text"), 116, 12, 1, "center") + meta:get_string("display_text"), font:get_height()*8.4, font:get_height(), 1, "center") formspec = "size[7,9]".. "background[0,0;7,9;signs_poster_formspec.png]".. - "image[0,0;8.4,1.5;"..titletexture.."]".. + "image[0,-0.2;8.4,2;"..titletexture.."]".. "textarea[0.3,1.5;7,8;;"..minetest.colorize("#111", minetest.formspec_escape(meta:get_string("text")))..";]".. "bgcolor[#0000]" @@ -105,7 +105,6 @@ local models = { entity_fields = { right = -3/32, size = { x = 12/16, y = 6/16 }, - resolution = { x = 9, y = 5 }, maxlines = 2, color="#000", }, @@ -128,7 +127,6 @@ local models = { entity_fields = { right = 3/32, size = { x = 12/16, y = 6/16 }, - resolution = { x = 9, y = 5 }, maxlines = 2, color = "#000", }, @@ -150,10 +148,10 @@ local models = { width = 26/32, height = 30/32, entity_fields = { - resolution = { x = 11, y = 5 }, + top = -11/32, + size = { x = 26/32, y = 6/32 }, maxlines = 1, - color="#000", - valign="top", + color = "#000", }, node_fields = { description = S("Poster"), diff --git a/signs_api/common.lua b/signs_api/common.lua deleted file mode 100644 index 2528ff5..0000000 --- a/signs_api/common.lua +++ /dev/null @@ -1,188 +0,0 @@ ---[[ - 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 . ---]] - -local S = signs_api.intllib -local F = function(...) return minetest.formspec_escape(S(...)) end - -function signs_api.set_display_text(pos,text) - local meta = minetest.get_meta(pos) - meta:set_string("display_text", text) - meta:set_string("infotext", "\""..text.."\"") - display_api.update_entities(pos) -end - -function signs_api.set_formspec(pos) - local meta = minetest.get_meta(pos) - local ndef = minetest.registered_nodes[minetest.get_node(pos).name] - if ndef and ndef.display_entities and ndef.display_entities["signs:display_text"] then - local maxlines = ndef.display_entities["signs:display_text"].maxlines - local formspec - - if maxlines == 1 then - formspec = "size[6,3]".. - default.gui_bg .. default.gui_bg_img .. default.gui_slots .. - "field[0.5,0.7;5.5,1;display_text;"..F("Text")..";${display_text}]".. - "button_exit[2,2;2,1;ok;"..F("Write").."]" - else - local extralabel = "" - if maxlines then - extralabel = F(" (first %s lines only)"):format(maxlines) - end - - formspec = "size[6,4]".. - default.gui_bg .. default.gui_bg_img .. default.gui_slots .. - "textarea[0.5,0.7;5.5,2;display_text;"..F("Text")..""..extralabel..";${display_text}]".. - "button_exit[2,3;2,1;ok;"..F("Write").."]" - end - - meta:set_string("formspec", formspec) - end -end - -function signs_api.on_receive_fields(pos, formname, fields, player) - if not minetest.is_protected(pos, player:get_player_name()) then - if fields and (fields.ok or fields.key_enter) then - signs_api.set_display_text(pos, fields.display_text) - end - end -end - --- On place callback for direction signs --- (chooses which sign according to look direction) -function signs_api.on_place_direction(itemstack, placer, pointed_thing) - local name = itemstack:get_name() - local ndef = minetest.registered_nodes[name] - - local bdir = {x = pointed_thing.under.x - pointed_thing.above.x, - y = pointed_thing.under.y - pointed_thing.above.y, - z = pointed_thing.under.z - pointed_thing.above.z} - local pdir = placer:get_look_dir() - - local ndir, test - - if ndef.paramtype2 == "facedir" then - if bdir.x == 0 and bdir.z == 0 then - -- Ceiling or floor pointed (facedir chosen from player dir) - ndir = minetest.dir_to_facedir({x=pdir.x, y=0, z=pdir.z}) - else - -- Wall pointed - ndir = minetest.dir_to_facedir(bdir) - end - - test = {[0]=-pdir.x, pdir.z, pdir.x, -pdir.z} - end - - if ndef.paramtype2 == "wallmounted" then - ndir = minetest.dir_to_wallmounted(bdir) - if ndir == 0 or ndir == 1 then - -- Ceiling or floor - ndir = minetest.dir_to_wallmounted({x=pdir.x, y=0, z=pdir.z}) - end - - test = {0, pdir.z, -pdir.z, -pdir.x, pdir.x} - end - - -- Only for direction signs - if ndef.signs_other_dir then - if test[ndir] > 0 then - itemstack:set_name(ndef.signs_other_dir) - end - itemstack = minetest.item_place(itemstack, placer, pointed_thing, ndir) - itemstack:set_name(name) - - return itemstack - else - return minetest.item_place(itemstack, placer, pointed_thing, ndir) - end -end - --- Handles screwdriver rotation. Direction is affected for direction signs -function signs_api.on_rotate(pos, node, player, mode, new_param2) - if mode == 2 then - local ndef = minetest.registered_nodes[node.name] - if ndef.signs_other_dir then - minetest.swap_node(pos, {name = ndef.signs_other_dir, - param1 = node.param1, param2 = node.param2}) - display_api.update_entities(pos) - end - else - display_api.on_rotate(pos, node, user, mode, new_param2) - end - return false; -end - -function signs_api.register_sign(mod, name, model) - -- Default fields - local fields = { - sunlight_propagates = true, - paramtype = "light", - paramtype2 = "facedir", - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = {-model.width/2, -model.height/2, 0.5, - model.width/2, model.height/2, 0.5 - model.depth}, - }, - groups = {choppy=2, dig_immediate=2, not_blocking_trains = 1, display_modpack_node = 1}, - sounds = default.node_sound_defaults(), - display_entities = { - ["signs:display_text"] = { - on_display_update = font_api.on_display_update, - depth = 0.5 - display_api.entity_spacing - model.depth, - size = { x = model.width, y = model.height }, - resolution = { x = 64, y = 64 }, - maxlines = 1, - }, - - }, - on_place = display_api.on_place, - on_construct = function(pos) - signs_api.set_formspec(pos) - display_api.on_construct(pos) - end, - on_destruct = display_api.on_destruct, - on_rotate = signs_api.on_rotate, - on_receive_fields = signs_api.on_receive_fields, - on_punch = function(pos, node, player, pointed_thing) display_api.update_entities(pos) end, - } - - -- Node fields override - for key, value in pairs(model.node_fields) do - if key == "groups" then - for key2, value2 in pairs(value) do - fields[key][key2] = value2 - end - else - fields[key] = value - end - end - - if not fields.wield_image then fields.wield_image = fields.inventory_image end - - -- Entity fields override - for key, value in pairs(model.entity_fields) do - fields.display_entities["signs:display_text"][key] = value - end - - minetest.register_node(mod..":"..name, fields) -end - --- Text entity for all signs -display_api.register_display_entity("signs:display_text") diff --git a/signs_api/init.lua b/signs_api/init.lua index c13a253..e8a2b2b 100644 --- a/signs_api/init.lua +++ b/signs_api/init.lua @@ -25,8 +25,200 @@ signs_api.path = minetest.get_modpath(signs_api.name) -- Load support for intllib. local S, NS = dofile(signs_api.path.."/intllib.lua") signs_api.intllib = S +local F = function(...) return minetest.formspec_escape(S(...)) end -dofile(signs_api.path.."/common.lua") +local function update_font_index_meta(meta) + local font = meta:get_string("font") + local count = 0 + for key, def in pairs(font_api.registered_fonts) do + count = count + 1 + if font == key then + meta:set_string("font_idx", count) + end + end +end + +function signs_api.set_display_text(pos,text,font) + local meta = minetest.get_meta(pos) + meta:set_string("display_text", text) + meta:set_string("infotext", "\""..text.."\"") + meta:set_string("font", font) + update_font_index_meta(meta) + display_api.update_entities(pos) +end + +function signs_api.set_formspec(pos) + local meta = minetest.get_meta(pos) + local ndef = minetest.registered_nodes[minetest.get_node(pos).name] + if ndef and ndef.display_entities + and ndef.display_entities["signs:display_text"] then + local maxlines = ndef.display_entities["signs:display_text"].maxlines + local formspec, formheight + + if maxlines == 1 then + formspec = + "field[0.5,0.7;5.5,1;display_text;"..F("Text").. + ";${display_text}]" + formheight = 2 + else + local extralabel = "" + if maxlines then + extralabel = F(" (first %s lines only)"):format(maxlines) + end + + formspec = + "textarea[0.5,0.7;5.5,2;display_text;"..F("Text").."".. + extralabel..";${display_text}]" + formheight = 3 + end + + formspec = formspec.."button_exit[2,"..formheight..";2,1;ok;".. + F("Write").."]" + formheight = formheight + 1 + formspec = "size[6,"..formheight.."]"..default.gui_bg.. + default.gui_bg_img..default.gui_slots..formspec + + meta:set_string("formspec", formspec) + end +end + +function signs_api.on_receive_fields(pos, formname, fields, player) + if not minetest.is_protected(pos, player:get_player_name()) then + if fields and (fields.ok or fields.key_enter) then + signs_api.set_display_text(pos, fields.display_text, fields.font) + end + end +end + +-- On place callback for direction signs +-- (chooses which sign according to look direction) +function signs_api.on_place_direction(itemstack, placer, pointed_thing) + local name = itemstack:get_name() + local ndef = minetest.registered_nodes[name] + + local bdir = {x = pointed_thing.under.x - pointed_thing.above.x, + y = pointed_thing.under.y - pointed_thing.above.y, + z = pointed_thing.under.z - pointed_thing.above.z} + local pdir = placer:get_look_dir() + + local ndir, test + + if ndef.paramtype2 == "facedir" then + if bdir.x == 0 and bdir.z == 0 then + -- Ceiling or floor pointed (facedir chosen from player dir) + ndir = minetest.dir_to_facedir({x=pdir.x, y=0, z=pdir.z}) + else + -- Wall pointed + ndir = minetest.dir_to_facedir(bdir) + end + + test = {[0]=-pdir.x, pdir.z, pdir.x, -pdir.z} + end + + if ndef.paramtype2 == "wallmounted" then + ndir = minetest.dir_to_wallmounted(bdir) + if ndir == 0 or ndir == 1 then + -- Ceiling or floor + ndir = minetest.dir_to_wallmounted({x=pdir.x, y=0, z=pdir.z}) + end + + test = {0, pdir.z, -pdir.z, -pdir.x, pdir.x} + end + + -- Only for direction signs + if ndef.signs_other_dir then + if test[ndir] > 0 then + itemstack:set_name(ndef.signs_other_dir) + end + itemstack = minetest.item_place(itemstack, placer, pointed_thing, ndir) + itemstack:set_name(name) + + return itemstack + else + return minetest.item_place(itemstack, placer, pointed_thing, ndir) + end +end + +-- Handles screwdriver rotation. Direction is affected for direction signs +function signs_api.on_rotate(pos, node, player, mode, new_param2) + if mode == 2 then + local ndef = minetest.registered_nodes[node.name] + if ndef.signs_other_dir then + minetest.swap_node(pos, {name = ndef.signs_other_dir, + param1 = node.param1, param2 = node.param2}) + display_api.update_entities(pos) + end + else + display_api.on_rotate(pos, node, user, mode, new_param2) + end + return false; +end + +function signs_api.register_sign(mod, name, model) + -- Default fields + local fields = { + sunlight_propagates = true, + paramtype = "light", + paramtype2 = "facedir", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = {-model.width/2, -model.height/2, 0.5, + model.width/2, model.height/2, 0.5 - model.depth}, + }, + groups = {choppy=2, dig_immediate=2, not_blocking_trains = 1, display_modpack_node = 1}, + sounds = default.node_sound_defaults(), + display_entities = { + ["signs:display_text"] = { + on_display_update = font_api.on_display_update, + depth = 0.5 - display_api.entity_spacing - model.depth, + size = { x = model.width, y = model.height }, + aspect_ratio = 1/2, + maxlines = 1, + }, + + }, + on_place = display_api.on_place, + on_construct = function(pos) + local ndef = minetest.registered_nodes[minetest.get_node(pos).name] + local meta = minetest.get_meta(pos) + meta:set_string("font", ndef.display_entities.font_name or + font_api.get_default_font_name()) + update_font_index_meta(meta) + signs_api.set_formspec(pos) + display_api.on_construct(pos) + end, + on_destruct = display_api.on_destruct, + on_rotate = signs_api.on_rotate, + on_receive_fields = signs_api.on_receive_fields, + on_punch = function(pos, node, player, pointed_thing) + display_api.update_entities(pos) + end, + } + + -- Node fields override + for key, value in pairs(model.node_fields) do + if key == "groups" then + for key2, value2 in pairs(value) do + fields[key][key2] = value2 + end + else + fields[key] = value + end + end + + if not fields.wield_image then fields.wield_image = fields.inventory_image end + + -- Entity fields override + for key, value in pairs(model.entity_fields) do + fields.display_entities["signs:display_text"][key] = value + end + + minetest.register_node(mod..":"..name, fields) +end + +-- Text entity for all signs +display_api.register_display_entity("signs:display_text") diff --git a/signs_road/nodes.lua b/signs_road/nodes.lua index c4c0b04..ab95b2b 100644 --- a/signs_road/nodes.lua +++ b/signs_road/nodes.lua @@ -27,7 +27,7 @@ local models = { width = 14/16, height = 12/16, entity_fields = { - resolution = { x = 11, y = 5.5 }, + size = { x = 14/16, y = 10/16 }, maxlines = 3, color = "#fff", }, @@ -44,7 +44,6 @@ local models = { width = 64/16, height = 12/16, entity_fields = { - resolution = { x = 2.5, y = 1.5 }, maxlines = 1, color = "#000", }, @@ -57,13 +56,12 @@ local models = { inventory_image = "signs_road_white.png", }, }, - red_street_sign = { depth = 1/16, width = 1, height = 7/16, entity_fields = { - resolution = { x = 8, y = 4 }, + size = { x = 1, y = 4/16 }, maxlines = 1, color = "#000", }, @@ -80,7 +78,7 @@ local models = { width = 1, height = 7/16, entity_fields = { - resolution = { x = 9, y = 5.5 }, + size = { x = 1, y = 6/16 }, maxlines = 2, color = "#000", }, @@ -97,7 +95,7 @@ local models = { width = 1, height = 7/16, entity_fields = { - resolution = { x = 9, y = 5.5 }, + size = { x = 1, y = 6/16 }, maxlines = 2, color = "#fff", }, @@ -114,7 +112,7 @@ local models = { width = 1, height = 7/16, entity_fields = { - resolution = { x = 9, y = 5.5 }, + size = { x = 1, y = 6/16 }, maxlines = 2, color = "#000", }, @@ -131,7 +129,8 @@ local models = { width = 1, height = 0.5, entity_fields = { - resolution = { x = 7, y = 5 }, + aspect_ratio = 3/4, + size = { x = 1, y = 3/16 }, maxlines = 1, color = "#000", }, @@ -151,7 +150,8 @@ local models = { width = 1, height = 0.5, entity_fields = { - resolution = { x = 7, y = 5 }, + aspect_ratio = 3/4, + size = { x = 1, y = 3/16 }, maxlines = 1, color = "#000", }, @@ -176,7 +176,6 @@ local models = { entity_fields = { right = -3/32, size = { x = 12/16, y = 6/16 }, - resolution = { x = 9, y = 5.5 }, maxlines = 2, color = "#fff", }, @@ -200,7 +199,6 @@ local models = { entity_fields = { right = 3/32, size = { x = 12/16, y = 6/16 }, - resolution = { x = 9, y = 5.5 }, maxlines = 2, color="#fff", }, @@ -226,7 +224,6 @@ local models = { entity_fields = { right = -3/32, size = { x = 12/16, y = 6/16 }, - resolution = { x = 9, y = 5.5 }, maxlines = 2, color = "#000", }, @@ -250,7 +247,6 @@ local models = { entity_fields = { right = 3/32, size = { x = 12/16, y = 6/16 }, - resolution = { x = 9, y = 5.5 }, maxlines = 2, color = "#000", }, @@ -266,7 +262,7 @@ local models = { 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 } }, groups = { not_in_creative_inventory = 1 }, - drop = "signs_road:yellow_left_sign", + drop = "signs_road:yellow_right_sign", }, }, white_right_sign = { @@ -276,7 +272,6 @@ local models = { entity_fields = { right = -3/32, size = { x = 12/16, y = 6/16 }, - resolution = { x = 9, y = 5.5 }, maxlines = 2, color = "#000", }, @@ -300,7 +295,6 @@ local models = { entity_fields = { right = 3/32, size = { x = 12/16, y = 6/16 }, - resolution = { x = 9, y = 5.5 }, maxlines = 2, color = "#000", }, diff --git a/steles/nodes.lua b/steles/nodes.lua index eabb096..9fb65dd 100644 --- a/steles/nodes.lua +++ b/steles/nodes.lua @@ -42,17 +42,18 @@ for i, material in ipairs(steles.materials) do node_box = { type = "fixed", fixed = { - {-5/16, -4/16, -2/16, 5/16, 0.5, 2/16}, - {-7/16, -0.5, -4/16, 7/16, -4/16, 4/16} - } + {-5/16, -5/16, -2/16, 5/16, 0.5, 2/16}, + {-7/16, -0.5, -4/16, 7/16, -5/16, 4/16} + }, }, groups = groups, display_entities = { ["steles:text"] = { on_display_update = font_api.on_display_update, - depth = -2/16 - display_api.entity_spacing, height = 2/16, - size = { x = 14/16, y = 12/16 }, - resolution = { x = 11, y = 5 }, + depth = -2/16 - display_api.entity_spacing, + top = -2/16, + aspect_ratio = 0.4, + size = { x = 10/16, y = 12/16 }, maxlines = 3, }, }, -- cgit v1.2.3 From c19348d305945f70af25257ad70e980687ffbae8 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Mon, 16 Jul 2018 10:18:37 +0200 Subject: Cleanup some unused code --- signs_api/init.lua | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'signs_api') diff --git a/signs_api/init.lua b/signs_api/init.lua index e8a2b2b..1a4357e 100644 --- a/signs_api/init.lua +++ b/signs_api/init.lua @@ -27,23 +27,15 @@ local S, NS = dofile(signs_api.path.."/intllib.lua") signs_api.intllib = S local F = function(...) return minetest.formspec_escape(S(...)) end -local function update_font_index_meta(meta) - local font = meta:get_string("font") - local count = 0 - for key, def in pairs(font_api.registered_fonts) do - count = count + 1 - if font == key then - meta:set_string("font_idx", count) - end - end -end - -function signs_api.set_display_text(pos,text,font) +function signs_api.set_display_text(pos, text, font) local meta = minetest.get_meta(pos) meta:set_string("display_text", text) - meta:set_string("infotext", "\""..text.."\"") + if text and text ~= "" then + meta:set_string("infotext", "\""..text.."\"") + else + meta:set_string("infotext", "") + end meta:set_string("font", font) - update_font_index_meta(meta) display_api.update_entities(pos) end @@ -184,7 +176,6 @@ function signs_api.register_sign(mod, name, model) local meta = minetest.get_meta(pos) meta:set_string("font", ndef.display_entities.font_name or font_api.get_default_font_name()) - update_font_index_meta(meta) signs_api.set_formspec(pos) display_api.on_construct(pos) end, -- cgit v1.2.3 From 44b911be9e57dccea606da2b6907135af75d5033 Mon Sep 17 00:00:00 2001 From: 12Me21 <12Me21.MC@gmail.com> Date: Wed, 26 Sep 2018 13:41:30 -0400 Subject: Improve on_rotate functions (#21) Fixed bugs and improve on_rotate and support color- paramtype2s --- display_api/init.lua | 93 +++++++++++++++++++--------------------------------- signs_api/init.lua | 15 +++++---- 2 files changed, 41 insertions(+), 67 deletions(-) (limited to 'signs_api') diff --git a/display_api/init.lua b/display_api/init.lua index ca7b779..b65eb89 100644 --- a/display_api/init.lua +++ b/display_api/init.lua @@ -26,55 +26,30 @@ display_api.entity_spacing = 0.002 -- Miscelaneous values depending on wallmounted param2 local wallmounted_values = { - [0]={dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, -- Should never be used - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=1}, -- Should never be used - {dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=5}, - {dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=4}, - {dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=2}, - {dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3} + [2]={dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2}, + [3]={dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2 }, + [4]={dx=0, dz=-1, rx=1, rz=0, yaw=0 }, + [5]={dx=0, dz=1, rx=-1, rz=0, yaw=math.pi } } -- Miscelaneous values depending on facedir param2 local facedir_values = { - [0]={dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=1}, - {dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=2}, - {dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3}, - {dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=0}, - -- Forbiden values : - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, - } + [0]={dx=0, dz=-1, rx=1, rz=0, yaw=0 }, + [1]={dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2}, + [2]={dx=0, dz=1, rx=-1, rz=0, yaw=math.pi }, + [3]={dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2 } +} -- dx/dy = depth vector, rx/ly = right vector, yaw = yaw of entity, --- rotate = next facedir/wallmount on rotate - local function get_values(node) local ndef = minetest.registered_nodes[node.name] - + if ndef then - if ndef.paramtype2 == "wallmounted" then - return wallmounted_values[node.param2] - end - if ndef.paramtype2 == "facedir" then - return facedir_values[node.param2] + local paramtype2 = ndef.paramtype2 + if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then + return wallmounted_values[node.param2 % 8] + elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then + return facedir_values[node.param2 % 32] end end end @@ -97,9 +72,9 @@ local function get_entities(pos) if ndef and ndef.display_entities then for _, objref in ipairs(minetest.get_objects_inside_radius(pos, 1.5)) do local entity = objref:get_luaentity() - if entity and ndef.display_entities[entity.name] and check_entity_pos(pos, objref) then + if entity and ndef.display_entities[entity.name] and check_entity_pos(pos, objref) then if objrefs[entity.name] then - objref:remove() + objref:remove() else objrefs[entity.name] = objref end @@ -123,9 +98,9 @@ local function place_entities(pos) local ndef = minetest.registered_nodes[node.name] local values = get_values(node) local objrefs = get_entities(pos) - + if values and ndef and ndef.display_entities then - + for entity_name, props in pairs(ndef.display_entities) do local depth = clip_pos_prop(props.depth) local right = clip_pos_prop(props.right) @@ -133,12 +108,12 @@ local function place_entities(pos) if not objrefs[entity_name] then objrefs[entity_name] = minetest.add_entity(pos, entity_name) end - + objrefs[entity_name]:setpos({ x = pos.x - values.dx * depth + values.rx * right, y = pos.y - top, z = pos.z - values.dz * depth + values.rz * right}) - + objrefs[entity_name]:setyaw(values.yaw) end end @@ -151,7 +126,7 @@ local function call_node_on_display_update(pos, objref) local entity = objref:get_luaentity() if ndef and ndef.display_entities and entity and ndef.display_entities[entity.name] then ndef.display_entities[entity.name].on_display_update(pos, objref) - end + end end --- Force entity update @@ -186,7 +161,7 @@ end --- On_place callback for display_api items. Does nothing more than preventing item --- from being placed on ceiling or ground -function display_api.on_place(itemstack, placer, pointed_thing) +function display_api.on_place(itemstack, placer, pointed_thing, override_param2) local ndef = itemstack:get_definition() local above = pointed_thing.above local under = pointed_thing.under @@ -200,15 +175,16 @@ function display_api.on_place(itemstack, placer, pointed_thing) dir.y = 0 end - local param2 + local param2 = 0 if ndef then - if ndef.paramtype2 == "wallmounted" then + local paramtype2 = ndef.paramtype2 + if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then param2 = minetest.dir_to_wallmounted(dir) - elseif ndef.paramtype2 == "facedir" then + elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then param2 = minetest.dir_to_facedir(dir) end end - return minetest.item_place(itemstack, placer, pointed_thing, param2) + return minetest.item_place(itemstack, placer, pointed_thing, param2 + (override_param2 or 0)) end --- On_construct callback for display_api items. Creates entities and update them. @@ -225,14 +201,11 @@ function display_api.on_destruct(pos) end end --- On_rotate (screwdriver) callback for display_api items. Prevents axis rotation and reorients entities. -function display_api.on_rotate(pos, node, user, mode, new_param2) - if mode ~= 1 then return false end - - local values = get_values(node) - - if values then - minetest.swap_node(pos, {name = node.name, param1 = node.param1, param2 = values.rotate}) +-- On_rotate (screwdriver) callback for display_api items. Prevents invalid rotations and reorients entities. +function display_api.on_rotate(pos, node, user, _, new_param2) + node.param2 = new_param2 + if get_values(node) then + minetest.swap_node(pos, node) place_entities(pos) return true else diff --git a/signs_api/init.lua b/signs_api/init.lua index 1a4357e..ec3b0e9 100644 --- a/signs_api/init.lua +++ b/signs_api/init.lua @@ -132,18 +132,19 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing) end -- Handles screwdriver rotation. Direction is affected for direction signs +-- If rotation mode is 2 and sign is directional, swap direction. +-- Otherwise use display_api's on_rotate function. function signs_api.on_rotate(pos, node, player, mode, new_param2) if mode == 2 then local ndef = minetest.registered_nodes[node.name] - if ndef.signs_other_dir then - minetest.swap_node(pos, {name = ndef.signs_other_dir, - param1 = node.param1, param2 = node.param2}) + if ndef.signs_other_dir then + minetest.swap_node(pos, {name = ndef.signs_other_dir, + param1 = node.param1, param2 = node.param2}) display_api.update_entities(pos) - end - else - display_api.on_rotate(pos, node, user, mode, new_param2) + return true + end end - return false; + return display_api.on_rotate(pos, node, user, mode, new_param2) end function signs_api.register_sign(mod, name, model) -- cgit v1.2.3 From 641dddfd5100eafc3d8571576c0ae679c2877ea3 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Sun, 18 Nov 2018 15:29:59 +0100 Subject: Code simplification and securisation --- font_api/fontform.lua | 149 ++++++++++++++++++++++---------------------------- signs_api/init.lua | 52 +++++++++++------- 2 files changed, 97 insertions(+), 104 deletions(-) (limited to 'signs_api') diff --git a/font_api/fontform.lua b/font_api/fontform.lua index 118d92d..01929dd 100644 --- a/font_api/fontform.lua +++ b/font_api/fontform.lua @@ -19,67 +19,37 @@ local modname = minetest.get_current_modname() --- Context management functions (surely many improvements to do) - local contexts = {} -local function get_player_name(player) - if type(player) == 'string' then return player end - if type(player) == 'userdata' and player.get_player_name then - return player:get_player_name() - end - minetest.log('warning', '['..modname..'] get_player_name could not identify player.') -end - minetest.register_on_leaveplayer(function(player) - local playername = get_player_name(player) - if playername then contexts[playername] = nil end -end) - -local function new_context(player, context) - local playername = get_player_name(player) - if playername then - contexts[playername] = context - contexts[playername].playername = playername - return contexts[playername] - end -end - -local function get_context(player) - local playername = get_player_name(player) - if playername then - if contexts[playername] then - return contexts[playername] - else - minetest.log('warning', '['..modname..'] Context not found for player "'..playername..'"') - end + if minetest.is_player(player) then + contexts[player:get_player_name()] = nil end -end +end) -local function update_context(player, changes) - local playername = get_player_name(player) - if playername then - if not contexts[playername] then - contexts[playername] = { playername = playername } - end - for key, value in pairs(changes) do - contexts[playername][key] = value - end +local function get_context(playername) + if not contexts[playername] then + contexts[playername] = { playername = playername } end + return contexts[playername] end -- Show node formspec functions - -local function show_node_formspec(player, pos) +local function show_node_formspec(playername, pos) local meta = minetest.get_meta(pos) - local playername = get_player_name(player) -- Decontextualize formspec local fs = meta:get_string('formspec') + if not fs then + return + end + + -- Change context and currrent_name references to nodemeta references -- Change context and currrent_name references to nodemeta references - fs = fs:gsub("current_name", "nodemeta:"..pos.x..","..pos.y..","..pos.z) - fs = fs:gsub("context", "nodemeta:"..pos.x..","..pos.y..","..pos.z) + local nodemeta = string.format("nodemeta:%i,%i,%i", pos.x, pos.y ,pos.z) + fs = fs:gsub("current_name", nodemeta) + fs = fs:gsub("context", nodemeta) -- Change all ${} to their corresponding metadata values local s, e @@ -92,44 +62,44 @@ local function show_node_formspec(player, pos) end until s == nil + local context = get_context(playername) + context.node_pos = pos + -- Find node on_receive_fields local ndef = minetest.registered_nodes[minetest.get_node(pos).name] - if ndef and ndef.on_receive_fields then - update_context(player, { on_receive_fields = ndef.on_receive_fields } ) + context.on_receive_fields = ndef.on_receive_fields end - update_context(player, { node_pos = pos } ) -- Show formspec minetest.show_formspec(playername, modname..':context_formspec', fs) end minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname == modname..':context_formspec' then - local context = get_context(player) - if context == nil then return end + if formname ~= modname..':context_formspec' then + return + end - if context.on_receive_fields then - context.on_receive_fields(context.pos, '', fields, player) - end + if not minetest.is_player(player) then + return true end + + local context = get_context(player:get_player_name()) + if context.on_receive_fields then + context.on_receive_fields(context.pos, '', fields, player) + end + return true end) -- Specific functions -local function font_list_prepare() - local list = {} +local function show_font_formspec(playername) + local context = get_context(playername) + local fonts = {} for name, _ in pairs(font_api.registered_fonts) do - list[#list+1] = name + fonts[#fonts+1] = name end - table.sort(list) - return list -end - -local function show_fs(player) - local context = get_context(player) - if context == nil then return end - local fonts = font_list_prepare() + table.sort(fonts) local fs = 'size[4,'..(#fonts + 0.8)..']' ..default.gui_bg..default.gui_bg_img..default.gui_slots @@ -146,26 +116,39 @@ local function show_fs(player) end minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname == modname..':font_list' then - local context = get_context(player) - if context == nil then return end - - if fields.quit == 'true' then - for name, _ in pairs(font_api.registered_fonts) do - if fields['font_'..name] then - local meta = minetest.get_meta(context.pos) - meta:set_string("font", name) - display_api.update_entities(context.pos) - end - end + if formname ~= modname..':font_list' then + return + end + + if not minetest.is_player(player) then + return true + end + + local playername = player:get_player_name() + local context = get_context(playername) - -- Using after to avoid the "double close" bug - minetest.after(0, show_node_formspec, player, context.pos) + if minetest.is_protected(context.pos, playername) then + return true + end + + if fields.quit == 'true' then + for name, _ in pairs(font_api.registered_fonts) do + if fields['font_'..name] then + local meta = minetest.get_meta(context.pos) + meta:set_string("font", name) + display_api.update_entities(context.pos) + end end + -- Using after to avoid the "double close" bug + minetest.after(0, show_node_formspec, playername, context.pos) end + return true end) -function font_api.show_font_list(player, pos) - new_context(player, { pos = pos }) - show_fs(player) +function font_api.show_font_list_from_pos(player, pos) + if minetest.is_player(player) then + local context = get_context(player:get_player_name()) + context.pos = pos + show_font_formspec(player:get_player_name()) + end end diff --git a/signs_api/init.lua b/signs_api/init.lua index ec3b0e9..7e81e94 100644 --- a/signs_api/init.lua +++ b/signs_api/init.lua @@ -35,49 +35,62 @@ function signs_api.set_display_text(pos, text, font) else meta:set_string("infotext", "") end - meta:set_string("font", font) + if font then + meta:set_string("font", font) + end display_api.update_entities(pos) end function signs_api.set_formspec(pos) local meta = minetest.get_meta(pos) local ndef = minetest.registered_nodes[minetest.get_node(pos).name] - if ndef and ndef.display_entities + if ndef and ndef.display_entities and ndef.display_entities["signs:display_text"] then local maxlines = ndef.display_entities["signs:display_text"].maxlines - local formspec, formheight + local fs, x, y if maxlines == 1 then - formspec = - "field[0.5,0.7;5.5,1;display_text;"..F("Text").. - ";${display_text}]" - formheight = 2 + fs = "field[0.5,0.7;5.5,1;display_text;"..F("Text").. + ";${display_text}]" + y = 1.2 else local extralabel = "" if maxlines then extralabel = F(" (first %s lines only)"):format(maxlines) end - formspec = - "textarea[0.5,0.7;5.5,2;display_text;"..F("Text").."".. + fs = "textarea[0.5,0.7;5.5,2;display_text;"..F("Text").."".. extralabel..";${display_text}]" - formheight = 3 + y = 2.4 end - formspec = formspec.."button_exit[2,"..formheight..";2,1;ok;".. + x = 0.2 + fs = fs.."image_button["..x..","..y..";0.5,0.5;font_api_font.png;font;]" + x = x + 0.4 + fs = fs.."image_button["..x..","..y..";0.5,0.5;font_api_left.png;left;]" + x = x + 0.4 + fs = fs.."image_button["..x..","..y..";0.5,0.5;font_api_center.png;center;]" + x = x + 0.4 + fs = fs.."image_button["..x..","..y..";0.5,0.5;font_api_right.png;right;]" + y = y + 0.7 + fs = fs.."button_exit[2,"..y..";2,1;ok;".. F("Write").."]" - formheight = formheight + 1 - formspec = "size[6,"..formheight.."]"..default.gui_bg.. - default.gui_bg_img..default.gui_slots..formspec + y = y + 0.8 + fs = "size[6,"..y.."]"..default.gui_bg.. + default.gui_bg_img..default.gui_slots..fs - meta:set_string("formspec", formspec) + meta:set_string("formspec", fs) end end function signs_api.on_receive_fields(pos, formname, fields, player) if not minetest.is_protected(pos, player:get_player_name()) then if fields and (fields.ok or fields.key_enter) then - signs_api.set_display_text(pos, fields.display_text, fields.font) + signs_api.set_display_text(pos, fields.display_text) + end + if fields and (fields.font) then + signs_api.set_display_text(pos, fields.display_text) + font_api.show_font_list_from_pos(player, pos) end end end @@ -183,7 +196,8 @@ function signs_api.register_sign(mod, name, model) on_destruct = display_api.on_destruct, on_rotate = signs_api.on_rotate, on_receive_fields = signs_api.on_receive_fields, - on_punch = function(pos, node, player, pointed_thing) + on_punch = function(pos, node, player, pointed_thing) + signs_api.set_formspec(pos) display_api.update_entities(pos) end, } @@ -211,7 +225,3 @@ end -- Text entity for all signs display_api.register_display_entity("signs:display_text") - - - - -- cgit v1.2.3 From 59ae9fa4d153d9f1a554357febecd7f69c2642c9 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Sun, 18 Nov 2018 15:44:55 +0100 Subject: Simplified signs formspec for release --- signs_api/init.lua | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'signs_api') diff --git a/signs_api/init.lua b/signs_api/init.lua index 7e81e94..4f21495 100644 --- a/signs_api/init.lua +++ b/signs_api/init.lua @@ -47,7 +47,7 @@ function signs_api.set_formspec(pos) if ndef and ndef.display_entities and ndef.display_entities["signs:display_text"] then local maxlines = ndef.display_entities["signs:display_text"].maxlines - local fs, x, y + local fs, y if maxlines == 1 then fs = "field[0.5,0.7;5.5,1;display_text;"..F("Text").. @@ -64,17 +64,8 @@ function signs_api.set_formspec(pos) y = 2.4 end - x = 0.2 - fs = fs.."image_button["..x..","..y..";0.5,0.5;font_api_font.png;font;]" - x = x + 0.4 - fs = fs.."image_button["..x..","..y..";0.5,0.5;font_api_left.png;left;]" - x = x + 0.4 - fs = fs.."image_button["..x..","..y..";0.5,0.5;font_api_center.png;center;]" - x = x + 0.4 - fs = fs.."image_button["..x..","..y..";0.5,0.5;font_api_right.png;right;]" - y = y + 0.7 - fs = fs.."button_exit[2,"..y..";2,1;ok;".. - F("Write").."]" + fs = fs.."button[1,"..y..";2,1;font;"..F("Font").."]" + fs = fs.."button_exit[3,"..y..";2,1;ok;"..F("Write").."]" y = y + 0.8 fs = "size[6,"..y.."]"..default.gui_bg.. default.gui_bg_img..default.gui_slots..fs -- cgit v1.2.3 From 367e5026ddef3e6a0220f37a2f4aba64ec88f16b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Rollo Date: Fri, 23 Nov 2018 11:34:55 +0100 Subject: Fonts configurable in signs, posters and steles --- font_api/fontform.lua | 33 ++++++++++++------ signs/nodes.lua | 93 +++++++++++++++++++++++++++++++-------------------- signs_api/init.lua | 2 +- steles/nodes.lua | 22 +++++++----- 4 files changed, 94 insertions(+), 56 deletions(-) (limited to 'signs_api') diff --git a/font_api/fontform.lua b/font_api/fontform.lua index 01929dd..e4952ed 100644 --- a/font_api/fontform.lua +++ b/font_api/fontform.lua @@ -101,16 +101,18 @@ local function show_font_formspec(playername) end table.sort(fonts) - local fs = 'size[4,'..(#fonts + 0.8)..']' - ..default.gui_bg..default.gui_bg_img..default.gui_slots - ..'button_exit[0,'..(#fonts)..';4,1;cancel;Cancel]' + local fs = string.format( + "size[4,%s]%s%s%sbutton_exit[0,%s;4,1;cancel;Cancel]", + #fonts + 0.8, default.gui_bg, default.gui_bg_img, default.gui_slots, + #fonts) for line = 1, #fonts do local font = font_api.get_font(fonts[line]) - fs = fs..'image[0.1,'..(line-0.9)..';4.5,0.8;' - ..font:make_text_texture(font.name, font:get_height()*5, + local texture = font:make_text_texture(font.name, font:get_height()*5, font:get_height()*1.2, 1, "center", "top", "#fff") - ..']button_exit[0,'..(line-1)..';4,1;font_'..font.name..';]' + fs = string.format( + "%simage[0.1,%s;4.5,0.8;%s]button_exit[0,%s;4,1;font_%s;]", + fs, line-0.9, texture, line-1, font.name) end minetest.show_formspec(context.playername, modname..':font_list', fs) end @@ -127,7 +129,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local playername = player:get_player_name() local context = get_context(playername) - if minetest.is_protected(context.pos, playername) then + if not context.pos + or minetest.is_protected(context.pos, playername) then return true end @@ -139,16 +142,26 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) display_api.update_entities(context.pos) end end - -- Using after to avoid the "double close" bug - minetest.after(0, show_node_formspec, playername, context.pos) + + if context.callback and type(context.callback) == "function" then + -- Using after to avoid the "double close" bug + minetest.after(0, context.callback, playername, context.pos) + else + -- Using after to avoid the "double close" bug + minetest.after(0, show_node_formspec, playername, context.pos) + end end return true end) -function font_api.show_font_list_from_pos(player, pos) +-- @param player Player viewing the form +-- @param pos Node pos +-- @param callback function(playername, pos) to be called on form close +function font_api.show_font_list(player, pos, callback) if minetest.is_player(player) then local context = get_context(player:get_player_name()) context.pos = pos + context.callback = callback show_font_formspec(player:get_player_name()) end end diff --git a/signs/nodes.lua b/signs/nodes.lua index c74ab6f..8e65e27 100644 --- a/signs/nodes.lua +++ b/signs/nodes.lua @@ -23,51 +23,58 @@ local F = function(...) return minetest.formspec_escape(S(...)) end -- Poster specific formspec local function display_poster(pos, node, player) - local formspec local meta = minetest.get_meta(pos) + local def = minetest.registered_nodes[node.name].display_entities["signs:display_text"] local font = font_api.get_font(meta:get_string("font") or def.font_name) + local fs + local fname = string.format("%s@%s:display", + node.name, minetest.pos_to_string(pos)) + -- Title texture local titletexture = font:make_text_texture( - meta:get_string("display_text"), font:get_height()*8.4, font:get_height(), 1, "center") - - formspec = - "size[7,9]".. - "background[0,0;7,9;signs_poster_formspec.png]".. - "image[0,-0.2;8.4,2;"..titletexture.."]".. - "textarea[0.3,1.5;7,8;;"..minetest.colorize("#111", minetest.formspec_escape(meta:get_string("text")))..";]".. - "bgcolor[#0000]" + meta:get_string("display_text"), font:get_height()*8.4, + font:get_height(), 1, "center") + + 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] + textarea[0.3,1.5;7,8;;%s;]]=], + titletexture, + minetest.colorize("#111", + minetest.formspec_escape(meta:get_string("text")))) if minetest.is_protected(pos, player:get_player_name()) then - formspec = formspec.. - "button_exit[2.5,8;2,1;ok;"..F("Close").."]" + fs = string.format("%sbutton_exit[2.5,8;2,1;ok;%s]", fs, F("Close")) else - formspec = formspec.. - "button[1,8;2,1;edit;"..F("Edit").."]".. - "button_exit[4,8;2,1;ok;"..F("Close").."]" + fs = string.format( + "%sbutton[1,8;2,1;edit;%s]button_exit[4,8;2,1;ok;%s]", + fs, F("Edit"), F("Close")) end - minetest.show_formspec(player:get_player_name(), - node.name.."@"..minetest.pos_to_string(pos)..":display", - formspec) + minetest.show_formspec(player:get_player_name(), fname, fs) end local function edit_poster(pos, node, player) - local formspec local meta = minetest.get_meta(pos) + local fs + local fname = string.format("%s@%s:edit", + node.name, minetest.pos_to_string(pos)) + if not minetest.is_protected(pos, player:get_player_name()) then - formspec = - "size[6.5,7.5]".. - default.gui_bg .. default.gui_bg_img .. default.gui_slots .. - "field[0.5,0.7;6,1;display_text;"..F("Title")..";".. - minetest.formspec_escape(meta:get_string("display_text")).."]".. - "textarea[0.5,1.7;6,6;text;"..F("Text")..";".. - minetest.formspec_escape(meta:get_string("text")).."]".. - "button_exit[2.25,7;2,1;write;"..F("Write").."]" - minetest.show_formspec(player:get_player_name(), - node.name.."@"..minetest.pos_to_string(pos)..":edit", - formspec) + 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]]=], + default.gui_bg, default.gui_bg_img, default.gui_slots, F("Title"), + minetest.formspec_escape(meta:get_string("display_text")), + F("Text"), minetest.formspec_escape(meta:get_string("text")), + F("Title font"), F("Write")) + minetest.show_formspec(player:get_player_name(), fname, fs) end end @@ -80,15 +87,29 @@ local function on_receive_fields_poster(pos, formname, fields, player) if formname == node.name.."@"..minetest.pos_to_string(pos)..":display" and fields.edit then edit_poster(pos, node, player) + return true end if formname == node.name.."@"..minetest.pos_to_string(pos)..":edit" - and (fields.write 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) - display_poster(pos, node, player) + 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 end end end diff --git a/signs_api/init.lua b/signs_api/init.lua index 4f21495..9fcaa10 100644 --- a/signs_api/init.lua +++ b/signs_api/init.lua @@ -81,7 +81,7 @@ function signs_api.on_receive_fields(pos, formname, fields, player) end if fields and (fields.font) then signs_api.set_display_text(pos, fields.display_text) - font_api.show_font_list_from_pos(player, pos) + font_api.show_font_list(player, pos) end end end diff --git a/steles/nodes.lua b/steles/nodes.lua index 9b23b8d..79a9ed3 100644 --- a/steles/nodes.lua +++ b/steles/nodes.lua @@ -50,7 +50,7 @@ for i, material in ipairs(steles.materials) do display_entities = { ["steles:text"] = { on_display_update = font_api.on_display_update, - depth = -2/16 - display_api.entity_spacing, + depth = -2/16 - display_api.entity_spacing, top = -2/16, aspect_ratio = 0.4, size = { x = 10/16, y = 12/16 }, @@ -63,12 +63,14 @@ for i, material in ipairs(steles.materials) do end, on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("formspec", "size[6,4]" - ..default.gui_bg .. default.gui_bg_img .. default.gui_slots - .."textarea[0.5,0.7;5.5,2;display_text;" - ..F("Displayed text (3 lines max)") - ..";${display_text}]" - .."button_exit[2,3;2,1;ok;"..F("Write").."]") + 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"))) display_api.on_construct(pos) end, on_destruct = display_api.on_destruct, @@ -76,15 +78,17 @@ for i, material in ipairs(steles.materials) do on_receive_fields = function(pos, formname, fields, player) if not minetest.is_protected(pos, player:get_player_name()) then local meta = minetest.get_meta(pos) - if fields and fields.ok then + if fields.ok or fields.font then meta:set_string("display_text", fields.display_text) meta:set_string("infotext", "\""..fields.display_text.."\"") display_api.update_entities(pos) end + if fields.font then + font_api.show_font_list(player, pos) + end end end, on_punch = display_api.update_entities, }) end end - -- cgit v1.2.3