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.0KB

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