mirror of
https://github.com/pyrollo/display_modpack.git
synced 2025-01-24 15:40:17 +01:00
Rework all nodes displaying text according to new font_api
This commit is contained in:
parent
825557ff31
commit
80b616ab97
16
font.lua
16
font.lua
@ -17,11 +17,6 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
|
||||||
--[[
|
|
||||||
Margins, spacings, can be negative numbers
|
|
||||||
]]--
|
|
||||||
|
|
||||||
-- Local functions
|
-- Local functions
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
@ -146,10 +141,10 @@ function font_api.Font:get_height(nb_of_lines)
|
|||||||
return
|
return
|
||||||
(
|
(
|
||||||
(self.height or 0) +
|
(self.height or 0) +
|
||||||
(self.margin_top or 0) +
|
(self.margintop or 0) +
|
||||||
(self.margin_bottom or 0)
|
(self.marginbottom or 0)
|
||||||
) * nb_of_lines +
|
) * nb_of_lines +
|
||||||
(self.line_spacing or 0) * (nb_of_lines -1)
|
(self.linespacing or 0) * (nb_of_lines -1)
|
||||||
else
|
else
|
||||||
return nb_of_lines == 0 and 0 or nil
|
return nb_of_lines == 0 and 0 or nil
|
||||||
end
|
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
|
-- Replace chars with no texture by the NULL(0) char
|
||||||
if self.widths[char] == nil
|
if self.widths[char] == nil
|
||||||
|
or char == 88
|
||||||
then
|
then
|
||||||
print(string.format("["..font_api.name
|
print(string.format("["..font_api.name
|
||||||
.."] Missing char %d (%04x)",char,char))
|
.."] 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
|
y = (textureh - textheight) / 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
y = y + (self.margintop or 0)
|
||||||
|
|
||||||
for _, line in pairs(lines) do
|
for _, line in pairs(lines) do
|
||||||
if halign == "left" then
|
if halign == "left" then
|
||||||
@ -259,7 +257,7 @@ function font_api.Font:make_text_texture(text, texturew, textureh, maxlines,
|
|||||||
(texturew - line.width) / 2, y)
|
(texturew - line.width) / 2, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
y = y + self:get_height() + (self.line_spacing or 0)
|
y = y + self:get_height() + (self.linespacing or 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
texture = string.format("[combine:%dx%d", texturew, textureh)..texture
|
texture = string.format("[combine:%dx%d", texturew, textureh)..texture
|
||||||
|
12
init.lua
12
init.lua
@ -45,10 +45,14 @@ function font_api.on_display_update(pos, objref)
|
|||||||
if entity and ndef.display_entities[entity.name] then
|
if entity and ndef.display_entities[entity.name] then
|
||||||
local def = ndef.display_entities[entity.name]
|
local def = ndef.display_entities[entity.name]
|
||||||
local font = font_api.get_font(meta:get_string("font") or def.font_name)
|
local font = font_api.get_font(meta:get_string("font") or def.font_name)
|
||||||
objref:set_properties({
|
|
||||||
textures={font:make_text_texture(text,
|
local maxlines = def.maxlines or 1 -- TODO:How to do w/o maxlines ?
|
||||||
def.size.x * def.resolution.x * font.height,
|
|
||||||
def.size.y * def.resolution.y * font.height,
|
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)},
|
def.maxlines, def.halign, def.valign, def.color)},
|
||||||
visual_size = def.size
|
visual_size = def.size
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user