More HUD options: now supports the Better HUD and Hudbars mods

This commit is contained in:
Ben Deutsch 2015-08-18 22:16:52 +02:00
parent fde026e6db
commit d26d409ea6
10 changed files with 336 additions and 44 deletions

2
depends.txt Normal file
View File

@ -0,0 +1,2 @@
hud?
hudbars?

40
hud.conf.no_hunger Normal file
View File

@ -0,0 +1,40 @@
--[[
Better HUD config file, without Hunger mod.
This file mirrors the default settings of the Better HUD mod,
except that it moves the "breath" bar upwards to make room
for the "sanity" bar.
Use this config file as a starting point if you *don't* have the
Hunger mod enabled.
For more information, see hud.conf.example in the mods/hud
directory.
]]
HUD_SB_SIZE = { x = 24, y = 24 }
--[[ Layout:
ARMOR | (AIR)
HEALTH | SANITY
]]
HUD_HEALTH_POS = { x = 0.5, y = 1 }
HUD_HEALTH_OFFSET = { x = -262, y = -87 }
-- not used
HUD_HUNGER_POS = { x = 0.5, y = 1 }
HUD_HUNGER_OFFSET = { x = 15, y = -133 }
HUD_AIR_POS = { x = 0.5, y = 1 }
HUD_AIR_OFFSET = { x = 15, y = -110 }
HUD_ARMOR_POS = { x = 0.5, y = 1 }
HUD_ARMOR_OFFSET = { x = -262, y = -110 }
HUD_SANITY_POS = { x = 0.5, y = 1 }
HUD_SANITY_OFFSET = { x = 15, y = -87 }

43
hud.conf.with_hunger Normal file
View File

@ -0,0 +1,43 @@
--[[
Better HUD config file, with Hunger mod.
This file mirrors the default settings of the Better HUD mod,
except that it moves the "breath" bar upwards to make room
for the "sanity" bar.
Use this config file as a starting point if you *do* have the
Hunger mod enabled.
For more information, see hud.conf.example in the mods/hud
directory.
]]
HUD_SB_SIZE = { x = 24, y = 24 }
--[[ Layout:
(AIR)
ARMOR | SANITY
HEALTH | HUNGER
]]
HUD_HEALTH_POS = { x = 0.5, y = 1 }
HUD_HEALTH_OFFSET = { x = -262, y = -87 }
-- At the time of writing, the Hunger mod contains code to swap
-- the positions of "hunger" and "air", so these positions are
-- "un-swapped"...
HUD_HUNGER_POS = { x = 0.5, y = 1 }
HUD_HUNGER_OFFSET = { x = 15, y = -133 }
HUD_AIR_POS = { x = 0.5, y = 1 }
HUD_AIR_OFFSET = { x = 15, y = -87 }
HUD_ARMOR_POS = { x = 0.5, y = 1 }
HUD_ARMOR_OFFSET = { x = -262, y = -110 }
HUD_SANITY_POS = { x = 0.5, y = 1 }
HUD_SANITY_OFFSET = { x = 15, y = -110 }

89
hud.lua Normal file
View File

@ -0,0 +1,89 @@
--[[
HUD definitions for Beware the Dark
Optionally from one of the supported mods
Any hud needs to define the following functions:
- bewarethedark.hud_init(player)
Initialize the HUD for a new player.
- bewarethedark.hud_update(player, value)
Display the new value "value" for the given player. "value" is
a floating point number, not necessarily bounded. You can use the
"bewarethedark.hud_clamp(value)" function to get an integer between 0
and 20.
]]
local M = bewarethedark
local C = bewarethedark.config
local PPA = persistent_player_attributes
function M.hud_clamp(value)
if value < 0 then
return 0
elseif value > 20 then
return 20
else
return math.ceil(value)
end
end
if minetest.get_modpath("hudbars") then
hb.register_hudbar('sanity', 0x000000, "Sanity", {
bar = 'bewarethedark_hudbars_bar.png',
icon = 'bewarethedark_eye.png'
}, 20, 20, false)
function M.hud_init(player)
hb.init_hudbar(player, 'sanity',
M.hud_clamp(PPA.get_value(player, 'bewarethedark_sanity')),
20, false)
end
function M.hud_update(player, value)
hb.change_hudbar(player, 'sanity', M.hud_clamp(value), 20)
end
elseif minetest.get_modpath("hud") then
-- default positions follow [hud] defaults
local position = HUD_SANITY_POS or { x=0.5, y=1 }
local offset = HUD_SANITY_OFFSET or { x=15, y=-133} -- above AIR
hud.register('sanity', {
hud_elem_type = "statbar",
position = position,
text = "bewarethedark_eye.png",
background = "bewarethedark_eye_closed.png",
number = 20,
max = 20,
size = HUD_SD_SIZE, -- by default { x=24, y=24 },
offset = offset,
})
function M.hud_init(player)
-- automatic by [hud]
end
function M.hud_update(player, value)
hud.change_item(player, 'sanity', {
number = M.hud_clamp(value)
})
end
else
-- 'builtin' hud
function M.hud_init(player)
-- above breath bar, for now
local name = player:get_player_name()
M.players[name].hud_id = player:hud_add({
hud_elem_type = "statbar",
position = { x=0.5, y=1 },
text = "bewarethedark_eye.png",
number = M.hud_clamp(PPA.get_value(player, 'bewarethedark_sanity')),
direction = 0,
size = { x=24, y=24 },
offset = { x=25, y=-(48+24+16+32)},
})
end
function M.hud_update(player, value)
local name = player:get_player_name()
local hud_id = M.players[name].hud_id
player:hud_change(hud_id, 'number', M.hud_clamp(value))
end
end

