-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add sliders to settings #14469
add sliders to settings #14469
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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.max - setting.min)*steps - setting.min | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpicking: Why not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rest of code in this file also does this so I guess it's better for consistency. |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||
Comment on lines
+154
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value should only be changed if the scrollbar is modified.
Suggested change
Edit: kotek pointed out in Discord that this somehow breaks mouse dragging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reason why mouse dragging stops working is that after returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. normally regenerating the GUI doesn't make scrollbars loose focus, but for some minetest reason it does in the main menu |
||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
end | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
function make.bool(setting) | ||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||
info_text = setting.comment, | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.