From 6c0c617b393c6d461316f5e70fedcb0b359ebe29 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 22 Nov 2016 14:59:40 +0100 Subject: [PATCH 01/11] Fix possible crash after player left --- API.md | 17 +++++++++-------- init.lua | 23 +++++++++++++++++++++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/API.md b/API.md index c4eb87b..03e93ea 100644 --- a/API.md +++ b/API.md @@ -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 #### Return value -Always `nil`. - +`true` on success, `false` otherwise. ## 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. #### Return value -Always `nil`. +`true` on success, `false` otherwise. ## 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`. #### Return value -Always `nil`. +`true` on success, `false` otherwise. ### `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`. #### Return value -Always `nil`. +`true` on success, `false` otherwise. ## 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`. #### Return value -A table which holds information on the current state of the HUD bar. Note the table is a deep -copy of the internal HUD bar state, it is *not* a reference; the information hold by the table is -only true for the moment you called this function. The fields of this table are: +On success, returns a table which holds information on the current state of the HUD bar. Note +the table is a deep copy of the internal HUD bar state, it is *not* a reference; the information +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. * `max`: Current maximum value of HUD bar. * `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. * `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. diff --git a/init.lua b/init.lua index ff95214..651a22d 100644 --- a/init.lua +++ b/init.lua @@ -90,6 +90,10 @@ else hb.settings.sorting_reverse = { [0] = "health", [1] = "breath" } 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) hb.players = {} @@ -285,13 +289,18 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta end 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) hb.hudtables[identifier].add_all(player, hudtable, start_value, start_max, start_hidden) + return true end 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 - return + return true + end + if not player_exists(player) then + return false end local name = player:get_player_name() @@ -379,11 +388,14 @@ function hb.change_hudbar(player, identifier, new_value, new_max_value, new_icon end end end + return true end function hb.hide_hudbar(player, identifier) + if not player_exists(player) then return false end local name = player:get_player_name() local hudtable = hb.get_hudtable(identifier) + if hudtable == nil then return false end if(hudtable.hudstate[name].hidden == false) then if hb.settings.bar_type == "progress_bar" then if hudtable.hudids[name].icon ~= nil then @@ -397,11 +409,14 @@ function hb.hide_hudbar(player, identifier) player:hud_change(hudtable.hudids[name].bar, "number", 0) hudtable.hudstate[name].hidden = true end + return true end function hb.unhide_hudbar(player, identifier) + if not player_exists(player) then return false end local name = player:get_player_name() local hudtable = hb.get_hudtable(identifier) + if hudtable == nil then return false end if(hudtable.hudstate[name].hidden) then local value = hudtable.hudstate[name].value local max = hudtable.hudstate[name].max @@ -419,9 +434,11 @@ function hb.unhide_hudbar(player, identifier) player:hud_change(hudtable.hudids[name].bar, "number", hb.value_to_barlength(value, max)) hudtable.hudstate[name].hidden = false end + return true 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()] -- Do not forget to update this chunk of code in case the state changes local copy = { @@ -467,6 +484,7 @@ end -- update built-in HUD bars local function update_hud(player) + if not player_exists() then return end if minetest.setting_getbool("enable_damage") then if hb.settings.forceload_default_hudbars then hb.unhide_hudbar(player, "health") @@ -510,7 +528,8 @@ minetest.register_globalstep(function(dtime) if minetest.setting_getbool("enable_damage") or hb.settings.forceload_default_hudbars then for _, player in pairs(hb.players) do -- update all hud elements - update_hud(player) +minetest.after(1,function(player) update_hud(player) end, player) +-- update_hud(player) end end end From 92d8c786a97e4297839070ea976a2948e14623f1 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 22 Nov 2016 15:03:06 +0100 Subject: [PATCH 02/11] Version 1.6.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 38dd28c..5f25a8d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ this mod will place them accordingly. position should be displayed correctly on every screen size. ## Current version -The current version is 1.5.1. +The current version is 1.5.2. This software uses [semantic versioning](http://semver.org), as defined by version 2.0.0 of the SemVer standard. From 48045ec7f042a8af55d109b575c15174973646ea Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 22 Nov 2016 15:03:44 +0100 Subject: [PATCH 03/11] Version 1.6.0 --- API.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/API.md b/API.md index 03e93ea..2691111 100644 --- a/API.md +++ b/API.md @@ -1,4 +1,4 @@ -API documentation for the HUD bars mod 1.5.1 +API documentation for the HUD bars mod 1.6.0 ============================================ ## Introduction diff --git a/README.md b/README.md index 5f25a8d..a0e6571 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ this mod will place them accordingly. position should be displayed correctly on every screen size. ## Current version -The current version is 1.5.2. +The current version is 1.6.0. This software uses [semantic versioning](http://semver.org), as defined by version 2.0.0 of the SemVer standard. From d099ae91e25ab0e3b0bfbcdbe6c0cad07cd5e177 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 22 Nov 2016 15:12:09 +0100 Subject: [PATCH 04/11] Remove stupid testing code --- init.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 651a22d..7030084 100644 --- a/init.lua +++ b/init.lua @@ -528,8 +528,7 @@ minetest.register_globalstep(function(dtime) if minetest.setting_getbool("enable_damage") or hb.settings.forceload_default_hudbars then for _, player in pairs(hb.players) do -- update all hud elements -minetest.after(1,function(player) update_hud(player) end, player) --- update_hud(player) + update_hud(player) end end end From 05f5ec0622a240056628cf9c89c64d14f3aafc7a Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 22 Nov 2016 15:13:00 +0100 Subject: [PATCH 05/11] Version 1.6.1 --- API.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/API.md b/API.md index 2691111..54fa1cf 100644 --- a/API.md +++ b/API.md @@ -1,4 +1,4 @@ -API documentation for the HUD bars mod 1.6.0 +API documentation for the HUD bars mod 1.6.1 ============================================ ## Introduction diff --git a/README.md b/README.md index a0e6571..aff4a7c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ this mod will place them accordingly. position should be displayed correctly on every screen size. ## Current version -The current version is 1.6.0. +The current version is 1.6.1. This software uses [semantic versioning](http://semver.org), as defined by version 2.0.0 of the SemVer standard. From 3d74745aec4d95d80090aa0730a7a1c1c4eab32f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 2 Dec 2016 21:40:46 +0100 Subject: [PATCH 06/11] Big statbar icons, introduce new offset config --- init.lua | 26 +++++++++++++++++++------- settingtypes.txt | 21 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/init.lua b/init.lua index 7030084..b06a85b 100644 --- a/init.lua +++ b/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_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.start_offset_left.x = hb.load_setting("hudbars_start_offset_left_x", "number", -175) -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) - +hb.settings.bar_type = hb.load_setting("hudbars_bar_type", "string", "progress_bar", {"progress_bar", "statbar_classic", "statbar_modern"}) +if hb.settings.bar_type == "progress_bar" then + hb.settings.start_offset_left.x = hb.load_setting("hudbars_start_offset_left_x", "number", -175) + 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", -88) + 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", -88) +end hb.settings.vmargin = hb.load_setting("hudbars_vmargin", "number", 24) 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 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) local sorting = minetest.setting_get("hudbars_sorting") @@ -222,14 +228,18 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta number = bgiconnumber, alignment = {x=-1,y=-1}, offset = { x = offset.x, y = offset.y }, + direction = 0, + size = {x=24, y=24}, }) end end - local bar_image + local bar_image, bar_size if hb.settings.bar_type == "progress_bar" then bar_image = textures.bar + bar_size = nil elseif hb.settings.bar_type == "statbar_classic" or hb.settings.bar_type == "statbar_modern" then bar_image = textures.icon + bar_size = {x=24, y=24} end ids.bar = player:hud_add({ hud_elem_type = "statbar", @@ -238,6 +248,8 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta number = barnumber, alignment = {x=-1,y=-1}, offset = offset, + direction = 0, + size = bar_size, }) if hb.settings.bar_type == "progress_bar" then ids.text = player:hud_add({ diff --git a/settingtypes.txt b/settingtypes.txt index 5779063..deffd61 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -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. # 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 # 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. +# This setting is used for the progress bar HUD bar style. 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. # 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 # Precise y offset in pixels from the basic screen y position of the right HUD bars. # 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 +# 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 -88 +# 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 -88 + # The vertical distance between two HUD bars, in pixels. hudbars_vmargin (Vertical distance between HUD bars) int 24 0 From 3c182884dcf4ec1a98ca05c16c247a62abbfe50f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 2 Dec 2016 22:36:10 +0100 Subject: [PATCH 07/11] Fix breath and health not being updated anymore --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index b06a85b..f5cc0ec 100644 --- a/init.lua +++ b/init.lua @@ -496,7 +496,7 @@ end -- update built-in HUD bars local function update_hud(player) - if not player_exists() then return end + if not player_exists(player) then return end if minetest.setting_getbool("enable_damage") then if hb.settings.forceload_default_hudbars then hb.unhide_hudbar(player, "health") From 5c0f165ddf588fda7cf565aae528c1ccab74ed29 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 2 Dec 2016 23:04:54 +0100 Subject: [PATCH 08/11] Event-based health bar change --- init.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index f5cc0ec..343358c 100644 --- a/init.lua +++ b/init.lua @@ -493,6 +493,9 @@ local function custom_hud(player) end end +local function update_health(player) + hb.change_hudbar(player, "health", player:get_hp()) +end -- update built-in HUD bars local function update_hud(player) @@ -510,15 +513,21 @@ local function update_hud(player) hb.unhide_hudbar(player, "breath") hb.change_hudbar(player, "breath", math.min(breath, 10)) end - --health - hb.change_hudbar(player, "health", player:get_hp()) + update_health(player) elseif hb.settings.forceload_default_hudbars then hb.hide_hudbar(player, "health") hb.hide_hudbar(player, "breath") 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) hide_builtin(player) custom_hud(player) From d3e51926bc917959012a02305501ba650dd6bc2f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 3 Dec 2016 01:23:12 +0100 Subject: [PATCH 09/11] Fix README.md syntax error --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index aff4a7c..439ec69 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Author: Wuzzy (2015) Also: This mod was forked from the “Better HUD” [hud] mod by BlockMen. Translations: + * German: Wuzzy * Portuguese: BrunoMine From 7cf82b4e2fd93e90c1319a42fe346db11e706845 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 3 Dec 2016 02:24:45 +0100 Subject: [PATCH 10/11] Move statbars 2 pixels up --- init.lua | 4 ++-- settingtypes.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 343358c..6bcc624 100644 --- a/init.lua +++ b/init.lua @@ -69,9 +69,9 @@ if hb.settings.bar_type == "progress_bar" then 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", -88) + 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", -88) + 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.tick = hb.load_setting("hudbars_tick", "number", 0.1) diff --git a/settingtypes.txt b/settingtypes.txt index deffd61..3e4390e 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -99,7 +99,7 @@ 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 -88 +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. @@ -107,7 +107,7 @@ 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 -88 +hudbars_start_statbar_offset_right_y (Right HUD statbar y offset) int -90 # The vertical distance between two HUD bars, in pixels. hudbars_vmargin (Vertical distance between HUD bars) int 24 0 From e11a52d8fba15ec04226d4659a8aeb9dc59eb632 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 3 Dec 2016 19:58:34 +0100 Subject: [PATCH 11/11] Version 1.7.0 --- API.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/API.md b/API.md index 54fa1cf..124da82 100644 --- a/API.md +++ b/API.md @@ -1,4 +1,4 @@ -API documentation for the HUD bars mod 1.6.1 +API documentation for the HUD bars mod 1.7.0 ============================================ ## Introduction diff --git a/README.md b/README.md index 439ec69..6571b77 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ this mod will place them accordingly. position should be displayed correctly on every screen size. ## Current version -The current version is 1.6.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 standard.