Advertisement
Guest User

Untitled

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