Update HUD bars mod
This commit is contained in:
parent
d7b5ee494e
commit
28dc5b802f
@ -170,7 +170,7 @@ Makes a previously hidden HUD bar visible again to a player.
|
||||
|
||||
|
||||
## Reading HUD bar information
|
||||
It is also possible to read information about an active HUD bar.
|
||||
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.
|
||||
@ -191,3 +191,6 @@ hold by the table is only true for the moment you called this function. The fiel
|
||||
* `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.
|
||||
|
||||
### `hb.get_hudbar_identifiers()`
|
||||
Returns a table of all currently registered HUD bar identifiers.
|
||||
|
48
mods/HUD/hudbars/default_settings.lua
Normal file
48
mods/HUD/hudbars/default_settings.lua
Normal file
@ -0,0 +1,48 @@
|
||||
-- (Hardcoded) default settings
|
||||
|
||||
hb.settings.max_bar_length = 160
|
||||
hb.settings.statbar_length = 20
|
||||
|
||||
-- Statbar positions
|
||||
hb.settings.pos_left = {}
|
||||
hb.settings.pos_right = {}
|
||||
hb.settings.start_offset_left = {}
|
||||
hb.settings.start_offset_right= {}
|
||||
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.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", -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.tick = hb.load_setting("hudbars_tick", "number", 0.1)
|
||||
|
||||
-- Experimental setting: Changing this setting is not officially supported, do NOT rely on it!
|
||||
hb.settings.forceload_default_hudbars = hb.load_setting("hudbars_forceload_default_hudbars", "bool", true)
|
||||
|
||||
-- Misc. settings
|
||||
hb.settings.alignment_pattern = hb.load_setting("hudbars_alignment_pattern", "string", "zigzag", {"zigzag", "stack_up", "stack_down"})
|
||||
hb.settings.autohide_breath = hb.load_setting("hudbars_autohide_breath", "bool", true)
|
||||
|
||||
local sorting = minetest.settings:get("hudbars_sorting")
|
||||
if sorting ~= nil then
|
||||
hb.settings.sorting = {}
|
||||
hb.settings.sorting_reverse = {}
|
||||
for k,v in string.gmatch(sorting, "(%w+)=(%w+)") do
|
||||
hb.settings.sorting[k] = tonumber(v)
|
||||
hb.settings.sorting_reverse[tonumber(v)] = k
|
||||
end
|
||||
else
|
||||
hb.settings.sorting = { ["health"] = 0, ["breath"] = 1 }
|
||||
hb.settings.sorting_reverse = { [0] = "health", [1] = "breath" }
|
||||
end
|
@ -20,11 +20,11 @@ hb.settings = {}
|
||||
function hb.load_setting(sname, stype, defaultval, valid_values)
|
||||
local sval
|
||||
if stype == "string" then
|
||||
sval = minetest.setting_get(sname)
|
||||
sval = minetest.settings:get(sname)
|
||||
elseif stype == "bool" then
|
||||
sval = minetest.setting_getbool(sname)
|
||||
sval = minetest.settings:get_bool(sname)
|
||||
elseif stype == "number" then
|
||||
sval = tonumber(minetest.setting_get(sname))
|
||||
sval = tonumber(minetest.settings:get(sname))
|
||||
end
|
||||
if sval ~= nil then
|
||||
if valid_values ~= nil then
|
||||
@ -48,58 +48,8 @@ function hb.load_setting(sname, stype, defaultval, valid_values)
|
||||
end
|
||||
end
|
||||
|
||||
-- (hardcoded) default settings
|
||||
hb.settings.max_bar_length = 160
|
||||
hb.settings.statbar_length = 20
|
||||
|
||||
-- statbar positions
|
||||
hb.settings.pos_left = {}
|
||||
hb.settings.pos_right = {}
|
||||
hb.settings.start_offset_left = {}
|
||||
hb.settings.start_offset_right= {}
|
||||
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.bar_type = hb.load_setting("hudbars_bar_type", "string", "statbar_modern", {"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", -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", 32)
|
||||
hb.settings.tick = hb.load_setting("hudbars_tick", "number", 0.1)
|
||||
|
||||
-- experimental setting: Changing this setting is not officially supported, do NOT rely on it!
|
||||
hb.settings.forceload_default_hudbars = hb.load_setting("hudbars_forceload_default_hudbars", "bool", true)
|
||||
|
||||
-- Misc. settings
|
||||
hb.settings.alignment_pattern = hb.load_setting("hudbars_alignment_pattern", "string", "zigzag", {"zigzag", "stack_up", "stack_down"})
|
||||
hb.settings.autohide_breath = hb.load_setting("hudbars_autohide_breath", "bool", true)
|
||||
|
||||
local sorting = minetest.setting_get("hudbars_sorting")
|
||||
if sorting ~= nil then
|
||||
hb.settings.sorting = {}
|
||||
hb.settings.sorting_reverse = {}
|
||||
for k,v in string.gmatch(sorting, "(%w+)=(%w+)") do
|
||||
hb.settings.sorting[k] = tonumber(v)
|
||||
hb.settings.sorting_reverse[tonumber(v)] = k
|
||||
end
|
||||
else
|
||||
sorting = ""
|
||||
hb.settings.sorting = { ["health"] = 0, ["hunger"] = 1, ["armor"] = 2, ["breath"] = 3, ["exhaustion"] = 4, ["saturation"] = 5 }
|
||||
end
|
||||
|
||||
hb.settings.sorting_reverse = {}
|
||||
for k,v in string.gmatch(sorting, "(%w+)=(%w+)") do
|
||||
hb.settings.sorting_reverse[tonumber(v)] = k
|
||||
end
|
||||
-- Load default settings
|
||||
dofile(minetest.get_modpath("hudbars").."/default_settings.lua")
|
||||
|
||||
local function player_exists(player)
|
||||
return player ~= nil and player:is_player()
|
||||
@ -468,8 +418,16 @@ function hb.get_hudbar_state(player, identifier)
|
||||
return copy
|
||||
end
|
||||
|
||||
function hb.get_hudbar_identifiers()
|
||||
local ids = {}
|
||||
for id, _ in pairs(hb.hudtables) do
|
||||
table.insert(ids, id)
|
||||
end
|
||||
return ids
|
||||
end
|
||||
|
||||
--register built-in HUD bars
|
||||
if minetest.setting_getbool("enable_damage") or hb.settings.forceload_default_hudbars then
|
||||
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)
|
||||
end
|
||||
@ -483,9 +441,9 @@ end
|
||||
|
||||
|
||||
local function custom_hud(player)
|
||||
if minetest.setting_getbool("enable_damage") or hb.settings.forceload_default_hudbars then
|
||||
if minetest.settings:get_bool("enable_damage") or hb.settings.forceload_default_hudbars then
|
||||
local hide
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
if minetest.settings:get_bool("enable_damage") then
|
||||
hide = false
|
||||
else
|
||||
hide = true
|
||||
@ -505,7 +463,7 @@ end
|
||||
-- update built-in HUD bars
|
||||
local function update_hud(player)
|
||||
if not player_exists(player) then return end
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
if minetest.settings:get_bool("enable_damage") then
|
||||
if hb.settings.forceload_default_hudbars then
|
||||
hb.unhide_hudbar(player, "health")
|
||||
end
|
||||
@ -555,7 +513,7 @@ minetest.register_globalstep(function(dtime)
|
||||
if main_timer > hb.settings.tick or timer > 4 then
|
||||
if main_timer > hb.settings.tick then main_timer = 0 end
|
||||
-- only proceed if damage is enabled
|
||||
if minetest.setting_getbool("enable_damage") or hb.settings.forceload_default_hudbars then
|
||||
if minetest.settings:get_bool("enable_damage") or hb.settings.forceload_default_hudbars then
|
||||
for _, player in pairs(hb.players) do
|
||||
-- update all hud elements
|
||||
update_hud(player)
|
||||
|
@ -1,5 +0,0 @@
|
||||
This mod is licensed under GNU LGPLv2 or later.
|
||||
|
||||
It was taken from the file “`item_names.lua`” found in the Unified Inventory mod maintained
|
||||
by VanessaE.
|
||||
Original author: 4aiman
|
@ -1 +0,0 @@
|
||||
hudbars?
|
@ -1 +0,0 @@
|
||||
Displays the name of the wielded item
|
@ -1,83 +0,0 @@
|
||||
-- Based on 4itemnames mod by 4aiman
|
||||
|
||||
local wield = {}
|
||||
local wieldindex = {}
|
||||
local huds = {}
|
||||
local dtimes = {}
|
||||
local dlimit = 3 -- HUD element will be hidden after this many seconds
|
||||
|
||||
local function set_hud(player)
|
||||
if not player:is_player() then return end
|
||||
local player_name = player:get_player_name()
|
||||
local off = {x=0, y=-136}
|
||||
huds[player_name] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x=0.5, y=1},
|
||||
offset = off,
|
||||
alignment = {x=0, y=0},
|
||||
number = 0xFFFFFF ,
|
||||
text = "",
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
set_hud(player)
|
||||
|
||||
local name = player:get_player_name()
|
||||
wield[name] = player:get_wielded_item():get_name()
|
||||
wieldindex[name] = player:get_wield_index()
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
wield[name] = nil
|
||||
wieldindex[name] = nil
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local player_name = player:get_player_name()
|
||||
local wstack = player:get_wielded_item()
|
||||
local wname = wstack:get_name()
|
||||
local windex = player:get_wield_index()
|
||||
|
||||
if dtimes[player_name] and dtimes[player_name] < dlimit then
|
||||
dtimes[player_name] = dtimes[player_name] + dtime
|
||||
if dtimes[player_name] > dlimit and huds[player_name] then
|
||||
player:hud_change(huds[player_name], 'text', "")
|
||||
end
|
||||
end
|
||||
|
||||
-- Update HUD when wielded item or wielded index changed
|
||||
if wname ~= wield[player_name] or windex ~= wieldindex[player_name] then
|
||||
wieldindex[player_name] = windex
|
||||
wield[player_name] = wname
|
||||
dtimes[player_name] = 0
|
||||
|
||||
if huds[player_name] then
|
||||
|
||||
local def = minetest.registered_items[wname]
|
||||
local meta = wstack:get_meta()
|
||||
|
||||
--[[ Get description. Order of preference:
|
||||
* description from metadata
|
||||
* description from item definition
|
||||
* itemstring ]]
|
||||
local desc = meta:get_string("description")
|
||||
if (desc == nil or desc == "") and def then
|
||||
desc = def.description
|
||||
end
|
||||
if desc == nil or desc == "" then
|
||||
desc = wname
|
||||
end
|
||||
-- Cut off item description after first newline
|
||||
local firstnewline = string.find(desc, "\n")
|
||||
if firstnewline then
|
||||
desc = string.sub(desc, 1, firstnewline-1)
|
||||
end
|
||||
player:hud_change(huds[player_name], 'text', desc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -1 +0,0 @@
|
||||
name = mcl_item_names
|
Loading…
Reference in New Issue
Block a user