This commit is contained in:
kotek900 2024-05-15 07:02:57 +03:00 committed by GitHub
commit 791bbe8890
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 67 additions and 4 deletions

View File

@ -126,6 +126,40 @@ end, is_valid_number)
make.string = make_field(tostring, nil)
function make.slider(setting)
local steps = tonumber(setting.steps) or 100
return {
info_text = setting.comment,
setting = setting,
get_formspec = function(self, avail_w)
local value = core.settings:get(setting.name) or setting.default
local scrollbar_value = (value - setting.min)/(setting.max - setting.min)*steps
self.resettable = true
local setting_label = ("label[0,0.25;%s]"):format(
setting.readable_name)
local scrollbar_options = ("scrollbaroptions[min=0;max=%f;smallstep=1;largestep=10]"):format(
steps)
local scrollbar_formspec = ("scrollbar[0,0.5;%f,0.4;horizontal;%s;%f]"):format(
avail_w - 1, setting.name, scrollbar_value)
local formspec = setting_label..scrollbar_options..scrollbar_formspec
return formspec, 1.1
end,
on_submit = function(self, fields)
local raw_value = core.explode_scrollbar_event(fields[setting.name]).value
local value = (raw_value/steps) * (setting.max - setting.min) + setting.min
core.settings:set(setting.name, tostring(value))
return false
end
}
end
function make.bool(setting)
return {
info_text = setting.comment,

View File

@ -295,6 +295,35 @@ local function parse_setting_line(settings, line, read_all, base_level, allow_se
return
end
if setting_type == "slider" then
local default, min, max, steps = remaining_line:match("^"
-- first 3 floats are required, the last is optional
.. "(" .. CHAR_CLASSES.FLOAT .. "+)" .. CHAR_CLASSES.SPACE .. "*"
.. "(" .. CHAR_CLASSES.FLOAT .. "+)" .. CHAR_CLASSES.SPACE .. "*"
.. "(" .. CHAR_CLASSES.FLOAT .. "+)" .. CHAR_CLASSES.SPACE .. "*"
.. "(" .. CHAR_CLASSES.FLOAT .. "*)"
.."$")
if not default or not tonumber(default) then
return "Invalid float setting"
end
min = tonumber(min)
max = tonumber(max)
table.insert(settings, {
name = name,
readable_name = readable_name,
type = "slider",
default = default,
min = min,
max = max,
steps = steps,
requires = requires,
comment = comment,
})
return
end
if setting_type == "enum" then
local default, values = remaining_line:match("^"
-- first value (default) may be empty (i.e. is optional)

View File

@ -138,7 +138,7 @@ invert_mouse (Invert mouse) bool false
# Mouse sensitivity multiplier.
#
# Requires: keyboard_mouse
mouse_sensitivity (Mouse sensitivity) float 0.2 0.001 10.0
mouse_sensitivity (Mouse sensitivity) slider 0.2 0.001 1.0 500
# Enable mouse wheel (scroll) for item selection in hotbar.
#
@ -666,10 +666,10 @@ enable_volumetric_lighting (Volumetric lighting) bool false
# Volume of all sounds.
# Requires the sound system to be enabled.
sound_volume (Volume) float 0.8 0.0 1.0
sound_volume (Volume) slider 0.8 0.0 1.0
# Volume multiplier when the window is unfocused.
sound_volume_unfocused (Volume when unfocused) float 0.3 0.0 1.0
sound_volume_unfocused (Volume when unfocused) slider 0.3 0.0 1.0
# Whether to mute sounds. You can unmute sounds at any time, unless the
# sound system is disabled (enable_sound=false).
@ -724,7 +724,7 @@ menu_clouds (Clouds in menu) bool true
[**HUD]
# Modifies the size of the HUD elements.
hud_scaling (HUD scaling) float 1.0 0.5 20
hud_scaling (HUD scaling) slider 1.0 0.5 20 1000
# Whether name tag backgrounds should be shown by default.
# Mods may still set a background.