Compare commits
5 Commits
b9b784af04
...
c58f7034e6
Author | SHA1 | Date |
---|---|---|
BlockMen | c58f7034e6 | |
BlockMen | fb0a4f2f10 | |
BlockMen | 44d40a92ae | |
BlockMen | d5254a20f5 | |
BlockMen | ec9f4b2875 |
9
API.txt
9
API.txt
|
@ -1,13 +1,18 @@
|
|||
function hud.register(name, def)
|
||||
hud.register(name, def)
|
||||
-- name: statbar name (health, air, hunger, armor already used by default)
|
||||
-- def: <HUD item definition> (see below)
|
||||
|
||||
hud.change_item(player, name, def)
|
||||
-- player: player object
|
||||
-- name: statbar name (health, air, hunger, armor already used by default)
|
||||
-- name: statbar name
|
||||
-- def: table containing new values
|
||||
-- currently supported: number, text and offset
|
||||
|
||||
hud.swap_statbar(player, name1, name2) -- swaps position and offset of statbar with name1 with statbar with name2
|
||||
-- player: player object
|
||||
-- name1: statbar name
|
||||
-- name2: statbar name
|
||||
|
||||
hud.remove_item(player, name)
|
||||
|
||||
HUD item definition
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
Minetest mod "Better HUD"
|
||||
=========================
|
||||
Version: 2.1.2
|
||||
Version: 2.1.5
|
||||
|
||||
(c) Copyright BlockMen (2013-2015)
|
||||
(c) Copyright BlockMen (2013-2016)
|
||||
|
||||
|
||||
About this mod:
|
||||
|
@ -26,7 +26,7 @@ This mod supports the 3d_armor mod by stu (https://github.com/stujones11/minetes
|
|||
|
||||
License:
|
||||
~~~~~~~~
|
||||
(c) Copyright BlockMen (2013-2015)
|
||||
(c) Copyright BlockMen (2013-2016)
|
||||
|
||||
|
||||
Code:
|
||||
|
|
80
api.lua
80
api.lua
|
@ -66,6 +66,59 @@ function hud.register(name, def)
|
|||
return true
|
||||
end
|
||||
|
||||
-- swaps stabar positions
|
||||
function hud.swap_statbar(player, item1, item2)
|
||||
if not player or not item1 or not item2 then
|
||||
throw_error("Not enough parameters given to swap statbars")
|
||||
return false
|
||||
end
|
||||
|
||||
local def1 = items[item1] or nil
|
||||
local def2 = items[item2] or nil
|
||||
|
||||
if not def1 or not def2 then
|
||||
throw_error("Can't swap statbars. Given statbars are not correct")
|
||||
return false
|
||||
end
|
||||
|
||||
local pos_swap = false
|
||||
local p_name = player:get_player_name()
|
||||
local elem1 = hud_id[p_name.."_"..item1]
|
||||
local elem2 = hud_id[p_name.."_"..item2]
|
||||
|
||||
if not elem1 or not elem2 or not elem1.id or not elem2.id then
|
||||
return false
|
||||
end
|
||||
|
||||
player:hud_change(elem2.id, "offset", def1.offset)
|
||||
player:hud_change(elem1.id, "offset", def2.offset)
|
||||
|
||||
if def1.position.x ~= def2.position.x or def1.position.y ~= def2.position.y then
|
||||
player:hud_change(elem2.id, "position", def1.position)
|
||||
player:hud_change(elem1.id, "position", def2.position)
|
||||
pos_swap = true
|
||||
end
|
||||
|
||||
-- do the items have backgrounds? if so, swap them aswell
|
||||
local bg1 = hud_id[p_name.."_"..item1.."_bg"] or nil
|
||||
local bg2 = hud_id[p_name.."_"..item2.."_bg"] or nil
|
||||
if bg1 ~= nil and bg1.id then
|
||||
player:hud_change(bg1.id, "offset", def2.offset)
|
||||
if pos_swap == true then
|
||||
player:hud_change(bg1.id, "position", def2.position)
|
||||
end
|
||||
end
|
||||
if bg2 ~= nil and bg2.id then
|
||||
player:hud_change(bg2.id, "offset", def1.offset)
|
||||
if pos_swap == true then
|
||||
player:hud_change(bg2.id, "position", def1.position)
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
|
||||
end
|
||||
|
||||
function hud.change_item(player, name, def)
|
||||
if not player or not player:is_player() or not name or not def then
|
||||
throw_error("Not enough parameters given to change HUD item")
|
||||
|
@ -106,6 +159,7 @@ function hud.change_item(player, name, def)
|
|||
if bg and bg.max and bg.max < 1 and def.max and def.max > bg.max then
|
||||
player:hud_change(bg.id, "number", def.max)
|
||||
bg.max = def.max
|
||||
bg.number = def.max
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -119,27 +173,9 @@ function hud.change_item(player, name, def)
|
|||
|
||||
if def.offset and elem.offset then
|
||||
if def.item_name and def.offset == "item" then
|
||||
local i_name2 = player:get_player_name().."_"..def.item_name
|
||||
local elem2 = hud_id[i_name2]
|
||||
if elem2 then
|
||||
local p2 = elem2.offset
|
||||
local p1 = elem.offset
|
||||
player:hud_change(elem2.id, "offset", p1)
|
||||
player:hud_change(elem.id, "offset", p2)
|
||||
elem2.offset = p1
|
||||
elem.offset = p2
|
||||
if elem.background then
|
||||
local elem3 = hud_id[i_name.."_bg"]
|
||||
if elem3 and elem3.offset then
|
||||
player:hud_change(elem3.id, "offset", p2)
|
||||
elem3.offset = p2
|
||||
local elem4 = hud_id[i_name2.."_bg"]
|
||||
if elem4 and elem4.offset then
|
||||
player:hud_change(elem4.id, "offset", p1)
|
||||
elem4.offset = p1
|
||||
end
|
||||
end
|
||||
end
|
||||
-- for legacy reasons
|
||||
if def.item_name then
|
||||
hud.swap_statbar(player, name, def.item_name)
|
||||
end
|
||||
else
|
||||
player:hud_change(elem.id, "offset", def.offset)
|
||||
|
@ -190,7 +226,7 @@ minetest.register_on_joinplayer(function(player)
|
|||
hud_flags.breathbar = false
|
||||
player:hud_set_flags(hud_flags)
|
||||
|
||||
-- now add the backgrounds (e.g. for statbars)
|
||||
-- now add the backgrounds for statbars
|
||||
for _,item in pairs(sb_bg) do
|
||||
add_hud_item(player, _.."_bg", item)
|
||||
end
|
||||
|
|
108
builtin.lua
108
builtin.lua
|
@ -44,70 +44,70 @@ end
|
|||
|
||||
if damage_enabled then
|
||||
hud.register("health", {
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HEALTH_POS,
|
||||
size = HUD_SB_SIZE,
|
||||
text = "hud_heart_fg.png",
|
||||
number = 20,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = HUD_HEALTH_OFFSET,
|
||||
background = "hud_heart_bg.png",
|
||||
events = {
|
||||
{
|
||||
type = "damage",
|
||||
func = function(player)
|
||||
hud.change_item(player, "health", {number = player:get_hp()})
|
||||
end
|
||||
}
|
||||
},
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HEALTH_POS,
|
||||
size = HUD_SB_SIZE,
|
||||
text = "hud_heart_fg.png",
|
||||
number = 20,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = HUD_HEALTH_OFFSET,
|
||||
background = "hud_heart_bg.png",
|
||||
events = {
|
||||
{
|
||||
type = "damage",
|
||||
func = function(player)
|
||||
hud.change_item(player, "health", {number = player:get_hp()})
|
||||
end
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
hud.register("air", {
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_AIR_POS,
|
||||
size = HUD_SB_SIZE,
|
||||
text = "hud_air_fg.png",
|
||||
number = 0,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = HUD_AIR_OFFSET,
|
||||
background = nil,
|
||||
events = {
|
||||
{
|
||||
type = "breath",
|
||||
func = function(player)
|
||||
local air = player:get_breath()
|
||||
if air > 10 then
|
||||
air = 0
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_AIR_POS,
|
||||
size = HUD_SB_SIZE,
|
||||
text = "hud_air_fg.png",
|
||||
number = 0,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = HUD_AIR_OFFSET,
|
||||
background = nil,
|
||||
events = {
|
||||
{
|
||||
type = "breath",
|
||||
func = function(player)
|
||||
local air = player:get_breath()
|
||||
if air > 10 then
|
||||
air = 0
|
||||
end
|
||||
hud.change_item(player, "air", {number = air * 2})
|
||||
end
|
||||
hud.change_item(player, "air", {number = air * 2})
|
||||
end
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
hud.register("armor", {
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_ARMOR_POS,
|
||||
size = HUD_SB_SIZE,
|
||||
text = "hud_armor_fg.png",
|
||||
number = 0,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = HUD_ARMOR_OFFSET,
|
||||
background = "hud_armor_bg.png",
|
||||
autohide_bg = true,
|
||||
max = 20,
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_ARMOR_POS,
|
||||
size = HUD_SB_SIZE,
|
||||
text = "hud_armor_fg.png",
|
||||
number = 0,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = HUD_ARMOR_OFFSET,
|
||||
background = "hud_armor_bg.png",
|
||||
autohide_bg = true,
|
||||
max = 20,
|
||||
})
|
||||
|
||||
hud.register("hunger", {
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HUNGER_POS,
|
||||
size = HUD_SB_SIZE,
|
||||
text = "hud_hunger_fg.png",
|
||||
number = 0,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = HUD_HUNGER_OFFSET,
|
||||
background = "hud_hunger_bg.png",
|
||||
max = 0,
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HUNGER_POS,
|
||||
size = HUD_SB_SIZE,
|
||||
text = "hud_hunger_fg.png",
|
||||
number = 0,
|
||||
alignment = {x = -1, y = -1},
|
||||
offset = HUD_HUNGER_OFFSET,
|
||||
background = "hud_hunger_bg.png",
|
||||
max = 0,
|
||||
})
|
||||
else
|
||||
hud.show_armor = false
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
2.1.5
|
||||
-----
|
||||
- Fixed armor not being updated correct due armor mod changes
|
||||
|
||||
2.1.4
|
||||
-----
|
||||
- Fixed unhandled exception in hud.swap_statbar()
|
||||
|
||||
2.1.3
|
||||
-----
|
||||
- Added hud.swap_statbar() and fix wrong behavior of previous workaround
|
||||
- Fixed missing background of some statbars in multiplayer
|
||||
|
||||
2.1.2
|
||||
-----
|
||||
- Fixed crash caused by animated nodes (reported by Krock)
|
||||
|
|
87
legacy.lua
87
legacy.lua
|
@ -3,59 +3,60 @@ function hud.set_armor()
|
|||
end
|
||||
|
||||
if hud.show_armor then
|
||||
local shields = minetest.get_modpath("shields") ~= nil
|
||||
local armor_org_func = armor.update_armor
|
||||
local shields = minetest.get_modpath("shields") ~= nil
|
||||
local armor_org_func = armor.set_player_armor
|
||||
|
||||
local function get_armor_lvl(def)
|
||||
-- items/protection based display
|
||||
local lvl = def.level or 0
|
||||
local max = 63 -- full diamond armor
|
||||
if shields then
|
||||
max = 84.14 -- full diamond armor + diamond shield
|
||||
end
|
||||
-- TODO: is there a sane way to read out max values?
|
||||
local ret = lvl/max
|
||||
if ret > 1 then
|
||||
ret = 1
|
||||
end
|
||||
|
||||
return tonumber(20 * ret)
|
||||
local function get_armor_lvl(def)
|
||||
-- items/protection based display
|
||||
local lvl = def.level or 0
|
||||
local max = 63 -- full diamond armor
|
||||
if shields then
|
||||
max = 84.14 -- full diamond armor + diamond shield
|
||||
end
|
||||
-- TODO: is there a sane way to read out max values?
|
||||
local ret = lvl/max
|
||||
if ret > 1 then
|
||||
ret = 1
|
||||
end
|
||||
|
||||
function armor.update_armor(self, player)
|
||||
armor_org_func(self, player)
|
||||
local name = player:get_player_name()
|
||||
local def = self.def
|
||||
local armor_lvl = 0
|
||||
if def[name] and def[name].level then
|
||||
armor_lvl = get_armor_lvl(def[name])
|
||||
end
|
||||
hud.change_item(player, "armor", {number = armor_lvl})
|
||||
return tonumber(20 * ret)
|
||||
end
|
||||
|
||||
function armor.set_player_armor(self, player)
|
||||
armor_org_func(self, player)
|
||||
local name = player:get_player_name()
|
||||
local def = self.def
|
||||
local armor_lvl = 0
|
||||
if def[name] and def[name].level then
|
||||
armor_lvl = get_armor_lvl(def[name])
|
||||
end
|
||||
hud.change_item(player, "armor", {number = armor_lvl})
|
||||
end
|
||||
end
|
||||
|
||||
-- Hunger related functions
|
||||
if not hud.show_hunger then
|
||||
function hud.set_hunger()
|
||||
hud.notify_hunger(1, true)
|
||||
end
|
||||
function hud.set_hunger()
|
||||
hud.notify_hunger(1, true)
|
||||
end
|
||||
|
||||
function hud.get_hunger()
|
||||
hud.notify_hunger(1, true)
|
||||
end
|
||||
function hud.get_hunger()
|
||||
hud.notify_hunger(1, true)
|
||||
end
|
||||
|
||||
function hud.item_eat(hp_change, replace_with_item)
|
||||
return function(itemstack, user, pointed_thing)
|
||||
hud.notify_hunger(1, true)
|
||||
local func = minetest.item_eat(hp_change, replace_with_item)
|
||||
return func(itemstack, user, pointed_thing)
|
||||
end
|
||||
function hud.item_eat(hp_change, replace_with_item)
|
||||
return function(itemstack, user, pointed_thing)
|
||||
hud.notify_hunger(1, true)
|
||||
local func = minetest.item_eat(hp_change, replace_with_item)
|
||||
return func(itemstack, user, pointed_thing)
|
||||
end
|
||||
end
|
||||
|
||||
function hud.save_hunger()
|
||||
hud.notify_hunger(1, true)
|
||||
end
|
||||
function hud.load_hunger(player)
|
||||
hud.notify_hunger(1, true)
|
||||
end
|
||||
function hud.save_hunger()
|
||||
hud.notify_hunger(1, true)
|
||||
end
|
||||
|
||||
function hud.load_hunger(player)
|
||||
hud.notify_hunger(1, true)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue