summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2015-02-12 18:46:05 +0100
committerWuzzy <almikes@aol.com>2015-02-12 18:46:05 +0100
commit377f194884958aebd9b1495cb93e76446330b1e8 (patch)
tree7e896238a06d55921ef1991b4362cfdf35acca88
parent98bc7a0bb514e21b6214088c8a64a878b75e407d (diff)
Move start_hidden to init_hudbar, rename start_hidden in register function to default_start_hidden
-rw-r--r--API.md7
-rw-r--r--init.lua14
2 files changed, 13 insertions, 8 deletions
diff --git a/API.md b/API.md
index 9e68ab1..1bf8ff8 100644
--- a/API.md
+++ b/API.md
@@ -49,7 +49,7 @@ a vertical gradient.
### Icon
A 16×16 image shown left of the HUD bar. This is optional.
-### `hb.register_hudbar(identifier, text_color, label, textures, default_start_value, default_start_max, start_hidden, format_string)`
+### `hb.register_hudbar(identifier, text_color, label, textures, default_start_value, default_start_max, default_start_hidden, format_string)`
This function registers a new custom HUD bar definition to the HUD bars mod, so it can be later used to be displayed, changed, hidden
and unhidden on a per-player basis.
Note this does not yet display the HUD bar.
@@ -67,7 +67,7 @@ manually in a reliable way.
* `icon`: The file name of the icon, as string. This field can be `nil`, in which case no icon will be used.
* `default_start_value`: If this HUD bar is added to a player, and no initial value is specified, this value will be used as initial current value
* `default_max_value`: If this HUD bar is added to a player, and no initial maximum value is specified, this value will be used as initial maximum value
-* `start_hidden`: The HUD bar will be initially start hidden when added to a player. Use `hb.unhide_hudbar` to unhide it.
+* `default_start_hidden`: The HUD bar will be initially start hidden by default when added to a player. Use `hb.unhide_hudbar` to unhide it.
* `format_string`: This is optional; You can specify an alternative format string display the final text on the HUD bar. The default format string is “`%s: %d/%d`” (in this order: Label, current value, maximum value). See also the Lua documentation of `string.format`.
#### Return value
@@ -80,7 +80,7 @@ explicitly initialized on a per-player basis.
You probably want to do this in the `minetest.register_on_joinplayer`.
-### `hb.init_hudbar(player, identifier, start_value, start_max)`
+### `hb.init_hudbar(player, identifier, start_value, start_max, start_hidden)`
This function initialzes and activates a previously registered HUD bar and assigns it to a
certain client/player. This has only to be done once per player and after that, you can change
the values using `hb.change_hudbar`.
@@ -94,6 +94,7 @@ the HUD bar will be initially be shown to the player.
* `identifier`: The identifier of the HUD bar type, as specified in `hb.register_hudbar`.
* `start_value`: The initial current value of the HUD bar. This is optional, `default_start_value` of the registration function will be used, if this is `nil`.
* `start_max`: The initial maximum value of the HUD bar. This is optional, `default_start_max` of the registration function will be used, if this is `nil`
+* `start_hidden`: Whether the HUD bar is initially hidden. This is optional, `default_start_hidden` of the registration function will be used as default
#### Return value
Always `nil`.
diff --git a/init.lua b/init.lua
index 06681dc..97b7cce 100644
--- a/init.lua
+++ b/init.lua
@@ -31,7 +31,7 @@ function hb.get_hudtable(identifier)
return hb.hudtables[identifier]
end
-function hb.register_hudbar(identifier, text_color, label, textures, default_start_value, default_start_max, start_hidden, format_string)
+function hb.register_hudbar(identifier, text_color, label, textures, default_start_value, default_start_max, default_start_hidden, format_string)
local hudtable = {}
local pos, offset
if hb.hudbars_count % 2 == 0 then
@@ -51,9 +51,10 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
format_string = "%s: %d/%d"
end
- hudtable.add_all = function(player, start_value, start_max)
+ hudtable.add_all = function(player, start_value, start_max, start_hidden)
if start_value == nil then start_value = default_start_value end
if start_max == nil then start_max = default_start_max end
+ if start_hidden == nil then start_hidden = default_start_hidden end
local ids = {}
local state = {}
local name = player:get_player_name()
@@ -142,8 +143,8 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
hb.hudtables[identifier] = hudtable
end
-function hb.init_hudbar(player, identifier, start_value, start_max)
- hb.hudtables[identifier].add_all(player, start_value, start_max)
+function hb.init_hudbar(player, identifier, start_value, start_max, start_hidden)
+ hb.hudtables[identifier].add_all(player, start_value, start_max, start_hidden)
end
function hb.change_hudbar(player, identifier, new_value, new_max_value)
@@ -276,7 +277,10 @@ end
local function custom_hud(player)
if minetest.setting_getbool("enable_damage") then
hb.init_hudbar(player, "health", player:get_hp())
- hb.init_hudbar(player, "breath", math.min(player:get_breath(), 10))
+ local breath = player:get_breath()
+ local hide_breath
+ if breath == 11 then hide_breath = true else hide_breath = false end
+ hb.init_hudbar(player, "breath", math.min(breath, 10), nil, hide_breath)
end
end