summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.txt20
-rw-r--r--changelog.txt2
-rw-r--r--hudbars.conf.example24
-rw-r--r--init.lua97
4 files changed, 76 insertions, 67 deletions
diff --git a/README.txt b/README.txt
index bf7777f..d0dcc1c 100644
--- a/README.txt
+++ b/README.txt
@@ -67,6 +67,26 @@ This mod can be configured by editing minetest.conf. Currently, the following se
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.
+
+- hudbars_vmargin: The vertical distance between two HUD bars in pixels (default: 24)
+- hudbars_tick: The number of seconds between two updates of the HUD bars. Increase this number if you have a slow server (default: 0.1)
+
+Position settings:
+With these settings you can configure the positions of the HUD bars. All settings must be specified as a number.
+The pos settings are specified as a floating-point number between 0 to 1 each, the start_offset settings are
+specified as whole numbers, they specify a number of pixels.
+The left and right variants are used for the zig-zag mode. In the stack_up and stack_down modes, only the left variant is used for
+the base position
+
+- hudbars_pos_left_x, hudbars_pos_left_y: Screen position (x and y) of the left HUD bar in zigzag mode. 0 is left-most/top, 1 is right-most/bottom.
+ Defaults: 0.5 (x) and 1 (y)
+- hudbars_pos_right_x, hudbars_pos_right_y: Same as above, but for the right one.
+ Defaults: 0.5 and 1.
+- hudbars_start_offset_left_x, hudbars_start_offset_left_y: Offset in pixels from the basic screen position specified in hudbars_pos_left_x/hudbars_pos_left_y.
+ Defaults: -175 and -86
+- hudbars_start_offset_right_x, hudbars_start_offset_right_y: Same as above, but for the right one.
+ Defaults: 15 and -86
+
API:
----
The API is used to add your own custom HUD bars.
diff --git a/changelog.txt b/changelog.txt
index 800abd0..dcb355f 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -58,3 +58,5 @@ as of version 2.0.0 of the standard <http://semver.org/>.
- New setting: hudbars_bar_type. You now can change the appearance of the HUD bars.
- New HUD bar types, slightly experimental: Classic statbars and modern [hud]-style statbars
- New experimental/unfinished setting: hudbars_alignment_pattern: You can now make the HUD bars stack vertically instead of the current zig-zag pattern. Note you probably need to change source code to productively use this feature
+- Various position-related HUD bar settings (see README.txt)
+- Remove hudbars.conf support and hudbars.conf.example (was never officially supported anyways)
diff --git a/hudbars.conf.example b/hudbars.conf.example
deleted file mode 100644
index 9ca9451..0000000
--- a/hudbars.conf.example
+++ /dev/null
@@ -1,24 +0,0 @@
--- HUD bars example config file
--------------------------------
--- Currently you can customize the starting position of the first bottom two HUD bars
--- and the vertical margin. That's all.
--- Remove the two dashes to activate a setting. Lua syntax is used.
--- The examples are all equal to the mod defaults
--------------------------------------------------------------------------------------------------------
-
-
--- Vertical space between two HUD bars
--- hb.settings.vmargin = 24
-
--- Pos of the first HUD bar the the left (“pos”, as in hud definition of hud_add of Minetest Lua API)
--- hb.settings.pos_left = { x=0.5, y=1 }
-
--- Pos of the first HUD bar the the right
--- hb.settings.pos_right= { x = 0.5, y = 1 }
-
--- Offset of the first HUD bar to the left (“offset”, as in HUD definition)
--- hb.settings.start_offset_left = { x = -175, y = -70 }
-
--- Offset of the first HUD bar to the right
--- hb.settings_start_offset_right = { x = 15, y = -70 }
-
diff --git a/init.lua b/init.lua
index 56bb2fd..1429a2c 100644
--- a/init.lua
+++ b/init.lua
@@ -10,17 +10,57 @@ hb.registered_slots = {}
hb.settings = {}
--- default settings
+function hb.load_setting(sname, stype, defaultval, valid_values)
+ local sval
+ if stype == "string" then
+ sval = minetest.setting_get(sname)
+ elseif stype == "bool" then
+ sval = minetest.setting_getbool(sname)
+ elseif stype == "number" then
+ sval = tonumber(minetest.setting_get(sname))
+ end
+ if sval ~= nil then
+ if valid_values ~= nil then
+ local valid = false
+ for i=1,#valid_values do
+ if sval == valid_values[i] then
+ valid = true
+ end
+ end
+ if not valid then
+ minetest.log("error", "[hudbars] Invalid value for "..sname.."! Using default value ("..tostring(defaultval)..").")
+ return defaultval
+ else
+ return sval
+ end
+ else
+ return sval
+ end
+ else
+ return defaultval
+ end
+end
+
+-- (hardcoded) default settings
hb.settings.max_bar_length = 160
+hb.settings.statbar_length = 20
-- statbar positions
-hb.settings.pos_left = { x=0.5, y=1 }
-hb.settings.pos_right= { x = 0.5, y = 1 }
-hb.settings.start_offset_left = { x = -175, y = -86 }
-hb.settings.start_offset_right = { x = 15, y = -86 }
-
-hb.settings.vmargin = 24
-hb.settings.tick = 0.1
+hb.settings.pos_left = {}
+hb.settings.pos_right = {}
+hb.settings.start_offset_left = {}
+hb.settings.start_offset_right= {}
+hb.settings.pos_left.x = hb.load_setting("hudbars_pos_left_x", "number", 0.5)
+hb.settings.pos_left.y = hb.load_setting("hudbars_pos_left_y", "number", 1)
+hb.settings.pos_right.x = hb.load_setting("hudbars_pos_right_x", "number", 0.5)
+hb.settings.pos_right.y = hb.load_setting("hudbars_pos_right_y", "number", 1)
+hb.settings.start_offset_left.x = hb.load_setting("hudbars_start_offset_left_x", "number", -175)
+hb.settings.start_offset_left.y = hb.load_setting("hudbars_start_offset_left_y", "number", -86)
+hb.settings.start_offset_right.x = hb.load_setting("hudbars_start_offset_right_x", "number", 15)
+hb.settings.start_offset_right.y = hb.load_setting("hudbars_start_offset_right_y", "number", -86)
+
+hb.settings.vmargin = hb.load_setting("hudbars_tick", "number", 24)
+hb.settings.tick = hb.load_setting("hudbars_tick", "number", 0.1)
--[[
- hudbars_alignment_pattern: This setting changes the way the HUD bars are ordered on the display. You can choose
@@ -32,33 +72,11 @@ hb.settings.tick = 0.1
stack_up: The HUD bars are stacked vertically, going upwards.
stack_down: The HUD bars are stacked vertically, going downwards.
]]
-hb.settings.alignment_pattern = "zigzag"
-local alignment_pattern = minetest.setting_get("hudbars_alignment_pattern")
-if alignment_pattern ~= nil then
- hb.settings.alignment_pattern = alignment_pattern
- if alignment_pattern ~= "zigzag" and alignment_pattern ~= "stack_up" and alignment_pattern ~= "stack_down" then
- hb.settings.alignment_pattern = "zigzag"
- minetest.log("error", "[hudbars] Invalid value for hudbars_alignment_pattern! Using default (zigzag).")
- end
-end
-
-hb.settings.bar_type = "progress_bar"
-local bar_type = minetest.setting_get("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
- hb.settings.bar_type = "progress_bar"
- minetest.log("error", "[hudbars] Invalid value for hudbars_bar_type! Using default (progress_bar).")
- end
-end
-
-
-hb.settings.autohide_breath = true
-local autohide_breath = minetest.setting_getbool("hudbars_autohide_breath")
-if autohide_breath ~= nil then
- hb.settings.autohide_breath = autohide_breath
-end
+-- Misc. settings
+hb.settings.alignment_pattern = hb.load_setting("hudbars_alignment_pattern", "string", "zigzag", {"zigzag", "stack_up", "stack_down"})
+hb.settings.bar_type = hb.load_setting("hudbars_bar_type", "string", "progress_bar", {"progress_bar", "statbar_classic", "statbar_modern"})
+hb.settings.autohide_breath = hb.load_setting("hudbars_autohide_breath", "bool", true)
local sorting = minetest.setting_get("hudbars_sorting")
if sorting ~= nil then
@@ -88,7 +106,7 @@ function hb.value_to_barlength(value, max)
else
local x
if value < 0 then x=-0.5 else x = 0.5 end
- local ret = math.modf((value/max) * 20 + x)
+ local ret = math.modf((value/max) * hb.settings.statbar_length + x)
return ret
end
end
@@ -196,7 +214,7 @@ function hb.register_hudbar(identifier, text_color, label, textures, default_sta
position = pos,
scale = bgscale,
text = textures.bgicon,
- number = 20,
+ number = hb.settings.statbar_length,
alignment = {x=-1,y=-1},
offset = { x = offset.x, y = offset.y },
})
@@ -391,13 +409,6 @@ if minetest.setting_getbool("enable_damage") then
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
- dofile(minetest.get_modpath("hudbars").."/hudbars.conf")
- set:close()
-end
-
local function hide_builtin(player)
local flags = player:hud_get_flags()
flags.healthbar = false