mirror of
https://repo.or.cz/minetest_hudbars.git
synced 2024-11-10 18:50:18 +01:00
Restructure format_string_config
This commit is contained in:
parent
915fab08e2
commit
afb0242b3b
28
init.lua
28
init.lua
|
@ -51,20 +51,21 @@ local function player_exists(player)
|
|||
return player ~= nil and player:is_player()
|
||||
end
|
||||
|
||||
local function make_label(format_string, format_string_config, format_string_textdomain, label, start_value, max_value)
|
||||
local function make_label(format_string, format_string_config, label, start_value, max_value)
|
||||
local params = {}
|
||||
for c=1, #format_string_config do
|
||||
if format_string_config[c] == "label" then
|
||||
local order = format_string_config.order
|
||||
for o=1, #order do
|
||||
if order[o] == "label" then
|
||||
table.insert(params, label)
|
||||
elseif format_string_config[c] == "value" then
|
||||
elseif order[o] == "value" then
|
||||
table.insert(params, start_value)
|
||||
elseif format_string_config[c] == "max_value" then
|
||||
elseif order[o] == "max_value" then
|
||||
table.insert(params, max_value)
|
||||
end
|
||||
end
|
||||
local ret
|
||||
if format_string_textdomain then
|
||||
ret = minetest.translate(format_string_textdomain, format_string, unpack(params))
|
||||
if format_string_config.textdomain then
|
||||
ret = minetest.translate(format_string_config.textdomain, format_string, unpack(params))
|
||||
else
|
||||
ret = S(format_string, unpack(params))
|
||||
end
|
||||
|
@ -110,7 +111,7 @@ function hb.get_hudbar_position_index(identifier)
|
|||
end
|
||||
end
|
||||
|
||||
function hb.register_hudbar(identifier, text_color, label, textures, default_start_value, default_start_max, default_start_hidden, format_string, format_string_config, format_string_textdomain)
|
||||
function hb.register_hudbar(identifier, text_color, label, textures, default_start_value, default_start_max, default_start_hidden, format_string, format_string_config)
|
||||
minetest.log("action", "hb.register_hudbar: "..tostring(identifier))
|
||||
local hudtable = {}
|
||||
local pos, offset
|
||||
|
@ -147,7 +148,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
|||
format_string = N("@1: @2/@3")
|
||||
end
|
||||
if format_string_config == nil then
|
||||
format_string_config = { "label", "value", "max_value" }
|
||||
format_string_config = { order = { "label", "value", "max_value" } }
|
||||
end
|
||||
|
||||
hudtable.add_all = function(player, hudtable, start_value, start_max, start_hidden)
|
||||
|
@ -172,7 +173,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
|||
iconscale = { x=1, y=1 }
|
||||
barnumber = hb.value_to_barlength(start_value, start_max)
|
||||
bgiconnumber = hb.settings.statbar_length
|
||||
text = make_label(format_string, format_string_config, format_string_textdomain, label, start_value, start_max)
|
||||
text = make_label(format_string, format_string_config, label, start_value, start_max)
|
||||
end
|
||||
if hb.settings.bar_type == "progress_bar" then
|
||||
ids.bg = player:hud_add({
|
||||
|
@ -263,7 +264,6 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
|||
hudtable.identifier = identifier
|
||||
hudtable.format_string = format_string
|
||||
hudtable.format_string_config = format_string_config
|
||||
hudtable.format_string_textdomain = format_string_textdomain
|
||||
hudtable.label = label
|
||||
hudtable.hudids = {}
|
||||
hudtable.hudstate = {}
|
||||
|
@ -324,7 +324,7 @@ function hb.change_hudbar(player, identifier, new_value, new_max_value, new_icon
|
|||
end
|
||||
if new_label ~= nil then
|
||||
hudtable.label = new_label
|
||||
local new_text = make_label(hudtable.format_string, hudtable.format_string_config, hudtable.format_string_textdomain, new_label, hudtable.hudstate[name].value, hudtable.hudstate[name].max)
|
||||
local new_text = make_label(hudtable.format_string, hudtable.format_string_config, new_label, hudtable.hudstate[name].value, hudtable.hudstate[name].max)
|
||||
player:hud_change(hudtable.hudids[name].text, "text", new_text)
|
||||
end
|
||||
if new_text_color ~= nil then
|
||||
|
@ -368,7 +368,7 @@ function hb.change_hudbar(player, identifier, new_value, new_max_value, new_icon
|
|||
end
|
||||
|
||||
if hb.settings.bar_type == "progress_bar" then
|
||||
local new_text = make_label(hudtable.format_string, hudtable.format_string_config, hudtable.format_string_textdomain, hudtable.label, new_value, new_max_value)
|
||||
local new_text = make_label(hudtable.format_string, hudtable.format_string_config, hudtable.label, new_value, new_max_value)
|
||||
if new_text ~= hudtable.hudstate[name].text then
|
||||
player:hud_change(hudtable.hudids[name].text, "text", new_text)
|
||||
hudtable.hudstate[name].text = new_text
|
||||
|
@ -412,7 +412,7 @@ function hb.unhide_hudbar(player, identifier)
|
|||
if hudtable.hudstate[name].max ~= 0 then
|
||||
player:hud_change(hudtable.hudids[name].bg, "scale", {x=1,y=1})
|
||||
end
|
||||
player:hud_change(hudtable.hudids[name].text, "text", make_label(hudtable.format_string, hudtable.format_string_config, hudtable.format_string_textdomain, hudtable.label, value, max))
|
||||
player:hud_change(hudtable.hudids[name].text, "text", make_label(hudtable.format_string, hudtable.format_string_config, hudtable.label, value, max))
|
||||
elseif hb.settings.bar_type == "statbar_modern" then
|
||||
player:hud_change(hudtable.hudids[name].bg, "number", hb.settings.statbar_length)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user