2012-07-05 20:49:10 +02:00
|
|
|
local defaultOptions = {
|
|
|
|
vsync = false,
|
2013-01-25 16:33:51 +01:00
|
|
|
showFps = false,
|
|
|
|
showPing = false,
|
2012-07-05 20:49:10 +02:00
|
|
|
fullscreen = false,
|
|
|
|
classicControl = false,
|
2012-08-25 21:11:54 +02:00
|
|
|
smartWalk = false,
|
2013-02-26 20:37:02 +01:00
|
|
|
dashWalk = 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,
|
2013-02-04 19:33:34 +01:00
|
|
|
showPrivateMessagesInConsole = true,
|
2012-07-05 20:49:10 +02:00
|
|
|
showPrivateMessagesOnScreen = true,
|
|
|
|
showLeftPanel = false,
|
|
|
|
foregroundFrameRate = 61,
|
|
|
|
backgroundFrameRate = 201,
|
2013-01-25 16:33:51 +01:00
|
|
|
painterEngine = 0,
|
|
|
|
enableAudio = true,
|
|
|
|
enableMusicSound = true,
|
|
|
|
musicSoundVolume = 100,
|
|
|
|
enableLights = true,
|
|
|
|
ambientLight = 25,
|
2013-02-01 15:38:17 +01:00
|
|
|
displayNames = true,
|
|
|
|
displayHealth = true,
|
|
|
|
displayText = true
|
2012-07-05 20:49:10 +02:00
|
|
|
}
|
|
|
|
|
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 = {}
|
2013-01-25 16:33:51 +01:00
|
|
|
local generalPanel
|
2012-12-29 18:41:14 +01:00
|
|
|
local consolePanel
|
2012-06-02 23:41:20 +02:00
|
|
|
local graphicsPanel
|
2013-01-25 16:33:51 +01:00
|
|
|
local soundPanel
|
|
|
|
local audioButton
|
2012-06-02 23:41:20 +02:00
|
|
|
|
|
|
|
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')
|
2013-01-25 16:33:51 +01:00
|
|
|
local dx9 = graphicsPanel:getChildById('directx9')
|
2012-06-02 23:41:20 +02:00
|
|
|
enginesRadioGroup:addWidget(ogl1)
|
|
|
|
enginesRadioGroup:addWidget(ogl2)
|
2013-01-25 16:33:51 +01:00
|
|
|
enginesRadioGroup:addWidget(dx9)
|
2012-06-02 23:41:20 +02:00
|
|
|
|
2013-01-25 16:33:51 +01:00
|
|
|
if g_window.getPlatformType() == 'WIN32-EGL' then
|
|
|
|
enginesRadioGroup:selectWidget(dx9)
|
|
|
|
ogl1:setEnabled(false)
|
|
|
|
ogl2:setEnabled(false)
|
|
|
|
dx9:setEnabled(true)
|
2012-06-02 23:41:20 +02:00
|
|
|
else
|
2013-01-25 16:33:51 +01:00
|
|
|
ogl1:setEnabled(g_graphics.isPainterEngineAvailable(1))
|
|
|
|
ogl2:setEnabled(g_graphics.isPainterEngineAvailable(2))
|
|
|
|
dx9:setEnabled(false)
|
|
|
|
if g_graphics.getPainterEngine() == 2 then
|
|
|
|
enginesRadioGroup:selectWidget(ogl2)
|
|
|
|
else
|
|
|
|
enginesRadioGroup:selectWidget(ogl1)
|
|
|
|
end
|
2012-06-02 23:41:20 +02:00
|
|
|
|
2013-01-25 16:33:51 +01:00
|
|
|
if g_app.getOs() ~= 'windows' then
|
|
|
|
dx9:hide()
|
|
|
|
end
|
|
|
|
end
|
2012-06-02 23:41:20 +02:00
|
|
|
|
|
|
|
enginesRadioGroup.onSelectionChange = function(self, selected)
|
|
|
|
if selected == ogl1 then
|
2013-01-18 23:39:11 +01:00
|
|
|
setOption('painterEngine', 1)
|
2012-06-02 23:41:20 +02:00
|
|
|
elseif selected == ogl2 then
|
2013-01-18 23:39:11 +01:00
|
|
|
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-12-29 18:41:14 +01:00
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function init()
|
2013-02-28 22:39:27 +01:00
|
|
|
for k,v in pairs(defaultOptions) do
|
|
|
|
g_settings.setDefault(k, v)
|
|
|
|
options[k] = v
|
|
|
|
end
|
|
|
|
|
2013-02-01 15:38:17 +01:00
|
|
|
optionsWindow = g_ui.displayUI('options')
|
|
|
|
optionsWindow:hide()
|
|
|
|
|
2013-02-01 17:31:24 +01:00
|
|
|
optionsTabBar = optionsWindow:getChildById('optionsTabBar')
|
|
|
|
optionsTabBar:setContentWidget(optionsWindow:getChildById('optionsTabContent'))
|
|
|
|
|
2013-02-01 15:38:17 +01:00
|
|
|
g_keyboard.bindKeyDown('Ctrl+Shift+F', function() toggleOption('fullscreen') end)
|
|
|
|
g_keyboard.bindKeyDown('Ctrl+N', toggleDisplays)
|
|
|
|
|
2013-02-28 22:39:27 +01:00
|
|
|
generalPanel = g_ui.loadUI('game')
|
|
|
|
optionsTabBar:addTab(tr('Game'), generalPanel, '/images/optionstab/game')
|
|
|
|
|
|
|
|
consolePanel = g_ui.loadUI('console')
|
|
|
|
optionsTabBar:addTab(tr('Console'), consolePanel, '/images/optionstab/console')
|
|
|
|
|
|
|
|
graphicsPanel = g_ui.loadUI('graphics')
|
|
|
|
optionsTabBar:addTab(tr('Graphics'), graphicsPanel, '/images/optionstab/graphics')
|
|
|
|
|
|
|
|
audioPanel = g_ui.loadUI('audio')
|
|
|
|
optionsTabBar:addTab(tr('Audio'), audioPanel, '/images/optionstab/audio')
|
|
|
|
|
|
|
|
optionsButton = modules.client_topmenu.addLeftButton('optionsButton', tr('Options'), '/images/topbuttons/options', toggle)
|
2013-02-01 15:38:17 +01:00
|
|
|
audioButton = modules.client_topmenu.addLeftButton('audioButton', tr('Audio'), '/images/topbuttons/audio', function() toggleOption('enableAudio') end)
|
2013-02-28 22:39:27 +01:00
|
|
|
|
|
|
|
addEvent(function() setup() end)
|
2013-02-01 15:38:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function terminate()
|
|
|
|
g_keyboard.unbindKeyDown('Ctrl+Shift+F')
|
|
|
|
g_keyboard.unbindKeyDown('Ctrl+N')
|
|
|
|
optionsWindow:destroy()
|
|
|
|
optionsButton:destroy()
|
|
|
|
audioButton:destroy()
|
|
|
|
end
|
|
|
|
|
|
|
|
function setup()
|
2013-02-28 22:39:27 +01:00
|
|
|
setupGraphicsEngines()
|
|
|
|
|
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
|
2012-02-20 03:27:08 +01:00
|
|
|
if type(v) == 'boolean' then
|
2013-02-28 22:39:27 +01:00
|
|
|
setOption(k, g_settings.getBoolean(k), true)
|
2012-07-05 20:49:10 +02:00
|
|
|
elseif type(v) == 'number' then
|
2013-02-28 22:39:27 +01:00
|
|
|
setOption(k, g_settings.getNumber(k), true)
|
2012-02-20 03:27:08 +01:00
|
|
|
end
|
2012-01-06 10:10:55 +01:00
|
|
|
end
|
2012-01-06 09:48:59 +01:00
|
|
|
end
|
2011-11-17 01:12:11 +01:00
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function toggle()
|
2012-01-07 21:00:07 +01:00
|
|
|
if optionsWindow:isVisible() then
|
2013-01-18 23:39:11 +01:00
|
|
|
hide()
|
2012-01-07 21:00:07 +01:00
|
|
|
else
|
2013-01-18 23:39:11 +01:00
|
|
|
show()
|
2012-01-07 21:00:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function 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
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function hide()
|
2012-01-07 21:00:07 +01:00
|
|
|
optionsWindow:hide()
|
2011-11-17 01:12:11 +01:00
|
|
|
end
|
|
|
|
|
2013-02-01 15:38:17 +01:00
|
|
|
function toggleDisplays()
|
|
|
|
if options['displayNames'] and options['displayHealth'] then
|
|
|
|
setOption('displayNames', false)
|
|
|
|
elseif options['displayHealth'] then
|
|
|
|
setOption('displayHealth', false)
|
|
|
|
else
|
|
|
|
if not options['displayNames'] and not options['displayHealth'] then
|
|
|
|
setOption('displayNames', true)
|
|
|
|
else
|
|
|
|
setOption('displayHealth', true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function toggleOption(key)
|
2013-01-25 16:33:51 +01:00
|
|
|
setOption(key, not getOption(key))
|
2012-04-24 14:14:03 +02:00
|
|
|
end
|
|
|
|
|
2013-02-28 22:39:27 +01:00
|
|
|
function setOption(key, value, force)
|
|
|
|
if not force and options[key] == value then return end
|
2013-02-01 15:38:17 +01:00
|
|
|
local gameMapPanel = modules.game_interface.getMapPanel()
|
|
|
|
|
|
|
|
local panel = nil
|
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
|
2013-02-24 21:26:19 +01:00
|
|
|
modules.client_topmenu.setFpsVisible(value)
|
2012-08-26 06:27:30 +02:00
|
|
|
elseif key == 'showPing' then
|
2013-02-24 21:26:19 +01:00
|
|
|
modules.client_topmenu.setPingVisible(value)
|
2012-01-06 10:10:55 +01:00
|
|
|
elseif key == 'fullscreen' then
|
2012-07-05 20:49:10 +02:00
|
|
|
g_window.setFullscreen(value)
|
2013-02-01 15:38:17 +01:00
|
|
|
panel = graphicsPanel
|
2013-01-25 16:33:51 +01:00
|
|
|
elseif key == 'enableAudio' then
|
|
|
|
g_sounds.setAudioEnabled(value)
|
2013-02-28 22:39:27 +01:00
|
|
|
if value then
|
|
|
|
audioButton:setIcon('/images/topbuttons/audio')
|
|
|
|
else
|
|
|
|
audioButton:setIcon('/images/topbuttons/audio_mute')
|
|
|
|
end
|
2013-02-12 17:14:16 +01:00
|
|
|
panel = audioPanel
|
2013-01-25 16:33:51 +01:00
|
|
|
elseif key == 'enableMusicSound' then
|
|
|
|
g_sounds.getChannel(SoundChannels.Music):setEnabled(value)
|
|
|
|
elseif key == 'musicSoundVolume' then
|
|
|
|
g_sounds.getChannel(SoundChannels.Music):setGain(value/100)
|
2013-02-28 22:39:27 +01:00
|
|
|
audioPanel:getChildById('musicSoundVolumeLabel'):setText(tr('Music volume: %d', value))
|
2012-06-21 21:31:22 +02:00
|
|
|
elseif key == 'showLeftPanel' then
|
2013-02-28 22:39:27 +01:00
|
|
|
modules.game_interface.getLeftPanel():setOn(value)
|
2012-07-05 20:49:10 +02:00
|
|
|
elseif key == 'backgroundFrameRate' then
|
|
|
|
local text = value
|
2013-02-28 22:39:27 +01:00
|
|
|
if value <= 0 or value >= 201 then text = 'max' value = 0 end
|
|
|
|
graphicsPanel:getChildById('backgroundFrameRateLabel'):setText(tr('Game framerate limit: %s', text))
|
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
|
2013-02-28 22:39:27 +01:00
|
|
|
if value <= 0 or value >= 61 then text = 'max' value = 0 end
|
|
|
|
graphicsPanel:getChildById('foregroundFrameRateLabel'):setText(tr('Interface framerate limit: %s', text))
|
2012-07-07 16:44:53 +02:00
|
|
|
g_app.setForegroundPaneMaxFps(value)
|
2013-01-25 16:33:51 +01:00
|
|
|
elseif key == 'enableLights' then
|
2013-02-28 22:39:27 +01:00
|
|
|
gameMapPanel:setDrawLights(value and options['ambientLight'] < 100)
|
|
|
|
graphicsPanel:getChildById('ambientLight'):setEnabled(value)
|
|
|
|
graphicsPanel:getChildById('ambientLightLabel'):setEnabled(value)
|
2012-11-30 17:47:53 +01:00
|
|
|
elseif key == 'ambientLight' then
|
2013-02-28 22:39:27 +01:00
|
|
|
graphicsPanel:getChildById('ambientLightLabel'):setText(tr('Ambient light: %s%%', value))
|
|
|
|
gameMapPanel:setMinimumAmbientLight(value/100)
|
|
|
|
gameMapPanel:setDrawLights(options['enableLights'] and value < 100)
|
2012-07-05 20:49:10 +02:00
|
|
|
elseif key == 'painterEngine' then
|
|
|
|
g_graphics.selectPainterEngine(value)
|
2013-02-01 15:38:17 +01:00
|
|
|
elseif key == 'displayNames' then
|
|
|
|
gameMapPanel:setDrawNames(value)
|
|
|
|
panel = generalPanel
|
|
|
|
elseif key == 'displayHealth' then
|
|
|
|
gameMapPanel:setDrawHealthBars(value)
|
|
|
|
panel = generalPanel
|
|
|
|
elseif key == 'displayText' then
|
|
|
|
gameMapPanel:setDrawTexts(value)
|
|
|
|
panel = generalPanel
|
|
|
|
end
|
|
|
|
|
|
|
|
-- change value for keybind updates
|
|
|
|
if panel then
|
|
|
|
local widget = panel:recursiveGetChildById(key)
|
|
|
|
if widget and widget:getStyle().__class == 'UICheckBox' then
|
|
|
|
widget:setChecked(value)
|
|
|
|
end
|
2012-01-06 10:10:55 +01:00
|
|
|
end
|
2013-02-01 15:38:17 +01:00
|
|
|
|
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
|
|
|
|
2013-01-18 23:39:11 +01:00
|
|
|
function getOption(key)
|
2012-02-20 03:27:08 +01:00
|
|
|
return options[key]
|
|
|
|
end
|
2012-07-05 20:49:10 +02:00
|
|
|
|
2013-01-25 16:33:51 +01:00
|
|
|
function addTab(name, panel, icon)
|
|
|
|
optionsTabBar:addTab(name, panel, icon)
|
|
|
|
end
|
2013-02-06 20:35:59 +01:00
|
|
|
|
|
|
|
function addButton(name, func, icon)
|
|
|
|
optionsTabBar:addButton(name, func, icon)
|
|
|
|
end
|