View File

@ -71,6 +71,8 @@ local C = bewarethedark.config
dofile(minetest.get_modpath('bewarethedark')..'/persistent_player_attributes.lua') dofile(minetest.get_modpath('bewarethedark')..'/persistent_player_attributes.lua')
local PPA = persistent_player_attributes local PPA = persistent_player_attributes
dofile(minetest.get_modpath('bewarethedark')..'/hud.lua')
PPA.register({ PPA.register({
name = 'bewarethedark_sanity', name = 'bewarethedark_sanity',
min = 0, min = 0,
@ -78,16 +80,6 @@ PPA.register({
default = 20, default = 20,
}) })
function bewarethedark.hud_clamp(value)
if value < 0 then
return 0
elseif value > 20 then
return 20
else
return math.ceil(value)
end
end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
local pl = M.players[name] local pl = M.players[name]
@ -95,15 +87,7 @@ minetest.register_on_joinplayer(function(player)
if not pl then if not pl then
M.players[name] = { pending_dmg = 0.0 } M.players[name] = { pending_dmg = 0.0 }
pl = M.players[name] pl = M.players[name]
pl.hud_id = player:hud_add({ M.hud_init(player)
hud_elem_type = "statbar",
position = { x=0.5, y=1 },
text = "bewarethedark_eye.png",
number = 20,
direction = 0,
size = { x=24, y=24 },
offset = { x=25, y=-(48+24+16+32)},
})
end end
end) end)
@ -149,7 +133,7 @@ minetest.register_globalstep(function(dtime)
PPA.set_value(player, "bewarethedark_sanity", sanity) PPA.set_value(player, "bewarethedark_sanity", sanity)
player:hud_change(pl.hud_id, 'number', bewarethedark.hud_clamp(sanity)) M.hud_update(player, sanity)
end end
end end
end end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 624 B

After

Width:  |  Height:  |  Size: 659 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 566 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

View File

@ -53,7 +53,7 @@
inkscape:pageopacity="0" inkscape:pageopacity="0"
inkscape:pageshadow="2" inkscape:pageshadow="2"
inkscape:zoom="31.678384" inkscape:zoom="31.678384"
inkscape:cx="6.2715941" inkscape:cx="8.065046"
inkscape:cy="8.0849876" inkscape:cy="8.0849876"
inkscape:document-units="px" inkscape:document-units="px"
inkscape:current-layer="layer1" inkscape:current-layer="layer1"
@ -82,7 +82,7 @@
<dc:format>image/svg+xml</dc:format> <dc:format>image/svg+xml</dc:format>
<dc:type <dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title> <dc:title />
</cc:Work> </cc:Work>
</rdf:RDF> </rdf:RDF>
</metadata> </metadata>
@ -91,16 +91,23 @@
inkscape:groupmode="layer" inkscape:groupmode="layer"
id="layer1" id="layer1"
transform="translate(0,-1036.3622)"> transform="translate(0,-1036.3622)">
<path <g
sodipodi:type="arc" id="g3783-6"
style="fill:#ffffff;fill-opacity:1;stroke:none" style="fill:#ffffff;fill-opacity:1;stroke:none">
id="path3077-5" <path
sodipodi:cx="7.5" sodipodi:nodetypes="czc"
sodipodi:cy="5" transform="translate(0,1036.3622)"
sodipodi:rx="6.5" inkscape:connector-curvature="0"
sodipodi:ry="4" id="path2995-6"
d="M 14,5 A 6.5,4 0 1 1 1,5 6.5,4 0 1 1 14,5 z" d="m 1,8 c 0,0 2,4 7,4 5,0 7,-4 7,-4"
transform="matrix(1.0769231,0,0,1,-0.0769231,1039.3622)" /> style="fill:#ffffff;fill-opacity:1;stroke:none" />
<path
sodipodi:nodetypes="czc"
inkscape:connector-curvature="0"
id="path2995-5-1"
d="m 1,1044.3622 c 0,0 2,-4 7,-4 5,0 7,4 7,4"
style="fill:#ffffff;fill-opacity:1;stroke:none" />
</g>
<path <path
sodipodi:type="arc" sodipodi:type="arc"
style="fill:#ffff00;fill-opacity:1;stroke:none" style="fill:#ffff00;fill-opacity:1;stroke:none"
@ -109,7 +116,7 @@
sodipodi:cy="8" sodipodi:cy="8"
sodipodi:rx="4" sodipodi:rx="4"
sodipodi:ry="4" sodipodi:ry="4"
d="M 9,8 A 4,4 0 1 1 1,8 4,4 0 1 1 9,8 z" d="M 9,8 C 9,10.209139 7.209139,12 5,12 2.790861,12 1,10.209139 1,8 1,5.790861 2.790861,4 5,4 7.209139,4 9,5.790861 9,8 z"
transform="translate(3,1036.3622)" /> transform="translate(3,1036.3622)" />
<path <path
sodipodi:type="arc" sodipodi:type="arc"
@ -119,17 +126,23 @@
sodipodi:cy="8" sodipodi:cy="8"
sodipodi:rx="2" sodipodi:rx="2"
sodipodi:ry="2" sodipodi:ry="2"
d="m -3,8 a 2,2 0 1 1 -4,0 2,2 0 1 1 4,0 z" d="m -3,8 c 0,1.1045695 -0.8954305,2 -2,2 -1.1045695,0 -2,-0.8954305 -2,-2 0,-1.1045695 0.8954305,-2 2,-2 1.1045695,0 2,0.8954305 2,2 z"
transform="translate(13,1036.3622)" /> transform="translate(13,1036.3622)" />
<path <g
sodipodi:type="arc" id="g3783">
style="fill:none;fill-opacity:1;stroke:#000000;stroke-opacity:1" <path
id="path3077" sodipodi:nodetypes="czc"
sodipodi:cx="7.5" transform="translate(0,1036.3622)"
sodipodi:cy="5" inkscape:connector-curvature="0"
sodipodi:rx="6.5" id="path2995"
sodipodi:ry="4" d="m 1,8 c 0,0 2,4 7,4 5,0 7,-4 7,-4"
d="M 14,5 A 6.5,4 0 1 1 1,5 6.5,4 0 1 1 14,5 z" style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
transform="matrix(1.0769231,0,0,1,-0.07692325,1039.3622)" /> <path
sodipodi:nodetypes="czc"
inkscape:connector-curvature="0"
id="path2995-5"
d="m 1,1044.3622 c 0,0 2,-4 7,-4 5,0 7,4 7,4"
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
</g>
</g> </g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

121
textures/src/eye_closed.svg Normal file
View File

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="eye_closed.svg"
inkscape:export-filename="/home/ben/progs/minetest/minetest-bewarethedark/textures/bewarethedark_eye.png"
inkscape:export-xdpi="135"
inkscape:export-ydpi="135">
<defs
id="defs4">
<inkscape:path-effect
effect="spiro"
id="path-effect3012"
is_visible="true" />
<inkscape:path-effect
effect="spiro"
id="path-effect3824"
is_visible="true" />
<inkscape:path-effect
effect="spiro"
id="path-effect3820"
is_visible="true" />
<inkscape:path-effect
effect="spiro"
id="path-effect3761"
is_visible="true" />
<inkscape:path-effect
effect="spiro"
id="path-effect3761-8"
is_visible="true" />
<inkscape:path-effect
effect="spiro"
id="path-effect3012-7"
is_visible="true" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#838181"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:zoom="31.678384"
inkscape:cx="8.065046"
inkscape:cy="8.0849876"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:window-width="1366"
inkscape:window-height="744"
inkscape:window-x="0"
inkscape:window-y="24"
inkscape:window-maximized="1"
inkscape:snap-global="true"
inkscape:snap-bbox="true"
inkscape:snap-bbox-midpoints="true">
<inkscape:grid
type="xygrid"
id="grid3755"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-1036.3622)">
<path
style="fill:#ffffff;fill-opacity:1;stroke:none"
d="m 1,1044.3622 c 0,0 2,4 7,4 5,0 7,-4 7,-4 0,0 -3,2 -7,2 -4,0 -7,-2 -7,-2 z"
id="path2995-6"
inkscape:connector-curvature="0"
sodipodi:nodetypes="czczc" />
<path
transform="translate(3,1036.3622)"
style="fill:#ffff00;fill-opacity:1;stroke:none"
clip-path="none"
d="M 8.6856602,9.5569805 C 8.4832492,10.035534 8.1903559,10.466498 7.8284271,10.828427 7.1045695,11.552285 6.1045695,12 5,12 3.8954305,12 2.8954305,11.552285 2.1715729,10.828427 1.8096441,10.466498 1.5167508,10.035534 1.3143398,9.5569805 4,10 6,10 8.6856602,9.5569805 z"
id="path3866"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cssscc" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1"
d="m 1,1044.3622 c 0,0 2,4 7,4 5,0 7,-4 7,-4"
id="path2995"
inkscape:connector-curvature="0"
sodipodi:nodetypes="czc" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1"
d="m 1,1044.3622 c 0,0 2,2 7,2 5,0 7,-2 7,-2"
id="path2995-5"
inkscape:connector-curvature="0"
sodipodi:nodetypes="czc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.9 KiB