forked from mtcontrib/minetest_hudbars
Add alternative statbar display modes
For those nostalgists. ;-)
This commit is contained in:
parent
897d40e47b
commit
4ac3b25539
11
README.txt
11
README.txt
|
@ -58,7 +58,15 @@ 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.
|
||||||
|
|
||||||
|
- hudbars_bar_type: Specifies the style of bars. You can select between the default progress-bar-like bars and the good old statbars
|
||||||
|
like you know from vanilla Minetest. Note that the classic and modern statbars are still a little bit experimental.
|
||||||
|
These values are possible:
|
||||||
|
- progress_bar: A horizontal progress-bar-like bar with a label, showing numerical value (current, maximum), and an icon.
|
||||||
|
These bars usually convey the most information. This is the default and recommended value..
|
||||||
|
- statbar_classic: Classic statbar, like in vanilla Minetest. Made out of up to 20 half-symbols. Those bars represent the vague ratio between
|
||||||
|
the current value and the maximum value. 1 half-symbol stands for approximately 5% of the maximum value.
|
||||||
|
- statbar_modern: Like the classic statbar, but also supports background images, this kind of statbar may be considered to be more user-friendly
|
||||||
|
than the classic statbar. This bar type closely resembles the [hud] mod.
|
||||||
API:
|
API:
|
||||||
----
|
----
|
||||||
The API is used to add your own custom HUD bars.
|
The API is used to add your own custom HUD bars.
|
||||||
|
@ -68,6 +76,7 @@ Documentation for the API of this mod can be found in API.md.
|
||||||
License of textures:
|
License of textures:
|
||||||
--------------------
|
--------------------
|
||||||
hudbars_icon_health.png - celeron55 (CC BY-SA 3.0), modified by BlockMen
|
hudbars_icon_health.png - celeron55 (CC BY-SA 3.0), modified by BlockMen
|
||||||
|
hudbars_bgicon_health.png - celeron55 (CC BY-SA 3.0), modified by BlockMen
|
||||||
hudbars_icon_breath.png - kaeza (WTFPL), modified by BlockMen
|
hudbars_icon_breath.png - kaeza (WTFPL), modified by BlockMen
|
||||||
hudbars_bar_health.png - Wuzzy (WTFPL)
|
hudbars_bar_health.png - Wuzzy (WTFPL)
|
||||||
hudbars_bar_breath.png - Wuzzy (WTFPL)
|
hudbars_bar_breath.png - Wuzzy (WTFPL)
|
||||||
|
|
123
init.lua
123
init.lua
|
@ -41,6 +41,17 @@ if alignment_pattern ~= nil then
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
hb.settings.bar_type = "progress_bar"
|
||||||
|
local bar_type = minetest.setting_getbool("hudbars_bar_type")
|
||||||
|
if bar_type ~= nil then
|
||||||
|
hb.settings.bar_type = bar_type
|
||||||
|
if bar_type ~= "progress_bar" and bar_type ~= "statbar_classic" and bar_type ~= "statbar_modern" then
|
||||||
|
minetest.log("error", "[hudbars] Invalid value for hudbars_alignment_pattern! Using default (progress_bar).")
|
||||||
|
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
|
||||||
|
@ -67,7 +78,11 @@ function hb.value_to_barlength(value, max)
|
||||||
if max == 0 then
|
if max == 0 then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return math.ceil((value/max) * hb.settings.max_bar_length)
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
|
return math.ceil((value/max) * hb.settings.max_bar_length)
|
||||||
|
else
|
||||||
|
return math.ceil((value/max) * 20)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -147,41 +162,63 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
|
||||||
barnumber = hb.value_to_barlength(start_value, start_max)
|
barnumber = hb.value_to_barlength(start_value, start_max)
|
||||||
text = string.format(format_string, label, start_value, start_max)
|
text = string.format(format_string, label, start_value, start_max)
|
||||||
end
|
end
|
||||||
ids.bg = player:hud_add({
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
hud_elem_type = "image",
|
ids.bg = player:hud_add({
|
||||||
position = pos,
|
|
||||||
scale = bgscale,
|
|
||||||
text = "hudbars_bar_background.png",
|
|
||||||
alignment = {x=1,y=1},
|
|
||||||
offset = { x = offset.x - 1, y = offset.y - 1 },
|
|
||||||
})
|
|
||||||
if textures.icon ~= nil then
|
|
||||||
ids.icon = player:hud_add({
|
|
||||||
hud_elem_type = "image",
|
hud_elem_type = "image",
|
||||||
position = pos,
|
position = pos,
|
||||||
scale = iconscale,
|
scale = bgscale,
|
||||||
text = textures.icon,
|
text = "hudbars_bar_background.png",
|
||||||
alignment = {x=-1,y=1},
|
alignment = {x=1,y=1},
|
||||||
offset = { x = offset.x - 3, y = offset.y },
|
offset = { x = offset.x - 1, y = offset.y - 1 },
|
||||||
})
|
})
|
||||||
|
if textures.icon ~= nil then
|
||||||
|
ids.icon = player:hud_add({
|
||||||
|
hud_elem_type = "image",
|
||||||
|
position = pos,
|
||||||
|
scale = iconscale,
|
||||||
|
text = textures.icon,
|
||||||
|
alignment = {x=-1,y=1},
|
||||||
|
offset = { x = offset.x - 3, y = offset.y },
|
||||||
|
})
|
||||||
|
end
|
||||||
|
elseif hb.settings.bar_type == "statbar_modern" then
|
||||||
|
if textures.bgicon ~= nil then
|
||||||
|
ids.bg = player:hud_add({
|
||||||
|
hud_elem_type = "statbar",
|
||||||
|
position = pos,
|
||||||
|
scale = bgscale,
|
||||||
|
text = textures.bgicon,
|
||||||
|
number = 20,
|
||||||
|
alignment = {x=-1,y=-1},
|
||||||
|
offset = { x = offset.x, y = offset.y },
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local bar_image
|
||||||
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
|
bar_image = textures.bar
|
||||||
|
elseif hb.settings.bar_type == "statbar_classic" or hb.settings.bar_type == "statbar_modern" then
|
||||||
|
bar_image = textures.icon
|
||||||
end
|
end
|
||||||
ids.bar = player:hud_add({
|
ids.bar = player:hud_add({
|
||||||
hud_elem_type = "statbar",
|
hud_elem_type = "statbar",
|
||||||
position = pos,
|
position = pos,
|
||||||
text = textures.bar,
|
text = bar_image,
|
||||||
number = barnumber,
|
number = barnumber,
|
||||||
alignment = {x=-1,y=-1},
|
alignment = {x=-1,y=-1},
|
||||||
offset = offset,
|
offset = offset,
|
||||||
})
|
})
|
||||||
ids.text = player:hud_add({
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
hud_elem_type = "text",
|
ids.text = player:hud_add({
|
||||||
position = pos,
|
hud_elem_type = "text",
|
||||||
text = text,
|
position = pos,
|
||||||
alignment = {x=1,y=1},
|
text = text,
|
||||||
number = text_color,
|
alignment = {x=1,y=1},
|
||||||
direction = 0,
|
number = text_color,
|
||||||
offset = { x = offset.x + 2, y = offset.y },
|
direction = 0,
|
||||||
|
offset = { x = offset.x + 2, y = offset.y },
|
||||||
})
|
})
|
||||||
|
end
|
||||||
-- Do not forget to update hb.get_hudbar_state if you add new fields to the state table
|
-- Do not forget to update hb.get_hudbar_state if you add new fields to the state table
|
||||||
state.hidden = start_hidden
|
state.hidden = start_hidden
|
||||||
state.value = start_value
|
state.value = start_value
|
||||||
|
@ -264,7 +301,7 @@ function hb.change_hudbar(player, identifier, new_value, new_max_value)
|
||||||
end
|
end
|
||||||
|
|
||||||
if hudtable.hudstate[name].hidden == false then
|
if hudtable.hudstate[name].hidden == false then
|
||||||
if max_changed then
|
if max_changed and hb.settings.bar_type == "progress_bar" then
|
||||||
if hudtable.hudstate[name].max == 0 then
|
if hudtable.hudstate[name].max == 0 then
|
||||||
player:hud_change(hudtable.hudids[name].bg, "scale", {x=0,y=0})
|
player:hud_change(hudtable.hudids[name].bg, "scale", {x=0,y=0})
|
||||||
else
|
else
|
||||||
|
@ -279,10 +316,12 @@ function hb.change_hudbar(player, identifier, new_value, new_max_value)
|
||||||
hudtable.hudstate[name].barlength = new_barlength
|
hudtable.hudstate[name].barlength = new_barlength
|
||||||
end
|
end
|
||||||
|
|
||||||
local new_text = string.format(hudtable.format_string, hudtable.label, new_value, new_max_value)
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
if new_text ~= hudtable.hudstate[name].text then
|
local new_text = string.format(hudtable.format_string, hudtable.label, new_value, new_max_value)
|
||||||
player:hud_change(hudtable.hudids[name].text, "text", new_text)
|
if new_text ~= hudtable.hudstate[name].text then
|
||||||
hudtable.hudstate[name].text = new_text
|
player:hud_change(hudtable.hudids[name].text, "text", new_text)
|
||||||
|
hudtable.hudstate[name].text = new_text
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -292,12 +331,14 @@ function hb.hide_hudbar(player, identifier)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local hudtable = hb.get_hudtable(identifier)
|
local hudtable = hb.get_hudtable(identifier)
|
||||||
if(hudtable.hudstate[name].hidden == false) then
|
if(hudtable.hudstate[name].hidden == false) then
|
||||||
if hudtable.hudids[name].icon ~= nil then
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
player:hud_change(hudtable.hudids[name].icon, "scale", {x=0,y=0})
|
if hudtable.hudids[name].icon ~= nil then
|
||||||
|
player:hud_change(hudtable.hudids[name].icon, "scale", {x=0,y=0})
|
||||||
|
end
|
||||||
|
player:hud_change(hudtable.hudids[name].bg, "scale", {x=0,y=0})
|
||||||
|
player:hud_change(hudtable.hudids[name].text, "text", "")
|
||||||
end
|
end
|
||||||
player:hud_change(hudtable.hudids[name].bg, "scale", {x=0,y=0})
|
|
||||||
player:hud_change(hudtable.hudids[name].bar, "number", 0)
|
player:hud_change(hudtable.hudids[name].bar, "number", 0)
|
||||||
player:hud_change(hudtable.hudids[name].text, "text", "")
|
|
||||||
hudtable.hudstate[name].hidden = true
|
hudtable.hudstate[name].hidden = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -309,14 +350,16 @@ function hb.unhide_hudbar(player, identifier)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local value = hudtable.hudstate[name].value
|
local value = hudtable.hudstate[name].value
|
||||||
local max = hudtable.hudstate[name].max
|
local max = hudtable.hudstate[name].max
|
||||||
if hudtable.hudids[name].icon ~= nil then
|
if hb.settings.bar_type == "progress_bar" then
|
||||||
player:hud_change(hudtable.hudids[name].icon, "scale", {x=1,y=1})
|
if hudtable.hudids[name].icon ~= nil then
|
||||||
end
|
player:hud_change(hudtable.hudids[name].icon, "scale", {x=1,y=1})
|
||||||
if hudtable.hudstate[name].max ~= 0 then
|
end
|
||||||
player:hud_change(hudtable.hudids[name].bg, "scale", {x=1,y=1})
|
if hudtable.hudstate[name].max ~= 0 then
|
||||||
|
player:hud_change(hudtable.hudids[name].bg, "scale", {x=1,y=1})
|
||||||
|
end
|
||||||
|
player:hud_change(hudtable.hudids[name].text, "text", tostring(string.format(hudtable.format_string, hudtable.label, value, max)))
|
||||||
end
|
end
|
||||||
player:hud_change(hudtable.hudids[name].bar, "number", hb.value_to_barlength(value, max))
|
player:hud_change(hudtable.hudids[name].bar, "number", hb.value_to_barlength(value, max))
|
||||||
player:hud_change(hudtable.hudids[name].text, "text", tostring(string.format(hudtable.format_string, hudtable.label, value, max)))
|
|
||||||
hudtable.hudstate[name].hidden = false
|
hudtable.hudstate[name].hidden = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -336,7 +379,7 @@ end
|
||||||
|
|
||||||
--register built-in HUD bars
|
--register built-in HUD bars
|
||||||
if minetest.setting_getbool("enable_damage") then
|
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("health", 0xFFFFFF, "Health", { bar = "hudbars_bar_health.png", icon = "hudbars_icon_health.png", bgicon = "hudbars_bgicon_health.png" }, 20, 20, false)
|
||||||
hb.register_hudbar("breath", 0xFFFFFF, "Breath", { bar = "hudbars_bar_breath.png", icon = "hudbars_icon_breath.png" }, 10, 10, true)
|
hb.register_hudbar("breath", 0xFFFFFF, "Breath", { bar = "hudbars_bar_breath.png", icon = "hudbars_icon_breath.png" }, 10, 10, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
BIN
textures/hudbars_bgicon_health.png
Normal file
BIN
textures/hudbars_bgicon_health.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 302 B |
Loading…
Reference in New Issue
Block a user