diff --git a/README.txt b/README.txt index 5e06c43..f349690 100644 --- a/README.txt +++ b/README.txt @@ -58,6 +58,7 @@ This mod can be configured by editing minetest.conf. Currently, the following se breath=0, health=1 This places the breath bar at the left side, and the health bar to the right side. + API: ---- The API is used to add your own custom HUD bars. diff --git a/init.lua b/init.lua index 3971057..9c03d8e 100644 --- a/init.lua +++ b/init.lua @@ -22,6 +22,25 @@ hb.settings.start_offset_right = { x = 15, y = -86 } hb.settings.vmargin = 24 hb.settings.tick = 0.1 +--[[ +- hudbars_display_mode: This setting changes the way the HUD bars are ordered on the display. You can choose + between a zig-zag pattern or a vertically stacked pattern. + The following values are allowed: + zigzag: Starting from the left bottom, the next is right from the first, + the next is above the first, the next is right of the third, etc. + This is the default. + stack_up: The HUD bars are stacked vertically, going upwards. + stack_down: The HUD bars are stacked vertically. going downwards. +]] +hb.settings.display_mode = "zigzag" +local display_mode = minetest.setting_getbool("hudbars_display_mode") +if display_mode ~= nil then + hb.settings.display_mode = display_mode + if display_mode ~= "zigzag" and display_mode ~= "stack_up" and display_mode ~= "stack_down" then + minetest.log("error", "[hudbars] Invalid value for hudbars_display_mode! Using default (zigzag).") + end +end + hb.settings.autohide_breath = true local autohide_breath = minetest.setting_getbool("hudbars_autohide_breath") if autohide_breath ~= nil then @@ -75,18 +94,32 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta local pos, offset local index = math.floor(hb.get_hudbar_position_index(identifier)) hb.registered_slots[index] = true - if index % 2 == 0 then + if hb.settings.display_mode == "stack_up" then pos = hb.settings.pos_left offset = { x = hb.settings.start_offset_left.x, - y = hb.settings.start_offset_left.y - hb.settings.vmargin * (index/2) + y = hb.settings.start_offset_left.y - hb.settings.vmargin * index + } + elseif hb.settings.display_mode == "stack_down" then + pos = hb.settings.pos_left + offset = { + x = hb.settings.start_offset_left.x, + y = hb.settings.start_offset_left.y + hb.settings.vmargin * index } else - pos = hb.settings.pos_right - offset = { - x = hb.settings.start_offset_right.x, - y = hb.settings.start_offset_right.y - hb.settings.vmargin * ((index-1)/2) - } + if index % 2 == 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 * (index/2) + } + else + pos = hb.settings.pos_right + offset = { + x = hb.settings.start_offset_right.x, + y = hb.settings.start_offset_right.y - hb.settings.vmargin * ((index-1)/2) + } + end end if format_string == nil then format_string = "%s: %d/%d"