MultiCraft_game/files/hud/builtin.lua

113 lines
2.4 KiB
Lua
Raw Normal View History

2016-02-07 03:24:38 +02:00
HUD_IW_MAX = 8
HUD_IW_TICK = 0.4
if minetest.is_singleplayer() == true then
HUD_IW_TICK = 0.2
end
2016-12-06 07:36:24 +03:00
2016-02-07 03:24:38 +02:00
HUD_SB_SIZE = {x = 24, y = 24}
HUD_HEALTH_POS = {x = 0.5,y = 1}
HUD_HEALTH_OFFSET = {x = -248, y = -93}
2016-02-07 03:24:38 +02:00
HUD_AIR_POS = {x = 0.5, y = 1}
HUD_AIR_OFFSET = {x = 6, y = -93}
2016-02-07 03:24:38 +02:00
HUD_HUNGER_POS = {x = 0.5, y = 1}
HUD_HUNGER_OFFSET = {x = 6, y = -124}
2016-02-07 03:24:38 +02:00
HUD_ARMOR_POS = {x = 0.5, y = 1}
HUD_ARMOR_OFFSET = {x = -248, y = -124}
2016-02-07 03:24:38 +02:00
-- read hud.conf settings
2016-12-06 07:36:24 +03:00
function hud.read_conf()
local mod_path = minetest.get_modpath("hud")
local set = io.open(mod_path .. "/hud.conf", "r")
if set then
dofile(mod_path .. "/hud.conf")
set:close()
end
end
2016-02-07 03:24:38 +02:00
hud.read_conf()
local damage_enabled = minetest.settings:get_bool("enable_damage")
2016-02-07 03:24:38 +02:00
hud.show_hunger = minetest.get_modpath("hunger") ~= nil
hud.show_armor = minetest.get_modpath("3d_armor") ~= nil
-- check if some settings are invalid
local enable_hunger = minetest.settings:get_bool("hud_hunger_enable")
2018-12-26 00:53:58 +01:00
if (enable_hunger == true) and not hud.show_hunger then
2016-02-07 03:24:38 +02:00
hud.notify_hunger(5)
end
2016-12-06 07:36:24 +03:00
if damage_enabled ~= true then
hud.show_armor = false
return
end
hud.register("health", {
hud_elem_type = "statbar",
position = HUD_HEALTH_POS,
size = HUD_SB_SIZE,
text = "heart.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
}
},
})
2016-02-07 03:24:38 +02:00
2016-12-06 07:36:24 +03:00
hud.register("air", {
hud_elem_type = "statbar",
position = HUD_AIR_POS,
size = HUD_SB_SIZE,
text = "bubble.png",
number = 0,
alignment = {x = -1, y = -1},
offset = HUD_AIR_OFFSET,
background = nil,
events = {
{
type = "breath",
func = function(player)
if not player then return end -- ADDED
local air = player:get_breath() or 11
if air > 10 then
air = 0
2016-02-07 03:24:38 +02:00
end
2016-12-06 07:36:24 +03:00
hud.change_item(player, "air", {number = air * 2})
end
}
},
})
2016-02-07 03:24:38 +02:00
2016-12-06 07:36:24 +03:00
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,
})
2016-02-07 03:24:38 +02:00
2016-12-06 07:36:24 +03:00
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,
})