From af4ff618bb9e50cef1d4300cbb36f9ce4582e20f Mon Sep 17 00:00:00 2001 From: crabman77 Date: Fri, 19 Jun 2015 13:19:09 +0200 Subject: [PATCH] added hudbars custom position possibility to define position("health" in left or "sprint" in right, etc) in .conf refactor code position, load config before registrer default hudbars(health,breath) --- mods/hudbars/hudbars.conf | 10 ++++++++++ mods/hudbars/init.lua | 33 +++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100755 mods/hudbars/hudbars.conf diff --git a/mods/hudbars/hudbars.conf b/mods/hudbars/hudbars.conf new file mode 100755 index 00000000..ab48b42d --- /dev/null +++ b/mods/hudbars/hudbars.conf @@ -0,0 +1,10 @@ +-- if custom==true, use custom position +-- X 0=left, 1=right +--Y 0,1,2 = down--> up +hb.settings.custom.custom = true +hb.settings.custom.health = { x = 0, y = 0 } +hb.settings.custom.satiation = { x = 1, y = 0 } +hb.settings.custom.sprint = { x = 0, y = 1 } +hb.settings.custom.mana = { x = 1, y = 1 } +hb.settings.custom.armor = { x = 0, y = 2 } +hb.settings.custom.breath = { x = 1, y = 2 } diff --git a/mods/hudbars/init.lua b/mods/hudbars/init.lua index eab13c8b..cd5e6557 100755 --- a/mods/hudbars/init.lua +++ b/mods/hudbars/init.lua @@ -6,7 +6,7 @@ hb.hudtables = {} hb.hudbars_count = 0 hb.settings = {} - +hb.settings.custom = {} --MFF (crabman|19/06/15) add custom pos -- default settings hb.settings.max_bar_length = 160 @@ -37,7 +37,24 @@ end function hb.register_hudbar(identifier, text_color, label, textures, default_start_value, default_start_max, default_start_hidden, format_string) local hudtable = {} local pos, offset - if hb.hudbars_count % 2 == 0 then + + --MFF (crabman|19/06/15)|DEBUT add custom pos + if hb.settings.custom.custom and hb.settings.custom[identifier] ~= nil then + if hb.settings.custom[identifier].x == 0 then + pos = hb.settings.pos_left + offset = { + x = hb.settings.start_offset_left.x, + y = hb.settings.start_offset_left.y - hb.settings.vmargin * math.floor(hb.settings.custom[identifier].y) + } + else + pos = hb.settings.pos_right + offset = { + x = hb.settings.start_offset_right.x, + y = hb.settings.start_offset_right.y - hb.settings.vmargin * math.floor(hb.settings.custom[identifier].y) + } + end + --MFF (crabman|19/06/15) /FIN + elseif hb.hudbars_count % 2 == 0 then pos = hb.settings.pos_left offset = { x = hb.settings.start_offset_left.x, @@ -263,12 +280,6 @@ function hb.get_hudbar_state(player, identifier) return copy end ---register built-in HUD bars -if minetest.setting_getbool("enable_damage") then - hb.register_hudbar("health", 0xFFFFFF, "Health", { bar = "hudbars_bar_health.png", icon = "hudbars_icon_health.png" }, 20, 20, false) - hb.register_hudbar("breath", 0xFFFFFF, "Breath", { bar = "hudbars_bar_breath.png", icon = "hudbars_icon_breath.png" }, 10, 10, true) -end - --load custom settings local set = io.open(minetest.get_modpath("hudbars").."/hudbars.conf", "r") if set then @@ -276,6 +287,12 @@ if set then set:close() end +--register built-in HUD bars +if minetest.setting_getbool("enable_damage") then + hb.register_hudbar("health", 0xFFFFFF, "Health", { bar = "hudbars_bar_health.png", icon = "hudbars_icon_health.png" }, 20, 20, false) + hb.register_hudbar("breath", 0xFFFFFF, "Breath", { bar = "hudbars_bar_breath.png", icon = "hudbars_icon_breath.png" }, 10, 10, true) +end + local function hide_builtin(player) local flags = player:hud_get_flags() flags.healthbar = false