mods - hudbars : not hardcoded the hb.init_hudbar max values

* real fix for missing format_string_config.textdomain
  backpoted from c219b708f8
* fix the backguard compatibility for format_string_config.format_string
* add configuration settings for hp_max of player and breath_max
* do not hardcoded hp_max neither breath_max and honor customizations
* real fix of get_properties when join players
* set alternate honored max values before get_properties when join players
* increase default ticks of updates for hud bar, to avoid performance
  issues in low end devices
* optimize and fix texture image
stable-5.2
mckaygerhard 2023-07-17 01:18:14 -04:00
parent a3cc45174b
commit e9a6c74826
9 changed files with 38 additions and 33 deletions

View File

@ -28,7 +28,7 @@ For information check [../README.md](../README.md)
| fire | https://codeberg.org/minenux/minetest-mod-fire | https://codeberg.org/minenux/minetest-mod-fire/commit/4e5f7ad55314bd9b126fb133cfc5a32fa58b20d2 | [fire/README.md](fire/README.md) |
| fireflies | https://codeberg.org/minenux/minetest-game-minetest | https://codeberg.org/minenux/minetest-game-minetest/commit/fc4ab2538d432a20978ee3bbd1b69a42446e9132 | [fireflies/README.md](fireflies/README.md) |
| flowers | https://codeberg.org/minenux/minetest-game-minetest | https://codeberg.org/minenux/minetest-game-minetest/commit/eb64ff94f82d726e4a55b20fa7ce30e4a7470cc5 | |
| hudbars | https://codeberg.org/minenux/minetest-mod-hudbars | https://codeberg.org/minenux/minetest-mod-hudbars/commit/facc2cffb88f1a14ec36becf19f673506c5689aa | [hudbars/README.md](hudbars/README.md) |
| hudbars | https://codeberg.org/minenux/minetest-mod-hudbars | https://codeberg.org/minenux/minetest-mod-hudbars/commit/c219b708f89ccf8683c3ee33e1fe55641cc8b10a | [hudbars/README.md](hudbars/README.md) |
| give_initial_stuff | https://codeberg.org/minenux/minetest-game-minetest | https://codeberg.org/minenux/minetest-game-minetest/commit/ee86fb1c41e7d8d2a1d94764dd64808bc8ff5999 | [give_initial_stuff/README.md](give_initial_stuff/README.md) |
| killme | https://codeberg.org/minenux/minetest-game-minetest | https://codeberg.org/minenux/minetest-game-minetest/commit/eb64ff94f82d726e4a55b20fa7ce30e4a7470cc5 | |
| sfinv | https://codeberg.org/minenux/minetest-game-minetest | https://codeberg.org/minenux/minetest-game-minetest/commit/eb64ff94f82d726e4a55b20fa7ce30e4a7470cc5 | |

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

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
mods/hudbars/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)
@ -485,6 +483,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 +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)
@ -527,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
@ -560,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")
@ -576,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

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