redef.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. --[========================================================================[--
  2. Key redefinition screen code for Thrust II Reloaded.
  3. Copyright © 2015 Pedro Gimeno Fortea
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. --]========================================================================]--
  20. local redef = {}
  21. local step
  22. function redef.activate()
  23. step = 1
  24. end
  25. local function xlate(s)
  26. return s == " " and "SPACE" or s:upper()
  27. end
  28. function redef.draw()
  29. lg.setColor(192, 192, 192, 255)
  30. main.centertext("DEFINE KEYS", main.ww/2, 56)
  31. lg.print("PRESS KEY FOR LEFT.....", 104, 112)
  32. if step >= 2 then
  33. lg.print(xlate(main.keys.left), 480, 112)
  34. lg.print("PRESS KEY FOR RIGHT....", 104, 160)
  35. end
  36. if step >= 3 then
  37. lg.print(xlate(main.keys.right), 480, 160)
  38. lg.print("PRESS KEY FOR THRUST...", 104, 208)
  39. end
  40. if step >= 4 then
  41. lg.print(xlate(main.keys.thrust), 480, 208)
  42. lg.print("PRESS KEY FOR PICKUP...", 104, 256)
  43. end
  44. if step >= 5 then
  45. lg.print(xlate(main.keys.pickup), 480, 256)
  46. lg.print("PRESS KEY FOR FIRE.....", 104, 304)
  47. end
  48. if step >= 6 then
  49. lg.print(xlate(main.keys.fire), 480, 304)
  50. lg.print("IS THIS CORRECT? (Y/N)", 128, 384)
  51. end
  52. lg.setColor(255, 255, 255)
  53. end
  54. function redef.keypressed(k, r)
  55. -- F10 reserved for save game, F3 for restore
  56. if k == "f10" or k == "f3" then return end
  57. if step == 1 then
  58. main.keys.left = k
  59. elseif step == 2 then
  60. main.keys.right = k
  61. elseif step == 3 then
  62. main.keys.thrust = k
  63. elseif step == 4 then
  64. main.keys.pickup = k
  65. elseif step == 5 then
  66. main.keys.fire = k
  67. end
  68. if step >= 1 and step <= 5 then
  69. step = step + 1
  70. end
  71. end
  72. function redef.textinput(c)
  73. if step == 6 then
  74. if c:lower() == "y" then
  75. -- save and return
  76. local s = main.keys.left .. "\n"
  77. .. main.keys.right .. "\n"
  78. .. main.keys.thrust .. "\n"
  79. .. main.keys.pickup .. "\n"
  80. .. main.keys.fire
  81. lfs.write("keys.txt", s, #s)
  82. main.activate(menu)
  83. elseif c:lower() == "n" then
  84. -- start again
  85. step = 1
  86. end
  87. end
  88. end
  89. return redef