Compare commits

...

5 Commits

Author SHA1 Message Date
mckaygerhard 0edeb5599e backguard compatibility of hp_max in older clients, (missing breath_max)
* honoring customizations of hp_max its not so valid in older
  clients becouse of a bug in older lients of hardcoded healt player
  at f7d50a8078
  long time ago user requested https://github.com/minetest/minetest/issues/2246
  the value was hardcoded into engine and do not allow to be
  customized by mods until the commit above, this patch
  takes that into consideration and set the value to 20.
* NOTE: as side effect if you started a server that support
  hp_max modification and try to connect using a older client,
  client will perfectly supports the already configured healt
  from client, but will start at 20 initialy, of course with
  max_hp supported over the value of 20
2023-07-18 23:07:28 -04:00
mckaygerhard c219b708f8 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
2023-07-17 00:35:34 -04:00
mckaygerhard 47615b8422 fix backgroun textures optimization for alpha transparency 2023-07-16 22:29:40 -04:00
mckaygerhard 3e73d3fa50 Merge branch 'nil_check_hudbar_state' of fluxionary for hudbar state checks
* another fix for https://codeberg.org/Wuzzy/minetest_hudbars/issues/4
  based on separate callbacks, when we have several mods that rely on
* this solves and close https://codeberg.org/Wuzzy/minetest_hudbars/issues/4
  but will need https://codeberg.org/Wuzzy/minetest_hudbars/pulls/7 also.
* this must be use in join with commit 20843d95ce
  of this repository that is a backport of my own fork at @mckaygerhard
2023-06-21 12:45:36 -04:00
flux 881564d441
get_hudbar_state: return nil if not initialized 2023-06-20 12:42:50 -07:00
8 changed files with 57 additions and 32 deletions

4
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`
@ -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,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
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")
@ -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 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 +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

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