local defaultOptions = {
vsync = true,
showFps = false,
showPing = false,
fullscreen = false,
classicControl = false,
autoChaseOverride = true,
showStatusMessagesInConsole = true,
showEventMessagesInConsole = true,
showInfoMessagesInConsole = true,
showTimestampsInConsole = true,
showPrivateMessagesInConsole = true,
showPrivateMessagesOnScreen = true,
showLeftPanel = false,
showExtraRightPanel = false,
foregroundFrameRate = 61,
backgroundFrameRate = 201,
painterEngine = 0,
displayNames = true,
displayHealth = true,
displayMana = true,
displayText = true,
dontStretchShrink = false,
smoothWalk = true,
walkingRepeatDelayScrollBar = 100,
walkingSensitivityScrollBar = 50,
bouncingKeys = true,
bouncingKeysDelayScrollBar = 100,
smartWalk = false,
blueNpc = true,
expBar = false,
}
local optionsWindow
local optionsButton
local hotkeysButton
local optionsTabBar
local options = {}
local generalPanel
local consolePanel
local graphicsPanel
local keyboardPanel
local soundPanel
local function setupGraphicsEngines()
local enginesRadioGroup = UIRadioGroup.create()
local ogl1 = graphicsPanel:getChildById('opengl1')
local ogl2 = graphicsPanel:getChildById('opengl2')
local dx9 = graphicsPanel:getChildById('directx9')
enginesRadioGroup:addWidget(ogl1)
enginesRadioGroup:addWidget(ogl2)
enginesRadioGroup:addWidget(dx9)
if g_window.getPlatformType() == 'WIN32-EGL' then
enginesRadioGroup:selectWidget(dx9)
ogl1:setEnabled(false)
ogl2:setEnabled(false)
dx9:setEnabled(true)
else
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
if g_app.getOs() ~= 'windows' then
dx9:hide()
end
end
enginesRadioGroup.onSelectionChange = function(self, selected)
if selected == ogl1 then
setOption('painterEngine', 1)
elseif selected == ogl2 then
setOption('painterEngine', 2)
end
end
--[[--]]if not g_graphics.canCacheBackbuffer() then
graphicsPanel:getChildById('foregroundFrameRate'):disable()
graphicsPanel:getChildById('foregroundFrameRateLabel'):disable()
end--
end
function init()
for k,v in pairs(defaultOptions) do
g_settings.setDefault(k, v)
options[k] = v
end
optionsWindow = g_ui.displayUI('options')
optionsWindow:hide()
optionsTabBar = optionsWindow:getChildById('optionsTabBar')
optionsTabBar:setContentWidget(optionsWindow:getChildById('optionsTabContent'))
g_keyboard.bindKeyDown('Ctrl+F', function() toggleFullScreen() end)
g_keyboard.bindKeyDown('Ctrl+N', toggleDisplays)
hotkeysButton = optionsWindow:getChildById('hotkeysButton')
generalPanel = g_ui.loadUI('game')
optionsTabBar:addTab(tr('General'), generalPanel, '/images/optionstab/option_button')
consolePanel = g_ui.loadUI('Console')
optionsTabBar:addTab(tr('Console'), consolePanel, '/images/optionstab/option_button')
graphicsPanel = g_ui.loadUI('Graphics')
optionsTabBar:addTab(tr('Graphics'), graphicsPanel, '/images/optionstab/option_button')
keyboardPanel = g_ui.loadUI('keyboard')
optionsTabBar:addTab(tr('Keyboard'), keyboardPanel, '/images/optionstab/option_button')
g_app.setForegroundPaneMaxFps(0)
addEvent(function() setup() end)
end
function toggleFullScreen()
local screenButton = modules.game_playerbars.fullScreenButton
if not g_window.isFullscreen() then
screenButton:setChecked(true)
g_window.setFullscreen(true)
else
g_window.setFullscreen(false)
screenButton:setChecked(false)
end
end
function setup()
local gameMapPanel = modules.game_interface.getMapPanel()
gameMapPanel:setDrawLights(false)
setupGraphicsEngines()
-- load options
for k,v in pairs(defaultOptions) do
if type(v) == 'boolean' then
setOption(k, g_settings.getBoolean(k), true)
elseif type(v) == 'number' then
setOption(k, g_settings.getNumber(k), true)
end
end
end
function toggle()
if optionsWindow:isVisible() then
hide()
else
show()
end
if g_game.isOnline() then
hotkeysButton:enable()
hotkeysButton:setOpacity(1)
else
hotkeysButton:disable()
end
end
function show()
optionsWindow:show()
optionsWindow:raise()
optionsWindow:focus()
end
function hide()
optionsWindow:hide()
end
function toggleDisplays()
if options['displayNames'] and options['displayHealth'] and options['displayMana'] then
setOption('displayNames', false)
elseif options['displayHealth'] then
setOption('displayHealth', false)
setOption('displayMana', false)
else
if not options['displayNames'] and not options['displayHealth'] then
setOption('displayNames', true)
else
setOption('displayHealth', true)
setOption('displayMana', true)
end
end
end
function toggleOption(key)
setOption(key, not getOption(key))
end
function setOption(key, value, force)
if not force and options[key] == value then return end
local gameMapPanel = modules.game_interface.getMapPanel()
if key == 'vsync' then
g_window.setVerticalSync(value)
elseif key == 'showFps' then
modules.game_interface.setFpsVisible(value)
elseif key == 'showPing' then
modules.game_interface.setPingVisible(value)
elseif key == 'fullscreen' then
g_window.setFullscreen(value)
elseif key == 'showLeftPanel' then
modules.game_interface.getLeftPanel():setOn(value)
elseif key == 'showExtraRightPanel' then
modules.game_interface.getExtraRightPanel():setOn(value)
elseif key == 'backgroundFrameRate' then
local text, v = value, value
if value <= 0 or value >= 201 then text = 'max' v = 0 end
graphicsPanel:getChildById('backgroundFrameRateLabel'):setText(tr('Game framerate limit: %s', text))
g_app.setBackgroundPaneMaxFps(v)
elseif key == 'bouncingKeysDelayScrollBar' then
keyboardPanel:getChildById('bouncingKeysDelayLabel'):setText(tr('Auto bouncing keys interval: %s ms', value))
elseif key == 'walkingSensitivityScrollBar' then
keyboardPanel:getChildById('walkingSensitivityLabel'):setText(tr('Walking keys sensitivity: %s%%', value))
elseif key == 'walkingRepeatDelayScrollBar' then
keyboardPanel:getChildById('walkingRepeatDelayLabel'):setText(tr('Walking keys auto-repeat delay: %s ms', value))
local scrollBar = keyboardPanel:getChildById('walkingRepeatDelayScrollBar')
modules.game_interface.setWalkingRepeatDelay(value)
elseif key == 'smoothWalk' then
keyboardPanel:getChildById('walkingSensitivityScrollBar'):setEnabled(value)
keyboardPanel:getChildById('walkingSensitivityLabel'):setEnabled(value)
elseif key == 'bouncingKeys' then
keyboardPanel:getChildById('bouncingKeysDelayScrollBar'):setEnabled(value)
keyboardPanel:getChildById('bouncingKeysDelayLabel'):setEnabled(value)
elseif key == 'painterEngine' then
g_graphics.selectPainterEngine(value)
elseif key == 'displayNames' then
gameMapPanel:setDrawNames(value)
elseif key == 'displayHealth' then
gameMapPanel:setDrawHealthBars(value)
elseif key == 'expBar' then
modules.game_healthinfo.toggleExpBar(value)
elseif key == 'blueNpc' then
if value then
g_game.enableFeature(GameBlueNpcNameColor)
else
g_game.disableFeature(GameBlueNpcNameColor)
end
modules.game_battle.checkCreatures()
elseif key == 'displayText' then
gameMapPanel:setDrawTexts(value)
elseif key == 'dontStretchShrink' then
addEvent(function()
modules.game_interface.updateStretchShrink()
end)
end
-- change value for keybind updates
for _,panel in pairs(optionsTabBar:getTabsPanel()) do
local widget = panel:recursiveGetChildById(key)
if widget then
if widget:getStyle().__class == 'UICheckBox' then
widget:setChecked(value)
elseif widget:getStyle().__class == 'UIScrollBar' then
widget:setValue(value)
end
break
end
end
g_settings.set(key, value)
options[key] = value
end
function getOption(key)
return options[key]
end
function addTab(name, panel, icon)
optionsTabBar:addTab(name, panel, icon)
end
function addButton(name, func, icon)
optionsTabBar:addButton(name, func, icon)
end