Merge git://repo.or.cz/minetest_hudbars into develop
commit
2935fc4364
19
API.md
19
API.md
|
@ -1,4 +1,4 @@
|
||||||
API documentation for the HUD bars mod 1.5.1
|
API documentation for the HUD bars mod 1.7.0
|
||||||
============================================
|
============================================
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
@ -95,8 +95,7 @@ the HUD bar will be initially be shown to the player.
|
||||||
* `start_hidden`: Whether the HUD bar is initially hidden. This is optional, `default_start_hidden` of the registration function will be used as default
|
* `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`.
|
`true` on success, `false` otherwise.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Modifying a HUD bar
|
## Modifying a HUD bar
|
||||||
|
@ -135,7 +134,7 @@ such network optimization for the “styling” parameters, so keep this in mind
|
||||||
* `new_text_color`: A 3-octet number defining the new color of the text.
|
* `new_text_color`: A 3-octet number defining the new color of the text.
|
||||||
|
|
||||||
#### Return value
|
#### Return value
|
||||||
Always `nil`.
|
`true` on success, `false` otherwise.
|
||||||
|
|
||||||
|
|
||||||
## Hiding and unhiding a HUD bar
|
## Hiding and unhiding a HUD bar
|
||||||
|
@ -156,7 +155,7 @@ Hides the specified HUD bar from the screen of the specified player.
|
||||||
* `identifier`: The identifier of the HUD bar type to hide, as specified in `hb.register_hudbar`.
|
* `identifier`: The identifier of the HUD bar type to hide, as specified in `hb.register_hudbar`.
|
||||||
|
|
||||||
#### Return value
|
#### Return value
|
||||||
Always `nil`.
|
`true` on success, `false` otherwise.
|
||||||
|
|
||||||
|
|
||||||
### `hb.unhide_hudbar(player, identifier)`
|
### `hb.unhide_hudbar(player, identifier)`
|
||||||
|
@ -167,7 +166,7 @@ Makes a previously hidden HUD bar visible again to a player.
|
||||||
* `identifier`: The identifier of the HUD bar type to unhide, as specified in `hb.register_hudbar`.
|
* `identifier`: The identifier of the HUD bar type to unhide, as specified in `hb.register_hudbar`.
|
||||||
|
|
||||||
#### Return value
|
#### Return value
|
||||||
Always `nil`.
|
`true` on success, `false` otherwise.
|
||||||
|
|
||||||
|
|
||||||
## Reading HUD bar information
|
## Reading HUD bar information
|
||||||
|
@ -181,12 +180,14 @@ Returns the current state of the active player's HUD bar.
|
||||||
* `identifier`: The identifier of the HUD bar type to hide, as specified in `hb.register_hudbar`.
|
* `identifier`: The identifier of the HUD bar type to hide, as specified in `hb.register_hudbar`.
|
||||||
|
|
||||||
#### Return value
|
#### Return value
|
||||||
A table which holds information on the current state of the HUD bar. Note the table is a deep
|
On success, returns a table which holds information on the current state of the HUD bar. Note
|
||||||
copy of the internal HUD bar state, it is *not* a reference; the information hold by the table is
|
the table is a deep copy of the internal HUD bar state, it is *not* a reference; the information
|
||||||
only true for the moment you called this function. The fields of this table are:
|
hold by the table is only true for the moment you called this function. The fields of this table are:
|
||||||
|
|
||||||
* `value`: Current value of HUD bar.
|
* `value`: Current value of HUD bar.
|
||||||
* `max`: Current maximum value of HUD bar.
|
* `max`: Current maximum value of HUD bar.
|
||||||
* `hidden`: Boolean denoting whether the HUD bar is hidden.
|
* `hidden`: Boolean denoting whether the HUD bar is hidden.
|
||||||
* `barlength`: The length of the HUD bar in pixels. This field is meaningless if the HUD bar is currently hidden.
|
* `barlength`: The length of the HUD bar in pixels. This field is meaningless if the HUD bar is currently hidden.
|
||||||
* `text`: The text shown on the HUD bar. This fiels is meaningless if the HUD bar is currently hidden.
|
* `text`: The text shown on the HUD bar. This fiels is meaningless if the HUD bar is currently hidden.
|
||||||
|
|
||||||
|
If the player does not exist, returns `nil` instead.
|
||||||
|
|
|
@ -11,7 +11,7 @@ this mod will place them accordingly.
|
||||||
position should be displayed correctly on every screen size.
|
position should be displayed correctly on every screen size.
|
||||||
|
|
||||||
## Current version
|
## Current version
|
||||||
The current version is 1.5.1.
|
The current version is 1.7.0.
|
||||||
|
|
||||||
This software uses [semantic versioning](http://semver.org), as defined by version 2.0.0 of the SemVer
|
This software uses [semantic versioning](http://semver.org), as defined by version 2.0.0 of the SemVer
|
||||||
standard.
|
standard.
|
||||||
|
@ -31,6 +31,7 @@ Author: Wuzzy (2015)
|
||||||
Also: This mod was forked from the “Better HUD” [hud] mod by BlockMen.
|
Also: This mod was forked from the “Better HUD” [hud] mod by BlockMen.
|
||||||
|
|
||||||
Translations:
|
Translations:
|
||||||
|
|
||||||
* German: Wuzzy
|
* German: Wuzzy
|
||||||
* Portuguese: BrunoMine
|
* Portuguese: BrunoMine
|
||||||
|
|
||||||
|
|
59
init.lua
59
init.lua
|
@ -61,11 +61,18 @@ hb.settings.pos_left.x = hb.load_setting("hudbars_pos_left_x", "number", 0.5)
|
||||||
hb.settings.pos_left.y = hb.load_setting("hudbars_pos_left_y", "number", 1)
|
hb.settings.pos_left.y = hb.load_setting("hudbars_pos_left_y", "number", 1)
|
||||||
hb.settings.pos_right.x = hb.load_setting("hudbars_pos_right_x", "number", 0.5)
|
hb.settings.pos_right.x = hb.load_setting("hudbars_pos_right_x", "number", 0.5)
|
||||||
hb.settings.pos_right.y = hb.load_setting("hudbars_pos_right_y", "number", 1)
|
hb.settings.pos_right.y = hb.load_setting("hudbars_pos_right_y", "number", 1)
|
||||||
hb.settings.start_offset_left.x = hb.load_setting("hudbars_start_offset_left_x", "number", -175)
|
hb.settings.bar_type = hb.load_setting("hudbars_bar_type", "string", "progress_bar", {"progress_bar", "statbar_classic", "statbar_modern"})
|
||||||
hb.settings.start_offset_left.y = hb.load_setting("hudbars_start_offset_left_y", "number", -86)
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
hb.settings.start_offset_right.x = hb.load_setting("hudbars_start_offset_right_x", "number", 15)
|
hb.settings.start_offset_left.x = hb.load_setting("hudbars_start_offset_left_x", "number", -175)
|
||||||
hb.settings.start_offset_right.y = hb.load_setting("hudbars_start_offset_right_y", "number", -86)
|
hb.settings.start_offset_left.y = hb.load_setting("hudbars_start_offset_left_y", "number", -86)
|
||||||
|
hb.settings.start_offset_right.x = hb.load_setting("hudbars_start_offset_right_x", "number", 15)
|
||||||
|
hb.settings.start_offset_right.y = hb.load_setting("hudbars_start_offset_right_y", "number", -86)
|
||||||
|
else
|
||||||
|
hb.settings.start_offset_left.x = hb.load_setting("hudbars_start_statbar_offset_left_x", "number", -265)
|
||||||
|
hb.settings.start_offset_left.y = hb.load_setting("hudbars_start_statbar_offset_left_y", "number", -90)
|
||||||
|
hb.settings.start_offset_right.x = hb.load_setting("hudbars_start_statbar_offset_right_x", "number", 25)
|
||||||
|
hb.settings.start_offset_right.y = hb.load_setting("hudbars_start_statbar_offset_right_y", "number", -90)
|
||||||
|
end
|
||||||
hb.settings.vmargin = hb.load_setting("hudbars_vmargin", "number", 24)
|
hb.settings.vmargin = hb.load_setting("hudbars_vmargin", "number", 24)
|
||||||
hb.settings.tick = hb.load_setting("hudbars_tick", "number", 0.1)
|
hb.settings.tick = hb.load_setting("hudbars_tick", "number", 0.1)
|
||||||
|
|
||||||
|
@ -74,7 +81,6 @@ hb.settings.forceload_default_hudbars = hb.load_setting("hudbars_forceload_defau
|
||||||
|
|
||||||
-- Misc. settings
|
-- Misc. settings
|
||||||
hb.settings.alignment_pattern = hb.load_setting("hudbars_alignment_pattern", "string", "zigzag", {"zigzag", "stack_up", "stack_down"})
|
hb.settings.alignment_pattern = hb.load_setting("hudbars_alignment_pattern", "string", "zigzag", {"zigzag", "stack_up", "stack_down"})
|
||||||
hb.settings.bar_type = hb.load_setting("hudbars_bar_type", "string", "progress_bar", {"progress_bar", "statbar_classic", "statbar_modern"})
|
|
||||||
hb.settings.autohide_breath = hb.load_setting("hudbars_autohide_breath", "bool", true)
|
hb.settings.autohide_breath = hb.load_setting("hudbars_autohide_breath", "bool", true)
|
||||||
|
|
||||||
local sorting = minetest.setting_get("hudbars_sorting")
|
local sorting = minetest.setting_get("hudbars_sorting")
|
||||||
|
@ -90,6 +96,10 @@ else
|
||||||
hb.settings.sorting_reverse = { [0] = "health", [1] = "breath" }
|
hb.settings.sorting_reverse = { [0] = "health", [1] = "breath" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function player_exists(player)
|
||||||
|
return player ~= nil and player:is_player()
|
||||||
|
end
|
||||||
|
|
||||||
-- Table which contains all players with active default HUD bars (only for internal use)
|
-- Table which contains all players with active default HUD bars (only for internal use)
|
||||||
hb.players = {}
|
hb.players = {}
|
||||||
|
|
||||||
|
@ -218,14 +228,18 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
||||||
number = bgiconnumber,
|
number = bgiconnumber,
|
||||||
alignment = {x=-1,y=-1},
|
alignment = {x=-1,y=-1},
|
||||||
offset = { x = offset.x, y = offset.y },
|
offset = { x = offset.x, y = offset.y },
|
||||||
|
direction = 0,
|
||||||
|
size = {x=24, y=24},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local bar_image
|
local bar_image, bar_size
|
||||||
if hb.settings.bar_type == "progress_bar" then
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
bar_image = textures.bar
|
bar_image = textures.bar
|
||||||
|
bar_size = nil
|
||||||
elseif hb.settings.bar_type == "statbar_classic" or hb.settings.bar_type == "statbar_modern" then
|
elseif hb.settings.bar_type == "statbar_classic" or hb.settings.bar_type == "statbar_modern" then
|
||||||
bar_image = textures.icon
|
bar_image = textures.icon
|
||||||
|
bar_size = {x=24, y=24}
|
||||||
end
|
end
|
||||||
ids.bar = player:hud_add({
|
ids.bar = player:hud_add({
|
||||||
hud_elem_type = "statbar",
|
hud_elem_type = "statbar",
|
||||||
|
@ -234,6 +248,8 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
||||||
number = barnumber,
|
number = barnumber,
|
||||||
alignment = {x=-1,y=-1},
|
alignment = {x=-1,y=-1},
|
||||||
offset = offset,
|
offset = offset,
|
||||||
|
direction = 0,
|
||||||
|
size = bar_size,
|
||||||
})
|
})
|
||||||
if hb.settings.bar_type == "progress_bar" then
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
ids.text = player:hud_add({
|
ids.text = player:hud_add({
|
||||||
|
@ -285,13 +301,18 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
||||||
end
|
end
|
||||||
|
|
||||||
function hb.init_hudbar(player, identifier, start_value, start_max, start_hidden)
|
function hb.init_hudbar(player, identifier, start_value, start_max, start_hidden)
|
||||||
|
if not player_exists(player) then return false end
|
||||||
local hudtable = hb.get_hudtable(identifier)
|
local hudtable = hb.get_hudtable(identifier)
|
||||||
hb.hudtables[identifier].add_all(player, hudtable, start_value, start_max, start_hidden)
|
hb.hudtables[identifier].add_all(player, hudtable, start_value, start_max, start_hidden)
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function hb.change_hudbar(player, identifier, new_value, new_max_value, new_icon, new_bgicon, new_bar, new_label, new_text_color)
|
function hb.change_hudbar(player, identifier, new_value, new_max_value, new_icon, new_bgicon, new_bar, new_label, new_text_color)
|
||||||
if new_value == nil and new_max_value == nil and new_icon == nil and new_bgicon == nil and new_bar == nil and new_label == nil and new_text_color == nil then
|
if new_value == nil and new_max_value == nil and new_icon == nil and new_bgicon == nil and new_bar == nil and new_label == nil and new_text_color == nil then
|
||||||
return
|
return true
|
||||||
|
end
|
||||||
|
if not player_exists(player) then
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
@ -379,11 +400,14 @@ function hb.change_hudbar(player, identifier, new_value, new_max_value, new_icon
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function hb.hide_hudbar(player, identifier)
|
function hb.hide_hudbar(player, identifier)
|
||||||
|
if not player_exists(player) then return false end
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local hudtable = hb.get_hudtable(identifier)
|
local hudtable = hb.get_hudtable(identifier)
|
||||||
|
if hudtable == nil then return false end
|
||||||
if(hudtable.hudstate[name].hidden == false) then
|
if(hudtable.hudstate[name].hidden == false) then
|
||||||
if hb.settings.bar_type == "progress_bar" then
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
if hudtable.hudids[name].icon ~= nil then
|
if hudtable.hudids[name].icon ~= nil then
|
||||||
|
@ -397,11 +421,14 @@ function hb.hide_hudbar(player, identifier)
|
||||||
player:hud_change(hudtable.hudids[name].bar, "number", 0)
|
player:hud_change(hudtable.hudids[name].bar, "number", 0)
|
||||||
hudtable.hudstate[name].hidden = true
|
hudtable.hudstate[name].hidden = true
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function hb.unhide_hudbar(player, identifier)
|
function hb.unhide_hudbar(player, identifier)
|
||||||
|
if not player_exists(player) then return false end
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local hudtable = hb.get_hudtable(identifier)
|
local hudtable = hb.get_hudtable(identifier)
|
||||||
|
if hudtable == nil then return false end
|
||||||
if(hudtable.hudstate[name].hidden) then
|
if(hudtable.hudstate[name].hidden) then
|
||||||
local value = hudtable.hudstate[name].value
|
local value = hudtable.hudstate[name].value
|
||||||
local max = hudtable.hudstate[name].max
|
local max = hudtable.hudstate[name].max
|
||||||
|
@ -419,9 +446,11 @@ function hb.unhide_hudbar(player, identifier)
|
||||||
player:hud_change(hudtable.hudids[name].bar, "number", hb.value_to_barlength(value, max))
|
player:hud_change(hudtable.hudids[name].bar, "number", hb.value_to_barlength(value, max))
|
||||||
hudtable.hudstate[name].hidden = false
|
hudtable.hudstate[name].hidden = false
|
||||||
end
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function hb.get_hudbar_state(player, identifier)
|
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()]
|
local ref = hb.get_hudtable(identifier).hudstate[player:get_player_name()]
|
||||||
-- Do not forget to update this chunk of code in case the state changes
|
-- Do not forget to update this chunk of code in case the state changes
|
||||||
local copy = {
|
local copy = {
|
||||||
|
@ -464,9 +493,13 @@ local function custom_hud(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function update_health(player)
|
||||||
|
hb.change_hudbar(player, "health", player:get_hp())
|
||||||
|
end
|
||||||
|
|
||||||
-- update built-in HUD bars
|
-- update built-in HUD bars
|
||||||
local function update_hud(player)
|
local function update_hud(player)
|
||||||
|
if not player_exists(player) then return end
|
||||||
if minetest.setting_getbool("enable_damage") then
|
if minetest.setting_getbool("enable_damage") then
|
||||||
if hb.settings.forceload_default_hudbars then
|
if hb.settings.forceload_default_hudbars then
|
||||||
hb.unhide_hudbar(player, "health")
|
hb.unhide_hudbar(player, "health")
|
||||||
|
@ -480,15 +513,21 @@ local function update_hud(player)
|
||||||
hb.unhide_hudbar(player, "breath")
|
hb.unhide_hudbar(player, "breath")
|
||||||
hb.change_hudbar(player, "breath", math.min(breath, 10))
|
hb.change_hudbar(player, "breath", math.min(breath, 10))
|
||||||
end
|
end
|
||||||
|
|
||||||
--health
|
--health
|
||||||
hb.change_hudbar(player, "health", player:get_hp())
|
update_health(player)
|
||||||
elseif hb.settings.forceload_default_hudbars then
|
elseif hb.settings.forceload_default_hudbars then
|
||||||
hb.hide_hudbar(player, "health")
|
hb.hide_hudbar(player, "health")
|
||||||
hb.hide_hudbar(player, "breath")
|
hb.hide_hudbar(player, "breath")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.register_on_player_hpchange(update_health)
|
||||||
|
|
||||||
|
minetest.register_on_respawnplayer(function(player)
|
||||||
|
update_health(player)
|
||||||
|
hb.hide_hudbar(player, "breath")
|
||||||
|
end)
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
hide_builtin(player)
|
hide_builtin(player)
|
||||||
custom_hud(player)
|
custom_hud(player)
|
||||||
|
|
|
@ -77,17 +77,38 @@ hudbars_pos_right_y (Right HUD bar screen y position) float 1.0 0.0 1.0
|
||||||
|
|
||||||
# Precise x offset in pixels from the basic screen x position of the HUD bars.
|
# Precise x offset in pixels from the basic screen x position of the HUD bars.
|
||||||
# For the zig-zag alignment pattern, this is for the left HUD bars.
|
# For the zig-zag alignment pattern, this is for the left HUD bars.
|
||||||
|
# This setting is used for the progress bar HUD bar style.
|
||||||
hudbars_start_offset_left_x (Left HUD bar x offset) int -175
|
hudbars_start_offset_left_x (Left HUD bar x offset) int -175
|
||||||
# Precise y offset in pixels from the basic screen y position of the HUD bars.
|
# Precise y offset in pixels from the basic screen y position of the HUD bars.
|
||||||
# For the zig-zag alignment pattern, this is for the left HUD bars.
|
# For the zig-zag alignment pattern, this is for the left HUD bars.
|
||||||
|
# This setting is used for the progress bar HUD bar style.
|
||||||
hudbars_start_offset_left_y (Left HUD bar y offset) int -86
|
hudbars_start_offset_left_y (Left HUD bar y offset) int -86
|
||||||
# Precise x offset in pixels from the basic screen x position of the right HUD bars.
|
# Precise x offset in pixels from the basic screen x position of the right HUD bars.
|
||||||
# Only used for the zig-zag alignment pattern.
|
# Only used for the zig-zag alignment pattern.
|
||||||
|
# This setting is used for the progress bar HUD bar style.
|
||||||
hudbars_start_offset_right_x (Right HUD bar x offset) int 15
|
hudbars_start_offset_right_x (Right HUD bar x offset) int 15
|
||||||
# Precise y offset in pixels from the basic screen y position of the right HUD bars.
|
# Precise y offset in pixels from the basic screen y position of the right HUD bars.
|
||||||
# Only used for the zig-zag alignment pattern.
|
# Only used for the zig-zag alignment pattern.
|
||||||
|
# This setting is used for the progress bar HUD bar style.
|
||||||
hudbars_start_offset_right_y (Right HUD bar y offset) int -86
|
hudbars_start_offset_right_y (Right HUD bar y offset) int -86
|
||||||
|
|
||||||
|
# Precise x offset in pixels from the basic screen x position of the HUD statbars.
|
||||||
|
# For the zig-zag alignment pattern, this is for the left HUD statbars.
|
||||||
|
# This setting is used for the classic and modern statbar styles.
|
||||||
|
hudbars_start_statbar_offset_left_x (Left HUD statbar x offset) int -265
|
||||||
|
# Precise y offset in pixels from the basic screen y position of the HUD statbars.
|
||||||
|
# For the zig-zag alignment pattern, this is for the left HUD statbars.
|
||||||
|
# This setting is used for the classic and modern statbar styles.
|
||||||
|
hudbars_start_statbar_offset_left_y (Left HUD statbar y offset) int -90
|
||||||
|
# Precise x offset in pixels from the basic screen x position of the right HUD statbars.
|
||||||
|
# Only used for the zig-zag alignment pattern.
|
||||||
|
# This setting is used for the classic and modern statbar styles.
|
||||||
|
hudbars_start_statbar_offset_right_x (Right HUD statbar x offset) int 25
|
||||||
|
# Precise y offset in pixels from the basic screen y position of the right HUD statbars.
|
||||||
|
# Only used for the zig-zag alignment pattern.
|
||||||
|
# This setting is used for the classic and modern statbar styles.
|
||||||
|
hudbars_start_statbar_offset_right_y (Right HUD statbar y offset) int -90
|
||||||
|
|
||||||
# The vertical distance between two HUD bars, in pixels.
|
# The vertical distance between two HUD bars, in pixels.
|
||||||
hudbars_vmargin (Vertical distance between HUD bars) int 24 0
|
hudbars_vmargin (Vertical distance between HUD bars) int 24 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue