mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 12:04:55 +02:00
save window position and size
This commit is contained in:
@@ -1,72 +1,34 @@
|
||||
Options = {}
|
||||
|
||||
-- private variables
|
||||
local options
|
||||
local fpsEnabled = false
|
||||
local vsyncEnabled = false
|
||||
|
||||
function getConfig(name, default)
|
||||
if g_configs.exists(name) then
|
||||
local val = g_configs.get(name):trim()
|
||||
if val == 'true' or val == 'false' then
|
||||
return toboolean(val)
|
||||
else
|
||||
return val
|
||||
end
|
||||
else
|
||||
if default ~= nil then
|
||||
g_configs.set(name, default)
|
||||
return default
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function setConfig(name, value)
|
||||
g_configs.set(name, tostring(value))
|
||||
end
|
||||
|
||||
-- private functions
|
||||
function Options.enableVsync(on)
|
||||
vsyncEnabled = on
|
||||
g_window.setVerticalSync(on)
|
||||
setConfig('vsync', on)
|
||||
end
|
||||
|
||||
function Options.enableFps(on)
|
||||
fpsEnabled = on
|
||||
local frameCounter = rootWidget:recursiveGetChildById('frameCounter')
|
||||
frameCounter:setVisible(on)
|
||||
setConfig('showfps', on)
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function Options.create()
|
||||
options = displayUI('options.otui', { locked = true })
|
||||
|
||||
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))
|
||||
-- set default settings
|
||||
Settings.setDefault('vsync', true)
|
||||
Settings.setDefault('showfps', true)
|
||||
|
||||
-- load the options
|
||||
Options.enableVsync(Settings.getBoolean('vsync'))
|
||||
Options.enableFps(Settings.getBoolean('showfps'))
|
||||
end
|
||||
|
||||
function Options.destroy()
|
||||
options:destroy()
|
||||
options = nil
|
||||
function Options.show()
|
||||
displayUI('options.otui', { locked = true })
|
||||
end
|
||||
|
||||
function Options.openWebpage()
|
||||
displayErrorBox("Error", "Not implemented yet")
|
||||
end
|
||||
|
||||
addEvent(Options.load)
|
||||
-- private functions
|
||||
function Options.enableVsync(on)
|
||||
g_window.setVerticalSync(on)
|
||||
Settings.set('vsync', on)
|
||||
Options.vsync = on
|
||||
end
|
||||
|
||||
function Options.enableFps(on)
|
||||
local frameCounter = rootWidget:recursiveGetChildById('frameCounter')
|
||||
frameCounter:setVisible(on)
|
||||
Settings.set('showfps', on)
|
||||
Options.fps = on
|
||||
end
|
||||
|
Reference in New Issue
Block a user