not hardcoded the hb.init_hudbar max values, real fix of get_properties when join players

* real fix for missing format_string_config.textdomain
  fixed https://codeberg.org/Wuzzy/minetest_hudbars/issues/8
* fix the backguard compatibility for format_string_config.format_string
  due commit 29c1a3c31c
* add configuration settings for hp_max of player and breath_max
  that really honors the configuration of customization of hp_max
* do not hardcoded hp_max neither breath_max and honor customizations
* real fix for commit 20843d95ce
  set alternate honored max values before get_properties when join players
  this finally fixed this is a merge of Wuzzy/minetest_hudbars#5
  and final fix for https://codeberg.org/Wuzzy/minetest_hudbars/issues/4
* increase default ticks of updates for hud bar, to avoid performance
  issues in low end devices
master
mckaygerhard 2023-07-17 00:35:34 -04:00
parent 47615b8422
commit c219b708f8
5 changed files with 35 additions and 31 deletions

2
API.md
View File

@ -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`

View File

@ -46,3 +46,7 @@ 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)

1
depends.txt Normal file
View File

@ -0,0 +1 @@
intllib?

View File

@ -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")
@ -81,13 +81,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 +95,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))
@ -185,10 +185,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)
@ -448,8 +448,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)
@ -507,8 +505,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)
@ -528,27 +526,22 @@ local function custom_hud(player)
hide = true
end
local hp = player:get_hp()
local hp_max = player:get_properties().hp_max
local hp_max = hb.settings.hp_player_maximun
hb.init_hudbar(player, "health", math.min(hp, hp_max), hp_max, hide)
local breath = player:get_breath()
local breath_max = player:get_properties().breath_max
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
hb.init_hudbar(player, "health", hp, hp_max, hide)
if hp_max then
hb.init_hudbar(player, "health", math.min(hp, hp_max), hp_max, hide)
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
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
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
@ -561,12 +554,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")
@ -577,6 +567,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

View File

@ -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