mirror of
https://github.com/mt-mods/signs_lib.git
synced 2024-12-25 16:50:17 +01:00
use a meta key to select wide-font mode
instead of using a separate node add LBM to convert old nodes.
This commit is contained in:
parent
77987d12b9
commit
d41e2ffd73
179
api.lua
179
api.lua
@ -31,6 +31,11 @@ signs_lib.standard_steel_sign_sounds = table.copy(minetest.registered_items["def
|
|||||||
|
|
||||||
signs_lib.default_text_scale = {x=10, y=10}
|
signs_lib.default_text_scale = {x=10, y=10}
|
||||||
|
|
||||||
|
signs_lib.old_widefont_signs = {}
|
||||||
|
|
||||||
|
signs_lib.block_list = {}
|
||||||
|
signs_lib.totalblocks = 0
|
||||||
|
|
||||||
signs_lib.standard_yaw = {
|
signs_lib.standard_yaw = {
|
||||||
0,
|
0,
|
||||||
math.pi / -2,
|
math.pi / -2,
|
||||||
@ -614,6 +619,8 @@ end
|
|||||||
|
|
||||||
local function make_sign_texture(lines, pos)
|
local function make_sign_texture(lines, pos)
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
local def = minetest.registered_items[node.name]
|
local def = minetest.registered_items[node.name]
|
||||||
if not def or not def.entity_info then return end
|
if not def or not def.entity_info then return end
|
||||||
|
|
||||||
@ -622,16 +629,21 @@ local function make_sign_texture(lines, pos)
|
|||||||
local line_height
|
local line_height
|
||||||
local char_width
|
local char_width
|
||||||
local colorbgw
|
local colorbgw
|
||||||
|
local widemult = 1
|
||||||
|
|
||||||
|
if meta:get_int("widefont") == 1 then
|
||||||
|
widemult = 0.5
|
||||||
|
end
|
||||||
|
|
||||||
if def.font_size and def.font_size == 31 then
|
if def.font_size and def.font_size == 31 then
|
||||||
font_size = 31
|
font_size = 31
|
||||||
line_width = math.floor(signs_lib.avgwidth31 * def.chars_per_line) * def.horiz_scaling
|
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
|
||||||
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
|
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
|
||||||
colorbgw = signs_lib.colorbgw15
|
colorbgw = signs_lib.colorbgw15
|
||||||
@ -667,31 +679,17 @@ function signs_lib.set_obj_text(pos, text)
|
|||||||
signs_lib.spawn_entity(pos, make_sign_texture(split(text_ansi), pos))
|
signs_lib.spawn_entity(pos, make_sign_texture(split(text_ansi), pos))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function make_widefont_nodename(name)
|
|
||||||
if string.find(name, "_widefont") then return name end
|
|
||||||
if string.find(name, "_onpole") then
|
|
||||||
if string.find(name, "_horiz") then
|
|
||||||
return string.gsub(name, "_onpole_horiz", "_widefont_onpole_horiz")
|
|
||||||
else
|
|
||||||
return string.gsub(name, "_onpole", "_widefont_onpole")
|
|
||||||
end
|
|
||||||
elseif string.find(name, "_hanging") then
|
|
||||||
return string.gsub(name, "_hanging", "_widefont_hanging")
|
|
||||||
else
|
|
||||||
return name.."_widefont"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function signs_lib.construct_sign(pos)
|
function signs_lib.construct_sign(pos)
|
||||||
local form = "size[6,4]"..
|
local form = "size[6,4]"..
|
||||||
"textarea[0,-0.3;6.5,3;text;;${text}]"..
|
"textarea[0,-0.3;6.5,3;text;;${text}]"..
|
||||||
"background[-0.5,-0.5;7,5;signs_lib_sign_bg.jpg]"
|
"background[-0.5,-0.5;7,5;signs_lib_sign_bg.jpg]"
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local wname = make_widefont_nodename(node.name)
|
local def = minetest.registered_items[node.name]
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
|
||||||
if minetest.registered_items[wname] then
|
if def.allow_widefont then
|
||||||
local state = "off"
|
local state = "off"
|
||||||
if string.find(node.name, "widefont") then state = "on" end
|
if meta:get_int("widefont") == 1 then state = "on" end
|
||||||
form = form.."label[1,3.4;Use wide font]"..
|
form = form.."label[1,3.4;Use wide font]"..
|
||||||
"image_button[1.1,3.7;1,0.6;signs_lib_switch_"..
|
"image_button[1.1,3.7;1,0.6;signs_lib_switch_"..
|
||||||
state..".png;"..
|
state..".png;"..
|
||||||
@ -701,7 +699,6 @@ function signs_lib.construct_sign(pos)
|
|||||||
form = form.."button_exit[2,3.4;2,1;ok;"..S("Write").."]"
|
form = form.."button_exit[2,3.4;2,1;ok;"..S("Write").."]"
|
||||||
end
|
end
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
meta:set_string("formspec", form)
|
meta:set_string("formspec", form)
|
||||||
local i = meta:get_string("infotext")
|
local i = meta:get_string("infotext")
|
||||||
if i == "" then -- it wasn't even set, so set it.
|
if i == "" then -- it wasn't even set, so set it.
|
||||||
@ -751,21 +748,22 @@ function signs_lib.receive_fields(pos, formname, fields, sender)
|
|||||||
signs_lib.update_sign(pos, fields)
|
signs_lib.update_sign(pos, fields)
|
||||||
elseif fields.on or fields.off then
|
elseif fields.on or fields.off then
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local newname
|
local meta = minetest.get_meta(pos)
|
||||||
|
local change
|
||||||
|
|
||||||
if fields.on and string.find(node.name, "widefont") then
|
if fields.on and meta:get_int("widefont") == 1 then
|
||||||
newname = string.gsub(node.name, "_widefont", "")
|
meta:set_int("widefont", 0)
|
||||||
elseif fields.off and not string.find(node.name, "widefont") then
|
change = true
|
||||||
newname = make_widefont_nodename(node.name)
|
elseif fields.off and meta:get_int("widefont") == 0 then
|
||||||
|
meta:set_int("widefont", 1)
|
||||||
|
change = true
|
||||||
end
|
end
|
||||||
if newname then
|
if change then
|
||||||
minetest.log("action", S("@1 flipped the wide-font switch to \"@2\" at @3",
|
minetest.log("action", S("@1 flipped the wide-font switch to \"@2\" at @3",
|
||||||
(sender:get_player_name() or ""),
|
(sender:get_player_name() or ""),
|
||||||
(fields.on and "off" or "on"),
|
(fields.on and "off" or "on"),
|
||||||
minetest.pos_to_string(pos)
|
minetest.pos_to_string(pos)
|
||||||
))
|
))
|
||||||
|
|
||||||
minetest.swap_node(pos, {name = newname, param2 = node.param2})
|
|
||||||
signs_lib.construct_sign(pos)
|
signs_lib.construct_sign(pos)
|
||||||
signs_lib.update_sign(pos, fields)
|
signs_lib.update_sign(pos, fields)
|
||||||
end
|
end
|
||||||
@ -962,7 +960,53 @@ function signs_lib.register_fence_with_sign()
|
|||||||
minetest.log("warning", "[signs_lib] ".."Attempt to call no longer used function signs_lib.register_fence_with_sign()")
|
minetest.log("warning", "[signs_lib] ".."Attempt to call no longer used function signs_lib.register_fence_with_sign()")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function register_sign(name, rdef)
|
--[[
|
||||||
|
The main sign registration function
|
||||||
|
===================================
|
||||||
|
|
||||||
|
Example minimal recommended def for writable signs:
|
||||||
|
|
||||||
|
signs_lib.register_sign("foo:my_cool_sign", {
|
||||||
|
description = "Wooden cool sign",
|
||||||
|
inventory_image = "signs_lib_sign_cool_inv.png",
|
||||||
|
tiles = {
|
||||||
|
"signs_lib_sign_cool.png",
|
||||||
|
"signs_lib_sign_cool_edges.png"
|
||||||
|
},
|
||||||
|
number_of_lines = 2,
|
||||||
|
horiz_scaling = 0.8,
|
||||||
|
vert_scaling = 1,
|
||||||
|
line_spacing = 9,
|
||||||
|
font_size = 31,
|
||||||
|
x_offset = 7,
|
||||||
|
y_offset = 4,
|
||||||
|
chars_per_line = 40,
|
||||||
|
entity_info = "standard"
|
||||||
|
})
|
||||||
|
|
||||||
|
* default def assumes a wallmounted sign with on-pole being allowed.
|
||||||
|
|
||||||
|
*For signs that can support being on a pole, include in the def:
|
||||||
|
allow_onpole = true,
|
||||||
|
(defaults to disabled)
|
||||||
|
|
||||||
|
*For signs that can support being on a horizontal pole, include in the def:
|
||||||
|
allow_onpole_horizontal = true,
|
||||||
|
(defaults to disabled)
|
||||||
|
|
||||||
|
* onpole/onpole_horizontal are independent; one may be allowed without the other
|
||||||
|
|
||||||
|
* "standard" entity info implies the standard wood/steel sign model, in
|
||||||
|
wallmounted mode. For facedir signs using the standard model, use:
|
||||||
|
|
||||||
|
entity_info = {
|
||||||
|
mesh = "signs_lib_standard_wall_sign_entity.obj",
|
||||||
|
yaw = signs_lib.standard_yaw
|
||||||
|
},
|
||||||
|
|
||||||
|
]]--
|
||||||
|
|
||||||
|
function signs_lib.register_sign(name, rdef)
|
||||||
local def = table.copy(rdef)
|
local def = table.copy(rdef)
|
||||||
|
|
||||||
if rdef.entity_info == "standard" then
|
if rdef.entity_info == "standard" then
|
||||||
@ -1100,64 +1144,9 @@ local function register_sign(name, rdef)
|
|||||||
minetest.register_node(":"..name.."_hanging", hdef)
|
minetest.register_node(":"..name.."_hanging", hdef)
|
||||||
table.insert(signs_lib.lbm_restore_nodes, name.."_hanging")
|
table.insert(signs_lib.lbm_restore_nodes, name.."_hanging")
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
The main sign registration function
|
|
||||||
===================================
|
|
||||||
|
|
||||||
Example minimal recommended def for writable signs:
|
|
||||||
|
|
||||||
signs_lib.register_sign("foo:my_cool_sign", {
|
|
||||||
description = "Wooden cool sign",
|
|
||||||
inventory_image = "signs_lib_sign_cool_inv.png",
|
|
||||||
tiles = {
|
|
||||||
"signs_lib_sign_cool.png",
|
|
||||||
"signs_lib_sign_cool_edges.png"
|
|
||||||
},
|
|
||||||
number_of_lines = 2,
|
|
||||||
horiz_scaling = 0.8,
|
|
||||||
vert_scaling = 1,
|
|
||||||
line_spacing = 9,
|
|
||||||
font_size = 31,
|
|
||||||
x_offset = 7,
|
|
||||||
y_offset = 4,
|
|
||||||
chars_per_line = 40,
|
|
||||||
entity_info = "standard"
|
|
||||||
})
|
|
||||||
|
|
||||||
* default def assumes a wallmounted sign with on-pole being allowed.
|
|
||||||
|
|
||||||
*For signs that can support being on a pole, include in the def:
|
|
||||||
allow_onpole = true,
|
|
||||||
(defaults to disabled)
|
|
||||||
|
|
||||||
*For signs that can support being on a horizontal pole, include in the def:
|
|
||||||
allow_onpole_horizontal = true,
|
|
||||||
(defaults to disabled)
|
|
||||||
|
|
||||||
* onpole/onpole_horizontal are independent; one may be allowed without the other
|
|
||||||
|
|
||||||
* "standard" entity info implies the standard wood/steel sign model, in
|
|
||||||
wallmounted mode. For facedir signs using the standard model, use:
|
|
||||||
|
|
||||||
entity_info = {
|
|
||||||
mesh = "signs_lib_standard_wall_sign_entity.obj",
|
|
||||||
yaw = signs_lib.standard_yaw
|
|
||||||
},
|
|
||||||
|
|
||||||
]]--
|
|
||||||
|
|
||||||
function signs_lib.register_sign(name, rdef)
|
|
||||||
register_sign(name, rdef)
|
|
||||||
|
|
||||||
if rdef.allow_widefont then
|
if rdef.allow_widefont then
|
||||||
|
table.insert(signs_lib.old_widefont_signs, name.."_widefont")
|
||||||
local wdef = table.copy(minetest.registered_items[name])
|
|
||||||
wdef.groups.not_in_creative_inventory = 1
|
|
||||||
wdef.horiz_scaling = wdef.horiz_scaling / 2
|
|
||||||
|
|
||||||
register_sign(name.."_widefont", wdef)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1207,8 +1196,22 @@ minetest.register_lbm({
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
signs_lib.block_list = {}
|
-- Convert widefont sign nodes to use one base node with meta flag to select wide mode
|
||||||
signs_lib.totalblocks = 0
|
|
||||||
|
minetest.register_lbm({
|
||||||
|
nodenames = signs_lib.old_widefont_signs,
|
||||||
|
name = "signs_lib:convert_widefont_signs",
|
||||||
|
label = "Convert widefont sign nodes",
|
||||||
|
run_at_every_load = false,
|
||||||
|
action = function(pos, node)
|
||||||
|
local basename = string.gsub(node.name, "_widefont", "")
|
||||||
|
minetest.swap_node(pos, {name = basename, param2 = node.param2})
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_int("widefont", 1)
|
||||||
|
signs_lib.delete_objects(pos)
|
||||||
|
signs_lib.update_sign(pos)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
-- Maintain a list of currently-loaded blocks
|
-- Maintain a list of currently-loaded blocks
|
||||||
minetest.register_lbm({
|
minetest.register_lbm({
|
||||||
|
Loading…
Reference in New Issue
Block a user