redef.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. --[========================================================================[--
  2. Key redefinition screen code for Thrust II Reloaded.
  3. Copyright © 2015-2018 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 la,le,lfs,lf,lg,li,lj,lk,lm,lmo,lp,ls,lsys,lth,lt,lw = require'ns'()
  22. local step
  23. local DIV = love_version >= 11000000 and 255 or 1
  24. function redef.activate()
  25. step = 1
  26. end
  27. local function xlate(s)
  28. return s == " " and "SPACE" or s:upper()
  29. end
  30. function redef.draw()
  31. lg.setColor(192/DIV, 192/DIV, 192/DIV, 255/DIV)
  32. main.centertext("DEFINE KEYS", main.wcx, 56)
  33. lg.print("PRESS KEY FOR LEFT.....", 104, 112)
  34. if step >= 2 then
  35. lg.print(xlate(main.keys.left), 480, 112)
  36. lg.print("PRESS KEY FOR RIGHT....", 104, 160)
  37. end
  38. if step >= 3 then
  39. lg.print(xlate(main.keys.right), 480, 160)
  40. lg.print("PRESS KEY FOR THRUST...", 104, 208)
  41. end
  42. if step >= 4 then
  43. lg.print(xlate(main.keys.thrust), 480, 208)
  44. lg.print("PRESS KEY FOR PICKUP...", 104, 256)
  45. end
  46. if step >= 5 then
  47. lg.print(xlate(main.keys.pickup), 480, 256)
  48. lg.print("PRESS KEY FOR FIRE.....", 104, 304)
  49. end
  50. if step >= 6 then
  51. lg.print(xlate(main.keys.fire), 480, 304)
  52. lg.print("IS THIS CORRECT? (Y/N)", 128, 384)
  53. end
  54. lg.setColor(255/DIV, 255/DIV, 255/DIV)
  55. end
  56. function redef.keypressed(k, r)
  57. -- F10 reserved for save game, F3 for restore
  58. if k == "f10" or k == "f3" then return end
  59. -- exit this screen with ESC
  60. if k == "escape" then
  61. -- abort
  62. main.activate(screens.menu)
  63. return
  64. end
  65. -- pause reserved for pausing the game
  66. if k == "pause" then return end
  67. if step == 1 then
  68. main.keys.left = k
  69. elseif step == 2 then
  70. main.keys.right = k
  71. elseif step == 3 then
  72. main.keys.thrust = k
  73. elseif step == 4 then
  74. main.keys.pickup = k
  75. elseif step == 5 then
  76. main.keys.fire = k
  77. end
  78. if step >= 1 and step <= 5 then
  79. step = step + 1
  80. end
  81. end
  82. function redef.textinput(c)
  83. if step == 6 then
  84. if c:lower() == "y" then
  85. -- save and return
  86. local s = main.keys.left .. "\n"
  87. .. main.keys.right .. "\n"
  88. .. main.keys.thrust .. "\n"
  89. .. main.keys.pickup .. "\n"
  90. .. main.keys.fire
  91. lfs.write("keys.txt", s, #s)
  92. main.activate(screens.menu)
  93. return
  94. elseif c:lower() == "n" then
  95. -- start again
  96. step = 1
  97. end
  98. end
  99. end
  100. return redef