mirror of
https://repo.or.cz/minetest_hudbars.git
synced 2024-08-20 21:24:05 +02: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()
|
return player ~= nil and player:is_player()
|
||||||
end
|
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 = {}
|
local params = {}
|
||||||
for c=1, #format_string_config do
|
local order = format_string_config.order
|
||||||
if format_string_config[c] == "label" then
|
for o=1, #order do
|
||||||
|
if order[o] == "label" then
|
||||||
table.insert(params, label)
|
table.insert(params, label)
|
||||||
elseif format_string_config[c] == "value" then
|
elseif order[o] == "value" then
|
||||||
table.insert(params, start_value)
|
table.insert(params, start_value)
|
||||||
elseif format_string_config[c] == "max_value" then
|
elseif order[o] == "max_value" then
|
||||||
table.insert(params, max_value)
|
table.insert(params, max_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local ret
|
local ret
|
||||||
if format_string_textdomain then
|
if format_string_config.textdomain then
|
||||||
ret = minetest.translate(format_string_textdomain, format_string, unpack(params))
|
ret = minetest.translate(format_string_config.textdomain, format_string, unpack(params))
|
||||||
else
|
else
|
||||||
ret = S(format_string, unpack(params))
|
ret = S(format_string, unpack(params))
|
||||||
end
|
end
|
||||||
@ -110,7 +111,7 @@ function hb.get_hudbar_position_index(identifier)
|
|||||||
end
|
end
|
||||||
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))
|
minetest.log("action", "hb.register_hudbar: "..tostring(identifier))
|
||||||
local hudtable = {}
|
local hudtable = {}
|
||||||
local pos, offset
|
local pos, offset
|
||||||
@ -147,7 +148,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
|||||||
format_string = N("@1: @2/@3")
|
format_string = N("@1: @2/@3")
|
||||||
end
|
end
|
||||||
if format_string_config == nil then
|
if format_string_config == nil then
|
||||||
format_string_config = { "label", "value", "max_value" }
|
format_string_config = { order = { "label", "value", "max_value" } }
|
||||||
end
|
end
|
||||||
|
|
||||||
hudtable.add_all = function(player, hudtable, start_value, start_max, start_hidden)
|
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 }
|
iconscale = { x=1, y=1 }
|
||||||
barnumber = hb.value_to_barlength(start_value, start_max)
|
barnumber = hb.value_to_barlength(start_value, start_max)
|
||||||
bgiconnumber = hb.settings.statbar_length
|
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
|
end
|
||||||
if hb.settings.bar_type == "progress_bar" then
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
ids.bg = player:hud_add({
|
ids.bg = player:hud_add({
|
||||||
@ -263,7 +264,6 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
|||||||
hudtable.identifier = identifier
|
hudtable.identifier = identifier
|
||||||
hudtable.format_string = format_string
|
hudtable.format_string = format_string
|
||||||
hudtable.format_string_config = format_string_config
|
hudtable.format_string_config = format_string_config
|
||||||
hudtable.format_string_textdomain = format_string_textdomain
|
|
||||||
hudtable.label = label
|
hudtable.label = label
|
||||||
hudtable.hudids = {}
|
hudtable.hudids = {}
|
||||||
hudtable.hudstate = {}
|
hudtable.hudstate = {}
|
||||||
@ -324,7 +324,7 @@ function hb.change_hudbar(player, identifier, new_value, new_max_value, new_icon
|
|||||||
end
|
end
|
||||||
if new_label ~= nil then
|
if new_label ~= nil then
|
||||||
hudtable.label = new_label
|
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)
|
player:hud_change(hudtable.hudids[name].text, "text", new_text)
|
||||||
end
|
end
|
||||||
if new_text_color ~= nil then
|
if new_text_color ~= nil then
|
||||||
@ -368,7 +368,7 @@ function hb.change_hudbar(player, identifier, new_value, new_max_value, new_icon
|
|||||||
end
|
end
|
||||||
|
|
||||||
if hb.settings.bar_type == "progress_bar" then
|
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
|
if new_text ~= hudtable.hudstate[name].text then
|
||||||
player:hud_change(hudtable.hudids[name].text, "text", new_text)
|
player:hud_change(hudtable.hudids[name].text, "text", new_text)
|
||||||
hudtable.hudstate[name].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
|
if hudtable.hudstate[name].max ~= 0 then
|
||||||
player:hud_change(hudtable.hudids[name].bg, "scale", {x=1,y=1})
|
player:hud_change(hudtable.hudids[name].bg, "scale", {x=1,y=1})
|
||||||
end
|
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
|
elseif hb.settings.bar_type == "statbar_modern" then
|
||||||
player:hud_change(hudtable.hudids[name].bg, "number", hb.settings.statbar_length)
|
player:hud_change(hudtable.hudids[name].bg, "number", hb.settings.statbar_length)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user