graphics-settings.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. graphicsSettings = {
  2. { "crt", false, "crt" },
  3. { "rays", false, "godsray" },
  4. { "vignette", false, "vignette"},
  5. { "posterize", false, "posterize" },
  6. selected = 1,
  7. noSettings = 4,
  8. }
  9. local mj, mi = love.getVersion()
  10. if mi >= 10 then
  11. graphicsSettings[5] = { "oldschool", false, "dmg" }
  12. graphicsSettings[6] = { "bloom", false, "glow" }
  13. graphicsSettings.noSettings = 6
  14. end
  15. function graphicsSettings.update(key)
  16. if key == ACTION.UP then
  17. graphicsSettings.selected = graphicsSettings.selected - 1
  18. if graphicsSettings.selected == 0 then
  19. graphicsSettings.selected = graphicsSettings.noSettings + 1
  20. end
  21. elseif key == ACTION.DOWN then
  22. graphicsSettings.selected = graphicsSettings.selected + 1
  23. if graphicsSettings.selected == graphicsSettings.noSettings + 2 then
  24. graphicsSettings.selected = 1
  25. end
  26. elseif key == ACTION.LEFT or key == ACTION.RIGHT then
  27. local opt = graphicsSettings[graphicsSettings.selected]
  28. if opt then
  29. -- Toggle the boolean
  30. opt[2] = not opt[2]
  31. -- Toggle the shader
  32. if opt[2] then
  33. fx.enable(opt[3])
  34. else
  35. fx.disable(opt[3])
  36. end
  37. else
  38. -- "return to game"
  39. state = "play"
  40. graphicsSettings.selected = 1
  41. end
  42. sounds.toggle:play()
  43. end
  44. end
  45. function graphicsSettings.render(text)
  46. local s = "GRAPHICS SETTINGS\n\n\n"
  47. for i, v in ipairs(graphicsSettings) do
  48. s = s .. leftpad(v[1], 10) .. " "
  49. if graphicsSettings.selected == i then
  50. s = s .. "["
  51. end
  52. if v[2] then s = s .. "ON"
  53. else s = s .. "off" end
  54. if graphicsSettings.selected == i then
  55. s = s .. "]"
  56. end
  57. s = s .. "\n"
  58. end
  59. s = s .. "\n\n "
  60. if graphicsSettings.selected == graphicsSettings.noSettings + 1 then
  61. s = s .. "["
  62. end
  63. s = s .. "return to game"
  64. if graphicsSettings.selected == graphicsSettings.noSettings + 1 then
  65. s = s .. "]"
  66. end
  67. drawTitle(s, text)
  68. end
  69. function leftpad(str, len, chr)
  70. local chr = chr or " "
  71. local l = len - #str
  72. if l > 0 then return string.rep(chr, l) .. str
  73. else return str end
  74. end