forked from mtcontrib/minetest_hudbars
Move start_hidden to init_hudbar, rename start_hidden in register function to default_start_hidden
This commit is contained in:
parent
98bc7a0bb5
commit
377f194884
7
API.md
7
API.md
@ -49,7 +49,7 @@ a vertical gradient.
|
|||||||
### Icon
|
### Icon
|
||||||
A 16×16 image shown left of the HUD bar. This is optional.
|
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
|
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.
|
and unhidden on a per-player basis.
|
||||||
Note this does not yet display the HUD bar.
|
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.
|
* `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_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
|
* `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`.
|
* `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
|
#### 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`.
|
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
|
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
|
certain client/player. This has only to be done once per player and after that, you can change
|
||||||
the values using `hb.change_hudbar`.
|
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`.
|
* `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_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_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
|
#### Return value
|
||||||
Always `nil`.
|
Always `nil`.
|
||||||
|
14
init.lua
14
init.lua
@ -31,7 +31,7 @@ function hb.get_hudtable(identifier)
|
|||||||
return hb.hudtables[identifier]
|
return hb.hudtables[identifier]
|
||||||
end
|
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 hudtable = {}
|
||||||
local pos, offset
|
local pos, offset
|
||||||
if hb.hudbars_count % 2 == 0 then
|
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"
|
format_string = "%s: %d/%d"
|
||||||
end
|
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_value == nil then start_value = default_start_value end
|
||||||
if start_max == nil then start_max = default_start_max 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 ids = {}
|
||||||
local state = {}
|
local state = {}
|
||||||
local name = player:get_player_name()
|
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
|
hb.hudtables[identifier] = hudtable
|
||||||
end
|
end
|
||||||
|
|
||||||
function hb.init_hudbar(player, identifier, 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)
|
hb.hudtables[identifier].add_all(player, start_value, start_max, start_hidden)
|
||||||
end
|
end
|
||||||
|
|
||||||
function hb.change_hudbar(player, identifier, new_value, new_max_value)
|
function hb.change_hudbar(player, identifier, new_value, new_max_value)
|
||||||
@ -276,7 +277,10 @@ end
|
|||||||
local function custom_hud(player)
|
local function custom_hud(player)
|
||||||
if minetest.setting_getbool("enable_damage") then
|
if minetest.setting_getbool("enable_damage") then
|
||||||
hb.init_hudbar(player, "health", player:get_hp())
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user