mirror of
https://repo.or.cz/minetest_hudbars.git
synced 2024-11-28 01:53:46 +01:00
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:
parent
fc66c4f0a5
commit
b68af069a4
@ -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.
|
||||
|
47
init.lua
47
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"
|
||||
|
Loading…
Reference in New Issue
Block a user