backguard compatibility for 0.4.16+ engines and 5.2+ and beyond
* boilerplace the minetest translation and only use format when is available to translate it * uses Use MT native support for "background icons" only when available and if validmaster
parent
20843d95ce
commit
29c1a3c31c
|
@ -12,7 +12,7 @@ position should be displayed correctly on every screen size.
|
|||
|
||||
## Current version
|
||||
The current version is 2.3.4.
|
||||
It works for Minetest 5.3.0 or later.
|
||||
It works for Minetest 0.4.17+ (maybe 0.4.16 too) or later.
|
||||
|
||||
This software uses [semantic versioning](http://semver.org), as defined by version 2.0.0 of the SemVer
|
||||
standard.
|
||||
|
|
49
init.lua
49
init.lua
|
@ -1,4 +1,27 @@
|
|||
local S = minetest.get_translator("hudbars")
|
||||
|
||||
local S
|
||||
-- Intllib
|
||||
if minetest.get_translator ~= nil then
|
||||
S = minetest.get_translator("ethereal") -- 5.x translation function
|
||||
else
|
||||
if minetest.get_modpath("intllib") then
|
||||
dofile(minetest.get_modpath("intllib") .. "/init.lua")
|
||||
if intllib.make_gettext_pair then
|
||||
gettext, ngettext = intllib.make_gettext_pair() -- new gettext method
|
||||
else
|
||||
gettext = intllib.Getter() -- old text file method
|
||||
end
|
||||
S = gettext
|
||||
else -- boilerplate function
|
||||
S = function(str, ...)
|
||||
local args = {...}
|
||||
return str:gsub("@%d+", function(match)
|
||||
return args[tonumber(match:sub(2))]
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local N = function(s) return s end
|
||||
|
||||
hb = {}
|
||||
|
@ -58,13 +81,13 @@ local function make_label(format_string, format_string_config, label, start_valu
|
|||
if order[o] == "label" then
|
||||
table.insert(params, label)
|
||||
elseif order[o] == "value" then
|
||||
if format_string_config.format_value then
|
||||
if format_string_config.format_value and minetest.get_translator ~= nil then
|
||||
table.insert(params, string.format(format_string_config.format_value, start_value))
|
||||
else
|
||||
table.insert(params, start_value)
|
||||
end
|
||||
elseif order[o] == "max_value" then
|
||||
if format_string_config.format_max_value then
|
||||
if format_string_config.format_max_value and minetest.get_translator ~= nil then
|
||||
table.insert(params, string.format(format_string_config.format_max_value, max_value))
|
||||
else
|
||||
table.insert(params, max_value)
|
||||
|
@ -72,7 +95,7 @@ local function make_label(format_string, format_string_config, label, start_valu
|
|||
end
|
||||
end
|
||||
local ret
|
||||
if format_string_config.textdomain then
|
||||
if format_string_config.textdomain and minetest.get_translator ~= nil then
|
||||
ret = minetest.translate(format_string_config.textdomain, format_string, unpack(params))
|
||||
else
|
||||
ret = S(format_string, unpack(params))
|
||||
|
@ -213,6 +236,20 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
|||
z_index = 1,
|
||||
})
|
||||
end
|
||||
elseif hb.settings.bar_type == "statbar_modern" then
|
||||
if textures.bgicon ~= nil then
|
||||
ids.bg = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = pos,
|
||||
text = textures.bgicon,
|
||||
number = bgiconnumber,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = { x = offset.x, y = offset.y },
|
||||
direction = 0,
|
||||
size = {x=24, y=24},
|
||||
z_index = 0,
|
||||
})
|
||||
end
|
||||
end
|
||||
local bar_image, bgicon, bar_size
|
||||
if hb.settings.bar_type == "progress_bar" then
|
||||
|
@ -226,7 +263,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
|||
bar_size = nil
|
||||
elseif hb.settings.bar_type == "statbar_classic" or hb.settings.bar_type == "statbar_modern" then
|
||||
bar_image = textures.icon
|
||||
bgicon = textures.bgicon
|
||||
if textures.bgicon then bgicon = textures.bgicon end
|
||||
bar_size = {x=24, y=24}
|
||||
end
|
||||
ids.bar = player:hud_add({
|
||||
|
@ -411,6 +448,8 @@ function hb.hide_hudbar(player, identifier)
|
|||
end
|
||||
player:hud_change(hudtable.hudids[name].bg, "scale", {x=0,y=0})
|
||||
player:hud_change(hudtable.hudids[name].text, "text", "")
|
||||
elseif hb.settings.bar_type == "statbar_modern" then
|
||||
player:hud_change(hudtable.hudids[name].bg, "number", 0)
|
||||
end
|
||||
player:hud_change(hudtable.hudids[name].bar, "number", 0)
|
||||
player:hud_change(hudtable.hudids[name].bar, "item", 0)
|
||||
|
|
Loading…
Reference in New Issue