2011-11-03 10:59:11 +01:00
|
|
|
Options = {}
|
|
|
|
|
2012-07-05 20:49:10 +02:00
|
|
|
local defaultOptions = {
|
|
|
|
vsync = false,
|
2012-08-26 06:27:30 +02:00
|
|
|
showFps = true,
|
|
|
|
showPing = true,
|
2012-07-05 20:49:10 +02:00
|
|
|
fullscreen = false,
|
2012-10-10 01:25:50 +02:00
|
|
|
dontStretchShrink = false,
|
2012-07-05 20:49:10 +02:00
|
|
|
classicControl = false,
|
2012-08-25 21:11:54 +02:00
|
|
|
walkBooster = false,
|
|
|
|
smartWalk = false,
|
2012-07-07 16:09:50 +02:00
|
|
|
autoChaseOverride = true,
|
2012-07-05 20:49:10 +02:00
|
|
|
showStatusMessagesInConsole = true,
|
|
|
|
showEventMessagesInConsole = true,
|
|
|
|
showInfoMessagesInConsole = true,
|
|
|
|
showTimestampsInConsole = true,
|
|
|
|
showLevelsInConsole = true,
|
|
|
|
showPrivateMessagesInConsole = false,
|
|
|
|
showPrivateMessagesOnScreen = true,
|
|
|
|
enableMusic = true,
|
|
|
|
showLeftPanel = false,
|
|
|
|
foregroundFrameRate = 61,
|
|
|
|
backgroundFrameRate = 201,
|
2012-11-30 17:47:53 +01:00
|
|
|
ambientLight = 15,
|
2012-07-05 20:49:10 +02:00
|
|
|
painterEngine = 0
|
|
|
|
}
|
|
|
|
|
2012-12-29 18:41:14 +01:00
|
|
|
local warningWindow
|
2012-01-07 21:00:07 +01:00
|
|
|
local optionsWindow
|
2012-01-07 18:36:58 +01:00
|
|
|
local optionsButton
|
2012-03-25 16:10:15 +02:00
|
|
|
local optionsTabBar
|
2012-07-05 20:49:10 +02:00
|
|
|
local options = {}
|
2012-12-29 18:41:14 +01:00
|
|
|
local gamePanel
|
|
|
|
local consolePanel
|
2012-06-02 23:41:20 +02:00
|
|
|
local graphicsPanel
|
|
|
|
|
|
|
|
local function setupGraphicsEngines()
|
2012-06-26 00:13:30 +02:00
|
|
|
local enginesRadioGroup = UIRadioGroup.create()
|
2012-06-02 23:41:20 +02:00
|
|
|
local ogl1 = graphicsPanel:getChildById('opengl1')
|
|
|
|
local ogl2 = graphicsPanel:getChildById('opengl2')
|
|
|
|
enginesRadioGroup:addWidget(ogl1)
|
|
|
|
enginesRadioGroup:addWidget(ogl2)
|
|
|
|
|
|
|
|
if g_graphics.getPainterEngine() == 2 then
|
|
|
|
enginesRadioGroup:selectWidget(ogl2)
|
|
|
|
else
|
|
|
|
enginesRadioGroup:selectWidget(ogl1)
|
|
|
|
end
|
|
|
|
|
|
|
|
ogl1:setEnabled(g_graphics.isPainterEngineAvailable(1))
|
|
|
|
ogl2:setEnabled(g_graphics.isPainterEngineAvailable(2))
|
|
|
|
|
|
|
|
enginesRadioGroup.onSelectionChange = function(self, selected)
|
|
|
|
if selected == ogl1 then
|
2012-07-05 20:49:10 +02:00
|
|
|
Options.setOption('painterEngine', 1)
|
2012-06-02 23:41:20 +02:00
|
|
|
elseif selected == ogl2 then
|
2012-07-05 20:49:10 +02:00
|
|
|
Options.setOption('painterEngine', 2)
|
2012-06-02 23:41:20 +02:00
|
|
|
end
|
|
|
|
end
|
2012-06-08 18:58:08 +02:00
|
|
|
|
|
|
|
if not g_graphics.canCacheBackbuffer() then
|
2012-08-24 19:16:30 +02:00
|
|
|
graphicsPanel:getChildById('foregroundFrameRate'):disable()
|
|
|
|
graphicsPanel:getChildById('foregroundFrameRateLabel'):disable()
|
2012-06-08 18:58:08 +02:00
|
|
|
end
|
2012-06-02 23:41:20 +02:00
|
|
|
end
|
2012-01-07 18:36:58 +01:00
|
|
|
|
2012-12-29 18:41:14 +01:00
|
|
|
function displayWarning(widget, warning)
|
|
|
|
if warningWindow and warningWindow:isVisible() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if g_game.isOfficialTibia() and widget:isChecked() then
|
|
|
|
local yesCallback = function() warningWindow:destroy() warningWindow=nil end
|
|
|
|
local noCallback = function() widget:setChecked(false) warningWindow:destroy() warningWindow=nil end
|
|
|
|
|
|
|
|
warningWindow = displayGeneralBox('Warning', tr(warning), {
|
|
|
|
{ text='Yes', callback=yesCallback },
|
|
|
|
{ text='No', callback=noCallback },
|
|
|
|
anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-07 18:36:58 +01:00
|
|
|
function Options.init()
|
2012-02-20 03:27:08 +01:00
|
|
|
-- load options
|
2012-07-05 20:49:10 +02:00
|
|
|
for k,v in pairs(defaultOptions) do
|
|
|
|
g_settings.setDefault(k, v)
|
2012-02-20 03:27:08 +01:00
|
|
|
if type(v) == 'boolean' then
|
2012-06-26 00:13:30 +02:00
|
|
|
Options.setOption(k, g_settings.getBoolean(k))
|
2012-07-05 20:49:10 +02:00
|
|
|
elseif type(v) == 'number' then
|
|
|
|
Options.setOption(k, g_settings.getNumber(k))
|
2012-02-20 03:27:08 +01:00
|
|
|
end
|
2012-01-06 10:10:55 +01:00
|
|
|
end
|
2012-01-07 22:19:40 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.bindKeyDown('Ctrl+F', function() Options.toggleOption('fullscreen') end)
|
2012-08-25 21:11:54 +02:00
|
|
|
g_keyboard.bindKeyDown('Ctrl+D', function() Options.toggleOption('walkBooster') end)
|
2012-03-25 16:10:15 +02:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
optionsWindow = g_ui.displayUI('options.otui')
|
2012-02-20 03:27:08 +01:00
|
|
|
optionsWindow:hide()
|
2012-06-08 18:58:08 +02:00
|
|
|
optionsButton = TopMenu.addLeftButton('optionsButton', tr('Options') .. ' (Ctrl+D)', 'options.png', Options.toggle)
|
2012-07-28 05:54:47 +02:00
|
|
|
|
2012-03-25 16:10:15 +02:00
|
|
|
optionsTabBar = optionsWindow:getChildById('optionsTabBar')
|
|
|
|
optionsTabBar:setContentWidget(optionsWindow:getChildById('optionsTabContent'))
|
2012-06-02 23:41:20 +02:00
|
|
|
|
2012-12-29 18:41:14 +01:00
|
|
|
gamePanel = g_ui.loadUI('game.otui')
|
|
|
|
optionsTabBar:addTab(tr('Game'), gamePanel)
|
2012-08-25 21:11:54 +02:00
|
|
|
|
2012-12-29 18:41:14 +01:00
|
|
|
consolePanel = g_ui.loadUI('console.otui')
|
|
|
|
optionsTabBar:addTab(tr('Console'), consolePanel)
|
2012-06-02 23:41:20 +02:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
graphicsPanel = g_ui.loadUI('graphics.otui')
|
2012-06-02 23:41:20 +02:00
|
|
|
optionsTabBar:addTab(tr('Graphics'), graphicsPanel)
|
|
|
|
|
2012-12-29 18:41:14 +01:00
|
|
|
local optionWalkBooster = gamePanel:getChildById('walkBooster')
|
|
|
|
optionWalkBooster.onCheckChange = function(widget)
|
|
|
|
displayWarning(widget, "This feature could be detectable by official Tibia servers. Would like to continue?")
|
|
|
|
Options.setOption(widget:getId(), widget:isChecked())
|
|
|
|
end
|
|
|
|
|
2012-06-02 23:41:20 +02:00
|
|
|
setupGraphicsEngines()
|
2012-01-06 09:48:59 +01:00
|
|
|
end
|
2011-11-17 01:12:11 +01:00
|
|
|
|
2012-01-07 21:00:07 +01:00
|
|
|
function Options.terminate()
|
2012-06-26 00:13:30 +02:00
|
|
|
g_keyboard.unbindKeyDown('Ctrl+D')
|
|
|
|
g_keyboard.unbindKeyDown('Ctrl+F')
|
2012-01-07 21:00:07 +01:00
|
|
|
optionsWindow:destroy()
|
|
|
|
optionsWindow = nil
|
|
|
|
optionsButton:destroy()
|
|
|
|
optionsButton = nil
|
2012-03-25 16:10:15 +02:00
|
|
|
optionsTabBar = nil
|
2012-12-29 18:41:14 +01:00
|
|
|
gamePanel = nil
|
|
|
|
consolePanel = nil
|
2012-06-02 23:41:20 +02:00
|
|
|
graphicsPanel = nil
|
2012-02-07 01:41:53 +01:00
|
|
|
Options = nil
|
2012-01-07 21:00:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Options.toggle()
|
|
|
|
if optionsWindow:isVisible() then
|
|
|
|
Options.hide()
|
|
|
|
else
|
|
|
|
Options.show()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-06 09:48:59 +01:00
|
|
|
function Options.show()
|
2012-01-07 21:00:07 +01:00
|
|
|
optionsWindow:show()
|
2012-02-20 03:27:08 +01:00
|
|
|
optionsWindow:raise()
|
|
|
|
optionsWindow:focus()
|
2012-01-07 21:00:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function Options.hide()
|
|
|
|
optionsWindow:hide()
|
2011-11-17 01:12:11 +01:00
|
|
|
end
|
|
|
|
|
2012-04-24 14:14:03 +02:00
|
|
|
function Options.toggleOption(key)
|
|
|
|
Options.setOption(key, not Options.getOption(key))
|
|
|
|
end
|
|
|
|
|
2012-02-20 03:27:08 +01:00
|
|
|
function Options.setOption(key, value)
|
2012-07-05 20:49:10 +02:00
|
|
|
if options[key] == value then return end
|
2012-01-06 10:10:55 +01:00
|
|
|
if key == 'vsync' then
|
2012-02-20 03:27:08 +01:00
|
|
|
g_window.setVerticalSync(value)
|
2012-08-26 06:27:30 +02:00
|
|
|
elseif key == 'showFps' then
|
2012-01-07 01:18:08 +01:00
|
|
|
addEvent(function()
|
|
|
|
local frameCounter = rootWidget:recursiveGetChildById('frameCounter')
|
2012-02-20 03:27:08 +01:00
|
|
|
if frameCounter then frameCounter:setVisible(value) end
|
2012-01-07 01:18:08 +01:00
|
|
|
end)
|
2012-08-26 06:27:30 +02:00
|
|
|
elseif key == 'showPing' then
|
|
|
|
addEvent(function()
|
|
|
|
local ping = rootWidget:recursiveGetChildById('pingLabel')
|
|
|
|
if ping then ping:setVisible(value) end
|
|
|
|
end)
|
2012-01-06 10:10:55 +01:00
|
|
|
elseif key == 'fullscreen' then
|
2012-07-05 20:49:10 +02:00
|
|
|
g_window.setFullscreen(value)
|
2012-10-10 01:25:50 +02:00
|
|
|
elseif key == 'dontStretchShrink' then
|
|
|
|
addEvent(function()
|
|
|
|
modules.game_interface.updateStretchShrink()
|
|
|
|
end)
|
2012-06-20 08:31:52 +02:00
|
|
|
elseif key == 'enableMusic' then
|
2012-07-05 20:49:10 +02:00
|
|
|
g_sounds.enableMusic(value)
|
2012-06-21 21:31:22 +02:00
|
|
|
elseif key == 'showLeftPanel' then
|
|
|
|
addEvent(function()
|
2012-07-24 07:30:08 +02:00
|
|
|
modules.game_interface.getLeftPanel():setOn(value)
|
2012-06-21 21:31:22 +02:00
|
|
|
end)
|
2012-07-05 20:49:10 +02:00
|
|
|
elseif key == 'backgroundFrameRate' then
|
|
|
|
local text = value
|
|
|
|
if value <= 0 or value >= 201 then
|
|
|
|
text = 'max'
|
|
|
|
value = 0
|
|
|
|
end
|
|
|
|
|
2012-07-28 05:54:47 +02:00
|
|
|
if graphicsPanel then
|
2012-08-25 21:11:54 +02:00
|
|
|
graphicsPanel:getChildById('backgroundFrameRateLabel'):setText(tr('Game framerate limit: %s', text))
|
|
|
|
end
|
2012-07-05 20:49:10 +02:00
|
|
|
g_app.setBackgroundPaneMaxFps(value)
|
|
|
|
elseif key == 'foregroundFrameRate' then
|
2012-07-07 16:44:53 +02:00
|
|
|
local text = value
|
|
|
|
if value <= 0 or value >= 61 then
|
|
|
|
text = 'max'
|
|
|
|
value = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
if graphicsPanel then
|
2012-08-25 21:11:54 +02:00
|
|
|
graphicsPanel:getChildById('foregroundFrameRateLabel'):setText(tr('Interface framerate limit: %s', text))
|
2012-07-07 16:44:53 +02:00
|
|
|
end
|
|
|
|
g_app.setForegroundPaneMaxFps(value)
|
2012-11-30 17:47:53 +01:00
|
|
|
elseif key == 'ambientLight' then
|
|
|
|
addEvent(function()
|
|
|
|
local map = rootWidget:recursiveGetChildById('gameMapPanel')
|
|
|
|
if graphicsPanel then
|
|
|
|
graphicsPanel:getChildById('ambientLightLabel'):setText(tr('Ambient light: %s%%', value))
|
|
|
|
end
|
|
|
|
if map then
|
|
|
|
map:setMinimumAmbientLight(value/100)
|
|
|
|
map:setDrawLights(value < 100)
|
|
|
|
end
|
|
|
|
end)
|
2012-07-05 20:49:10 +02:00
|
|
|
elseif key == 'painterEngine' then
|
|
|
|
g_graphics.selectPainterEngine(value)
|
2012-01-06 10:10:55 +01:00
|
|
|
end
|
2012-06-26 00:13:30 +02:00
|
|
|
g_settings.set(key, value)
|
2012-02-20 03:27:08 +01:00
|
|
|
options[key] = value
|
2011-11-03 10:59:11 +01:00
|
|
|
end
|
2012-02-20 03:27:08 +01:00
|
|
|
|
|
|
|
function Options.getOption(key)
|
|
|
|
return options[key]
|
|
|
|
end
|
2012-07-05 20:49:10 +02:00
|
|
|
|
|
|
|
|