Add setting 'hudbars_autohide_stamina' to disable hiding stamina

This commit is contained in:
Jordan Irwin 2017-08-12 07:57:21 -07:00
parent fd5df30755
commit 192f73e71a
2 changed files with 10 additions and 3 deletions

@ -12,6 +12,7 @@ local starve = minetest.settings:get_bool("sprint_starve")
local starve_drain = tonumber(minetest.settings:get("sprint_starve_drain")) or 0.5 local starve_drain = tonumber(minetest.settings:get("sprint_starve_drain")) or 0.5
local breath = minetest.settings:get_bool("sprint_breath") local breath = minetest.settings:get_bool("sprint_breath")
local breath_drain = tonumber(minetest.settings:get("sprint_breath_drain")) or 1 local breath_drain = tonumber(minetest.settings:get("sprint_breath_drain")) or 1
local autohide = minetest.settings:get_bool("hudbars_autohide_stamina") ~= false
if dir ~= false then dir = true end if dir ~= false then dir = true end
if stamina ~= false then stamina = true end if stamina ~= false then stamina = true end
if starve ~= false then starve = true end if starve ~= false then starve = true end
@ -61,7 +62,7 @@ local function drain_stamina(player)
player:set_attribute("stamina", player_stamina - stamina_drain) player:set_attribute("stamina", player_stamina - stamina_drain)
end end
if hudbars then if hudbars then
if player_stamina < 20 then hb.unhide_hudbar(player, "stamina") end if autohide and player_stamina < 20 then hb.unhide_hudbar(player, "stamina") end
hb.change_hudbar(player, "stamina", player_stamina) hb.change_hudbar(player, "stamina", player_stamina)
end end
end end
@ -73,7 +74,7 @@ local function replenish_stamina(player)
end end
if hudbars then if hudbars then
hb.change_hudbar(player, "stamina", player_stamina) hb.change_hudbar(player, "stamina", player_stamina)
if player_stamina == 20 then hb.hide_hudbar(player, "stamina") end if autohide and player_stamina == 20 then hb.hide_hudbar(player, "stamina") end
end end
end end
@ -124,7 +125,9 @@ if minetest.get_modpath("hudbars") ~= nil and stamina then
player_stamina, player_stamina, player_stamina, player_stamina,
false, "%s: %.1f/%.1f") false, "%s: %.1f/%.1f")
hudbars = true hudbars = true
hb.hide_hudbar(player, "stamina") if autohide then
hb.hide_hudbar(player, "stamina")
end
end end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)

@ -33,3 +33,7 @@ sprint_breath (Breath) bool true
#The amount of air to drain while sprinting under water #The amount of air to drain while sprinting under water
sprint_breath_drain (Breath drain) float 1 sprint_breath_drain (Breath drain) float 1
#If enabled (default), the stamina indicators in the HUD will be automatically hidden shortly
#after stamina has filled up. Otherwise, stamina will always be displayed.
hudbars_autohide_stamina (Automatically hide staminal indicator) bool true