Add preliminary display mode setting

Intentionally not in README.txt yet, because the positions cannot be set in minetest.conf yet.
This commit is contained in:
Wuzzy 2015-05-19 22:28:55 +02:00
parent fc66c4f0a5
commit b68af069a4
2 changed files with 41 additions and 7 deletions

View File

@ -58,6 +58,7 @@ This mod can be configured by editing minetest.conf. Currently, the following se
breath=0, health=1 breath=0, health=1
This places the breath bar at the left side, and the health bar to the right side. This places the breath bar at the left side, and the health bar to the right side.
API: API:
---- ----
The API is used to add your own custom HUD bars. The API is used to add your own custom HUD bars.

View File

@ -22,6 +22,25 @@ hb.settings.start_offset_right = { x = 15, y = -86 }
hb.settings.vmargin = 24 hb.settings.vmargin = 24
hb.settings.tick = 0.1 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 hb.settings.autohide_breath = true
local autohide_breath = minetest.setting_getbool("hudbars_autohide_breath") local autohide_breath = minetest.setting_getbool("hudbars_autohide_breath")
if autohide_breath ~= nil then if autohide_breath ~= nil then
@ -75,18 +94,32 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
local pos, offset local pos, offset
local index = math.floor(hb.get_hudbar_position_index(identifier)) local index = math.floor(hb.get_hudbar_position_index(identifier))
hb.registered_slots[index] = true hb.registered_slots[index] = true
if index % 2 == 0 then if hb.settings.display_mode == "stack_up" then
pos = hb.settings.pos_left pos = hb.settings.pos_left
offset = { offset = {
x = hb.settings.start_offset_left.x, 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 else
pos = hb.settings.pos_right if index % 2 == 0 then
offset = { pos = hb.settings.pos_left
x = hb.settings.start_offset_right.x, offset = {
y = hb.settings.start_offset_right.y - hb.settings.vmargin * ((index-1)/2) 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 end
if format_string == nil then if format_string == nil then
format_string = "%s: %d/%d" format_string = "%s: %d/%d"