1
0
mirror of https://github.com/mt-mods/signs_lib.git synced 2025-06-28 22:06:20 +02:00

Compare commits

...

29 Commits

Author SHA1 Message Date
8b6e41c3fe Fix warnings regarding use_texture_alpha
Add use_texture_alpha = "clip" for standard signs.
Break Minetest 5.4< compatibility.
2021-02-28 12:27:34 +01:00
d077d23f1a mod.conf update to minetest 5.2.0+ compat 2021-02-27 05:15:21 +00:00
d71dcf4874 add text check for entity creation 2021-02-19 09:33:14 +00:00
ac8b00f826 Merge branch 'nonascii' into nonascii-european-test 2021-02-17 17:37:36 +01:00
707f633f0d Merge branch 'master' into nonascii 2021-02-17 17:37:11 +01:00
8527f1d5b2 writing [ or ] into a sign breaks the form for some users
the exact effect varies with client behavior and the particular text contents.
(characters erased, disappering formspec elements, loss of text)
2021-01-21 13:34:58 -05:00
3c824aedf8 Merge branch 'updateonoff' into 'master'
On/off switch doesn't reset the text anymore

See merge request VanessaE/signs_lib!5
2021-01-18 15:18:55 +00:00
fe72e32396 update on off 2021-01-16 11:57:06 +01:00
f7a4fefd34 Merge branch 'no_priv' into 'master'
Sign and land owners always able to edit a sign

See merge request VanessaE/signs_lib!4
2021-01-08 18:29:44 +00:00
664e99d34a Sign and land owners always able to edit a sign 2021-01-08 18:29:44 +00:00
e3c5fd2736 Merge branch 'separate_formspec' into 'master'
Signs formspec as separate formspecs (instead of dwelling in nodes metadata)

See merge request VanessaE/signs_lib!3
2021-01-03 18:39:29 +00:00
e7ab3e66a7 Signs formspec as separate formspecs (instead of dwelling in nodes metadata) 2021-01-03 18:39:29 +00:00
c82952befb Merge branch 'nonascii' into nonascii-european-test 2020-12-07 13:45:07 +01:00
26c3935c9b add texture generation scripts from https://github.com/zeuner/signs-font-generate 2020-12-07 13:38:31 +01:00
3ef11a995b recreate textures using latest version of https://github.com/zeuner/signs-font-generate 2020-12-05 18:55:42 +01:00
22af21aeaf Merge branch 'nonascii' into nonascii-european-test 2020-12-05 18:53:57 +01:00
af45e591e3 recreate textures using https://github.com/zeuner/signs-font-generate 2020-12-05 18:53:42 +01:00
b174cea893 Merge branch 'nonascii' into nonascii-european-test 2020-11-26 05:54:25 +01:00
4a196211ee Merge branch 'master' into nonascii 2020-11-26 05:53:45 +01:00
942e91e00e better align to existing font 2020-11-14 13:04:50 +01:00
4b2d4db848 test with some european languages 2020-11-13 12:08:39 +01:00
4b432eec08 support for non-ascii characters 2020-11-12 06:22:34 +01:00
d956c87dbc support for non-ascii characters 2020-11-12 06:02:56 +01:00
1a6b9f38ff enable static save on signs' entities 2020-11-01 12:43:55 -05:00
8b975d7fa1 add minimum minetest version key for contentdb 2020-06-03 13:00:34 -04:00
b633a4bf8c fix wrong default sign entity ref 2020-04-16 17:06:07 -04:00
bd20f9b776 add prefab_redo to opt depends 2020-02-26 16:03:48 +00:00
7c6a1c7611 add some missing aliases (and rearrange them) 2019-10-22 15:25:58 -04:00
bd8ae112d0 README tweaks 2019-10-11 06:00:31 -04:00
286 changed files with 693 additions and 146 deletions

7
.gitignore vendored
View File

@ -1,7 +0,0 @@
# temporary files
*~
# eclipse project files
.project
.settings
.buildpath

24
API.md
View File

