tibia-client/modules/client_options/options.lua

72 lines
1.6 KiB
Lua
Raw Normal View History

Options = {}
-- private variables
local options
2011-11-17 01:12:11 +01:00
local fpsEnabled = false
local vsyncEnabled = false
function getConfig(name, default)
if g_configs.exists(name) then
2011-12-07 01:31:55 +01:00
local val = g_configs.get(name):trim()
2011-11-17 01:12:11 +01:00
if val == 'true' or val == 'false' then
return toboolean(val)
else
return val
end
else
if default ~= nil then
g_configs.set(name, default)
2011-11-17 01:12:11 +01:00
return default
else
return nil
end
end
end
function setConfig(name, value)
g_configs.set(name, tostring(value))
2011-11-17 01:12:11 +01:00
end
-- private functions
function Options.enableVsync(on)
vsyncEnabled = on
g_window.setVerticalSync(on)
2011-11-17 01:12:11 +01:00
setConfig('vsync', on)
end
function Options.enableFps(on)
fpsEnabled = on
local frameCounter = rootWidget:recursiveGetChildById('frameCounter')
2011-11-17 01:12:11 +01:00
frameCounter:setVisible(on)
setConfig('showfps', on)
end
-- public functions
function Options.create()
options = displayUI('options.otui', { locked = true })
2011-11-17 01:12:11 +01:00
local fpsBox = options:getChildById('fpsCheckBox')
local vsyncBox = options:getChildById('vsyncCheckBox')
fpsBox:setChecked(fpsEnabled)
vsyncBox:setChecked(vsyncEnabled)
fpsBox.onCheckChange = function(self, checked) Options.enableFps(checked) end
vsyncBox.onCheckChange = function(self, checked) Options.enableVsync(checked) end
end
function Options.load()
Options.enableVsync(getConfig('vsync', true))
Options.enableFps(getConfig('showfps', true))
end
function Options.destroy()
options:destroy()
options = nil
end
function Options.openWebpage()
displayErrorBox("Error", "Not implemented yet")
2011-11-17 01:12:11 +01:00
end
addEvent(Options.load)