Compare commits
5 Commits
facc2cffb8
...
0edeb5599e
Author | SHA1 | Date | |
---|---|---|---|
0edeb5599e | |||
c219b708f8 | |||
47615b8422 | |||
3e73d3fa50 | |||
|
881564d441 |
4
API.md
4
API.md
@ -68,7 +68,7 @@ for more information.
|
||||
* `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`: Optional; You can specify an alternative format string to use for the final text on the HUD bar. The default format string is “`@1: @2/@3`” (The “@” numbers are placeholders that have a meaning in this order: @1 = Label, @2 = current value, @3 = maximum value). Do *not* use minetest.translator on this string, the string will be translated by `hudbars`, but you still must put this string into the translation catalogue file.
|
||||
* `format_string_config`: Required if `format_string` is set. This allows to change which parameters to use in the format string. It's a table with these fields:
|
||||
* `textdomain`: Text domain of the format string, used by `minetest.translate`
|
||||
* `textdomain`: Text domain of the format string, used by `minetest.translate` if missing or set to `nil` will use `minetest.get_translator`
|
||||
* `order`: Table that contains the order of the placeholders. It's also possible to remove placeholders. Default order: `{ "label", "value", "max_value" }`
|
||||
* `format_value`: Format string to apply when displaying `value`. Syntax is same as in `string.format`. Default: `"%d"`
|
||||
* `format_max_value`: Same as `format_value` but is applied to `max_value`
|
||||
@ -187,7 +187,7 @@ Makes a previously hidden HUD bar visible again to a player.
|
||||
It is also possible to read information about existing HUD bars.
|
||||
|
||||
### `hb.get_hudbar_state(player, identifier)`
|
||||
Returns the current state of the active player's HUD bar.
|
||||
Returns the current state of the active player's HUD bar. Will return `nil` if the hudbar is not initialized.
|
||||
|
||||
#### Parameters
|
||||
* `player`: `ObjectRef` of the player to which the HUD bar belongs to
|
||||
|
@ -46,3 +46,12 @@ else
|
||||
hb.settings.sorting = { ["health"] = 0, ["breath"] = 1 }
|
||||
hb.settings.sorting_reverse = { [0] = "health", [1] = "breath" }
|
||||
end
|
||||
|
||||
hb.settings.hp_player_maximun = hb.load_setting("hudbars_hp_player_maximun", "number", 20)
|
||||
hb.settings.br_player_maximun = hb.load_setting("hudbars_br_player_maximun", "number", 10)
|
||||
|
||||
if minetest.has_feature("object_use_texture_alpha") then
|
||||
core.PLAYER_MAX_HP_DEFAULT = hb.settings.hp_player_maximun
|
||||
else
|
||||
core.PLAYER_MAX_HP = hb.settings.hp_player_maximun
|
||||
end
|
||||
|
1
depends.txt
Normal file
1
depends.txt
Normal file
@ -0,0 +1 @@
|
||||
intllib?
|
63
init.lua
63
init.lua
@ -2,7 +2,7 @@
|
||||
local S
|
||||
-- Intllib
|
||||
if minetest.get_translator ~= nil then
|
||||
S = minetest.get_translator("ethereal") -- 5.x translation function
|
||||
S = minetest.get_translator("hudbars") -- 5.x translation function
|
||||
else
|
||||
if minetest.get_modpath("intllib") then
|
||||
dofile(minetest.get_modpath("intllib") .. "/init.lua")
|
||||
@ -74,6 +74,19 @@ local function player_exists(player)
|
||||
return player ~= nil and player:is_player()
|
||||
end
|
||||
|
||||
local function checksupportmax(player)
|
||||
local statusinfo = minetest.get_server_status()
|
||||
if string.find(statusinfo,"0.4.1") and not string.find(statusinfo,"0.4.18") and not string.find(statusinfo,"0.4.17.5") then
|
||||
hb.settings.hp_player_maximun = 20
|
||||
hb.settings.br_player_maximun = 10
|
||||
if player_exists(player) then
|
||||
player:set_properties({hp_max = 20})
|
||||
else
|
||||
minetest.log("error","[hudbars] WARNING! minetest version do not support customization of hp_max healt player values")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function make_label(format_string, format_string_config, label, start_value, max_value)
|
||||
local params = {}
|
||||
local order = format_string_config.order
|
||||
@ -81,13 +94,13 @@ local function make_label(format_string, format_string_config, label, start_valu
|
||||
if order[o] == "label" then
|
||||
table.insert(params, label)
|
||||
elseif order[o] == "value" then
|
||||
if format_string_config.format_value and minetest.get_translator ~= nil then
|
||||
if format_string_config.format_value then
|
||||
table.insert(params, string.format(format_string_config.format_value, start_value))
|
||||
else
|
||||
table.insert(params, start_value)
|
||||
end
|
||||
elseif order[o] == "max_value" then
|
||||
if format_string_config.format_max_value and minetest.get_translator ~= nil then
|
||||
if format_string_config.format_max_value then
|
||||
table.insert(params, string.format(format_string_config.format_max_value, max_value))
|
||||
else
|
||||
table.insert(params, max_value)
|
||||
@ -95,7 +108,7 @@ local function make_label(format_string, format_string_config, label, start_valu
|
||||
end
|
||||
end
|
||||
local ret
|
||||
if format_string_config.textdomain and minetest.get_translator ~= nil then
|
||||
if format_string_config.textdomain and minetest.translate ~= nil then
|
||||
ret = minetest.translate(format_string_config.textdomain, format_string, unpack(params))
|
||||
else
|
||||
ret = S(format_string, unpack(params))
|
||||
@ -143,6 +156,7 @@ function hb.get_hudbar_position_index(identifier)
|
||||
end
|
||||
|
||||
function hb.register_hudbar(identifier, text_color, label, textures, default_start_value, default_start_max, default_start_hidden, format_string, format_string_config)
|
||||
checksupportmax()
|
||||
minetest.log("action", "hb.register_hudbar: "..tostring(identifier))
|
||||
local hudtable = {}
|
||||
local pos, offset
|
||||
@ -185,10 +199,10 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
||||
format_string_config.order = { "label", "value", "max_value" }
|
||||
end
|
||||
if format_string_config.format_value == nil then
|
||||
format_string_config.format_value = "%d"
|
||||
format_string_config.format_value = "%02d"
|
||||
end
|
||||
if format_string_config.format_max_value == nil then
|
||||
format_string_config.format_max_value = "%d"
|
||||
format_string_config.format_max_value = "%02d"
|
||||
end
|
||||
|
||||
hudtable.add_all = function(player, hudtable, start_value, start_max, start_hidden)
|
||||
@ -331,6 +345,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
||||
end
|
||||
|
||||
function hb.init_hudbar(player, identifier, start_value, start_max, start_hidden)
|
||||
checksupportmax(player)
|
||||
if not player_exists(player) then return false end
|
||||
local hudtable = hb.get_hudtable(identifier)
|
||||
hb.hudtables[identifier].add_all(player, hudtable, start_value, start_max, start_hidden)
|
||||
@ -448,8 +463,6 @@ function hb.hide_hudbar(player, identifier)
|
||||
end
|
||||
player:hud_change(hudtable.hudids[name].bg, "scale", {x=0,y=0})
|
||||
player:hud_change(hudtable.hudids[name].text, "text", "")
|
||||
elseif hb.settings.bar_type == "statbar_modern" then
|
||||
player:hud_change(hudtable.hudids[name].bg, "number", 0)
|
||||
end
|
||||
player:hud_change(hudtable.hudids[name].bar, "number", 0)
|
||||
player:hud_change(hudtable.hudids[name].bar, "item", 0)
|
||||
@ -485,6 +498,7 @@ end
|
||||
function hb.get_hudbar_state(player, identifier)
|
||||
if not player_exists(player) then return nil end
|
||||
local ref = hb.get_hudtable(identifier).hudstate[player:get_player_name()]
|
||||
if not ref then return nil end
|
||||
-- Do not forget to update this chunk of code in case the state changes
|
||||
local copy = {
|
||||
hidden = ref.hidden,
|
||||
@ -506,8 +520,8 @@ end
|
||||
|
||||
--register built-in HUD bars
|
||||
if minetest.settings:get_bool("enable_damage") or hb.settings.forceload_default_hudbars then
|
||||
hb.register_hudbar("health", 0xFFFFFF, S("Health"), { bar = "hudbars_bar_health.png", icon = "hudbars_icon_health.png", bgicon = "hudbars_bgicon_health.png" }, 20, 20, false)
|
||||
hb.register_hudbar("breath", 0xFFFFFF, S("Breath"), { bar = "hudbars_bar_breath.png", icon = "hudbars_icon_breath.png", bgicon = "hudbars_bgicon_breath.png" }, 10, 10, true)
|
||||
hb.register_hudbar("health", 0xFFFFFF, S("Health"), { bar = "hudbars_bar_health.png", icon = "hudbars_icon_health.png", bgicon = "hudbars_bgicon_health.png" }, hb.settings.hp_player_maximun, hb.settings.hp_player_maximun, false)
|
||||
hb.register_hudbar("breath", 0xFFFFFF, S("Breath"), { bar = "hudbars_bar_breath.png", icon = "hudbars_icon_breath.png", bgicon = "hudbars_bgicon_breath.png" }, hb.settings.br_player_maximun, hb.settings.br_player_maximun, true)
|
||||
end
|
||||
|
||||
local function hide_builtin(player)
|
||||
@ -527,27 +541,22 @@ local function custom_hud(player)
|
||||
hide = true
|
||||
end
|
||||
local hp = player:get_hp()
|
||||
local hp_max = player:get_properties().hp_max
|
||||
local breath = player:get_breath()
|
||||
local breath_max = player:get_properties().breath_max
|
||||
local hide_breath
|
||||
-- workaround bug https://github.com/minetest/minetest/issues/12350
|
||||
hb.init_hudbar(player, "health", hp, hp_max, hide)
|
||||
if hp_max then
|
||||
local hp_max = hb.settings.hp_player_maximun
|
||||
hb.init_hudbar(player, "health", math.min(hp, hp_max), hp_max, hide)
|
||||
end
|
||||
local breath = player:get_breath()
|
||||
local breath_max = hb.settings.br_player_maximun
|
||||
local hide_breath
|
||||
-- real honoring to configuration of max hp custom heal and breath
|
||||
if player:get_properties().hp_max then player:set_properties({hp_max = hb.settings.hp_player_maximun}) end
|
||||
if player:get_properties().breath_max then player:set_properties({breath_max = hb.settings.br_player_maximun}) end
|
||||
-- workaround bug https://github.com/minetest/minetest/issues/12350
|
||||
if breath == 11 and hb.settings.autohide_breath == true then hide_breath = true else hide_breath = false end
|
||||
hb.init_hudbar(player, "breath", math.min(breath, 10), breath_max, hide_breath or hide)
|
||||
if breath_max then
|
||||
if breath >= breath_max and hb.settings.autohide_breath == true then hide_breath = true else hide_breath = false end
|
||||
hb.init_hudbar(player, "breath", math.min(breath, breath_max), breath_max, hide_breath or hide)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function update_health(player)
|
||||
local hp_max = player:get_properties().hp_max
|
||||
local hp_max = hb.settings.hp_player_maximun
|
||||
local hp = math.min(player:get_hp(), hp_max)
|
||||
hb.change_hudbar(player, "health", hp, hp_max)
|
||||
end
|
||||
@ -560,12 +569,9 @@ local function update_hud(player)
|
||||
hb.unhide_hudbar(player, "health")
|
||||
end
|
||||
--air
|
||||
local breath_max = 10
|
||||
local breath = player:get_breath()
|
||||
local breath_max = player:get_properties().breath_max or hb.settings.br_player_maximun
|
||||
-- workaround bug https://github.com/minetest/minetest/issues/12350
|
||||
if player:get_properties() then
|
||||
if player:get_properties().breath_max then breath_max = player:get_properties().breath_max end
|
||||
end
|
||||
local breath = player:get_breath()
|
||||
|
||||
if breath >= breath_max and hb.settings.autohide_breath == true then
|
||||
hb.hide_hudbar(player, "breath")
|
||||
@ -576,6 +582,7 @@ local function update_hud(player)
|
||||
--health
|
||||
update_health(player)
|
||||
elseif hb.settings.forceload_default_hudbars then
|
||||
update_health(player)
|
||||
hb.hide_hudbar(player, "health")
|
||||
hb.hide_hudbar(player, "breath")
|
||||
end
|
||||
|
@ -116,4 +116,12 @@ hudbars_vmargin (Vertical distance between HUD bars) int 24 0
|
||||
# The of seconds which need to pass before the server updates the default HUD bars
|
||||
# (health and breath). Increase this number if you have a slow server or a slow network
|
||||
# connection and experience performance problems.
|
||||
hudbars_tick (Default HUD bars update interval) float 0.1 0.0 4.0
|
||||
hudbars_tick (Default HUD bars update interval) float 0.3 0.0 4.0
|
||||
|
||||
[player values defaults]
|
||||
# set a default value for max hp healt of player, if you customized and need on older engines
|
||||
hudbars_hp_player_maximun (maximun value of heal of player) int 20
|
||||
# set a default value for max breath of player, if you customized and need on older engines
|
||||
hudbars_br_player_maximun (maximun value of braeth of player) int 10
|
||||
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 96 B After Width: | Height: | Size: 80 B |
Binary file not shown.
Before Width: | Height: | Size: 83 B After Width: | Height: | Size: 80 B |
Binary file not shown.
Before Width: | Height: | Size: 586 B After Width: | Height: | Size: 302 B |
Loading…
x
Reference in New Issue
Block a user