summaryrefslogtreecommitdiff
path: root/builtin.lua
blob: dfdb7072804abc8383972ee5b329acd0addc1860 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
HUD_IW_MAX = 8
HUD_IW_TICK = 0.4
if minetest.is_singleplayer() == true then
	HUD_IW_TICK = 0.2
end

HUD_SB_SIZE = {x = 24, y = 24}

HUD_HEALTH_POS = {x = 0.5,y = 1}
HUD_HEALTH_OFFSET = {x = -262, y = -87}
HUD_AIR_POS = {x = 0.5, y = 1}
HUD_AIR_OFFSET = {x = 15, y = -87}
HUD_HUNGER_POS = {x = 0.5, y = 1}
HUD_HUNGER_OFFSET = {x = 15, y = -110}
HUD_ARMOR_POS = {x = 0.5, y = 1}
HUD_ARMOR_OFFSET = {x = -262, y = -110}

-- Reorder everything when using ItemWeel
hud.item_wheel = minetest.setting_getbool("hud_item_wheel")
if hud.item_wheel then
	HUD_HEALTH_POS = {x = 0.5,y = 1}
	HUD_HEALTH_OFFSET = {x = -385, y = -77}
	HUD_AIR_POS = {x = 0.5, y = 1}
	HUD_AIR_OFFSET = {x = 150, y = -77}
	HUD_HUNGER_POS = {x = 0.5, y = 1}
	HUD_HUNGER_OFFSET = {x = 180, y = -44}
	HUD_ARMOR_POS = {x = 0.5, y = 1}
	HUD_ARMOR_OFFSET = {x = -415, y = -44}
end

-- read hud.conf settings
hud.read_conf()

local damage_enabled = minetest.setting_getbool("enable_damage")

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.setting_getbool("hud_hunger_enable")
if (enable_hunger == true or HUD_ENABLE_HUNGER == true) and not hud.show_hunger then
	hud.notify_hunger(5)
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.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
					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.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,
    })
else
	hud.show_armor = false
end