voxelcore/res/layouts/pages/settings_display.xml.lua
loki5512344 33e132a231 Share settings page helpers, add GUI cursor/scale API
- move create_trackbar_setting/update_trackbar_label/create_checkbox from
  settings_audio/display/graphics pages to core:settings_common module
- GUI scale trackbar shows the really applied scale, e.g. '3 (effective 2)'
- add gui.get_scale(), gui.get_max_scale(), gui.get_cursor_pos() (UI units);
  document that input.get_mouse_pos() returns window pixels
- InventoryView default color is defined once (InventoryView::DEFAULT_COLOR)
  instead of duplicated literals; 'color' attribute still overrides it
2026-10-03 13:12:30 +00:00

50 lines
2 KiB
Lua

local tostring_overrides = {}
tostring_overrides["display.framerate"] = function(x)
if x == -1 then
return gui.str("V-Sync")
elseif x == 0 then
return gui.str("Unlimited")
else
return tostring(x)
end
end
tostring_overrides["display.gui-scale"] = function(x)
-- scale is limited by the window size, show what is really applied
local effective = gui.get_max_scale()
if x > 0 then
effective = math.min(x, effective)
end
if x == 0 then
return string.format("%s (%d)", gui.str("Auto"), effective)
elseif effective < x then
return string.format("%d (%s %d)", x, gui.str("Effective"), effective)
end
return tostring(x)
end
local settings = require "core:settings_common".new(document, {tostring_overrides=tostring_overrides})
-- templates call these functions by name, so they must be global
create_trackbar_setting = settings.create_trackbar_setting
update_trackbar_label = settings.update_trackbar_label
create_checkbox = settings.create_checkbox
function on_open()
create_trackbar_setting("camera.fov", "FOV", 1, "°")
create_trackbar_setting("display.framerate", "Framerate", 1, "", "", true)
create_trackbar_setting("display.gui-scale", "GUI Scale", 1, "", "display.gui-scale.tooltip", true)
document.root:add(string.format(
"<select context='settings' onselect='function(opt) app.set_setting(\"display.window-mode\", tonumber(opt)) end' selected='%s'>"..
"<option value='0'>@Windowed</option>"..
"<option value='1'>@Fullscreen</option>"..
"<option value='2'>@Borderless</option>"..
"</select>", app.get_setting("display.window-mode"))
)
create_checkbox("camera.shaking", "Camera Shaking")
create_checkbox("camera.inertia", "Camera Inertia")
create_checkbox("camera.fov-effects", "Camera FOV Effects")
create_checkbox("display.limit-fps-iconified", "Limit Background FPS")
create_trackbar_setting("graphics.gamma", "Gamma", 0.05, "", "graphics.gamma.tooltip")
end