diff options
author | Wuzzy <almikes@aol.com> | 2015-02-04 21:28:20 +0100 |
---|---|---|
committer | Wuzzy <almikes@aol.com> | 2015-02-04 21:28:20 +0100 |
commit | e6e8f2d6882e106d48123d7f23651b3faeed84fd (patch) | |
tree | 2b25cfcbf93201246dccf5cbf6796a89416aa85e | |
parent | 017b304396e139b85105c4133e99c9cadd6d8b41 (diff) |
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.
-rw-r--r-- | init.lua | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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}) - player:hud_change(hudtable.hudids[name].bg, "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 |