Refactor settings

This commit is contained in:
Wuzzy 2015-02-12 05:22:08 +01:00
parent 65c8702e64
commit 197fc56145
3 changed files with 40 additions and 32 deletions

@ -19,7 +19,9 @@ the number.
Furthermore, it enables other mods to add their own custom bars to the HUD, this mod will place them accordingly.
You can create a “hudbars.conf” file to customize the positions of the health and breath bars. Take a look at “hudbars.conf.example” to get more infos.
You can create a “hudbars.conf” file to customize the positions of the health and breath bars. Take a look at “hudbars.conf.example”
to get more infos. The lines starting with “--” are comments, remove the two dashes to activate a setting. Settings which are not
set will use a default value instead.
IMPORTANT:

@ -1,20 +1,24 @@
--##HUD bars example config file##
------------------------------------
-- This example moves the health bar in the top left corner and the hunger bar in the top right corner
-- HUD bars example config file
-------------------------------
-- Currently you can customize the starting position of the first bottom two HUD bars
-- and the vertical margin. That's all.
-- Remove the two dashes to activate a setting. Lua syntax is used.
-- The examples are all equal to the mod defaults
-------------------------------------------------------------------------------------------------------
--!NOTICE!--
-- >>if damage is disabled neither health bar nor breath bar is shown
-- Vertical space between two HUD bars
-- hb.settings.vmargin = 24
--
-- health bar
--
HUD_HEALTH_POS = {x=0,y=0} --min 0, max 1
HUD_HEALTH_OFFSET = {x=5,y=30} --offset in pixel
-- Pos of the first HUD bar the the left (“pos”, as in hud definition of hud_add of Minetest Lua API)
-- hb.settings.pos_left = { x=0.5, y=1 }
--
-- breath bar
--
HUD_AIR_POS = {x=0.5,y=1} --min 0, max 1
HUD_AIR_OFFSET = {x=15,y=-75} --offset in pixel
-- Pos of the first HUD bar the the right
-- hb.settings.pos_right= { x = 0.5, y = 1 }
-- Offset of the first HUD bar to the left (“offset”, as in HUD definition)
-- hb.settings.start_offset_left = { x = -175, y = -70 }
-- Offset of the first HUD bar to the right
-- hb.settings_start_offset_right = { x = 15, y = -70 }

@ -5,23 +5,25 @@ hb.hudtables = {}
-- number of registered HUD bars
hb.hudbars_count = 0
hb.settings = {}
-- default settings
HUD_BARLENGTH = 160
hb.settings.max_bar_length = 160
-- statbar positions
HUD_START_OFFSET_LEFT = { x = -175, y = -70 }
HUD_START_OFFSET_RIGHT = { x = 15, y = -70 }
HUD_POS_LEFT = { x=0.5, y=1 }
HUD_POS_RIGHT = { x = 0.5, y = 1 }
hb.settings.pos_left = { x=0.5, y=1 }
hb.settings.pos_right= { x = 0.5, y = 1 }
hb.settings.start_offset_left = { x = -175, y = -70 }
hb.settings.start_offset_right = { x = 15, y = -70 }
HUD_VMARGIN = 24
HUD_TICK = 0.1
hb.settings.vmargin = 24
hb.settings.tick = 0.1
function hb.value_to_barlength(value, max)
if max == 0 then
return 0
else
return math.ceil((value/max) * HUD_BARLENGTH)
return math.ceil((value/max) * hb.settings.max_bar_length)
end
end
@ -33,16 +35,16 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
local hudtable = {}
local pos, offset
if hb.hudbars_count % 2 == 0 then
pos = HUD_POS_LEFT
pos = hb.settings.pos_left
offset = {
x = HUD_START_OFFSET_LEFT.x,
y = HUD_START_OFFSET_LEFT.y - HUD_VMARGIN * math.floor(hb.hudbars_count/2)
x = hb.settings.start_offset_left.x,
y = hb.settings.start_offset_left.y - hb.settings.vmargin * math.floor(hb.hudbars_count/2)
}
else
pos = HUD_POS_RIGHT
pos = hb.settings.pos_right
offset = {
x = HUD_START_OFFSET_RIGHT.x,
y = HUD_START_OFFSET_RIGHT.y - HUD_VMARGIN * math.floor((hb.hudbars_count-1)/2)
x = hb.settings.start_offset_right.x,
y = hb.settings.start_offset_right.y - hb.settings.vmargin * math.floor((hb.hudbars_count-1)/2)
}
end
if format_string == nil then
@ -308,8 +310,8 @@ minetest.after(2.5, function()
main_timer = main_timer + dtime
timer = timer + dtime
timer2 = timer2 + dtime
if main_timer > HUD_TICK or timer > 4 then
if main_timer > HUD_TICK then main_timer = 0 end
if main_timer > hb.settings.tick or timer > 4 then
if main_timer > hb.settings.tick then main_timer = 0 end
for _,player in ipairs(minetest.get_connected_players()) do
-- only proceed if damage is enabled
if minetest.setting_getbool("enable_damage") then