2011-11-03 10:59:11 +01:00
|
|
|
Options = {}
|
|
|
|
|
|
|
|
-- private variables
|
|
|
|
local options
|
2011-11-17 01:12:11 +01:00
|
|
|
local fpsEnabled = false
|
|
|
|
local vsyncEnabled = false
|
|
|
|
|
|
|
|
function getConfig(name, default)
|
2011-12-03 22:41:37 +01:00
|
|
|
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
|
2011-12-03 22:41:37 +01:00
|
|
|
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)
|
2011-12-03 22:41:37 +01:00
|
|
|
g_configs.set(name, tostring(value))
|
2011-11-17 01:12:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- private functions
|
|
|
|
function Options.enableVsync(on)
|
|
|
|
vsyncEnabled = on
|
2011-12-03 22:41:37 +01:00
|
|
|
g_window.setVerticalSync(on)
|
2011-11-17 01:12:11 +01:00
|
|
|
setConfig('vsync', on)
|
|
|
|
end
|
|
|
|
|
|
|
|
function Options.enableFps(on)
|
|
|
|
fpsEnabled = on
|
|
|
|
local frameCounter = UI.root:recursiveGetChildById('frameCounter')
|
|
|
|
frameCounter:setVisible(on)
|
|
|
|
setConfig('showfps', on)
|
|
|
|
end
|
2011-11-03 10:59:11 +01:00
|
|
|
|
|
|
|
-- public functions
|
|
|
|
function Options.create()
|
2011-11-17 21:40:31 +01:00
|
|
|
options = UI.display('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))
|
2011-11-03 10:59:11 +01:00
|
|
|
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)
|