No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

options.lua 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. local defaultOptions = {
  2. vsync = false,
  3. showFps = false,
  4. showPing = false,
  5. fullscreen = false,
  6. classicControl = false,
  7. smartWalk = false,
  8. dashWalk = false,
  9. autoChaseOverride = true,
  10. showStatusMessagesInConsole = true,
  11. showEventMessagesInConsole = true,
  12. showInfoMessagesInConsole = true,
  13. showTimestampsInConsole = true,
  14. showLevelsInConsole = true,
  15. showPrivateMessagesInConsole = true,
  16. showPrivateMessagesOnScreen = true,
  17. showLeftPanel = false,
  18. foregroundFrameRate = 61,
  19. backgroundFrameRate = 201,
  20. painterEngine = 0,
  21. enableAudio = true,
  22. enableMusicSound = true,
  23. musicSoundVolume = 100,
  24. enableLights = true,
  25. ambientLight = 25,
  26. displayNames = true,
  27. displayHealth = true,
  28. displayMana = true,
  29. displayText = true,
  30. dontStretchShrink = false,
  31. turnDelay = 50,
  32. hotkeyDelay = 50,
  33. }
  34. local optionsWindow
  35. local optionsButton
  36. local optionsTabBar
  37. local options = {}
  38. local generalPanel
  39. local consolePanel
  40. local graphicsPanel
  41. local soundPanel
  42. local audioButton
  43. local function setupGraphicsEngines()
  44. local enginesRadioGroup = UIRadioGroup.create()
  45. local ogl1 = graphicsPanel:getChildById('opengl1')
  46. local ogl2 = graphicsPanel:getChildById('opengl2')
  47. local dx9 = graphicsPanel:getChildById('directx9')
  48. enginesRadioGroup:addWidget(ogl1)
  49. enginesRadioGroup:addWidget(ogl2)
  50. enginesRadioGroup:addWidget(dx9)
  51. if g_window.getPlatformType() == 'WIN32-EGL' then
  52. enginesRadioGroup:selectWidget(dx9)
  53. ogl1:setEnabled(false)
  54. ogl2:setEnabled(false)
  55. dx9:setEnabled(true)
  56. else
  57. ogl1:setEnabled(g_graphics.isPainterEngineAvailable(1))
  58. ogl2:setEnabled(g_graphics.isPainterEngineAvailable(2))
  59. dx9:setEnabled(false)
  60. if g_graphics.getPainterEngine() == 2 then
  61. enginesRadioGroup:selectWidget(ogl2)
  62. else
  63. enginesRadioGroup:selectWidget(ogl1)
  64. end
  65. if g_app.getOs() ~= 'windows' then
  66. dx9:hide()
  67. end
  68. end
  69. enginesRadioGroup.onSelectionChange = function(self, selected)
  70. if selected == ogl1 then
  71. setOption('painterEngine', 1)
  72. elseif selected == ogl2 then
  73. setOption('painterEngine', 2)
  74. end
  75. end
  76. if not g_graphics.canCacheBackbuffer() then
  77. graphicsPanel:getChildById('foregroundFrameRate'):disable()
  78. graphicsPanel:getChildById('foregroundFrameRateLabel'):disable()
  79. end
  80. end
  81. function init()
  82. for k,v in pairs(defaultOptions) do
  83. g_settings.setDefault(k, v)
  84. options[k] = v
  85. end
  86. optionsWindow = g_ui.displayUI('options')
  87. optionsWindow:hide()
  88. optionsTabBar = optionsWindow:getChildById('optionsTabBar')
  89. optionsTabBar:setContentWidget(optionsWindow:getChildById('optionsTabContent'))
  90. g_keyboard.bindKeyDown('Ctrl+Shift+F', function() toggleOption('fullscreen') end)
  91. g_keyboard.bindKeyDown('Ctrl+N', toggleDisplays)
  92. generalPanel = g_ui.loadUI('game')
  93. optionsTabBar:addTab(tr('Game'), generalPanel, '/images/optionstab/game')
  94. consolePanel = g_ui.loadUI('console')
  95. optionsTabBar:addTab(tr('Console'), consolePanel, '/images/optionstab/console')
  96. graphicsPanel = g_ui.loadUI('graphics')
  97. optionsTabBar:addTab(tr('Graphics'), graphicsPanel, '/images/optionstab/graphics')
  98. audioPanel = g_ui.loadUI('audio')
  99. optionsTabBar:addTab(tr('Audio'), audioPanel, '/images/optionstab/audio')
  100. optionsButton = modules.client_topmenu.addLeftButton('optionsButton', tr('Options'), '/images/topbuttons/options', toggle)
  101. audioButton = modules.client_topmenu.addLeftButton('audioButton', tr('Audio'), '/images/topbuttons/audio', function() toggleOption('enableAudio') end)
  102. addEvent(function() setup() end)
  103. end
  104. function terminate()
  105. g_keyboard.unbindKeyDown('Ctrl+Shift+F')
  106. g_keyboard.unbindKeyDown('Ctrl+N')
  107. optionsWindow:destroy()
  108. optionsButton:destroy()
  109. audioButton:destroy()
  110. end
  111. function setup()
  112. setupGraphicsEngines()
  113. -- load options
  114. for k,v in pairs(defaultOptions) do
  115. if type(v) == 'boolean' then
  116. setOption(k, g_settings.getBoolean(k), true)
  117. elseif type(v) == 'number' then
  118. setOption(k, g_settings.getNumber(k), true)
  119. end
  120. end
  121. end
  122. function toggle()
  123. if optionsWindow:isVisible() then
  124. hide()
  125. else
  126. show()
  127. end
  128. end
  129. function show()
  130. optionsWindow:show()
  131. optionsWindow:raise()
  132. optionsWindow:focus()
  133. end
  134. function hide()
  135. optionsWindow:hide()
  136. end
  137. function toggleDisplays()
  138. if options['displayNames'] and options['displayHealth'] and options['displayMana'] then
  139. setOption('displayNames', false)
  140. elseif options['displayHealth'] then
  141. setOption('displayHealth', false)
  142. setOption('displayMana', false)
  143. else
  144. if not options['displayNames'] and not options['displayHealth'] then
  145. setOption('displayNames', true)
  146. else
  147. setOption('displayHealth', true)
  148. setOption('displayMana', true)
  149. end
  150. end
  151. end
  152. function toggleOption(key)
  153. setOption(key, not getOption(key))
  154. end
  155. function setOption(key, value, force)
  156. if not force and options[key] == value then return end
  157. local gameMapPanel = modules.game_interface.getMapPanel()
  158. if key == 'vsync' then
  159. g_window.setVerticalSync(value)
  160. elseif key == 'showFps' then
  161. modules.client_topmenu.setFpsVisible(value)
  162. elseif key == 'showPing' then
  163. modules.client_topmenu.setPingVisible(value)
  164. elseif key == 'fullscreen' then
  165. g_window.setFullscreen(value)
  166. elseif key == 'enableAudio' then
  167. g_sounds.setAudioEnabled(value)
  168. if value then
  169. audioButton:setIcon('/images/topbuttons/audio')
  170. else
  171. audioButton:setIcon('/images/topbuttons/audio_mute')
  172. end
  173. elseif key == 'enableMusicSound' then
  174. g_sounds.getChannel(SoundChannels.Music):setEnabled(value)
  175. elseif key == 'musicSoundVolume' then
  176. g_sounds.getChannel(SoundChannels.Music):setGain(value/100)
  177. audioPanel:getChildById('musicSoundVolumeLabel'):setText(tr('Music volume: %d', value))
  178. elseif key == 'showLeftPanel' then
  179. modules.game_interface.getLeftPanel():setOn(value)
  180. elseif key == 'backgroundFrameRate' then
  181. local text, v = value, value
  182. if value <= 0 or value >= 201 then text = 'max' v = 0 end
  183. graphicsPanel:getChildById('backgroundFrameRateLabel'):setText(tr('Game framerate limit: %s', text))
  184. g_app.setBackgroundPaneMaxFps(v)
  185. elseif key == 'foregroundFrameRate' then
  186. local text, v = value, value
  187. if value <= 0 or value >= 61 then text = 'max' v = 0 end
  188. graphicsPanel:getChildById('foregroundFrameRateLabel'):setText(tr('Interface framerate limit: %s', text))
  189. g_app.setForegroundPaneMaxFps(v)
  190. elseif key == 'enableLights' then
  191. gameMapPanel:setDrawLights(value and options['ambientLight'] < 100)
  192. graphicsPanel:getChildById('ambientLight'):setEnabled(value)
  193. graphicsPanel:getChildById('ambientLightLabel'):setEnabled(value)
  194. elseif key == 'ambientLight' then
  195. graphicsPanel:getChildById('ambientLightLabel'):setText(tr('Ambient light: %s%%', value))
  196. gameMapPanel:setMinimumAmbientLight(value/100)
  197. gameMapPanel:setDrawLights(options['enableLights'] and value < 100)
  198. elseif key == 'painterEngine' then
  199. g_graphics.selectPainterEngine(value)
  200. elseif key == 'displayNames' then
  201. gameMapPanel:setDrawNames(value)
  202. elseif key == 'displayHealth' then
  203. gameMapPanel:setDrawHealthBars(value)
  204. elseif key == 'displayMana' then
  205. gameMapPanel:setDrawManaBar(value)
  206. elseif key == 'displayText' then
  207. gameMapPanel:setDrawTexts(value)
  208. elseif key == 'dontStretchShrink' then
  209. addEvent(function()
  210. modules.game_interface.updateStretchShrink()
  211. end)
  212. elseif key == 'turnDelay' then
  213. generalPanel:getChildById('turnDelayLabel'):setText(tr('Turn delay: %sms', value))
  214. elseif key == 'hotkeyDelay' then
  215. generalPanel:getChildById('hotkeyDelayLabel'):setText(tr('Hotkey delay: %sms', value))
  216. end
  217. -- change value for keybind updates
  218. for _,panel in pairs(optionsTabBar:getTabsPanel()) do
  219. local widget = panel:recursiveGetChildById(key)
  220. if widget then
  221. if widget:getStyle().__class == 'UICheckBox' then
  222. widget:setChecked(value)
  223. elseif widget:getStyle().__class == 'UIScrollBar' then
  224. widget:setValue(value)
  225. end
  226. break
  227. end
  228. end
  229. g_settings.set(key, value)
  230. options[key] = value
  231. end
  232. function getOption(key)
  233. return options[key]
  234. end
  235. function addTab(name, panel, icon)
  236. optionsTabBar:addTab(name, panel, icon)
  237. end
  238. function addButton(name, func, icon)
  239. optionsTabBar:addButton(name, func, icon)
  240. end