mirror of
https://repo.or.cz/minetest_hudbars.git
synced 2024-11-23 23:53:54 +01:00
Hide bar background when max == 0
The bars are intended to show the ratio between value and max. For a max of 0 (which implies a value of 0), this implies a value/max ratio of 0/0, which is undefined. Therefore, for this very special case, we just hide the bar altogether.
This commit is contained in:
parent
017b304396
commit
e6e8f2d688
7
init.lua
7
init.lua
@ -142,6 +142,11 @@ function hud.change_hudbar(player, hudtable, new_value, new_max_value)
|
||||
hudtable.hudstate[name].value = new_value
|
||||
hudtable.hudstate[name].max = new_max_value
|
||||
if hudtable.hudstate[name].hidden == false then
|
||||
if hudtable.hudstate[name].max == 0 then
|
||||
player:hud_change(hudtable.hudids[name].bg, "scale", {x=0,y=0})
|
||||
else
|
||||
player:hud_change(hudtable.hudids[name].bg, "scale", {x=1,y=1})
|
||||
end
|
||||
player:hud_change(hudtable.hudids[name].bar, "number", hud.value_to_barlength(new_value, new_max_value))
|
||||
player:hud_change(hudtable.hudids[name].text, "text",
|
||||
tostring(string.format(hudtable.format_string, hudtable.label, new_value, new_max_value))
|
||||
@ -167,7 +172,9 @@ function hud.unhide_hudbar(player, hudtable)
|
||||
local value = hudtable.hudstate[name].value
|
||||
local max = hudtable.hudstate[name].max
|
||||
player:hud_change(hudtable.hudids[name].icon, "scale", {x=1,y=1})
|
||||
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].bar, "number", hud.value_to_barlength(value, max))
|
||||
player:hud_change(hudtable.hudids[name].text, "text", tostring(string.format(hudtable.format_string, hudtable.label, value, max)))
|
||||
hudtable.hudstate[name].hidden = false
|
||||
|
Loading…
Reference in New Issue
Block a user