mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 16:13:46 +01:00
Add viewing range GUI setting
This commit is contained in:
parent
e62eac49d5
commit
caf0df8924
@ -199,6 +199,33 @@ local function scrollbar_to_gui_scale(value)
|
||||
return 1
|
||||
end
|
||||
|
||||
local function viewing_range_min_to_scrollbar()
|
||||
local current_value_min = tonumber(core.setting_get("viewing_range_nodes_min"))
|
||||
|
||||
if (current_value_min == nil) then
|
||||
return 0
|
||||
end
|
||||
return current_value_min * 2
|
||||
end
|
||||
|
||||
local function viewing_range_max_to_scrollbar()
|
||||
local current_value_max = tonumber(core.setting_get("viewing_range_nodes_max"))
|
||||
|
||||
if (current_value_max == nil) then
|
||||
return 0
|
||||
end
|
||||
return current_value_max * 2
|
||||
end
|
||||
|
||||
local function scrollbar_to_viewing_range(value)
|
||||
value = tonumber(value)
|
||||
|
||||
if (value <= 1000) then
|
||||
return value / 2
|
||||
end
|
||||
return 35
|
||||
end
|
||||
|
||||
local function formspec(tabview, name, tabdata)
|
||||
local tab_string =
|
||||
"box[0,0;3.5,4.0;#999999]" ..
|
||||
@ -282,6 +309,44 @@ local function formspec(tabview, name, tabdata)
|
||||
"textlist[8.33,2.7;4,1;;#888888" .. fgettext("Waving Leaves") .. ";0;true]" ..
|
||||
"textlist[8.33,3.2;4,1;;#888888" .. fgettext("Waving Plants") .. ";0;true]"
|
||||
end
|
||||
|
||||
local get_vrange_min = core.setting_get("viewing_range_nodes_min")
|
||||
local get_vrange_max = core.setting_get("viewing_range_nodes_max")
|
||||
|
||||
if core.setting_getbool("viewing_range_auto") then
|
||||
tab_string = tab_string ..
|
||||
"box[3.75,3.5;3.75,2;#999999]" ..
|
||||
"label[3.85,3.5;" .. fgettext("Viewing Range :") .. "]" ..
|
||||
"label[3.85,4;" .. fgettext("Min.") .. "]" ..
|
||||
"scrollbar[4.65,4.05;2.75,0.4;sb_viewing_range_min;horizontal;" ..
|
||||
viewing_range_min_to_scrollbar() .. "]" ..
|
||||
"tooltip[sb_viewing_range_min;" .. fgettext("Minimal Viewing Range: $1 nodes",
|
||||
get_vrange_min) .. "]" ..
|
||||
"checkbox[3.85,4.8;cb_vrange_auto_adjust;" .. fgettext("Auto-adjust") .. ";" ..
|
||||
dump(core.setting_getbool("viewing_range_auto")) .. "]"..
|
||||
"label[3.85,4.5;" .. fgettext("Max.") .. "]" ..
|
||||
"scrollbar[4.65,4.55;2.75,0.4;sb_viewing_range_max;horizontal;" ..
|
||||
viewing_range_max_to_scrollbar() .. "]" ..
|
||||
"tooltip[sb_viewing_range_max;" .. fgettext("Maximal Viewing Range: $1 nodes",
|
||||
get_vrange_max) .. "]"
|
||||
|
||||
if (get_vrange_min == nil and get_vrange_min > get_vrange_max) then
|
||||
core.setting_set("viewing_range_nodes_min", get_vrange_max)
|
||||
end
|
||||
elseif (core.setting_getbool("viewing_range_auto") == nil or
|
||||
core.setting_getbool("viewing_range_auto") == false) then
|
||||
tab_string = tab_string ..
|
||||
"box[3.75,3.5;3.75,1.5;#999999]" ..
|
||||
"label[3.85,3.5;" .. fgettext("Viewing Range :") .. "]" ..
|
||||
"label[3.85,4;" .. fgettext("Fixed") .. "]" ..
|
||||
"scrollbar[4.65,4.05;2.75,0.4;sb_viewing_range_fixed;horizontal;" ..
|
||||
viewing_range_min_to_scrollbar() .. "]" ..
|
||||
"tooltip[sb_viewing_range_fixed;" .. fgettext("Fixed Viewing Range: $1 nodes",
|
||||
get_vrange_min) .. "]" ..
|
||||
"checkbox[3.85,4.3;cb_vrange_auto_adjust;" .. fgettext("Auto-adjust") .. ";" ..
|
||||
dump(core.setting_getbool("viewing_range_auto")) .. "]"
|
||||
end
|
||||
|
||||
return tab_string
|
||||
end
|
||||
|
||||
@ -311,7 +376,10 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
|
||||
core.setting_set("enable_node_highlighting", fields["cb_node_highlighting"])
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["cb_vrange_auto_adjust"] then
|
||||
core.setting_set("viewing_range_auto", fields["cb_vrange_auto_adjust"])
|
||||
return true
|
||||
end
|
||||
if fields["cb_shaders"] then
|
||||
if (core.setting_get("video_driver") == "direct3d8"
|
||||
or core.setting_get("video_driver") == "direct3d9") then
|
||||
@ -353,6 +421,23 @@ local function handle_settings_buttons(this, fields, tabname, tabdata)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
for k, range in pairs({"min", "max", "fixed"}) do
|
||||
if fields["sb_viewing_range_"..range] then
|
||||
local event = core.explode_scrollbar_event(fields["sb_viewing_range_"..range])
|
||||
local tosave = string.format("%d", scrollbar_to_viewing_range(event.value))
|
||||
|
||||
if event.type == "CHG" and k < 3 then
|
||||
core.setting_set("viewing_range_nodes_"..range, tosave)
|
||||
return true
|
||||
elseif event.type == "CHG" and k == 3 then
|
||||
core.setting_set("viewing_range_nodes_min", tosave)
|
||||
core.setting_set("viewing_range_nodes_max", tosave)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if fields["btn_change_keys"] then
|
||||
core.show_keys_menu()
|
||||
return true
|
||||
|
Loading…
Reference in New Issue
Block a user