@ -78,17 +78,11 @@ In this text, common terms such as `pos`, `node`, or `placer`/`digger` will not
Default: `signs_lib.after_place_node` Default: `signs_lib.after_place_node`
* `on_rightclick = function(pos)` * `on_rightclick = function(pos, node, player, itemstack, pointed_thing)`
See below under "Main functions". See below under "Main functions".
Default: `signs_lib.construct_sign` Default: `signs_lib.rightclick_sign`
* `on_construct = function(pos)`
See below under "Main functions".
Default: `signs_lib.construct_sign`
* `on_destruct = function(pos)` * `on_destruct = function(pos)`
@ -96,12 +90,6 @@ In this text, common terms such as `pos`, `node`, or `placer`/`digger` will not
Default: `signs_lib.destruct_sign` Default: `signs_lib.destruct_sign`
* `on_receive_fields = function(pos, formname, fields, sender)`
See below under "Main functions".
Default: `signs_lib.receive_fields`
* `on_punch = function(pos)` * `on_punch = function(pos)`
See below under "Main functions". See below under "Main functions".
@ -258,18 +246,14 @@ signs_lib.register_sign("basic_signs:sign_wall_glass", {
* `locked`: if set to **true**, the sign's meta will be tweaked to indicate its ownership by the `placer`. * `locked`: if set to **true**, the sign's meta will be tweaked to indicate its ownership by the `placer`.
* `signs_lib.construct_sign(pos)` * `signs_lib.rightclick_sign(pos, node, player, itemstack, pointed_thing)`
Sets up the sign's formspec and infotext overlay. Open the default sign formspec, if the player has the `signslib_edit` privilege.
* `signs_lib.destruct_sign(pos)` * `signs_lib.destruct_sign(pos)`
Deletes the sign's entity, if any, when the sign is dug. Deletes the sign's entity, if any, when the sign is dug.
* `signs_lib.receive_fields(pos, formname, fields, sender)`
This handles the text input and wide font on/off switch, logging any actions the user takes. Bails-out silently if the user is not allowed to edit the sign. See the standard Minetest lua_api.txt for details.
* `signs_lib.update_sign(pos, fields)` * `signs_lib.update_sign(pos, fields)`
If the sign's writable, this deletes any sign-related entities in the sign's node space, spawns a new one, and renders whatever text is in the sign's meta. If the sign's writable, this deletes any sign-related entities in the sign's node space, spawns a new one, and renders whatever text is in the sign's meta.

View File

@ -24,19 +24,17 @@ That said, there are some basic text formatting options:
* A color may be specified in the sign text by using "#" followed by a single hexadcimal digit (0-9 or a-f). These colors come from the standard Linux/IRC/CGA color set, and are shown in the sign's formspec. Any color change will remain in effect until changed again, or until the next line break. Any number of color changes in any arbitrary arrangement is allowed. * A color may be specified in the sign text by using "#" followed by a single hexadcimal digit (0-9 or a-f). These colors come from the standard Linux/IRC/CGA color set, and are shown in the sign's formspec. Any color change will remain in effect until changed again, or until the next line break. Any number of color changes in any arbitrary arrangement is allowed.
* Most writable signs can display double-wide text by flipping a switch in the sign's formspec.
## Sign placement and rotation notes ## Sign placement and rotation notes
* Pointing at a wall while placing will, of course, place the sign on the wall. * Pointing at a wall while placing will, of course, place the sign on the wall.
* For most signs, pointing at the ground while placing puts the sign flat on the ground. * For most signs that use the standard sign model, pointing at the ground while placing creates an upright standalone yard sign. Others not using the standard model will most often end up flat on the ground.
Exception: if you have [basic_signs](https://forum.minetest.net/viewtopic.php?f=11&t=23289) installed, placing a default wooden sign on the ground will instead create a "yard" sign (basically a regular wooden sign mounted upright on a small stick). * For most standard signs, pointing at the ceiling while placing will hang the sign from the ceiling by a pair of chains. Others not using the standard model will usually end up flat on the ceiling.
* For most signs, pointing at the ceiling while placing will put the sign flat against the ceiling. * Pointing at an X or Z side of something that's detected as a pole/post will mount the sign onto that pole, if possible. Note that the sign actually occupies the node space in front of the pole, since they're still separate nodes. But, I figure, no one's going to want to use the space in front of the sign anyway, because doing so would of course obscure the sign, so it doesn't matter if the sign logically occupies that node space.
Exception: default wood and steel signs will instead be hung from the ceiling by a pair of chains. If you have [basic_signs](https://forum.minetest.net/viewtopic.php?f=11&t=23289), all standard signs created by it will do the same.
* Pointing at an X or Z side of something that's detected as a pole/post will mount the sign onto that pole. Note that the sign actually occupies the node space in front of the pole, since they're still separate nodes. But, I figure, no one's going to want to use the space in front of the sign anyway, because doing so would of course obscure the sign, so it doesn't matter if the sign logically occupies that node space.
* If you're holding the "Sneak" key (usually `Shift`) while placing, the on-pole/hanging/yard checks are skipped, allowing you to just place a sign flat onto the ground, ceiling, or top/bottom of a pole/post, like they used to work before `signs_lib` was a thing. * If you're holding the "Sneak" key (usually `Shift`) while placing, the on-pole/hanging/yard checks are skipped, allowing you to just place a sign flat onto the ground, ceiling, or top/bottom of a pole/post, like they used to work before `signs_lib` was a thing.
@ -57,3 +55,9 @@ At present, only one command is defined:
This will read through the list of currently-loaded blocks known to contain one or more signs, delete all entities found in each sign's node space, and respawn and re-render each from scratch. This will read through the list of currently-loaded blocks known to contain one or more signs, delete all entities found in each sign's node space, and respawn and re-render each from scratch.
The list of loaded, sign-bearing blocks is created/populated by an LBM (and trimmed by this command if any listed blocks are found to have been unloaded). The list of loaded, sign-bearing blocks is created/populated by an LBM (and trimmed by this command if any listed blocks are found to have been unloaded).
## Privileges
* `signslib_edit`
Allows to rotate signs and to open (and consequently edit) any default sign formspec.

238
api.lua
View File

@ -2,6 +2,8 @@
local S = signs_lib.gettext local S = signs_lib.gettext
local function get_sign_formspec() end
signs_lib.lbm_restore_nodes = {} signs_lib.lbm_restore_nodes = {}
signs_lib.old_fenceposts = {} signs_lib.old_fenceposts = {}
signs_lib.old_fenceposts_replacement_signs = {} signs_lib.old_fenceposts_replacement_signs = {}
@ -153,15 +155,16 @@ signs_lib.flip_walldir = {
-- Initialize character texture cache -- Initialize character texture cache
local ctexcache = {} local ctexcache = {}
local ctexcache_wide = {}
-- entity handling -- entity handling
minetest.register_entity("signs_lib:text", { minetest.register_entity("signs_lib:text", {
collisionbox = { 0, 0, 0, 0, 0, 0 }, collisionbox = { 0, 0, 0, 0, 0, 0 },
visual = "mesh", visual = "mesh",
mesh = "signs_lib_standard_wall_sign_entity.obj", mesh = "signs_lib_standard_sign_entity_wall.obj",
textures = {}, textures = {},
static_save = false, static_save = true,
backface_culling = false backface_culling = false
}) })
@ -249,7 +252,10 @@ function signs_lib.set_obj_text(pos, text)
local text_ansi = Utf8ToAnsi(text) local text_ansi = Utf8ToAnsi(text)
local n = minetest.registered_nodes[minetest.get_node(pos).name] local n = minetest.registered_nodes[minetest.get_node(pos).name]
signs_lib.delete_objects(pos) signs_lib.delete_objects(pos)
-- only create sign entity for actual text
if text_ansi and text_ansi ~= "" then
signs_lib.spawn_entity(pos, signs_lib.make_sign_texture(split(text_ansi), pos) ) signs_lib.spawn_entity(pos, signs_lib.make_sign_texture(split(text_ansi), pos) )
end
end end
-- rotation -- rotation
@ -328,8 +334,10 @@ end
local TP = signs_lib.path .. "/textures" local TP = signs_lib.path .. "/textures"
-- Font file formatter -- Font file formatter
local CHAR_FILE = "%s_%02x.png" local CHAR_FILE = "%s_%02x.png"
local CHAR_FILE_WIDE = "%s_%s.png"
-- Fonts path -- Fonts path
local CHAR_PATH = TP .. "/" .. CHAR_FILE local CHAR_PATH = TP .. "/" .. CHAR_FILE
local CHAR_PATH_WIDE = TP .. "/" .. CHAR_FILE_WIDE
-- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza -- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza
@ -389,6 +397,7 @@ end
local function build_char_db(font_size) local function build_char_db(font_size)
local cw = {} local cw = {}
local cw_wide = {}
-- To calculate average char width. -- To calculate average char width.
local total_width = 0 local total_width = 0
@ -404,20 +413,32 @@ local function build_char_db(font_size)
end end
end end
for i = 1, #signs_lib.wide_character_codes do
local ch = signs_lib.wide_character_codes[i]
local w, h = signs_lib.read_image_size(CHAR_PATH_WIDE:format("signs_lib_font_"..font_size.."px", ch))
if w and h then
cw_wide[ch] = w
total_width = total_width + w
char_count = char_count + 1
end
end
local cbw, cbh = signs_lib.read_image_size(TP.."/signs_lib_color_"..font_size.."px_n.png") local cbw, cbh = signs_lib.read_image_size(TP.."/signs_lib_color_"..font_size.."px_n.png")
assert(cbw and cbh, "error reading bg dimensions") assert(cbw and cbh, "error reading bg dimensions")
return cw, cbw, cbh, (total_width / char_count) return cw, cbw, cbh, (total_width / char_count), cw_wide
end end
signs_lib.charwidth15, signs_lib.charwidth15,
signs_lib.colorbgw15, signs_lib.colorbgw15,
signs_lib.lineheight15, signs_lib.lineheight15,
signs_lib.avgwidth15 = build_char_db(15) signs_lib.avgwidth15,
signs_lib.charwidth_wide15 = build_char_db(15)
signs_lib.charwidth31, signs_lib.charwidth31,
signs_lib.colorbgw31, signs_lib.colorbgw31,
signs_lib.lineheight31, signs_lib.lineheight31,
signs_lib.avgwidth31 = build_char_db(31) signs_lib.avgwidth31,
signs_lib.charwidth_wide31 = build_char_db(31)
local sign_groups = {choppy=2, dig_immediate=2} local sign_groups = {choppy=2, dig_immediate=2}
local fences_with_sign = { } local fences_with_sign = { }
@ -453,7 +474,22 @@ local function char_tex(font_name, ch)
end end
end end
local function make_line_texture(line, lineno, pos, line_width, line_height, cwidth_tab, font_size, colorbgw) local function char_tex_wide(font_name, ch)
if ctexcache_wide[font_name..ch] then
return ctexcache_wide[font_name..ch], true
else
local exists, tex = file_exists(CHAR_PATH_WIDE:format(font_name, ch))
if exists then
tex = CHAR_FILE_WIDE:format(font_name, ch)
else
tex = CHAR_FILE:format(font_name, 0x5f)
end
ctexcache_wide[font_name..ch] = tex
return tex, exists
end
end
local function make_line_texture(line, lineno, pos, line_width, line_height, cwidth_tab, font_size, colorbgw, cwidth_tab_wide)
local width = 0 local width = 0
local maxw = 0 local maxw = 0
local font_name = "signs_lib_font_"..font_size.."px" local font_name = "signs_lib_font_"..font_size.."px"
@ -490,6 +526,27 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
local word_l = #word local word_l = #word
local i = 1 local i = 1
while i <= word_l do while i <= word_l do
local wide_c
if "&#x" == word:sub(i, i + 2) then
local j = i + 3
local collected = ""
while j <= word_l do
local c = word:sub(j, j)
if c == ";" then
wide_c = collected
break
elseif c < "0" then
break
elseif "f" < c then
break
elseif ("9" < c) and (c < "a") then
break
else
collected = collected .. c
j = j + 1
end
end
end
local c = word:sub(i, i) local c = word:sub(i, i)
if c == "#" then if c == "#" then
local cc = tonumber(word:sub(i+1, i+1), 16) local cc = tonumber(word:sub(i+1, i+1), 16)
@ -497,6 +554,25 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
i = i + 1 i = i + 1
cur_color = cc cur_color = cc
end end
elseif wide_c then
local w = cwidth_tab_wide[wide_c]
if w then
width = width + w + 1
if width >= (line_width - cwidth_tab[" "]) then
width = 0
else
maxw = math_max(width, maxw)
end
if #chars < MAX_INPUT_CHARS then
table.insert(chars, {
off = ch_offs,
tex = char_tex_wide(font_name, wide_c),
col = ("%X"):format(cur_color),
})
end
ch_offs = ch_offs + w
end
i = i + #wide_c + 3
else else
local w = cwidth_tab[c] local w = cwidth_tab[c]
if w then if w then
@ -576,6 +652,7 @@ function signs_lib.make_sign_texture(lines, pos)
local line_width local line_width
local line_height local line_height
local char_width local char_width
local char_width_wide
local colorbgw local colorbgw
local widemult = 1 local widemult = 1
@ -588,12 +665,14 @@ function signs_lib.make_sign_texture(lines, pos)
line_width = math.floor(signs_lib.avgwidth31 * def.chars_per_line) * (def.horiz_scaling * widemult) line_width = math.floor(signs_lib.avgwidth31 * def.chars_per_line) * (def.horiz_scaling * widemult)
line_height = signs_lib.lineheight31 line_height = signs_lib.lineheight31
char_width = signs_lib.charwidth31 char_width = signs_lib.charwidth31
char_width_wide = signs_lib.charwidth_wide31
colorbgw = signs_lib.colorbgw31 colorbgw = signs_lib.colorbgw31
else else
font_size = 15 font_size = 15
line_width = math.floor(signs_lib.avgwidth15 * def.chars_per_line) * (def.horiz_scaling * widemult) line_width = math.floor(signs_lib.avgwidth15 * def.chars_per_line) * (def.horiz_scaling * widemult)
line_height = signs_lib.lineheight15 line_height = signs_lib.lineheight15
char_width = signs_lib.charwidth15 char_width = signs_lib.charwidth15
char_width_wide = signs_lib.charwidth_wide15
colorbgw = signs_lib.colorbgw15 colorbgw = signs_lib.colorbgw15
end end
@ -602,7 +681,7 @@ function signs_lib.make_sign_texture(lines, pos)
local lineno = 0 local lineno = 0
for i = 1, #lines do for i = 1, #lines do
if lineno >= def.number_of_lines then break end if lineno >= def.number_of_lines then break end
local linetex, ln = make_line_texture(lines[i], lineno, pos, line_width, line_height, char_width, font_size, colorbgw) local linetex, ln = make_line_texture(lines[i], lineno, pos, line_width, line_height, char_width, font_size, colorbgw, char_width_wide)
table.insert(texture, linetex) table.insert(texture, linetex)
lineno = ln + 1 lineno = ln + 1
end end
@ -619,31 +698,12 @@ function signs_lib.split_lines_and_words(text)
return lines return lines
end end
function signs_lib.construct_sign(pos) function signs_lib.rightclick_sign(pos, node, player, itemstack, pointed_thing)
local form = "size[6,4]"..
"textarea[0,-0.3;6.5,3;text;;${text}]"..
"background[-0.5,-0.5;7,5;signs_lib_sign_bg.jpg]"
local node = minetest.get_node(pos)
local def = minetest.registered_items[node.name]
local meta = minetest.get_meta(pos)
if def.allow_widefont then if not signs_lib.can_modify(pos, player) then return end
local state = "off"
if meta:get_int("widefont") == 1 then state = "on" end
form = form.."label[1,3.4;Use wide font]"..
"image_button[1.1,3.7;1,0.6;signs_lib_switch_"..
state..".png;"..
state..";;;false;signs_lib_switch_interm.png]"..
"button_exit[3,3.4;2,1;ok;"..S("Write").."]"
else
form = form.."button_exit[2,3.4;2,1;ok;"..S("Write").."]"
end
meta:set_string("formspec", form) player:get_meta():set_string("signslib:pos", minetest.pos_to_string(pos))
local i = meta:get_string("infotext") minetest.show_formspec(player:get_player_name(), "signs_lib:sign", get_sign_formspec(pos, node.name))
if i == "" then -- it wasn't even set, so set it.
meta:set_string("infotext", "")
end
end end
function signs_lib.destruct_sign(pos) function signs_lib.destruct_sign(pos)
@ -663,6 +723,11 @@ end
function signs_lib.update_sign(pos, fields) function signs_lib.update_sign(pos, fields)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
-- legacy udpate
if meta:get_string("formspec") ~= "" then
meta:set_string("formspec", "")
end
local text = fields and fields.text or meta:get_string("text") local text = fields and fields.text or meta:get_string("text")
text = trim_input(text) text = trim_input(text)
@ -675,41 +740,6 @@ function signs_lib.update_sign(pos, fields)
signs_lib.set_obj_text(pos, text) signs_lib.set_obj_text(pos, text)
end end
function signs_lib.receive_fields(pos, formname, fields, sender)
if not fields or not signs_lib.can_modify(pos, sender) then return end
if fields.text and fields.ok then
minetest.log("action", S("@1 wrote \"@2\" to sign at @3",
(sender:get_player_name() or ""),
fields.text:gsub('\\', '\\\\'):gsub("\n", "\\n"),
minetest.pos_to_string(pos)
))
signs_lib.update_sign(pos, fields)
elseif fields.on or fields.off then
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local change
if fields.on and meta:get_int("widefont") == 1 then
meta:set_int("widefont", 0)
change = true
elseif fields.off and meta:get_int("widefont") == 0 then
meta:set_int("widefont", 1)
change = true
end
if change then
minetest.log("action", S("@1 flipped the wide-font switch to \"@2\" at @3",
(sender:get_player_name() or ""),
(fields.on and "off" or "on"),
minetest.pos_to_string(pos)
))
signs_lib.construct_sign(pos)
signs_lib.update_sign(pos, fields)
end
end
end
function signs_lib.can_modify(pos, player) function signs_lib.can_modify(pos, player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
@ -722,7 +752,7 @@ function signs_lib.can_modify(pos, player)
if owner == "" if owner == ""
or playername == owner or playername == owner
or (minetest.check_player_privs(playername, {sign_editor=true})) or (minetest.check_player_privs(playername, {signslib_edit=true}))
or (playername == minetest.settings:get("name")) then or (playername == minetest.settings:get("name")) then
return true return true
end end
@ -887,10 +917,8 @@ function signs_lib.register_sign(name, raw_def)
def.after_place_node = raw_def.after_place_node or signs_lib.after_place_node def.after_place_node = raw_def.after_place_node or signs_lib.after_place_node
if raw_def.entity_info then if raw_def.entity_info then
def.on_rightclick = raw_def.on_rightclick or signs_lib.construct_sign def.on_rightclick = raw_def.on_rightclick or signs_lib.rightclick_sign
def.on_construct = raw_def.on_construct or signs_lib.construct_sign
def.on_destruct = raw_def.on_destruct or signs_lib.destruct_sign def.on_destruct = raw_def.on_destruct or signs_lib.destruct_sign
def.on_receive_fields = raw_def.on_receive_fields or signs_lib.receive_fields
def.on_punch = raw_def.on_punch or signs_lib.update_sign def.on_punch = raw_def.on_punch or signs_lib.update_sign
def.number_of_lines = raw_def.number_of_lines or signs_lib.standard_lines def.number_of_lines = raw_def.number_of_lines or signs_lib.standard_lines
def.horiz_scaling = raw_def.horiz_scaling or signs_lib.standard_hscale def.horiz_scaling = raw_def.horiz_scaling or signs_lib.standard_hscale
@ -1184,3 +1212,75 @@ minetest.register_chatcommand("regen_signs", {
minetest.chat_send_player(player_name, "Finished.") minetest.chat_send_player(player_name, "Finished.")
end end
}) })
minetest.register_privilege("signslib_edit", {})
--
-- local functions
--
function get_sign_formspec(pos, nodename)
local meta = minetest.get_meta(pos)
local txt = meta:get_string("text")
local formspec = {
"size[6,4]",
"textarea[0,-0.3;6.5,3;text;;" .. minetest.formspec_escape(txt) .. "]",
"background[-0.5,-0.5;7,5;signs_lib_sign_bg.jpg]",
"button_exit[2,3.4;2,1;ok;" .. S("Write") .. "]"
}
if minetest.registered_nodes[nodename].allow_widefont then
local state = "off"
if meta:get_int("widefont") == 1 then state = "on" end
formspec[5] = "label[0.5,3.4;Use wide font]"
formspec[6] = "image_button[0.6,3.7;1,0.6;signs_lib_switch_" .. state .. ".png;"
.. state .. ";;;false;signs_lib_switch_interm.png]"
end
return table.concat(formspec, "")
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "signs_lib:sign" then return end
local pos_string = player:get_meta():get_string("signslib:pos")
local pos = minetest.string_to_pos(pos_string)
local playername = player:get_player_name()
if fields.text and fields.ok then
minetest.log("action", S("@1 wrote \"@2\" to sign at @3",
(playername or ""),
fields.text:gsub('\\', '\\\\'):gsub("\n", "\\n"),
pos_string
))
signs_lib.update_sign(pos, fields)
elseif fields.on or fields.off then
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local change
if fields.on and meta:get_int("widefont") == 1 then
meta:set_int("widefont", 0)
change = true
elseif fields.off and meta:get_int("widefont") == 0 then
meta:set_int("widefont", 1)
change = true
end
if change then
minetest.log("action", S("@1 flipped the wide-font switch to \"@2\" at @3",
(playername or ""),
(fields.on and "off" or "on"),
minetest.pos_to_string(pos)
))
signs_lib.update_sign(pos, fields)
minetest.show_formspec(playername, "signs_lib:sign", get_sign_formspec(pos, node.name))
end
end
end)

View File

@ -1,6 +0,0 @@
default
intllib?
screwdriver?
streetspoles?
streetlamps?
cottages?

View File

@ -1 +0,0 @@
Adds signs with readable text.

View File

@ -203,6 +203,32 @@ local utf8_decode = {
[210] = {[144] = "\165", [145] = "\180"} [210] = {[144] = "\165", [145] = "\180"}
} }
local wide_character_codes = {
}
signs_lib.unicode_install = function(
numbers
)
local scope = utf8_decode
for i = 1,#numbers-2 do
if not scope[numbers[i]] then
scope[numbers[i]] = {}
end
scope = scope[numbers[i]]
end
scope[numbers[#numbers-1]] = "&#x" .. numbers[#numbers] .. ";"
table.insert(
wide_character_codes,
numbers[#numbers]
)
end
signs_lib.unicode_install({38,"26"})
dofile(signs_lib.path.."/nonascii-de.lua")
dofile(signs_lib.path.."/nonascii-fr.lua")
dofile(signs_lib.path.."/nonascii-pl.lua")
local nmdc = { local nmdc = {
[36] = "$", [36] = "$",
[124] = "|" [124] = "|"
@ -230,36 +256,33 @@ function AnsiToUtf8(s)
end end
function Utf8ToAnsi(s) function Utf8ToAnsi(s)
local a, j, r, b = 0, 0, "" local a, j, r, b, scope = 0, 0, ""
for i = 1, s and s:len() or 0 do for i = 1, s and s:len() or 0 do
b = s:byte(i) b = s:byte(i)
if b < 128 then if b == 0x26 then
r = r .. "&#x26;"
elseif b < 128 then
if nmdc[b] then if nmdc[b] then
r = r .. nmdc[b] r = r .. nmdc[b]
else else
r = r .. string.char(b) r = r .. string.char(b)
end end
elseif a == 2 then elseif scope then
a, j = a - 1, b if scope[b] then
elseif a == 1 then scope = scope[b]
--if j == nil or b == nil then return r end if "string" == type(scope) then
--print(j) r, scope = r .. scope
--print(b)
--local ansi = utf8_decode[j]
--if ansi == nil then return r end
--if ansi[b] == nil then return r end
if utf8_decode[j] then
if utf8_decode[j][b] then
a, r = a - 1, r .. utf8_decode[j][b]
end end
else
r, scope = r .. "_"
end end
elseif b == 226 then elseif utf8_decode[b] then
a = 2 scope = utf8_decode[b]
elseif b == 194 or b == 208 or b == 209 or b == 210 then
j, a = b, 1
else else
r = r .. "_" r = r .. "_"
end end
end end
return r return r
end end
signs_lib.wide_character_codes = wide_character_codes

View File

@ -10,7 +10,7 @@ signs_lib.path = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(signs_lib.path .. "/intllib.lua") local S, NS = dofile(signs_lib.path .. "/intllib.lua")
signs_lib.gettext = S signs_lib.gettext = S
dofile(signs_lib.path.."/api.lua")
dofile(signs_lib.path.."/encoding.lua") dofile(signs_lib.path.."/encoding.lua")
dofile(signs_lib.path.."/api.lua")
dofile(signs_lib.path.."/standard_signs.lua") dofile(signs_lib.path.."/standard_signs.lua")
dofile(signs_lib.path.."/compat.lua") dofile(signs_lib.path.."/compat.lua")

View File

@ -1 +1,6 @@
name = signs_lib name = signs_lib
author = VanessaE
depends = default
optional_depends = intllib, screwdriver, streetspoles, streetlamps, cottages, prefab_redo
description = Adds signs with readable text.
min_minetest_version = 5.2.0

7
nonascii-de.lua Normal file
View File

@ -0,0 +1,7 @@
signs_lib.unicode_install({195,132,"00c4"})
signs_lib.unicode_install({195,150,"00d6"})
signs_lib.unicode_install({195,156,"00dc"})
signs_lib.unicode_install({195,159,"00df"})
signs_lib.unicode_install({195,164,"00e4"})
signs_lib.unicode_install({195,182,"00f6"})
signs_lib.unicode_install({195,188,"00fc"})

16
nonascii-fr.lua Normal file
View File

@ -0,0 +1,16 @@
signs_lib.unicode_install({195,128,"00c0"})
signs_lib.unicode_install({195,134,"00c6"})
signs_lib.unicode_install({195,135,"00c7"})
signs_lib.unicode_install({195,136,"00c8"})
signs_lib.unicode_install({195,137,"00c9"})
signs_lib.unicode_install({195,138,"00ca"})
signs_lib.unicode_install({195,148,"00d4"})
signs_lib.unicode_install({195,153,"00d9"})
signs_lib.unicode_install({195,160,"00e0"})
signs_lib.unicode_install({195,166,"00e6"})
signs_lib.unicode_install({195,167,"00e7"})
signs_lib.unicode_install({195,168,"00e8"})
signs_lib.unicode_install({195,169,"00e9"})
signs_lib.unicode_install({195,170,"00ea"})
signs_lib.unicode_install({195,180,"00f4"})
signs_lib.unicode_install({195,185,"00f9"})

16
nonascii-pl.lua Normal file
View File

@ -0,0 +1,16 @@
signs_lib.unicode_install({195,147,"00d3"})
signs_lib.unicode_install({195,179,"00f3"})
signs_lib.unicode_install({196,132,"0104"})
signs_lib.unicode_install({196,133,"0105"})
signs_lib.unicode_install({196,134,"0106"})
signs_lib.unicode_install({196,135,"0107"})
signs_lib.unicode_install({196,152,"0118"})
signs_lib.unicode_install({196,153,"0119"})
signs_lib.unicode_install({197,129,"0141"})
signs_lib.unicode_install({197,130,"0142"})
signs_lib.unicode_install({197,154,"015a"})
signs_lib.unicode_install({197,155,"015b"})
signs_lib.unicode_install({197,185,"0179"})
signs_lib.unicode_install({197,186,"017a"})
signs_lib.unicode_install({197,187,"017b"})
signs_lib.unicode_install({197,188,"017c"})

View File

@ -14,7 +14,8 @@ signs_lib.register_sign("default:sign_wall_wood", {
allow_widefont = true, allow_widefont = true,
allow_onpole = true, allow_onpole = true,
allow_onpole_horizontal = true, allow_onpole_horizontal = true,
allow_yard = true allow_yard = true,
use_texture_alpha = "clip",
}) })
signs_lib.register_sign("default:sign_wall_steel", { signs_lib.register_sign("default:sign_wall_steel", {
@ -35,20 +36,26 @@ signs_lib.register_sign("default:sign_wall_steel", {
allow_widefont = true, allow_widefont = true,
allow_onpole = true, allow_onpole = true,
allow_onpole_horizontal = true, allow_onpole_horizontal = true,
allow_yard = true allow_yard = true,
use_texture_alpha = "clip",
}) })
minetest.register_alias("default:sign_wall_wood_onpole", "default:sign_wood_onpole")
minetest.register_alias("default:sign_wall_wood_hanging", "default:sign_wood_hanging")
minetest.register_alias("signs:sign_hanging", "default:sign_wood_hanging") minetest.register_alias("signs:sign_hanging", "default:sign_wood_hanging")
minetest.register_alias("basic_signs:hanging_sign", "default:sign_wood_hanging") minetest.register_alias("basic_signs:hanging_sign", "default:sign_wood_hanging")
minetest.register_alias("default:sign_wall_wood_yard", "default:sign_wood_yard")
minetest.register_alias("signs:sign_yard", "default:sign_wood_yard") minetest.register_alias("signs:sign_yard", "default:sign_wood_yard")
minetest.register_alias("basic_signs:yard_sign", "default:sign_wood_yard") minetest.register_alias("basic_signs:yard_sign", "default:sign_wood_yard")
minetest.register_alias("default:sign_wall_wood_onpole", "default:sign_wood_onpole")
minetest.register_alias("default:sign_wall_wood_onpole_horiz", "default:sign_wood_onpole_horiz")
minetest.register_alias("default:sign_wall_wood_hanging", "default:sign_wood_hanging")
minetest.register_alias("default:sign_wall_wood_yard", "default:sign_wood_yard")
minetest.register_alias("default:sign_wall_steel_onpole", "default:sign_steel_onpole")
minetest.register_alias("default:sign_wall_steel_onpole_horiz", "default:sign_steel_onpole_horiz")
minetest.register_alias("default:sign_wall_steel_hanging", "default:sign_steel_hanging")
minetest.register_alias("default:sign_wall_steel_yard", "default:sign_steel_yard")
table.insert(signs_lib.lbm_restore_nodes, "signs:sign_hanging") table.insert(signs_lib.lbm_restore_nodes, "signs:sign_hanging")
table.insert(signs_lib.lbm_restore_nodes, "basic_signs:hanging_sign") table.insert(signs_lib.lbm_restore_nodes, "basic_signs:hanging_sign")
table.insert(signs_lib.lbm_restore_nodes, "signs:sign_yard") table.insert(signs_lib.lbm_restore_nodes, "signs:sign_yard")

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 B

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 B

After

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 B

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 B

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 B

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 B

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 B

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 B

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 B

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 B

After

Width:  |  Height:  |  Size: 309 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 B

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 B

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 B

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 B

After

Width:  |  Height:  |  Size: 316 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 B

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 B

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 B

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 B

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 B

After

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 B

After

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 B

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 B

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 B

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 B

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 B

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 B

After

Width:  |  Height:  |  Size: 322 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 B

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 B

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 B

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 128 B

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 B

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 B

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 B

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 B

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 B

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 B

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 B

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 89 B

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 B

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 B

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 B

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 B

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 B

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 B

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 116 B

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 99 B

After

Width:  |  Height:  |  Size: 321 B

Some files were not shown because too many files have changed in this diff Show More